Jpp - 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 "JDetector/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 
24  /**
25  * Data structure for single photo-electron.
26  */
27  struct JPhotoElectron {
28  /**
29  * Default constructor.
30  */
32  t_ns(0.0)
33  {}
34 
35 
36  /**
37  * Constructor.
38  *
39  * \param __t_ns time [ns]
40  */
41  JPhotoElectron(const double __t_ns) :
42  t_ns(__t_ns)
43  {}
44 
45 
46  /**
47  * Get end marker.
48  *
49  * \return latest possible photo-electron
50  */
51  static inline JPhotoElectron getEndMarker()
52  {
53  return JPhotoElectron(std::numeric_limits<double>::max());
54  }
55 
56 
57  double t_ns; //!< time [ns]
58  };
59 
60 
61  /**
62  * Less than operator for photo-elecrons.
63  *
64  * \param first first photo-electron
65  * \param second second photo-electron
66  * \return true if first photo-electron earlier than second; else false
67  */
68  inline bool operator<(const JPhotoElectron& first, const JPhotoElectron& second)
69  {
70  return first.t_ns < second.t_ns;
71  }
72 
73 
74  /**
75  * Data structure for PMT analogue signal.
76  */
77  struct JPMTSignal {
78  /**
79  * Default constructor.
80  */
82  t_ns(0.0),
83  npe (0)
84  {}
85 
86 
87  /**
88  * Constructor.
89  *
90  * \param __t_ns time [ns]
91  * \param __npe number of photo-electrons
92  */
93  JPMTSignal(const double __t_ns,
94  const int __npe) :
95  t_ns(__t_ns),
96  npe (__npe)
97  {}
98 
99 
100  double t_ns; //!< time [ns]
101  int npe; //!< number of photo-electrons
102  };
103 
104 
105  /**
106  * Less than operator for PMT signals.
107  *
108  * \param first first PMT signal
109  * \param second second PMT signal
110  * \return true if first PMT signal earlier than second; else false
111  */
112  inline bool operator<(const JPMTSignal& first, const JPMTSignal& second)
113  {
114  return first.t_ns < second.t_ns;
115  }
116 
117 
118  /**
119  * Data structure for PMT digital pulse.
120  */
121  struct JPMTPulse {
122  /**
123  * Default constructor.
124  */
126  t_ns (0.0),
127  tot_ns(0.0)
128  {}
129 
130 
131  /**
132  * Constructor.
133  *
134  * \param __t_ns time [ns]
135  * \param __tot_ns time-over-threshold [ns]
136  */
137  JPMTPulse(const double __t_ns,
138  const double __tot_ns) :
139  t_ns (__t_ns),
140  tot_ns(__tot_ns)
141  {}
142 
143 
144  double t_ns; //!< time [ns]
145  double tot_ns; //!< time-over-threshold [ns]
146  };
147 
148 
149  /**
150  * Less than operator for PMT pulses.
151  *
152  * \param first first PMT pulse
153  * \param second second PMT pulse
154  * \return true if first PMT pulse earlier than second; else false
155  */
156  inline bool operator<(const JPMTPulse& first, const JPMTPulse& second)
157  {
158  return first.t_ns < second.t_ns;
159  }
160 
161 
162  /**
163  * Template data structure for PMT I/O.
164  */
165  template<class JElement_t>
166  class JPMTData :
167  public std::vector<JElement_t>
168  {
169  public:
170 
175 
176 
177  /**
178  * Default constructor.
179  */
180  JPMTData() :
181  std::vector<JElement_t>()
182  {}
183 
184 
185  /**
186  * Sort.
187  */
188  void sort()
189  {
190  std::sort(this->begin(), this->end());
191  }
192 
193 
194  /**
195  * Insert element whilst maintaining order.
196  *
197  * \param element element
198  */
199  void insert(const JElement_t& element)
200  {
201  iterator i = std::lower_bound(this->begin(), this->end(), element);
202 
204  }
205  };
206 
207 
208 
209  /**
210  * Data structure for PMT data corresponding to a detector module.
211  */
212  class JModuleData :
213  public std::vector< JPMTData<JPMTSignal> >
214  {
215  public:
216  /**
217  * Default constructor.
218  */
220  std::vector< JPMTData<JPMTSignal> >()
221  {}
222 
223 
224  /**
225  * Reset buffers.
226  *
227  * \param size number of buffers
228  */
229  void reset(size_t size)
230  {
231  this->resize(size);
232 
233  for (iterator i = this->begin(); i != this->end(); ++i) {
234  i->clear();
235  }
236  }
237  };
238 
239 
240  /**
241  * Interface for PMT simulation.
242  * The input buffer consists of a sorted array of PMT analogue signals JDETECTOR::JPMTSignal and
243  * the output of an array of PMT digital pulses JDETECTOR::JPMTPulse.
244  */
246  protected:
247  /**
248  * Default constructor.
249  */
251  {}
252 
253 
254  public:
255  /**
256  * Virtual destructor.
257  */
258  virtual ~JPMTSimulator()
259  {}
260 
261 
262  /**
263  * Process hits.
264  *
265  * \param id PMT identifier
266  * \param calibration PMT calibration
267  * \param status PMT status
268  * \param input PMT signals
269  * \param output PMT pulses
270  */
271  virtual void processHits(const JPMTIdentifier& id,
272  const JCalibration& calibration,
273  const JStatus& status,
274  const JPMTData<JPMTSignal>& input,
275  JPMTData<JPMTPulse>& output) const = 0;
276  };
277 
278 
279  /**
280  * Get time range (i.e.\ earlist and latest hit time) of PMT data.
281  *
282  * \param input PMT data
283  * \return time range
284  */
286  {
288 
289  for (JPMTData<JPMTSignal>::const_iterator hit = input.begin(); hit != input.end(); ++hit) {
290  range.include(hit->t_ns);
291  }
292 
293  return range;
294  }
295 
296 
297  /**
298  * Get time range (i.e.\ earlist and latest hit time) of module data.
299  *
300  * \param input module data
301  * \return time range
302  */
303  inline JTimeRange getTimeRange(const JModuleData& input)
304  {
306 
307  for (JModuleData::const_iterator frame = input.begin(); frame != input.end(); ++frame) {
308  for (JModuleData::value_type::const_iterator hit = frame->begin(); hit != frame->end(); ++hit) {
309  range.include(hit->t_ns);
310  }
311  }
312 
313  return range;
314  }
315 }
316 
317 #endif
static const JRange< double, std::less< double > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:568
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.
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:1603
Data structure for single photo-electron.
int npe
number of photo-electrons
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [ns]).
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
Auxiliary class for controlling PMT status.
Definition: JStatus.hh:42
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
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]
std::vector< JElement_t >::const_iterator const_iterator