6 #include "nlohmann/json.hpp"
40 int main(
int argc,
char* argv[]) {
47 string outputFileName;
48 bool testMode =
false;
56 int statPrintInterval_s;
59 string dummyDetectorFile;
64 int preTriggerThreshold;
71 JParser<> zap(
"Supernova realtime monitor");
73 zap[
'H'] =
make_field(controlhost,
"CH server (input)") =
"localhost";
75 zap[
'T'] =
make_field(outputTag,
"Output tag for the json messages") =
JTag(
"SNT_part");
76 zap[
'O'] =
make_field(testMode,
"Test mode if true (no output to Ligier)");
77 zap[
'N'] =
make_field(nTestEntries,
"Number of test entries to write") = 1;
78 zap[
'o'] =
make_field(outputFileName,
"Output json file name if run in test mode") =
"";
82 zap[
'C'] =
make_field(selector) = getROOTClassSelection<JDAQTimesliceTypes_t>();
83 zap[
'Q'] =
make_field(queueLength,
"number of timeslices of trigger queue") = 100;
84 zap[
'W'] =
make_field(windowLength,
"number of timeslices of trigger sliding window") = 5;
85 zap[
'T'] =
make_field(TMax_ns,
"coincidence time window [ns]") = 10;
87 zap[
'S'] =
make_field(preTriggerThreshold,
"muon veto multiplicity threshold") = 4;
88 zap[
'V'] =
make_field(TVeto_ns,
"muon veto time interval") = 1000;
89 zap[
's'] =
make_field(summaryFile,
"summary output file") =
"";
90 zap[
'P'] =
make_field(statPrintInterval_s,
"statistics & file print interval [s]") = 30;
93 zap[
'B'] =
make_field(M_BDT,
"multiplicity range for SN coincidences (with BDT)") =
JRange<int>(5,10);
100 catch(
const exception &error) {
101 FATAL(error.what() << endl);
104 if (queueLength < windowLength) {
105 FATAL(
"Length of the trigger window must be smaller than the queue.");
128 load(dummyDetectorFile, dummyDetector);
140 const int detectorSize =
detector.size();
150 typedef priority_queue<trigger_type, vector<trigger_type>, greater<trigger_type> > queue_type;
152 typedef deque<trigger_type> window_type;
161 window_type trgWindow;
168 long int counter_live_ts = 0;
169 long int counter_lost_ts = 0;
175 int nWrittenEntries = 0;
196 const double asyncTimeout_us = 1000.0;
203 if (!testMode &&
ligier !=
"") {
212 for (
int i = 0; i != numberOfTimeouts; ) {
218 DEBUG(timeslice->getDAQHeader() << endl);
220 int timesliceSize = timeslice->size();
226 const int r = timeslice->getRunNumber();
232 NOTICE(
"RUN CHANGE" << endl);
234 while (trgQueue.size() > 0) { trgQueue.pop(); }
262 for (JDAQSummaryslice::const_iterator summary_frame = summary->begin();
263 summary_frame != summary->end();
266 int DOMID = summary_frame->getModuleID();
269 rates[frame_index][DOMID] += summary_frame->getRate(ipmt, 1.0/1000);
272 pmts[frame_index] += summary_frame->countActiveChannels();
277 DEBUG(
"LOADING EVENTS" << endl);
283 DEBUG(
"EVT " << event->getDAQHeader() << endl);
285 int frame_index =
event->getFrameIndex();
287 veto[frame_index].push_back(
JVeto(*event, hitRouter));
295 JDataSN preTrigger(TMax_ns, preTriggerThreshold);
297 preTrigger(timeslice, moduleRouter, totSelector_ns, dummyDetector);
312 if (trgQueue.size() >= (
unsigned) queueLength) {
314 while (trgWindow.size() <= (
unsigned) windowLength) {
316 trigger_type pending = trgQueue.top();
318 if ( trgWindow.size() == 0 || pending > trgWindow.back() ) {
320 trgWindow.push_back( pending );
335 int trg_cc_counts = 0;
336 int trg_cc_modules = 0;
339 int trg_ev_counts = 0;
340 int trg_ev_modules = 0;
344 for (
int its = 0; its < windowLength; its++) {
346 const int frame_index = trgWindow[its].frameIndex;
349 if (veto.count(frame_index)) {
350 vetoSet = veto.at(frame_index);
356 set<int> cc_vec = trgWindow[its].getModules(F_M1);
357 set<int> ev_vec = trgWindow[its].getModules(F_MV);
359 cc_modules.insert(cc_vec.begin(), cc_vec.end());
360 ev_modules.insert(ev_vec.begin(), ev_vec.end());
362 trg_cc_counts += count_if(trgWindow[its].begin(), trgWindow[its].end(), F_M1);
363 trg_ev_counts += count_if(trgWindow[its].begin(), trgWindow[its].end(), F_MV);
366 for (
auto &trg: trgWindow[its]){
367 auto sn_candidate = trg.getPeak();
368 if (F_MV_BDT(sn_candidate)){
369 multiplicities.push_back(sn_candidate.multiplicity);
370 observables.push_back(sn_candidate.total_ToT);
371 observables.push_back(sn_candidate.deltaT);
372 observables.push_back(sn_candidate.mean_dir_norm);
373 observables.push_back(sn_candidate.mean_dir_ctheta);
378 trg_cc_modules = cc_modules.size();
379 trg_ev_modules = ev_modules.size();
383 int currentFrame = trgWindow[0].frameIndex;
386 trgWindow.pop_front();
390 ++stats[trg_cc_counts];
394 int activeModules = -1;
395 double detectorRate = 0.0;
397 if (!rates.empty() &&
398 rates.count(currentFrame)) {
403 p != rates.at(currentFrame).end(); p++ ) {
405 detectorRate += p->second;
407 activeModules += (p->second > 0);
412 activeModules = timesliceSize;
434 string msg = jd.dump();
439 if (nWrittenEntries < nTestEntries){
451 if (out != NULL && trg_ev_counts > 0) {
452 out->PutFullString(outputTag, msg);
458 if ( (counter_live_ts % ((
int)(statPrintInterval_s / frameTime_s)) == 0 ) ) {
460 double livetime = counter_live_ts * frameTime_s;
466 NOTICE(
"=> discarded out-of-order timeslices = " << counter_lost_ts << endl);
468 if (summaryFile !=
"") {
469 ofstream of(summaryFile.c_str());
477 NOTICE(
"Filling trigger queue: " << trgQueue.size() <<
"/" << queueLength <<
'\r');
482 NOTICE(
"timeout " << setw(3) << i << endl);
490 ERROR(error.what() << endl);
Data structure for detector geometry and calibration.
General purpose messaging.
#define DEBUG(A)
Message macros.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
int main(int argc, char *argv[])
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
ROOT TTree parameter settings of various packages.
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.
virtual const pointer_type & next() override
Get next element.
virtual bool hasNext() override
Check availability of next element.
The template JSinglePointer class can be used to hold a pointer to an object.
virtual void reset() override
Reset pointer.
Auxiliary class for time values.
Object iteration through ControlHost.
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 ...
string toString()
put statistics into printable form outputs trigger level - rate - error
void setLiveTime(const double lt)
string toSummaryFile()
put statistics into printable form outputs trigger level - rate - error
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.
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.
Auxiliary data structure to store data and fit in memory.
Auxiliary class to select ROOT class based on class name.
Auxiliary class to select DAQ hits based on time-over-treshold value.
Timeslice data structure for SN data.