54 string outputFileName;
59 string domDetectorFile;
62 int numberOfTimeouts = 1e3;
63 int queueLength = 100;
67 int preTriggerThreshold = 4;
69 double TVeto_ns = 1000;
73 string summaryFile =
"";
74 int statPrintInterval_s = 30;
79 string properties_description =
"\n";
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");
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");
106 properties_description.append(
"\tsummaryFile: summary output file\n");
108 properties_description.append(
"\tstatPrintInterval_s: statistics & file print interval [s]");
110 JParser<> zap(
"Supernova realtime processor");
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;
127 catch(
const exception &error) {
128 FATAL(error.what() << endl);
131 if (queueLength <= windowLength) {
132 FATAL(
"Length of the trigger window must be smaller than the queue.");
155 load(domDetectorFile, domDetector);
167 const int detectorSize =
detector.size();
177 typedef priority_queue<trigger_type, vector<trigger_type>, greater<trigger_type> > queue_type;
179 typedef deque<trigger_type> window_type;
188 window_type trgWindow;
195 long int counter_live_ts = 0;
196 long int counter_lost_ts = 0;
202 int nWrittenEntries = 0;
203 if (outputFileName !=
""){
223 if (inputFileName !=
"") {
229 else if (inputLigier !=
"") {
234 const double asyncTimeout_us = 1000.0;
239 else {
FATAL(
"Need either a root file or a ligier as input!" << endl); }
242 if (outputLigier !=
"") {
247 if (outputFileName !=
"") {
254 int timesliceSize = 0;
256 for (
int i = 0; i != numberOfTimeouts; ) {
262 DEBUG(timeslice->getDAQHeader() << endl);
264 timesliceSize = timeslice->size();
270 const int r = timeslice->getRunNumber();
276 NOTICE(
"RUN CHANGE" << endl);
278 while (trgQueue.size() > 0) { trgQueue.pop(); }
306 for (JDAQSummaryslice::const_iterator summary_frame = summary->begin();
307 summary_frame != summary->end();
310 int DOMID = summary_frame->getModuleID();
313 rates[frame_index][DOMID] += summary_frame->getRate(ipmt, 1.0/1000);
316 pmts[frame_index] += summary_frame->countActiveChannels();
325 DEBUG(
"EVT " << event->getDAQHeader() << endl);
327 int frame_index =
event->getFrameIndex();
329 veto[frame_index].push_back(
JVeto(*event, hitRouter));
337 JDataSN preTrigger(TMax_ns, preTriggerThreshold);
339 preTrigger(timeslice, moduleRouter, totSelector_ns, domDetector);
351 if ( trgQueue.size() >= (
unsigned) queueLength ) {
353 while ( trgWindow.size() <= (
unsigned) windowLength ) {
355 trigger_type pending = trgQueue.top();
357 if ( trgWindow.size() == 0 || pending > trgWindow.back() ) {
359 trgWindow.push_back( pending );
374 NOTICE(
"Filling trigger queue: " << trgQueue.size() <<
"/" << queueLength <<
'\r');
378 else if ( inputFileName !=
"" ) {
381 if ( trgQueue.size() > 0 ) {
382 while ( trgQueue.size() > 0 ) {
383 trgWindow.push_back(trgQueue.top());
387 else if ( trgWindow.size() < (
unsigned) windowLength ) {
388 i = numberOfTimeouts;
392 NOTICE(
"timeout " << setw(3) << i << endl);
397 if (trgWindow.size() >= (
unsigned) windowLength) {
404 int trg_cc_counts = 0;
405 int trg_cc_modules = 0;
408 int trg_ev_counts = 0;
409 int trg_ev_modules = 0;
413 for (
int its = 0; its < windowLength; its++) {
415 const int frame_index = trgWindow[its].frameIndex;
418 if (veto.count(frame_index)) {
419 vetoSet = veto.at(frame_index);
425 set<int> cc_vec = trgWindow[its].getModules(F_M1);
426 set<int> ev_vec = trgWindow[its].getModules(F_MV);
428 cc_modules.insert(cc_vec.begin(), cc_vec.end());
429 ev_modules.insert(ev_vec.begin(), ev_vec.end());
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);
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);
447 trg_cc_modules = cc_modules.size();
448 trg_ev_modules = ev_modules.size();
452 int currentFrame = trgWindow[0].frameIndex;
455 trgWindow.pop_front();
459 ++stats[trg_cc_counts];
463 int activeModules = -1;
464 double detectorRate = 0.0;
466 if (!rates.empty() &&
467 rates.count(currentFrame)) {
472 p != rates.at(currentFrame).end(); p++ ) {
474 detectorRate += p->second;
476 activeModules += (p->second > 0);
481 activeModules = timesliceSize;
503 string msg = jd.dump();
507 if (outputFileName !=
""){
508 if (nWrittenEntries < nEntries || nEntries == -1) {
529 if ( (counter_live_ts % ((
int)(statPrintInterval_s / frameTime_s)) == 0 ) ) {
531 double livetime = counter_live_ts * frameTime_s;
537 NOTICE(
"=> discarded out-of-order timeslices = " << counter_lost_ts << endl);
539 if (summaryFile !=
"") {
540 ofstream of(summaryFile.c_str());
541 of << stats.toSummaryFile();
554 if (outputFileName !=
"") {
outputFile.close(); }
#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 const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of 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 data structure to store data and fit in memory.
Auxiliary class to select DAQ hits based on time-over-treshold value.
Timeslice data structure for SN data.