Jpp
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 JHit class.
186  */
187  template<>
188  struct JHitToolkit<JHitR0, false> :
189  public JHitToolkit<JHit, false>
190  {
191  /**
192  * Get toolkit.
193  *
194  * \return this hit toolkit
195  */
197  {
198  return *this;
199  }
200 
201 
202  /**
203  * Construct hit.
204  *
205  * \param hit DAQ hit
206  * \param cal calibration
207  * \return hit
208  */
209  static inline JHitR0 getHit(const JDAQHit& hit, const JCalibration& cal)
210  {
211  return JHitR0(hit.getPMT(), JHitToolkit<JHit, false>::getHit(hit, cal));
212  }
213 
214 
215  /**
216  * Get end marker.
217  *
218  * \return latest possible hit
219  */
220  static inline JHitR0 getEndMarker()
221  {
223  }
224 
225 
226  /**
227  * Join two hits.
228  *
229  * \param first first hit
230  * \param second second hit
231  * \return joined hit
232  */
233  static inline JHitR0 join(const JHitR0& first, const JHitR0& second)
234  {
235  JHitR0 hit(first);
236 
237  hit.join(second);
238 
239  return hit;
240  }
241  };
242 
243 
244  /**
245  * Template specialisation of hit toolkit for any primitive data type.
246  */
247  template<class JHit_t>
248  struct JHitToolkit<JHit_t, true>
249  {
250  /**
251  * Get toolkit.
252  *
253  * \return this hit toolkit
254  */
256  {
257  return *this;
258  }
259 
260 
261  /**
262  * Get time of hit.
263  *
264  * \param hit hit
265  * \return time of hit [ns]
266  */
267  static inline double getT(const JHit_t hit)
268  {
269  return hit;
270  }
271 
272 
273  /**
274  * Get time-over-threshold of hit.
275  *
276  * \param hit hit
277  * \return 0
278  */
279  static inline double getToT(const JHit_t& hit)
280  {
281  return 0.0;
282  }
283 
284 
285  /**
286  * Construct JHit.
287  *
288  * \param hit hit
289  * \return hit
290  */
291  static inline JHit getJHit(const JHit_t hit)
292  {
293  return JHit(getT(hit), getToT(hit));
294  }
295 
296 
297  /**
298  * Construct hit.
299  *
300  * \param hit DAQ hit
301  * \param cal calibration
302  * \return hit
303  */
304  static inline JHit_t getHit(const JDAQHit& hit, const JCalibration& cal)
305  {
306  return getTime(hit, cal);
307  }
308 
309 
310  /**
311  * Get end marker.
312  *
313  * \return latest possible hit
314  */
315  static inline JHit_t getEndMarker()
316  {
317  return std::numeric_limits<JHit_t>::max();
318  }
319 
320 
321  /**
322  * Get time difference between two hits.
323  *
324  * \param first first hit
325  * \param second second hit
326  * \return time second hit - time first hit [ns]
327  */
328  static inline JHit_t getTimeDifference(const JHit_t first, const JHit_t second)
329  {
330  return second - first;
331  }
332 
333 
334  /**
335  * Compare time of two hits.
336  *
337  * \param first first value [ns]
338  * \param second second value [ns]
339  * \return true if second hit later; else false
340  */
341  inline bool operator()(const JHit_t first, const JHit_t second) const
342  {
343  return first < second;
344  }
345 
346 
347  /**
348  * Join two hits.
349  *
350  * Note that this method returns the first hit as-is.
351  *
352  * \param first first hit
353  * \param second second hit
354  * \return joined hit
355  */
356  static inline JHit_t join(const JHit_t& first, const JHit_t& second)
357  {
358  return first;
359  }
360  };
361 }
362 
363 #endif
JTRIGGER::JHitToolkit< JHit, false >::getEndMarker
static JHit getEndMarker()
Get end marker.
Definition: JHitToolkit.hh:134
JTRIGGER::JHitToolkit
Template definition of hit toolkit.
Definition: JHitToolkit.hh:60
JTRIGGER::JHitToolkit< JHitR0, false >::getHit
static JHitR0 getHit(const JDAQHit &hit, const JCalibration &cal)
Construct hit.
Definition: JHitToolkit.hh:209
JTRIGGER::JHitToolkit< JHit_t, true >::getToolkit
const JHitToolkit< JHit_t, true > & getToolkit() const
Get toolkit.
Definition: JHitToolkit.hh:255
JTRIGGER::JHitToolkit< JHit_t, true >::getHit
static JHit_t getHit(const JDAQHit &hit, const JCalibration &cal)
Construct hit.
Definition: JHitToolkit.hh:304
JTRIGGER::getTime
double getTime(const JDAQHit &hit, const JCalibration &cal)
Get calibrated time of DAQ hit.
Definition: JHitToolkit.hh:34
JAANET::JHit_t
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
JTRIGGER::JHitToolkit< JHit_t, true >
Template specialisation of hit toolkit for any primitive data type.
Definition: JHitToolkit.hh:248
JTRIGGER::JHitToolkit< JHit, false >::getT
static double getT(const JHit &hit)
Get time of hit.
Definition: JHitToolkit.hh:86
JTRIGGER::JHitToolkit< JHit, false >
Template specialisation of hit toolkit for JHit class.
Definition: JHitToolkit.hh:67
KM3NETDAQ::JDAQHit::getPMT
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:75
JAANET::getHit
JHitL0 getHit(const Hit &hit)
Get transformation.
Definition: JAAnetToolkit.hh:292
JTRIGGER::JHitToolkit< JHit_t, true >::getT
static double getT(const JHit_t hit)
Get time of hit.
Definition: JHitToolkit.hh:267
JTRIGGER::JHitToolkit< JHit, false >::join
static JHit join(const JHit &first, const JHit &second)
Join two hits.
Definition: JHitToolkit.hh:173
JTRIGGER::JHitToolkit< JHit_t, true >::getEndMarker
static JHit_t getEndMarker()
Get end marker.
Definition: JHitToolkit.hh:315
JDETECTOR::JCalibration
Data structure for PMT calibration.
Definition: JDetector/JCalibration.hh:35
JTRIGGER::JHitToolkit< JHit, false >::getToolkit
const JHitToolkit< JHit, false > & getToolkit() const
Get toolkit.
Definition: JHitToolkit.hh:74
JTRIGGER::JHitToolkit< JHitR0, false >::getToolkit
const JHitToolkit< JHit, false > & getToolkit() const
Get toolkit.
Definition: JHitToolkit.hh:196
JTRIGGER::JHit::getT
double getT() const
Get calibrated time of hit.
Definition: JHit.hh:143
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JTRIGGER::JHitToolkit< JHit_t, true >::operator()
bool operator()(const JHit_t first, const JHit_t second) const
Compare time of two hits.
Definition: JHitToolkit.hh:341
JTRIGGER::JHitToolkit< JHitR0, false >::join
static JHitR0 join(const JHitR0 &first, const JHitR0 &second)
Join two hits.
Definition: JHitToolkit.hh:233
JTRIGGER::JHitToolkit< JHit_t, true >::join
static JHit_t join(const JHit_t &first, const JHit_t &second)
Join two hits.
Definition: JHitToolkit.hh:356
JTRIGGER::JHitR0
Reduced data structure for L0 hit.
Definition: JHitR0.hh:25
KM3NETDAQ::JDAQHit::getT
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:86
JHit.hh
JTRIGGER::JHitToolkit< JHit, false >::getToT
static double getToT(const JHit &hit)
Get time-over-threshold of hit.
Definition: JHitToolkit.hh:98
KM3NETDAQ::JDAQHit::getToT
JTOT_t getToT() const
Get time-over-threshold.
Definition: JDAQHit.hh:97
JCalibration.hh
JTRIGGER::JHitToolkit< JHit, false >::getHit
static JHit getHit(const JDAQHit &hit, const JCalibration &cal)
Construct hit.
Definition: JHitToolkit.hh:123
JTRIGGER::JHit
Hit data structure.
Definition: JHit.hh:22
JHitR0.hh
JClass.hh
KM3NETDAQ::JDAQHit
Hit data structure.
Definition: JDAQHit.hh:34
JTRIGGER::JHitToolkit< JHit, false >::getJHit
static JHit getJHit(const JHit &hit)
Construct JHit.
Definition: JHitToolkit.hh:110
JTRIGGER::JHitToolkit< JHit, false >::getTimeDifference
static double getTimeDifference(const JHit &first, const JHit &second)
Get time difference between two hits.
Definition: JHitToolkit.hh:147
JDAQHit.hh
JTRIGGER
Checksum.
Definition: JSupport/JSupport.hh:35
JTRIGGER::JHitToolkit< JHit_t, true >::getTimeDifference
static JHit_t getTimeDifference(const JHit_t first, const JHit_t second)
Get time difference between two hits.
Definition: JHitToolkit.hh:328
JTRIGGER::JHitToolkit< JHit_t, true >::getJHit
static JHit getJHit(const JHit_t hit)
Construct JHit.
Definition: JHitToolkit.hh:291
JTRIGGER::JHitToolkit< JHit, false >::operator()
bool operator()(const JHit &first, const JHit &second) const
Compare time of two hits.
Definition: JHitToolkit.hh:160
JTRIGGER::getToT
double getToT(const JDAQHit &hit, const JCalibration &cal)
Get calibrated time-over-threshold of DAQ hit.
Definition: JHitToolkit.hh:47
JTRIGGER::JHitToolkit< JHitR0, false >::getEndMarker
static JHitR0 getEndMarker()
Get end marker.
Definition: JHitToolkit.hh:220
JTRIGGER::JHit::join
void join(const JHit &hit)
Join hit.
Definition: JHit.hh:198
JTRIGGER::JHit::getToT
double getToT() const
Get calibrated time over threshold of hit.
Definition: JHit.hh:157
JTRIGGER::JHitToolkit< JHit_t, true >::getToT
static double getToT(const JHit_t &hit)
Get time-over-threshold of hit.
Definition: JHitToolkit.hh:279