TabulatedTankSimulator.cc
Go to the documentation of this file.
2 #include <utl/ErrorLogger.h>
3 #include <utl/PhysicalConstants.h>
4 #include <utl/AugerUnits.h>
5 #include <utl/ParticleCases.h>
6 
7 #include <evt/Event.h>
8 #include <sevt/SEvent.h>
9 #include <sevt/Station.h>
10 #include <sevt/PMT.h>
11 #include <sevt/StationSimData.h>
12 #include <sevt/PMTSimData.h>
13 
14 #include <fwk/CentralConfig.h>
15 #include <fwk/RandomEngineRegistry.h>
16 #include <det/Detector.h>
17 #include <sdet/SDetector.h>
18 
19 #include <CLHEP/Random/RandFlat.h>
20 
21 
22 //using namespace sdet;
23 using namespace std;
24 using namespace sevt;
25 using namespace evt;
26 using namespace fwk;
27 using namespace utl;
28 using CLHEP::RandFlat;
29 using namespace TabulatedTankSimulatorNS;
30 
31 
32 namespace TabulatedTankSimulatorNS {
33  const double pulse_Tau = 60.; //ns
34  const double pulse_tMax = 25.; //ns
35  const double pulse_cdfMax = 0.3; //Probability (time <= pulse_tMax)
36 }
37 
38 
39 TabulatedTankSimulator::TabulatedTankSimulator() :
40  fTauMuon(kMuonLifetime/ns)
41 { }
42 
43 
45 {
46  delete fTankResponse;
47 }
48 
49 
52 {
53  Branch topB =
54  CentralConfig::GetInstance()->GetTopBranch("TabulatedTankSimulator");
55 
56  string sepMode;
57  topB.GetChild("signalSeparationMode").GetData(sepMode);
58  if (sepMode == "Standard")
60  else if (sepMode == "Universality")
62 
64  &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector).GetEngine();
65 
66  delete fTankResponse;
67 
68  bool useG4 = false;
69  // 0: WCD, 1: ASCII, 2: AMIGA (this module can be used only for WCD)
70  int DetectorType = 0;
71  bool UseEnlargeArea = false;
72  fTankResponse = new DetectorResponse(useG4, DetectorType, UseEnlargeArea);
73 
74  return eSuccess;
75 }
76 
77 
80 {
81  INFO("TabulatedTankSimulator::Run()");
82 
83  SEvent& sEvent = event.GetSEvent();
84  for (SEvent::StationIterator sIt = sEvent.StationsBegin();
85  sIt != sEvent.StationsEnd(); ++sIt)
86  SimulateStation(*sIt);
87 
88  return eSuccess;
89 }
90 
91 
94 {
95  INFO("TabulatedTankSimulator::Finish()");
96  return eSuccess;
97 }
98 
99 
100 int
102 {
103  switch (pid) {
104  case utl::Particle::eMuon: return 0;
105  case utl::Particle::eAntiMuon: return 0;
106  case utl::Particle::eElectron: return 1;
107  case utl::Particle::ePositron: return 1;
108  case utl::Particle::ePhoton: return 2;
109  case utl::Particle::eProton: return -5000;
110  case utl::Particle::eAntiProton: return -5000;
111  case utl::Particle::eNeutron: return -5000;
112  case utl::Particle::eAntiNeutron: return -5000;
113  default: return -5000;
114  }
115 }
116 
117 
118 double
120 {
121  double time = 0;
122  double rnd = RandFlat::shoot(fRandomEngine, 0., 1.);
123 
124  if (rnd < pulse_cdfMax)
125  time = rnd * pulse_tMax / pulse_cdfMax; //Simple linear interpolation
126  else {
127  rnd = (rnd - pulse_cdfMax) / (1 - pulse_cdfMax);
128  time = pulse_tMax - pulse_Tau * log(1 - rnd);
129  }
130 
131  if (!std::isnan(time) && !std::isinf(time))
132  return time;
133 
134  return 25.;
135 }
136 
137 
138 void
140 {
141  if (!station.HasSimData())
142  return;
143 
144  StationSimData& simData = station.GetSimData();
145  const sdet::SDetector& sDetector = det::Detector::GetInstance().GetSDetector();
146 
147  simData.SetSimulatorSignature("TabulatedTankSimulatorKG");
148 
149  const unsigned long numParticles =
150  simData.ParticlesEnd() - simData.ParticlesBegin();
151 
152  if (!numParticles)
153  return;
154 
155  /*
156  * Counting the number of particles that are actually simulated (post
157  * station-level thinning). Due to resampling simulation option that
158  * uses cycles with maximum particle number per cycle, we always check
159  * if particles have already been simulated.
160  */
161  const unsigned int nParticlesAlreadySimulated = simData.GetTotalSimParticleCount();
162  if (!nParticlesAlreadySimulated)
163  simData.SetTotalSimParticleCount(numParticles);
164  else
165  simData.SetTotalSimParticleCount(nParticlesAlreadySimulated + numParticles);
166 
167  const sdet::Station& detStation = sDetector.GetStation(station);
168  for (sevt::Station::PMTIterator pmtIt = station.PMTsBegin();
169  pmtIt != station.PMTsEnd(); ++pmtIt) {
170  if (!pmtIt->HasSimData()) {
171  pmtIt->MakeSimData();
172  pmtIt->GetSimData().MakePETimeDistribution();
173  }
174  }
175 
177  pIt != simData.ParticlesEnd(); ++pIt) {
178 
179  const double pke = pIt->GetKineticEnergy();
180  const double ptheta = kPi - pIt->GetDirection().GetTheta(detStation.GetLocalCoordinateSystem());
181 
182  const int itype = PDGToCDF(pIt->GetType());
183  if (itype == -5000)
184  continue;
185 
186  const double rnd = RandFlat::shoot(fRandomEngine, 0, 1);
187  const int nPe = int(fTankResponse->GetPe(pke/GeV, ptheta, itype, rnd));
188 
189  int nPe_decay = 0;
190 
191  if (itype == 0) {
192  const double rnd_d = RandFlat::shoot(fRandomEngine, 0, 1);
193  nPe_decay = int(fTankResponse->GetPe(pke/GeV, ptheta, 4, rnd_d)); // type 4: decay electrons
194  }
195 
196  if (nPe + nPe_decay == 0)
197  continue;
198 
199  ostringstream msg;
200  msg << "Theta " << ptheta*180/3.14 << "| KE GeV " << pke/GeV << " | Id " << itype
201  << " | NPE= " << nPe << " - " << nPe_decay;
202  //INFO(msg);
203 
204  double tdecay = 0;
205  if (nPe_decay > 0)
206  tdecay = -fTauMuon * log(1 - RandFlat::shoot(fRandomEngine, 0, 1));
207 
208  for (int kk = 0; kk < (nPe + nPe_decay); ++kk) {
209 
210  TimeInterval pe_time(pIt->GetTime());
211  pe_time += GetTimePE();
212  if (kk >= nPe)
213  pe_time += tdecay;
214 
215  const int pmtId = int(RandFlat::shoot(fRandomEngine, 0, 3)) + 1;
216  if (!station.HasPMT(pmtId))
217  continue;
218 
219  if (!station.GetPMT(pmtId).HasSimData())
220  station.GetPMT(pmtId).MakeSimData();
221  PMTSimData& pmtSim = station.GetPMT(pmtId).GetSimData();
222  AddPhoton(*pIt, pmtSim, pe_time.GetInterval());
223  }
224  }
225 }
226 
227 
228 void
230  const
231 {
232  const int type = particle.GetType();
233  const int source = particle.GetSource();
234 
237 
238  switch (fSignalSeparationMode) {
239  case eStandard:
240  switch (type) {
241  case OFFLINE_ELECTRONS:
245  break;
246  case OFFLINE_PHOTON:
250  break;
251  case OFFLINE_MUONS:
252  component = sevt::StationConstants::eMuon;
253  break;
254  case OFFLINE_HADRONS:
256  break;
257  default:
258  cerr << "Unknown particle type" << endl;
259  exit(-1);
260  }
261  break;
262  case eUniversality:
263  switch (type) {
264  case OFFLINE_ELECTRONS:
265  switch (source) {
268  break;
271  break;
272  default:
274  break;
275  }
276  break;
277  case OFFLINE_PHOTON:
278  switch (source) {
281  break;
284  break;
285  default:
287  break;
288  }
289  break;
290  case OFFLINE_MUONS:
291  component = sevt::StationConstants::eMuon;
292  break;
293  case OFFLINE_HADRONS:
295  break;
296  default:
297  cerr << "Unknown particle type" << endl;
298  exit(-1);
299  }
300  break;
301  }
302 
303  if (!pmtSim.HasPETimeDistribution())
304  pmtSim.MakePETimeDistribution();
305  pmtSim.GetPETimeDistribution().AddTime(peTime);
306 
307  if (!pmtSim.HasPETimeDistribution(component))
308  pmtSim.MakePETimeDistribution(component);
309  pmtSim.GetPETimeDistribution(component).AddTime(peTime);
310 
311  if (extraComponent != sevt::StationConstants::eTotal) {
312  if (!pmtSim.HasPETimeDistribution(extraComponent))
313  pmtSim.MakePETimeDistribution(extraComponent);
314  pmtSim.GetPETimeDistribution(extraComponent).AddTime(peTime);
315  }
316 
317 }
Branch GetTopBranch() const
Definition: Branch.cc:63
constexpr double kMuonLifetime
bool HasPMT(const unsigned int pmtId) const
Check if a particular PMT object exists.
Station Level Simulated Data
StationIterator StationsEnd()
End of all stations.
Definition: SEvent.h:59
PMTSimData & GetSimData()
Get object containing PMT simulated data.
Definition: SEvent/PMT.h:40
Detector description interface for Station-related data.
Report success to RunController.
Definition: VModule.h:62
total (shower and background)
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
Interface class to access to the SD part of an event.
Definition: SEvent.h:39
Describes a particle for Simulation.
Definition: Particle.h:26
PMTIterator PMTsBegin(const sdet::PMTConstants::PMTType type=sdet::PMTConstants::eWaterCherenkovLarge)
begin PMT iterator for read/write
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
electrons produced by hadrons close to the detector
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
boost::filter_iterator< PMTFilter, InternalPMTIterator > PMTIterator
Iterator over station for read/write.
int exit
Definition: dump1090.h:237
void SetSimulatorSignature(const std::string &name)
Set name of the tank simulator module used to simulate this station.
bool HasPETimeDistribution(const StationConstants::SignalComponent source=StationConstants::eTotal) const
Check if a PE release time distribution exists (optionally for a given source)
Definition: PMTSimData.h:65
void MakeSimData()
Make PMT simulated data object.
Definition: SEvent/PMT.cc:19
ParticleVector::iterator ParticleIterator
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
void AddPhoton(const utl::Particle &particle, sevt::PMTSimData &pmtSim, const double peTime) const
electrons and positrons from shower
Class representing a document branch.
Definition: Branch.h:107
class to hold data at Station level
bool HasSimData() const
Check whether station simulated data exists.
const double ns
constexpr double kPi
Definition: MathConstants.h:24
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Get the Auger reference system centered on the tank.
PMTIterator PMTsEnd(const sdet::PMTConstants::PMTType type=sdet::PMTConstants::eWaterCherenkovLarge)
end PMT iterator for read/write
double GetPe(double ke, double theta, int itype, double f)
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
bool HasSimData() const
Check for existence of PMT simulated data object.
Definition: SEvent/PMT.h:45
ParticleIterator ParticlesBegin()
Beginning of simulated particles entering the station.
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
utl::RandomEngine::RandomEngineType * fRandomEngine
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
constexpr double GeV
Definition: AugerUnits.h:187
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
PMT & GetPMT(const unsigned int pmtId)
Retrive a PMT by Id.
unsigned int GetTotalSimParticleCount() const
Get the total number of particles that were actually simulated (after thinning)
void SetTotalSimParticleCount(const unsigned int n)
StationIterator StationsBegin()
Beginning of all stations.
Definition: SEvent.h:57
Source GetSource() const
Source of the particle (eg. shower or background)
Definition: Particle.h:107
Class to hold simulated data at PMT level.
Definition: PMTSimData.h:40
struct particle_info particle[80]
int GetType() const
Definition: Particle.h:101
Detector description interface for SDetector-related data.
Definition: SDetector.h:42
boost::indirect_iterator< InternalStationIterator, Station & > StationIterator
Iterator over all stations.
Definition: SEvent.h:52
sevt::StationSimData & GetSimData()
Get simulated data at station level.
utl::TimeDistributionI & GetPETimeDistribution(const StationConstants::SignalComponent source=StationConstants::eTotal)
Simulated photoelectron time distribution.
Definition: PMTSimData.h:54
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: SDetector.cc:192
ParticleIterator ParticlesEnd()
End of simulated particles entering the station.
void AddTime(const double time, const T weight=T(1))
Add an entry (optionally weighted) for the given time. Slot will be computed.
mu+ and mu- (including signal from mu decay electrons) from shower
void MakePETimeDistribution(const StationConstants::SignalComponent source=StationConstants::eTotal)
Create a PE release time distribution (optionally for given source)
Definition: PMTSimData.cc:12

, generated on Tue Sep 26 2023.