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