Jpp in_tag_pdf_generation
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 * \param fake fake
90 */
91 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)
93 { }
94
95 /**
96 * Compute single-DOM observables |R|, cos(theta), total ToT, and Delta(t) and set the corresponding class attributes
97 *
98 * \param hits Hit vector from timeslice
99 * \param det Single-DOM detx file used to simulate CCSN signal
100 */
101 bool operator()(const vector<JHitR0>& hits, const JDetector& det){
102 if (hits.size() == 0) return 1;
103 JVector3D mean_pmt_dir;
104 double first_hit_time = 0;
105 this->total_ToT = 0;
106 this->multiplicity = 0;
107 this->deltaT = 0;
108 int hitcount=0;
109 for(auto &hit: hits){
110 this->multiplicity++;
111 this->total_ToT += hit.getToT();
112 if (hitcount > 0) {
113 this->deltaT += hit.getT() - first_hit_time;
114 }
115 else first_hit_time = hit.getT();
116 int channel_id = hit.getPMT();
117 JPMTAddress pmt_address(JModuleRouter(det).getAddress(101),channel_id);
118 auto pmt = det.getPMT(pmt_address).getDirection();
119 mean_pmt_dir += pmt.getDirection();
120 hitcount++;
121 }
122 if (this->multiplicity >= 2) {
123 this->mean_dir_norm = mean_pmt_dir.getLength()/this->multiplicity;
124 this->mean_dir_ctheta = mean_pmt_dir.getZ()/this->multiplicity;
125 this->deltaT /= (this->multiplicity-1);
126 }
127 return 0;
128 }
129
130 int getMultiplicity() const {
131 return multiplicity;
132 }
133
134 int getModule() const {
135 return moduleID;
136 }
137
138 double getTime() const {
139 return time;
140 }
141
142 bool operator<(const JCoincidenceSN& rhs) const {
143 return (time < rhs.time);
144 }
145
146 };
147
148 /**
149 * Auxiliary class to define a veto time window on a set of optical modules
150 */
151 class JVeto {
152
153 private:
156
157 public:
158
159 /**
160 * Default constructor
161 * \param event DAQ event
162 * \param hitRouter hit router as source of hit time calibration
163 *
164 */
165 JVeto(const JDAQEvent& event, const JDAQHitRouter& hitRouter) {
166
168
170
172 hit != event.end<hit_type>();
173 ++hit) {
174
175 moduleSet.insert(hit->getModuleID());
176
177 timeRange.include(getTime(*hit, hitRouter.getPMT(*hit)));
178
179 }
180 }
181
182
183 /**
184 * Get length of veto time range
185 */
186 double getLength() {
187 return timeRange.getLength();
188 }
189
190 /**
191 * Determines if a coincidence is vetoed
192 * \param in coincidence under test
193 */
194 bool operator() (const JCoincidenceSN& in) const {
195 return timeRange(in.getTime()) &&
196 (moduleSet.find(in.getModule()) != moduleSet.end());
197 }
198
199 };
200
201
202 /**
203 * Auxiliary class to build the supernova trigger dataset
204 */
206 : public vector<JCoincidenceSN> {
207
208 private:
210 int min_M;
211 // JDAQHitSelector& hitSelector;// = JDAQHitDefaultSelector();
212
213 public:
216
217 /**
218 * Default constructor
219 * Configures the trigger with a time window and the pretrigger threshold.
220 */
221 JDataSN(double window, int threshold = 4) // JDAQHitSelector& selector = JDAQHitDefaultSelector())
222 : TMax_ns(window), min_M(threshold) // , hitSelector(selector)
223 { };
224
225 /**
226 * Builds coincidences from calibrated hit data and loads them in the internal vector.
227 * \param in hit data
228 * \param moduleID optical module ID for the hit data
229 * \param det single-DOM detx file used to simulate CCSN neutrinos (default: empty detector)
230 */
231 void operator() (const vector<JHitR0>& in, const int& moduleID, const JDetector& det = JDetector()) {
232
233 if (in.size() > 1) {
234
235 for (vector<JHitR0>::const_iterator p = in.begin(); p != in.end(); ) {
236
237 vector<JHitR0>::const_iterator q = p;
238
239 while (++q != in.end() && q->getT() - p->getT() <= TMax_ns ) {}
240
241 int M = distance(p, q);
242
243 if (M >= min_M) {
244 JCoincidenceSN coincidence(p->getT(), M, moduleID);
245 if (det.size() > 0) {
246 vector<JHitR0> coincidence_hits;
247 coincidence_hits.assign(p,q);
248 coincidence(coincidence_hits, det);
249 }
250 this->push_back(coincidence);
251 }
252
253 p = q;
254
255 }
256 }
257 }
258
259
260 /**
261 * Builds coincidences from a timeslice and loads them into the internal vector.
262 * Double pulses are merged according to the coincidence time window.
263 *
264 * \param timeslice input timeslice
265 * \param moduleRouter detector module router
266 * \param selector hit selector
267 * \param det single-DOM detx file used to simulate signal events
268 */
269 void operator() (const JDAQTimeslice* timeslice, const JModuleRouter& moduleRouter, const JDAQHitSelector& selector = JDAQHitDefaultSelector(), const JDetector& det = JDetector()) {
270
271 frameIndex = timeslice->getFrameIndex();
272 timeUTC = timeslice->getTimesliceStart();
273
274 typedef JHitR0 hit_t;
275
276 typedef JSuperFrame2D<hit_t> JSuperFrame2D_t;
277
278 typedef JSuperFrame1D<hit_t> JSuperFrame1D_t;
279
280 const JMatchL0<hit_t> match(TMax_ns);
281
282 for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
283
284 int moduleID = frame->getModuleID();
285
286 JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame,
287 moduleRouter.getModule(moduleID),
288 selector);
289
290 buffer.preprocess(JPreprocessor::join_t, match);
291
292 JSuperFrame1D_t& data = JSuperFrame1D_t::multiplex(buffer);
293
294 if (det.size() < 0)(*this)(data, moduleID);
295 else (*this)(data, moduleID, det);
296
297 }
298
299 sort(this->begin(), this->end());
300
301 }
302
303 };
304
305
306 /**
307 * Auxiliary class-operator to match a JVeto with a JCoincidenceSN object
308 * Provides an operator to test if a coincidence is vetoed
309 */
310
312
313 private:
315
316 public:
317 /**
318 * Default constructor
319 * \param in coincidence to be matched against veto
320 */
321 JMatchVeto(const JCoincidenceSN& in) : dut(in) {}
322
323 /**
324 * Operator
325 * \param in veto to be matched against inner coincidence
326 */
327 bool operator() (const JVeto& in) {
328 return in(dut);
329 }
330
331 };
332
333
334 /**
335 * Auxiliary class to manage a set of vetoes
336 */
337 class JVetoSet : public vector<JVeto> {
338
339 public:
340 /**
341 * Applies the veto set to a coincidence
342 * \param in coincidence to be tested
343 */
344 bool operator() (const JCoincidenceSN& in) const {
345 return any_of(this->begin(), this->end(), JMatchVeto(in));
346 }
347
348 };
349
350
351 /**
352 * Auxiliary class to manage a cluster of coincidences
353 */
354 class JClusterSN : public vector<JCoincidenceSN> {
355
356 public:
357
358 /**
359 * Finds coincidence with maximum multiplicity.
360 */
362
363 JClusterSN::const_iterator p = this->begin();
364
365 for (JClusterSN::const_iterator q = p + 1; q != this->end(); q++) {
366 if (q->getMultiplicity() > p->getMultiplicity()) {
367 p = q;
368 }
369 }
370
371 return (*p);
372
373 }
374
375
376 /*
377 * Returns the set of modules spanned over by the cluster.
378 */
380
381 JModuleSet out;
382
383 for (JClusterSN::const_iterator p = this->begin(); p != this->end(); p++) {
384 out.insert(p->getModule());
385 }
386
387 return out;
388 }
389
390 };
391
392
393 /**
394 * Interface for SN filter operator.
395 * This operator is meant to determine the SN trigger count from a vector of JClusterSN
396 */
397 class JSNFilter {
398 public:
399 virtual bool operator() (const JCoincidenceSN& in) const = 0;
400 virtual bool operator() (const JClusterSN& in) const = 0;
401 };
402
403
404 /**
405 * SN filter based on multiplicity selection
406 * optional suppression of multi-module coincidences
407 * WARNING: no minimum threshold for the veto
408 */
409 class JSNFilterM : public JSNFilter {
410
411 private:
413 bool mode;
414
415 public:
417 : A(R), mode(m)
418 {}
419
420 // select coincidence if within multiplicity acceptance
421 bool operator() (const JCoincidenceSN& in) const {
422 return A(in.getMultiplicity());
423 }
424
425 // select cluster if any coincidence is accepted
426 // optionally veto if more of one module is interested
427 bool operator() (const JClusterSN& in) const {
428
429 bool out = (*this)(in.getPeak());
430
431 if (mode == 1) {
432 out = out && (in.getModules().size() == 1);
433 }
434
435 return out;
436 }
437
438 };
439
440
441 /**
442 * SN filter based on veto window
443 */
444 class JSNFilterMV : public JSNFilter {
445
446 private:
449
450 public:
452 : A(R), V(S)
453 {}
454
455 bool operator() (const JCoincidenceSN& in) const {
456 return A(in.getMultiplicity()) && !V(in);
457 }
458
459 bool operator() (const JClusterSN& in) const {
460 return (*this)(in.getPeak());
461 // return any_of(in.begin(), in.end(), *this);
462 }
463
464 };
465
466
467
468 /**
469 * Auxiliary class to apply the supernova trigger to SN data
470 */
471 class JTriggerSN : public vector<JClusterSN> {
472
473 private:
474
475 double TMaxCluster_ns = 1000.0;
476
477 // JVetoSet veto;
478
479 public:
480
483
484 /**
485 * Default constructor
486 *
487 * \param TMax_ns time width for coincidence clustering (track / afterpulse)
488 */
489 JTriggerSN(double TMax_ns) :
490 TMaxCluster_ns(TMax_ns)
491 {};
492
493 // void setVeto(JVetoSet &vt) {
494 // veto = vt;
495 // }
496
497
498 /**
499 * Builds trigger by clustering pretrigger data
500 *
501 * \param in pretrigger SN data
502 */
503 void operator() (const JDataSN& in) {
504
506 timeUTC = in.timeUTC;
507
508 for (vector<JCoincidenceSN>::const_iterator p = in.begin(); p != in.end(); ) {
509
510 JClusterSN cluster;
511
512 cluster.push_back(*p);
513
514 vector<JCoincidenceSN>::const_iterator q = p + 1;
515
516 while(q != in.end() && (q->getTime() <= (p->getTime() + TMaxCluster_ns))) {
517 cluster.push_back(*q);
518 ++q;
519 }
520
521 p = q;
522
523 this->push_back(cluster);
524
525 }
526 }
527
528
529 /**
530 * Get triggered modules after track veto
531 *
532 * \return std::set containing triggered modules IDs
533 */
535
536 JModuleSet triggeredModules;
537
538 JSNFilterM F(A, 1);
539
540 for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
541
542 if ( F(*p) ) {
543
544 // only clusters with one module pass the selection JSNFilterM(A, 1)
545 triggeredModules.insert((*p)[0].getModule());
546
547 }
548
549 }
550
551 return triggeredModules;
552
553 }
554
555
556 /**
557 * Get triggered modules according to given filter
558 */
560
561 JModuleSet out;
562
563 for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
564 if ( F(*p) ) {
565 out.insert(p->getPeak().getModule());
566 }
567 }
568 return out;
569 }
570
571 /**
572 * Fill histogram with multiplicity spectrum resulting from given filter
573 */
574 void fill(TH1D* out, const JSNFilter& F) {
575 for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
576 if (F(*p)) {
577 out->Fill( p->getPeak().getMultiplicity() );
578 }
579 }
580 }
581
583 vector<double> out;
584
585 for (JTriggerSN::const_iterator p = this->begin(); p != this->end(); p++) {
586 if (F(*p)) {
587 out.push_back( p->getPeak().getMultiplicity() );
588 }
589 }
590 return out;
591 }
592
593
594
595
596 /**
597 * > operator
598 * used by (reverse) std:priority_queue, in absence of this operator the container will behave unpredictably
599 */
600 bool operator>(const JTriggerSN& rhs) const {
601 return (frameIndex > rhs.frameIndex);
602 }
603
604 /**
605 * < operator
606 */
607 bool operator<(const JTriggerSN& rhs) const {
608 return (frameIndex < rhs.frameIndex);
609 }
610
611
612 };
613
614
615 /**
616 * SN trigger statistics, the information is stored in the form of a count as a function of the trigger level.
617 * the livetime needs to be set manually to compute the rates for the printing.
618 */
619
620 class JTriggerSNStats : public vector<double> {
621
622 private:
623 double livetime;
624
625 public:
626 /**
627 * default constructor
628 *
629 * \param nModules number of modules of the detector
630 */
631 JTriggerSNStats(const int nModules) : vector<double>(nModules) {}
632
633 void setLiveTime(const double lt) {
634 livetime = lt;
635 }
636
637 /**
638 * put statistics into printable form
639 * outputs trigger level - rate - error
640 */
641 string toString() {
642
643 ostringstream os;
644
645 os << "=== SUPERNOVA TRIGGER STATISTICS ==" << endl;
646 os << "=> livetime [s] = " << livetime << endl;
647 os << "Level" << '\t' << "Rate (error)" << endl;
648
649 if (livetime > 0) {
650 for (unsigned i = 0; i < this->size(); i++) {
651
652 double count = (*this)[i];
653 double rate = count / livetime;
654 double error = 100 * (sqrt(count) / count);
655
656 if (rate > 0) {
657 os << i << '\t';
658 os << scientific << setprecision(2) << rate << "Hz ";
659 os << fixed << setprecision(0) << "(" << setw(2) << error << "%)";
660 os << endl;
661 }
662 }
663 }
664
665 return os.str();
666
667 }
668
669
670 /**
671 * put statistics into printable form
672 * outputs trigger level - rate - error
673 */
674 string toSummaryFile() {
675
676 ostringstream os;
677
678 if (livetime > 0) {
679
680 os << livetime << endl;
681
682 for (unsigned i = 0; i < this->size(); i++) {
683
684 double count = (*this)[i];
685 double rate = count / livetime;
686 double error = (sqrt(count) / count);
687
688 if (rate > 0) {
689 os << i << ",";
690 os << scientific;
691 os << setprecision(2);
692 os << rate << ",";
693 os << error;
694 os << endl;
695 }
696 }
697 }
698
699
700 return os.str();
701
702 }
703
704 };
705
706}
707
708#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:91
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