Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JFrame.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JFRAME__
2 #define __JTRIGGER__JFRAME__
3 
4 #include <vector>
5 
8 #include "JTrigger/JMatch.hh"
9 #include "JTrigger/JPMTHeader.hh"
10 #include "JTrigger/JHitToolkit.hh"
11 #include "JTrigger/JCalibration.hh"
12 #include "JLang/JSTDToolkit.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JTRIGGER {}
20 namespace JPP { using namespace JTRIGGER; }
21 
22 namespace JTRIGGER {
23 
24  using KM3NETDAQ::JDAQHit;
25 
26 
27  /**
28  * Data frame for calibrated hits of one PMT.
29  *
30  * Note that the calibration is applied on the fly in the member method JFrame::push_back.
31  */
32  template<class JElement_t, class JAllocator_t = std::allocator<JElement_t> >
33  class JFrame :
34  public JPMTHeader,
35  public JCalibration,
36  public std::vector<JElement_t, JAllocator_t>,
37  public JHitToolkit<JElement_t>
38  {
39  public:
40 
42  typedef JElement_t value_type;
44 
45  typedef typename container_type::iterator iterator;
46  typedef typename container_type::const_iterator const_iterator;
47  typedef typename container_type::reverse_iterator reverse_iterator;
48  typedef typename container_type::const_reverse_iterator const_reverse_iterator;
49 
50  using container_type::push_back;
52 
53 
54  /**
55  * Default constructor.
56  */
57  JFrame() :
58  JPMTHeader (),
59  JCalibration(),
60  std::vector<JElement_t, JAllocator_t>(),
61  JHitToolkit<JElement_t>()
62  {}
63 
64 
65  /**
66  * Constructor.
67  *
68  * \param chronometer DAQ chronometer
69  * \param id PMT identifier
70  * \param axis PMT axis
71  * \param calibration calibration
72  */
73  JFrame(const JDAQChronometer& chronometer,
74  const JDAQPMTIdentifier& id,
75  const JAxis3D& axis,
76  const JCalibration& calibration) :
77  JPMTHeader (chronometer, id, axis),
78  JCalibration(calibration),
79  std::vector<JElement_t, JAllocator_t>(),
80  JHitToolkit<JElement_t>()
81  {}
82 
83 
84  /**
85  * Append DAQ hit.
86  *
87  * The time calibration is applied before the hit is appended.
88  *
89  * \param hit DAQ hit
90  */
91  void push_back(const JDAQHit& hit)
92  {
93  container_type::push_back(this->getHit(hit, this->getCalibration()));
94  }
95 
96 
97  /**
98  * Check presence of end marker.
99  *
100  * \return true if end marker present; else false
101  */
102  bool hasEndMarker() const
103  {
104  return (this->capacity() > this->size() && this->getT(*(this->end())) == this->getT(this->getEndMarker()));
105  }
106 
107 
108  /**
109  * Append end marker to data.
110  *
111  * Note that the end marker is put within the capacity of the container whilst its size is maintained.
112  */
113  void putEndMarker()
114  {
115  JPP::putEndMarker(*this, this->getEndMarker());
116  }
117 
118 
119  /**
120  * Reset.
121  *
122  * Clear container and put end marker.
123  */
124  void reset()
125  {
126  this->clear();
127  this->putEndMarker();
128  }
129 
130 
131  /**
132  * Apply high-rate veto.
133  *
134  * If vetoed, the container is cleared and an end marker is put.
135  *
136  * \param rate_Hz high-rate veto [Hz]
137  */
138  void applyHighRateVeto(const double rate_Hz)
139  {
141 
142  if (this->size() * 1.0e9 / getFrameTime() > rate_Hz) {
143  this->reset();
144  }
145  }
146 
147 
148  /**
149  * Join consecutive hits when matched according given criterion.
150  *
151  * \param match match criterion
152  */
153  void join(const match_type& match)
154  {
155  iterator out = this->begin();
156 
157  for (const_iterator p = this->begin(); p != this->end(); ) {
158 
159  *out = *p;
160 
161  while (++p != this->end() && match(*out,*p)) {
162  *out = join(*out,*p);
163  }
164 
165  ++out;
166  }
167 
168  if (out != this->end()) {
169  this->erase(out, this->end());
170  this->putEndMarker();
171  }
172  }
173 
174 
175  /**
176  * Filter-out consecutive hits when matched according given criterion.
177  *
178  * Note that all hits which are matched are removed.
179  *
180  * \param match match criterion
181  */
182  void filter(const match_type& match)
183  {
184  iterator out = this->begin();
185 
186  for (const_iterator p = this->begin(); p != this->end(); ) {
187 
188  const_iterator q = p;
189 
190  for (const_iterator i = p; ++q != this->end() && match(*i,*q); ++i) {}
191 
192  if (std::distance(p,q) == 1) {
193  *out = *p;
194  ++out;
195  }
196 
197  p = q;
198  }
199 
200  if (out != this->end()) {
201  this->erase(out, this->end());
202  this->putEndMarker();
203  }
204  }
205  };
206 }
207 
208 #endif
container_type::const_iterator const_iterator
Definition: JFrame.hh:46
void join(const match_type &match)
Join consecutive hits when matched according given criterion.
Definition: JFrame.hh:153
std::vector< JElement_t, JAllocator_t > container_type
Definition: JFrame.hh:41
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
const JCalibration & getCalibration() const
Get calibration.
bool hasEndMarker() const
Check presence of end marker.
Definition: JFrame.hh:102
Header for PMT.
Definition: JPMTHeader.hh:26
JElement_t value_type
Definition: JFrame.hh:42
Function object interface for hit matching.
Definition: JMatch.hh:25
Data structure for time calibration.
Tools for handling different hit types.
container_type::reverse_iterator reverse_iterator
Definition: JFrame.hh:47
Axis object.
Definition: JAxis3D.hh:38
JFrame(const JDAQChronometer &chronometer, const JDAQPMTIdentifier &id, const JAxis3D &axis, const JCalibration &calibration)
Constructor.
Definition: JFrame.hh:73
Base class for match operations for cluster and hit-preprocessing methods.
Hit data structure.
Definition: JDAQHit.hh:34
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
Data frame for calibrated hits of one PMT.
Definition: JFrame.hh:33
void filter(const match_type &match)
Filter-out consecutive hits when matched according given criterion.
Definition: JFrame.hh:182
JFrame()
Default constructor.
Definition: JFrame.hh:57
container_type::const_reverse_iterator const_reverse_iterator
Definition: JFrame.hh:48
void reset()
Reset.
Definition: JFrame.hh:124
container_type::iterator iterator
Definition: JFrame.hh:45
Template definition of hit toolkit.
Definition: JHitToolkit.hh:60
JMatch< value_type > match_type
Definition: JFrame.hh:43
void putEndMarker(std::vector< JElement_t, JAllocator_t > &buffer, const JElement_t &value)
Put end marker.
Definition: JSTDToolkit.hh:47
void putEndMarker()
Append end marker to data.
Definition: JFrame.hh:113
void applyHighRateVeto(const double rate_Hz)
Apply high-rate veto.
Definition: JFrame.hh:138
void push_back(const JDAQHit &hit)
Append DAQ hit.
Definition: JFrame.hh:91