45 {
49
50 string inputLigier;
51 string inputFileName;
52 string outputLigier;
54 string outputFileName;
55 int nEntries;
57
58 string detectorFile;
59 string domDetectorFile;
60
62 int numberOfTimeouts = 1e3;
63 int queueLength = 100;
64 int windowLength = 5;
65
66 int TMax_ns = 10;
67 int preTriggerThreshold = 4;
69 double TVeto_ns = 1000;
72
73 string summaryFile = "";
74 int statPrintInterval_s = 30;
75
76 try {
77
79 string properties_description = "\n";
80
82
84 properties_description.append("\ttimeout_us: timeout for input [us]\n");
86 properties_description.append("\tnumberOfTimeouts: number of timeouts before stop\n");
88 properties_description.append("\tqueueLength: number of timeslices of trigger queue\n");
90 properties_description.append("\twindowLength: number of timeslices of trigger sliding window\n");
91
93 properties_description.append("\tTMax_ns: coincidence time window [ns]\n");
95 properties_description.append("\tpreTriggerThreshold: muon veto multiplicity threshold\n");
97 properties_description.append("\ttotSelector_ns: hit selector\n");
99 properties_description.append("\tTVeto_ns: muon veto time interval [ns]\n");
101 properties_description.append("\tM: multiplicity range for SN coincidence level\n");
103 properties_description.append("\tM_BDT: multiplicity range for SN coincidence level (with BDT)\n");
104
106 properties_description.append("\tsummaryFile: summary output file\n");
108 properties_description.append("\tstatPrintInterval_s: statistics & file print interval [s]");
109
110 JParser<> zap(
"Supernova realtime processor");
111
112 zap[
'H'] =
make_field(inputLigier,
"Input Ligier server") =
"";
114 zap[
'L'] =
make_field(outputLigier,
"Output Ligier server") =
"";
115 zap[
'T'] =
make_field(outputTag,
"Output tag for the json messages") =
JTag();
116 zap[
'o'] =
make_field(outputFileName,
"Output json file name (no output to Ligier)") =
"";
117 zap[
'n'] =
make_field(nEntries,
"Number of entries to write") = -1;
122
123 zap(argc, argv);
124
125 }
126
127 catch(const exception &error) {
128 FATAL(error.what() << endl);
129 }
130
131 if (queueLength <= windowLength) {
132 FATAL(
"Length of the trigger window must be smaller than the queue.");
133 }
134
135
137
139
140
141
142
143
146
147 try {
149 }
152 }
153
154 try {
155 load(domDetectorFile, domDetector);
156 }
159 }
160
162
164
166
167 const int detectorSize =
detector.size();
168
170
171
172
173
174
176
177 typedef priority_queue<trigger_type, vector<trigger_type>, greater<trigger_type> > queue_type;
178
179 typedef deque<trigger_type> window_type;
180
181
182
186
187 queue_type trgQueue;
188 window_type trgWindow;
189 rates_type rates;
190 npmt_type pmts;
191 veto_type veto;
192
194
195 long int counter_live_ts = 0;
196 long int counter_lost_ts = 0;
197
199
200
202 int nWrittenEntries = 0;
203 if (outputFileName != ""){
205 }
206
207
208
209
210
211 try {
212
213
214
218
222
223 if (inputFileName != "") {
227
228 }
229 else if (inputLigier != "") {
231
232
233
234 const double asyncTimeout_us = 1000.0;
235
238 }
239 else {
FATAL(
"Need either a root file or a ligier as input!" << endl); }
240
242 if (outputLigier != "") {
244 }
245
247 if (outputFileName != "") {
249 }
250
251
252
253 int RUN = 0;
254 int timesliceSize = 0;
255
256 for (int i = 0; i != numberOfTimeouts; ) {
257
259
261
262 DEBUG(timeslice->getDAQHeader() << endl);
263
264 timesliceSize = timeslice->size();
265
266
267
268
269
270 const int r = timeslice->getRunNumber();
271
272 if (r != RUN) {
273
274 if (RUN != 0) {
275
276 NOTICE(
"RUN CHANGE" << endl);
277
278 while (trgQueue.size() > 0) { trgQueue.pop(); }
279
280 trgWindow.clear();
281
282 rates.clear();
283
284 pmts.clear();
285
286 veto.clear();
287
288 }
289
290 RUN = r;
291
292 }
293
294
295
296
297
299
301
303
305
306 for (JDAQSummaryslice::const_iterator summary_frame = summary->begin();
307 summary_frame != summary->end();
308 ++summary_frame) {
309
310 int DOMID = summary_frame->getModuleID();
311
313 rates[frame_index][DOMID] += summary_frame->getRate(ipmt, 1.0/1000);
314 }
315
316 pmts[frame_index] += summary_frame->countActiveChannels();
317 }
318
319 }
320
322
324
325 DEBUG(
"EVT " << event->getDAQHeader() << endl);
326
327 int frame_index = event->getFrameIndex();
328
329 veto[frame_index].push_back(
JVeto(*event, hitRouter));
330
331 }
332
333
334
335
336
337 JDataSN preTrigger(TMax_ns, preTriggerThreshold);
338
339 preTrigger(timeslice, moduleRouter, totSelector_ns, domDetector);
340
342
344
346
347
348
349
350
351 if ( trgQueue.size() >= (unsigned) queueLength ) {
352
353 while ( trgWindow.size() <= (unsigned) windowLength ) {
354
355 trigger_type pending = trgQueue.top();
356
357 if ( trgWindow.size() == 0 || pending > trgWindow.back() ) {
358
359 trgWindow.push_back( pending );
360
361 counter_live_ts++;
362
363 }
364 else {
365
366 counter_lost_ts++;
367 }
368
369 trgQueue.pop();
370
371 }
372 }
373 else {
374 NOTICE(
"Filling trigger queue: " << trgQueue.size() <<
"/" << queueLength <<
'\r');
375 }
376 }
377
378 else if ( inputFileName != "" ) {
379
380
381 if ( trgQueue.size() > 0 ) {
382 while ( trgQueue.size() > 0 ) {
383 trgWindow.push_back(trgQueue.top());
384 trgQueue.pop();
385 }
386 }
387 else if ( trgWindow.size() < (unsigned) windowLength ) {
388 i = numberOfTimeouts;
389 }
390 }
391 else {
392 NOTICE(
"timeout " << setw(3) << i << endl);
393
394 ++i;
395 }
396
397 if (trgWindow.size() >= (unsigned) windowLength) {
398
399
400
403
404 int trg_cc_counts = 0;
405 int trg_cc_modules = 0;
407
408 int trg_ev_counts = 0;
409 int trg_ev_modules = 0;
411
412
413 for (int its = 0; its < windowLength; its++) {
414
415 const int frame_index = trgWindow[its].frameIndex;
416
418 if (veto.count(frame_index)) {
419 vetoSet = veto.at(frame_index);
420 }
421
424
425 set<int> cc_vec = trgWindow[its].getModules(F_M1);
426 set<int> ev_vec = trgWindow[its].getModules(F_MV);
427
428 cc_modules.insert(cc_vec.begin(), cc_vec.end());
429 ev_modules.insert(ev_vec.begin(), ev_vec.end());
430
431 trg_cc_counts += count_if(trgWindow[its].begin(), trgWindow[its].end(), F_M1);
432 trg_ev_counts += count_if(trgWindow[its].begin(), trgWindow[its].end(), F_MV);
433
434
435 for (auto &trg: trgWindow[its]){
436 auto sn_candidate = trg.getPeak();
437 if (F_MV_BDT(sn_candidate)){
438 multiplicities.push_back(sn_candidate.multiplicity);
439 observables.push_back(sn_candidate.total_ToT);
440 observables.push_back(sn_candidate.deltaT);
441 observables.push_back(sn_candidate.mean_dir_norm);
442 observables.push_back(sn_candidate.mean_dir_ctheta);
443 }
444 }
445 }
446
447 trg_cc_modules = cc_modules.size();
448 trg_ev_modules = ev_modules.size();
449
450
451
452 int currentFrame = trgWindow[0].frameIndex;
454
455 trgWindow.pop_front();
456
457
458
459 ++stats[trg_cc_counts];
460
461
462
463 int activeModules = -1;
464 double detectorRate = 0.0;
465
466 if (!rates.empty() &&
467 rates.count(currentFrame)) {
468
469 activeModules = 0;
470
472 p != rates.at(currentFrame).end(); p++ ) {
473
474 detectorRate += p->second;
475
476 activeModules += (p->second > 0);
477
478 }
479 } else {
480
481 activeModules = timesliceSize;
482
483 }
484
485
486
488
502
503 string msg = jd.dump();
504
506
507 if (outputFileName != ""){
508 if (nWrittenEntries < nEntries || nEntries == -1) {
509
511 nWrittenEntries++;
512 }
513 else {
514
516 break;
517 }
518 }
519 else {
520
521
522 if (out != NULL) {
524 }
525 }
526
527
528
529 if ( (counter_live_ts % ((int)(statPrintInterval_s / frameTime_s)) == 0 ) ) {
530
531 double livetime = counter_live_ts * frameTime_s;
532
534
537 NOTICE(
"=> discarded out-of-order timeslices = " << counter_lost_ts << endl);
538
539 if (summaryFile != "") {
540 ofstream of(summaryFile.c_str());
541 of << stats.toSummaryFile();
542 of.close();
543 }
544
545 }
546 }
547 }
548 }
549
552 }
553
554 if (outputFileName !=
"") {
outputFile.close(); }
555
556}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
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 c_name
static const std::string m_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...
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.
virtual const char * what() const override
Get error message.
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.
Auxiliary class for time values.
Object iteration through ControlHost.
int PutFullString(const JTag &tag, const std::string &buffer)
Send string.
Utility class to parse command line options.
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.
int getFrameIndex() const
Get frame index.
Data structure for UTC time.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
std::string to_string(const T &value)
Convert value to string.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< event_type > data_type
KM3NeT DAQ data structures and auxiliaries.
double getFrameTime()
Get frame time duration.
void setDAQLongprint(const bool option)
Set DAQ print option.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Normalisation of MUPAGE events.
Data structure for measured coincidence rates of all pairs of PMTs in optical module.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Auxiliary class to select DAQ hits based on time-over-treshold value.
Timeslice data structure for SN data.