Jpp  16.0.0
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 #include <algorithm>
10 
11 #include <TROOT.h>
12 #include <TObject.h>
13 
14 #include "JAcoustics/JCounter.hh"
16 
17 #include "JTools/JQuantile.hh"
18 
19 
20 /**
21  * \file
22  *
23  * Acoustic event.
24  * \author mdejong
25  */
26 namespace JACOUSTICS {}
27 namespace JPP { using namespace JACOUSTICS; }
28 
29 namespace JACOUSTICS {
30 
31  /**
32  * Acoustic event.
33  */
34  struct JEvent :
35  public JCounter,
36  public std::vector<JTransmission>,
37  public TObject
38  {
39  /**
40  * Auxiliary class to determine value of acoustic events.\n
41  * This class can be used with JSUPPORT::JTreeScanner so to read acoustics events in order of time-of-emission.
42  */
43  struct JEvaluator {
44  /**
45  * Default constructor.
46  */
48  {}
49 
50 
51  /**
52  * Get value of object.
53  *
54  * \param event event
55  * \return value
56  */
57  inline double operator()(const JEvent& event) const
58  {
59  return event.begin()->getToE();
60  }
61  };
62 
63 
64  /**
65  * Default constructor.
66  */
67  JEvent() :
68  JCounter(),
69  overlays(0),
70  id (-1)
71  {}
72 
73 
74  /**
75  * Constructor.
76  *
77  * The transmissions will be sorted to ensure proper functioning of method JEvent::merge and class JEventOverlap.
78  *
79  * \param oid detector identifier
80  * \param counter counter
81  * \param id identifier
82  * \param __begin begin of data
83  * \param __end end of data
84  */
85  template<class T>
86  JEvent(const std::string& oid,
87  const int counter,
88  const int id,
89  T __begin,
90  T __end) :
91  JCounter(counter),
92  oid (oid),
93  overlays(0),
94  id (id)
95  {
96  using namespace std;
97 
98  for (T i = __begin; i != __end; ++i) {
99  push_back(*i);
100  }
101 
102  sort(this->begin(), this->end());
103  }
104 
105 
106  /**
107  * Virtual destructor.
108  */
109  virtual ~JEvent()
110  {}
111 
112 
113  /**
114  * Get detector identifier.
115  *
116  * \return detector identifier.
117  */
118  const std::string& getOID() const
119  {
120  return oid;
121  }
122 
123 
124  /**
125  * Get counter.
126  *
127  * \return counter
128  */
129  int getCounter() const
130  {
131  return counter;
132  }
133 
134 
135  /**
136  * Get overlays.
137  *
138  * \return overlays
139  */
140  int getOverlays() const
141  {
142  return overlays;
143  }
144 
145 
146  /**
147  * Get 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 
169  vector<JTransmission> buffer;
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  * Remove outliers.
219  *
220  * First, the transmissions are sorted according to their time-of-emission.
221  * The mean and standard deviation of the times of emission is then determined,
222  * excluding the first and last possible number of outliers from either side.
223  * From the excluded transmissions, the ones with a time-of-emission less than
224  * the given number of standard deviations away from the mean are retained.
225  *
226  * \param ns number of outliers
227  * \param stdev number of standard deviations
228  */
229  void remove(const size_t ns, const double stdev)
230  {
231  using namespace std;
232  using namespace JPP;
233 
234  if (ns > 0 && 2*ns < this->size()) {
235 
236  sort(this->begin(), this->end());
237 
238  iterator p = this->begin();
239  reverse_iterator q = this->rbegin();
240 
241  advance(p, ns);
242  advance(q, ns);
243 
244  JQuantile Q;
245 
246  for (const_iterator i = p; i != q.base(); ++i) {
247  Q.put(i->getToE());
248  }
249 
250  const double t1 = Q.getMean() - stdev * Q.getSTDev();
251  const double t2 = Q.getMean() + stdev * Q.getSTDev();
252 
253  for (size_t i = ns; i != 0 && p->getToE() >= t1; --i, --p) {}
254  for (size_t i = ns; i != 0 && q->getToE() <= t2; --i, --q) {}
255 
256  vector<JTransmission> buffer(p, q.base());
257 
258  this->swap(buffer);
259  }
260  }
261 
262 
263  /**
264  * Write event to output stream.
265  *
266  * \param out output stream
267  * \param event event
268  * \return output stream
269  */
270  friend inline std::ostream& operator<<(std::ostream& out, const JEvent& event)
271  {
272  using namespace std;
273 
274  out << event.getOID() << endl;
275  out << setw(8) << event.getCounter() << endl;
276  out << setw(2) << event.getOverlays() << endl;
277  out << setw(3) << event.getID() << endl;
278 
279  for (const_iterator i = event.begin(); i != event.end(); ++i) {
280 
281  out << setw(10) << i->getID() << ' '
282  << setw(10) << i->getRunNumber() << ' '
283  << fixed << setw(12) << setprecision(6) << i->getToA() << ' '
284  << fixed << setw(12) << setprecision(6) << i->getToE() << ' '
285  << fixed << setw(8) << setprecision(0) << i->getQ() << endl;
286  }
287 
288  return out;
289  }
290 
291  ClassDef(JEvent, 2);
292 
293  protected:
294  std::string oid;
295  int overlays;
296  int id;
297  };
298 
299 
300  /**
301  * Less than operator for acoustics events.
302  *
303  * The less than operator is applied to the first hit in the events.\n
304  * If there are no hits in either event, the counter of the events is used.
305  *
306  * \param first first event
307  * \param second second event
308  * \return true if first event earliear than second; else false
309  */
310  inline bool operator<(const JEvent& first, const JEvent& second)
311  {
312  if (!first.empty() && !second.empty())
313  return first.begin()->getToE() < second.begin()->getToE();
314  else
315  return first.getCounter() < second.getCounter();
316  }
317 }
318 
319 #endif
Acoustic counter.
int getOverlays() const
Get overlays.
Q(UTCMax_s-UTCMin_s)-livetime_s
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:1678
JEvent()
Default constructor.
ClassDef(JEvent, 2)
stdev
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
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
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:139
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.