Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JAcoustics/JEvent.hh
Go to the documentation of this file.
1#ifndef __JACOUSTICS__JEVENT__
2#define __JACOUSTICS__JEVENT__
3
4#include <string>
5#include <istream>
6#include <ostream>
7#include <iomanip>
8#include <vector>
9
10#include <TROOT.h>
11#include <TObject.h>
12
13#include "JIO/JSerialisable.hh"
14#include "JIO/JSTDIO.hh"
15
18
19
20/**
21 * \file
22 *
23 * Acoustic event.
24 * \author mdejong
25 */
26namespace JACOUSTICS {}
27namespace JPP { using namespace JACOUSTICS; }
28
29namespace JACOUSTICS {
30
32 using JIO::JReader;
33 using JIO::JWriter;
34
35 /**
36 * Acoustic event.
37 */
38 struct JEvent :
39 public JSerialisable,
40 public JCounter,
41 public std::vector<JTransmission>,
42 public TObject
43 {
44 /**
45 * Auxiliary class to determine value of acoustic events.\n
46 * This class can be used with JSUPPORT::JTreeScanner so to read acoustics events in order of time-of-emission.
47 */
48 struct JEvaluator {
49 /**
50 * Type definition of time value.
51 */
52 typedef double value_type;
53
54
55 /**
56 * Default constructor.
57 */
59 {}
60
61
62 /**
63 * Get value of object.
64 *
65 * \param event event
66 * \return value
67 */
68 inline value_type operator()(const JEvent& event) const
69 {
70 return event.begin()->getToE();
71 }
72 };
73
74
75 /**
76 * Default constructor.
77 */
79 JCounter(),
80 overlays(0),
81 id (-1)
82 {}
83
84
85 /**
86 * Constructor.
87 *
88 * The transmissions will be sorted to ensure proper functioning of method JEvent::merge and class JEventOverlap.
89 *
90 * \param detid detector identifier
91 * \param counter counter
92 * \param id identifier
93 * \param __begin begin of data
94 * \param __end end of data
95 */
96 template<class T>
97 JEvent(const int detid,
98 const int counter,
99 const int id,
100 T __begin,
101 T __end) :
103 detid (detid),
104 overlays(0),
105 id (id)
106 {
107 using namespace std;
108
109 for (T i = __begin; i != __end; ++i) {
110 push_back(*i);
111 }
112
113 sort(this->begin(), this->end());
114 }
115
116
117 /**
118 * Virtual destructor.
119 */
120 virtual ~JEvent()
121 {}
122
123
124 /**
125 * Get detector identifier.
126 *
127 * \return detector identifier.
128 */
129 const int getDetectorID() const
130 {
131 return detid;
132 }
133
134
135 /**
136 * Get number of overlayed events.
137 *
138 * \return overlays
139 */
140 int getOverlays() const
141 {
142 return overlays;
143 }
144
145
146 /**
147 * Get emitter identifier.
148 *
149 * \return identifier
150 */
151 int getID() const
152 {
153 return id;
154 }
155
156
157 /**
158 * Merge event.
159 *
160 * It is assumed that the transmissions in both events are ordered
161 * according the default less-than operator.
162 *
163 * \param event event
164 */
165 void merge(const JEvent& event)
166 {
167 using namespace std;
168
170
171 const_iterator __hit1 = this ->begin();
172 const_iterator __end1 = this ->end();
173
174 const_iterator __hit2 = event.begin();
175 const_iterator __end2 = event.end();
176
177 buffer.resize(this->size() + event.size());
178
179 iterator out = buffer.begin();
180
181 while (__hit1 != __end1 && __hit2 != __end2) {
182
183 if (*__hit1 < *__hit2) {
184
185 *out = *__hit1;
186 ++__hit1;
187
188 } else if (*__hit2 < *__hit1) {
189
190 *out = *__hit2;
191 ++__hit2;
192
193 } else {
194
195 *out = *__hit1;
196
197 ++__hit1;
198 ++__hit2;
199 }
200
201 ++out;
202 }
203
204 // append remaining hits from either set
205
206 out = copy(__hit1, __end1, out);
207 out = copy(__hit2, __end2, out);
208
209 buffer.resize(distance(buffer.begin(), out));
210
211 this->swap(buffer);
212
213 ++overlays;
214 }
215
216
217 /**
218 * Swap events.
219 *
220 * \param first first event
221 * \param second second event
222 */
223 friend inline void swap(JEvent& first, JEvent& second)
224 {
225 std::swap(first.counter, second.counter);
226 std::swap(first.detid, second.detid);
227 std::swap(first.overlays, second.overlays);
228 std::swap(first.id, second.id);
229
230 static_cast<std::vector<JTransmission>&>(first).swap(static_cast<std::vector<JTransmission>&>(second));
231 }
232
233
234 /**
235 * Empty overlapping events.
236 *
237 * The events should be time sorted on input.\n
238 * The time window applies to the difference between the first transmission
239 * of an event and the last transmission of the previous event.
240 *
241 * \param p begin of events
242 * \param q end of events
243 * \param Tmax_s time window [s]
244 *
245 */
246 template<class T>
247 static inline void overlap(T p, T q, const double Tmax_s)
248 {
249 for (T __q = p, __p = __q++; __p != q && __q != q; __p = __q++) {
250
251 if (!__p->empty() &&
252 !__q->empty() &&
253 __q->begin()->getToE() < __p->rbegin()->getToE() + Tmax_s) {
254
255 __p->clear(); // clear first
256
257 for (__p = __q++; __p != q && __q != q; __p = __q++) {
258
259 if (__q->begin()->getToE() < __p->rbegin()->getToE() + Tmax_s)
260 __p->clear(); // clear intermediate
261 else
262 break;
263 }
264
265 __p->clear(); // clear last
266 }
267 }
268 }
269
270
271 /**
272 * Less than operator for acoustics events.
273 *
274 * The less than operator is applied to the first hit in the events.\n
275 * If there are no hits in either event, the counter of the events is used.
276 *
277 * \param first first event
278 * \param second second event
279 * \return true if first event earliear than second; else false
280 */
281 friend inline bool operator<(const JEvent& first, const JEvent& second)
282 {
283 if (!first.empty() && !second.empty())
284 return first.begin()->getToE() < second.begin()->getToE();
285 else
286 return first.getCounter() < second.getCounter();
287 }
288
289
290 /**
291 * Write event to output stream.
292 *
293 * \param out output stream
294 * \param event event
295 * \return output stream
296 */
297 friend inline std::ostream& operator<<(std::ostream& out, const JEvent& event)
298 {
299 using namespace std;
300
301 out << event.getDetectorID() << endl;
302 out << setw(8) << event.getCounter() << endl;
303 out << setw(2) << event.getOverlays() << endl;
304 out << setw(3) << event.getID() << endl;
305
306 for (const_iterator i = event.begin(); i != event.end(); ++i) {
307
308 out << setw(10) << i->getID() << ' '
309 << setw(10) << i->getRunNumber() << ' '
310 << fixed << setw(12) << setprecision(6) << i->getToA() << ' '
311 << fixed << setw(12) << setprecision(6) << i->getToE() << ' '
312 << fixed << setw(8) << setprecision(0) << i->getQ() << ' '
313 << fixed << setw(8) << setprecision(0) << i->getW() << endl;
314 }
315
316 return out;
317 }
318
319
320 /**
321 * Read from input.
322 *
323 * \param in reader
324 * \return reader
325 */
326 virtual JReader& read(JReader& in) override
327 {
328 in >> static_cast<JCounter&>(*this);
329 in >> this->detid;
330 in >> this->overlays;
331 in >> this->id;
332 in >> static_cast<std::vector<JTransmission>&>(*this);
333
334 return in;
335 }
336
337
338 /**
339 * Write to output.
340 *
341 * \param out writer
342 * \return writer
343 */
344 virtual JWriter& write(JWriter& out) const override
345 {
346 out << static_cast<const JCounter&>(*this);
347 out << this->detid;
348 out << this->overlays;
349 out << this->id;
350 out << static_cast<const std::vector<JTransmission>&>(*this);
351
352 return out;
353 }
354
356
357 protected:
358 int detid;
360 int id;
361 };
362}
363
364#endif
Acoustic counter.
STD extensions for binary I/O.
Acoustic transmission.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Interface for binary input.
Forward declaration of binary output.
Interface for binary output.
Auxiliary classes and methods for acoustic position calibration.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
int getCounter() const
Get counter.
Auxiliary class to determine value of acoustic events.
double value_type
Type definition of time value.
value_type operator()(const JEvent &event) const
Get value of object.
virtual JWriter & write(JWriter &out) const override
Write to output.
void merge(const JEvent &event)
Merge event.
static void overlap(T p, T q, const double Tmax_s)
Empty overlapping events.
JEvent(const int detid, const int counter, const int id, T __begin, T __end)
Constructor.
virtual JReader & read(JReader &in) override
Read from input.
int getID() const
Get emitter identifier.
friend std::ostream & operator<<(std::ostream &out, const JEvent &event)
Write event to output stream.
friend bool operator<(const JEvent &first, const JEvent &second)
Less than operator for acoustics events.
const int getDetectorID() const
Get detector identifier.
virtual ~JEvent()
Virtual destructor.
int getOverlays() const
Get number of overlayed events.
friend void swap(JEvent &first, JEvent &second)
Swap events.
ClassDefOverride(JEvent, 4)
JEvent()
Default constructor.