Jpp  pmt_effective_area_update_2
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 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace JTRIGGER {}
19 namespace JPP { using namespace JTRIGGER; }
20 
21 namespace JTRIGGER {
22 
23  using KM3NETDAQ::JDAQHit;
24 
25 
26  /**
27  * Data frame for calibrated hits of one PMT.
28  *
29  * Note that the calibration is applied on the fly in the method JFrame::push_back.
30  */
31  template<class JElement_t, class JAllocator_t = std::allocator<JElement_t> >
32  class JFrame :
33  public JPMTHeader,
34  public JCalibration,
35  public std::vector<JElement_t, JAllocator_t>,
36  public JHitToolkit<JElement_t>
37  {
38  public:
39 
41  typedef JElement_t value_type;
43 
44  typedef typename container_type::iterator iterator;
45  typedef typename container_type::const_iterator const_iterator;
46  typedef typename container_type::reverse_iterator reverse_iterator;
47  typedef typename container_type::const_reverse_iterator const_reverse_iterator;
48 
49  using container_type::push_back;
51 
52 
53  /**
54  * Default constructor.
55  */
56  JFrame() :
57  JPMTHeader (),
58  JCalibration(),
59  std::vector<JElement_t, JAllocator_t>(),
60  JHitToolkit<JElement_t>()
61  {}
62 
63 
64  /**
65  * Constructor.
66  *
67  * \param chronometer DAQ chronometer
68  * \param id PMT identifier
69  * \param axis PMT axis
70  * \param calibration calibration
71  */
72  JFrame(const JDAQChronometer& chronometer,
73  const JDAQPMTIdentifier& id,
74  const JAxis3D& axis,
75  const JCalibration& calibration) :
76  JPMTHeader (chronometer, id, axis),
77  JCalibration(calibration),
78  std::vector<JElement_t, JAllocator_t>(),
79  JHitToolkit<JElement_t>()
80  {}
81 
82 
83  /**
84  * Append DAQ hit.
85  *
86  * The time calibration is applied before the hit is appended.
87  *
88  * \param hit DAQ hit
89  */
90  void push_back(const JDAQHit& hit)
91  {
92  container_type::push_back(this->getHit(hit, this->getCalibration()));
93  }
94 
95 
96  /**
97  * Append end marker to data.
98  */
99  void putEndMarker()
100  {
101  container_type::push_back(this->getEndMarker());
102  }
103 
104 
105  const_iterator u_begin() const { return container_type::begin(); } //!< iterator without end marker
106  const_iterator u_end() const { return container_type::end() - 1; } //!< iterator without end marker
107  iterator u_begin() { return container_type::begin(); } //!< iterator without end marker
108  iterator u_end() { return container_type::end() - 1; } //!< iterator without end marker
109 
110  const_reverse_iterator u_rbegin() const { return container_type::rbegin() + 1; } //!< iterator without end marker
111  const_reverse_iterator u_rend() const { return container_type::rend(); } //!< iterator without end marker
112  reverse_iterator u_rbegin() { return container_type::rbegin() + 1; } //!< iterator without end marker
113  reverse_iterator u_rend() { return container_type::rend(); } //!< iterator without end marker
114 
115  size_t u_size() const { return container_type::size() - 1; } //!< size without end marker
116 
117 
118  /**
119  * Reset.\n
120  * The contents of this frame are reduced to a single end marker.
121  */
122  void reset()
123  {
124  this->clear();
125  this->putEndMarker();
126  }
127 
128 
129  /**
130  * Apply high-rate veto.\n
131  * If vetoed, the contents of this frame are reduced to a single end marker.
132  *
133  * \param rate_Hz high-rate veto [Hz]
134  */
135  void applyHighRateVeto(const double rate_Hz)
136  {
138 
139  if (this->size() * 1.0e9 / getFrameTime() > rate_Hz) {
140  this->reset();
141  }
142  }
143 
144 
145  /**
146  * Join consecutive hits when matched according given criterion.
147  *
148  * \param match match criterion
149  */
150  void join(const match_type& match)
151  {
152  iterator out = this->u_begin();
153 
154  for (const_iterator p = this->u_begin(); p != this->u_end(); ) {
155 
156  *out = *p;
157 
158  while (++p != this->u_end() && match(*out,*p)) {
159  *out = join(*out,*p);
160  }
161 
162  ++out;
163  }
164 
165  if (out != this->u_end()) {
166  this->erase(out, this->end());
167  this->putEndMarker();
168  }
169  }
170 
171 
172  /**
173  * Filter-out consecutive hits when matched according given criterion.
174  *
175  * Note that all hits which are matched are removed.
176  *
177  * \param match match criterion
178  */
179  void filter(const match_type& match)
180  {
181  iterator out = this->u_begin();
182 
183  for (const_iterator p = this->u_begin(); p != this->u_end(); ) {
184 
185  const_iterator q = p;
186 
187  for (const_iterator i = p; ++q != this->u_end() && match(*i,*q); ++i) {}
188 
189  if (std::distance(p,q) == 1) {
190  *out = *p;
191  ++out;
192  }
193 
194  p = q;
195  }
196 
197  if (out != this->u_end()) {
198  this->erase(out, this->end());
199  this->putEndMarker();
200  }
201  }
202  };
203 }
204 
205 #endif
container_type::const_iterator const_iterator
Definition: JFrame.hh:45
void join(const match_type &match)
Join consecutive hits when matched according given criterion.
Definition: JFrame.hh:150
const_iterator u_end() const
iterator without end marker
Definition: JFrame.hh:106
std::vector< JElement_t, JAllocator_t > container_type
Definition: JFrame.hh:40
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.
Header for PMT.
Definition: JPMTHeader.hh:26
JElement_t value_type
Definition: JFrame.hh:41
const_reverse_iterator u_rbegin() const
iterator without end marker
Definition: JFrame.hh:110
iterator u_begin()
iterator without end marker
Definition: JFrame.hh:107
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:46
Axis object.
Definition: JAxis3D.hh:38
JFrame(const JDAQChronometer &chronometer, const JDAQPMTIdentifier &id, const JAxis3D &axis, const JCalibration &calibration)
Constructor.
Definition: JFrame.hh:72
Base class for match operations for cluster and hit-preprocessing methods.
size_t u_size() const
size without end marker
Definition: JFrame.hh:115
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:32
void filter(const match_type &match)
Filter-out consecutive hits when matched according given criterion.
Definition: JFrame.hh:179
reverse_iterator u_rend()
iterator without end marker
Definition: JFrame.hh:113
const_reverse_iterator u_rend() const
iterator without end marker
Definition: JFrame.hh:111
JFrame()
Default constructor.
Definition: JFrame.hh:56
container_type::const_reverse_iterator const_reverse_iterator
Definition: JFrame.hh:47
void reset()
Reset.
Definition: JFrame.hh:122
container_type::iterator iterator
Definition: JFrame.hh:44
Template definition of hit toolkit.
Definition: JHitToolkit.hh:60
JMatch< value_type > match_type
Definition: JFrame.hh:42
reverse_iterator u_rbegin()
iterator without end marker
Definition: JFrame.hh:112
iterator u_end()
iterator without end marker
Definition: JFrame.hh:108
const_iterator u_begin() const
iterator without end marker
Definition: JFrame.hh:105
void putEndMarker()
Append end marker to data.
Definition: JFrame.hh:99
void applyHighRateVeto(const double rate_Hz)
Apply high-rate veto.
Definition: JFrame.hh:135
void push_back(const JDAQHit &hit)
Append DAQ hit.
Definition: JFrame.hh:90