Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
18 #include "JGeometry3D/JAxis3D.hh"
19 #include "JDAQ/JDAQSuperFrame.hh"
20 #include "JDetector/JModule.hh"
21 #include "JMath/JMathToolkit.hh"
22 
23 
24 /**
25  * \author mdejong
26  */
27 
28 namespace JTRIGGER {}
29 namespace JPP { using namespace JTRIGGER; }
30 
31 namespace JTRIGGER {
32 
34  using JDETECTOR::JModule;
35 
36 
37  /**
38  * Template L2 builder.
39  *
40  * An L2 hit is a local coincidence between two or more hits from different PMTs
41  * within the same optical module satisfying:
42  * - minimal number of hits requirement;
43  * - maximal time difference between hits; and
44  * - maximal space angle requirement between the PMT axes.
45  */
46  template<class JElement_t>
47  class JBuildL2 :
48  public JL2Parameters,
49  public JHitToolkit<JElement_t>,
50  public JBuildHelper< JBuildL2<JElement_t> >
51  {
52  public:
53 
54  using JBuildHelper< JBuildL2<JElement_t> >::operator();
55 
56  typedef JElement_t value_type;
57 
58 
59  /**
60  * Constructor.
61  *
62  * \param numberOfHits minimal number of hits
63  * \param Tmax_ns maximal time difference [ns]
64  * \param ctMin minimal cosine space angle between PMT axes
65  */
67  const double Tmax_ns,
68  const double ctMin) :
69  JL2Parameters(numberOfHits, Tmax_ns, ctMin)
70  {}
71 
72 
73  /**
74  * Constructor.
75  *
76  * \param parameters L2 parameters
77  */
78  JBuildL2(const JL2Parameters& parameters) :
79  JL2Parameters(parameters)
80  {}
81 
82 
83  /**
84  * Build hits from calibrated data.
85  *
86  * Only the input hits that satify the predefined requirements are copied from input to output.
87  * The requirements are checked using the calibrated data of each PMT inside the same module.
88  * The input data should be time sorted.
89  * The output data are time sorted.
90  *
91  * \param super_frame input L0 data
92  * \param input input L1 data
93  * \param out output L2 data
94  */
95  template<template<class, class> class JContainer_t, class JAllocator_t, class JOutput_t>
96  void operator()(const JSuperFrame2D<JElement_t>& super_frame,
97  const JContainer_t <JElement_t, JAllocator_t>& input,
98  JOutput_t out) const
99  {
100  clone = super_frame;
101 
102  for (typename JContainer_t<JElement_t, JAllocator_t>::const_iterator __p = input.begin(); __p != input.end(); ++__p) {
103 
104  clone.fast_forward(*__p);
105 
106  if (isL2(*__p)) {
107  *out = *__p;
108  ++out;
109  }
110  }
111  }
112 
113 
114  /**
115  * Build hits from calibrated data.
116  *
117  * The calibrated data of each PMT inside the optical module are used to build L1 coincidences.
118  * The predefined requirements are then checked using the same calibrated data of each PMT.
119  * The output data are time sorted.
120  *
121  * \param input input L0 data
122  * \param out output L2 data
123  */
124  template<class JOutput_t>
125  void operator()(const JSuperFrame2D<JElement_t>& input, JOutput_t out) const
126  {
127  using namespace std;
128 
129  vector <JElement_t> buffer;
130  JBuildL1<JElement_t> build(this->TMaxLocal_ns, true);
131 
132  build(input, back_inserter(buffer));
133 
134  (*this)(input, buffer, out);
135  }
136 
137 
138  /**
139  * Build hits from DAQ data.
140  *
141  * The time calibration is applied and the requirements are applied to the calibrated data.
142  * The output data are time sorted.
143  *
144  * \param input DAQ super frame
145  * \param module module
146  * \param out output L2 data
147  */
148  template<class JOutput_t>
149  void operator()(const JDAQSuperFrame& input,
150  const JModule& module,
151  JOutput_t out) const
152  {
153  if (!input.empty()) {
154  (*this)(JSuperFrame2D<JElement_t>::demultiplex(input, module), out);
155  }
156  }
157 
158  protected:
159  /**
160  * Test if requirements for given hit are satisfied.
161  * The internal iterators should be set before this test operation.
162  *
163  * \param hit L1 hit
164  * \return true is L2 condition is satisfied; else false
165  */
166  bool isL2(const JElement_t& hit) const
167  {
168  for (typename JSuperFrameClone2D<JElement_t>::const_iterator i = clone.begin(); i != clone.end(); ++i) {
169 
170  if (this->getTimeDifference(hit,*(i->get())) <= TMaxLocal_ns) {
171 
172  int n = 1;
173 
174  for (typename JSuperFrameClone2D<JElement_t>::const_iterator j = i; ++j != clone.end(); ) {
175 
176  if (this->getTimeDifference(hit,*(j->get())) <= TMaxLocal_ns) {
177 
178  if (JMATH::getDot(i->getDirection(), j->getDirection()) >= ctMin) {
179 
180  if (++n >= numberOfHits) {
181  return true;
182  }
183  }
184  }
185  }
186  }
187  }
188 
189  return false;
190  }
191 
192 
194  };
195 
196 
197  /**
198  * Template specialisation of L2 builder for JHitL1 data type.
199  *
200  * An L2 hit is a local coincidence between two or more hits from different PMTs
201  * within the same optical module satisfying:
202  * - minimal number of hits requirement;
203  * - maximal time difference between hits; and
204  * - maximal space angle requirement between the PMT axes.
205  */
206  template<>
207  class JBuildL2<JHitL2> :
208  public JL2Parameters,
209  public JBuildHelper< JBuildL2<JHitL2> >
210  {
211  public:
212 
213  using JBuildHelper< JBuildL2<JHitL2> >::operator();
214 
216 
217 
218  /**
219  * Constructor.
220  *
221  * \param numberOfHits minimal number of hits
222  * \param Tmax_ns maximal time difference [ns]
223  * \param ctMin minimal cosine space angle between PMT axes
224  */
226  const double Tmax_ns,
227  const double ctMin) :
228  JL2Parameters(numberOfHits, Tmax_ns, ctMin)
229  {}
230 
231 
232  /**
233  * Constructor.
234  *
235  * \param parameters L2 parameters
236  */
237  JBuildL2(const JL2Parameters& parameters) :
238  JL2Parameters(parameters)
239  {}
240 
241 
242  /**
243  * Build hits from calibrated data.
244  *
245  * Only the input hits that satify the predefined requirements are copied from input to output.
246  * The requirements are checked using the calibrated data of each PMT inside the same module.
247  * The input data should be time sorted.
248  * The output data are time sorted.
249  *
250  * \param super_frame input L0 data
251  * \param input input L1 data
252  * \param out output L2 data
253  */
254  template<class JElement_t, template<class, class> class JContainer_t, class JAllocator_t, class JOutput_t>
255  void operator()(const JSuperFrame2D<JElement_t>& super_frame,
256  const JContainer_t <JElement_t, JAllocator_t>& input,
257  JOutput_t out) const
258  {
259  using namespace std;
260 
261  typedef JSuperFrameClone2D<JElement_t> JSuperFrameClone2D_t;
262 
263  vector <JElement_t> buffer;
264  JBuildL2<JElement_t> build(*this);
265 
266  build(super_frame, input, back_inserter(buffer));
267 
268  JSuperFrameClone2D_t clone(super_frame);
269 
270  for (typename vector<JElement_t>::const_iterator __p = buffer.begin(); __p != buffer.end(); ++__p) {
271 
272  JHitL1 hit(super_frame.getModuleID());
273 
274  for (typename JSuperFrameClone2D_t::const_iterator i = clone.begin(); i != clone.end(); ++i) {
275 
276  for (typename JSuperFrameClone2D_t::value_type::const_iterator __q = i->fast_forward(*__p); JSuperFrameClone2D_t::getTimeDifference(*__p,*__q) <= TMaxLocal_ns; ++__q) {
277 
278  hit.push_back(JHitL0(i->getPMTIdentifier(),
279  i->getAxis(),
280  JSuperFrameClone2D_t::getJHit(*__q)));
281  }
282  }
283 
284  *out = hit.sort();
285  ++out;
286  }
287  }
288 
289 
290  /**
291  * Build hits from calibrated data.
292  *
293  * The calibrated data of each PMT inside the optical module are used to build L1 coincidences.
294  * The predefined requirements are then checked using the same calibrated data of each PMT.
295  * The output data are time sorted.
296  *
297  * \param input input L0 data
298  * \param out output L1 data
299  */
300  template<class JElement_t, class JOutput_t>
301  void operator()(const JSuperFrame2D<JElement_t>& input, JOutput_t out) const
302  {
303  using namespace std;
304 
305  vector <JElement_t> buffer;
306  JBuildL1<JElement_t> build(this->TMaxLocal_ns, true);
307 
308  build(input, back_inserter(buffer));
309 
310  (*this)(input, buffer, out);
311  }
312 
313 
314  /**
315  * Build hits from DAQ data.
316  *
317  * The time calibration is applied and the requirements are applied to the calibrated data.
318  * The output data are time sorted.
319  *
320  * \param input DAQ super frame
321  * \param module module
322  * \param out output L2 data
323  */
324  template<class JOutput_t>
325  void operator()(const JDAQSuperFrame& input,
326  const JModule& module,
327  JOutput_t out) const
328  {
329  if (!input.empty()) {
330  (*this)(JSuperFrame2D<JHit>::demultiplex(input, module), out);
331  }
332  }
333  };
334 
335 
336  /**
337  * Template specialisation of L2 builder for JHitR1 data type.
338  *
339  * An L2 hit is a local coincidence between two or more hits from different PMTs
340  * within the same optical module satisfying:
341  * - minimal number of hits requirement;
342  * - maximal time difference between hits; and
343  * - maximal space angle requirement between the PMT axes.
344  */
345  template<>
346  class JBuildL2<JHitR2> :
347  public JL2Parameters,
348  public JBuildHelper< JBuildL2<JHitR2> >
349  {
350  public:
351 
352  using JBuildHelper< JBuildL2<JHitR2> >::operator();
353 
355 
356 
357  /**
358  * Constructor.
359  *
360  * \param numberOfHits minimal number of hits
361  * \param Tmax_ns maximal time difference [ns]
362  * \param ctMin minimal cosine space angle between PMT axes
363  */
365  const double Tmax_ns,
366  const double ctMin) :
367  JL2Parameters(numberOfHits, Tmax_ns, ctMin)
368  {}
369 
370 
371  /**
372  * Constructor.
373  *
374  * \param parameters L2 parameters
375  */
376  JBuildL2(const JL2Parameters& parameters) :
377  JL2Parameters(parameters)
378  {}
379 
380 
381  /**
382  * Build hits from calibrated data.
383  *
384  * Only the input hits that satify the predefined requirements are copied from input to output.
385  * The requirements are checked using the calibrated data of each PMT inside the same module.
386  * The input data should be time sorted.
387  * The output data are time sorted.
388  *
389  * \param super_frame input L0 data
390  * \param input input L1 data
391  * \param out output L2 data
392  */
393  template<class JElement_t, template<class, class> class JContainer_t, class JAllocator_t, class JOutput_t>
394  void operator()(const JSuperFrame2D<JElement_t>& super_frame,
395  const JContainer_t <JElement_t, JAllocator_t>& input,
396  JOutput_t out) const
397  {
398  using namespace std;
399 
400  vector <JElement_t> buffer;
401  JBuildL2<JElement_t> build(*this);
402 
403  build(super_frame, input, back_inserter(buffer));
404 
406 
407  for (typename vector<JElement_t>::const_iterator __p = buffer.begin(); __p != buffer.end(); ++__p) {
408 
409  JHitR2 hit(super_frame.getModuleID(),
410  super_frame.getPosition());
411 
412  clone.fast_forward(*__p);
413 
414  for (typename JSuperFrameClone2D<JElement_t>::const_iterator i = clone.begin(); i != clone.end(); ++i) {
415 
416  if (i->getTimeDifference(*__p) <= TMaxLocal_ns) {
417 
418  if (hit.getN() == 0)
419  hit.set(i->getJHit());
420  else
421  hit.add(i->getJHit());
422  }
423  }
424 
425  *out = hit;
426  ++out;
427  }
428  }
429 
430 
431  /**
432  * Build hits from calibrated data.
433  *
434  * The calibrated data of each PMT inside the optical module are used to build L1 coincidences.
435  * The predefined requirements are then checked using the same calibrated data of each PMT.
436  * The output data are time sorted.
437  *
438  * \param input input L0 data
439  * \param out output L1 data
440  */
441  template<class JElement_t, class JOutput_t>
442  void operator()(const JSuperFrame2D<JElement_t>& input, JOutput_t out) const
443  {
444  using namespace std;
445 
446  vector <JElement_t> buffer;
447  JBuildL1<JElement_t> build(this->TMaxLocal_ns, true);
448 
449  build(input, back_inserter(buffer));
450 
451  (*this)(input, buffer, out);
452  }
453 
454 
455  /**
456  * Build hits from DAQ data.
457  *
458  * The time calibration is applied and the requirements are applied to the calibrated data.
459  * The output data are time sorted.
460  *
461  * \param input DAQ super frame
462  * \param module module
463  * \param out output L2 data
464  */
465  template<class JOutput_t>
466  void operator()(const JDAQSuperFrame& input,
467  const JModule& module,
468  JOutput_t out) const
469  {
470  if (!input.empty()) {
471  (*this)(JSuperFrame2D<JHit>::demultiplex(input, module), out);
472  }
473  }
474  };
475 }
476 
477 #endif
int getModuleID() const
Get module identifier.
bool empty() const
Definition: JDAQFrame.hh:155
std::vector< value_type >::const_iterator const_iterator
JBuildL2(const int numberOfHits, const double Tmax_ns, const double ctMin)
Constructor.
Definition: JBuildL2.hh:364
Auxiliary methods for geometrical methods.
Data structure for L1 hit.
Definition: JHitL1.hh:34
Data structure for a composite optical module.
Definition: JModule.hh:47
static JSuperFrame2D< JElement_t > demultiplex
Demultiplexer.
void operator()(const JSuperFrame2D< JElement_t > &input, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:125
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:78
double ctMin
minimal cosine space angle between PMT axes
void operator()(const JSuperFrame2D< JElement_t > &super_frame, const JContainer_t< JElement_t, JAllocator_t > &input, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:96
Clone of JSuperFrame2D.
void operator()(const JSuperFrame2D< JElement_t > &input, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:442
Basic data structure for R2 hit.
void operator()(const JSuperFrame2D< JElement_t > &super_frame, const JContainer_t< JElement_t, JAllocator_t > &input, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:255
int numberOfHits
minimal number of hits
Tools for handling different hit types.
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL2.hh:149
Basic data structure for L0 hit.
Basic data structure for time and time over threshold information of hit.
JBuildL2(const int numberOfHits, const double Tmax_ns, const double ctMin)
Constructor.
Definition: JBuildL2.hh:225
Template L2 builder.
Definition: JBuildL2.hh:47
void operator()(const JSuperFrame2D< JElement_t > &super_frame, const JContainer_t< JElement_t, JAllocator_t > &input, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:394
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:376
Basic data structure for L2 hit.
double getDot(const JFirst_t &first, const JSecond_t &second)
Get dot product of objects.
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
JSuperFrameClone2D< JElement_t > clone
Definition: JBuildL2.hh:193
Template L1 hit builder.
Definition: JBuildL1.hh:76
Data structure for L2 parameters.
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL2.hh:325
JBuildL2(const int numberOfHits, const double Tmax_ns, const double ctMin)
Constructor.
Definition: JBuildL2.hh:66
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:237
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL2.hh:466
bool isL2(const JElement_t &hit) const
Test if requirements for given hit are satisfied.
Definition: JBuildL2.hh:166
Data structure for L0 hit.
Definition: JHitL0.hh:27
double TMaxLocal_ns
maximal time difference [ns]
void fast_forward(argument_type hit) const
Increment the internal iterators until the lower bounds corresponding to the time of the given hit...
const JHitL1 & sort()
Sort L0 hits.
Definition: JHitL1.hh:97
Reduced data structure for L1 hit.
Definition: JHitR1.hh:31
2-dimensional frame with time calibrated data from one optical module.
Template definition of hit toolkit.
Definition: JHitToolkit.hh:60
void operator()(const JSuperFrame2D< JElement_t > &input, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:301
Auxiliary class to extend hit building functionality to all DAQ data types.
Definition: JBuildHelper.hh:44
Data frame of one optical module.
JElement_t value_type
Definition: JBuildL2.hh:56
Data structure for a composite optical module.