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"
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  * 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  */
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  */
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  if (i->getT() < hit.getT()) {
356  hit.setPosition(i->getPosition());
357  }
358  }
359  }
360 
361  *out = hit;
362  ++out;
363  }
364  }
365 
366 
367  /**
368  * Build hits from calibrated data.
369  *
370  * The calibrated data of each PMT inside the optical module are used to build L2 coincidences.
371  * The predefined requirements are then checked using the same calibrated data of each PMT.
372  * The output data are time sorted.
373  *
374  * \param inputL0 input L0 data
375  * \param out output L2 data
376  */
377  template<class JOutput_t>
378  void operator()(const JSuperFrame2D<JHit>& inputL0, JOutput_t out) const
379  {
380  bufferL2.clear();
381 
382  static_cast<const JBuildL2<JHit>&>(*this)(inputL0, std::back_inserter(bufferL2));
383 
384  (*this)(inputL0, bufferL2, out);
385  }
386 
387 
388  /**
389  * Build hits from DAQ data.
390  *
391  * The time calibration is applied and the requirements are applied to the calibrated data.
392  * The output data are time sorted.
393  *
394  * \param input DAQ super frame
395  * \param module module
396  * \param out output L2 data
397  */
398  template<class JOutput_t>
399  void operator()(const JDAQSuperFrame& input,
400  const JModule& module,
401  JOutput_t out) const
402  {
403  if (!input.empty()) {
404 
405  const JSuperFrame2D<JHit>& bufferL0 = this->demultiplex(input, module);
406 
407  (*this)(bufferL0, out);
408  }
409  }
410 
411  private:
413  };
414 }
415 
416 #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:50
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:220
*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:257
Basic data structure for L0 hit.
void operator()(const JSuperFrame2D< JHit > &inputL0, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:378
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:333
std::vector< JHit_t > bufferL1
Definition: JBuildL2.hh:178
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:315
Basic data structure for L2 hit.
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
std::vector< JHit > bufferL2
Definition: JBuildL2.hh:291
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:278
JBuildL2(const JL2Parameters &parameters)
Constructor.
Definition: JBuildL2.hh:202
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL2.hh:399
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:412
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:634
void operator()(const JSuperFrame2D< JHit_t > &inputL0, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL2.hh:110
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:149
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL2.hh:131
Data frame of one optical module.
Data structure for a composite optical module.