Jpp 20.0.0-rc.9-29-gccc23c492-D
the software that should make you happy
Loading...
Searching...
No Matches
JEvt.hh
Go to the documentation of this file.
1#ifndef __JACOUSTICS__JEVT__
2#define __JACOUSTICS__JEVT__
3
4#include <string>
5#include <ostream>
6#include <iomanip>
7#include <vector>
8
9#include <TObject.h>
10
11#include "JLang/JManip.hh"
12#include "JIO/JSerialisable.hh"
13#include "JIO/JSTDIO.hh"
15
16/**
17 * \file
18 *
19 * Acoustic event fit.
20 * \author mdejong
21 */
22namespace JACOUSTICS {}
23namespace JPP { using namespace JACOUSTICS; }
24
25namespace JACOUSTICS {
26
27 using JIO::JSerialisable;
28 using JIO::JReader;
29 using JIO::JWriter;
30
31 /**
32 * Acoustic single fit.
33 */
34 struct JFit :
35 public TObject
36 {
37 /**
38 * Default constructor.
39 */
40 JFit() :
41 id (-1),
42 tx (0.0),
43 ty (0.0),
44 tx2(0.0),
45 ty2(0.0),
46 vs (0.0)
47 {}
48
49
50 /**
51 * Constructor.
52 *
53 * \param id string identifier
54 * \param tx slope dx/dz
55 * \param ty slope dy/dz
56 * \param tx2 2nd order correction of slope dx/dz
57 * \param ty2 2nd order correction of slope dy/dz
58 * \param vs stretching factor
59 */
60 JFit(const int id,
61 const double tx,
62 const double ty,
63 const double tx2,
64 const double ty2,
65 const double vs) :
66 id (id),
67 tx (tx),
68 ty (ty),
69 tx2(tx2),
70 ty2(ty2),
71 vs (vs)
72 {}
73
74
75 /**
76 * Virtual destructor.
77 */
78 virtual ~JFit()
79 {}
80
81
82 /**
83 * Write fit to output.
84 *
85 * \param out output stream
86 * \param fit fit
87 * \return output stream
88 */
89 friend inline std::ostream& operator<<(std::ostream& out, const JFit& fit)
90 {
91 using namespace std;
92
93 out << setw(4) << fit.id << ' '
94 << FIXED(10,7) << fit.tx << ' '
95 << FIXED(10,7) << fit.ty << ' '
96 << SCIENTIFIC(12,3) << fit.tx2 << ' '
97 << SCIENTIFIC(12,3) << fit.ty2 << ' '
98 << FIXED(8,5) << fit.vs;
99
100 return out;
101 }
102
103
104 /**
105 * Read fit from input.
106 *
107 * \param in reader
108 * \param object fit
109 * \return reader
110 */
111 friend inline JReader& operator>>(JReader& in, JFit& object)
112 {
113 in >> object.id;
114 in >> object.tx;
115 in >> object.ty;
116 in >> object.tx2;
117 in >> object.ty2;
118 in >> object.vs;
119
120 return in;
121 }
122
123
124 /**
125 * Write fit to output.
126 *
127 * \param out writer
128 * \param object fit
129 * \return writer
130 */
131 friend inline JWriter& operator<<(JWriter& out, const JFit& object)
132 {
133 out << object.id;
134 out << object.tx;
135 out << object.ty;
136 out << object.tx2;
137 out << object.ty2;
138 out << object.vs;
139
140 return out;
141 }
142
144
145 int id; ///< string identifier
146 double tx; ///< slope dx/dz
147 double ty; ///< slope dy/dz
148 double tx2; ///< 2nd order correction of slope dx/dz
149 double ty2; ///< 2nd order correction of slope dy/dz
150 double vs; ///< stretching factor
151 };
152
153
154 /**
155 * Acoustic event header.
156 */
157 struct JHead {
158 /**
159 * Default constructor.
160 */
162 detid(),
163 UNIXTimeStart(0.0),
164 UNIXTimeStop (0.0),
165 nhit(0),
166 nfit(0),
167 npar(0),
168 ndf (0.0),
169 chi2(0.0),
171 {}
172
173
174 /**
175 * Constructor.
176 *
177 * \param detid detector identifer
178 * \param range UNIX start and stop time [s]
179 * \param nhit number of hits
180 * \param nfit number of hits used in fit (after outlier removal)
181 * \param npar number of fit parameters
182 * \param ndf weighed number of degrees of freedom
183 * \param chi2 chi2
184 * \param ns number of iterations
185 */
186 JHead(const int detid,
187 const JTimeRange& range,
188 const int nhit,
189 const int nfit,
190 const int npar,
191 const double ndf,
192 const double chi2,
193 const int ns) :
194 detid(detid),
195 UNIXTimeStart(range.getLowerLimit()),
196 UNIXTimeStop (range.getUpperLimit()),
197 nhit(nhit),
198 nfit(nfit),
199 npar(npar),
200 ndf (ndf),
201 chi2(chi2),
203 {}
204
205
206 /**
207 * Virtual destructor.
208 */
209 virtual ~JHead()
210 {}
211
212
213 /**
214 * Read head from input.
215 *
216 * \param in reader
217 * \param object head
218 * \return reader
219 */
220 friend inline JReader& operator>>(JReader& in, JHead& object)
221 {
222 in >> object.detid;
223 in >> object.UNIXTimeStart;
224 in >> object.UNIXTimeStop;
225 in >> object.nhit;
226 in >> object.nfit;
227 in >> object.npar;
228 in >> object.ndf;
229 in >> object.chi2;
230 in >> object.numberOfIterations;
231
232 return in;
233 }
234
235
236 /**
237 * Write head to output.
238 *
239 * \param out writer
240 * \param object head
241 * \return writer
242 */
243 friend inline JWriter& operator<<(JWriter& out, const JHead& object)
244 {
245 out << object.detid;
246 out << object.UNIXTimeStart;
247 out << object.UNIXTimeStop;
248 out << object.nhit;
249 out << object.nfit;
250 out << object.npar;
251 out << object.ndf;
252 out << object.chi2;
253 out << object.numberOfIterations;
254
255 return out;
256 }
257
259
260 int detid; ///< detector identifier
261 double UNIXTimeStart; ///< start time
262 double UNIXTimeStop; ///< stop time
263 int nhit; ///< number of hits
264 int nfit; ///< number of hits used in fit (after outlier removal)
265 int npar; ///< number of fit parameters
266 double ndf; ///< weighed number of degrees of freedom
267 double chi2; ///< chi2
268 int numberOfIterations; ///< number of iterations
269 };
270
271
272 /**
273 * Less than operator for acoustics event headers.
274 *
275 * The less than operator is applied to the object identifier,
276 * the UNIX start time and the UNIX stop time, respectively.
277 *
278 * \param first first header
279 * \param second second header
280 * \return true if first event header earliear than second; else false
281 */
282 inline bool operator<(const JHead& first, const JHead& second)
283 {
284 if (first.detid == second.detid) {
285
286 if (first.UNIXTimeStart == second.UNIXTimeStart) {
287
288 return first.UNIXTimeStop < second.UNIXTimeStop;
289
290 } else {
291
292 return first.UNIXTimeStart < second.UNIXTimeStart;
293 }
294
295 } else {
296
297 return first.detid < second.detid;
298 }
299 }
300
301
302 /**
303 * Acoustic event fit.
304 */
305 struct JEvt :
306 public virtual JSerialisable,
307 public JHead,
308 public std::vector<JFit>,
309 public TObject
310 {
311 /**
312 * Auxiliary class to determine value of acoustic events.\n
313 * This class can be used with JSUPPORT::JTreeScanner so to read acoustics events in order of start time.
314 */
315 struct JEvaluator {
316 /**
317 * Type definition of time value.
318 */
319 typedef double value_type;
320
321
322 /**
323 * Default constructor.
324 */
326 {}
327
328
329 /**
330 * Get value of object.
331 *
332 * \param event event
333 * \return value
334 */
335 inline value_type operator()(const JEvt& event) const
336 {
337 return event.UNIXTimeStart;
338 }
339 };
340
341
342 /**
343 * Default constructor.
344 */
346 JHead()
347 {}
348
349
350 /**
351 * Constructor.
352 *
353 * \param header header
354 */
355 JEvt(const JHead& header) :
356 JHead(header)
357 {}
358
359
360 /**
361 * Virtual destructor.
362 */
363 virtual ~JEvt()
364 {}
365
366
367 /**
368 * Write event to output.
369 *
370 * \param out output stream
371 * \param event event
372 * \return output stream
373 */
374 friend inline std::ostream& operator<<(std::ostream& out, const JEvt& event)
375 {
376 using namespace std;
377
378 out << event.detid << endl
379 << FIXED(20,5) << event.UNIXTimeStart << endl
380 << FIXED(20,5) << event.UNIXTimeStop << endl
381 << setw(5) << event.nhit << ' '
382 << setw(5) << event.nfit << ' '
383 << setw(4) << event.npar << endl
384 << FIXED(12,3) << event.chi2 << '/'
385 << FIXED(7,1) << event.ndf << endl;
386
387 for (JEvt::const_iterator fit = event.begin(); fit != event.end(); ++fit) {
388 out << *fit << endl;
389 }
390
391 return out;
392 }
393
394
395 /**
396 * Read from input.
397 *
398 * \param in reader
399 * \return reader
400 */
401 virtual JReader& read(JReader& in) override
402 {
403 in >> static_cast<JHead&> (*this);
404 in >> static_cast<std::vector<JFit>&>(*this);
405
406 return in;
407 }
408
409
410 /**
411 * Write to output.
412 *
413 * \param out writer
414 * \return writer
415 */
416 virtual JWriter& write(JWriter& out) const override
417 {
418 out << static_cast<const JHead&> (*this);
419 out << static_cast<const std::vector<JFit>&>(*this);
420
421 return out;
422 }
423
425 };
426}
427
428#endif
Auxiliary classes and methods for acoustic position calibration.
static bool operator<(const JCounter &first, const JCounter &second)
Less-than operator for two counters.
Definition JCounter.hh:99
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [s]).
Auxiliary class to determine value of acoustic events.
Definition JEvt.hh:315
value_type operator()(const JEvt &event) const
Get value of object.
Definition JEvt.hh:335
JEvaluator()
Default constructor.
Definition JEvt.hh:325
double value_type
Type definition of time value.
Definition JEvt.hh:319
Acoustic event fit.
Definition JEvt.hh:310
JEvt(const JHead &header)
Constructor.
Definition JEvt.hh:355
friend std::ostream & operator<<(std::ostream &out, const JEvt &event)
Write event to output.
Definition JEvt.hh:374
virtual JReader & read(JReader &in) override
Read from input.
Definition JEvt.hh:401
virtual ~JEvt()
Virtual destructor.
Definition JEvt.hh:363
JEvt()
Default constructor.
Definition JEvt.hh:345
ClassDefOverride(JEvt, 9)
virtual JWriter & write(JWriter &out) const override
Write to output.
Definition JEvt.hh:416
Acoustic single fit.
Definition JEvt.hh:36
double tx
slope dx/dz
Definition JEvt.hh:146
double vs
stretching factor
Definition JEvt.hh:150
friend JWriter & operator<<(JWriter &out, const JFit &object)
Write fit to output.
Definition JEvt.hh:131
int id
string identifier
Definition JEvt.hh:145
friend std::ostream & operator<<(std::ostream &out, const JFit &fit)
Write fit to output.
Definition JEvt.hh:89
ClassDefOverride(JFit, 2)
virtual ~JFit()
Virtual destructor.
Definition JEvt.hh:78
double ty
slope dy/dz
Definition JEvt.hh:147
double ty2
2nd order correction of slope dy/dz
Definition JEvt.hh:149
friend JReader & operator>>(JReader &in, JFit &object)
Read fit from input.
Definition JEvt.hh:111
double tx2
2nd order correction of slope dx/dz
Definition JEvt.hh:148
JFit()
Default constructor.
Definition JEvt.hh:40
JFit(const int id, const double tx, const double ty, const double tx2, const double ty2, const double vs)
Constructor.
Definition JEvt.hh:60
Acoustic event header.
Definition JEvt.hh:157
virtual ~JHead()
Virtual destructor.
Definition JEvt.hh:209
int nhit
number of hits
Definition JEvt.hh:263
ClassDef(JHead, 7)
JHead(const int detid, const JTimeRange &range, const int nhit, const int nfit, const int npar, const double ndf, const double chi2, const int ns)
Constructor.
Definition JEvt.hh:186
double UNIXTimeStop
stop time
Definition JEvt.hh:262
double ndf
weighed number of degrees of freedom
Definition JEvt.hh:266
int detid
detector identifier
Definition JEvt.hh:260
friend JReader & operator>>(JReader &in, JHead &object)
Read head from input.
Definition JEvt.hh:220
double chi2
chi2
Definition JEvt.hh:267
int nfit
number of hits used in fit (after outlier removal)
Definition JEvt.hh:264
friend JWriter & operator<<(JWriter &out, const JHead &object)
Write head to output.
Definition JEvt.hh:243
int npar
number of fit parameters
Definition JEvt.hh:265
JHead()
Default constructor.
Definition JEvt.hh:161
double UNIXTimeStart
start time
Definition JEvt.hh:261
int numberOfIterations
number of iterations
Definition JEvt.hh:268