6 #include "nlohmann/json.hpp"
40 int main(
int argc,
char* argv[]) {
43 using namespace KM3NETDAQ;
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";
74 zap[
'L'] =
make_field(ligier,
"Ligier server (output)") =
"";
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.");
111 using namespace JSUPERNOVA;
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; ) {
216 data_type* timeslice = in.
next();
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);
303 trgQueue.push(trigger);
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) {
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);
Utility class to parse command line options.
static const std::string run_number_name
int main(int argc, char *argv[])
ROOT TTree parameter settings of various packages.
int MyId(const std::string &nick_name)
Identify.
std::vector< event_type > data_type
static const std::string multiplicities_name
static const std::string ev_name
Auxiliary class to define a veto time window on a set of optical modules.
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
Auxiliary class to select ROOT class based on class name.
SN filter based on veto window.
Router for direct addressing of module data in detector data structure.
virtual void reset() override
Reset pointer.
Data structure for UTC time.
static const std::string frame_index_name
Data structure for detector geometry and calibration.
static const std::string daq_time_name
static const std::string active_doms_name
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
int getFrameIndex() const
Get frame index.
Auxiliary data structure to store data and fit in memory.
string toSummaryFile()
put statistics into printable form outputs trigger level - rate - error
Auxiliary class for time values.
static const std::string detid_name
void setDAQLongprint(const bool option)
Set DAQ print option.
The template JSinglePointer class can be used to hold a pointer to an object.
static const std::string observables_name
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
string toString()
put statistics into printable form outputs trigger level - rate - error
SN trigger statistics, the information is stored in the form of a count as a function of the trigger ...
double getFrameTime()
Get frame time duration.
then rm i $OUTPUT_FILE fi let RUN
Auxiliary class to apply the supernova trigger to SN data.
SN filter based on multiplicity selection optional suppression of multi-module coincidences WARNING: ...
Timeslice data structure for SN data.
static const std::string trigger_name
General purpose messaging.
static const std::string m_name
Object iteration through ControlHost.
static const std::string detector_rate_name
Auxiliary class to build the supernova trigger dataset.
virtual const char * what() const override
Get error message.
Normalisation of MUPAGE events.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Utility class to parse command line options.
std::string to_string(const T &value)
Convert value to string.
Auxiliary class to select DAQ hits based on time-over-treshold value.
void setLiveTime(const double lt)
do set_variable DETECTOR_TXT $WORKDIR detector
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
static const std::string c_name
static const std::string active_pmts_name
static const std::string cc_name
int PutFullString(const JTag &tag, const std::string &buffer)
Send string.
#define DEBUG(A)
Message macros.
Auxiliary class to manage a set of vetoes.