SEvent/StationSimData.cc
Go to the documentation of this file.
1 #include <sevt/StationSimData.h>
2 #include <sevt/StationTriggerData.h>
3 #include <sevt/StationGPSData.h>
4 #include <sdet/Station.h>
5 #include <utl/Particle.h>
6 #include <utl/ShadowPtr.h>
7 #include <utl/ErrorLogger.h>
8 #include <fwk/RandomEngineRegistry.h>
9 #include <sstream>
10 
11 using namespace utl;
12 using namespace fwk;
13 using namespace std;
14 
15 
16 namespace sevt {
17 
18  void
19  StationSimData::AddParticle(const utl::Particle& particle)
20  {
21  /*
22  * Add one to the counter for all injection candidate particles
23  * regardless of whether they are truly injected in the end or
24  * removed during a Shrink() (station-level particle thinning).
25  */
26  ++fTotalSimCandidateParticleCount;
27 
28  // keep this decision inline
29  if (fThinning == 1)
30  AlwaysInsertParticle(particle);
31  else
32  SometimesInsertParticle(particle);
33  if (fParticles.size() >= fMaxNParticles)
34  Shrink();
35  }
36 
37 
38  void
39  StationSimData::CountParticle(const utl::Particle& particle)
40  {
41  ++fTotalParticleCount;
42  /*
43  * Should return enum, not int. Perhaps modification of GetType() member
44  * function of Particle class warranted
45  */
46  int type = particle.GetType();
47  if (type == utl::Particle::eMuon || type == utl::Particle::eAntiMuon)
48  ++fNumberOfMuons;
49  else if (type == utl::Particle::eElectron || type == utl::Particle::ePositron)
50  ++fNumberOfElectrons;
51  else if (type == utl::Particle::ePhoton)
52  ++fNumberOfPhotons;
53  }
54 
55 
56  void
57  StationSimData::SometimesInsertParticle(const Particle& particle)
58  {
59  const double sometimes =
60  RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector).GetEngine().flat();
61  if (sometimes < fThinning)
62  AlwaysInsertParticle(particle);
63  }
64 
65 
66  void
67  StationSimData::Shrink()
68  {
69  ParticleVector newList;
70  auto& rnd = RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector).GetEngine();
71  for (const auto& p : fParticles)
72  if (rnd.flat() < fThinningFactor)
73  newList.push_back(p);
74  fParticles.swap(newList);
75  fThinning *= fThinningFactor;
76  }
77 
78 
79  void
80  StationSimData::ClearParticleList()
81  {
82  decltype(fParticles)().swap(fParticles);
83  }
84 
85 
86  void
87  StationSimData::MakeTriggerAndGPSData(const TimeStamp& time)
88  {
89  if (HasTriggerData(time)) {
90  WARNING("Trigger and GPS data already present!");
91  return;
92  }
93 
94  fTriggerAndGPSData.emplace(time, TriggerGPSPair(StationTriggerData(), StationGPSData()));
95  }
96 
97 
98  const std::string&
99  StationSimData::GetSimulatorSignature()
100  const
101  {
102  if (fSimulatorSignature.empty()) {
103  const string err = "Requesting an SD simulator signature which was never set.";
104  ERROR(err);
106  }
107  return fSimulatorSignature;
108  }
109 
110 
111  bool
112  StationSimData::HasGPSData(const TimeStamp& time)
113  const
114  {
115  return fTriggerAndGPSData.find(time) != fTriggerAndGPSData.end();
116  }
117 
118 
120  StationSimData::GetGPSData(const TimeStamp& time)
121  {
122  if (!HasTriggerData(time)) {
123  ostringstream err;
124  err << "Tried to get unavailable GPS data at time " << time;
125  ERROR(err);
126  throw NonExistentComponentException(err.str());
127  }
128 
129  return fTriggerAndGPSData.find(time)->second.second;
130  }
131 
132 
133  const StationGPSData&
134  StationSimData::GetGPSData(const TimeStamp& time)
135  const
136  {
137  if (!HasTriggerData(time)) {
138  ostringstream err;
139  err << "Tried to get unavailable GPS data at time " << time;
140  ERROR(err);
141  throw NonExistentComponentException(err.str());
142  }
143 
144  return fTriggerAndGPSData.find(time)->second.second;
145  }
146 
147 
149  StationSimData::GetTriggerData(const TimeStamp& time)
150  {
151  if (!HasTriggerData(time)) {
152  ostringstream err;
153  err << "Tried to get unavailable trigger data at time " << time;
154  ERROR(err);
155  throw NonExistentComponentException(err.str());
156  }
157 
158  return fTriggerAndGPSData.find(time)->second.first;
159  }
160 
161 
162  const StationTriggerData&
163  StationSimData::GetTriggerData(const TimeStamp& time)
164  const
165  {
166  if (!HasTriggerData(time)) {
167  ostringstream err;
168  err << "Tried to get unavailable trigger data at time " << time;
169  ERROR(err);
170  throw NonExistentComponentException(err.str());
171  }
172 
173  return fTriggerAndGPSData.find(time)->second.first;
174  }
175 
176 }
void swap(utl::TabulatedFunction &t1, utl::TabulatedFunction &t2)
Describes a particle for Simulation.
Definition: Particle.h:26
std::vector< utl::Particle > ParticleVector
Base class for exceptions trying to access non-existing components.
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
std::pair< StationTriggerData, StationGPSData > TriggerGPSPair
Station Trigger Data description
struct particle_info particle[80]
int GetType() const
Definition: Particle.h:101
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.