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
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  for (typename JSuperFrameClone2D<JHit_t>::const_iterator i = clone.begin(); i != clone.end(); ++i) {
187 
188  if (this->getTimeDifference(hit,*(i->get())) <= TMaxLocal_ns) {
189 
190  int n = 1;
191 
192  for (typename JSuperFrameClone2D<JHit_t>::const_iterator j = i; ++j != clone.end(); ) {
193 
194  if (this->getTimeDifference(hit,*(j->get())) <= TMaxLocal_ns) {
195 
196  if (getDot(i->getDirection(), j->getDirection()) >= ctMin) {
197 
198  if (++n >= numberOfHits) {
199  return true;
200  }
201  }
202  }
203  }
204  }
205  }
206 
207  return false;
208  }
209 
210 
212  };
213 
214 
215  /**
216  * Template specialisation of L2 builder for JHitL2 data type.
217  */
218  template<>
219  class JBuildL2<JHitL2> :
220  public JBuildL2<JHit>,
221  public JBuildHelper< JBuildL2<JHitL2> >
222  {
223  public:
224 
225  using JBuildHelper< JBuildL2<JHitL2> >::operator();
226 
228 
229 
230  /**
231  * Constructor.
232  *
233  * \param parameters L2 parameters
234  */
236  JBuildL2<JHit>(parameters)
237  {}
238 
239 
240  /**
241  * Build hits from calibrated data.
242  *
243  * Only the input hits that satify the predefined requirements are copied from input to output.
244  * The requirements are checked using the calibrated data of each PMT inside the same module.
245  * The input data should be time sorted.
246  * The output data are time sorted.
247  *
248  * \param inputL0 input L0 data
249  * \param inputL2 input L2 data
250  * \param out output L2 data
251  */
252  template<class JOutput_t>
253  void operator()(const JSuperFrame2D<JHit>& inputL0,
254  const std::vector <JHit>& inputL2,
255  JOutput_t out) const
256  {
257  const JSuperFrameClone2D<JHit> clone(inputL0);
258 
259  for (typename std::vector<JHit>::const_iterator p = inputL2.begin(); p != inputL2.end(); ++p) {
260 
261  JHitL2 hit(inputL0.getModuleID());
262 
263  for (typename JSuperFrameClone2D<JHit>::const_iterator i = clone.begin(); i != clone.end(); ++i) {
264 
265  for (typename JSuperFrameClone2D<JHit>::value_type::const_iterator q = i->fast_forward(*p); this->getTimeDifference(*p,*q) <= TMaxLocal_ns; ++q) {
266 
267  hit.push_back(JHitL0(i->getPMTIdentifier(),
268  i->getAxis(),
269  *q));
270  }
271  }
272 
273  *out = hit.sort();
274  ++out;
275  }
276  }
277 
278 
279  /**
280  * Build hits from calibrated data.
281  *
282  * The calibrated data of each PMT inside the optical module are used to build L2 coincidences.
283  * The predefined requirements are then checked using the same calibrated data of each PMT.
284  * The output data are time sorted.
285  *
286  * \param inputL0 input L0 data
287  * \param out output L2 data
288  */
289  template<class JOutput_t>
290  void operator()(const JSuperFrame2D<JHit>& inputL0, JOutput_t out) const
291  {
292  bufferL2.clear();
293 
294  static_cast<const JBuildL2<JHit>&>(*this)(inputL0, std::back_inserter(bufferL2));
295 
296  (*this)(inputL0, bufferL2, out);
297  }
298 
299 
300  /**
301  * Build hits from DAQ data.
302  *
303  * The time calibration is applied and the requirements are applied to the calibrated data.
304  * The output data are time sorted.
305  *
306  * \param input DAQ super frame
307  * \param module module
308  * \param out output L2 data
309  */
310  template<class JOutput_t>
311  void operator()(const JDAQSuperFrame& input,
312  const JModule& module,
313  JOutput_t out) const
314  {
315  if (!input.empty()) {
316 
317  const JSuperFrame2D<JHit>& bufferL0 = this->demultiplex(input, module);
318 
319  (*this)(bufferL0, out);
320  }
321  }
322 
323  protected:
325  };
326 
327 
328  /**
329  * Template specialisation of L2 builder for JHitR2 data type.
330  */
331  template<>
332  class JBuildL2<JHitR2> :
333  public JBuildL2<JHit>,
334  public JBuildHelper< JBuildL2<JHitR2> >
335  {
336  public:
337 
338  using JBuildHelper< JBuildL2<JHitR2> >::operator();
339 
341 
342 
343  /**
344  * Constructor.
345  *
346  * \param parameters L2 parameters
347  */
349  JBuildL2<JHit>(parameters)
350  {}
351 
352 
353  /**
354  * Build hits from calibrated data.
355  *
356  * Only the input hits that satify the predefined requirements are copied from input to output.
357  * The requirements are checked using the calibrated data of each PMT inside the same module.
358  * The input data should be time sorted.
359  * The output data are time sorted.
360  *
361  * \param inputL0 input L0 data
362  * \param inputL2 input L2 data
363  * \param out output L2 data
364  */
365  template<class JOutput_t>
366  void operator()(const JSuperFrame2D<JHit>& inputL0,
367  const std::vector <JHit>& inputL2,
368  JOutput_t out) const
369  {
370  const JSuperFrameClone2D<JHit> clone(inputL0);
371 
372  for (typename std::vector<JHit>::const_iterator p = inputL2.begin(); p != inputL2.end(); ++p) {
373 
374  JHitR2 hit(inputL0.getModuleID(),
375  inputL0.getPosition());
376 
377  clone.fast_forward(*p);
378 
379  for (typename JSuperFrameClone2D<JHit>::const_iterator i = clone.begin(); i != clone.end(); ++i) {
380 
381  if (i->getTimeDifference(*p) <= TMaxLocal_ns) {
382 
383  if (hit.getN() == 0)
384  hit.set(i->getJHit());
385  else
386  hit.add(i->getJHit());
387 
388  if (i->getT() < hit.getT()) {
389  hit.setPosition(i->getPosition());
390  }
391  }
392  }
393 
394  *out = hit;
395  ++out;
396  }
397  }
398 
399 
400  /**
401  * Build hits from calibrated data.
402  *
403  * The calibrated data of each PMT inside the optical module are used to build L2 coincidences.
404  * The predefined requirements are then checked using the same calibrated data of each PMT.
405  * The output data are time sorted.
406  *
407  * \param inputL0 input L0 data
408  * \param out output L2 data
409  */
410  template<class JOutput_t>
411  void operator()(const JSuperFrame2D<JHit>& inputL0, JOutput_t out) const
412  {
413  bufferL2.clear();
414 
415  static_cast<const JBuildL2<JHit>&>(*this)(inputL0, std::back_inserter(bufferL2));
416 
417  (*this)(inputL0, bufferL2, out);
418  }
419 
420 
421  /**
422  * Build hits from DAQ data.
423  *
424  * The time calibration is applied and the requirements are applied to the calibrated data.
425  * The output data are time sorted.
426  *
427  * \param input DAQ super frame
428  * \param module module
429  * \param out output L2 data
430  */
431  template<class JOutput_t>
432  void operator()(const JDAQSuperFrame& input,
433  const JModule& module,
434  JOutput_t out) const
435  {
436  if (!input.empty()) {
437 
438  const JSuperFrame2D<JHit>& bufferL0 = this->demultiplex(input, module);
439 
440  (*this)(bufferL0, out);
441  }
442  }
443 
444  private:
446  };
447 }
448 
449 #endif
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
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:152
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:66
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:253
*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:290
Basic data structure for L0 hit.
void operator()(const JSuperFrame2D< JHit > &inputL0, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:411
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:366
std::vector< JHit_t > bufferL1
Definition: JBuildL2.hh:211
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:348
Basic data structure for L2 hit.
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
std::vector< JHit > bufferL2
Definition: JBuildL2.hh:324
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:311
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:235
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL2.hh:432
Data structure for L0 hit.
Definition: JHitL0.hh:27
alias put_queue eval echo n
Definition: qlib.csh:19
std::vector< JHit > bufferL2
Definition: JBuildL2.hh:445
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:666
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.