#include #include #include #include #include "km3net-dataformat/offline/Head.hh" #include "km3net-dataformat/offline/MultiHead.hh" #include "km3net-dataformat/online/JDAQ.hh" #include "km3net-dataformat/online/JDAQClock.hh" #include "JDAQ/JDAQTimesliceIO.hh" #include "JDAQ/JDAQEventIO.hh" #include "JDAQ/JDAQSummarysliceIO.hh" #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JModuleRouter.hh" #include "JTrigger/JHit.hh" #include "JTrigger/JHitToolkit.hh" #include "JTrigger/JSuperFrame1D.hh" #include "JTrigger/JSuperFrame2D.hh" #include "JTrigger/JTimeslice.hh" #include "JTrigger/JHitL0.hh" #include "JTrigger/JHitL1.hh" #include "JTrigger/JBuildL1.hh" #include "JTrigger/JBuildL2.hh" #include "JTrigger/JTrigger3DShower.hh" #include "JTrigger/JTriggerMXShower.hh" #include "JTrigger/JTrigger3DMuon.hh" #include "JTrigger/JTriggerNB.hh" #include "JTrigger/JTriggerBits.hh" #include "JTrigger/JEventOverlap.hh" #include "JTrigger/JTimesliceRouter.hh" #include "JTrigger/JTriggeredEvent.hh" #include "JTrigger/JTimesliceL1.hh" #include "JTrigger/JTriggerParameters.hh" #include "JTrigger/JTriggerToolkit.hh" #include "JROOT/JROOTClassSelector.hh" #include "JLang/JObjectMultiplexer.hh" #include "JSupport/JMonteCarloFileSupportkit.hh" #include "JSupport/JMultipleFileScanner.hh" #include "JSupport/JFileRecorder.hh" #include "JSupport/JSupport.hh" #include "JSupport/JMeta.hh" #include "Jeep/JTimer.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * Auxiliary program to trigger KM3NETDAQ::JDAQTimeslice data. * Random KM3NETDAQ::JDAQTimeslice data can be produced with JRandomTimesliceWriter.cc application. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace KM3NETDAQ; using namespace JPP; typedef JTYPELIST::typelist typelist; JMultipleFileScanner inputFile; JLimit_t& numberOfEvents = inputFile.getLimit(); JFileRecorder outputFile; string detectorFile; JTriggerParameters parameters; JDAQClock clock; JROOTClassSelector selector; int debug; try { JParser<> zap("Auxiliary program to trigger time slice data."); zap['f'] = make_field(inputFile, "input file."); zap['o'] = make_field(outputFile, "output file.") = "trigger_processor.dat"; zap['n'] = make_field(numberOfEvents) = JLimit::max(); zap['a'] = make_field(detectorFile, "detector file."); zap['@'] = make_field(parameters, "trigger parameters") = JPARSER::initialised(); zap['c'] = make_field(clock, "DAQ clock") = JDAQClock::KM3NET, JDAQClock::PPM_DU, JDAQClock::ANTARES; zap['C'] = make_field(selector, "timeslice selector, e.g. JDAQTimesliceL1.") = getROOTClassSelection(); zap['d'] = make_field(debug, "debug flag.") = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } clock.set(); setDAQLongprint(debug >= JEEP::debug_t); DEBUG("Frame time [ms] " << getFrameTime() * 1e-6 << endl); DEBUG("Reset time [ms] " << getRTS() * 1e-6 << endl); DEBUG("Trigger" << endl << parameters << endl); JDetector detector; try { load(detectorFile, detector); } catch(const JException& error) { FATAL(error); } // detector if (parameters.disableHighRateVeto) { NOTICE("Disabling high-rate veto of all PMTs." << endl); detector.setPMTStatus(HIGH_RATE_VETO_DISABLE); } parameters.set(getMaximalDistance(detector)); const JModuleRouter moduleRouter(detector); //typedef JHit hit_type; //typedef int hit_type; typedef double hit_type; typedef JSuperFrame1D JSuperFrame1D_t; typedef JSuperFrame2D JSuperFrame2D_t; typedef JTimeslice JTimeslice_t; typedef JBuildL1 JBuildL1_t; typedef JBuildL2 JBuildL2_t; const JBuildL1_t buildL1(parameters); const JBuildL2_t buildL2(parameters.L2); const JBuildL2_t buildSN(parameters.SN); const JBuildL2_t buildNB(parameters.NB); JTimer timerCC("Calibration"); JTimer timerL0("L0"); JTimer timerL1("L1"); JTimer timerL2("L2"); JTimer timerSN("SN"); JTimer timerRX("Timeslice router"); JTimer timerTR("Trigger"); JTimer timerTX("Trigger router"); JTimer timerTW("Timeslice writer"); JTimer timerSW("Summary writer"); JTimesliceRouter timesliceRouter(parameters.numberOfBins); const JTriggerNB triggerNB (parameters); const JTrigger3DMuon trigger3DMuon (parameters); const JTrigger3DShower trigger3DShower(parameters); const JTriggerMXShower triggerMXShower(parameters, detector); outputFile.open(); if (!outputFile.is_open()) FATAL("Error opening file " << outputFile << endl); outputFile.put(JMeta(argc, argv)); outputFile.put(parameters); unsigned int numberOfTriggers = 0; JObjectMultiplexer in(inputFile, selector); counter_type counter = 0; for ( ; in.hasNext() && counter != inputFile.getLimit(); ++counter) { STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl); const JDAQTimeslice* timeslice = in.next(); DEBUG(*timeslice << endl); timerRX.start(); timesliceRouter.configure(*timeslice); timerRX.stop(); JTimeslice_t timesliceL0(timeslice->getDAQChronometer()); JTimeslice_t timesliceL1(timeslice->getDAQChronometer()); JTimeslice_t timesliceL2(timeslice->getDAQChronometer()); JTimeslice_t timesliceSN(timeslice->getDAQChronometer()); JTimeslice_t timesliceNB(timeslice->getDAQChronometer()); for (JDAQTimeslice::const_iterator super_frame = timeslice->begin(); super_frame != timeslice->end(); ++super_frame) { if (moduleRouter.hasModule(super_frame->getModuleID())) { // calibration timerCC.start(); const JModule& module = moduleRouter.getModule(super_frame->getModuleID()); JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*super_frame, module); timerCC.stop(); // Apply high-rate veto buffer.applyHighRateVeto(parameters.highRateVeto_Hz); // L0 timerL0.start(); timesliceL0.push_back(JSuperFrame1D_t(buffer)); timerL0.stop(); // Nano-beacon trigger if (parameters.triggerNB.enabled) { JSuperFrame2D_t::iterator __end = partition(buffer.begin(), buffer.end(), parameters.triggerNB.pmts); if (buffer.begin() != __end) { timesliceNB.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(), super_frame->getModuleIdentifier(), module.getPosition())); JSuperFrame1D_t zbuf; buildL1(buffer.begin(), __end , back_inserter(zbuf)); buildNB(buffer.begin() , __end, zbuf, back_inserter(*timesliceNB.rbegin())); } } // L1 timerL1.start(); timesliceL1.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(), super_frame->getModuleIdentifier(), module.getPosition())); buildL1(*timesliceL0.rbegin(), back_inserter(*timesliceL1.rbegin())); timerL1.stop(); // L2 timerL2.start(); timesliceL2.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(), super_frame->getModuleIdentifier(), module.getPosition())); buildL2(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceL2.rbegin())); timerL2.stop(); // SN timerSN.start(); timesliceSN.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(), super_frame->getModuleIdentifier(), module.getPosition())); buildSN(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceSN.rbegin())); timerSN.stop(); } } // Trigger if (parameters.triggerNB.enabled) { timerTX.start(); const JTriggerInput trigger_input(timesliceNB); for (JTriggerInput::const_iterator hit = trigger_input.begin(); hit != trigger_input.end(); ++hit) { if (parameters.triggerNB.write()) { JTriggeredEvent tev(timesliceNB.getDAQChronometer(), getTriggerMask(triggerNB.getTriggerBit()), *hit, timesliceRouter, moduleRouter, parameters.TMaxLocal_ns, parameters.triggerNB.DMax_m, getTimeRange(parameters.triggerNB)); outputFile.put(tev); } } timerTX.stop(); } timerTR.start(); JTriggerInput trigger_input(timesliceL2); JTriggerOutput trigger_output; trigger3DMuon (trigger_input, back_inserter(trigger_output)); trigger3DShower(trigger_input, back_inserter(trigger_output)); triggerMXShower(trigger_input, timesliceL0, back_inserter(trigger_output)); trigger_output.merge(JEventOverlap(parameters.TMaxEvent_ns)); numberOfTriggers += trigger_output.size(); timerTR.stop(); DEBUG("Number of triggers: " << trigger_output.size() << endl); for (JTriggerOutput::const_iterator event = trigger_output.begin(); event != trigger_output.end(); ++event) { timerTX.start(); JTriggeredEvent tev(*event, timesliceRouter, moduleRouter, parameters.TMaxLocal_ns, getTimeRange(parameters)); outputFile.put(tev); timerTX.stop(); } if (parameters.writeL0()) { timerTW.start(); outputFile.put(*timeslice); timerTW.stop(); } if (parameters.writeL1()) { timerTW.start(); outputFile.put(JTimesliceL1(timesliceL1, timesliceRouter, moduleRouter, parameters.TMaxLocal_ns)); timerTW.stop(); } if (parameters.writeL2()) { timerTW.start(); outputFile.put(JTimesliceL1(timesliceL2, timesliceRouter, moduleRouter, parameters.L2.TMaxLocal_ns)); timerTW.stop(); } if (parameters.writeSN()) { timerTW.start(); outputFile.put(JTimesliceL1(timesliceSN, timesliceRouter, moduleRouter, parameters.SN.TMaxLocal_ns)); timerTW.stop(); } if (parameters.writeSummary()) { timerSW.start(); outputFile.put(JDAQSummaryslice(*timeslice)); timerSW.stop(); } } STATUS(endl); if (debug >= JEEP::notice_t&& counter != 0) { const double factor = 1.0 / (double) counter; for (const JTimer* p : { &timerCC, &timerL0, &timerL1, &timerL2, &timerSN, &timerRX, &timerTR, &timerTX, &timerTW, &timerSW }) { p->print(cout, factor); } NOTICE("Number of trigger/slices " << numberOfTriggers << "/" << counter << endl); NOTICE("Trigger rate [Hz] " << numberOfTriggers * 1.0e9 * factor / getFrameTime() << endl); } JMultipleFileScanner::typelist> io(inputFile); io >> outputFile; outputFile.close(); }