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