LArSoft  v10_06_00
Liquid Argon Software toolkit - https://larsoft.org/
OpDetBacktrackerRecord.h
Go to the documentation of this file.
1 /*
2  * @file OpDetBacktrackerRecord.h
3  * @brief object containing MC truth information necessary for backtracking Photons.
4  * Based on SimChannels by seligman@nevis.columbia.edu
5  * @author jason.stock@mines.sdsmt.edu
6  * @see OpDetBacktrackerRecord.cxx
7  *
8  * This class uses only LArSoft libraries that are header only.
9  */
10 
11 #ifndef LARSIMOBJ_SIMULATION_OPDETBACKTRACKERRECORD_H
12 #define LARSIMOBJ_SIMULATION_OPDETBACKTRACKERRECORD_H
13 
14 // C/C++ standard libraries
15 #include <map>
16 #include <string>
17 #include <utility> // std::pair
18 #include <vector>
19 namespace sim {
20 
22  struct TrackSDP {
23  int trackID;
24  float energyFrac;
25  float energy;
26 
27  TrackSDP() {}
28 
29  TrackSDP(int id, float phF, float ph) : trackID(id), energyFrac(phF), energy(ph) {}
30  };
31 
61  struct SDP {
62 
64  typedef int TrackID_t;
65 
67  SDP();
68 
70  SDP(SDP const& sdp, int offset);
71 
73  SDP(TrackID_t tid, float nPh, float e, float xpos, float ypos, float zpos)
74  : trackID(tid), numPhotons(nPh), energy(e), x(xpos), y(ypos), z(zpos)
75  {}
76 
77  TrackID_t trackID;
78  float numPhotons;
79  float energy;
80  float x;
81  float y;
82  float z;
83  }; // struct SDP
84 
86  typedef std::pair<double, std::vector<sim::SDP>> timePDclockSDP_t;
87 
88  class OBTRHelper {
89  friend class OpDetBacktrackerRecord;
90 
91  public:
92  typedef double timePDclock_t;
94 
95  OBTRHelper(TrackID_t trackID) : fTrackID(trackID) {}
96 
97  void AddScintillationPhotonsToMap(
98  // std::map<timePDclock_t, std::vector<sim::SDP>> & timePDclockSDPs,
99  TrackID_t trackID,
100  timePDclock_t iTimePDclock,
101  double numberPhotons,
102  double const* xyz,
103  double energy);
104 
105  private:
106  std::map<timePDclock_t, std::vector<sim::SDP>> fTimePDclockSDPs;
107  TrackID_t fTrackID;
108  };
109 
128  public:
130  typedef timePDclockSDP_t::first_type storedTimePDclock_t;
131 
133  typedef std::vector<timePDclockSDP_t> timePDclockSDPs_t;
134  // typedef std::map<storedTimePDclock_t, std::vector<sim::SDP>> timePDclockSDPs_t;
135 
136  private:
137  int iOpDetNum;
138  timePDclockSDPs_t timePDclockSDPs;
139 
140  public:
141  // Default constructor
143 
145  //typedef unsigned short timePDclock_t;
146  typedef double timePDclock_t; //This is the G4Time from OpFastScintillation. (ns)
147 
150 
152  explicit OpDetBacktrackerRecord(int detNum);
153 
154  explicit OpDetBacktrackerRecord(OBTRHelper& helper);
155 
165  void AddScintillationPhotons(TrackID_t trackID,
166  timePDclock_t timePDclock,
167  double numberPhotons,
168  double const* xyz,
169  double energy);
170 
172  int OpDetNum() const;
173 
191  std::vector<sim::SDP> TrackIDsAndEnergies(timePDclock_t startTimePDclock,
192  timePDclock_t endTimePDclock) const;
193 
206  timePDclockSDPs_t const& timePDclockSDPsMap() const;
207 
209  double Photons(timePDclock_t iTimePDclock) const;
210 
212  double Energy(timePDclock_t iTimePDclock) const;
213 
214  // /// Sorts the timeClockSDPs by increasing timePDclock tick
215  // void SortTimePDclockSDPs();
216 
239  std::vector<sim::TrackSDP> TrackSDPs(timePDclock_t startTimePDclock,
240  timePDclock_t endTimePDclock) const;
241 
243  bool operator<(const OpDetBacktrackerRecord& other) const;
244 
246  bool operator==(const OpDetBacktrackerRecord& other) const;
247 
273  std::pair<TrackID_t, TrackID_t> MergeOpDetBacktrackerRecord(
274  const OpDetBacktrackerRecord& opDetNum,
275  int offset);
276 
284  template <typename Stream>
285  void Dump(Stream&& out, std::string indent, std::string first_indent) const;
286 
288  template <typename Stream>
289  void Dump(Stream&& out, std::string indent = "") const
290  {
291  Dump(std::forward<Stream>(out), indent, indent);
292  }
293 
294  private:
296  struct CompareByTimePDclock;
297 
299  timePDclockSDPs_t::iterator findClosestTimePDclockSDP(storedTimePDclock_t timePDclock);
300 
302  timePDclockSDPs_t::const_iterator findClosestTimePDclockSDP(
303  storedTimePDclock_t timePDclock) const;
304  };
305 
306 } // namespace sim
307 
309 {
310  return iOpDetNum < other.OpDetNum();
311 }
313 {
314  return iOpDetNum == other.OpDetNum();
315 }
318 {
319  return timePDclockSDPs;
320 }
322 {
323  return iOpDetNum;
324 }
325 
326 // -----------------------------------------------------------------------------
327 // --- template implementation
328 // ---
329 template <class Stream>
331  std::string indent,
332  std::string first_indent) const
333 {
334  out << first_indent << "OpDet #" << OpDetNum() << " read " << timePDclockSDPs.size()
335  << " timePDclocks:\n";
336  double opDet_energy = 0., opDet_photons = 0.;
337  for (const auto& timePDclockinfo : timePDclockSDPs) {
338  auto const iTimePDclock = timePDclockinfo.first;
339  out << indent << " timePDclock #" << iTimePDclock << " with " << timePDclockinfo.second.size()
340  << " SDPs\n";
341  double timePDclock_energy = 0., timePDclock_photons = 0.;
342  for (const sim::SDP& sdp : timePDclockinfo.second) {
343  out << indent << " (" << sdp.x << ", " << sdp.y << ", " << sdp.z << ") " << sdp.numPhotons
344  << " photons, " << sdp.energy << "MeV (trkID=" << sdp.trackID << ")\n";
345  timePDclock_energy += sdp.energy;
346  timePDclock_photons += sdp.numPhotons;
347  } // for SDPs
348  out << indent << " => timePDclock #" << iTimePDclock << " CH #" << OpDetNum()
349  << " collected " << timePDclock_energy << " MeV and " << timePDclock_photons
350  << " photons. \n";
351  opDet_energy += timePDclock_energy;
352  opDet_photons += timePDclock_photons;
353  } // for timePDclocks
354  out << indent << " => channel #" << OpDetNum() << " collected " << opDet_photons
355  << " photons and " << opDet_energy << " MeV.\n";
356 } // sim::OpDetBacktrackerRecord::Dump<>()
357 
358 #endif // LARSIMOBJ_SIMULATION_OPDETBACKTRACKERRECORD_H
359 
Float_t x
Definition: compare.C:6
intermediate_table::iterator iterator
int iOpDetNum
OpticalDetector where the photons were detected.
OBTRHelper(TrackID_t trackID)
float x
x position of ionization [cm]
bool operator<(const OpDetBacktrackerRecord &other) const
Comparison: sorts by Optical Detector ID.
SDP(TrackID_t tid, float nPh, float e, float xpos, float ypos, float zpos)
Constructor: sets all data members.
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:276
std::vector< timePDclockSDP_t > timePDclockSDPs_t
Type of list of energy deposits for each timePDclock with signal.
std::pair< double, std::vector< sim::SDP > > timePDclockSDP_t
List of energy deposits at the same time (on this Optical Detector)
intermediate_table::const_iterator const_iterator
void Dump(Stream &&out, std::string indent="") const
Documentation at Dump(Stream&&, std::string, std::string) const.
timePDclockSDP_t::first_type storedTimePDclock_t
Type for timePDclock tick used in the internal representation.
Energy deposited on a readout Optical Detector by simulated tracks.
timePDclockSDPs_t timePDclockSDPs
list of energy deposits for each timePDclock with signal
int OpDetNum() const
Returns the readout Optical Detector this object describes.
int trackID
Geant4 supplied trackID.
TrackID_t trackID
Geant4 supplied track ID.
SDP::TrackID_t TrackID_t
Type of track ID (the value comes from Geant4)
void Dump(Stream &&out, std::string indent, std::string first_indent) const
Dumps the full content of the OpDetBacktrackerRecord into a stream.
float energyFrac
fraction of OpHit energy from the particle with this trackID
double timePDclock_t
Type for iTimePDclock tick used in the interface.
std::string indent(std::size_t const i)
Monte Carlo Simulation.
std::map< timePDclock_t, std::vector< sim::SDP > > fTimePDclockSDPs
Ionization photons from a Geant4 track.
float y
y position of ionization [cm]
int TrackID_t
Type of track ID (the value comes from Geant4)
TrackSDP(int id, float phF, float ph)
float numPhotons
number of photons at the optical detector for this track ID and time
float energy
energy deposited by ionization
SDP::TrackID_t TrackID_t
bool operator==(const OpDetBacktrackerRecord &other) const
Comparison: true if OpDetBacktrackerRecords have the same Optical Detector ID.
float energy
energy from the particle with this trackID [MeV]
Float_t e
Definition: plot.C:35
float z
z position of ionization [cm]
bool operator==(infinite_endcount_iterator< T > const &, count_iterator< T > const &)
Definition: counter.h:277
timePDclockSDPs_t const & timePDclockSDPsMap() const
Returns all the deposited energy information as stored.
bool operator<(const BeamGateInfo &lhs, const BeamGateInfo &rhs)
Definition: BeamGateInfo.h:40