Jpp 20.0.0-rc.8
the software that should make you happy
Loading...
Searching...
No Matches
JSupernovaProcessor.cc File Reference

Online supernova processor. More...

#include <iostream>
#include <iomanip>
#include <queue>
#include <string>
#include "nlohmann/json.hpp"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JDAQ/JDAQTags.hh"
#include "JDAQ/JDAQEvaluator.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JNet/JControlHostObjectIterator.hh"
#include "JNet/JControlHost.hh"
#include "JLang/JObjectIterator.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "Jeep/JProperties.hh"
#include "JROOT/JROOTClassSelector.hh"
#include "JTrigger/JDAQHitToTSelector.hh"
#include "JSupport/JSupport.hh"
#include "JMath/JRandom.hh"
#include "JSupport/JTreeScanner.hh"
#include "JSupernova.hh"
#include "JSupernovaProcessor.hh"

Go to the source code of this file.

Typedefs

using json = nlohmann::json
 

Functions

int main (int argc, char *argv[])
 

Detailed Description

Online supernova processor.

Author
mlincett,selhedri,iagoos,gvannoye

Definition in file JSupernovaProcessor.cc.

Typedef Documentation

◆ json

using json = nlohmann::json

Definition at line 38 of file JSupernovaProcessor.cc.

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 46 of file JSupernovaProcessor.cc.

46 {
47 using namespace std;
48 using namespace JPP;
49 using namespace KM3NETDAQ;
50
51 string inputLigier;
52 string ligierFireDrill;
53 string inputFileName;
54 string outputLigier;
55 JTag outputTag, tagFireDrill;
56 string outputFileName;
57 int nEntries;
58 size_t nBufferedTimeslices;
59 int debug;
60
61 string detectorFile;
62 string domDetectorFile;
63
64 JTimeval timeout_us = JTimeval(1e6); // timeout for input [us]
65 int numberOfTimeouts = 1e3; // number of timeouts before stop
66 int queueLength = 100; // number of timeslices of trigger queue
67 int windowLength = 5; // number of timeslices of trigger sliding window
68
69 int TMax_ns = 10; // coincidence time window [ns]
70 int preTriggerThreshold = 4; // muon veto multiplicity threshold
71 JDAQHitToTSelector totSelector_ns = JDAQHitToTSelector(4, 255); // hit selector
72 double TVeto_ns = 1000; // muon veto time interval [ns]
73 JRange<int> M = JRange<int>(6, 10); // multiplicity range for SN coincidence level
74 JRange<int> M_BDT = JRange<int>(6, 10); // multiplicity range for SN coincidence level (with BDT)
75 int M_RATE = 8; // multiplicity threshold to compare SN hit rate to triggered event rate
76
77 string summaryFile = ""; // summary output file
78 int statPrintInterval_s = 30; // statistics & file print interval [s]
79
80 try {
81
82 JProperties properties;
83 string properties_description = "\n";
84
85 properties.setEndOfLine(";");
86
87 properties.insert(gmake_property(timeout_us));
88 properties_description.append("\ttimeout_us: timeout for input [us]\n");
89 properties.insert(gmake_property(numberOfTimeouts));
90 properties_description.append("\tnumberOfTimeouts: number of timeouts before stop\n");
91 properties.insert(gmake_property(queueLength));
92 properties_description.append("\tqueueLength: number of timeslices of trigger queue\n");
93 properties.insert(gmake_property(windowLength));
94 properties_description.append("\twindowLength: number of timeslices of trigger sliding window\n");
95
96 properties.insert(gmake_property(TMax_ns));
97 properties_description.append("\tTMax_ns: coincidence time window [ns]\n");
98 properties.insert(gmake_property(preTriggerThreshold));
99 properties_description.append("\tpreTriggerThreshold: muon veto multiplicity threshold\n");
100 properties.insert(gmake_property(totSelector_ns));
101 properties_description.append("\ttotSelector_ns: hit selector\n");
102 properties.insert(gmake_property(TVeto_ns));
103 properties_description.append("\tTVeto_ns: muon veto time interval [ns]\n");
104 properties.insert(gmake_property(M));
105 properties_description.append("\tM: multiplicity range for SN coincidence level\n");
106 properties.insert(gmake_property(M_BDT));
107 properties_description.append("\tM_BDT: multiplicity range for SN coincidence level (with BDT)\n");
108
109 properties.insert(gmake_property(M_RATE));
110 properties_description.append("\tM_RATE: multiplicity threshold to compare the SN hit rates to the triggered event rates\n");
111
112 properties.insert(gmake_property(summaryFile));
113 properties_description.append("\tsummaryFile: summary output file\n");
114 properties.insert(gmake_property(statPrintInterval_s));
115 properties_description.append("\tstatPrintInterval_s: statistics & file print interval [s]");
116
117 JParser<> zap("Supernova realtime processor");
118
119 zap['H'] = make_field(inputLigier, "Input Ligier server") = "";
120 zap['l'] = make_field(ligierFireDrill, "Ligier server for the fire drill") = "";
121 zap['g'] = make_field(tagFireDrill, "Ligier tag for the fire drill") = JTag("FDRILL");
122 zap['f'] = make_field(inputFileName) = "";
123 zap['L'] = make_field(outputLigier, "Output Ligier server") = "";
124 zap['T'] = make_field(outputTag, "Output tag for the json messages") = JTag();
125 zap['o'] = make_field(outputFileName, "Output json file name (no output to Ligier)") = "";
126 zap['n'] = make_field(nEntries, "Number of entries to write") = -1;
127 zap['N'] = make_field(nBufferedTimeslices, "Maximum number of timeslices to save in DOM ID map") = 200;
128 zap['a'] = make_field(detectorFile);
129 zap['b'] = make_field(domDetectorFile) = "";
130 zap['d'] = make_field(debug) = 1;
131 zap['@'] = make_field(properties, properties_description) = JPARSER::initialised();
132
133 zap(argc, argv);
134
135 }
136
137 catch(const exception &error) {
138 FATAL(error.what() << endl);
139 }
140
141 if (queueLength <= windowLength) {
142 FATAL("Length of the trigger window must be smaller than the queue.");
143 }
144
145
147
148 using namespace JSUPERNOVA;
149
150 // -------------------------------
151 // load detector and build routers
152 // -------------------------------
153
155 JDetector domDetector;
156
157 try {
158 load(detectorFile, detector);
159 }
160 catch(const JException& error) {
161 FATAL(error);
162 }
163
164 try {
165 load(domDetectorFile, domDetector);
166 }
167 catch(const JException& error) {
168 domDetector = JDetector();
169 }
170
171 const JDAQHitRouter hitRouter(detector);
172
173 const JModuleRouter& moduleRouter = hitRouter;
174
175 const int DETID = detector.getID();
176
177 const int detectorSize = detector.size();
178
179 JSNFilterM F_M1(M, 1);
180
181 // -------------------------------
182 // initialize processing queue
183 // -------------------------------
184
185 typedef JTriggerSN trigger_type;
186
187 typedef priority_queue<trigger_type, vector<trigger_type>, greater<trigger_type> > queue_type;
188
189 typedef deque<trigger_type> window_type;
190
191
192
193 typedef map<int, map<int, double> > rates_type; // (frameindex, DOMID) -> DOM rate [kHz]
194 typedef map<int, int> npmt_type ; // (frameindex) -> # active PMTs
195 typedef map<int, JVetoSet> veto_type ; // (frameindex) -> vetoes
196
197 queue_type trgQueue;
198 window_type trgWindow;
199 rates_type rates;
200 npmt_type pmts;
201 veto_type veto;
203 map<int, int> coincNumber;
204
205 JTriggerSNStats stats(detectorSize);
206
207 long int counter_live_ts = 0;
208 long int counter_lost_ts = 0;
209
210 double frameTime_s = getFrameTime() / 1.0e9;
211
212 // Initialize output file name and number of entries for testing
213 ofstream outputFile;
214 int nWrittenEntries = 0;
215 if (outputFileName != ""){
216 outputFile.open(outputFileName);
217 }
218
219 // -------------------------------
220 // main processing
221 // -------------------------------
222
223 try {
224
225 // setup input
226
228 typedef JDAQSummaryslice summary_type;
229 typedef JDAQEvent event_type;
230
234
235 if (inputFileName != "") {
236 in = new JTreeScanner<data_type, JDAQEvaluator>(inputFileName);
237 sm = new JTreeScanner<summary_type, JDAQEvaluator>(inputFileName);
238 ev = new JTreeScanner<event_type, JDAQEvaluator>(inputFileName);
239
240 }
241 else if (inputLigier != "") {
242 in = new JControlHostObjectIterator<data_type>(inputLigier, timeout_us, true);
243
244 // timeout for the asynchronous reading of summary and event data
245 // needs to be smaller than the timeslice duration
246 const double asyncTimeout_us = 1000.0;
247
248 sm = new JControlHostObjectIterator<summary_type>(inputLigier, asyncTimeout_us, true);
249 ev = new JControlHostObjectIterator<event_type>(inputLigier, asyncTimeout_us, true);
250 }
251 else { FATAL("Need either a root file or a ligier as input!" << endl); }
252
253 JControlHost* out = NULL;
254 if (outputLigier != "") {
255 out = new JControlHost(outputLigier);
256 }
257
258 JControlHost fireDrill(ligierFireDrill);
259
260 if (ligierFireDrill != "") {
261 JSubscriptionList buffer;
262 buffer.add(JSubscriptionAll(tagFireDrill));
263
264 fireDrill.MyId("JGetMessage");
265 fireDrill.Subscribe(buffer);
266 fireDrill.SendMeAlways();
267 }
268
269 ofstream outputFile;
270 if (outputFileName != "") {
271 outputFile.open(outputFileName);
272 }
273
274 // setup state
275
276 int RUN = 0;
277 int timesliceSize = 0;
278 map<int,int> timesliceSize_all;
279
280 // Fire drill variables
281 int startedFireDrill = false;
282 vector<char> fireDrillFile;
283 JPrefix prefix;
284 ifstream fireDrillData;
285 int fireDrillTimeslice = 0;
286 double fireDrillOffsetTime, timeFireDrill, MultFireDrill, RFireDrill, CThetaFireDrill, TotalToTFireDrill, DeltaTFireDrill;
287 int timeSinceLastFireDrill = 10000;
288
289 for (int i = 0; i != numberOfTimeouts; ) {
290
291 if (in->hasNext()) {
292
293 data_type* timeslice = in->next();
294
295 DEBUG(timeslice->getDAQHeader() << endl);
296 timesliceSize = timeslice->size();
297
298 timesliceSize_all[timeslice->getFrameIndex()] = timesliceSize;
299
300 // --------------------------------
301 // run number initialise and update
302 // --------------------------------
303
304 const int r = timeslice->getRunNumber();
305
306 if (r != RUN) {
307
308 if (RUN != 0) {
309
310 NOTICE("RUN CHANGE" << endl);
311
312 while (trgQueue.size() > 0) { trgQueue.pop(); }
313
314 trgWindow.clear();
315
316 timesliceSize_all.clear();
317
318 rates.clear();
319
320 pmts.clear();
321
322 veto.clear();
323
324 doms.clear();
325
326 coincNumber.clear();
327
328 }
329
330 RUN = r;
331
332 }
333
334 // ------------------------------
335 // process pending summary slices
336 // ------------------------------
337
338 while ( sm->hasNext() ) {
339
340 JDAQSummaryslice* summary = sm->next();
341
342 DEBUG("SUM " << summary->getDAQHeader() << endl);
343
344 int frame_index = summary->getFrameIndex();
345
346 for (JDAQSummaryslice::const_iterator summary_frame = summary->begin();
347 summary_frame != summary->end();
348 ++summary_frame) {
349
350 int DOMID = summary_frame->getModuleID();
351
352 for (int ipmt = 0 ; ipmt < NUMBER_OF_PMTS ; ipmt++) {
353 rates[frame_index][DOMID] += summary_frame->getRate(ipmt, 1.0/1000);
354 }
355
356 doms[frame_index].push_back(DOMID);
357
358 // Erase first recorded summary slices to avoid having too many elements in the map
359 if (doms.size() > nBufferedTimeslices){
360 doms.erase(doms.begin()->first);
361 }
362
363 pmts[frame_index] += summary_frame->countActiveChannels();
364 }
365
366 }
367
368 while ( ev->hasNext() ) {
369
370 JDAQEvent* event = ev->next();
371
372 DEBUG("EVT " << event->getDAQHeader() << endl);
373
374 int frame_index = event->getFrameIndex();
375
376 veto[frame_index].push_back(JVeto(*event, hitRouter));
377
378 }
379
380 // -----------------
381 // process timeslice
382 // -----------------
383
384 JDataSN preTrigger(TMax_ns, preTriggerThreshold);
385
386 preTrigger(timeslice, moduleRouter, totSelector_ns, domDetector);
387
388 JTriggerSN trigger(TVeto_ns);
389
390 trigger(preTrigger);
391
392 JTriggerSN trigger_final(TVeto_ns);
393 trigger_final.frameIndex = trigger.frameIndex;
394 trigger_final.timeUTC = trigger.timeUTC;
395
396 //----------------
397 // Inject fake CCSN candidates (fire drill)
398 //----------------
399
400 if (!startedFireDrill){
401
402 timeSinceLastFireDrill += 0.1;
403
404 // Get input file name for simulated CCSN signal
405 int drill = fireDrill.CheckHead(prefix);
406 if (drill){
407 fireDrillFile.resize(prefix.getSize());
408 fireDrill.GetFullData(fireDrillFile.data(), fireDrillFile.size());
409 }
410
411 // Determines whether to start fire drill and set
412 // Enforce 100s wait time between fire drills to make sure the triggers do not pile up
413 if (fireDrillFile.size()>0 && timeSinceLastFireDrill > 100) {
414 startedFireDrill = true;
415 fireDrillOffsetTime = 0.05; // seconds
416 fireDrillTimeslice = 0;
417 string fireDrillFileName(fireDrillFile.begin()+1, fireDrillFile.end()-1);
418 fireDrillData.open(fireDrillFileName.c_str());
419 timeFireDrill = -100;
420 } else {
421 trigger_final = trigger;
422 }
423 }
424
425 // Read simulated signal and inject it into data
426 if (startedFireDrill) {
427
428 double tmin = 0.1*fireDrillTimeslice;
429 double tmax = tmin + 0.1;
430
431 if (fireDrillTimeslice == 0) { // At start of injection, read first event in signal file
432 fireDrillData >> timeFireDrill >> MultFireDrill >> CThetaFireDrill >> RFireDrill >> TotalToTFireDrill >> DeltaTFireDrill;
433 timeFireDrill += fireDrillOffsetTime;
434 }
435
436 // Read first event in timeslice (in real data)
437 auto sn_it = trigger.begin();
438 double event_time = (sn_it==trigger.end()) ? 100 : sn_it->getPeak().time/1.0e9; // If no data in timeslice set event time to large value
439
440 // Iterate over signal file (text file)
441 while (fireDrillData && timeFireDrill < tmax) {
442
443 // Add data until we reach the time of the simulated event
444 while(event_time < timeFireDrill-tmin && sn_it != trigger.end()) {
445 trigger_final.push_back(*sn_it);
446 sn_it++;
447 if (sn_it != trigger.end()) event_time = sn_it->getPeak().time/1.0e9;
448 }
449
450 if (sn_it > trigger.begin() && event_time > timeFireDrill-tmin) sn_it -= 1; // Offset back one unit
451
452 // Inject signal event
453 if (timeFireDrill >= tmin && timeFireDrill < tmax) {
454
455 // Get random DOM ID
456 int frame_number = timeslice->getFrameIndex();
457 int dom_id = doms[frame_number][(int) getRandom(0,(int)doms[frame_number].size())];
458 // Build JCoincidenceSN object, put it in a JClusterSN, add to the trigger
459 JCoincidenceSN sn((timeFireDrill-tmin)*1e9, (int) MultFireDrill, dom_id, 0, CThetaFireDrill, RFireDrill, DeltaTFireDrill, TotalToTFireDrill, -1, true);// the last argument "true" means the event is flagged as fake
460 JClusterSN sncluster;
461 sncluster.push_back(sn); // Neglect accidental coincidences with background events
462 trigger_final.push_back(sncluster); // Add SN cluster to trigger
463
464 }
465
466 // Read new event
467 fireDrillData >> timeFireDrill >> MultFireDrill >> CThetaFireDrill >> RFireDrill >> TotalToTFireDrill >> DeltaTFireDrill;
468 timeFireDrill += fireDrillOffsetTime;
469
470 }
471
472 // Pad with what remains of noise in timeslice
473 while(sn_it != trigger.end()) {
474 trigger_final.push_back(*sn_it);
475 sn_it++;
476 }
477
478 fireDrillTimeslice++; // Increment the timeslice counter
479
480 // If no signal left in file, fire drill injection is finished
481 if (!fireDrillData){
482 startedFireDrill = false;
483 fireDrillFile.clear();
484 timeSinceLastFireDrill = 0;
485 fireDrillData.close();
486 }
487
488 }
489
490 trgQueue.push(trigger_final);
491
492 //----------------
493 // compute trigger
494 //----------------
495
496 if ( trgQueue.size() >= (unsigned) queueLength ) {
497
498 while ( trgWindow.size() <= (unsigned) windowLength ) {
499
500 trigger_type pending = trgQueue.top();
501
502 if ( trgWindow.size() == 0 || pending > trgWindow.back() ) {
503
504 trgWindow.push_back( pending );
505
506 counter_live_ts++;
507
508 }
509 else {
510 // latecoming (out of order) timeslice
511 counter_lost_ts++;
512 }
513
514 trgQueue.pop();
515
516 }
517 }
518 else {
519 NOTICE("Filling trigger queue: " << trgQueue.size() << "/" << queueLength << '\r');
520 }
521 }
522
523 else if ( inputFileName != "" ) {
524 // if we are reading from a file and we don't have timeslices anymore, we are at the end of the file
525 // we can push the content of the queue to the trigger window to process it
526 if ( trgQueue.size() > 0 ) {
527 while ( trgQueue.size() > 0 ) {
528 trgWindow.push_back(trgQueue.top());
529
530 trgQueue.pop();
531 }
532 }
533 else if ( trgWindow.size() < (unsigned) windowLength ) {
534 i = numberOfTimeouts;
535 }
536 }
537 else {
538 NOTICE("timeout " << setw(3) << i << endl);
539
540 ++i;
541 }
542
543 if (trgWindow.size() >= (unsigned) windowLength) {
544
545 // build triggered modules with both data and simulated signal
546
547 vector<double> observables;
548 vector<int> multiplicities;
549
550 int trg_cc_counts = 0;
551 int trg_cc_modules = 0;
552 set<int> cc_modules;
553
554 int trg_ev_counts = 0;
555 int trg_ev_modules = 0;
556 set<int> ev_modules;
557
558 // build triggered modules with only data
559
560 vector<double> observables_nofakes;
561 vector<int> multiplicities_nofakes;
562
563 int trg_cc_counts_nofakes = 0;
564 int trg_cc_modules_nofakes = 0;
565 set<int> cc_modules_nofakes;
566
567 int trg_ev_counts_nofakes = 0;
568 int trg_ev_modules_nofakes = 0;
569 set<int> ev_modules_nofakes;
570
571 // loop over the trigger window and count the triggers
572 for (int its = 0; its < windowLength; its++) {
573
574 const int frame_index = trgWindow[its].frameIndex;
575
576 JVetoSet vetoSet;
577 if (veto.count(frame_index)) {
578 vetoSet = veto.at(frame_index);
579 }
580
581 JSNFilterMV F_MV(M, vetoSet);
582 JSNFilterMV F_MV_BDT(M_BDT, vetoSet);
583
584 set<int> cc_vec = trgWindow[its].getModules(F_M1);
585 set<int> ev_vec = trgWindow[its].getModules(F_MV);
586
587 // Get cluster and event counts without the simulated CCSN signal
588 set<int> cc_vec_nofakes;
589 set<int> ev_vec_nofakes;
590
591 int ncoinc = 0;
592 for (auto &trg: trgWindow[its]){
593 if (trg.getPeak().multiplicity >= M_RATE) {
594 ncoinc++;
595 }
596 if (F_M1(trg)){
597 if (!trg.getPeak().fake) trg_cc_counts_nofakes++;
598 for (auto &snc: trg){
599 if (!snc.fake){
600 cc_vec_nofakes.insert(snc.moduleID);
601 }
602 }
603 }
604 if (F_MV(trg)){
605 if (!trg.getPeak().fake) trg_ev_counts_nofakes++;
606 for (auto &snc: trg){
607 if (!snc.fake){
608 ev_vec_nofakes.insert(snc.moduleID);
609 }
610 }
611 }
612 }
613
614 // Count number of coincidences above a given multiplicity threshold
615 // To monitor the status of the data filters
616 coincNumber[frame_index] = ncoinc;
617
618 cc_modules.insert(cc_vec.begin(), cc_vec.end());
619 ev_modules.insert(ev_vec.begin(), ev_vec.end());
620
621 cc_modules_nofakes.insert(cc_vec_nofakes.begin(), cc_vec_nofakes.end());
622 ev_modules_nofakes.insert(ev_vec_nofakes.begin(), ev_vec_nofakes.end());
623
624 trg_cc_counts += count_if(trgWindow[its].begin(), trgWindow[its].end(), F_M1);
625 trg_ev_counts += count_if(trgWindow[its].begin(), trgWindow[its].end(), F_MV);
626
627 // Write table of observables
628 for (auto &trg: trgWindow[its]){
629 auto sn_candidate = trg.getPeak();
630 if (F_MV_BDT(sn_candidate)){
631 multiplicities.push_back(sn_candidate.multiplicity);
632 observables.push_back(sn_candidate.total_ToT);
633 observables.push_back(sn_candidate.deltaT);
634 observables.push_back(sn_candidate.mean_dir_norm);
635 observables.push_back(sn_candidate.mean_dir_ctheta);
636
637 if (!sn_candidate.fake){
638 multiplicities_nofakes.push_back(sn_candidate.multiplicity);
639 observables_nofakes.push_back(sn_candidate.total_ToT);
640 observables_nofakes.push_back(sn_candidate.deltaT);
641 observables_nofakes.push_back(sn_candidate.mean_dir_norm);
642 observables_nofakes.push_back(sn_candidate.mean_dir_ctheta);
643 }
644 }
645 }
646 }
647
648 trg_cc_modules = cc_modules.size();
649 trg_ev_modules = ev_modules.size();
650
651 trg_cc_modules_nofakes = cc_modules_nofakes.size();
652 trg_ev_modules_nofakes = ev_modules_nofakes.size();
653
654 // trigger window slide of one element
655
656 int currentFrame = trgWindow[0].frameIndex;
657 JDAQUTCExtended currentTime = trgWindow[0].timeUTC;
658
659 trgWindow.pop_front();
660
661 // calculate trigger
662
663 ++stats[trg_cc_counts];
664
665 // calculate average number of active modules and PMTs over trigger window
666
667 int activeModules = -1;
668 int activePMTs = 0;
669 double detectorRate = 0.0;
670 double triggerNum = 0.0;
671 int coincNum = 0;
672
673 for (int frame=0; frame < windowLength; frame++) {
674
675 activePMTs += pmts[currentFrame+frame];
676 triggerNum += veto[currentFrame+frame].size();
677 coincNum += coincNumber[currentFrame+frame];
678
679 int activeModules_frame = 0;
680
681 if (!rates.empty() &&
682 rates.count(currentFrame+frame)) {
683
684 activeModules_frame = 0;
685
686 for (map<int, double>::const_iterator p = rates.at(currentFrame+frame).begin();
687 p != rates.at(currentFrame+frame).end(); p++ ) {
688
689 detectorRate += p->second;
690
691 activeModules_frame += (p->second > 0);
692
693 }
694
695 } else {
696
697 activeModules_frame = timesliceSize_all[currentFrame+frame];
698
699 }
700
701 activeModules += activeModules_frame;
702
703 }
704
705 activeModules /= windowLength;
706 activePMTs /= windowLength;
707
708 // build summary message
709
710 json jd;
711 string daq_time = to_string(currentTime);
712
713 // Output with only data (even in case of a signal injection)
714 jd[detid_name] = DETID;
715 jd[trignum_name] = triggerNum;
716 jd[coincnum_name] = coincNum;
717 jd[active_doms_name] = activeModules;
718 jd[detector_rate_name] = int(detectorRate / 1000.0);
719 jd[run_number_name] = RUN;
720 jd[frame_index_name] = currentFrame;
721 jd[daq_time_name] = daq_time;
722 jd[trigger_name][cc_name][c_name] = trg_cc_counts_nofakes;
723 jd[trigger_name][cc_name][m_name] = trg_cc_modules_nofakes;
724 jd[trigger_name][ev_name][c_name] = trg_ev_counts_nofakes;
725 jd[trigger_name][ev_name][m_name] = trg_ev_modules_nofakes;
726 jd[active_pmts_name] = activePMTs;
727 jd[observables_name] = observables_nofakes;
728 jd[multiplicities_name] = multiplicities_nofakes;
729
730 string msg = jd.dump();
731
732 DEBUG(msg << endl);
733
734 // If a simulated signal has been injected, write the corresponding output
735 // DET ID is set to a negative value to distinguish it from the real output
736 string msg2 = "";
737 if (multiplicities.size() != multiplicities_nofakes.size()){
738 jd[detid_name] = -DETID;
739 jd[trignum_name] = triggerNum;
740 jd[coincnum_name] = coincNum;
741 jd[active_doms_name] = activeModules;
742 jd[detector_rate_name] = int(detectorRate / 1000.0);
743 jd[run_number_name] = RUN;
744 jd[frame_index_name] = currentFrame;
745 jd[daq_time_name] = daq_time;
746 jd[trigger_name][cc_name][c_name] = trg_cc_counts;
747 jd[trigger_name][cc_name][m_name] = trg_cc_modules;
748 jd[trigger_name][ev_name][c_name] = trg_ev_counts;
749 jd[trigger_name][ev_name][m_name] = trg_ev_modules;
750 jd[active_pmts_name] = activePMTs;
751 jd[observables_name] = observables;
752 jd[multiplicities_name] = multiplicities;
753
754 msg2 = jd.dump();
755
756 DEBUG(msg2 << endl);
757 }
758
759 if (outputFileName != ""){
760 if (nWrittenEntries < nEntries || nEntries == -1) {
761 // write summary information to output file (first nEntries)
762 outputFile << msg << endl;
763 nWrittenEntries++;
764 }
765 else {
766 // When entries written, close output file and exit loop
767 outputFile.close();
768 break;
769 }
770 }
771 else {
772 // send summary information to output ligier
773
774 if (out != NULL) {
775 if (msg2 != "") out->PutFullString(outputTag, msg2);
776 out->PutFullString(outputTag, msg);
777 }
778 }
779
780 // print stats
781
782 if ( (counter_live_ts % ((int)(statPrintInterval_s / frameTime_s)) == 0 ) ) {
783
784 double livetime = counter_live_ts * frameTime_s;
785
786 stats.setLiveTime(livetime);
787
788 NOTICE(endl);
789 NOTICE(stats.toString());
790 NOTICE("=> discarded out-of-order timeslices = " << counter_lost_ts << endl);
791
792 if (summaryFile != "") {
793 ofstream of(summaryFile.c_str());
794 of << stats.toSummaryFile();
795 of.close();
796 }
797
798 }
799 }
800 }
801 }
802
803 catch(const JSocketException& error) {
804 ERROR(error.what() << endl);
805 }
806
807 if (outputFileName != "") { outputFile.close(); }
808
809}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
nlohmann::json json
static const std::string active_pmts_name
static const std::string cc_name
static const std::string daq_time_name
static const std::string detid_name
static const std::string trignum_name
static const std::string c_name
static const std::string m_name
static const std::string coincnum_name
static const std::string run_number_name
static const std::string observables_name
static const std::string detector_rate_name
static const std::string ev_name
static const std::string trigger_name
static const std::string active_doms_name
static const std::string frame_index_name
static const std::string multiplicities_name
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
Utility class to parse parameter values.
void setEndOfLine(const std::string &eol)
Set end of line characters.
General exception.
Definition JException.hh:24
virtual const char * what() const override
Get error message.
Definition JException.hh:64
Interface of object iteration for a single data type.
virtual bool hasNext()=0
Check availability of next element.
virtual const pointer_type & next()=0
Get next element.
Exception for socket.
Auxiliary class for time values.
Definition JTimeval.hh:29
Object iteration through ControlHost.
ControlHost class.
int PutFullString(const JTag &tag, const std::string &buffer)
Send string.
ControlHost prefix.
Definition JPrefix.hh:33
int getSize() const
Get size.
Definition JPrefix.hh:62
Subscription list.
JSubscriptionList & add(const JSubscription &subscription)
Add subscription.
ControlHost tag.
Definition JTag.hh:38
Utility class to parse command line options.
Definition JParser.hh:1698
Auxiliary class to manage a cluster of coincidences.
Auxiliary class to store reduced information of a coincidence on an optical module This class allows ...
Definition JSupernova.hh:52
Auxiliary class to build the supernova trigger dataset.
SN filter based on veto window.
SN filter based on multiplicity selection optional suppression of multi-module coincidences WARNING: ...
SN trigger statistics, the information is stored in the form of a count as a function of the trigger ...
Auxiliary class to apply the supernova trigger to SN data.
Auxiliary class to manage a set of vetoes.
Auxiliary class to define a veto time window on a set of optical modules.
Template definition for direct access of elements in ROOT TChain.
Range of values.
Definition JRange.hh:42
int getFrameIndex() const
Get frame index.
const JDAQHeader & getDAQHeader() const
Get DAQ header.
Definition JDAQHeader.hh:49
Data structure for UTC time.
uint32_t dom_id(frame_idx_t idx)
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
@ debug_t
debug
Definition JMessage.hh:29
std::string to_string(const T &value)
Convert value to string.
T getRandom()
Get random value.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< event_type > data_type
Definition JPerth.cc:82
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
double getFrameTime()
Get frame time duration.
Definition JDAQClock.hh:162
void setDAQLongprint(const bool option)
Set DAQ print option.
Definition JDAQPrint.hh:28
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition JDAQ.hh:26
Detector file.
Definition JHead.hh:227
Normalisation of MUPAGE events.
Definition JHead.hh:835
Data structure for measured coincidence rates of all pairs of PMTs in optical module.
Definition JFitK40.hh:103
Auxiliary class for all subscription.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary class to select DAQ hits based on time-over-treshold value.
Timeslice data structure for SN data.