Pottu
DetectorEvent.hpp
Go to the documentation of this file.
1 
6 #ifndef H_DETECTOREVENT
7 #define H_DETECTOREVENT
8 
9 #include "dataitem.hpp"
10 
11 
12 #include <cstring>
13 #include <memory>
14 #include <vector>
15 
16 
17 namespace pottu {
18 
47  {
48  public:
49 
50  using group_type = int16_t;
51  using coord_type = int16_t;
52 
63  return DetectorEvent();
64  }
65 
69  struct compTimeLess {
70  bool operator()( const DetectorEvent &det1, const DetectorEvent &det2 ) const noexcept {
71  return det1.time < det2.time;
72  }
73  };
74 
78  struct compTimeGreater {
79  bool operator()( const DetectorEvent &det1, const DetectorEvent &det2 ) const noexcept {
80  return det1.time > det2.time;
81  }
82  };
83 
87  struct compCoordLess {
88  bool operator()( const DetectorEvent &det1, const DetectorEvent &det2 ) const noexcept {
89  return det1.coord < det2.coord;
90  }
91  };
92 
94  enum flags : uint16_t {
95  FLAG_PILEUP = 1 << 0,
96  FLAG_OVERRANGE = 1 << 1,
97  FLAG_UNDERRANGE = 1 << 2,
98  FLAG_OVERFLOW = 1 << 3,
99  FLAG_UNDERFLOW = 1 << 4,
100  FLAG_FAIL = 1 << 5,
101  FLAG_VETO = 1 << 6,
102  FLAG_INVALID = 1 << 15
103  };
104 
105  // /** \brief Clears all the members to zero. */
106  //void clear() { std::memset( this, 0, sizeof(DetectorEvent) ); }
107 
108  void markPileup() noexcept { flags |= FLAG_PILEUP; }
109  void markOverrange() noexcept { flags |= FLAG_OVERRANGE; }
110  void markUnderrange()noexcept { flags |= FLAG_UNDERRANGE; }
111  void markOverflow() noexcept { flags |= FLAG_OVERFLOW; }
112  void markUnderflow() noexcept { flags |= FLAG_UNDERFLOW; }
113  void markVeto() noexcept { flags |= FLAG_VETO; }
114  void markFail() noexcept { flags |= FLAG_FAIL; }
115  void markInvalid() noexcept { flags |= FLAG_INVALID; }
116 
117  bool pileup() const noexcept { return flags & FLAG_PILEUP; }
118  bool overrange() const noexcept { return flags & FLAG_OVERRANGE; }
119  bool underrange() const noexcept { return flags & FLAG_UNDERRANGE; }
120  bool overflow() const noexcept { return flags & FLAG_OVERFLOW; }
121  bool underflow() const noexcept { return flags & FLAG_UNDERFLOW; }
122  bool fail() const noexcept { return flags & FLAG_FAIL; }
123  bool veto() const noexcept { return flags & FLAG_VETO; }
124  bool good() const noexcept { return flags == 0; }
125 
128  bool invalid() const noexcept { return flags & FLAG_INVALID; }
129 
134  explicit operator bool() const { return !invalid(); }
135 
136  int64_t time{0};
137 
138  uint16_t ch{0};
139  uint16_t adc{0};
140  uint16_t flags{FLAG_INVALID};
141 
142  // Detector group index
143  uint16_t group{0};
144 
145  // Coordinate in detector group
146  uint16_t coord{0};
147 
148  // Calibrated energy
149  float e{0};
150 
151 
152 #if POTTU_ENABLE_TRACES
153  std::vector<uint16_t> trace;
154 #endif
155 
156  };
157 
158 
159 
162  struct SelectorGroup {
163  DetectorEvent::group_type group;
164 
170  bool operator()( const DetectorEvent &det ) const noexcept {
171  return det.group == group;
172  }
173  };
174 
178  DetectorEvent::group_type group;
179  DetectorEvent::coord_type coord;
180 
186  bool operator()( const DetectorEvent &det ) const noexcept {
187  return det.group == group && det.coord == coord;
188  }
189  };
190 
191 
195  uint16_t ch;
196 
202  bool operator()( const DetectorEvent &det ) const noexcept {
203  return det.ch == ch;
204  }
205  };
206 
207 
219  DetectorEvent::group_type group;
220  double eLow;
221  double eHigh;
222 
228  bool operator()( const DetectorEvent &det ) const noexcept {
229  return det.group == group && det.e >= eLow && det.e < eHigh;
230  }
231  };
232 
233 
234 
237  struct EventOpEnergy {
243  double operator()( const DetectorEvent &det ) const noexcept {
244  return det.e;
245  }
246  };
247 
248 
251  struct EventOpADC {
257  double operator()( const DetectorEvent &det ) const noexcept {
258  return det.adc;
259  }
260  };
261 
262 
263 
264 
265 
266 }
267 
268 
269 
270 #endif
Event containing event information of one daq channel.
Definition: DetectorEvent.hpp:47
bool invalid() const noexcept
Checks if the detector event is marked invalid.
Definition: DetectorEvent.hpp:128
flags
Flag values used in the bitmask field flags.
Definition: DetectorEvent.hpp:94
static DetectorEvent createInvalid()
Creates a new detector event.
Definition: DetectorEvent.hpp:62
Defines the raw low level dataitems used in tdr datastreams and files.
Definition: mainpage.dox:6
Functor to compare DetectorEvent instances based on coord field (as std::greater<>).
Definition: DetectorEvent.hpp:87
Functor to compare DetectorEvent instances based on time field (as std::greater<>).
Definition: DetectorEvent.hpp:78
Functor to compare DetectorEvent instances based on time field (as std::less<>).
Definition: DetectorEvent.hpp:69
Detector event operation which extracts adc value.
Definition: DetectorEvent.hpp:251
double operator()(const DetectorEvent &det) const noexcept
Extract the adc value from a DetectorEvent.
Definition: DetectorEvent.hpp:257
Detector event operation which extracts energy.
Definition: DetectorEvent.hpp:237
double operator()(const DetectorEvent &det) const noexcept
Extract the energy from a DetectorEvent.
Definition: DetectorEvent.hpp:243
Detector event filter for DAQ channel.
Definition: DetectorEvent.hpp:194
bool operator()(const DetectorEvent &det) const noexcept
Tests if event passes the filter.
Definition: DetectorEvent.hpp:202
Detector event filter for detector group and coordinate.
Definition: DetectorEvent.hpp:177
bool operator()(const DetectorEvent &det) const noexcept
Tests if event passes the filter.
Definition: DetectorEvent.hpp:186
Detector event filter for group index and energy.
Definition: DetectorEvent.hpp:218
bool operator()(const DetectorEvent &det) const noexcept
Tests if event passes the filter.
Definition: DetectorEvent.hpp:228
Detector event filter for detector group.
Definition: DetectorEvent.hpp:162
bool operator()(const DetectorEvent &det) const noexcept
Tests if event passes the filter.
Definition: DetectorEvent.hpp:170