Jpp
JDetector/JCalibration.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JCALIBRATION__
2 #define __JDETECTOR__JCALIBRATION__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JIO/JSerialisable.hh"
8 #include "JLang/JClass.hh"
9 
10 
11 /**
12  * \file
13  *
14  * PMT calibration (including definition of sign of time offset).
15  * \author mdejong
16  */
17 namespace JDETECTOR {}
18 namespace JPP { using namespace JDETECTOR; }
19 
20 namespace JDETECTOR {
21 
22  using JIO::JReader;
23  using JIO::JWriter;
24 
25 
26  /**
27  * Specification for time-over-threshold corresponding to a one photo-electron pulse.
28  */
29  const double TIME_OVER_THRESHOLD_NS = 26.4; // [ns]
30 
31 
32  /**
33  * Data structure for PMT calibration.
34  */
36  {
37  public:
38  /**
39  * Default constructor.
40  */
42  t0(0.0)
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param __t0 time offset [ns]
50  */
51  JCalibration(const double __t0) :
52  t0(__t0)
53  {}
54 
55 
56  /**
57  * Get calibration.
58  *
59  * \return calibration
60  */
62  {
63  return *this;
64  }
65 
66 
67  /**
68  * Set calibration.
69  *
70  * \param cal calibration
71  */
72  void setCalibration(const JCalibration& cal)
73  {
74  *this = cal;
75  }
76 
77 
78  /**
79  * Get time offset.
80  *
81  * \return time offset [ns]
82  */
83  double getT0() const
84  {
85  return t0;
86  }
87 
88 
89  /**
90  * Set time offset.
91  *
92  * \param t0 time offset [ns]
93  */
94  void setT0(const double t0)
95  {
96  this->t0 = t0;
97  }
98 
99 
100  /**
101  * Add time offset.
102  *
103  * \param t0 time offset [ns]
104  */
105  void addT0(const double t0)
106  {
107  this->t0 += t0;
108  }
109 
110 
111  /**
112  * Subtract time offset.
113  *
114  * \param t0 time offset [ns]
115  */
116  void subT0(const double t0)
117  {
118  this->t0 -= t0;
119  }
120 
121 
122  /**
123  * Read JCalibration from input.
124  *
125  * \param in input stream
126  * \param cal JCalibration
127  * \return input stream
128  */
129  friend inline std::istream& operator>>(std::istream& in, JCalibration& cal)
130  {
131  in >> cal.t0;
132 
133  return in;
134  }
135 
136 
137  /**
138  * Write JCalibration to output.
139  *
140  * \param out output stream
141  * \param cal JCalibration
142  * \return output stream
143  */
144  friend inline std::ostream& operator<<(std::ostream& out, const JCalibration& cal)
145  {
146  out << cal.t0;
147 
148  return out;
149  }
150 
151 
152  /**
153  * Read JCalibration from input.
154  *
155  * \param in JReader
156  * \param cal JCalibration
157  * \return JReader
158  */
159  friend inline JReader& operator>>(JReader& in, JCalibration& cal)
160  {
161  in >> cal.t0;
162 
163  return in;
164  }
165 
166 
167  /**
168  * Write JCalibration to output.
169  *
170  * \param out JWriter
171  * \param cal JCalibration
172  * \return JWriter
173  */
174  friend inline JWriter& operator<<(JWriter& out, const JCalibration& cal)
175  {
176  out << cal.t0;
177 
178  return out;
179  }
180 
181 
182  protected:
183  double t0;
184  };
185 
186 
187  /**
188  * Auxiliary class to apply (de-)calibration to template hit.
189  */
190  template<class T, bool is_primitive = JLANG::JClass<T>::is_primitive>
191  struct JCalibrator;
192 
193 
194  /**
195  * Get calibrated time.
196  *
197  * \param t1 time [ns]
198  * \param cal calibration
199  * \return time [ns]
200  */
201  template<class T>
202  inline double getTime(const T& t1, const JCalibration& cal)
203  {
204  return JCalibrator<T>::getTime(t1, cal);
205  }
206 
207 
208  /**
209  * Get de-calibrated time.
210  *
211  * \param t1 time [ns]
212  * \param cal calibration
213  * \return time [ns]
214  */
215  template<class T>
216  inline double putTime(const T& t1, const JCalibration& cal)
217  {
218  return JCalibrator<T>::putTime(t1, cal);
219  }
220 
221 
222  /**
223  * Get calibrated time-over-threshold of hit.
224  *
225  * \param tot time-over-threshold [ns]
226  * \param cal calibration
227  * \return time-over-threshold [ns]
228  */
229  template<class T>
230  inline double getToT(const T& tot, const JCalibration& cal)
231  {
232  return JCalibrator<T>::getToT(tot, cal);
233  }
234 
235 
236  /**
237  * Get de-calibrated time-over-threshold of hit.
238  *
239  * \param tot time-over-threshold [ns]
240  * \param cal calibration
241  * \return time-over-threshold [ns]
242  */
243  template<class T>
244  inline double putToT(const T& tot, const JCalibration& cal)
245  {
246  return JCalibrator<T>::putToT(tot, cal);
247  }
248 
249 
250  /**
251  * Template specialisation of JCalibrator for primitive data types.
252  */
253  template<class T>
254  struct JCalibrator<T, true>
255  {
256  /**
257  * Get calibrated time.
258  *
259  * \param t1 time [ns]
260  * \param cal calibration
261  * \return time [ns]
262  */
263  static inline double getTime(const T t1, const JCalibration& cal)
264  {
265  return t1 + cal.getT0();
266  }
267 
268 
269  /**
270  * Get de-calibrated time.
271  *
272  * \param t1 time [ns]
273  * \param cal calibration
274  * \return time [ns]
275  */
276  static inline double putTime(const T t1, const JCalibration& cal)
277  {
278  return t1 - cal.getT0();
279  }
280 
281 
282  /**
283  * Get calibrated time-over-threshold of hit.
284  *
285  * \param tot time-over-threshold [ns]
286  * \param cal calibration
287  * \return time-over-threshold [ns]
288  */
289  static inline double getToT(const T tot, const JCalibration& cal)
290  {
291  return tot;
292  }
293 
294 
295  /**
296  * Get de-calibrated time-over-threshold of hit.
297  *
298  * \param tot time-over-threshold [ns]
299  * \param cal calibration
300  * \return time-over-threshold [ns]
301  */
302  static inline double putToT(const T tot, const JCalibration& cal)
303  {
304  return tot;
305  }
306  };
307 
308 
309  /**
310  * Template specialisation of JCalibrator for non-primitive data types.
311  * It is assumed that the template class has the following methods:
312  * <pre>
313  * %getT();
314  * %getToT();
315  * </pre>
316  * which should return the time (ns) and time-over-threshold (ns), respectively.
317  */
318  template<class JHit_t>
319  struct JCalibrator<JHit_t, false> {
320  /**
321  * Get calibrated time of hit.
322  *
323  * \param hit hit
324  * \param cal calibration
325  * \return time [ns]
326  */
327  static inline double getTime(const JHit_t& hit, const JCalibration& cal)
328  {
329  return JDETECTOR::getTime(hit.getT(), cal);
330  }
331 
332 
333  /**
334  * Get de-calibrated time of hit.
335  *
336  * \param hit hit
337  * \param cal calibration
338  * \return time [ns]
339  */
340  static inline double putTime(const JHit_t& hit, const JCalibration& cal)
341  {
342  return JDETECTOR::putTime(hit.getT(), cal);
343  }
344 
345 
346  /**
347  * Get calibrated time-over-threshold of hit.
348  *
349  * \param hit hit
350  * \param cal calibration
351  * \return time-over-threshold [ns]
352  */
353  static inline double getToT(const JHit_t& hit, const JCalibration& cal)
354  {
355  return JDETECTOR::getToT(hit.getToT(), cal);
356  }
357 
358 
359  /**
360  * Get de-calibrated time-over-threshold of hit.
361  *
362  * \param hit hit
363  * \param cal calibration
364  * \return time-over-threshold [ns]
365  */
366  inline double putToT(const JHit_t& hit, const JCalibration& cal)
367  {
368  return JDETECTOR::putToT(hit.getToT(), cal);
369  }
370  };
371 }
372 
373 #endif
JDETECTOR::getToT
double getToT(const T &tot, const JCalibration &cal)
Get calibrated time-over-threshold of hit.
Definition: JDetector/JCalibration.hh:230
JDETECTOR::JCalibration::operator<<
friend std::ostream & operator<<(std::ostream &out, const JCalibration &cal)
Write JCalibration to output.
Definition: JDetector/JCalibration.hh:144
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
JDETECTOR::JCalibration::operator>>
friend JReader & operator>>(JReader &in, JCalibration &cal)
Read JCalibration from input.
Definition: JDetector/JCalibration.hh:159
JDETECTOR::TIME_OVER_THRESHOLD_NS
const double TIME_OVER_THRESHOLD_NS
Specification for time-over-threshold corresponding to a one photo-electron pulse.
Definition: JDetector/JCalibration.hh:29
JDETECTOR::JCalibration
Data structure for PMT calibration.
Definition: JDetector/JCalibration.hh:35
JDETECTOR::putTime
double putTime(const T &t1, const JCalibration &cal)
Get de-calibrated time.
Definition: JDetector/JCalibration.hh:216
JDETECTOR::JCalibration::JCalibration
JCalibration(const double __t0)
Constructor.
Definition: JDetector/JCalibration.hh:51
JDETECTOR::JCalibrator< JHit_t, false >::getToT
static double getToT(const JHit_t &hit, const JCalibration &cal)
Get calibrated time-over-threshold of hit.
Definition: JDetector/JCalibration.hh:353
JDETECTOR::JCalibration::getT0
double getT0() const
Get time offset.
Definition: JDetector/JCalibration.hh:83
JDETECTOR::JCalibration::subT0
void subT0(const double t0)
Subtract time offset.
Definition: JDetector/JCalibration.hh:116
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDETECTOR::JCalibrator< T, true >::getToT
static double getToT(const T tot, const JCalibration &cal)
Get calibrated time-over-threshold of hit.
Definition: JDetector/JCalibration.hh:289
JDETECTOR::JCalibration::t0
double t0
Definition: JDetector/JCalibration.hh:183
JSerialisable.hh
JDETECTOR::getTime
double getTime(const T &t1, const JCalibration &cal)
Get calibrated time.
Definition: JDetector/JCalibration.hh:202
JDETECTOR::JCalibration::getCalibration
const JCalibration & getCalibration() const
Get calibration.
Definition: JDetector/JCalibration.hh:61
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:130
JDETECTOR::JCalibrator< JHit_t, false >::getTime
static double getTime(const JHit_t &hit, const JCalibration &cal)
Get calibrated time of hit.
Definition: JDetector/JCalibration.hh:327
JDETECTOR::JCalibrator< T, true >::getTime
static double getTime(const T t1, const JCalibration &cal)
Get calibrated time.
Definition: JDetector/JCalibration.hh:263
JDETECTOR::putToT
double putToT(const T &tot, const JCalibration &cal)
Get de-calibrated time-over-threshold of hit.
Definition: JDetector/JCalibration.hh:244
JDETECTOR::JCalibration::setT0
void setT0(const double t0)
Set time offset.
Definition: JDetector/JCalibration.hh:94
JDETECTOR::JCalibrator< JHit_t, false >::putTime
static double putTime(const JHit_t &hit, const JCalibration &cal)
Get de-calibrated time of hit.
Definition: JDetector/JCalibration.hh:340
JDETECTOR::JCalibration::setCalibration
void setCalibration(const JCalibration &cal)
Set calibration.
Definition: JDetector/JCalibration.hh:72
JDETECTOR::JCalibrator< T, true >::putToT
static double putToT(const T tot, const JCalibration &cal)
Get de-calibrated time-over-threshold of hit.
Definition: JDetector/JCalibration.hh:302
JDETECTOR::JCalibrator
Auxiliary class to apply (de-)calibration to template hit.
Definition: JDetector/JCalibration.hh:191
JDETECTOR::JCalibration::operator<<
friend JWriter & operator<<(JWriter &out, const JCalibration &cal)
Write JCalibration to output.
Definition: JDetector/JCalibration.hh:174
JDETECTOR::JCalibration::addT0
void addT0(const double t0)
Add time offset.
Definition: JDetector/JCalibration.hh:105
JDETECTOR::JCalibrator< JHit_t, false >::putToT
double putToT(const JHit_t &hit, const JCalibration &cal)
Get de-calibrated time-over-threshold of hit.
Definition: JDetector/JCalibration.hh:366
JClass.hh
JDETECTOR::JCalibrator< T, true >::putTime
static double putTime(const T t1, const JCalibration &cal)
Get de-calibrated time.
Definition: JDetector/JCalibration.hh:276
JDETECTOR::JCalibration::operator>>
friend std::istream & operator>>(std::istream &in, JCalibration &cal)
Read JCalibration from input.
Definition: JDetector/JCalibration.hh:129
JDETECTOR::JCalibration::JCalibration
JCalibration()
Default constructor.
Definition: JDetector/JCalibration.hh:41
JDETECTOR
Auxiliary classes and methods for detector calibration.
Definition: JAnchor.hh:12