Jpp
JBuildL2.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JBUILDL2__
2 #define __JTRIGGER__JBUILDL2__
3 
4 #include <vector>
5 #include <iterator>
6 
11 #include "JTrigger/JHit.hh"
12 #include "JTrigger/JHitL0.hh"
13 #include "JTrigger/JHitL2.hh"
14 #include "JTrigger/JHitR2.hh"
15 #include "JTrigger/JBuildHelper.hh"
16 #include "JTrigger/JBuildL1.hh"
19 #include "JDetector/JModule.hh"
20 #include "JMath/JMathToolkit.hh"
21 
22 
23 /**
24  * \author mdejong
25  */
26 
27 namespace JTRIGGER {}
28 namespace JPP { using namespace JTRIGGER; }
29 
30 namespace JTRIGGER {
31 
33  using JDETECTOR::JModule;
34 
35  /**
36  * Template L2 builder.
37  *
38  * An L2 hit is a local coincidence between two or more hits from different PMTs
39  * within the same optical module satisfying:
40  * - minimal number of hits requirement;
41  * - maximal time difference between hits; and
42  * - maximal space angle requirement between the PMT axes.
43  */
44  template<class JHit_t>
45  class JBuildL2 :
46  public JL2Parameters,
47  public JBuildL1<JHit_t>,
48  public JBuildHelper< JBuildL2<JHit_t> >
49  {
50  public:
51 
52  using JBuildHelper< JBuildL2<JHit_t> >::operator();
53 
54  typedef JHit_t value_type;
55 
56 
57  /**
58  * Constructor.
59  *
60  * \param parameters L2 parameters
61  */
62  JBuildL2(const JL2Parameters& parameters) :
63  JL2Parameters (parameters),
64  JBuildL1<JHit_t>(parameters)
65  {}
66 
67 
68  /**
69  * Build hits from calibrated data.
70  *
71  * Only the input hits that satisfy the predefined requirements are copied from input to output.\n
72  * The requirements are checked using the calibrated data of each PMT inside the same module.
73  * The input data should be time sorted.
74  * The output data are time sorted.
75  *
76  * \param inputL0 input L0 data
77  * \param inputL1 input L1 data
78  * \param out output L2 data
79  */
80  template<class JOutput_t>
81  void operator()(const JSuperFrame2D<JHit_t>& inputL0,
82  const std::vector <JHit_t>& inputL1,
83  JOutput_t out) const
84  {
85  const JSuperFrameClone2D<JHit_t> clone(inputL0);
86 
87  for (typename std::vector<JHit_t>::const_iterator p = inputL1.begin(); p != inputL1.end(); ++p) {
88 
89  clone.fast_forward(*p);
90 
91  if (isL2(clone,*p)) {
92  *out = *p;
93  ++out;
94  }
95  }
96  }
97 
98 
99  /**
100  * Build hits from calibrated data.
101  *
102  * The calibrated data of each PMT inside the optical module are used to build L2 coincidences.
103  * The predefined requirements are then checked using the same calibrated data of each PMT.
104  * The output data are time sorted.
105  *
106  * \param inputL0 input L0 data
107  * \param out output L2 data
108  */
109  template<class JOutput_t>
110  void operator()(const JSuperFrame2D<JHit_t>& inputL0, JOutput_t out) const
111  {
112  bufferL1.clear();
113 
114  static_cast<const JBuildL1<JHit_t>&>(*this)(inputL0, std::back_inserter(bufferL1));
115 
116  (*this)(inputL0, bufferL1, out);
117  }
118 
119 
120  /**
121  * Build hits from DAQ data.
122  *
123  * The time calibration is applied and the requirements are applied to the calibrated data.
124  * The output data are time sorted.
125  *
126  * \param input DAQ super frame
127  * \param module module
128  * \param out output L2 data
129  */
130  template<class JOutput_t>
131  void operator()(const JDAQSuperFrame& input,
132  const JModule& module,
133  JOutput_t out) const
134  {
135  if (!input.empty()) {
136  (*this)(this->demultiplex(input, module), out);
137  }
138  }
139 
140  protected:
141  /**
142  * Test if requirements for given hit are satisfied.\n
143  * The internal iterators of the cloned L0 data should be set before this test operation.
144  *
145  * \param clone L0 data
146  * \param hit L1 hit
147  * \return true is L2 condition is satisfied; else false
148  */
149  bool isL2(const JSuperFrameClone2D<JHit_t>& clone, const JHit_t& hit) const
150  {
151  using namespace JPP;
152 
153  for (typename JSuperFrameClone2D<JHit_t>::const_iterator i = clone.begin(); i != clone.end(); ++i) {
154 
155  if (this->getTimeDifference(hit,*(i->get())) <= TMaxLocal_ns) {
156 
157  int n = 1;
158 
159  for (typename JSuperFrameClone2D<JHit_t>::const_iterator j = i; ++j != clone.end(); ) {
160 
161  if (this->getTimeDifference(hit,*(j->get())) <= TMaxLocal_ns) {
162 
163  if (getDot(i->getDirection(), j->getDirection()) >= ctMin) {
164 
165  if (++n >= numberOfHits) {
166  return true;
167  }
168  }
169  }
170  }
171  }
172  }
173 
174  return false;
175  }
176 
177 
179  };
180 
181 
182  /**
183  * Template specialisation of L2 builder for JHitL2 data type.
184  */
185  template<>
186  class JBuildL2<JHitL2> :
187  public JBuildL2<JHit>,
188  public JBuildHelper< JBuildL2<JHitL2> >
189  {
190  public:
191 
192  using JBuildHelper< JBuildL2<JHitL2> >::operator();
193 
195 
196 
197  /**
198  * Constructor.
199  *
200  * \param parameters L2 parameters
201  */
202  JBuildL2(const JL2Parameters& parameters) :
203  JBuildL2<JHit>(parameters)
204  {}
205 
206 
207  /**
208  * Build hits from calibrated data.
209  *
210  * Only the input hits that satify the predefined requirements are copied from input to output.
211  * The requirements are checked using the calibrated data of each PMT inside the same module.
212  * The input data should be time sorted.
213  * The output data are time sorted.
214  *
215  * \param inputL0 input L0 data
216  * \param inputL2 input L2 data
217  * \param out output L2 data
218  */
219  template<class JOutput_t>
220  void operator()(const JSuperFrame2D<JHit>& inputL0,
221  const std::vector <JHit>& inputL2,
222  JOutput_t out) const
223  {
224  const JSuperFrameClone2D<JHit> clone(inputL0);
225 
226  for (typename std::vector<JHit>::const_iterator p = inputL2.begin(); p != inputL2.end(); ++p) {
227 
228  JHitL2 hit(inputL0.getModuleID());
229 
230  for (typename JSuperFrameClone2D<JHit>::const_iterator i = clone.begin(); i != clone.end(); ++i) {
231 
232  for (typename JSuperFrameClone2D<JHit>::value_type::const_iterator q = i->fast_forward(*p); this->getTimeDifference(*p,*q) <= TMaxLocal_ns; ++q) {
233 
234  hit.push_back(JHitL0(i->getPMTIdentifier(),
235  i->getAxis(),
236  *q));
237  }
238  }
239 
240  *out = hit.sort();
241  ++out;
242  }
243  }
244 
245 
246  /**
247  * Build hits from calibrated data.
248  *
249  * The calibrated data of each PMT inside the optical module are used to build L2 coincidences.
250  * The predefined requirements are then checked using the same calibrated data of each PMT.
251  * The output data are time sorted.
252  *
253  * \param inputL0 input L0 data
254  * \param out output L2 data
255  */
256  template<class JOutput_t>
257  void operator()(const JSuperFrame2D<JHit>& inputL0, JOutput_t out) const
258  {
259  bufferL2.clear();
260 
261  static_cast<const JBuildL2<JHit>&>(*this)(inputL0, std::back_inserter(bufferL2));
262 
263  (*this)(inputL0, bufferL2, out);
264  }
265 
266 
267  /**
268  * Build hits from DAQ data.
269  *
270  * The time calibration is applied and the requirements are applied to the calibrated data.
271  * The output data are time sorted.
272  *
273  * \param input DAQ super frame
274  * \param module module
275  * \param out output L2 data
276  */
277  template<class JOutput_t>
278  void operator()(const JDAQSuperFrame& input,
279  const JModule& module,
280  JOutput_t out) const
281  {
282  if (!input.empty()) {
283 
284  const JSuperFrame2D<JHit>& bufferL0 = this->demultiplex(input, module);
285 
286  (*this)(bufferL0, out);
287  }
288  }
289 
290  protected:
292  };
293 
294 
295  /**
296  * Template specialisation of L2 builder for JHitR2 data type.
297  */
298  template<>
299  class JBuildL2<JHitR2> :
300  public JBuildL2<JHit>,
301  public JBuildHelper< JBuildL2<JHitR2> >
302  {
303  public:
304 
305  using JBuildHelper< JBuildL2<JHitR2> >::operator();
306 
308 
309 
310  /**
311  * Constructor.
312  *
313  * \param parameters L2 parameters
314  */
315  JBuildL2(const JL2Parameters& parameters) :
316  JBuildL2<JHit>(parameters)
317  {}
318 
319 
320  /**
321  * Build hits from calibrated data.
322  *
323  * Only the input hits that satify the predefined requirements are copied from input to output.
324  * The requirements are checked using the calibrated data of each PMT inside the same module.
325  * The input data should be time sorted.
326  * The output data are time sorted.
327  *
328  * \param inputL0 input L0 data
329  * \param inputL2 input L2 data
330  * \param out output L2 data
331  */
332  template<class JOutput_t>
333  void operator()(const JSuperFrame2D<JHit>& inputL0,
334  const std::vector <JHit>& inputL2,
335  JOutput_t out) const
336  {
337  const JSuperFrameClone2D<JHit> clone(inputL0);
338 
339  for (typename std::vector<JHit>::const_iterator p = inputL2.begin(); p != inputL2.end(); ++p) {
340 
341  JHitR2 hit(inputL0.getModuleID(),
342  inputL0.getPosition());
343 
344  clone.fast_forward(*p);
345 
346  for (typename JSuperFrameClone2D<JHit>::const_iterator i = clone.begin(); i != clone.end(); ++i) {
347 
348  if (i->getTimeDifference(*p) <= TMaxLocal_ns) {
349 
350  if (hit.getN() == 0)
351  hit.set(i->getJHit());
352  else
353  hit.add(i->getJHit());
354  }
355  }
356 
357  *out = hit;
358  ++out;
359  }
360  }
361 
362 
363  /**
364  * Build hits from calibrated data.
365  *
366  * The calibrated data of each PMT inside the optical module are used to build L2 coincidences.
367  * The predefined requirements are then checked using the same calibrated data of each PMT.
368  * The output data are time sorted.
369  *
370  * \param inputL0 input L0 data
371  * \param out output L2 data
372  */
373  template<class JOutput_t>
374  void operator()(const JSuperFrame2D<JHit>& inputL0, JOutput_t out) const
375  {
376  bufferL2.clear();
377 
378  static_cast<const JBuildL2<JHit>&>(*this)(inputL0, std::back_inserter(bufferL2));
379 
380  (*this)(inputL0, bufferL2, out);
381  }
382 
383 
384  /**
385  * Build hits from DAQ data.
386  *
387  * The time calibration is applied and the requirements are applied to the calibrated data.
388  * The output data are time sorted.
389  *
390  * \param input DAQ super frame
391  * \param module module
392  * \param out output L2 data
393  */
394  template<class JOutput_t>
395  void operator()(const JDAQSuperFrame& input,
396  const JModule& module,
397  JOutput_t out) const
398  {
399  if (!input.empty()) {
400 
401  const JSuperFrame2D<JHit>& bufferL0 = this->demultiplex(input, module);
402 
403  (*this)(bufferL0, out);
404  }
405  }
406 
407  private:
409  };
410 }
411 
412 #endif
JModule.hh
JTRIGGER::JBuildL2< JHitL2 >::operator()
void operator()(const JSuperFrame2D< JHit > &inputL0, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:257
JTRIGGER::JSuperFrameClone2D::fast_forward
void fast_forward(argument_type hit) const
Increment the internal iterators until the lower bounds corresponding to the time of the given hit.
Definition: JSuperFrameClone2D.hh:94
JHitL2.hh
JTRIGGER::JBuildL2::JBuildL2
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:62
JAANET::JHit_t
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
JTriggerParameters.hh
JTRIGGER::JBuildL2< JHitL2 >::operator()
void operator()(const JSuperFrame2D< JHit > &inputL0, const std::vector< JHit > &inputL2, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:220
JSuperFrame2D.hh
JTRIGGER::JL2Parameters
Data structure for L2 parameters.
Definition: JTriggerParameters.hh:33
JTRIGGER::JBuildL2< JHitL2 >::bufferL2
std::vector< JHit > bufferL2
Definition: JBuildL2.hh:291
JTRIGGER::JL2Parameters::numberOfHits
int numberOfHits
minimal number of hits
Definition: JTriggerParameters.hh:107
JTRIGGER::JBuildL2< JHitR2 >::operator()
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL2.hh:395
JTRIGGER::JBuildL1
Template L1 hit builder.
Definition: JBuildL1.hh:85
JTRIGGER::JBuildL2< JHitL2 >::value_type
JHitL2 value_type
Definition: JBuildL2.hh:194
JTOOLS::n
const int n
Definition: JPolint.hh:628
JSuperFrameClone2D.hh
std::vector< JHit_t >
JTRIGGER::JBuildL2::value_type
JHit_t value_type
Definition: JBuildL2.hh:54
KM3NETDAQ::JDAQFrame::empty
bool empty() const
Definition: JDAQFrame.hh:152
JTRIGGER::JBuild::demultiplex
JSuperFrame2D< JHit_t > & demultiplex(const JDAQSuperFrame &input, const JModule &module) const
Demultiplex and pre-process DAQ super frame.
Definition: JBuild.hh:66
JTOOLS::j
int j
Definition: JPolint.hh:634
JTRIGGER::JClone< JFrame< JElement_t, JAllocator_t > >::const_iterator
JFrame< JElement_t, JAllocator_t > ::const_iterator const_iterator
Definition: JClone.hh:45
KM3NETDAQ::JDAQModuleIdentifier::getModuleID
int getModuleID() const
Get module identifier.
Definition: JDAQModuleIdentifier.hh:72
JTRIGGER::JSuperFrameClone2D
Clone of JSuperFrame2D.
Definition: JSuperFrameClone2D.hh:26
JTRIGGER::JBuildL2::operator()
void operator()(const JSuperFrame2D< JHit_t > &inputL0, const std::vector< JHit_t > &inputL1, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:81
JTRIGGER::JBuildL2< JHitR2 >::operator()
void operator()(const JSuperFrame2D< JHit > &inputL0, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:374
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JBuildL1.hh
JTRIGGER::JL2Parameters::ctMin
double ctMin
minimal cosine space angle between PMT axes
Definition: JTriggerParameters.hh:109
JMathToolkit.hh
JTRIGGER::JHitL1::sort
const JHitL1 & sort()
Sort L0 hits.
Definition: JHitL1.hh:97
JTRIGGER::JBuildL2::operator()
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL2.hh:131
JHitToolkit.hh
JTRIGGER::JBuildL2< JHitR2 >::bufferL2
std::vector< JHit > bufferL2
Definition: JBuildL2.hh:408
JTRIGGER::JBuildL2< JHitL2 >::JBuildL2
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:202
JHit.hh
JDETECTOR::JModule
Data structure for a composite optical module.
Definition: JModule.hh:49
JTRIGGER::JBuildHelper
Auxiliary class to extend hit building functionality to all DAQ data types.
Definition: JBuildHelper.hh:44
JTRIGGER::JBuildL2::bufferL1
std::vector< JHit_t > bufferL1
Definition: JBuildL2.hh:178
JTRIGGER::JBuildL2< JHitL2 >::operator()
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL2.hh:278
JTRIGGER::JBuildL2< JHitR2 >::JBuildL2
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:315
JTRIGGER::JHitR1
Reduced data structure for L1 hit.
Definition: JHitR1.hh:31
JGEOMETRY3D::JPosition3D::getPosition
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
JTRIGGER::JHitL0
Data structure for L0 hit.
Definition: JHitL0.hh:27
JSuperFrame1D.hh
JTRIGGER::JSuperFrameClone2D::const_iterator
std::vector< value_type >::const_iterator const_iterator
Definition: JSuperFrameClone2D.hh:36
JDAQSuperFrame.hh
JTRIGGER::JHit
Hit data structure.
Definition: JHit.hh:22
JTRIGGER::JBuildL2::operator()
void operator()(const JSuperFrame2D< JHit_t > &inputL0, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:110
JTRIGGER::JBuildL2< JHitR2 >::operator()
void operator()(const JSuperFrame2D< JHit > &inputL0, const std::vector< JHit > &inputL2, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:333
KM3NETDAQ::JDAQSuperFrame
Data frame of one optical module.
Definition: JDAQSuperFrame.hh:22
JASTRONOMY::getDot
double getDot(const JNeutrinoDirection &first, const JNeutrinoDirection &second)
Dot product.
Definition: JAstronomy.hh:409
JTRIGGER::JBuildL2::isL2
bool isL2(const JSuperFrameClone2D< JHit_t > &clone, const JHit_t &hit) const
Test if requirements for given hit are satisfied.
Definition: JBuildL2.hh:149
JTRIGGER
Checksum.
Definition: JSupport/JSupport.hh:35
JHitL0.hh
JTRIGGER::JSuperFrame2D
2-dimensional frame with time calibrated data from one optical module.
Definition: JSuperFrame2D.hh:41
JTRIGGER::JBuildL2< JHitR2 >::value_type
JHitR2 value_type
Definition: JBuildL2.hh:307
JTRIGGER::JL2Parameters::TMaxLocal_ns
double TMaxLocal_ns
maximal time difference [ns]
Definition: JTriggerParameters.hh:108
JTRIGGER::JHitL1
Data structure for L1 hit.
Definition: JHitL1.hh:34
JHitR2.hh
JBuildHelper.hh
JTRIGGER::JBuildL2
Template L2 builder.
Definition: JBuildL2.hh:45