Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
7 #include "JDAQ/JDAQHit.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 value [ns]
157  * \param second second value [ns]
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  /**
168  * Template specialisation of hit toolkit for JHit class.
169  */
170  template<>
171  struct JHitToolkit<JHitR0, false> :
172  public JHitToolkit<JHit, false>
173  {
174  /**
175  * Get toolkit.
176  *
177  * \return this hit toolkit
178  */
180  {
181  return *this;
182  }
183 
184 
185  /**
186  * Construct hit.
187  *
188  * \param hit DAQ hit
189  * \param cal calibration
190  * \return hit
191  */
192  static inline JHitR0 getHit(const JDAQHit& hit, const JCalibration& cal)
193  {
194  return JHitR0(hit.getPMT(), JHitToolkit<JHit, false>::getHit(hit, cal));
195  }
196 
197 
198  /**
199  * Get end marker.
200  *
201  * \return latest possible hit
202  */
203  static inline JHitR0 getEndMarker()
204  {
206  }
207  };
208 
209 
210  /**
211  * Template specialisation of hit toolkit for any primitive data type.
212  */
213  template<class JHit_t>
214  struct JHitToolkit<JHit_t, true>
215  {
216  /**
217  * Get toolkit.
218  *
219  * \return this hit toolkit
220  */
222  {
223  return *this;
224  }
225 
226 
227  /**
228  * Get time of hit.
229  *
230  * \param hit hit
231  * \return time of hit [ns]
232  */
233  static inline double getT(const JHit_t hit)
234  {
235  return hit;
236  }
237 
238 
239  /**
240  * Get time-over-threshold of hit.
241  *
242  * \param hit hit
243  * \return 0
244  */
245  static inline double getToT(const JHit_t& hit)
246  {
247  return 0.0;
248  }
249 
250 
251  /**
252  * Construct JHit.
253  *
254  * \param hit hit
255  * \return hit
256  */
257  static inline JHit getJHit(const JHit_t hit)
258  {
259  return JHit(getT(hit), getToT(hit));
260  }
261 
262 
263  /**
264  * Construct hit.
265  *
266  * \param hit DAQ hit
267  * \param cal calibration
268  * \return hit
269  */
270  static inline JHit_t getHit(const JDAQHit& hit, const JCalibration& cal)
271  {
272  return getTime(hit, cal);
273  }
274 
275 
276  /**
277  * Get end marker.
278  *
279  * \return latest possible hit
280  */
281  static inline JHit_t getEndMarker()
282  {
283  return std::numeric_limits<JHit_t>::max();
284  }
285 
286 
287  /**
288  * Get time difference between two hits.
289  *
290  * \param first first hit
291  * \param second second hit
292  * \return time second hit - time first hit [ns]
293  */
294  static inline JHit_t getTimeDifference(const JHit_t first, const JHit_t second)
295  {
296  return second - first;
297  }
298 
299 
300  /**
301  * Compare time of two hits.
302  *
303  * \param first first value [ns]
304  * \param second second value [ns]
305  * \return true if second hit later; else false
306  */
307  inline bool operator()(const JHit_t first, const JHit_t second) const
308  {
309  return first < second;
310  }
311  };
312 }
313 
314 #endif
double getT() const
Get calibrated time of hit.
Definition: JHit.hh:143
bool operator()(const JHit_t first, const JHit_t second) const
Compare time of two hits.
Definition: JHitToolkit.hh:307
static JHit getHit(const JDAQHit &hit, const JCalibration &cal)
Construct hit.
Definition: JHitToolkit.hh:123
static JHitR0 getHit(const JDAQHit &hit, const JCalibration &cal)
Construct hit.
Definition: JHitToolkit.hh:192
Basic data structure for L0 hit.
bool operator()(const JHit &first, const JHit &second) const
Compare time of two hits.
Definition: JHitToolkit.hh:160
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:214
Hit data structure.
Definition: JHit.hh:22
static double getTimeDifference(const JHit &first, const JHit &second)
Get time difference between two hits.
Definition: JHitToolkit.hh:147
Data structure for PMT calibration.
double getTime(const Hit &hit)
Get true time of hit.
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:85
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:74
static JHit getEndMarker()
Get end marker.
Definition: JHitToolkit.hh:134
static JHitR0 getEndMarker()
Get end marker.
Definition: JHitToolkit.hh:203
static JHit_t getHit(const JDAQHit &hit, const JCalibration &cal)
Construct hit.
Definition: JHitToolkit.hh:270
Basic data structure for time and time over threshold information of hit.
JTOT_t getToT() const
Get time-over-threshold.
Definition: JDAQHit.hh:96
double getToT(const T &tot, const JCalibration &cal)
Get calibrated time-over-threshold of hit.
double getToT() const
Get calibrated time over threshold of hit.
Definition: JHit.hh:157
Reduced data structure for L0 hit.
Definition: JHitR0.hh:25
Hit data structure.
Definition: JDAQHit.hh:36
static double getT(const JHit_t hit)
Get time of hit.
Definition: JHitToolkit.hh:233
static JHit_t getTimeDifference(const JHit_t first, const JHit_t second)
Get time difference between two hits.
Definition: JHitToolkit.hh:294
static double getToT(const JHit &hit)
Get time-over-threshold of hit.
Definition: JHitToolkit.hh:98
static JHit getJHit(const JHit_t hit)
Construct JHit.
Definition: JHitToolkit.hh:257
double getToT(const JDAQHit &hit, const JCalibration &cal)
Get calibrated time-over-threshold of DAQ hit.
Definition: JHitToolkit.hh:47
static double getT(const JHit &hit)
Get time of hit.
Definition: JHitToolkit.hh:86
static JHit getJHit(const JHit &hit)
Construct JHit.
Definition: JHitToolkit.hh:110
static JHit_t getEndMarker()
Get end marker.
Definition: JHitToolkit.hh:281
static double getToT(const JHit_t &hit)
Get time-over-threshold of hit.
Definition: JHitToolkit.hh:245
const JHitToolkit< JHit, false > & getToolkit() const
Get toolkit.
Definition: JHitToolkit.hh:179
Template definition of hit toolkit.
Definition: JHitToolkit.hh:60
JHitL0 getHit(const Hit &hit)
Get transformation.
Template specialisation of hit toolkit for JHit class.
Definition: JHitToolkit.hh:67
double getTime(const JDAQHit &hit, const JCalibration &cal)
Get calibrated time of DAQ hit.
Definition: JHitToolkit.hh:34
const JHitToolkit< JHit_t, true > & getToolkit() const
Get toolkit.
Definition: JHitToolkit.hh:221