LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
SimEnergyDeposit.h
Go to the documentation of this file.
1 #ifndef LARDATAOBJ_SIMULATION_SIMENERGYDEPOSIT_H
8 #define LARDATAOBJ_SIMULATION_SIMENERGYDEPOSIT_H
9 
10 // LArSoft includes
11 // Define the LArSoft standard geometry types and methods.
13 
14 // C++ includes
15 #include <vector>
16 
17 namespace sim {
41  public:
42  // Define the types for the private members below.
43  using Length_t = float;
45 
46  // Since we're using LArSoft geometry types, the typical way to
47  // construct a SimEnergyDeposit might be:
48  // sim::SimEnergyDeposit sed(numPhotons,
49  // numElectrons,
50  // stepEnergy,
51  // { startX, startY, startZ },
52  // { endX, endY, endZ },
53  // startTime,
54  // endTime,
55  // trackID,
56  // pdgCode);
57 
58  SimEnergyDeposit(int np = 0,
59  // int nfp = 0,
60  // int nsp = 0,
61  int ne = 0,
62  double sy = 0,
63  double e = 0.,
64  geo::Point_t start = {0., 0., 0.},
65  geo::Point_t end = {0., 0., 0.},
66  double t0 = 0.,
67  double t1 = 0.,
68  int id = 0,
69  int pdg = 0,
70  int origTrackID = 0)
71  : numPhotons(np)
72  // , numFPhotons(nfp)
73  // , numSPhotons(nsp)
74  , numElectrons(ne)
75  , scintYieldRatio(sy)
76  , edep(e)
77  , startPos(start)
78  , endPos(end)
79  , startTime(t0)
80  , endTime(t1)
81  , trackID(id)
82  , pdgCode(pdg)
83  , origTrackID(origTrackID)
84  {}
85 
86  // Note that even if we store a value as float, we return
87  // it as double so the user doesn't have to think about
88  // precision issues.
89 
90  int NumPhotons() const { return numPhotons; }
91  int NumFPhotons() const { return round(numPhotons * scintYieldRatio); }
92  int NumSPhotons() const { return round(numPhotons * (1.0 - scintYieldRatio)); }
93  int NumElectrons() const { return numElectrons; }
94  double ScintYieldRatio() const { return scintYieldRatio; }
95  double Energy() const { return edep; }
96  geo::Point_t Start() const { return startPos; }
97  geo::Point_t End() const { return endPos; }
98  double Time() const { return (startTime + endTime) / 2.; }
99  int TrackID() const { return trackID; }
100  int OrigTrackID() const { return origTrackID; }
101  void setTrackID(int id) { trackID = id; }
102  int PdgCode() const { return pdgCode; }
103 
104  // While it's clear how a SimEnergyDeposit will be created by its
105  // constructor, it's not clear how users will want to access its
106  // data. So give them as many different kinds of accessors as I
107  // can think of.
108  geo::Length_t StartX() const { return startPos.X(); }
109  geo::Length_t StartY() const { return startPos.Y(); }
110  geo::Length_t StartZ() const { return startPos.Z(); }
111  double StartT() const { return startTime; }
112  geo::Length_t EndX() const { return endPos.X(); }
113  geo::Length_t EndY() const { return endPos.Y(); }
114  geo::Length_t EndZ() const { return endPos.Z(); }
115  double EndT() const { return endTime; }
116 
117  // Step mid-point.
119  {
120  return startPos + 0.5 * (endPos - startPos);
121  }
122  geo::Length_t MidPointX() const { return (startPos.X() + endPos.X()) / 2.; }
123  geo::Length_t MidPointY() const { return (startPos.Y() + endPos.Y()) / 2.; }
124  geo::Length_t MidPointZ() const { return (startPos.Z() + endPos.Z()) / 2.; }
125  geo::Length_t X() const { return MidPointX(); }
126  geo::Length_t Y() const { return MidPointY(); }
127  geo::Length_t Z() const { return MidPointZ(); }
128  double T() const { return (startTime + endTime) / 2.; }
129  double T0() const { return startTime; }
130  double T1() const { return endTime; }
131  double E() const { return edep; }
132 
133  // Step length. (Recall that the difference between two
134  // geo::Point_t objects is a geo::Vector_t; we get the length from
135  // spherical coordinates.
136  geo::Length_t StepLength() const { return (endPos - startPos).R(); }
137 
138  // Just in case someone wants to store sim::SimEnergyDeposit
139  // objects in a sorted container, define a sort function. Note
140  // that the ideal sort order is dependent of the analysis you're
141  // trying to perform; for example, if you're dealing with cosmic
142  // rays coming along the y-axis, sorting first by z may cause some
143  // tasks like insertions to take a very long time.
144 
145  bool operator<(const SimEnergyDeposit& rhs) const
146  {
147  return trackID < rhs.trackID && startTime < rhs.startTime &&
148  startPos.Z() < rhs.startPos.Z() && startPos.Y() < rhs.startPos.Y() &&
149  startPos.X() < rhs.startPos.X() && edep > rhs.edep; // sort by _decreasing_ energy
150  }
151 
152  private:
153  // While the accessors above return all values in double
154  // precision, store whatever we can in single precision to save
155  // memory and disk space.
156 
157  // There are roughly 7 digits of decimal precision in a float.
158  // This will suffice for energy. A float (as opposed to a double)
159  // can hold a little more than 7 digits of decimal precision. The
160  // smallest position resolution in the simulation is about 0.1mm,
161  // or 10^-4m. With seven digits of precision, that means a float
162  // can be accurate to up to the range of 10^3m. That's why the
163  // definition of our local Point_t (see above) is based on float,
164  // while geo::Point_t is based on double.
165 
166  // If the above reasoning is wrong, just change the definition of
167  // Length_t near the top of this file. Of course, also edit these
168  // comments if you do, because you're a good and responsible
169  // programmer.
170 
171  // For time, it's possible for long-lived particles like neutrons
172  // to deposit energy after billions of ns. Chances are time cuts
173  // will take care of that, but let's make sure that any overlay studies
174  // won't suffer due to lack of precision.
175 
177  // int numFPhotons; ///< of fast scintillation photons
178  // int numSPhotons; ///< of slow scintillation photons
181  float edep;
184  double startTime;
185  double endTime;
186  int trackID;
187  int pdgCode;
188  int
190  };
191  /*
192  // Class utility functions.
193 
194  // The format of the sim::SimEnergyDeposit output. I'm using a
195  // template for the ostream type, since LArSoft may have some
196  // special classes for its output streams.
197  template <typename Stream>
198  Stream& operator<<(Stream&& os, const sim::SimEnergyDeposit& sed)
199  {
200  // Note that the geo::Point_t type (returned by Start() and End())
201  // has an ostream operator defined for it.
202  os << "trackID " << sed.TrackID()
203  << " pdgCode=" << sed.PdgCode()
204  << " start=" << sed.Start()
205  << " t0=" << sed.T0()
206  << " end=" << sed.End()
207  << " t1=" << sed.T1() << " [cm,ns]"
208  << " E=" << sed.E() << "[GeV]"
209  << " #photons=" << sed.NumPhotons();
210  return os;
211  }
212 
213  // It can be more memory efficient to sort objects by pointers;
214  // e.g., if you've got an unsorted
215  // std::vector<sim::SimEnergyDeposit>, create a
216  // std::set<sim::SimEnergyDeposit*,sim::CompareSED> so you're not
217  // duplicating the objects in memory. The following definition
218  // covers sorting the pointers.
219  bool compareSED(const SimEnergyDeposit* const lhs, const SimEnergyDeposit* const rhs)
220  {
221  return (*lhs) < (*rhs);
222  }
223  */
224  typedef std::vector<SimEnergyDeposit> SimEnergyDepositCollection;
225 } // namespace sim
226 #endif // LARDATAOBJ_SIMULATION_SIMENERGYDEPOSIT_H
geo::Length_t StartX() const
code to link reconstructed objects back to the MC truth information
geo::Length_t EndZ() const
geo::Length_t StepLength() const
geo::Length_t EndY() const
TTree * t1
Definition: plottest35.C:26
double Length_t
Type used for coordinates and distances. They are measured in centimeters.
Definition: geo_vectors.h:133
geo::Length_t Y() const
int numElectrons
of ionization electrons
int origTrackID
complementary simulation track id, kept true to G4 even for shower secondaries/tertiaries etc...
SimEnergyDeposit(int np=0, int ne=0, double sy=0, double e=0., geo::Point_t start={0., 0., 0.}, geo::Point_t end={0., 0., 0.}, double t0=0., double t1=0., int id=0, int pdg=0, int origTrackID=0)
geo::Length_t StartY() const
double StartT() const
geo::Point_t startPos
positions in (cm)
int numPhotons
of scintillation photons
geo::Length_t Z() const
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
int pdgCode
pdg code of particle to avoid lookup by particle type later
geo::Length_t EndX() const
geo::Point_t Start() const
geo::Point_t End() const
Definitions of geometry vector data types.
int trackID
simulation track id
double Time() const
geo::Point_t MidPoint() const
geo::Length_t StartZ() const
Monte Carlo Simulation.
geo::Length_t MidPointX() const
geo::Length_t MidPointY() const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
std::vector< SimEnergyDeposit > SimEnergyDepositCollection
float scintYieldRatio
scintillation yield of LAr
bool operator<(const SimEnergyDeposit &rhs) const
geo::Length_t MidPointZ() const
Energy deposition in the active material.
double Energy() const
Float_t e
Definition: plot.C:35
geo::Length_t X() const
double ScintYieldRatio() const
float edep
energy deposition (MeV)