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