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