Jpp  18.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPMTSimulator.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JPMTSIMULATOR__
2 #define __JDETECTOR__JPMTSIMULATOR__
3 
4 #include <vector>
5 #include <algorithm>
6 #include <limits>
7 
10 #include "JDetector/JTimeRange.hh"
11 #include "Jeep/JStatus.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace JDETECTOR {}
19 namespace JPP { using namespace JDETECTOR; }
20 
21 namespace JDETECTOR {
22 
23  using JEEP::JStatus;
24 
25 
26  /**
27  * Data structure for single photo-electron.
28  */
29  struct JPhotoElectron {
30  /**
31  * Default constructor.
32  */
34  t_ns(0.0)
35  {}
36 
37 
38  /**
39  * Constructor.
40  *
41  * \param __t_ns time [ns]
42  */
43  JPhotoElectron(const double __t_ns) :
44  t_ns(__t_ns)
45  {}
46 
47 
48  /**
49  * Get end marker.
50  *
51  * \return latest possible photo-electron
52  */
53  static inline JPhotoElectron getEndMarker()
54  {
55  return JPhotoElectron(std::numeric_limits<double>::max());
56  }
57 
58 
59  double t_ns; //!< time [ns]
60  };
61 
62 
63  /**
64  * Less than operator for photo-elecrons.
65  *
66  * \param first first photo-electron
67  * \param second second photo-electron
68  * \return true if first photo-electron earlier than second; else false
69  */
70  inline bool operator<(const JPhotoElectron& first, const JPhotoElectron& second)
71  {
72  return first.t_ns < second.t_ns;
73  }
74 
75 
76  /**
77  * Data structure for PMT analogue signal.
78  */
79  struct JPMTSignal {
80  /**
81  * Default constructor.
82  */
84  t_ns(0.0),
85  npe (0)
86  {}
87 
88 
89  /**
90  * Constructor.
91  *
92  * \param __t_ns time [ns]
93  * \param __npe number of photo-electrons
94  */
95  JPMTSignal(const double __t_ns,
96  const int __npe) :
97  t_ns(__t_ns),
98  npe (__npe)
99  {}
100 
101 
102  double t_ns; //!< time [ns]
103  int npe; //!< number of photo-electrons
104  };
105 
106 
107  /**
108  * Less than operator for PMT signals.
109  *
110  * \param first first PMT signal
111  * \param second second PMT signal
112  * \return true if first PMT signal earlier than second; else false
113  */
114  inline bool operator<(const JPMTSignal& first, const JPMTSignal& second)
115  {
116  return first.t_ns < second.t_ns;
117  }
118 
119 
120  /**
121  * Data structure for PMT digital pulse.
122  */
123  struct JPMTPulse {
124  /**
125  * Default constructor.
126  */
128  t_ns (0.0),
129  tot_ns(0.0)
130  {}
131 
132 
133  /**
134  * Constructor.
135  *
136  * \param __t_ns time [ns]
137  * \param __tot_ns time-over-threshold [ns]
138  */
139  JPMTPulse(const double __t_ns,
140  const double __tot_ns) :
141  t_ns (__t_ns),
142  tot_ns(__tot_ns)
143  {}
144 
145 
146  double t_ns; //!< time [ns]
147  double tot_ns; //!< time-over-threshold [ns]
148  };
149 
150 
151  /**
152  * Less than operator for PMT pulses.
153  *
154  * \param first first PMT pulse
155  * \param second second PMT pulse
156  * \return true if first PMT pulse earlier than second; else false
157  */
158  inline bool operator<(const JPMTPulse& first, const JPMTPulse& second)
159  {
160  return first.t_ns < second.t_ns;
161  }
162 
163 
164  /**
165  * Template data structure for PMT I/O.
166  */
167  template<class JElement_t>
168  class JPMTData :
169  public std::vector<JElement_t>
170  {
171  public:
172 
177 
178 
179  /**
180  * Default constructor.
181  */
182  JPMTData() :
183  std::vector<JElement_t>()
184  {}
185 
186 
187  /**
188  * Sort.
189  */
190  void sort()
191  {
192  std::sort(this->begin(), this->end());
193  }
194 
195 
196  /**
197  * Insert element whilst maintaining order.
198  *
199  * \param element element
200  */
201  void insert(const JElement_t& element)
202  {
203  iterator i = std::lower_bound(this->begin(), this->end(), element);
204 
206  }
207  };
208 
209 
210 
211  /**
212  * Data structure for PMT data corresponding to a detector module.
213  */
214  class JModuleData :
215  public std::vector< JPMTData<JPMTSignal> >
216  {
217  public:
218  /**
219  * Default constructor.
220  */
222  std::vector< JPMTData<JPMTSignal> >()
223  {}
224 
225 
226  /**
227  * Reset buffers.
228  *
229  * \param size number of buffers
230  */
231  void reset(size_t size)
232  {
233  this->resize(size);
234 
235  for (iterator i = this->begin(); i != this->end(); ++i) {
236  i->clear();
237  }
238  }
239  };
240 
241 
242  /**
243  * Interface for PMT simulation.
244  * The input buffer consists of a sorted array of PMT analogue signals JDETECTOR::JPMTSignal and
245  * the output of an array of PMT digital pulses JDETECTOR::JPMTPulse.
246  */
248  protected:
249  /**
250  * Default constructor.
251  */
253  {}
254 
255 
256  public:
257  /**
258  * Virtual destructor.
259  */
260  virtual ~JPMTSimulator()
261  {}
262 
263 
264  /**
265  * Process hits.
266  *
267  * \param id PMT identifier
268  * \param calibration PMT calibration
269  * \param status PMT status
270  * \param input PMT signals
271  * \param output PMT pulses
272  */
273  virtual void processHits(const JPMTIdentifier& id,
274  const JCalibration& calibration,
275  const JStatus& status,
276  const JPMTData<JPMTSignal>& input,
277  JPMTData<JPMTPulse>& output) const = 0;
278  };
279 
280 
281  /**
282  * Get time range (i.e.\ earlist and latest hit time) of PMT data.
283  *
284  * \param input PMT data
285  * \return time range
286  */
288  {
290 
291  for (JPMTData<JPMTSignal>::const_iterator hit = input.begin(); hit != input.end(); ++hit) {
292  range.include(hit->t_ns);
293  }
294 
295  return range;
296  }
297 
298 
299  /**
300  * Get time range (i.e.\ earlist and latest hit time) of module data.
301  *
302  * \param input module data
303  * \return time range
304  */
305  inline JTimeRange getTimeRange(const JModuleData& input)
306  {
308 
309  for (JModuleData::const_iterator frame = input.begin(); frame != input.end(); ++frame) {
310  for (JModuleData::value_type::const_iterator hit = frame->begin(); hit != frame->end(); ++hit) {
311  range.include(hit->t_ns);
312  }
313  }
314 
315  return range;
316  }
317 }
318 
319 #endif
void reset(size_t size)
Reset buffers.
Data structure for PMT analogue signal.
Data structure for PMT digital pulse.
Interface for PMT simulation.
virtual void processHits(const JPMTIdentifier &id, const JCalibration &calibration, const JStatus &status, const JPMTData< JPMTSignal > &input, JPMTData< JPMTPulse > &output) const =0
Process hits.
Data structure for PMT data corresponding to a detector module.
range_type & include(argument_type x)
Include given value to range.
Definition: JRange.hh:397
Time calibration (including definition of sign of time offset).
JPMTData()
Default constructor.
double t_ns
time [ns]
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition: JHead.hh:1799
Data structure for single photo-electron.
int npe
number of photo-electrons
JPMTSignal(const double __t_ns, const int __npe)
Constructor.
JPhotoElectron(const double __t_ns)
Constructor.
std::vector< JElement_t >::const_reverse_iterator const_reverse_iterator
JModuleData()
Default constructor.
Data structure for time calibration.
double tot_ns
time-over-threshold [ns]
JPhotoElectron()
Default constructor.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
std::vector< JElement_t >::iterator iterator
Auxiliary class for handling status.
Definition: JStatus.hh:37
JPMTSimulator()
Default constructor.
JPMTPulse()
Default constructor.
virtual ~JPMTSimulator()
Virtual destructor.
JPMTPulse(const double __t_ns, const double __tot_ns)
Constructor.
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
static JPhotoElectron getEndMarker()
Get end marker.
void insert(const JElement_t &element)
Insert element whilst maintaining order.
Template data structure for PMT I/O.
std::vector< JElement_t >::reverse_iterator reverse_iterator
JPMTSignal()
Default constructor.
double t_ns
time [ns]
static JRange< double, std::less< double > > DEFAULT_RANGE()
Default range.
Definition: JRange.hh:555
std::vector< JElement_t >::const_iterator const_iterator