Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSupernova.hh
Go to the documentation of this file.
1 #ifndef __JSUPERNOVA_JSUPERNOVA__
2 #define __JSUPERNOVA_JSUPERNOVA__
3 
4 #include <set>
5 
6 #include "JDAQ/JDAQEvent.hh"
8 #include "JDAQ/JDAQTimeslice.hh"
10 
13 
14 #include "JTools/JRange.hh"
15 
17 #include "JTrigger/JHitR0.hh"
20 
21 #include "TH1D.h"
22 
23 namespace JSUPERNOVA {
24 
25  using namespace std;
26  using namespace JPP;
27  using namespace KM3NETDAQ;
28 
30 
31  /**
32  * Auxiliary class to store reduced information of a coincidence on an optical module
33  */
35 
36  private:
37  double time;
39  int moduleID;
40 
41  public:
42  JCoincidenceSN(double t, int m, int dom)
43  : time(t), multiplicity(m), moduleID(dom)
44  { }
45 
46  int getMultiplicity() const {
47  return multiplicity;
48  }
49 
50  int getModule() const {
51  return moduleID;
52  }
53 
54  double getTime() const {
55  return time;
56  }
57 
58  bool operator<(const JCoincidenceSN& rhs) const {
59  return (time < rhs.time);
60  }
61 
62  };
63 
64  /**
65  * Auxiliary class to define a veto time window on a set of optical modules
66  */
67  class JVeto {
68 
69  private:
72 
73  public:
74 
75  /**
76  * Default constructor
77  * \param event DAQ event
78  * \param hitRouter hit router as source of hit time calibration
79  *
80  */
81  JVeto(const JDAQEvent& event, const JDAQHitRouter& hitRouter) {
82 
83  timeRange = JTimeRange::DEFAULT_RANGE;
84 
85  typedef JDAQTriggeredHit JHit_t;
86 
87  for (JDAQEvent::const_iterator<JHit_t> hit = event.begin<JHit_t>();
88  hit != event.end<JHit_t>();
89  ++hit) {
90 
91  moduleSet.insert(hit->getModuleID());
92 
93  timeRange.include(getTime(*hit, hitRouter.getPMT(*hit)));
94 
95  }
96  }
97 
98 
99  /**
100  * Get length of veto time range
101  */
102  double getLength() {
103  return timeRange.getLength();
104  }
105 
106  /**
107  * Determines if a coincidence is vetoed
108  * \param in coincidence under test
109  */
110  bool operator() (const JCoincidenceSN& in) const {
111  return timeRange(in.getTime()) &&
112  (moduleSet.find(in.getModule()) != moduleSet.end());
113  }
114 
115  };
116 
117 
118  /**
119  * Auxiliary class to build the supernova trigger dataset
120  */
121  class JDataSN
122  : public vector<JCoincidenceSN> {
123 
124  private:
125  int TMax_ns;
127 
128  public:
131 
132  /**
133  * Default constructor
134  * Configures the trigger with a time window and the pretrigger threshold.
135  */
136  JDataSN(double window, int threshold = 4)
137  : TMax_ns(window), multiplicityThreshold(threshold)
138  { };
139 
140  /**
141  * Builds coincidences from calibrated hit data and loads them in the internal vector.
142  * \param in hit data
143  * \param moduleID optical module ID for the hit data
144  */
145  void operator() (vector<JHitR0> in, int moduleID) {
146 
147  if (in.size() > 1) {
148 
149  for (vector<JHitR0>::const_iterator p = in.begin(); p != in.end(); ) {
150 
152 
153  while (++q != in.end() && q->getT() - p->getT() <= TMax_ns ) {}
154 
155  int M = distance(p, q);
156 
157  if (M >= multiplicityThreshold)
158  { this->push_back(JCoincidenceSN(p->getT(), M, moduleID)); }
159 
160  p = q;
161 
162  }
163  }
164  }
165 
166 
167  /**
168  * Builds coincidences from a timeslice and loads them into the internal vector.
169  * Double pulses are merged according to the coincidence time window.
170  *
171  * \param timeslice input timeslice
172  * \param moduleRouter detector module router
173  */
174  void operator() (const JDAQTimeslice* timeslice, const JModuleRouter& moduleRouter) {
175 
176  frameIndex = timeslice->getFrameIndex();
177  timeUTC = timeslice->getTimesliceStart();
178 
180 
182 
183  const JMatch_t match(TMax_ns);
184 
185  for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
186 
187  int moduleID = frame->getModuleID();
188 
189  JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame, moduleRouter.getModule(moduleID));
190 
191  for (JSuperFrame2D_t::iterator i = buffer.begin(); i != buffer.end(); ++i) { i->join(match); }
192 
193  JSuperFrame1D_t& data = JSuperFrame1D_t::multiplex(buffer); data.pop_back();
194 
195  (*this)(data, moduleID);
196 
197  }
198 
199  sort(this->begin(), this->end());
200 
201  }
202 
203  };
204 
205 
206  /**
207  * Auxiliary class-operator to match a JVeto with a JCoincidenceSN object
208  * Provides an operator to test if a coincidence is vetoed
209  */
210 
211  class JMatchVeto {
212 
213  private:
215 
216  public:
217  /**
218  * Default constructor
219  * \param in coincidence to be matched against veto
220  */
221  JMatchVeto(const JCoincidenceSN& in) : dut(in) {}
222 
223  /**
224  * Operator
225  * \param in veto to be matched against inner coincidence
226  */
227  bool operator() (const JVeto& in) {
228  return in(dut);
229  }
230 
231  };
232 
233 
234  /**
235  * Auxiliary class to manage a set of vetoes
236  */
237  class JVetoSet : public vector<JVeto> {
238 
239  public:
240  /**
241  * Applies the veto set to a coincidence
242  * \param in coincidence to be tested
243  */
244  bool operator() (const JCoincidenceSN& in) {
245  return any_of(this->begin(), this->end(), JMatchVeto(in));
246  }
247 
248  };
249 
250 
251  /**
252  * Auxiliary class to manage a cluster of coincidences
253  */
254  class JClusterSN : public vector<JCoincidenceSN> {
255 
256  public:
257  /*
258  * Return the set of modules spanned over by the cluster
259  */
261 
262  JModuleSet out;
263 
264  for (JClusterSN::const_iterator p = this->begin(); p != this->end(); p++) {
265  out.insert(p->getModule());
266  }
267 
268  return out;
269  }
270 
271 
272 
273  /*
274  * Return the set of modules spanned over by the cluster
275  * \param multiplicityThreshold minimum multiplicity to count the coincidence
276  */
277  JModuleSet getModules(int multiplicityThreshold) const {
278 
279  JModuleSet out;
280 
281  for (JClusterSN::const_iterator p = this->begin(); p != this->end(); p++) {
282  if (p->getMultiplicity() >= multiplicityThreshold) {
283  out.insert(p->getModule());
284  }
285  }
286 
287  return out;
288  }
289 
290 
291  };
292 
293 
294  /**
295  * Interface for SN filter operator.
296  * This operator is meant to determine the SN trigger count.
297  */
298  class JSNFilter {
299  public:
300  virtual bool operator() (const JCoincidenceSN& in) = 0;
301  virtual bool operator() (const JClusterSN& in) = 0;
302  };
303 
304 
305  /**
306  * SN filter based on multiplicity selection
307  * optional suppression of multi-module coincidences
308  */
310 
311  private:
313  bool mode;
314 
315  public:
316  JSNFilterM(JRange<int> R, int m = 0) : A(R), mode(m) {}
317 
318  bool operator() (const JCoincidenceSN& in) {
319  return A(in.getMultiplicity());
320  }
321 
322  bool operator() (const JClusterSN& in) {
323  bool out = any_of(in.begin(), in.end(), *this);
324 
325  if (mode == 1) {
326  out = out && (in.getModules().size() == 1);
327  }
328 
329  return out;
330  }
331 
332  };
333 
334 
335  /**
336  * Select clusters without correlated coincidences
337  */
341 
342  public:
343  JSNFilterNM(const int n, const int m) :
344  numberOfModules(n), multiplicityThreshold(m)
345  {}
346 
347  bool operator() (const JCoincidenceSN& in) {
348  return true;
349  }
350 
351  bool operator() (const JClusterSN& in) {
352  JModuleSet modules = in.getModules(multiplicityThreshold);
353  return (modules.size() <= 1);
354  }
355 
356  };
357 
358 
359  /**
360  * SN filter based on veto window
361  */
363 
364  private:
367 
368  public:
369  JSNFilterMV(JRange<int>& R, JVetoSet& S) : A(R), V(S) {}
370 
371  bool operator() (const JCoincidenceSN& in) {
372  return A(in.getMultiplicity()) && !V(in);
373  }
374 
375  bool operator() (const JClusterSN& in) {
376  return any_of(in.begin(), in.end(), *this);
377  }
378 
379  };
380 
381 
382  /**
383  * Auxiliary class to apply the supernova trigger to SN data
384  */
385  class JTriggerSN : public vector<JClusterSN> {
386 
387  private:
388 
389  double TMaxCluster_ms = 1000.0;
390 
392 
393  public:
394 
397 
398  /**
399  * Default constructor
400  *
401  * \param tRange multiplicity range for selection of supernova coincidences
402  * \param TMax_ms time width for coincidence clustering (track / afterpulse)
403  */
404  JTriggerSN(JRange<int> tRange, double TMax_ms) :
405  TMaxCluster_ms(TMax_ms)
406  {};
407 
408  void setVeto(JVetoSet &vt) {
409  veto = vt;
410  }
411 
412 
413  /**
414  * Builds trigger
415  *
416  * \param in pretrigger SN data
417  */
418  void operator() (const JDataSN& in) {
419 
420  frameIndex = in.frameIndex;
421  timeUTC = in.timeUTC;
422 
423  for (vector<JCoincidenceSN>::const_iterator p = in.begin(); p != in.end(); ) {
424 
425  JClusterSN cluster;
426 
427  cluster.push_back(*p);
428 
430 
431  while(q != in.end() && (q->getTime() <= (p->getTime() + TMaxCluster_ms))) {
432  cluster.push_back(*q);
433  ++q;
434  }
435 
436  p = q;
437 
438  this->push_back(cluster);
439 
440  }
441  }
442 
443 
444  /**
445  * Benchmark different trigger steps
446  *
447  * 0: count every triggering cluster of coincidences
448  * 1: track veto based on time-correlated coincidences
449  * 2: track veto based on triggered events
450  * \return vector with count as a function of trigger step
451  */
453 
454  const int nBenchmarks = 3;
455 
456  vector<int> bench(nBenchmarks, 0);
457 
458  bench[0] = count_if(this->begin(), this->end(), JSNFilterM(A, 0));
459  bench[1] = count_if(this->begin(), this->end(), JSNFilterM(A, 1));
460  bench[2] = count_if(this->begin(), this->end(), JSNFilterMV(A, veto));
461 
462  return bench;
463 
464  }
465 
466 
467  /**
468  * Get triggered modules after track veto
469  *
470  * \return std::set containing triggered modules IDs
471  */
473 
474  JModuleSet triggeredModules;
475 
476  JSNFilterM F(A, 1);
477 
478  for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
479 
480  if ( F(*p) ) {
481  triggeredModules.insert((*p)[0].getModule());
482  }
483 
484  }
485 
486  return triggeredModules;
487 
488  }
489 
490 
491  /**
492  * Get modules according to a filter criterion
493  JModuleSet getModules(const JSNFilter& F) {
494  JModuleSet out;
495 
496  for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
497  if (F(*p)) {
498 
499  }
500  }
501 
502  }*/
503 
504 
505  /**
506  * Fills histogram with multiplicity counts
507  */
508  void fill(TH1D* out, const JSNFilter& F) {
509  for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
510 
511  JSNFilterNM F(2, 4);
512 
513 
514  for (JClusterSN::const_iterator q = p->begin(); q != p->end(); q++) {
515 
516  }
517  }
518  }
519 
520  /**
521  * > operator
522  * used by (reverse) std:priority_queue, in absence of this operator the container will behave unpredictably
523  */
524  bool operator>(const JTriggerSN& rhs) const {
525  return (frameIndex > rhs.frameIndex);
526  }
527 
528  /**
529  * < operator
530  */
531  bool operator<(const JTriggerSN& rhs) const {
532  return (frameIndex < rhs.frameIndex);
533  }
534 
535 
536  };
537 
538 
539  /**
540  * SN trigger summary information
541  *
542  */
543  class JSummarySN {
544  private:
545  int DETID;
547  int RUNNR;
548  int frame;
549  int trigger;
551 
552  public:
553  JSummarySN(int d, int am, int r, int f, JDAQUTCExtended tm, int tr)
554  : DETID(d), activeModules(am), RUNNR(r), frame(f), trigger(tr), time(tm)
555  { }
556 
557  friend inline std::ostream& operator<<(std::ostream& out, const JSummarySN& summary) {
558  out << summary.DETID << " ";
559  out << summary.activeModules << " ";
560  out << summary.RUNNR << " ";
561  out << summary.frame << " ";
562  out << summary.time << " ";
563  out << summary.trigger;
564 
565  return out;
566  }
567 
568  friend inline std::istream& operator>>(std::istream& in, JSummarySN& summary) {
569  in >> summary.DETID;
570  in >> summary.activeModules;
571  in >> summary.RUNNR;
572  in >> summary.frame;
573  in >> summary.time ;
574  in >> summary.trigger;
575 
576  return in;
577  }
578 
579  };
580 
581  /**
582  * SN trigger statistics, the information is stored in the form of a count as a function of the trigger level.
583  * the livetime needs to be set manually to compute the rates for the printing.
584  */
585 
586  class JTriggerSNStats : public vector<double> {
587 
588  private:
589  double livetime;
590 
591  public:
592  /**
593  * default constructor
594  *
595  * \param nModules number of modules of the detector
596  */
597  JTriggerSNStats(const int nModules) : vector<double>(nModules) {}
598 
599  void setLiveTime(const double lt) {
600  livetime = lt;
601  }
602 
603  /**
604  * put statistics into printable form
605  * outputs trigger level - rate - error
606  */
607  string toString() {
608 
609  ostringstream os;
610 
611  os << "=== SUPERNOVA TRIGGER STATISTICS ==" << endl;
612  os << "=> livetime [s] = " << livetime << endl;
613  os << "Level" << '\t' << "Rate (error)" << endl;
614 
615  if (livetime > 0) {
616  for (unsigned i = 0; i < this->size(); i++) {
617 
618  double count = (*this)[i];
619  double rate = count / livetime;
620  double error = 100 * (sqrt(count) / count);
621 
622  if (rate > 0) {
623  os << i << '\t';
624  os << scientific << setprecision(2) << rate << "Hz ";
625  os << fixed << setprecision(0) << "(" << setw(2) << error << "%)";
626  os << endl;
627  }
628  }
629  }
630 
631  return os.str();
632 
633  }
634 
635 
636  /**
637  * put statistics into printable form
638  * outputs trigger level - rate - error
639  */
640  string toSummaryFile() {
641 
642  ostringstream os;
643 
644  if (livetime > 0) {
645 
646  os << livetime << endl;
647 
648  for (unsigned i = 0; i < this->size(); i++) {
649 
650  double count = (*this)[i];
651  double rate = count / livetime;
652  double error = (sqrt(count) / count);
653 
654  if (rate > 0) {
655  os << i << ",";
656  os << scientific;
657  os << setprecision(2);
658  os << rate << ",";
659  os << error;
660  os << endl;
661  }
662  }
663  }
664 
665 
666  return os.str();
667 
668  }
669 
670  };
671 
672 }
673 
674 #endif
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:22
double getLength()
Get length of veto time range.
Definition: JSupernova.hh:102
JTriggerSNStats(const int nModules)
default constructor
Definition: JSupernova.hh:597
static const JRange< double, std::less< double > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:506
Interface for SN filter operator.
Definition: JSupernova.hh:298
Auxiliary class to store reduced information of a coincidence on an optical module.
Definition: JSupernova.hh:34
bool operator>(const JTriggerSN &rhs) const
operatorused by (reverse) std:priority_queue, in absence of this operator the container will behave u...
Definition: JSupernova.hh:524
SN trigger summary information.
Definition: JSupernova.hh:543
Direct access to PMT data in detector data structure for DAQ hits.
const JDAQUTCExtended & getTimesliceStart() const
Get start of timeslice.
JDAQUTCExtended timeUTC
Definition: JSupernova.hh:396
JSummarySN(int d, int am, int r, int f, JDAQUTCExtended tm, int tr)
Definition: JSupernova.hh:553
JModuleSet getModules() const
Definition: JSupernova.hh:260
Basic data structure for L0 hit.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
JModuleSet getModules(JRange< int > A=JRange< int >(6, 10))
Get triggered modules after track veto.
Definition: JSupernova.hh:472
JMatchVeto(const JCoincidenceSN &in)
Default constructor.
Definition: JSupernova.hh:221
Auxiliary class to define a veto time window on a set of optical modules.
Definition: JSupernova.hh:67
JCoincidenceSN dut
Definition: JSupernova.hh:214
Template const_iterator.
Definition: JDAQEvent.hh:69
SN filter based on veto window.
Definition: JSupernova.hh:362
Router for direct addressing of module data in detector data structure.
bool operator<(const JCoincidenceSN &rhs) const
Definition: JSupernova.hh:58
JModuleSet getModules(int multiplicityThreshold) const
Definition: JSupernova.hh:277
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
friend std::istream & operator>>(std::istream &in, JSummarySN &summary)
Definition: JSupernova.hh:568
int getMultiplicity() const
Definition: JSupernova.hh:46
JSuperFrame2D< hit_type > JSuperFrame2D_t
Definition: JDataFilter.cc:93
double getTime(const Hit &hit)
Get true time of hit.
Data structure for UTC time.
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
int getFrameIndex() const
Get frame index.
1-dimensional frame with time calibrated data from one optical module.
string toSummaryFile()
put statistics into printable form outputs trigger level - rate - error
Definition: JSupernova.hh:640
JDAQUTCExtended timeUTC
Definition: JSupernova.hh:130
const_iterator< T > end() const
Get end of data.
void setVeto(JVetoSet &vt)
Definition: JSupernova.hh:408
JTimeRange timeRange
Definition: JSupernova.hh:70
void fill(TH1D *out, const JSNFilter &F)
Get modules according to a filter criterion JModuleSet getModules(const JSNFilter&amp; F) { JModuleSet ou...
Definition: JSupernova.hh:508
const_iterator< T > begin() const
Get begin of data.
string toString()
put statistics into printable form outputs trigger level - rate - error
Definition: JSupernova.hh:607
SN trigger statistics, the information is stored in the form of a count as a function of the trigger ...
Definition: JSupernova.hh:586
JCoincidenceSN(double t, int m, int dom)
Definition: JSupernova.hh:42
JVeto(const JDAQEvent &event, const JDAQHitRouter &hitRouter)
Default constructor.
Definition: JSupernova.hh:81
Auxiliary class to apply the supernova trigger to SN data.
Definition: JSupernova.hh:385
Data time slice.
SN filter based on multiplicity selection optional suppression of multi-module coincidences.
Definition: JSupernova.hh:309
vector< int > benchmark(JRange< int > A=JRange< int >(6, 10))
Benchmark different trigger steps.
Definition: JSupernova.hh:452
double getTime() const
Definition: JSupernova.hh:54
bool operator<(const JTriggerSN &rhs) const
&lt; operator
Definition: JSupernova.hh:531
Direct access to module in detector data structure.
Select clusters without correlated coincidences.
Definition: JSupernova.hh:338
JDAQUTCExtended time
Definition: JSupernova.hh:550
Auxiliary class to build the supernova trigger dataset.
Definition: JSupernova.hh:121
set< int > JModuleSet
Definition: JSupernova.hh:29
Normalisation of MUPAGE events.
Definition: JHead.hh:537
Auxiliary class to define a range between two values.
JSNFilterMV(JRange< int > &R, JVetoSet &S)
Definition: JSupernova.hh:369
Auxiliary class to manage a cluster of coincidences.
Definition: JSupernova.hh:254
std::vector< frame_type >::iterator iterator
Auxiliary class to check whether two consecutive hits should be joined.
Definition: JHit.hh:275
Auxiliary class-operator to match a JVeto with a JCoincidenceSN object Provides an operator to test i...
Definition: JSupernova.hh:211
2-dimensional frame with time calibrated data from one optical module.
void setLiveTime(const double lt)
Definition: JSupernova.hh:599
JDataSN(double window, int threshold=4)
Default constructor Configures the trigger with a time window and the pretrigger threshold.
Definition: JSupernova.hh:136
const JPMT & getPMT(const JDAQKeyHit &hit) const
Get PMT parameters.
friend std::ostream & operator<<(std::ostream &out, const JSummarySN &summary)
Definition: JSupernova.hh:557
JTriggerSN(JRange< int > tRange, double TMax_ms)
Default constructor.
Definition: JSupernova.hh:404
JSNFilterM(JRange< int > R, int m=0)
Definition: JSupernova.hh:316
JModuleSet moduleSet
Definition: JSupernova.hh:71
JSNFilterNM(const int n, const int m)
Definition: JSupernova.hh:343
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number
JSuperFrame1D< hit_type > JSuperFrame1D_t
Definition: JDataFilter.cc:92
Auxiliary class to manage a set of vetoes.
Definition: JSupernova.hh:237