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