Jpp - 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 
18 /**
19  * \file
20  *
21  * Acoustic event.
22  * \author mdejong
23  */
24 namespace JACOUSTICS {}
25 namespace JPP { using namespace JACOUSTICS; }
26 
27 namespace JACOUSTICS {
28 
29  /**
30  * Acoustic event.
31  */
32  struct JEvent :
33  public JCounter,
34  public std::vector<JTransmission>,
35  public TObject
36  {
37  /**
38  * Auxiliary class to determine value of acoustic events.\n
39  * This class can be used with JSUPPORT::JTreeScanner so to read acoustics events in order of time-of-emission.
40  */
41  struct JEvaluator {
42  /**
43  * Default constructor.
44  */
46  {}
47 
48 
49  /**
50  * Get value of object.
51  *
52  * \param event event
53  * \return value
54  */
55  inline double operator()(const JEvent& event) const
56  {
57  return event.begin()->getToE();
58  }
59  };
60 
61 
62  /**
63  * Default constructor.
64  */
65  JEvent() :
66  JCounter(),
67  overlays(0),
68  id (-1)
69  {}
70 
71 
72  /**
73  * Constructor.
74  *
75  * The transmissions will be sorted to ensure proper functioning of method JEvent::merge and class JEventOverlap.
76  *
77  * \param oid detector identifier
78  * \param counter counter
79  * \param id identifier
80  * \param __begin begin of data
81  * \param __end end of data
82  */
83  template<class T>
84  JEvent(const std::string& oid,
85  const int counter,
86  const int id,
87  T __begin,
88  T __end) :
89  JCounter(counter),
90  oid (oid),
91  overlays(0),
92  id (id)
93  {
94  using namespace std;
95 
96  for (T i = __begin; i != __end; ++i) {
97  push_back(*i);
98  }
99 
100  sort(this->begin(), this->end());
101  }
102 
103 
104  /**
105  * Virtual destructor.
106  */
107  virtual ~JEvent()
108  {}
109 
110 
111  /**
112  * Get detector identifier.
113  *
114  * \return detector identifier.
115  */
116  const std::string& getOID() const
117  {
118  return oid;
119  }
120 
121 
122  /**
123  * Get counter.
124  *
125  * \return counter
126  */
127  int getCounter() const
128  {
129  return counter;
130  }
131 
132 
133  /**
134  * Get overlays.
135  *
136  * \return overlays
137  */
138  int getOverlays() const
139  {
140  return overlays;
141  }
142 
143 
144  /**
145  * Get identifier.
146  *
147  * \return identifier
148  */
149  int getID() const
150  {
151  return id;
152  }
153 
154 
155  /**
156  * Merge event.
157  *
158  * \param event event
159  */
160  void merge(const JEvent& event)
161  {
162  using namespace std;
163 
164  vector<JTransmission> buffer;
165 
166  const_iterator __hit1 = this ->begin();
167  const_iterator __end1 = this ->end();
168 
169  const_iterator __hit2 = event.begin();
170  const_iterator __end2 = event.end();
171 
172  buffer.resize(this->size() + event.size());
173 
174  iterator out = buffer.begin();
175 
176  while (__hit1 != __end1 && __hit2 != __end2) {
177 
178  if (*__hit1 < *__hit2) {
179 
180  *out = *__hit1;
181  ++__hit1;
182 
183  } else if (*__hit2 < *__hit1) {
184 
185  *out = *__hit2;
186  ++__hit2;
187 
188  } else {
189 
190  *out = *__hit1;
191 
192  ++__hit1;
193  ++__hit2;
194  }
195 
196  ++out;
197  }
198 
199  // append remaining hits from either set
200 
201  out = copy(__hit1, __end1, out);
202  out = copy(__hit2, __end2, out);
203 
204  buffer.resize(distance(buffer.begin(), out));
205 
206  this->swap(buffer);
207 
208  ++overlays;
209  }
210 
211 
212  /**
213  * Write event to output stream.
214  *
215  * \param out output stream
216  * \param event event
217  * \return output stream
218  */
219  friend inline std::ostream& operator<<(std::ostream& out, const JEvent& event)
220  {
221  using namespace std;
222 
223  out << event.getOID() << endl;
224  out << setw(8) << event.getCounter() << endl;
225  out << setw(2) << event.getOverlays() << endl;
226  out << setw(3) << event.getID() << endl;
227 
228  for (const_iterator i = event.begin(); i != event.end(); ++i) {
229 
230  out << setw(10) << i->getID() << ' '
231  << setw(10) << i->getRunNumber() << ' '
232  << fixed << setw(12) << setprecision(6) << i->getToA() << ' '
233  << fixed << setw(12) << setprecision(6) << i->getToE() << ' '
234  << fixed << setw(8) << setprecision(0) << i->getQ() << endl;
235  }
236 
237  return out;
238  }
239 
240  ClassDef(JEvent, 2);
241 
242  protected:
243  std::string oid;
244  int overlays;
245  int id;
246  };
247 
248 
249  /**
250  * Less than operator for acoustics events.
251  *
252  * The less than operator is applied to the first hit in the events.\n
253  * If there are no hits in either event, the counter of the events is used.
254  *
255  * \param first first event
256  * \param second second event
257  * \return true if first event earliear than second; else false
258  */
259  inline bool operator<(const JEvent& first, const JEvent& second)
260  {
261  if (!first.empty() && !second.empty())
262  return first.begin()->getToE() < second.begin()->getToE();
263  else
264  return first.getCounter() < second.getCounter();
265  }
266 }
267 
268 #endif
Acoustic counter.
int getOverlays() const
Get overlays.
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:1603
JEvent()
Default constructor.
ClassDef(JEvent, 2)
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
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.