Jpp  18.0.0
the software that should make you happy
 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"
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  */
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  * Only the input hits that satisfy the predefined requirements are copied from input to output.\n
103  * The requirements are checked using the calibrated data of each PMT inside the same module.
104  * The input data should be time sorted.
105  * The output data are time sorted.
106  *
107  * \param __begin begin L0 data
108  * \param __end end L0 data
109  * \param inputL1 input L1 data
110  * \param out output L2 data
111  */
112  template<class T, class JOutput_t>
113  void operator()(T __begin,
114  T __end,
115  const std::vector <JHit_t>& inputL1,
116  JOutput_t out) const
117  {
118  const JSuperFrameClone2D<JHit_t> clone(__begin, __end);
119 
120  for (typename std::vector<JHit_t>::const_iterator p = inputL1.begin(); p != inputL1.end(); ++p) {
121 
122  clone.fast_forward(*p);
123 
124  if (isL2(clone,*p)) {
125  *out = *p;
126  ++out;
127  }
128  }
129  }
130 
131 
132  /**
133  * Build hits from calibrated data.
134  *
135  * The calibrated data of each PMT inside the optical module are used to build L2 coincidences.
136  * The predefined requirements are then checked using the same calibrated data of each PMT.
137  * The output data are time sorted.
138  *
139  * \param inputL0 input L0 data
140  * \param out output L2 data
141  */
142  template<class JOutput_t>
143  void operator()(const JSuperFrame2D<JHit_t>& inputL0, JOutput_t out) const
144  {
145  bufferL1.clear();
146 
147  static_cast<const JBuildL1<JHit_t>&>(*this)(inputL0, std::back_inserter(bufferL1));
148 
149  (*this)(inputL0, bufferL1, out);
150  }
151 
152 
153  /**
154  * Build hits from DAQ data.
155  *
156  * The time calibration is applied and the requirements are applied to the calibrated data.
157  * The output data are time sorted.
158  *
159  * \param input DAQ super frame
160  * \param module module
161  * \param out output L2 data
162  */
163  template<class JOutput_t>
164  void operator()(const JDAQSuperFrame& input,
165  const JModule& module,
166  JOutput_t out) const
167  {
168  if (!input.empty()) {
169  (*this)(this->demultiplex(input, module), out);
170  }
171  }
172 
173  protected:
174  /**
175  * Test if requirements for given hit are satisfied.\n
176  * The internal iterators of the cloned L0 data should be set before this test operation.
177  *
178  * \param clone L0 data
179  * \param hit L1 hit
180  * \return true is L2 condition is satisfied; else false
181  */
182  bool isL2(const JSuperFrameClone2D<JHit_t>& clone, const JHit_t& hit) const
183  {
184  using namespace JPP;
185 
186  if (numberOfHits < 2) {
187  return true;
188  }
189 
190  for (typename JSuperFrameClone2D<JHit_t>::const_iterator i = clone.begin(); i != clone.end(); ++i) {
191 
192  if (this->getTimeDifference(hit,*(i->get())) <= TMaxLocal_ns) {
193 
194  int n = 1;
195 
196  for (typename JSuperFrameClone2D<JHit_t>::const_iterator j = clone.begin(); j != clone.end(); ++j) {
197 
198  if (i != j) {
199 
200  if (this->getTimeDifference(hit,*(j->get())) <= TMaxLocal_ns) {
201 
202  if (getDot(i->getDirection(), j->getDirection()) >= ctMin) {
203 
204  if (++n >= numberOfHits) {
205  return true;
206  }
207  }
208  }
209  }
210  }
211  }
212  }
213 
214  return false;
215  }
216 
217 
219  };
220 
221 
222  /**
223  * Template specialisation of L2 builder for JHitL2 data type.
224  */
225  template<>
226  class JBuildL2<JHitL2> :
227  public JBuildL2<JHit>,
228  public JBuildHelper< JBuildL2<JHitL2> >
229  {
230  public:
231 
232  using JBuildHelper< JBuildL2<JHitL2> >::operator();
233 
235 
236 
237  /**
238  * Constructor.
239  *
240  * \param parameters L2 parameters
241  */
243  JBuildL2<JHit>(parameters)
244  {}
245 
246 
247  /**
248  * Build hits from calibrated data.
249  *
250  * Only the input hits that satify the predefined requirements are copied from input to output.
251  * The requirements are checked using the calibrated data of each PMT inside the same module.
252  * The input data should be time sorted.
253  * The output data are time sorted.
254  *
255  * \param inputL0 input L0 data
256  * \param inputL2 input L2 data
257  * \param out output L2 data
258  */
259  template<class JOutput_t>
260  void operator()(const JSuperFrame2D<JHit>& inputL0,
261  const std::vector <JHit>& inputL2,
262  JOutput_t out) const
263  {
264  const JSuperFrameClone2D<JHit> clone(inputL0);
265 
266  for (typename std::vector<JHit>::const_iterator p = inputL2.begin(); p != inputL2.end(); ++p) {
267 
268  JHitL2 hit(inputL0.getModuleID());
269 
270  for (typename JSuperFrameClone2D<JHit>::const_iterator i = clone.begin(); i != clone.end(); ++i) {
271 
272  for (typename JSuperFrameClone2D<JHit>::value_type::const_iterator q = i->fast_forward(*p); this->getTimeDifference(*p,*q) <= TMaxLocal_ns; ++q) {
273 
274  hit.push_back(JHitL0(i->getPMTIdentifier(),
275  i->getAxis(),
276  *q));
277  }
278  }
279 
280  *out = hit.sort();
281  ++out;
282  }
283  }
284 
285 
286  /**
287  * Build hits from calibrated data.
288  *
289  * The calibrated data of each PMT inside the optical module are used to build L2 coincidences.
290  * The predefined requirements are then checked using the same calibrated data of each PMT.
291  * The output data are time sorted.
292  *
293  * \param inputL0 input L0 data
294  * \param out output L2 data
295  */
296  template<class JOutput_t>
297  void operator()(const JSuperFrame2D<JHit>& inputL0, JOutput_t out) const
298  {
299  bufferL2.clear();
300 
301  static_cast<const JBuildL2<JHit>&>(*this)(inputL0, std::back_inserter(bufferL2));
302 
303  (*this)(inputL0, bufferL2, out);
304  }
305 
306 
307  /**
308  * Build hits from DAQ data.
309  *
310  * The time calibration is applied and the requirements are applied to the calibrated data.
311  * The output data are time sorted.
312  *
313  * \param input DAQ super frame
314  * \param module module
315  * \param out output L2 data
316  */
317  template<class JOutput_t>
318  void operator()(const JDAQSuperFrame& input,
319  const JModule& module,
320  JOutput_t out) const
321  {
322  if (!input.empty()) {
323 
324  const JSuperFrame2D<JHit>& bufferL0 = this->demultiplex(input, module);
325 
326  (*this)(bufferL0, out);
327  }
328  }
329 
330  protected:
332  };
333 
334 
335  /**
336  * Template specialisation of L2 builder for JHitR2 data type.
337  */
338  template<>
339  class JBuildL2<JHitR2> :
340  public JBuildL2<JHit>,
341  public JBuildHelper< JBuildL2<JHitR2> >
342  {
343  public:
344 
345  using JBuildHelper< JBuildL2<JHitR2> >::operator();
346 
348 
349 
350  /**
351  * Constructor.
352  *
353  * \param parameters L2 parameters
354  */
356  JBuildL2<JHit>(parameters)
357  {}
358 
359 
360  /**
361  * Build hits from calibrated data.
362  *
363  * Only the input hits that satify the predefined requirements are copied from input to output.
364  * The requirements are checked using the calibrated data of each PMT inside the same module.
365  * The input data should be time sorted.
366  * The output data are time sorted.
367  *
368  * \param inputL0 input L0 data
369  * \param inputL2 input L2 data
370  * \param out output L2 data
371  */
372  template<class JOutput_t>
373  void operator()(const JSuperFrame2D<JHit>& inputL0,
374  const std::vector <JHit>& inputL2,
375  JOutput_t out) const
376  {
377  const JSuperFrameClone2D<JHit> clone(inputL0);
378 
379  for (typename std::vector<JHit>::const_iterator p = inputL2.begin(); p != inputL2.end(); ++p) {
380 
381  JHitR2 hit(inputL0.getModuleID(),
382  inputL0.getPosition());
383 
384  clone.fast_forward(*p);
385 
386  for (typename JSuperFrameClone2D<JHit>::const_iterator i = clone.begin(); i != clone.end(); ++i) {
387 
388  if (i->getTimeDifference(*p) <= TMaxLocal_ns) {
389 
390  if (hit.getN() == 0)
391  hit.set(i->getJHit());
392  else
393  hit.add(i->getJHit());
394 
395  if (i->getT() < hit.getT()) {
396  hit.setPosition(i->getPosition());
397  }
398  }
399  }
400 
401  *out = hit;
402  ++out;
403  }
404  }
405 
406 
407  /**
408  * Build hits from calibrated data.
409  *
410  * The calibrated data of each PMT inside the optical module are used to build L2 coincidences.
411  * The predefined requirements are then checked using the same calibrated data of each PMT.
412  * The output data are time sorted.
413  *
414  * \param inputL0 input L0 data
415  * \param out output L2 data
416  */
417  template<class JOutput_t>
418  void operator()(const JSuperFrame2D<JHit>& inputL0, JOutput_t out) const
419  {
420  bufferL2.clear();
421 
422  static_cast<const JBuildL2<JHit>&>(*this)(inputL0, std::back_inserter(bufferL2));
423 
424  (*this)(inputL0, bufferL2, out);
425  }
426 
427 
428  /**
429  * Build hits from DAQ data.
430  *
431  * The time calibration is applied and the requirements are applied to the calibrated data.
432  * The output data are time sorted.
433  *
434  * \param input DAQ super frame
435  * \param module module
436  * \param out output L2 data
437  */
438  template<class JOutput_t>
439  void operator()(const JDAQSuperFrame& input,
440  const JModule& module,
441  JOutput_t out) const
442  {
443  if (!input.empty()) {
444 
445  const JSuperFrame2D<JHit>& bufferL0 = this->demultiplex(input, module);
446 
447  (*this)(bufferL0, out);
448  }
449  }
450 
451  private:
453  };
454 }
455 
456 #endif
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
JFrame< JElement_t, JAllocator_t >::const_iterator const_iterator
Definition: JClone.hh:45
int getModuleID() const
Get module identifier.
bool empty() const
Definition: JDAQFrame.hh:180
std::vector< value_type >::const_iterator const_iterator
Auxiliary methods for geometrical methods.
Data structure for L1 hit.
Definition: JHitL1.hh:34
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:62
Data structure for a composite optical module.
Definition: JModule.hh:68
double getDot(const JNeutrinoDirection &first, const JNeutrinoDirection &second)
Dot product.
Definition: JAstronomy.hh:409
double ctMin
minimal cosine space angle between PMT axes
void operator()(const JSuperFrame2D< JHit > &inputL0, const std::vector< JHit > &inputL2, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:260
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Hit data structure.
Clone of JSuperFrame2D.
Basic data structure for R2 hit.
Basic data structure for time and time over threshold information of hit.
int numberOfHits
minimal number of hits
Tools for handling different hit types.
void operator()(const JSuperFrame2D< JHit > &inputL0, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:297
Basic data structure for L0 hit.
const int n
Definition: JPolint.hh:697
void operator()(const JSuperFrame2D< JHit > &inputL0, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:418
Template L2 builder.
Definition: JBuildL2.hh:45
void operator()(const JSuperFrame2D< JHit > &inputL0, const std::vector< JHit > &inputL2, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:373
std::vector< JHit_t > bufferL1
Definition: JBuildL2.hh:218
double getTimeDifference(const JDAQChronometer &first, const JDAQChronometer &second)
Get time difference between two chronometers.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:355
Basic data structure for L2 hit.
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
std::vector< JHit > bufferL2
Definition: JBuildL2.hh:331
JSuperFrame2D< JHit_t > & demultiplex(const JDAQSuperFrame &input, const JModule &module) const
Demultiplex and pre-process DAQ super frame.
Definition: JBuild.hh:103
Template L1 hit builder.
Definition: JBuildL1.hh:85
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:318
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:242
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL2.hh:439
Data structure for L0 hit.
Definition: JHitL0.hh:27
std::vector< JHit > bufferL2
Definition: JBuildL2.hh:452
Auxiliary class to set-up Hit.
Definition: JSirene.hh:57
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.
int j
Definition: JPolint.hh:703
void operator()(T __begin, T __end, const std::vector< JHit_t > &inputL1, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:113
void operator()(const JSuperFrame2D< JHit_t > &inputL0, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:143
Auxiliary class to extend hit building functionality to all DAQ data types.
Definition: JBuildHelper.hh:44
bool isL2(const JSuperFrameClone2D< JHit_t > &clone, const JHit_t &hit) const
Test if requirements for given hit are satisfied.
Definition: JBuildL2.hh:182
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL2.hh:164
Data frame of one optical module.
Data structure for optical module.