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