Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JTriggerProcessor.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <set>
6
11
13#include "JDAQ/JDAQEventIO.hh"
15
19
20#include "JTrigger/JHit.hh"
25#include "JTrigger/JHitL0.hh"
26#include "JTrigger/JHitL1.hh"
27#include "JTrigger/JBuildL1.hh"
28#include "JTrigger/JBuildL2.hh"
29
41
44
48#include "JSupport/JSupport.hh"
49#include "JSupport/JMeta.hh"
50
51#include "Jeep/JTimer.hh"
52#include "Jeep/JParser.hh"
53#include "Jeep/JMessage.hh"
54
55
56/**
57 * \file
58 * Auxiliary program to trigger KM3NETDAQ::JDAQTimeslice data.
59 * Random KM3NETDAQ::JDAQTimeslice data can be produced with JRandomTimesliceWriter.cc application.
60 * \author mdejong
61 */
62int main(int argc, char **argv)
63{
64 using namespace std;
65 using namespace KM3NETDAQ;
66 using namespace JPP;
67
68 typedef JTYPELIST<JAllTypes_t>::typelist typelist;
69
71 JLimit_t& numberOfEvents = inputFile.getLimit();
73 string detectorFile;
74 JTriggerParameters parameters;
75 JDAQClock clock;
76 JROOTClassSelector selector;
77 bool profile;
79 int debug;
80
81 try {
82
83 JParser<> zap("Auxiliary program to trigger time slice data.");
84
85 zap['f'] = make_field(inputFile, "input file.");
86 zap['o'] = make_field(outputFile, "output file.") = "trigger_processor.dat";
87 zap['n'] = make_field(numberOfEvents) = JLimit::max();
88 zap['a'] = make_field(detectorFile, "detector file.");
89 zap['@'] = make_field(parameters, "trigger parameters") = JPARSER::initialised();
90 zap['c'] = make_field(clock, "DAQ clock") = JDAQClock::KM3NET, JDAQClock::PPM_DU, JDAQClock::ANTARES;
91 zap['C'] = make_field(selector, "timeslice selector, e.g. JDAQTimesliceL1.") = getROOTClassSelection<JDAQTimesliceTypes_t>();
92 zap['P'] = make_field(profile, "profile CPU");
93 zap['m'] = make_field(merge, "Allow merging of files w/o Monte Carlo headers");
94 zap['d'] = make_field(debug, "debug flag.") = 1;
95
96 zap(argc, argv);
97 }
98 catch(const exception &error) {
99 FATAL(error.what() << endl);
100 }
101
102
103 clock.set();
104
106
107 if (!profile) {
109 }
110
111 DEBUG("Frame time [ms] " << getFrameTime() * 1e-6 << endl);
112 DEBUG("Reset time [ms] " << getRTS() * 1e-6 << endl);
113 DEBUG("Trigger" << endl << parameters << endl);
114
116
117 try {
118 load(detectorFile, detector);
119 }
120 catch(const JException& error) {
121 FATAL(error);
122 }
123
124 // detector
125
126 if (parameters.disableHighRateVeto) {
127
128 NOTICE("Disabling high-rate veto of all PMTs." << endl);
129
130 detector.setPMTStatus(HIGH_RATE_VETO_DISABLE);
131 }
132
133 parameters.set(getMaximalDistance(detector));
134
135 const JModuleRouter moduleRouter(detector);
136
137 //typedef JHit hit_type;
138 //typedef int hit_type;
139 typedef double hit_type;
140
141 typedef JSuperFrame1D<hit_type> JSuperFrame1D_t;
142 typedef JSuperFrame2D<hit_type> JSuperFrame2D_t;
143 typedef JTimeslice <hit_type> JTimeslice_t;
144 typedef JBuildL1 <hit_type> JBuildL1_t;
145 typedef JBuildL2 <hit_type> JBuildL2_t;
146
147 const JBuildL1_t buildL1(parameters);
148 const JBuildL2_t buildL2(parameters.L2);
149 const JBuildL2_t buildSN(parameters.SN);
150 const JBuildL2_t buildNB(parameters.NB);
151
152 JTimer timerCC("Calibration");
153 JTimer timerL0("L0");
154 JTimer timerL1("L1");
155 JTimer timerL2("L2");
156 JTimer timerSN("SN");
157 JTimer timerRX("Timeslice router");
158 JTimer timerTR("Trigger");
159 JTimer timerTX("Trigger router");
160 JTimer timerTW("Timeslice writer");
161 JTimer timerSW("Summary writer");
162
163 JTimesliceRouter timesliceRouter(parameters.numberOfBins);
164
165 const JTriggerNB triggerNB (parameters);
166 const JTrigger3DMuon trigger3DMuon (parameters);
167 const JTrigger3DShower trigger3DShower(parameters);
168 const JTriggerMXShower triggerMXShower(parameters, detector);
169
170
171 outputFile.open();
172
173 if (!outputFile.is_open()) FATAL("Error opening file " << outputFile << endl);
174
175 outputFile.put(JMeta(argc, argv));
176 outputFile.put(parameters);
177
178 unsigned int numberOfTriggers = 0;
179
181
182 counter_type counter = 0;
183
184 for ( ; in.hasNext() && counter != inputFile.getLimit(); ++counter) {
185
186 STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
187
188 const JDAQTimeslice* timeslice = in.next();
189
190 DEBUG(*timeslice << endl);
191
192 timerRX.start();
193
194 timesliceRouter.configure(*timeslice);
195
196 timerRX.stop();
197
198
199 JTimeslice_t timesliceL0(timeslice->getDAQChronometer());
200 JTimeslice_t timesliceL1(timeslice->getDAQChronometer());
201 JTimeslice_t timesliceL2(timeslice->getDAQChronometer());
202 JTimeslice_t timesliceSN(timeslice->getDAQChronometer());
203 JTimeslice_t timesliceNB(timeslice->getDAQChronometer());
204
205 for (JDAQTimeslice::const_iterator super_frame = timeslice->begin(); super_frame != timeslice->end(); ++super_frame) {
206
207 if (moduleRouter.hasModule(super_frame->getModuleID())) {
208
209 // calibration
210
211 timerCC.start();
212
213 const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
214 JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*super_frame, module);
215
216 timerCC.stop();
217
218 // Apply high-rate veto
219
220 buffer.applyHighRateVeto(parameters.highRateVeto_Hz);
221
222 // L0
223
224 timerL0.start();
225
226 timesliceL0.push_back(JSuperFrame1D_t(buffer));
227
228 timerL0.stop();
229
230 // Nano-beacon trigger
231
232 if (parameters.triggerNB.enabled) {
233
234 JSuperFrame2D_t::iterator __end = partition(buffer.begin(), buffer.end(), parameters.triggerNB.pmts);
235
236 if (buffer.begin() != __end) {
237
238 timesliceNB.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
239 super_frame->getModuleIdentifier(),
240 module.getPosition()));
241
242 JSuperFrame1D_t zbuf;
243
244 buildL1(buffer.begin(), __end , back_inserter(zbuf));
245
246 buildNB(buffer.begin() , __end, zbuf, back_inserter(*timesliceNB.rbegin()));
247 }
248 }
249
250 // L1
251
252 timerL1.start();
253
254 timesliceL1.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
255 super_frame->getModuleIdentifier(),
256 module.getPosition()));
257
258 buildL1(*timesliceL0.rbegin(), back_inserter(*timesliceL1.rbegin()));
259
260 timerL1.stop();
261
262 // L2
263
264 timerL2.start();
265
266 timesliceL2.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
267 super_frame->getModuleIdentifier(),
268 module.getPosition()));
269
270 buildL2(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceL2.rbegin()));
271
272 timerL2.stop();
273
274 // SN
275
276 timerSN.start();
277
278 timesliceSN.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
279 super_frame->getModuleIdentifier(),
280 module.getPosition()));
281
282 buildSN(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceSN.rbegin()));
283
284 timerSN.stop();
285 }
286 }
287
288 // Trigger
289
290 if (parameters.triggerNB.enabled) {
291
292 timerTX.start();
293
294 const JTriggerInput trigger_input(timesliceNB);
295
296 for (JTriggerInput::const_iterator hit = trigger_input.begin(); hit != trigger_input.end(); ++hit) {
297
298 if (parameters.triggerNB.write()) {
299
300 JTriggeredEvent tev(timesliceNB.getDAQChronometer(),
301 getTriggerMask(triggerNB.getTriggerBit()),
302 *hit,
303 timesliceRouter,
304 moduleRouter,
305 parameters.TMaxLocal_ns,
306 parameters.triggerNB.DMax_m,
307 getTimeRange(parameters.triggerNB));
308
309 outputFile.put(tev);
310 }
311 }
312
313 timerTX.stop();
314 }
315
316 timerTR.start();
317
318 JTriggerInput trigger_input(timesliceL2);
319 JTriggerOutput trigger_output;
320
321 trigger3DMuon (trigger_input, back_inserter(trigger_output));
322 trigger3DShower(trigger_input, back_inserter(trigger_output));
323 triggerMXShower(trigger_input, timesliceL0, back_inserter(trigger_output));
324
325 trigger_output.merge(JEventOverlap(parameters.TMaxEvent_ns));
326
327 numberOfTriggers += trigger_output.size();
328
329 timerTR.stop();
330
331 DEBUG("Number of triggers: " << trigger_output.size() << endl);
332
333 for (JTriggerOutput::const_iterator event = trigger_output.begin(); event != trigger_output.end(); ++event) {
334
335 timerTX.start();
336
337 JTriggeredEvent tev(*event,
338 timesliceRouter,
339 moduleRouter,
340 parameters.TMaxLocal_ns,
341 getTimeRange(parameters));
342
343 outputFile.put(tev);
344
345 timerTX.stop();
346 }
347
348 if (parameters.writeL0()) {
349
350 timerTW.start();
351
352 outputFile.put(*timeslice);
353
354 timerTW.stop();
355 }
356
357 if (parameters.writeL1()) {
358
359 timerTW.start();
360
361 outputFile.put(JTimesliceL1<JDAQTimesliceL1>(timesliceL1, timesliceRouter, moduleRouter, parameters.TMaxLocal_ns));
362
363 timerTW.stop();
364 }
365
366 if (parameters.writeL2()) {
367
368 timerTW.start();
369
370 outputFile.put(JTimesliceL1<JDAQTimesliceL2>(timesliceL2, timesliceRouter, moduleRouter, parameters.L2.TMaxLocal_ns));
371
372 timerTW.stop();
373 }
374
375 if (parameters.writeSN()) {
376
377 timerTW.start();
378
379 outputFile.put(JTimesliceL1<JDAQTimesliceSN>(timesliceSN, timesliceRouter, moduleRouter, parameters.SN.TMaxLocal_ns));
380
381 timerTW.stop();
382 }
383
384 if (parameters.writeSummary()) {
385
386 timerSW.start();
387
388 outputFile.put(JDAQSummaryslice(*timeslice));
389
390 timerSW.stop();
391 }
392 }
393 STATUS(endl);
394
395 if (debug >= JEEP::notice_t&& counter != 0) {
396
397 const double factor = 1.0 / (double) counter;
398
399 for (const JTimer* p : { &timerCC, &timerL0, &timerL1, &timerL2, &timerSN, &timerRX, &timerTR, &timerTX, &timerTW, &timerSW }) {
400 p->print(cout, factor);
401 }
402
403 NOTICE("Number of trigger/slices " << numberOfTriggers << "/" << counter << endl);
404 NOTICE("Trigger rate [Hz] " << numberOfTriggers * 1.0e9 * factor / getFrameTime() << endl);
405 }
406
408
409 io >> outputFile;
410
411 outputFile.close();
412}
string outputFile
KM3NeT DAQ constants, bit handling, etc.
Data structure for detector geometry and calibration.
Recording of objects on file according a format that follows from the file name extension.
Basic data structure for L0 hit.
Basic data structure for L1 hit.
Tools for handling different hit types.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
ROOT I/O of application specific meta data.
Direct access to module in detector data structure.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
ROOT TTree parameter settings of various packages.
Setting of trigger bits.
int main(int argc, char **argv)
Basic data structure for time and time over threshold information of hit.
void merge(const JMatch_t &match)
Merge events.
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
bool hasModule(const JObjectID &id) const
Has module.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition JModule.hh:75
Auxiliary class for CPU timing and usage.
Definition JTimer.hh:33
void stop()
Stop timer.
Definition JTimer.hh:127
static void disable()
Disable timers.
Definition JTimer.hh:84
void start()
Start timer.
Definition JTimer.hh:106
const JPosition3D & getPosition() const
Get position.
General exception.
Definition JException.hh:24
Auxiliary class for multiplexing object iterators.
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
Utility class to parse command line options.
Definition JParser.hh:1698
Object writing to file.
General purpose class for object reading from a list of file names.
1-dimensional frame with time calibrated data from one optical module.
2-dimensional frame with time calibrated data from one optical module.
Auxiliary class to build JDAQTimeslice for L1 timeslice.
Data structure for input to trigger algorithm.
JTriggerbit_t getTriggerBit() const
Get the trigger bit.
Nano-beacon trigger.
Definition JTriggerNB.hh:21
Auxiliary class to build JDAQEvent for a triggered event.
const JDAQChronometer & getDAQChronometer() const
Get DAQ chronometer.
Auxiliary class to set DAQ system clock parameters.
Definition JDAQClock.hh:27
void set(const JDAQClock_t clock)
Set clock type.
Definition JDAQClock.hh:64
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
double getMaximalDistance(const JDetector &detector, const bool option=false)
Get maximal distance between modules in detector.
@ debug_t
debug
Definition JMessage.hh:29
@ notice_t
notice
Definition JMessage.hh:32
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::set< JROOTClassSelector > getROOTClassSelection(const bool option=false)
Get ROOT class selection.
Long64_t counter_type
Type definition for counter.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
double getFrameTime()
Get frame time duration.
Definition JDAQClock.hh:162
void setDAQLongprint(const bool option)
Set DAQ print option.
Definition JDAQPrint.hh:28
double getRTS()
Get TDC dynamic range.
Definition JDAQClock.hh:173
static const int HIGH_RATE_VETO_DISABLE
Enable (disable) use of high-rate veto test if this status bit is 0 (1);.
Definition pmt_status.hh:13
Detector file.
Definition JHead.hh:227
Match of two events considering overlap in time and position.
Acoustic hit.
Definition JBillabong.cc:70
Type list.
Definition JTypeList.hh:23
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary class to select ROOT class based on class name.
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72
Router for fast addressing of hits in KM3NETDAQ::JDAQTimeslice data structure as a function of the op...
void configure(const JDAQTimeslice &timeslice)
Configure.