SimPhotons.h
Go to the documentation of this file.
1 /**
2  * @file lardataobj/Simulation/SimPhotons.h
3  * @brief Simulation objects for optical detectors.
4  * @author Ben Jones
5  * @date 06/04/2010
6  * @see `lardataobj/Simulation/SimPhotons.cxx`
7  *
8  * This file contains the definitions of the classes which are stored in the
9  * event representing scintillation photons detected by the optical detectors.
10  *
11  * A scintillation photon collection (`sim::SimPhotons`) stores data for each
12  * photon which steps inside the optical detector volume.
13  * Currently the quantities stored are position, time, 4-momentum
14  * and the ID of the GEANT4 track emitting it.
15  * A `sim::SimPhotonsCollection` is a set of `sim::SimPhotonss`, one per
16  * optical detector in the collection.
17  *
18  * The `sim::SimPhotons` is filled in by the `larg4::OpFastScintillation` class
19  * in `LegacyLArG4` module and will be used to generate the optical detector
20  * response later in the simulation chain.
21  *
22  * `sim::OnePhoton`, `sim::SimPhotons` and `sim::SimPhotonsCollection` are all
23  * persistent under ROOT I/O.
24  *
25  * The current implementation resembles that of an C++ STL container in
26  * some respects but needs more work before it is polished product.
27  */
28 
29 
30 #ifndef LARDATAOBJ_SIMULATION_SIMPHOTONS_H
31 #define LARDATAOBJ_SIMULATION_SIMPHOTONS_H
32 
33 
34 // LArSoft libraries
37 
38 // C/C++ standard libraries
39 #include <map>
40 #include <vector>
41 #include <string>
42 #include <limits> // std::numeric_limits<>
43 
44 
45 // -----------------------------------------------------------------------------
46 // forward declarations
47 namespace sim {
48  struct OnePhoton;
49  class SimPhotons;
50  class SimPhotonsLite;
51  class SimPhotonsCollection;
52 
53  /// `a` is smaller than `b` if has earlier `Time`, or lower `MotherTrackID`.
54  bool operator< (OnePhoton const&, OnePhoton const&);
55 
56 } // namespace sim
57 
58 
59 // -----------------------------------------------------------------------------
60 /**
61  * @brief All information of a photon entering the sensitive optical detector
62  * volume.
63  */
65 
66  /// Scintillation position in world coordinates [cm]
68 
69  /**
70  * @brief Where photon enters the optical detector in local coordinates [cm]
71  *
72  * The coordinates are in the local reference of the sensitive optical
73  * detector, in centimeters.
74  */
76 
77  /// Arrival time to the detector in
78  /// @ref DetectorClocksGeant4Time "simulation time scale" [ns]
80 
81  /// Scintillation photon energy [GeV]
82  float Energy { 0.0 };
83 
84  /// ID of the GEANT4 track causing the scintillation.
86 
87  /// Whether the photon reaches the sensitive detector.
88  bool SetInSD { true };
89 
90 }; // sim::OnePhoton
91 
92 
93 // -----------------------------------------------------------------------------
94 /**
95  * @brief Compact representation of photons on a channel.
96  * @see `sim::SimPhotons`
97  *
98  * Compared to `sim::SimPhotons`, this object contains only the _total count_
99  * of photon arriving at a certain time on the channel. The time is
100  * discretized in ticks.
101  *
102  */
104  public:
105 
106  /// Default constructor (do not use! it's for ROOT only).
107  SimPhotonsLite() = default;
108 
109  /// Constructor: associated to optical detector channel `chan`, and empty.
110  SimPhotonsLite(int chan)
111  : OpChannel(chan)
112  {}
113 
114  int OpChannel; ///< Optical detector channel associated to this data.
115 
116  /// Number of photons detected at each given time: time tick -> photons.
117  std::map<int, int> DetectedPhotons;
118 
119  /// Add all photons from `rhs` to this ones, at their original time.
121 
122  /// Creates a new `sim::SimPhotonsLite` with all photons from `rhs` and
123  /// this object.
124  SimPhotonsLite operator+(const SimPhotonsLite &rhs) const;
125 
126  /// Returns whether `other` is on the same channel (`OpChannel`) as this.
127  bool operator== (const SimPhotonsLite &other) const;
128 
129 }; // sim::SimPhotonsLite
130 
131 
132 // -----------------------------------------------------------------------------
133 /**
134  * @brief Collection of photons which recorded on one channel.
135  */
136 class sim::SimPhotons: public std::vector<sim::OnePhoton> {
137 
138 public:
139 
140  int fOpChannel; ///< Optical detector channel associated to this data.
141 
142 
143  // --- BEGIN -- Vector types -------------------------------------------------
144  /// @name Vector types
145  /// @{
146 
147  typedef std::vector<OnePhoton> list_type;
148  typedef list_type::value_type value_type;
151  typedef list_type::reverse_iterator reverse_iterator;
152  typedef list_type::const_reverse_iterator const_reverse_iterator;
153  typedef list_type::size_type size_type;
154  typedef list_type::difference_type difference_type;
155 
156  /// @}
157  // --- END -- Vector types ---------------------------------------------------
158 
159  /// Default constructor (do not use! it's for ROOT only).
160  SimPhotons() = default;
161 
162  /// Constructor: associated to optical detector channel `chan`, and empty.
163  SimPhotons(int chan): fOpChannel(chan) {}
164 
165 
166  /// Returns the optical channel number this object is associated to.
167  int OpChannel() const;
168 
169  /// Sets the optical detector channel number this object is associated to.
170  void SetChannel(int ch);
171 
172 
173  /// Add all photons from `rhs` to this ones; no sorting is applied.
174  SimPhotons& operator+=(const SimPhotons &rhs);
175 
176  /// Creates a new `sim::SimPhotons` with all photons from `rhs` and
177  /// this object.
178  SimPhotons operator+(const SimPhotons &rhs) const;
179 
180  /// Returns whether `other` is on the same channel (`OpChannel`) as this.
181  bool operator== (const SimPhotons &other) const;
182 
183 }; // sim::SimPhotons
184 
185 
186 // -----------------------------------------------------------------------------
187 /**
188  * @brief Collection of `sim::SimPhotons`, indexed by channel number.
189  *
190  * The collection owns the photon data.
191  */
192 class sim::SimPhotonsCollection : public std::map<int, sim::SimPhotons> {
193 
194  std::string fTheSDName; ///< Sensitive detector name.
195 
196 public:
197 
198  // --- BEGIN -- Vector types -------------------------------------------------
199  /// @name Vector types
200  /// @{
201  typedef std::map<int,SimPhotons> list_type;
202  typedef list_type::key_type key_type;
203  typedef list_type::mapped_type mapped_type;
204  typedef list_type::value_type value_type;
207  typedef list_type::reverse_iterator reverse_iterator;
208  typedef list_type::const_reverse_iterator const_reverse_iterator;
209  typedef list_type::size_type size_type;
210  typedef list_type::difference_type difference_type;
211  typedef list_type::key_compare key_compare;
212  typedef list_type::allocator_type allocator_type;
213 
214  /// @}
215  // --- END -- Vector types ---------------------------------------------------
216 
217  /// Constructor: an empty collection and no sensitive detector name.
218  SimPhotonsCollection() = default;
219 
220  /// Returns the name of the sensitive detector for this collection.
221  std::string const& GetSDName() const;
222 
223  /// Sets the name of the sensitive detector for this collection.
224  void SetSDName(std::string const& TheSDName);
225 
226 }; // sim::SimPhotonsCollection
227 
228 
229 // =============================================================================
230 // === Inline implementations
231 // =============================================================================
232 // -----------------------------------------------------------------------------
233 // --- sim::OnePhoton
234 // -----------------------------------------------------------------------------
235 inline bool sim::operator< (OnePhoton const& a, OnePhoton const& b) {
236  if (a.Time < b.Time) return true;
237  if (a.Time > b.Time) return false;
238 
239  return (a.MotherTrackID < b.MotherTrackID);
240 } // sim::operator< (OnePhoton const&, OnePhoton const&)
241 
242 
243 // -----------------------------------------------------------------------------
244 // --- sim::SimPhotonsLite
245 // -----------------------------------------------------------------------------
246 inline bool sim::SimPhotonsLite::operator==
247  (const sim::SimPhotonsLite& other) const
248  { return OpChannel == other.OpChannel; }
249 
250 // -----------------------------------------------------------------------------
251 // --- sim::SimPhotons
252 // -----------------------------------------------------------------------------
253 
254 inline int sim::SimPhotons::OpChannel() const { return fOpChannel; }
255 
256 inline void sim::SimPhotons::SetChannel(int ch) { fOpChannel = ch; }
257 
259  { return OpChannel() == other.OpChannel(); }
260 
261 // -----------------------------------------------------------------------------
262 // --- sim::SimPhotonsCollection
263 // -----------------------------------------------------------------------------
264 
266  { return fTheSDName; }
267 
269  { fTheSDName = TheSDName; }
270 
271 // -----------------------------------------------------------------------------
272 
273 
274 #endif // LARDATAOBJ_SIMULATION_SIMPHOTONS_H
list_type::allocator_type allocator_type
Definition: SimPhotons.h:212
std::map< int, SimPhotons > list_type
Definition: SimPhotons.h:201
void SetSDName(std::string const &TheSDName)
Sets the name of the sensitive detector for this collection.
Definition: SimPhotons.h:268
intermediate_table::iterator iterator
Index OpChannel(Index detNum, Index channel)
bool operator==(const SimPhotons &other) const
Returns whether other is on the same channel (OpChannel) as this.
Definition: SimPhotons.h:258
int OpChannel() const
Returns the optical channel number this object is associated to.
Definition: SimPhotons.h:254
list_type::difference_type difference_type
Definition: SimPhotons.h:210
std::vector< OnePhoton > list_type
Definition: SimPhotons.h:147
DoubleProduct & operator+=(DoubleProduct &left, DoubleProduct const &right)
Definition: ToyProducts.h:103
list_type::size_type size_type
Definition: SimPhotons.h:209
std::string string
Definition: nybbler.cc:12
list_type::size_type size_type
Definition: SimPhotons.h:153
All information of a photon entering the sensitive optical detector volume.
Definition: SimPhotons.h:64
struct vector vector
list_type::difference_type difference_type
Definition: SimPhotons.h:154
intermediate_table::const_iterator const_iterator
int fOpChannel
Optical detector channel associated to this data.
Definition: SimPhotons.h:140
list_type::key_compare key_compare
Definition: SimPhotons.h:211
SimPhotons(int chan)
Constructor: associated to optical detector channel chan, and empty.
Definition: SimPhotons.h:163
list_type::key_type key_type
Definition: SimPhotons.h:202
geo::Point_t InitialPosition
Scintillation position in world coordinates [cm].
Definition: SimPhotons.h:67
list_type::reverse_iterator reverse_iterator
Definition: SimPhotons.h:151
std::map< int, int > DetectedPhotons
Number of photons detected at each given time: time tick -> photons.
Definition: SimPhotons.h:117
void SetChannel(int ch)
Sets the optical detector channel number this object is associated to.
Definition: SimPhotons.h:256
Definitions of vector data types for optical detectors.
list_type::const_reverse_iterator const_reverse_iterator
Definition: SimPhotons.h:208
std::string const & GetSDName() const
Returns the name of the sensitive detector for this collection.
Definition: SimPhotons.h:265
const double a
list_type::const_reverse_iterator const_reverse_iterator
Definition: SimPhotons.h:152
int OpChannel
Optical detector channel associated to this data.
Definition: SimPhotons.h:114
list_type::iterator iterator
Definition: SimPhotons.h:149
SimPhotonsLite(int chan)
Constructor: associated to optical detector channel chan, and empty.
Definition: SimPhotons.h:110
list_type::iterator iterator
Definition: SimPhotons.h:205
Code to link reconstructed objects back to the MC truth information.
list_type::mapped_type mapped_type
Definition: SimPhotons.h:203
list_type::value_type value_type
Definition: SimPhotons.h:148
list_type::reverse_iterator reverse_iterator
Definition: SimPhotons.h:207
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:184
Collection of photons which recorded on one channel.
Definition: SimPhotons.h:136
Compact representation of photons on a channel.
Definition: SimPhotons.h:103
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
DoubleProduct operator+(DoubleProduct const &left, DoubleProduct const right)
Definition: ToyProducts.h:97
bool SetInSD
Whether the photon reaches the sensitive detector.
Definition: SimPhotons.h:88
list_type::const_iterator const_iterator
Definition: SimPhotons.h:206
list_type::value_type value_type
Definition: SimPhotons.h:204
geo::OpticalPoint_t FinalLocalPosition
Where photon enters the optical detector in local coordinates [cm].
Definition: SimPhotons.h:75
static bool * b
Definition: config.cpp:1043
list_type::const_iterator const_iterator
Definition: SimPhotons.h:150
Definitions of geometry vector data types.
OpticalPoint3DBase_t< double > OpticalPoint_t
Type of optical 3D point with representation in double precision.
std::string fTheSDName
Sensitive detector name.
Definition: SimPhotons.h:194
float Energy
Scintillation photon energy [GeV].
Definition: SimPhotons.h:82
Collection of sim::SimPhotons, indexed by channel number.
Definition: SimPhotons.h:192
bool operator<(const BeamGateInfo &lhs, const BeamGateInfo &rhs)
Definition: BeamGateInfo.h:45
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
int MotherTrackID
ID of the GEANT4 track causing the scintillation.
Definition: SimPhotons.h:85