Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JBuildL1.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JBUILDL1__
2 #define __JTRIGGER__JBUILDL1__
3 
4 #include <vector>
5 #include <iterator>
6 
11 #include "JTrigger/JHit.hh"
12 #include "JTrigger/JHitL0.hh"
13 #include "JTrigger/JHitL1.hh"
14 #include "JTrigger/JHitR1.hh"
15 #include "JTrigger/JBuildHelper.hh"
16 #include "JTrigger/JBuildL0.hh"
18 #include "JGeometry3D/JAxis3D.hh"
19 #include "JDAQ/JDAQSuperFrame.hh"
20 #include "JDetector/JModule.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  /**
37  * Auxiliary data structure for L1 build parameters.
38  */
40  {
41  /**
42  * Constructor.
43  *
44  * \param Tmax_ns maximal time difference of L1 [ns]
45  * \param combine combine multiple L1 within given time window
46  */
47  JBuildL1Parameters(const double Tmax_ns,
48  const bool combine) :
49  TMaxLocal_ns(Tmax_ns),
50  combineL1 (combine)
51  {}
52 
53 
54  /**
55  * Constructor.
56  *
57  * \param parameters trigger parameters
58  */
60  TMaxLocal_ns(parameters.TMaxLocal_ns),
61  combineL1 (parameters.combineL1)
62  {}
63 
64 
65  double TMaxLocal_ns;
66  bool combineL1;
67  };
68 
69 
70  /**
71  * Template L1 hit builder.
72  *
73  * An L1 hit is a local coincidence between two different PMTs within the same optical module.
74  */
75  template<class JElement_t>
76  class JBuildL1 :
77  public JBuildL1Parameters,
78  public JHitToolkit<JElement_t>,
79  public JBuildHelper< JBuildL1<JElement_t> >
80  {
81  public:
82 
83  using JBuildHelper< JBuildL1<JElement_t> >::operator();
84 
85  typedef JElement_t value_type;
86 
87 
88  /**
89  * Constructor.
90  *
91  * \param Tmax_ns maximal time difference of L1 [ns]
92  * \param combine combine multiple L1 within given time window
93  */
94  JBuildL1(const double Tmax_ns,
95  const bool combine) :
96  JBuildL1Parameters(Tmax_ns, combine)
97  {}
98 
99 
100  /**
101  * Constructor.
102  *
103  * \param parameters trigger parameters
104  */
105  JBuildL1(const JTriggerParameters& parameters) :
106  JBuildL1Parameters(parameters)
107  {}
108 
109 
110  /**
111  * Constructor.
112  *
113  * \param parameters build L1 parameters
114  */
115  JBuildL1(const JBuildL1Parameters& parameters) :
116  JBuildL1Parameters(parameters)
117  {}
118 
119 
120  /**
121  * Build hits from calibrated data.
122  *
123  * The output data are time sorted.
124  *
125  * \param input input L0 data
126  * \param out output L1 data
127  */
128  template<class JOutput_t>
129  void operator()(const JSuperFrame2D<JElement_t>& input, JOutput_t out) const
130  {
131  (*this)(input.begin(), input.end(), out);
132  }
133 
134 
135  /**
136  * Build hits from set of frames with calibrated data.
137  *
138  * The output data are time sorted.
139  *
140  * \param __begin begin of input L0 data
141  * \param __end end of input L0 data
142  * \param out output L1 data
143  */
144  template<class JOutput_t>
147  JOutput_t out) const
148  {
149  (*this)(JSuperFrame1D<JElement_t>::multiplex(__begin, __end), out);
150  }
151 
152 
153  /**
154  * Build hits from calibrated data.
155  *
156  * The output data are time sorted.
157  *
158  * \param input input L0 data
159  * \param out output L1 data
160  */
161  template<class JOutput_t>
162  void operator()(const JSuperFrame1D<JElement_t>& input, JOutput_t out) const
163  {
164  int n = (int) input.size() - 1; // remove end marker
165 
166  for (typename JSuperFrame1D<JElement_t>::const_iterator q = input.begin(), p = q++; n != 0; ++q, --n) {
167 
168  if (this->getTimeDifference(*p,*q) <= TMaxLocal_ns) {
169 
170  *out = *p;
171  ++out;
172 
173  if (combineL1) {
174  for (++q, --n; this->getTimeDifference(*p,*q) <= TMaxLocal_ns; ++q, --n) {}
175  }
176  }
177 
178  p = q;
179  }
180  }
181 
182 
183  /**
184  * Build hits from DAQ data.
185  *
186  * The time calibration is applied.
187  * The output data are time sorted.
188  *
189  * \param input DAQ super frame
190  * \param module module
191  * \param out output L1 data
192  */
193  template<class JOutput_t>
194  void operator()(const JDAQSuperFrame& input,
195  const JModule& module,
196  JOutput_t out) const
197  {
198  if (!input.empty()) {
199  (*this)(JSuperFrame2D<JElement_t>::demultiplex(input, module), out);
200  }
201  }
202  };
203 
204 
205  /**
206  * Template specialisation of L1 builder for JHitL1 data type.
207  */
208  template<>
209  class JBuildL1<JHitL1> :
210  public JBuildL1Parameters,
211  public JBuildHelper< JBuildL1<JHitL1> >
212  {
213  public:
214 
215  using JBuildHelper< JBuildL1<JHitL1> >::operator();
216 
218 
219 
220  /**
221  * Constructor.
222  *
223  * \param Tmax_ns maximal time difference of L1 [ns]
224  * \param combine combine multiple L1 within given time window
225  */
226  JBuildL1(const double Tmax_ns,
227  const bool combine) :
228  JBuildL1Parameters(Tmax_ns, combine)
229  {}
230 
231 
232  /**
233  * Constructor.
234  *
235  * \param parameters trigger parameters
236  */
237  JBuildL1(const JTriggerParameters& parameters) :
238  JBuildL1Parameters(parameters)
239  {}
240 
241 
242  /**
243  * Constructor.
244  *
245  * \param parameters build L1 parameters
246  */
247  JBuildL1(const JBuildL1Parameters& parameters) :
248  JBuildL1Parameters(parameters)
249  {}
250 
251 
252  /**
253  * Build hits from calibrated data.
254  *
255  * The output data are time sorted.
256  *
257  * \param input input L0 data
258  * \param out output L1 data
259  */
260  template<class JElement_t, class JOutput_t>
261  void operator()(const JSuperFrame2D<JElement_t>& input, JOutput_t out) const
262  {
263  using namespace std;
264 
265  typedef JSuperFrameClone2D<JElement_t> JSuperFrameClone2D_t;
266 
267  vector <JElement_t> buffer;
268  JBuildL1<JElement_t> build(*this);
269 
270  build(JSuperFrame1D<JElement_t>::multiplex(input), back_inserter(buffer));
271 
272  JSuperFrameClone2D_t clone(input);
273 
274  for (typename vector<JElement_t>::const_iterator __p = buffer.begin(); __p != buffer.end(); ++__p) {
275 
276  JHitL1 hit(input.getModuleID());
277 
278  for (typename JSuperFrameClone2D_t::const_iterator i = clone.begin(); i != clone.end(); ++i) {
279 
280  for (typename JSuperFrameClone2D_t::value_type::const_iterator __q = i->fast_forward(*__p); JSuperFrameClone2D_t::getTimeDifference(*__p,*__q) <= TMaxLocal_ns; ++__q) {
281 
282  hit.push_back(JHitL0(i->getPMTIdentifier(),
283  i->getAxis(),
284  JSuperFrameClone2D_t::getJHit(*__q)));
285  }
286  }
287 
288  *out = hit.sort();
289  ++out;
290  }
291  }
292 
293 
294  /**
295  * Build hits from uncalibrated DAQ data.
296  *
297  * The time calibration is applied.
298  * The output data are time sorted.
299  *
300  * \param input DAQ super frame
301  * \param module module
302  * \param out output L1 data
303  */
304  template<class JOutput_t>
305  void operator()(const JDAQSuperFrame& input,
306  const JModule& module,
307  JOutput_t out) const
308  {
309  if (!input.empty()) {
310  (*this)(JSuperFrame2D<JHit>::demultiplex(input, module), out);
311  }
312  }
313  };
314 
315 
316  /**
317  * Template specialisation of L1 builder for JHitR1 data type.
318  *
319  * Note that by constuction all hits which consitute an L1 hits are combined.
320  */
321  template<>
322  class JBuildL1<JHitR1> :
323  public JBuildL1Parameters,
324  public JBuildHelper< JBuildL1<JHitR1> >
325  {
326  public:
327 
328  using JBuildHelper< JBuildL1<JHitR1> >::operator();
329 
331 
332 
333  /**
334  * Constructor.
335  *
336  * \param Tmax_ns maximal time difference of L1 [ns]
337  * \param combine combine multiple L1 within given time window
338  */
339  JBuildL1(const double Tmax_ns,
340  const bool combine) :
341  JBuildL1Parameters(Tmax_ns, combine)
342  {}
343 
344 
345  /**
346  * Constructor.
347  *
348  * \param parameters trigger parameters
349  */
350  JBuildL1(const JTriggerParameters& parameters) :
351  JBuildL1Parameters(parameters)
352  {}
353 
354 
355  /**
356  * Constructor.
357  *
358  * \param parameters build L1 parameters
359  */
360  JBuildL1(const JBuildL1Parameters& parameters) :
361  JBuildL1Parameters(parameters)
362  {}
363 
364 
365  /**
366  * Build hits from calibrated data.
367  *
368  * The output data are time sorted.
369  *
370  * \param input input L0 data
371  * \param out output L1 data
372  */
373  template<class JElement_t, class JOutput_t>
374  void operator()(const JSuperFrame2D<JElement_t>& input, JOutput_t out) const
375  {
376  using namespace std;
377 
378  vector <JElement_t> buffer;
379  JBuildL1<JElement_t> build(*this);
380 
381  build(JSuperFrame1D<JElement_t>::multiplex(input), back_inserter(buffer));
382 
383  for (typename vector<JElement_t>::const_iterator __p = buffer.begin(); __p != buffer.end(); ++__p) {
384 
385  *out = JHitR1(input.getModuleID(),
386  input.getPosition(),
388  ++out;
389  }
390  }
391 
392 
393  /**
394  * Build hits from uncalibrated DAQ data.
395  *
396  * The time calibration is applied.
397  * The output data are time sorted.
398  *
399  * \param input DAQ super frame
400  * \param module module
401  * \param out output L1 data
402  */
403  template<class JOutput_t>
404  void operator()(const JDAQSuperFrame& input,
405  const JModule& module,
406  JOutput_t out) const
407  {
408  if (!input.empty()) {
409  (*this)(JSuperFrame2D<JHit>::demultiplex(input, module), out);
410  }
411  }
412  };
413 }
414 
415 #endif
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from uncalibrated DAQ data.
Definition: JBuildL1.hh:305
Data structure for all trigger parameters.
int getModuleID() const
Get module identifier.
bool empty() const
Definition: JDAQFrame.hh:155
Data structure for L1 hit.
Definition: JHitL1.hh:34
Data structure for a composite optical module.
Definition: JModule.hh:47
JBuildL1Parameters(const JTriggerParameters &parameters)
Constructor.
Definition: JBuildL1.hh:59
JBuildL1(const double Tmax_ns, const bool combine)
Constructor.
Definition: JBuildL1.hh:226
static JSuperFrame1D< JElement_t, JAllocator_t > multiplex
Multiplexer.
static JSuperFrame2D< JElement_t > demultiplex
Demultiplexer.
JBuildL1Parameters(const double Tmax_ns, const bool combine)
Constructor.
Definition: JBuildL1.hh:47
JBuildL1(const JTriggerParameters &parameters)
Constructor.
Definition: JBuildL1.hh:105
void operator()(const JSuperFrame1D< JElement_t > &input, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL1.hh:162
JBuildL1(const JBuildL1Parameters &parameters)
Constructor.
Definition: JBuildL1.hh:247
Clone of JSuperFrame2D.
Tools for handling different hit types.
JBuildL1(const JTriggerParameters &parameters)
Constructor.
Definition: JBuildL1.hh:237
Basic data structure for L0 hit.
void operator()(const JSuperFrame2D< JElement_t > &input, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL1.hh:261
Basic data structure for time and time over threshold information of hit.
std::vector< frame_type >::const_iterator const_iterator
JBuildL1(const JBuildL1Parameters &parameters)
Constructor.
Definition: JBuildL1.hh:115
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from DAQ data.
Definition: JBuildL1.hh:194
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
void operator()(const JSuperFrame2D< JElement_t > &input, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL1.hh:129
JRange< T, JComparator_t > combine(const JRange< T, JComparator_t > &first, const JRange< T, JComparator_t > &second)
Combine ranges.
Definition: JRange.hh:590
Template L1 hit builder.
Definition: JBuildL1.hh:76
JBuildL1(const double Tmax_ns, const bool combine)
Constructor.
Definition: JBuildL1.hh:339
Reduced data structure for L1 hit.
JBuildL1(const double Tmax_ns, const bool combine)
Constructor.
Definition: JBuildL1.hh:94
void operator()(const JSuperFrame2D< JElement_t > &input, JOutput_t out) const
Build hits from calibrated data.
Definition: JBuildL1.hh:374
JElement_t value_type
Definition: JBuildL1.hh:85
Data structure for L0 hit.
Definition: JHitL0.hh:27
Auxiliary data structure for L1 build parameters.
Definition: JBuildL1.hh:39
void operator()(const JDAQSuperFrame &input, const JModule &module, JOutput_t out) const
Build hits from uncalibrated DAQ data.
Definition: JBuildL1.hh:404
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
JBuildL1(const JTriggerParameters &parameters)
Constructor.
Definition: JBuildL1.hh:350
Auxiliary class to extend hit building functionality to all DAQ data types.
Definition: JBuildHelper.hh:44
Data frame of one optical module.
void operator()(typename JSuperFrame2D< JElement_t >::const_iterator __begin, typename JSuperFrame2D< JElement_t >::const_iterator __end, JOutput_t out) const
Build hits from set of frames with calibrated data.
Definition: JBuildL1.hh:145
Basic data structure for L1 hit.
JBuildL1(const JBuildL1Parameters &parameters)
Constructor.
Definition: JBuildL1.hh:360
Data structure for a composite optical module.