Jpp  18.0.0-rc.2
the software that should make you happy
 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  * Get calibration.
75  *
76  * \return calibration
77  */
79  {
80  return *this;
81  }
82 
83 
84  /**
85  * Set calibration.
86  *
87  * \param cal calibration
88  */
89  void setCalibration(const JCalibration& cal)
90  {
91  *this = cal;
92  }
93 
94 
95  /**
96  * Get time offset.
97  *
98  * \return time offset [ns]
99  */
100  double getT0() const
101  {
102  return t0;
103  }
104 
105 
106  /**
107  * Set time offset.
108  *
109  * \param t0 time offset [ns]
110  */
111  void setT0(const double t0)
112  {
113  this->t0 = t0;
114  }
115 
116 
117  /**
118  * Add time offset.
119  *
120  * \param t0 time offset [ns]
121  */
122  void addT0(const double t0)
123  {
124  this->t0 += t0;
125  }
126 
127 
128  /**
129  * Subtract time offset.
130  *
131  * \param t0 time offset [ns]
132  */
133  void subT0(const double t0)
134  {
135  this->t0 -= t0;
136  }
137 
138 
139  /**
140  * Read calibration from input.
141  *
142  * \param in input stream
143  * \param cal calibration
144  * \return input stream
145  */
146  friend inline std::istream& operator>>(std::istream& in, JCalibration& cal)
147  {
148  in >> cal.t0;
149 
150  return in;
151  }
152 
153 
154  /**
155  * Write calibration to output.
156  *
157  * \param out output stream
158  * \param cal calibration
159  * \return output stream
160  */
161  friend inline std::ostream& operator<<(std::ostream& out, const JCalibration& cal)
162  {
163  const JFormat format(out, getFormat<JCalibration>(JFormat_t(9, 3, std::ios::fixed | std::ios::showpos)));
164 
165  out << format << cal.t0;
166 
167  return out;
168  }
169 
170 
171  /**
172  * Read calibration from input.
173  *
174  * \param in reader
175  * \param cal calibration
176  * \return reader
177  */
178  friend inline JReader& operator>>(JReader& in, JCalibration& cal)
179  {
180  in >> cal.t0;
181 
182  return in;
183  }
184 
185 
186  /**
187  * Write calibration to output.
188  *
189  * \param out writer
190  * \param cal calibration
191  * \return writer
192  */
193  friend inline JWriter& operator<<(JWriter& out, const JCalibration& cal)
194  {
195  out << cal.t0;
196 
197  return out;
198  }
199 
200 
201  protected:
202  double t0;
203  };
204 
205 
206 
207  /**
208  * Auxiliary class to apply (de-)calibration to template hit.
209  */
210  template<class T, bool is_primitive = JLANG::JClass<T>::is_primitive>
211  struct JCalibrator;
212 
213 
214  /**
215  * Get calibrated time.
216  *
217  * \param t1 time [ns]
218  * \param cal calibration
219  * \return time [ns]
220  */
221  template<class T>
222  inline double getTime(const T& t1, const JCalibration& cal)
223  {
224  return JCalibrator<T>::getTime(t1, cal);
225  }
226 
227 
228  /**
229  * Get de-calibrated time.
230  *
231  * \param t1 time [ns]
232  * \param cal calibration
233  * \return time [ns]
234  */
235  template<class T>
236  inline double putTime(const T& t1, const JCalibration& cal)
237  {
238  return JCalibrator<T>::putTime(t1, cal);
239  }
240 
241 
242  /**
243  * Get 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 getToT(const T& tot, const JCalibration& cal)
251  {
252  return JCalibrator<T>::getToT(tot, cal);
253  }
254 
255 
256  /**
257  * Get de-calibrated time-over-threshold of hit.
258  *
259  * \param tot time-over-threshold [ns]
260  * \param cal calibration
261  * \return time-over-threshold [ns]
262  */
263  template<class T>
264  inline double putToT(const T& tot, const JCalibration& cal)
265  {
266  return JCalibrator<T>::putToT(tot, cal);
267  }
268 
269 
270  /**
271  * Template specialisation of JCalibrator for primitive data types.
272  */
273  template<class T>
274  struct JCalibrator<T, true>
275  {
276  /**
277  * Get calibrated time.
278  *
279  * \param t1 time [ns]
280  * \param cal calibration
281  * \return time [ns]
282  */
283  static inline double getTime(const T t1, const JCalibration& cal)
284  {
285  return t1 + cal.getT0();
286  }
287 
288 
289  /**
290  * Get de-calibrated time.
291  *
292  * \param t1 time [ns]
293  * \param cal calibration
294  * \return time [ns]
295  */
296  static inline double putTime(const T t1, const JCalibration& cal)
297  {
298  return t1 - cal.getT0();
299  }
300 
301 
302  /**
303  * Get calibrated time-over-threshold of hit.
304  *
305  * \param tot time-over-threshold [ns]
306  * \param cal calibration
307  * \return time-over-threshold [ns]
308  */
309  static inline double getToT(const T tot, const JCalibration& cal)
310  {
311  return tot;
312  }
313 
314 
315  /**
316  * Get de-calibrated time-over-threshold of hit.
317  *
318  * \param tot time-over-threshold [ns]
319  * \param cal calibration
320  * \return time-over-threshold [ns]
321  */
322  static inline double putToT(const T tot, const JCalibration& cal)
323  {
324  return tot;
325  }
326  };
327 
328 
329  /**
330  * Template specialisation of JCalibrator for non-primitive data types.
331  * It is assumed that the template class has the following methods:
332  * <pre>
333  * %getT();
334  * %getToT();
335  * </pre>
336  * which should return the time (ns) and time-over-threshold (ns), respectively.
337  */
338  template<class JHit_t>
339  struct JCalibrator<JHit_t, false> {
340  /**
341  * Get calibrated time of hit.
342  *
343  * \param hit hit
344  * \param cal calibration
345  * \return time [ns]
346  */
347  static inline double getTime(const JHit_t& hit, const JCalibration& cal)
348  {
349  return JDETECTOR::getTime(hit.getT(), cal);
350  }
351 
352 
353  /**
354  * Get de-calibrated time of hit.
355  *
356  * \param hit hit
357  * \param cal calibration
358  * \return time [ns]
359  */
360  static inline double putTime(const JHit_t& hit, const JCalibration& cal)
361  {
362  return JDETECTOR::putTime(hit.getT(), cal);
363  }
364 
365 
366  /**
367  * Get calibrated time-over-threshold of hit.
368  *
369  * \param hit hit
370  * \param cal calibration
371  * \return time-over-threshold [ns]
372  */
373  static inline double getToT(const JHit_t& hit, const JCalibration& cal)
374  {
375  return JDETECTOR::getToT(hit.getToT(), cal);
376  }
377 
378 
379  /**
380  * Get de-calibrated time-over-threshold of hit.
381  *
382  * \param hit hit
383  * \param cal calibration
384  * \return time-over-threshold [ns]
385  */
386  inline double putToT(const JHit_t& hit, const JCalibration& cal)
387  {
388  return JDETECTOR::putToT(hit.getToT(), cal);
389  }
390  };
391 }
392 
393 #endif
static double getTime(const T t1, const JCalibration &cal)
Get calibrated time.
JCalibration & getCalibration()
Get calibration.
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:632
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
Data structure for format specifications.
Definition: JManip.hh:522
JCalibration()
Default constructor.
double getT0() const
Get time offset.