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