Jpp  debug
the software that should make you happy
JHitToolkit.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JHITTOOLKIT__
2 #define __JTRIGGER__JHITTOOLKIT__
3 
4 #include <limits>
5 
6 #include "JLang/JClass.hh"
8 #include "JTrigger/JHit.hh"
9 #include "JTrigger/JHitR0.hh"
10 #include "JTrigger/JCalibration.hh"
11 
12 
13 /**
14  * \file
15  *
16  * Tools for handling different hit types.
17  * \author mdejong
18  */
19 namespace JTRIGGER {}
20 namespace JPP { using namespace JTRIGGER; }
21 
22 namespace JTRIGGER {
23 
24  using KM3NETDAQ::JDAQHit;
25 
26 
27  /**
28  * Get calibrated time of DAQ hit.
29  *
30  * \param hit DAQ hit
31  * \param cal calibration
32  * \return time [ns]
33  */
34  inline double getTime(const JDAQHit& hit, const JCalibration& cal)
35  {
36  return getTime(hit.getT(), cal);
37  }
38 
39 
40  /**
41  * Get calibrated time-over-threshold of DAQ hit.
42  *
43  * \param hit DAQ hit
44  * \param cal calibration
45  * \return time-over-threshold [ns]
46  */
47  inline double getToT(const JDAQHit& hit, const JCalibration& cal)
48  {
49  return getToT(hit.getToT(), cal);
50  }
51 
52 
53  /**
54  * Template definition of hit toolkit.
55  *
56  * The specialised class should provide implementations for
57  * the methods and operators that are used by the trigger.
58  */
59  template<class JHit_t, bool isPrimitive = JLANG::JClass<JHit_t>::is_primitive>
60  struct JHitToolkit;
61 
62 
63  /**
64  * Template specialisation of hit toolkit for JHit class.
65  */
66  template<>
67  struct JHitToolkit<JHit, false>
68  {
69  /**
70  * Get toolkit.
71  *
72  * \return this hit toolkit
73  */
75  {
76  return *this;
77  }
78 
79 
80  /**
81  * Get time of hit.
82  *
83  * \param hit hit
84  * \return time of hit [ns]
85  */
86  static inline double getT(const JHit& hit)
87  {
88  return hit.getT();
89  }
90 
91 
92  /**
93  * Get time-over-threshold of hit.
94  *
95  * \param hit hit
96  * \return time-over-threshold of hit [ns]
97  */
98  static inline double getToT(const JHit& hit)
99  {
100  return hit.getToT();
101  }
102 
103 
104  /**
105  * Construct JHit.
106  *
107  * \param hit hit
108  * \return hit
109  */
110  static inline JHit getJHit(const JHit& hit)
111  {
112  return hit;
113  }
114 
115 
116  /**
117  * Construct hit.
118  *
119  * \param hit DAQ hit
120  * \param cal calibration
121  * \return hit
122  */
123  static inline JHit getHit(const JDAQHit& hit, const JCalibration& cal)
124  {
125  return JHit(JTRIGGER::getTime(hit, cal), JTRIGGER::getToT(hit, cal));
126  }
127 
128 
129  /**
130  * Get end marker.
131  *
132  * \return latest possible hit
133  */
134  static inline JHit getEndMarker()
135  {
136  return JHit(std::numeric_limits<double>::max());
137  }
138 
139 
140  /**
141  * Get time difference between two hits.
142  *
143  * \param first first hit
144  * \param second second hit
145  * \return time second hit - time first hit [ns]
146  */
147  static inline double getTimeDifference(const JHit& first, const JHit& second)
148  {
149  return getT(second) - getT(first);
150  }
151 
152 
153  /**
154  * Compare time of two hits.
155  *
156  * \param first first hit
157  * \param second second hit
158  * \return true if second hit later; else false
159  */
160  inline bool operator()(const JHit& first, const JHit& second) const
161  {
162  return getT(first) < getT(second);
163  }
164 
165 
166  /**
167  * Join two hits.
168  *
169  * \param first first hit
170  * \param second second hit
171  * \return joined hit
172  */
173  static inline JHit join(const JHit& first, const JHit& second)
174  {
175  JHit hit(first);
176 
177  hit.join(second);
178 
179  return hit;
180  }
181  };
182 
183 
184  /**
185  * Template specialisation of hit toolkit for JDAQHit class.
186  */
187  template<>
188  struct JHitToolkit<JDAQHit, false>
189  {
190  /**
191  * Get toolkit.
192  *
193  * \return this hit toolkit
194  */
196  {
197  return *this;
198  }
199 
200 
201  /**
202  * Get time of hit.
203  *
204  * \param hit hit
205  * \return time of hit [ns]
206  */
207  static inline double getT(const JDAQHit& hit)
208  {
209  return hit.getT();
210  }
211 
212 
213  /**
214  * Get time-over-threshold of hit.
215  *
216  * \param hit hit
217  * \return time-over-threshold of hit [ns]
218  */
219  static inline double getToT(const JDAQHit& hit)
220  {
221  return hit.getToT();
222  }
223 
224 
225  /**
226  * Construct JHit.
227  *
228  * \param hit hit
229  * \return hit
230  */
231  static inline JHit getJHit(const JDAQHit& hit)
232  {
233  return JHit(hit.getT(), hit.getToT());
234  }
235 
236 
237  /**
238  * Construct hit.
239  *
240  * \param hit DAQ hit
241  * \param cal calibration
242  * \return hit
243  */
244  static inline JDAQHit getHit(const JDAQHit& hit, const JCalibration& cal)
245  {
246  return hit;
247  }
248 
249 
250  /**
251  * Get end marker.
252  *
253  * \return latest possible hit
254  */
255  static inline JDAQHit getEndMarker()
256  {
257  return JDAQHit(0, std::numeric_limits<JDAQHit::JTDC_t>::max(), 0);
258  }
259 
260 
261  /**
262  * Get time difference between two hits.
263  *
264  * \param first first hit
265  * \param second second hit
266  * \return time second hit - time first hit [ns]
267  */
268  static inline double getTimeDifference(const JDAQHit& first, const JDAQHit& second)
269  {
270  return getT(second) - getT(first);
271  }
272 
273 
274  /**
275  * Compare time of two hits.
276  *
277  * \param first first hit
278  * \param second second hit
279  * \return true if second hit later; else false
280  */
281  inline bool operator()(const JDAQHit& first, const JDAQHit& second) const
282  {
283  return getT(first) < getT(second);
284  }
285 
286 
287  /**
288  * Join two hits.
289  *
290  * \param first first hit
291  * \param second second hit
292  * \return joined hit
293  */
294  static inline JHit join(const JHit& first, const JHit& second)
295  {
296  JHit hit(first);
297 
298  hit.join(second);
299 
300  return hit;
301  }
302  };
303 
304 
305  /**
306  * Template specialisation of hit toolkit for JHitR0 class.
307  */
308  template<>
309  struct JHitToolkit<JHitR0, false> :
310  public JHitToolkit<JHit, false>
311  {
312  /**
313  * Get toolkit.
314  *
315  * \return this hit toolkit
316  */
318  {
319  return *this;
320  }
321 
322 
323  /**
324  * Construct hit.
325  *
326  * \param hit DAQ hit
327  * \param cal calibration
328  * \return hit
329  */
330  static inline JHitR0 getHit(const JDAQHit& hit, const JCalibration& cal)
331  {
332  return JHitR0(hit.getPMT(), JHitToolkit<JHit, false>::getHit(hit, cal));
333  }
334 
335 
336  /**
337  * Get end marker.
338  *
339  * \return latest possible hit
340  */
341  static inline JHitR0 getEndMarker()
342  {
344  }
345 
346 
347  /**
348  * Join two hits.
349  *
350  * \param first first hit
351  * \param second second hit
352  * \return joined hit
353  */
354  static inline JHitR0 join(const JHitR0& first, const JHitR0& second)
355  {
356  JHitR0 hit(first);
357 
358  hit.join(second);
359 
360  return hit;
361  }
362  };
363 
364 
365  /**
366  * Template specialisation of hit toolkit for any primitive data type.
367  */
368  template<class JHit_t>
369  struct JHitToolkit<JHit_t, true>
370  {
371  /**
372  * Get toolkit.
373  *
374  * \return this hit toolkit
375  */
377  {
378  return *this;
379  }
380 
381 
382  /**
383  * Get time of hit.
384  *
385  * \param hit hit
386  * \return time of hit [ns]
387  */
388  static inline double getT(const JHit_t hit)
389  {
390  return hit;
391  }
392 
393 
394  /**
395  * Get time-over-threshold of hit.
396  *
397  * \param hit hit
398  * \return 0
399  */
400  static inline double getToT(const JHit_t& hit)
401  {
402  return 0.0;
403  }
404 
405 
406  /**
407  * Construct JHit.
408  *
409  * \param hit hit
410  * \return hit
411  */
412  static inline JHit getJHit(const JHit_t hit)
413  {
414  return JHit(getT(hit), getToT(hit));
415  }
416 
417 
418  /**
419  * Construct hit.
420  *
421  * \param hit DAQ hit
422  * \param cal calibration
423  * \return hit
424  */
425  static inline JHit_t getHit(const JDAQHit& hit, const JCalibration& cal)
426  {
427  return getTime(hit, cal);
428  }
429 
430 
431  /**
432  * Get end marker.
433  *
434  * \return latest possible hit
435  */
436  static inline JHit_t getEndMarker()
437  {
438  return std::numeric_limits<JHit_t>::max();
439  }
440 
441 
442  /**
443  * Get time difference between two hits.
444  *
445  * \param first first hit
446  * \param second second hit
447  * \return time second hit - time first hit [ns]
448  */
449  static inline JHit_t getTimeDifference(const JHit_t first, const JHit_t second)
450  {
451  return second - first;
452  }
453 
454 
455  /**
456  * Compare time of two hits.
457  *
458  * \param first first value [ns]
459  * \param second second value [ns]
460  * \return true if second hit later; else false
461  */
462  inline bool operator()(const JHit_t first, const JHit_t second) const
463  {
464  return first < second;
465  }
466 
467 
468  /**
469  * Join two hits.
470  *
471  * Note that this method returns the first hit as-is.
472  *
473  * \param first first hit
474  * \param second second hit
475  * \return joined hit
476  */
477  static inline JHit_t join(const JHit_t& first, const JHit_t& second)
478  {
479  return first;
480  }
481  };
482 }
483 
484 #endif
Basic data structure for L0 hit.
Basic data structure for time and time over threshold information of hit.
Data structure for time calibration.
Reduced data structure for L0 hit.
Definition: JHitR0.hh:27
Hit data structure.
void join(const JHit &hit)
Join hit.
double getToT() const
Get calibrated time over threshold of hit.
double getT() const
Get calibrated time of hit.
Hit data structure.
Definition: JDAQHit.hh:35
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:75
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:86
JTOT_t getToT() const
Get time-over-threshold.
Definition: JDAQHit.hh:97
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for triggering.
double getTime(const JDAQHit &hit, const JCalibration &cal)
Get calibrated time of DAQ hit.
Definition: JHitToolkit.hh:34
double getToT(const JDAQHit &hit, const JCalibration &cal)
Get calibrated time-over-threshold of DAQ hit.
Definition: JHitToolkit.hh:47
Auxiliary class to set-up Hit.
Definition: JSirene.hh:58
Template specialisation of hit toolkit for JDAQHit class.
Definition: JHitToolkit.hh:189
static JDAQHit getHit(const JDAQHit &hit, const JCalibration &cal)
Construct hit.
Definition: JHitToolkit.hh:244
static double getT(const JDAQHit &hit)
Get time of hit.
Definition: JHitToolkit.hh:207
bool operator()(const JDAQHit &first, const JDAQHit &second) const
Compare time of two hits.
Definition: JHitToolkit.hh:281
static double getToT(const JDAQHit &hit)
Get time-over-threshold of hit.
Definition: JHitToolkit.hh:219
static JHit getJHit(const JDAQHit &hit)
Construct JHit.
Definition: JHitToolkit.hh:231
static JHit join(const JHit &first, const JHit &second)
Join two hits.
Definition: JHitToolkit.hh:294
const JHitToolkit< JDAQHit, false > & getToolkit() const
Get toolkit.
Definition: JHitToolkit.hh:195
static JDAQHit getEndMarker()
Get end marker.
Definition: JHitToolkit.hh:255
static double getTimeDifference(const JDAQHit &first, const JDAQHit &second)
Get time difference between two hits.
Definition: JHitToolkit.hh:268
const JHitToolkit< JHit, false > & getToolkit() const
Get toolkit.
Definition: JHitToolkit.hh:317
static JHitR0 getEndMarker()
Get end marker.
Definition: JHitToolkit.hh:341
static JHitR0 join(const JHitR0 &first, const JHitR0 &second)
Join two hits.
Definition: JHitToolkit.hh:354
static JHitR0 getHit(const JDAQHit &hit, const JCalibration &cal)
Construct hit.
Definition: JHitToolkit.hh:330
Template specialisation of hit toolkit for JHit class.
Definition: JHitToolkit.hh:68
static JHit getJHit(const JHit &hit)
Construct JHit.
Definition: JHitToolkit.hh:110
bool operator()(const JHit &first, const JHit &second) const
Compare time of two hits.
Definition: JHitToolkit.hh:160
static double getToT(const JHit &hit)
Get time-over-threshold of hit.
Definition: JHitToolkit.hh:98
static JHit getEndMarker()
Get end marker.
Definition: JHitToolkit.hh:134
static JHit getHit(const JDAQHit &hit, const JCalibration &cal)
Construct hit.
Definition: JHitToolkit.hh:123
static JHit join(const JHit &first, const JHit &second)
Join two hits.
Definition: JHitToolkit.hh:173
static double getT(const JHit &hit)
Get time of hit.
Definition: JHitToolkit.hh:86
static double getTimeDifference(const JHit &first, const JHit &second)
Get time difference between two hits.
Definition: JHitToolkit.hh:147
const JHitToolkit< JHit, false > & getToolkit() const
Get toolkit.
Definition: JHitToolkit.hh:74
Template specialisation of hit toolkit for any primitive data type.
Definition: JHitToolkit.hh:370
static JHit getJHit(const JHit_t hit)
Construct JHit.
Definition: JHitToolkit.hh:412
bool operator()(const JHit_t first, const JHit_t second) const
Compare time of two hits.
Definition: JHitToolkit.hh:462
static JHit_t getTimeDifference(const JHit_t first, const JHit_t second)
Get time difference between two hits.
Definition: JHitToolkit.hh:449
const JHitToolkit< JHit_t, true > & getToolkit() const
Get toolkit.
Definition: JHitToolkit.hh:376
static JHit_t getEndMarker()
Get end marker.
Definition: JHitToolkit.hh:436
static JHit_t getHit(const JDAQHit &hit, const JCalibration &cal)
Construct hit.
Definition: JHitToolkit.hh:425
static double getToT(const JHit_t &hit)
Get time-over-threshold of hit.
Definition: JHitToolkit.hh:400
static double getT(const JHit_t hit)
Get time of hit.
Definition: JHitToolkit.hh:388
static JHit_t join(const JHit_t &first, const JHit_t &second)
Join two hits.
Definition: JHitToolkit.hh:477
Template definition of hit toolkit.
Definition: JHitToolkit.hh:60