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 
10 
13 
14 #include "JGeometry3D/JAxis3D.hh"
15 
16 #include "JTools/JRange.hh"
17 
19 #include "JTrigger/JHitR0.hh"
20 #include "JTrigger/JMatchL0.hh"
26 
27 #include "TH1D.h"
28 
29 namespace JSUPERNOVA {
30 
31  using namespace std;
32  using namespace JPP;
33  using namespace KM3NETDAQ;
34 
35  /**
36  * Get ordinal of a module according to increasing number of string and floor
37  *
38  * \param location module location
39  * \param numberOfFloors detector number of floors
40  */
41  inline int getModuleIndex(const JLocation& location, const int numberOfFloors) {
42  return (location.getString() - 1) * numberOfFloors + location.getFloor();
43  }
44 
46 
48 
49  /**
50  * Get module indices from a set of modules
51  * \param in module set
52  * \param router module router
53  * \param numberOfFloors number of floors per string
54  */
55 
56  set<int> getModuleIndices(const JModuleSet& in, const JModuleRouter& router, int numberOfFloors = 18) {
57 
58  set<int> indices;
59 
60  for (JModuleSet::const_iterator p = in.begin(); p != in.end(); ++p) {
61  indices.insert(getModuleIndex(router.getModule(*p).getLocation(), numberOfFloors));
62  }
63 
64  return indices;
65  }
66 
67 
68  /**
69  * Auxiliary class to store reduced information of a coincidence on an optical module
70  */
72 
73  private:
74  double time;
76  int moduleID;
77 
78  public:
79  JCoincidenceSN(double t, int m, int dom)
80  : time(t), multiplicity(m), moduleID(dom)
81  { }
82 
83  int getMultiplicity() const {
84  return multiplicity;
85  }
86 
87  int getModule() const {
88  return moduleID;
89  }
90 
91  double getTime() const {
92  return time;
93  }
94 
95  bool operator<(const JCoincidenceSN& rhs) const {
96  return (time < rhs.time);
97  }
98 
99  };
100 
101  /**
102  * Auxiliary class to define a veto time window on a set of optical modules
103  */
104  class JVeto {
105 
106  private:
109 
110  public:
111 
112  /**
113  * Default constructor
114  * \param event DAQ event
115  * \param hitRouter hit router as source of hit time calibration
116  *
117  */
118  JVeto(const JDAQEvent& event, const JDAQHitRouter& hitRouter) {
119 
120  timeRange = JTimeRange::DEFAULT_RANGE;
121 
122  typedef JDAQTriggeredHit hit_type;
123 
124  for (JDAQEvent::const_iterator<hit_type> hit = event.begin<hit_type>();
125  hit != event.end<hit_type>();
126  ++hit) {
127 
128  moduleSet.insert(hit->getModuleID());
129 
130  timeRange.include(getTime(*hit, hitRouter.getPMT(*hit)));
131 
132  }
133  }
134 
135 
136  /**
137  * Get length of veto time range
138  */
139  double getLength() {
140  return timeRange.getLength();
141  }
142 
143  /**
144  * Determines if a coincidence is vetoed
145  * \param in coincidence under test
146  */
147  bool operator() (const JCoincidenceSN& in) const {
148  return timeRange(in.getTime()) &&
149  (moduleSet.find(in.getModule()) != moduleSet.end());
150  }
151 
152  };
153 
154 
155  /**
156  * Auxiliary class to build the supernova trigger dataset
157  */
158  class JDataSN
159  : public vector<JCoincidenceSN> {
160 
161  private:
162  int TMax_ns;
163  int min_M;
164 
165  public:
168 
169  /**
170  * Default constructor
171  * Configures the trigger with a time window and the pretrigger threshold.
172  */
173  JDataSN(double window, int threshold = 4)
174  : TMax_ns(window), min_M(threshold)
175  { };
176 
177  /**
178  * Builds coincidences from calibrated hit data and loads them in the internal vector.
179  * \param in hit data
180  * \param moduleID optical module ID for the hit data
181  */
182  void operator() (vector<JHitR0> in, int moduleID) {
183 
184  if (in.size() > 1) {
185 
186  for (vector<JHitR0>::const_iterator p = in.begin(); p != in.end(); ) {
187 
189 
190  while (++q != in.end() && q->getT() - p->getT() <= TMax_ns ) {}
191 
192  int M = distance(p, q);
193 
194  if (M >= min_M) {
195  this->push_back(JCoincidenceSN(p->getT(), M, moduleID));
196  }
197 
198  p = q;
199 
200  }
201  }
202  }
203 
204 
205  /**
206  * Builds coincidences from a timeslice and loads them into the internal vector.
207  * Double pulses are merged according to the coincidence time window.
208  *
209  * \param timeslice input timeslice
210  * \param moduleRouter detector module router
211  */
212  void operator() (const JDAQTimeslice* timeslice, const JModuleRouter& moduleRouter) {
213 
214  frameIndex = timeslice->getFrameIndex();
215  timeUTC = timeslice->getTimesliceStart();
216 
217  typedef JHitR0 hit_t;
218 
219  typedef JSuperFrame2D<hit_t> JSuperFrame2D_t;
220 
221  typedef JSuperFrame1D<hit_t> JSuperFrame1D_t;
222 
223  const JMatchL0<hit_t> match(TMax_ns);
224 
225  for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
226 
227  int moduleID = frame->getModuleID();
228 
229  JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame, moduleRouter.getModule(moduleID));
230 
231  buffer.preprocess(JPreprocessor::join_t, match);
232 
233  JSuperFrame1D_t& data = JSuperFrame1D_t::multiplex(buffer); data.pop_back();
234 
235  (*this)(data, moduleID);
236 
237  }
238 
239  sort(this->begin(), this->end());
240 
241  }
242 
243  };
244 
245 
246  /**
247  * Auxiliary class-operator to match a JVeto with a JCoincidenceSN object
248  * Provides an operator to test if a coincidence is vetoed
249  */
250 
251  class JMatchVeto {
252 
253  private:
255 
256  public:
257  /**
258  * Default constructor
259  * \param in coincidence to be matched against veto
260  */
261  JMatchVeto(const JCoincidenceSN& in) : dut(in) {}
262 
263  /**
264  * Operator
265  * \param in veto to be matched against inner coincidence
266  */
267  bool operator() (const JVeto& in) {
268  return in(dut);
269  }
270 
271  };
272 
273 
274  /**
275  * Auxiliary class to manage a set of vetoes
276  */
277  class JVetoSet : public vector<JVeto> {
278 
279  public:
280  /**
281  * Applies the veto set to a coincidence
282  * \param in coincidence to be tested
283  */
284  bool operator() (const JCoincidenceSN& in) const {
285  return any_of(this->begin(), this->end(), JMatchVeto(in));
286  }
287 
288  };
289 
290 
291  /**
292  * Auxiliary class to manage a cluster of coincidences
293  */
294  class JClusterSN : public vector<JCoincidenceSN> {
295 
296  public:
297 
298  /**
299  * Finds coincidence with maximum multiplicity.
300  */
302 
303  JClusterSN::const_iterator p = this->begin();
304 
305  for (JClusterSN::const_iterator q = p + 1; q != this->end(); q++) {
306  if (q->getMultiplicity() > p->getMultiplicity()) {
307  p = q;
308  }
309  }
310 
311  return (*p);
312 
313  }
314 
315 
316  /*
317  * Returns the set of modules spanned over by the cluster.
318  */
320 
321  JModuleSet out;
322 
323  for (JClusterSN::const_iterator p = this->begin(); p != this->end(); p++) {
324  out.insert(p->getModule());
325  }
326 
327  return out;
328  }
329 
330  };
331 
332 
333  /**
334  * Interface for SN filter operator.
335  * This operator is meant to determine the SN trigger count from a vector of JClusterSN
336  */
337  class JSNFilter {
338  public:
339  virtual bool operator() (const JCoincidenceSN& in) const = 0;
340  virtual bool operator() (const JClusterSN& in) const = 0;
341  };
342 
343 
344  /**
345  * SN filter based on multiplicity selection
346  * optional suppression of multi-module coincidences
347  * WARNING: no minimum threshold for the veto
348  */
349  class JSNFilterM : public JSNFilter {
350 
351  private:
353  bool mode;
354 
355  public:
357  : A(R), mode(m)
358  {}
359 
360  // select coincidence if within multiplicity acceptance
361  bool operator() (const JCoincidenceSN& in) const {
362  return A(in.getMultiplicity());
363  }
364 
365  // select cluster if any coincidence is accepted
366  // optionally veto if more of one module is interested
367  bool operator() (const JClusterSN& in) const {
368 
369  bool out = (*this)(in.getPeak());
370 
371  if (mode == 1) {
372  out = out && (in.getModules().size() == 1);
373  }
374 
375  return out;
376  }
377 
378  };
379 
380 
381  /**
382  * SN filter based on veto window
383  */
384  class JSNFilterMV : public JSNFilter {
385 
386  private:
389 
390  public:
392  : A(R), V(S)
393  {}
394 
395  bool operator() (const JCoincidenceSN& in) const {
396  return A(in.getMultiplicity()) && !V(in);
397  }
398 
399  bool operator() (const JClusterSN& in) const {
400  return (*this)(in.getPeak());
401  // return any_of(in.begin(), in.end(), *this);
402  }
403 
404  };
405 
406 
407 
408  /**
409  * Auxiliary class to apply the supernova trigger to SN data
410  */
411  class JTriggerSN : public vector<JClusterSN> {
412 
413  private:
414 
415  double TMaxCluster_ns = 1000.0;
416 
418 
419  public:
420 
423 
424  /**
425  * Default constructor
426  *
427  * \param TMax_ns time width for coincidence clustering (track / afterpulse)
428  */
429  JTriggerSN(double TMax_ns) :
430  TMaxCluster_ns(TMax_ns)
431  {};
432 
433  void setVeto(JVetoSet &vt) {
434  veto = vt;
435  }
436 
437 
438  /**
439  * Builds trigger by clustering pretrigger data
440  *
441  * \param in pretrigger SN data
442  */
443  void operator() (const JDataSN& in) {
444 
445  frameIndex = in.frameIndex;
446  timeUTC = in.timeUTC;
447 
448  for (vector<JCoincidenceSN>::const_iterator p = in.begin(); p != in.end(); ) {
449 
450  JClusterSN cluster;
451 
452  cluster.push_back(*p);
453 
455 
456  while(q != in.end() && (q->getTime() <= (p->getTime() + TMaxCluster_ns))) {
457  cluster.push_back(*q);
458  ++q;
459  }
460 
461  p = q;
462 
463  this->push_back(cluster);
464 
465  }
466  }
467 
468 
469  /**
470  * Get triggered modules after track veto
471  *
472  * \return std::set containing triggered modules IDs
473  */
475 
476  JModuleSet triggeredModules;
477 
478  JSNFilterM F(A, 1);
479 
480  for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
481 
482  if ( F(*p) ) {
483 
484  // only clusters with one module pass the selection JSNFilterM(A, 1)
485  triggeredModules.insert((*p)[0].getModule());
486 
487  }
488 
489  }
490 
491  return triggeredModules;
492 
493  }
494 
495 
496  /**
497  * Get triggered modules according to given filter
498  */
500 
501  JModuleSet out;
502 
503  for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
504  if ( F(*p) ) {
505  out.insert(p->getPeak().getModule());
506  }
507  }
508  return out;
509  }
510 
511  /**
512  * Fill histogram with multiplicity spectrum resulting from given filter
513  */
514  void fill(TH1D* out, const JSNFilter& F) {
515  for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
516  if (F(*p)) {
517  out->Fill( p->getPeak().getMultiplicity() );
518  }
519  }
520  }
521 
523  vector<double> out;
524 
525  for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
526  if (F(*p)) {
527  out.push_back( p->getPeak().getMultiplicity() );
528  }
529  }
530  return out;
531  }
532 
533 
534 
535 
536  /**
537  * > operator
538  * used by (reverse) std:priority_queue, in absence of this operator the container will behave unpredictably
539  */
540  bool operator>(const JTriggerSN& rhs) const {
541  return (frameIndex > rhs.frameIndex);
542  }
543 
544  /**
545  * < operator
546  */
547  bool operator<(const JTriggerSN& rhs) const {
548  return (frameIndex < rhs.frameIndex);
549  }
550 
551 
552  };
553 
554 
555  /**
556  * SN trigger statistics, the information is stored in the form of a count as a function of the trigger level.
557  * the livetime needs to be set manually to compute the rates for the printing.
558  */
559 
560  class JTriggerSNStats : public vector<double> {
561 
562  private:
563  double livetime;
564 
565  public:
566  /**
567  * default constructor
568  *
569  * \param nModules number of modules of the detector
570  */
571  JTriggerSNStats(const int nModules) : vector<double>(nModules) {}
572 
573  void setLiveTime(const double lt) {
574  livetime = lt;
575  }
576 
577  /**
578  * put statistics into printable form
579  * outputs trigger level - rate - error
580  */
581  string toString() {
582 
583  ostringstream os;
584 
585  os << "=== SUPERNOVA TRIGGER STATISTICS ==" << endl;
586  os << "=> livetime [s] = " << livetime << endl;
587  os << "Level" << '\t' << "Rate (error)" << endl;
588 
589  if (livetime > 0) {
590  for (unsigned i = 0; i < this->size(); i++) {
591 
592  double count = (*this)[i];
593  double rate = count / livetime;
594  double error = 100 * (sqrt(count) / count);
595 
596  if (rate > 0) {
597  os << i << '\t';
598  os << scientific << setprecision(2) << rate << "Hz ";
599  os << fixed << setprecision(0) << "(" << setw(2) << error << "%)";
600  os << endl;
601  }
602  }
603  }
604 
605  return os.str();
606 
607  }
608 
609 
610  /**
611  * put statistics into printable form
612  * outputs trigger level - rate - error
613  */
614  string toSummaryFile() {
615 
616  ostringstream os;
617 
618  if (livetime > 0) {
619 
620  os << livetime << endl;
621 
622  for (unsigned i = 0; i < this->size(); i++) {
623 
624  double count = (*this)[i];
625  double rate = count / livetime;
626  double error = (sqrt(count) / count);
627 
628  if (rate > 0) {
629  os << i << ",";
630  os << scientific;
631  os << setprecision(2);
632  os << rate << ",";
633  os << error;
634  os << endl;
635  }
636  }
637  }
638 
639 
640  return os.str();
641 
642  }
643 
644  };
645 
646 }
647 
648 #endif
int getModuleIndex(const JLocation &location, const int numberOfFloors)
Get ordinal of a module according to increasing number of string and floor.
Definition: JSupernova.hh:41
double getLength()
Get length of veto time range.
Definition: JSupernova.hh:139
JTriggerSNStats(const int nModules)
default constructor
Definition: JSupernova.hh:571
static const JRange< double, std::less< double > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:569
Interface for SN filter operator.
Definition: JSupernova.hh:337
Auxiliary class to store reduced information of a coincidence on an optical module.
Definition: JSupernova.hh:71
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:540
Auxiliaries for pre-processing of hits.
Direct access to PMT data in detector data structure for DAQ hits.
JDAQUTCExtended timeUTC
Definition: JSupernova.hh:422
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
JModuleSet getModules() const
Definition: JSupernova.hh:319
do $JPP JMEstimator M
Definition: JMEstimator.sh:37
Basic data structure for L0 hit.
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
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:474
JMatchVeto(const JCoincidenceSN &in)
Default constructor.
Definition: JSupernova.hh:261
Auxiliary class to define a veto time window on a set of optical modules.
Definition: JSupernova.hh:104
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
JCoincidenceSN dut
Definition: JSupernova.hh:254
L0 match criterion.
Definition: JMatchL0.hh:27
then check_input_file $DETECTOR $INPUT_FILE for OPTION in A B C D E F
Definition: JFilter.sh:47
Template const_iterator.
Definition: JDAQEvent.hh:68
SN filter based on veto window.
Definition: JSupernova.hh:384
Router for direct addressing of module data in detector data structure.
then set_variable singlesRate set_variable doublesRate set_variable numberOfSlices echo Generating random background echo Singles rate
bool operator<(const JCoincidenceSN &rhs) const
Definition: JSupernova.hh:95
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
int getMultiplicity() const
Definition: JSupernova.hh:83
JTriggerSN(double TMax_ns)
Default constructor.
Definition: JSupernova.hh:429
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:614
JDAQUTCExtended timeUTC
Definition: JSupernova.hh:167
JCoincidenceSN getPeak() const
Finds coincidence with maximum multiplicity.
Definition: JSupernova.hh:301
const_iterator< T > end() const
Get end of data.
void setVeto(JVetoSet &vt)
Definition: JSupernova.hh:433
join consecutive hits according match criterion
JTimeRange timeRange
Definition: JSupernova.hh:107
Reduced data structure for L0 hit.
Definition: JHitR0.hh:25
void fill(TH1D *out, const JSNFilter &F)
Fill histogram with multiplicity spectrum resulting from given filter.
Definition: JSupernova.hh:514
const_iterator< T > begin() const
Get begin of data.
Logical location of module.
Definition: JLocation.hh:37
const JLocation & getLocation() const
Get location.
Definition: JLocation.hh:69
string toString()
put statistics into printable form outputs trigger level - rate - error
Definition: JSupernova.hh:581
SN trigger statistics, the information is stored in the form of a count as a function of the trigger ...
Definition: JSupernova.hh:560
JCoincidenceSN(double t, int m, int dom)
Definition: JSupernova.hh:79
JVeto(const JDAQEvent &event, const JDAQHitRouter &hitRouter)
Default constructor.
Definition: JSupernova.hh:118
vector< double > multiplicities_t
Definition: JSupernova.hh:45
Auxiliary class to apply the supernova trigger to SN data.
Definition: JSupernova.hh:411
Data time slice.
SN filter based on multiplicity selection optional suppression of multi-module coincidences WARNING: ...
Definition: JSupernova.hh:349
Match operator for consecutive hits.
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:40
double getTime() const
Definition: JSupernova.hh:91
bool operator<(const JTriggerSN &rhs) const
&lt; operator
Definition: JSupernova.hh:547
Direct access to module in detector data structure.
Auxiliary class to build the supernova trigger dataset.
Definition: JSupernova.hh:158
do set_variable SIGMA_NS set_variable OUTLIERS set_variable OUTPUT_FILE matrix[${ALPHA_DEG}\deg\] root $JPP JMatrixNZ a $DETECTOR f $INPUT_FILE o $OUTPUT_FILE S
Definition: JMatrixNZ.sh:56
set< int > JModuleSet
Definition: JSupernova.hh:47
int getString() const
Get string number.
Definition: JLocation.hh:134
JModuleSet getModules(const JSNFilter &F)
Get triggered modules according to given filter.
Definition: JSupernova.hh:499
Normalisation of MUPAGE events.
Definition: JHead.hh:604
std::vector< int > count
Definition: JAlgorithm.hh:184
Auxiliary class to define a range between two values.
JSNFilterMV(JRange< int > &R, JVetoSet &S)
Definition: JSupernova.hh:391
Auxiliary class to manage a cluster of coincidences.
Definition: JSupernova.hh:294
Auxiliary class-operator to match a JVeto with a JCoincidenceSN object Provides an operator to test i...
Definition: JSupernova.hh:251
const char *const hit_t
Definition: io_ascii.hh:23
2-dimensional frame with time calibrated data from one optical module.
void setLiveTime(const double lt)
Definition: JSupernova.hh:573
JDataSN(double window, int threshold=4)
Default constructor Configures the trigger with a time window and the pretrigger threshold.
Definition: JSupernova.hh:173
set< int > getModuleIndices(const JModuleSet &in, const JModuleRouter &router, int numberOfFloors=18)
Get module indices from a set of modules.
Definition: JSupernova.hh:56
const JPMT & getPMT(const JDAQKeyHit &hit) const
Get PMT parameters.
JSNFilterM(JRange< int > R, int m=0)
Definition: JSupernova.hh:356
JModuleSet moduleSet
Definition: JSupernova.hh:108
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number
vector< double > getMultiplicities(const JSNFilter &F)
Definition: JSupernova.hh:522
Auxiliary class to manage a set of vetoes.
Definition: JSupernova.hh:277