Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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
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 */
18namespace JDETECTOR {}
19namespace JPP { using namespace JDETECTOR; }
20
21namespace 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 */
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>
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
I/O manipulators.
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
Data structure for time calibration.
double getT0() const
Get time offset.
JCalibration()
Default constructor.
const JCalibration & getCalibration() const
Get calibration.
friend JReader & operator>>(JReader &in, JCalibration &cal)
Read calibration from input.
void subT0(const double t0)
Subtract time offset.
friend JWriter & operator<<(JWriter &out, const JCalibration &cal)
Write calibration to output.
void setCalibration(const JCalibration &cal)
Set calibration.
JCalibration & getCalibration()
Get calibration.
void setT0(const double t0)
Set time offset.
JCalibration(const double __t0)
Constructor.
friend std::ostream & operator<<(std::ostream &out, const JCalibration &cal)
Write calibration to output.
void addT0(const double t0)
Add time offset.
friend std::istream & operator>>(std::istream &in, JCalibration &cal)
Read calibration from input.
Interface for binary input.
Interface for binary output.
file Auxiliary data structures and methods for detector calibration.
Definition JAnchor.hh:12
double getToT(const T &tot, const JCalibration &cal)
Get calibrated time-over-threshold of hit.
double getTime(const T &t1, const JCalibration &cal)
Get calibrated time.
const double TIME_OVER_THRESHOLD_NS
Specification for time-over-threshold corresponding to a one photo-electron pulse.
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.
double putTime(const T &t1, const JCalibration &cal)
Get de-calibrated time.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static double getTime(const JHit_t &hit, const JCalibration &cal)
Get calibrated time of hit.
static double getToT(const JHit_t &hit, const JCalibration &cal)
Get calibrated time-over-threshold of hit.
static double putTime(const JHit_t &hit, const JCalibration &cal)
Get de-calibrated time of hit.
double putToT(const JHit_t &hit, const JCalibration &cal)
Get de-calibrated time-over-threshold of hit.
static double getTime(const T t1, const JCalibration &cal)
Get calibrated time.
static double getToT(const T tot, const JCalibration &cal)
Get calibrated time-over-threshold of hit.
static double putTime(const T t1, const JCalibration &cal)
Get de-calibrated time.
static double putToT(const T tot, const JCalibration &cal)
Get de-calibrated time-over-threshold of hit.
Auxiliary class to apply (de-)calibration to template hit.
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636