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