Pixie16 Analysis Software Suite
Analysis code for processing of .ldf files
Places.hpp
Go to the documentation of this file.
1 
6 #ifndef __PLACES_HPP__
7 #define __PLACES_HPP__
8 
9 #include <deque>
10 #include <iostream>
11 #include <vector>
12 #include <utility>
13 
14 #include <cstdlib>
15 
16 #include "Globals.hpp"
17 #include "EventData.hpp"
18 
24 class Place {
25 public:
30  Place(bool resetable = true, unsigned max_size = 2) {
32  max_size_ = max_size;
33  status_ = false;
34  }
36  virtual ~Place() {};
37 
44  virtual void addChild(Place* child, bool coin = true);
45 
50  virtual bool checkChildren(Place* child);
51 
56  virtual bool checkParents(Place* child);
57 
61  virtual void activate(EventData& info) {
62  if(!status_) {
63  status_ = true;
64  add_info_(info);
65  report_(info);
66  } else {
67  add_info_(info);
68  }
69  }
73  virtual void activate(double time) {
74  EventData info(time);
75  activate(info);
76  }
77 
81  virtual void deactivate(double time) {
82  if(status_) {
83  status_ = false;
84  EventData info(time, status_);
85  add_info_(info);
86  report_(info);
87  }
88  else {
89  EventData info(time, status_);
90  add_info_(info);
91  }
92  }
97  virtual void reset() { status_ = false; };
98 
101  virtual bool operator&& (const Place& right) const {
102  return (*this)() && right();
103  }
104 
107  virtual bool operator|| (const Place& right) const {
108  return (*this)() || right();
109  }
110 
112  virtual bool operator()() const {
113  return status_;
114  }
115 
117  virtual bool status() const {
118  return (*this)();
119  }
120 
125  virtual EventData& operator [](unsigned index) {
126  return info_.at(index);
127  }
128 
133  virtual EventData operator [](unsigned index) const {
134  return info_.at(index);
135  }
136 
140  virtual EventData last() {
141  if(info_.size() > 0)
142  return info_.back();
143  else {
144  EventData empty(-1);
145  return empty;
146  }
147  }
148 
152  virtual EventData secondlast() {
153  if(info_.size() > 1) {
154  unsigned sz = info_.size();
155  return info_.at(sz - 2);
156  }
157  else {
158  EventData empty(-1);
159  return empty;
160  }
161  }
162 
168  virtual bool resetable() const {
169  return resetable_;
170  }
174  std::deque<EventData> info_;
175 
176 protected:
181  virtual void check_(EventData& info) = 0;
183  unsigned max_size_;
184 
189  virtual void addParent_(Place* parent) {
190  parents_.push_back(parent);
191  }
192 
197  virtual void report_(EventData& info) {
198  std::vector<Place*>::iterator it;
199  for(it = parents_.begin(); it != parents_.end(); ++it)
200  (*it)->check_(info);
201  }
202 
205  virtual void add_info_(const EventData& info) {
206  info_.push_back(info);
207  while(info_.size() > max_size_)
208  info_.pop_front();
209  }
210 
213  bool status_;
214 
218 
224  std::vector< std::pair<Place*, bool> > children_;
225 
229  std::vector<Place*> parents_;
230 };
231 
234 class PlaceLazy : public Place {
235 public:
239  PlaceLazy(bool resetable = true, unsigned max_size = 2) :
240  Place(resetable, max_size) {}
241 
245  virtual void activate(EventData& info) {
246  if(!status_) {
247  status_ = true;
248  add_info_(info);
249  report_(info);
250  }
251  }
255  virtual void deactivate(double time) {
256  if(status_) {
257  status_ = false;
258  EventData info(time, status_);
259  add_info_(info);
260  report_(info);
261  }
262  }
263 };
264 
267 class PlaceDetector : public Place {
268 public:
272  PlaceDetector(bool resetable = true, unsigned max_size = 2) :
273  Place(resetable, max_size) {}
274 protected:
277  virtual void check_(EventData& info){};
278 };
279 
281 class PlaceThreshold : public Place {
282 public:
290  PlaceThreshold(double low_limit, double high_limit, bool resetable = true,
291  unsigned max_size = 2) : Place(resetable, max_size) {
292  low_limit_ = low_limit;
293  high_limit_ = high_limit;
294  }
295 
298  void activate(EventData& info) {
299  if(low_limit_ == 0 && high_limit_ == 0)
300  Place::activate(info);
301  else if(info.energy > low_limit_ && info.energy < high_limit_)
302  Place::activate(info);
303  }
304 
306  double getLowLimit() {return low_limit_; };
307 
309  double getHighLimit() { return high_limit_; };
310 
311 protected:
315  virtual void check_(EventData& info){};
316 
317  double low_limit_;
318  double high_limit_;
319 };
320 
323 public:
331  PlaceThresholdOR(double low_limit, double high_limit, bool resetable = true,
332  unsigned max_size = 2)
333  : PlaceThreshold(low_limit, high_limit, resetable, max_size) {
334  };
335 
336 protected:
339  virtual void check_(EventData& info);
340 };
341 
343 class PlaceCounter : public Place {
344 public:
348  PlaceCounter(bool resetable = true, unsigned max_size = 2)
349  : Place(resetable, max_size) {
350  counter_ = 0;
351  }
352 
355  void activate(EventData& info) {
356  ++counter_;
357  Place::activate(info);
358  }
359 
362  void deactivate(double time) {
363  --counter_;
364  Place::deactivate(time);
365  }
366 
368  void reset() {
369  Place::reset();
370  counter_ = 0;
371  }
372 
374  virtual int getCounter() const {
375  return counter_;
376  }
377 
378 protected:
379  int counter_;
380 
383  virtual void check_(EventData& info);
384 };
385 
394 class PlaceOR : public Place {
395 public:
399  PlaceOR(bool resetable = true, unsigned max_size = 2) :
400  Place(resetable, max_size) {}
401 protected:
411  virtual void check_(EventData& info);
412 };
413 
421 class PlaceAND : public Place {
422 public:
426  PlaceAND(bool resetable = true, unsigned max_size = 2) :
427  Place(resetable, max_size) {}
428 protected:
434  virtual void check_(EventData& info);
435 };
436 #endif
virtual void add_info_(const EventData &info)
Definition: Places.hpp:205
PlaceThresholdOR(double low_limit, double high_limit, bool resetable=true, unsigned max_size=2)
Definition: Places.hpp:331
Each activation must be within the set thresholds.
Definition: Places.hpp:281
Structure holding event data.
"Lazy" Place does not store multiple activation or deactivation events. Abstract class.
Definition: Places.hpp:234
virtual void activate(EventData &info)
Definition: Places.hpp:245
virtual bool operator&&(const Place &right) const
Definition: Places.hpp:101
void deactivate(double time)
Definition: Places.hpp:362
The basic detector which does not depend on children status. Will use info_ map to store additional i...
Definition: Places.hpp:267
PlaceDetector(bool resetable=true, unsigned max_size=2)
Definition: Places.hpp:272
Similar to PlaceOR but uses AND relation.
Definition: Places.hpp:421
Each activation must be within the set thresholds.
Definition: Places.hpp:322
std::deque< EventData > info_
Definition: Places.hpp:174
bool status_
Definition: Places.hpp:213
virtual void activate(double time)
Definition: Places.hpp:73
virtual void check_(EventData &info)
Definition: Places.hpp:277
A pure abstract class to define a "place" for correlator.
Definition: Places.hpp:24
virtual void addChild(Place *child, bool coin=true)
virtual bool resetable() const
Definition: Places.hpp:168
PlaceOR(bool resetable=true, unsigned max_size=2)
Definition: Places.hpp:399
virtual void report_(EventData &info)
Definition: Places.hpp:197
virtual void check_(EventData &info)
virtual int getCounter() const
Definition: Places.hpp:374
virtual bool status() const
Definition: Places.hpp:117
virtual EventData secondlast()
Definition: Places.hpp:152
double low_limit_
low limit for the threshold
Definition: Places.hpp:315
PlaceCounter(bool resetable=true, unsigned max_size=2)
Definition: Places.hpp:348
constant parameters used in pixie16 analysis
int counter_
The counter for the place activation.
Definition: Places.hpp:379
virtual bool operator()() const
Definition: Places.hpp:112
PlaceThreshold(double low_limit, double high_limit, bool resetable=true, unsigned max_size=2)
Definition: Places.hpp:290
bool resetable_
Definition: Places.hpp:217
void activate(EventData &info)
Definition: Places.hpp:355
virtual bool checkChildren(Place *child)
virtual EventData last()
Definition: Places.hpp:140
std::vector< std::pair< Place *, bool > > children_
Definition: Places.hpp:224
virtual void reset()
Definition: Places.hpp:97
virtual void check_(EventData &info)
Checks to see if a place is active.
virtual void addParent_(Place *parent)
Definition: Places.hpp:189
An abstract place using OR logic to set the activation of places.
Definition: Places.hpp:394
virtual bool operator||(const Place &right) const
Definition: Places.hpp:107
virtual void check_(EventData &info)
virtual EventData & operator[](unsigned index)
Definition: Places.hpp:125
PlaceLazy(bool resetable=true, unsigned max_size=2)
Definition: Places.hpp:239
virtual void deactivate(double time)
Definition: Places.hpp:81
Simple structure holding basic parameters needed for correlation of events in the same place...
Definition: EventData.hpp:12
unsigned max_size_
Definition: Places.hpp:183
void activate(EventData &info)
Definition: Places.hpp:298
virtual void check_(EventData &info)=0
virtual void activate(EventData &info)
Definition: Places.hpp:61
double high_limit_
high limit for the threshold
Definition: Places.hpp:318
double getLowLimit()
Definition: Places.hpp:306
void reset()
Definition: Places.hpp:368
virtual void check_(EventData &info)
Does not depend on children. If you need some behaviour derive a new class from this one...
Definition: Places.hpp:315
double energy
the energy of the event
Definition: EventData.hpp:48
Counts number of activations coming from directly or from children.
Definition: Places.hpp:343
virtual void deactivate(double time)
Definition: Places.hpp:255
std::vector< Place * > parents_
Definition: Places.hpp:229
PlaceAND(bool resetable=true, unsigned max_size=2)
Definition: Places.hpp:426
virtual void check_(EventData &info)
Checks if the OR should be activated or not.
virtual bool checkParents(Place *child)
virtual ~Place()
Definition: Places.hpp:36
double getHighLimit()
Definition: Places.hpp:309
Place(bool resetable=true, unsigned max_size=2)
Definition: Places.hpp:30