Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "JAcoustics/JCounter.hh"
15 
16 
17 /**
18  * \file
19  *
20  * Acoustic event.
21  * \author mdejong
22  */
23 namespace JACOUSTICS {}
24 namespace JPP { using namespace JACOUSTICS; }
25 
26 namespace JACOUSTICS {
27 
28  /**
29  * Acoustic event.
30  */
31  struct JEvent :
32  public JCounter,
33  public std::vector<JTransmission>,
34  public TObject
35  {
36  /**
37  * Auxiliary class to determine value of acoustic events.\n
38  * This class can be used with JSUPPORT::JTreeScanner so to read acoustics events in order of time-of-emission.
39  */
40  struct JEvaluator {
41  /**
42  * Default constructor.
43  */
45  {}
46 
47 
48  /**
49  * Get value of object.
50  *
51  * \param event event
52  * \return value
53  */
54  inline double operator()(const JEvent& event) const
55  {
56  return event.begin()->getToE();
57  }
58  };
59 
60 
61  /**
62  * Default constructor.
63  */
64  JEvent() :
65  JCounter(),
66  overlays(0),
67  id (-1)
68  {}
69 
70 
71  /**
72  * Constructor.
73  *
74  * The transmissions will be sorted to ensure proper functioning of method JEvent::merge and class JEventOverlap.
75  *
76  * \param oid detector identifier
77  * \param counter counter
78  * \param id identifier
79  * \param __begin begin of data
80  * \param __end end of data
81  */
82  template<class T>
84  const int counter,
85  const int id,
86  T __begin,
87  T __end) :
88  JCounter(counter),
89  oid (oid),
90  overlays(0),
91  id (id)
92  {
93  using namespace std;
94 
95  for (T i = __begin; i != __end; ++i) {
96  push_back(*i);
97  }
98 
99  sort(this->begin(), this->end());
100  }
101 
102 
103  /**
104  * Virtual destructor.
105  */
106  virtual ~JEvent()
107  {}
108 
109 
110  /**
111  * Get detector identifier.
112  *
113  * \return detector identifier.
114  */
115  const std::string& getOID() const
116  {
117  return oid;
118  }
119 
120 
121  /**
122  * Get counter.
123  *
124  * \return counter
125  */
126  int getCounter() const
127  {
128  return counter;
129  }
130 
131 
132  /**
133  * Get overlays.
134  *
135  * \return overlays
136  */
137  int getOverlays() const
138  {
139  return overlays;
140  }
141 
142 
143  /**
144  * Get identifier.
145  *
146  * \return identifier
147  */
148  int getID() const
149  {
150  return id;
151  }
152 
153 
154  /**
155  * Merge event.
156  *
157  * It is assumed that the transmissions in both events are ordered
158  * according the default less-than operator.
159  *
160  * \param event event
161  */
162  void merge(const JEvent& event)
163  {
164  using namespace std;
165 
166  vector<JTransmission> buffer;
167 
168  const_iterator __hit1 = this ->begin();
169  const_iterator __end1 = this ->end();
170 
171  const_iterator __hit2 = event.begin();
172  const_iterator __end2 = event.end();
173 
174  buffer.resize(this->size() + event.size());
175 
176  iterator out = buffer.begin();
177 
178  while (__hit1 != __end1 && __hit2 != __end2) {
179 
180  if (*__hit1 < *__hit2) {
181 
182  *out = *__hit1;
183  ++__hit1;
184 
185  } else if (*__hit2 < *__hit1) {
186 
187  *out = *__hit2;
188  ++__hit2;
189 
190  } else {
191 
192  *out = *__hit1;
193 
194  ++__hit1;
195  ++__hit2;
196  }
197 
198  ++out;
199  }
200 
201  // append remaining hits from either set
202 
203  out = copy(__hit1, __end1, out);
204  out = copy(__hit2, __end2, out);
205 
206  buffer.resize(distance(buffer.begin(), out));
207 
208  this->swap(buffer);
209 
210  ++overlays;
211  }
212 
213 
214  /**
215  * Write event to output stream.
216  *
217  * \param out output stream
218  * \param event event
219  * \return output stream
220  */
221  friend inline std::ostream& operator<<(std::ostream& out, const JEvent& event)
222  {
223  using namespace std;
224 
225  out << event.getOID() << endl;
226  out << setw(8) << event.getCounter() << endl;
227  out << setw(2) << event.getOverlays() << endl;
228  out << setw(3) << event.getID() << endl;
229 
230  for (const_iterator i = event.begin(); i != event.end(); ++i) {
231 
232  out << setw(10) << i->getID() << ' '
233  << setw(10) << i->getRunNumber() << ' '
234  << fixed << setw(12) << setprecision(6) << i->getToA() << ' '
235  << fixed << setw(12) << setprecision(6) << i->getToE() << ' '
236  << fixed << setw(8) << setprecision(0) << i->getQ() << ' '
237  << fixed << setw(8) << setprecision(0) << i->getW() << endl;
238  }
239 
240  return out;
241  }
242 
243  ClassDef(JEvent, 3);
244 
245  protected:
247  int overlays;
248  int id;
249  };
250 
251 
252  /**
253  * Less than operator for acoustics events.
254  *
255  * The less than operator is applied to the first hit in the events.\n
256  * If there are no hits in either event, the counter of the events is used.
257  *
258  * \param first first event
259  * \param second second event
260  * \return true if first event earliear than second; else false
261  */
262  inline bool operator<(const JEvent& first, const JEvent& second)
263  {
264  if (!first.empty() && !second.empty())
265  return first.begin()->getToE() < second.begin()->getToE();
266  else
267  return first.getCounter() < second.getCounter();
268  }
269 
270 
271  /**
272  * Empty overlapping events.
273  *
274  * The events should be time sorted on input.\n
275  * The time window applies to the difference between the first transmission
276  * of an event and the last transmission of the previous event.
277  *
278  * \param p begin of events
279  * \param q end of events
280  * \param Tmax_s time window [s]
281  *
282  */
283  template<class T>
284  inline void overlap(T p, T q, const double Tmax_s)
285  {
286  for (T __q = p, __p = __q++; __p != q && __q != q; __p = __q++) {
287 
288  if (!__p->empty() &&
289  !__q->empty() &&
290  __q->begin()->getToE() < __p->rbegin()->getToE() + Tmax_s) {
291 
292  __p->clear(); // clear first
293 
294  for (__p = __q++; __p != q && __q != q; __p = __q++) {
295 
296  if (__q->begin()->getToE() < __p->rbegin()->getToE() + Tmax_s)
297  __p->clear(); // clear intermediate
298  else
299  break;
300  }
301 
302  __p->clear(); // clear last
303  }
304  }
305  }
306 }
307 
308 #endif
Acoustic counter.
int getOverlays() const
Get overlays.
void overlap(T p, T q, const double Tmax_s)
Empty overlapping events.
Acoustic counter.
void merge(const JEvent &event)
Merge event.
JEvaluator()
Default constructor.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition: JHead.hh:1741
JEvent()
Default constructor.
ClassDef(JEvent, 3)
Definition: JRoot.hh:19
friend std::ostream & operator<<(std::ostream &out, const JEvent &event)
Write event to output stream.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
const std::string & getOID() const
Get detector identifier.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
then awk string
virtual ~JEvent()
Virtual destructor.
int getCounter() const
Get counter.
Acoustic transmission.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
Acoustic event.
JEvent(const std::string &oid, const int counter, const int id, T __begin, T __end)
Constructor.
int getID() const
Get identifier.
Auxiliary class to determine value of acoustic events.
double operator()(const JEvent &event) const
Get value of object.