Jpp test-rotations-old-57-g407471f53
the software that should make you happy
Loading...
Searching...
No Matches
JSupernova.hh
Go to the documentation of this file.
1#ifndef __JSUPERNOVA_JSUPERNOVA__
2#define __JSUPERNOVA_JSUPERNOVA__
3
4#include <set>
5
10
13
15
16#include "JTools/JRange.hh"
17
20#include "JTrigger/JHitR0.hh"
21#include "JTrigger/JMatchL0.hh"
27
28#include "TH1D.h"
29
32
33/**
34 * \author mlincett,selhedri,iagoos
35 */
36
37namespace JSUPERNOVA {
38
39 using namespace std;
40 using namespace JPP;
41 using namespace KM3NETDAQ;
42
44
46
47 /**
48 * Auxiliary class to store reduced information of a coincidence on an optical module
49 * This class allows storing the observables associated with searches for low-energy
50 * neutrinos from Core-Collapse supernovae:
51 */
53
54 public:
55 double time;
59 // Observables computed using hits in 10ns window in same DOM
61 double mean_dir_ctheta = -2; // mean PMT direction cos(theta)
62 double mean_dir_norm = -1; // hit concentration |R|
63 double deltaT = -1; // mean time spread
64 double total_ToT = -1; // total ToT
65 bool fake = false; // For fire drills (when simulated events are injected)
66
67 void clear(){
68 this->vetoIndex = 0;
69 this->multiplicity = 0;
70 this->mean_dir_ctheta = -2;
71 this->mean_dir_norm = -1;
72 this->total_ToT = -1;
73 this->deltaT = -1;
74 this->fake = false;
75 }
76
77 /**
78 * Constructor:
79 *
80 * \param t Event timing within a timeslice
81 * \param m Number of hits within 10ns
82 * \param dom ID of the module
83 * \param vetoIndex Muon veto index: 0 if pass all vetoes, 1 if pass only trigger veto, 2 if pass only correlation veto, 3 if fails all vetoes
84 * \param ctheta Mean z position of hit cluster on DOM
85 * \param rnorm Hit concentration |R|
86 * \param deltaT Average time spread of hit cluster
87 * \param total_ToT Total ToT in DOM
88 * \param timeslice_time Absolute time of the timeslice
89 */
90 JCoincidenceSN(double t, int m, int dom, int vetoIndex=-1, double ctheta=-2, double rnorm=-1, double deltaT=-1, double total_ToT=-1, double timeslice_time=-1, bool fake=false)
92 { }
93
94 /**
95 * Compute single-DOM observables |R|, cos(theta), total ToT, and Delta(t) and set the corresponding class attributes
96 *
97 * \param hits Hit vector from timeslice
98 * \param det Single-DOM detx file used to simulate CCSN signal
99 */
100 bool operator()(const vector<JHitR0>& hits, const JDetector& det){
101 if (hits.size() == 0) return 1;
102 JVector3D mean_pmt_dir;
103 double first_hit_time = 0;
104 this->total_ToT = 0;
105 this->multiplicity = 0;
106 this->deltaT = 0;
107 int hitcount=0;
108 for(auto &hit: hits){
109 this->multiplicity++;
110 this->total_ToT += hit.getToT();
111 if (hitcount > 0) {
112 this->deltaT += hit.getT() - first_hit_time;
113 }
114 else first_hit_time = hit.getT();
115 int channel_id = hit.getPMT();
116 JPMTAddress pmt_address(JModuleRouter(det).getAddress(101),channel_id);
117 auto pmt = det.getPMT(pmt_address).getDirection();
118 mean_pmt_dir += pmt.getDirection();
119 hitcount++;
120 }
121 if (this->multiplicity >= 2) {
122 this->mean_dir_norm = mean_pmt_dir.getLength()/this->multiplicity;
123 this->mean_dir_ctheta = mean_pmt_dir.getZ()/this->multiplicity;
124 this->deltaT /= (this->multiplicity-1);
125 }
126 return 0;
127 }
128
129 int getMultiplicity() const {
130 return multiplicity;
131 }
132
133 int getModule() const {
134 return moduleID;
135 }
136
137 double getTime() const {
138 return time;
139 }
140
141 bool operator<(const JCoincidenceSN& rhs) const {
142 return (time < rhs.time);
143 }
144
145 };
146
147 /**
148 * Auxiliary class to define a veto time window on a set of optical modules
149 */
150 class JVeto {
151
152 private:
155
156 public:
157
158 /**
159 * Default constructor
160 * \param event DAQ event
161 * \param hitRouter hit router as source of hit time calibration
162 *
163 */
164 JVeto(const JDAQEvent& event, const JDAQHitRouter& hitRouter) {
165
167
169
171 hit != event.end<hit_type>();
172 ++hit) {
173
174 moduleSet.insert(hit->getModuleID());
175
176 timeRange.include(getTime(*hit, hitRouter.getPMT(*hit)));
177
178 }
179 }
180
181
182 /**
183 * Get length of veto time range
184 */
185 double getLength() {
186 return timeRange.getLength();
187 }
188
189 /**
190 * Determines if a coincidence is vetoed
191 * \param in coincidence under test
192 */
193 bool operator() (const JCoincidenceSN& in) const {
194 return timeRange(in.getTime()) &&
195 (moduleSet.find(in.getModule()) != moduleSet.end());
196 }
197
198 };
199
200
201 /**
202 * Auxiliary class to build the supernova trigger dataset
203 */
205 : public vector<JCoincidenceSN> {
206
207 private:
209 int min_M;
210 // JDAQHitSelector& hitSelector;// = JDAQHitDefaultSelector();
211
212 public:
215
216 /**
217 * Default constructor
218 * Configures the trigger with a time window and the pretrigger threshold.
219 */
220 JDataSN(double window, int threshold = 4) // JDAQHitSelector& selector = JDAQHitDefaultSelector())
221 : TMax_ns(window), min_M(threshold) // , hitSelector(selector)
222 { };
223
224 /**
225 * Builds coincidences from calibrated hit data and loads them in the internal vector.
226 * \param in hit data
227 * \param moduleID optical module ID for the hit data
228 * \param det single-DOM detx file used to simulate CCSN neutrinos (default: empty detector)
229 */
230 void operator() (const vector<JHitR0>& in, const int& moduleID, const JDetector& det = JDetector()) {
231
232 if (in.size() > 1) {
233
234 for (vector<JHitR0>::const_iterator p = in.begin(); p != in.end(); ) {
235
236 vector<JHitR0>::const_iterator q = p;
237
238 while (++q != in.end() && q->getT() - p->getT() <= TMax_ns ) {}
239
240 int M = distance(p, q);
241
242 if (M >= min_M) {
243 JCoincidenceSN coincidence(p->getT(), M, moduleID);
244 if (det.size() > 0) {
245 vector<JHitR0> coincidence_hits;
246 coincidence_hits.assign(p,q);
247 coincidence(coincidence_hits, det);
248 }
249 this->push_back(coincidence);
250 }
251
252 p = q;
253
254 }
255 }
256 }
257
258
259 /**
260 * Builds coincidences from a timeslice and loads them into the internal vector.
261 * Double pulses are merged according to the coincidence time window.
262 *
263 * \param timeslice input timeslice
264 * \param moduleRouter detector module router
265 * \param selector hit selector
266 * \param det single-DOM detx file used to simulate signal events
267 */
268 void operator() (const JDAQTimeslice* timeslice, const JModuleRouter& moduleRouter, const JDAQHitSelector& selector = JDAQHitDefaultSelector(), const JDetector& det = JDetector()) {
269
270 frameIndex = timeslice->getFrameIndex();
271 timeUTC = timeslice->getTimesliceStart();
272
273 typedef JHitR0 hit_t;
274
275 typedef JSuperFrame2D<hit_t> JSuperFrame2D_t;
276
277 typedef JSuperFrame1D<hit_t> JSuperFrame1D_t;
278
279 const JMatchL0<hit_t> match(TMax_ns);
280
281 for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
282
283 int moduleID = frame->getModuleID();
284
285 JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame,
286 moduleRouter.getModule(moduleID),
287 selector);
288
289 buffer.preprocess(JPreprocessor::join_t, match);
290
291 JSuperFrame1D_t& data = JSuperFrame1D_t::multiplex(buffer);
292
293 if (det.size() < 0)(*this)(data, moduleID);
294 else (*this)(data, moduleID, det);
295
296 }
297
298 sort(this->begin(), this->end());
299
300 }
301
302 };
303
304
305 /**
306 * Auxiliary class-operator to match a JVeto with a JCoincidenceSN object
307 * Provides an operator to test if a coincidence is vetoed
308 */
309
311
312 private:
314
315 public:
316 /**
317 * Default constructor
318 * \param in coincidence to be matched against veto
319 */
320 JMatchVeto(const JCoincidenceSN& in) : dut(in) {}
321
322 /**
323 * Operator
324 * \param in veto to be matched against inner coincidence
325 */
326 bool operator() (const JVeto& in) {
327 return in(dut);
328 }
329
330 };
331
332
333 /**
334 * Auxiliary class to manage a set of vetoes
335 */
336 class JVetoSet : public vector<JVeto> {
337
338 public:
339 /**
340 * Applies the veto set to a coincidence
341 * \param in coincidence to be tested
342 */
343 bool operator() (const JCoincidenceSN& in) const {
344 return any_of(this->begin(), this->end(), JMatchVeto(in));
345 }
346
347 };
348
349
350 /**
351 * Auxiliary class to manage a cluster of coincidences
352 */
353 class JClusterSN : public vector<JCoincidenceSN> {
354
355 public:
356
357 /**
358 * Finds coincidence with maximum multiplicity.
359 */
361
362 JClusterSN::const_iterator p = this->begin();
363
364 for (JClusterSN::const_iterator q = p + 1; q != this->end(); q++) {
365 if (q->getMultiplicity() > p->getMultiplicity()) {
366 p = q;
367 }
368 }
369
370 return (*p);
371
372 }
373
374
375 /*
376 * Returns the set of modules spanned over by the cluster.
377 */
379
380 JModuleSet out;
381
382 for (JClusterSN::const_iterator p = this->begin(); p != this->end(); p++) {
383 out.insert(p->getModule());
384 }
385
386 return out;
387 }
388
389 };
390
391
392 /**
393 * Interface for SN filter operator.
394 * This operator is meant to determine the SN trigger count from a vector of JClusterSN
395 */
396 class JSNFilter {
397 public:
398 virtual bool operator() (const JCoincidenceSN& in) const = 0;
399 virtual bool operator() (const JClusterSN& in) const = 0;
400 };
401
402
403 /**
404 * SN filter based on multiplicity selection
405 * optional suppression of multi-module coincidences
406 * WARNING: no minimum threshold for the veto
407 */
408 class JSNFilterM : public JSNFilter {
409
410 private:
412 bool mode;
413
414 public:
416 : A(R), mode(m)
417 {}
418
419 // select coincidence if within multiplicity acceptance
420 bool operator() (const JCoincidenceSN& in) const {
421 return A(in.getMultiplicity());
422 }
423
424 // select cluster if any coincidence is accepted
425 // optionally veto if more of one module is interested
426 bool operator() (const JClusterSN& in) const {
427
428 bool out = (*this)(in.getPeak());
429
430 if (mode == 1) {
431 out = out && (in.getModules().size() == 1);
432 }
433
434 return out;
435 }
436
437 };
438
439
440 /**
441 * SN filter based on veto window
442 */
443 class JSNFilterMV : public JSNFilter {
444
445 private:
448
449 public:
451 : A(R), V(S)
452 {}
453
454 bool operator() (const JCoincidenceSN& in) const {
455 return A(in.getMultiplicity()) && !V(in);
456 }
457
458 bool operator() (const JClusterSN& in) const {
459 return (*this)(in.getPeak());
460 // return any_of(in.begin(), in.end(), *this);
461 }
462
463 };
464
465
466
467 /**
468 * Auxiliary class to apply the supernova trigger to SN data
469 */
470 class JTriggerSN : public vector<JClusterSN> {
471
472 private:
473
474 double TMaxCluster_ns = 1000.0;
475
476 // JVetoSet veto;
477
478 public:
479
482
483 /**
484 * Default constructor
485 *
486 * \param TMax_ns time width for coincidence clustering (track / afterpulse)
487 */
488 JTriggerSN(double TMax_ns) :
489 TMaxCluster_ns(TMax_ns)
490 {};
491
492 // void setVeto(JVetoSet &vt) {
493 // veto = vt;
494 // }
495
496
497 /**
498 * Builds trigger by clustering pretrigger data
499 *
500 * \param in pretrigger SN data
501 */
502 void operator() (const JDataSN& in) {
503
505 timeUTC = in.timeUTC;
506
507 for (vector<JCoincidenceSN>::const_iterator p = in.begin(); p != in.end(); ) {
508
509 JClusterSN cluster;
510
511 cluster.push_back(*p);
512
513 vector<JCoincidenceSN>::const_iterator q = p + 1;
514
515 while(q != in.end() && (q->getTime() <= (p->getTime() + TMaxCluster_ns))) {
516 cluster.push_back(*q);
517 ++q;
518 }
519
520 p = q;
521
522 this->push_back(cluster);
523
524 }
525 }
526
527
528 /**
529 * Get triggered modules after track veto
530 *
531 * \return std::set containing triggered modules IDs
532 */
534
535 JModuleSet triggeredModules;
536
537 JSNFilterM F(A, 1);
538
539 for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
540
541 if ( F(*p) ) {
542
543 // only clusters with one module pass the selection JSNFilterM(A, 1)
544 triggeredModules.insert((*p)[0].getModule());
545
546 }
547
548 }
549
550 return triggeredModules;
551
552 }
553
554
555 /**
556 * Get triggered modules according to given filter
557 */
559
560 JModuleSet out;
561
562 for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
563 if ( F(*p) ) {
564 out.insert(p->getPeak().getModule());
565 }
566 }
567 return out;
568 }
569
570 /**
571 * Fill histogram with multiplicity spectrum resulting from given filter
572 */
573 void fill(TH1D* out, const JSNFilter& F) {
574 for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
575 if (F(*p)) {
576 out->Fill( p->getPeak().getMultiplicity() );
577 }
578 }
579 }
580
582 vector<double> out;
583
584 for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
585 if (F(*p)) {
586 out.push_back( p->getPeak().getMultiplicity() );
587 }
588 }
589 return out;
590 }
591
592
593
594
595 /**
596 * > operator
597 * used by (reverse) std:priority_queue, in absence of this operator the container will behave unpredictably
598 */
599 bool operator>(const JTriggerSN& rhs) const {
600 return (frameIndex > rhs.frameIndex);
601 }
602
603 /**
604 * < operator
605 */
606 bool operator<(const JTriggerSN& rhs) const {
607 return (frameIndex < rhs.frameIndex);
608 }
609
610
611 };
612
613
614 /**
615 * SN trigger statistics, the information is stored in the form of a count as a function of the trigger level.
616 * the livetime needs to be set manually to compute the rates for the printing.
617 */
618
619 class JTriggerSNStats : public vector<double> {
620
621 private:
622 double livetime;
623
624 public:
625 /**
626 * default constructor
627 *
628 * \param nModules number of modules of the detector
629 */
630 JTriggerSNStats(const int nModules) : vector<double>(nModules) {}
631
632 void setLiveTime(const double lt) {
633 livetime = lt;
634 }
635
636 /**
637 * put statistics into printable form
638 * outputs trigger level - rate - error
639 */
640 string toString() {
641
642 ostringstream os;
643
644 os << "=== SUPERNOVA TRIGGER STATISTICS ==" << endl;
645 os << "=> livetime [s] = " << livetime << endl;
646 os << "Level" << '\t' << "Rate (error)" << endl;
647
648 if (livetime > 0) {
649 for (unsigned i = 0; i < this->size(); i++) {
650
651 double count = (*this)[i];
652 double rate = count / livetime;
653 double error = 100 * (sqrt(count) / count);
654
655 if (rate > 0) {
656 os << i << '\t';
657 os << scientific << setprecision(2) << rate << "Hz ";
658 os << fixed << setprecision(0) << "(" << setw(2) << error << "%)";
659 os << endl;
660 }
661 }
662 }
663
664 return os.str();
665
666 }
667
668
669 /**
670 * put statistics into printable form
671 * outputs trigger level - rate - error
672 */
673 string toSummaryFile() {
674
675 ostringstream os;
676
677 if (livetime > 0) {
678
679 os << livetime << endl;
680
681 for (unsigned i = 0; i < this->size(); i++) {
682
683 double count = (*this)[i];
684 double rate = count / livetime;
685 double error = (sqrt(count) / count);
686
687 if (rate > 0) {
688 os << i << ",";
689 os << scientific;
690 os << setprecision(2);
691 os << rate << ",";
692 os << error;
693 os << endl;
694 }
695 }
696 }
697
698
699 return os.str();
700
701 }
702
703 };
704
705}
706
707#endif
Direct access to PMT data in detector data structure for DAQ hits.
Data structure for detector geometry and calibration.
Basic data structure for L0 hit.
Match operator for consecutive hits.
Direct access to module in detector data structure.
Auxiliaries for pre-processing of hits.
Auxiliary class to define a range between two values.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
const JPMT & getPMT(const JDAQKeyHit &hit) const
Get PMT parameters.
Detector data structure.
Definition JDetector.hh:96
const JPMT & getPMT(const JPMTAddress &address) const
Get PMT parameters.
Definition JDetector.hh:348
Router for direct addressing of module data in detector data structure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Address of PMT in detector data structure.
const JDirection3D & getDirection() const
Get direction.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
double getLength() const
Get length.
Definition JVector3D.hh:246
double getZ() const
Get z position.
Definition JVector3D.hh:115
Auxiliary class to manage a cluster of coincidences.
JCoincidenceSN getPeak() const
Finds coincidence with maximum multiplicity.
JModuleSet getModules() const
Auxiliary class to store reduced information of a coincidence on an optical module This class allows ...
Definition JSupernova.hh:52
JCoincidenceSN(double t, int m, int dom, int vetoIndex=-1, double ctheta=-2, double rnorm=-1, double deltaT=-1, double total_ToT=-1, double timeslice_time=-1, bool fake=false)
Constructor:
Definition JSupernova.hh:90
bool operator()(const vector< JHitR0 > &hits, const JDetector &det)
Compute single-DOM observables |R|, cos(theta), total ToT, and Delta(t) and set the corresponding cla...
bool operator<(const JCoincidenceSN &rhs) const
Auxiliary class to build the supernova trigger dataset.
JDAQUTCExtended timeUTC
JDataSN(double window, int threshold=4)
Default constructor Configures the trigger with a time window and the pretrigger threshold.
void operator()(const vector< JHitR0 > &in, const int &moduleID, const JDetector &det=JDetector())
Builds coincidences from calibrated hit data and loads them in the internal vector.
Auxiliary class-operator to match a JVeto with a JCoincidenceSN object Provides an operator to test i...
bool operator()(const JVeto &in)
Operator.
JMatchVeto(const JCoincidenceSN &in)
Default constructor.
SN filter based on veto window.
JSNFilterMV(JRange< int > &R, JVetoSet &S)
bool operator()(const JCoincidenceSN &in) const
SN filter based on multiplicity selection optional suppression of multi-module coincidences WARNING: ...
JSNFilterM(JRange< int > R, int m=0)
bool operator()(const JCoincidenceSN &in) const
Interface for SN filter operator.
virtual bool operator()(const JCoincidenceSN &in) const =0
SN trigger statistics, the information is stored in the form of a count as a function of the trigger ...
string toString()
put statistics into printable form outputs trigger level - rate - error
void setLiveTime(const double lt)
JTriggerSNStats(const int nModules)
default constructor
string toSummaryFile()
put statistics into printable form outputs trigger level - rate - error
Auxiliary class to apply the supernova trigger to SN data.
void fill(TH1D *out, const JSNFilter &F)
Fill histogram with multiplicity spectrum resulting from given filter.
void operator()(const JDataSN &in)
Builds trigger by clustering pretrigger data.
JDAQUTCExtended timeUTC
JTriggerSN(double TMax_ns)
Default constructor.
JModuleSet getModules(const JSNFilter &F)
Get triggered modules according to given filter.
JModuleSet getModules(JRange< int > A=JRange< int >(6, 10))
Get triggered modules after track veto.
vector< double > getMultiplicities(const JSNFilter &F)
bool operator<(const JTriggerSN &rhs) const
< operator
bool operator>(const JTriggerSN &rhs) const
Auxiliary class to manage a set of vetoes.
bool operator()(const JCoincidenceSN &in) const
Applies the veto set to a coincidence.
Auxiliary class to define a veto time window on a set of optical modules.
double getLength()
Get length of veto time range.
bool operator()(const JCoincidenceSN &in) const
Determines if a coincidence is vetoed.
JTimeRange timeRange
JVeto(const JDAQEvent &event, const JDAQHitRouter &hitRouter)
Default constructor.
JModuleSet moduleSet
T getLength() const
Get length (difference between upper and lower limit).
Definition JRange.hh:289
static JRange< double, std::less< double > > DEFAULT_RANGE()
Definition JRange.hh:555
range_type & include(argument_type x)
Include given value to range.
Definition JRange.hh:397
Reduced data structure for L0 hit.
Definition JHitR0.hh:27
L0 match criterion.
Definition JMatchL0.hh:29
1-dimensional frame with time calibrated data from one optical module.
2-dimensional frame with time calibrated data from one optical module.
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
int getFrameIndex() const
Get frame index.
Template const_iterator.
Definition JDAQEvent.hh:68
const_iterator< T > end() const
Get end of data.
const_iterator< T > begin() const
Get begin of data.
Data structure for UTC time.
const JModule & getModule(const JType< JDetector_t > type, const int id, const JLocation &location=JLocation())
Get module according given detector type.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
set< int > JModuleSet
Definition JSupernova.hh:45
vector< double > multiplicities_t
Definition JSupernova.hh:43
const char * getTime()
Get current local time conform ISO-8601 standard.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
Normalisation of MUPAGE events.
Definition JHead.hh:835
Acoustic hit.
Definition JBillabong.cc:70
Default class to select DAQ hits.
Auxiliary class to select DAQ hits.
@ join_t
join consecutive hits according match criterion