Jpp 20.0.0-27-g39925593c-D
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();
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 {
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 {
279 JTimeslice_t::value_type tv(super_frame->getDAQChronometer(),
280 super_frame->getModuleIdentifier(),
281 module.getPosition());
282
283 buildSN(buffer, *timesliceL1.rbegin(), back_inserter(tv));
284
285 if (!tv.empty()) {
286 timesliceSN.push_back(tv);
287 }
288 }
289
290 timerSN.stop();
291 }
292 }
293
294 // Trigger
295
296 if (parameters.triggerNB.enabled) {
297
298 timerTX.start();
299
301
302 for (JTriggerInput::const_iterator hit = trigger_input.begin(); hit != trigger_input.end(); ++hit) {
303
304 if (parameters.triggerNB.write()) {
305
306 JTriggeredEvent tev(timesliceNB.getDAQChronometer(),
307 getTriggerMask(triggerNB.getTriggerBit()),
308 *hit,
309 timesliceRouter,
310 moduleRouter,
311 parameters.TMaxLocal_ns,
312 parameters.triggerNB.DMax_m,
313 getTimeRange(parameters.triggerNB));
314
315 outputFile.put(tev);
316 }
317 }
318
319 timerTX.stop();
320 }
321
322 timerTR.start();
323
326
328 trigger3DShower(trigger_input, back_inserter(trigger_output));
330
331 trigger_output.merge(JEventOverlap(parameters.TMaxEvent_ns));
332
334
335 timerTR.stop();
336
337 DEBUG("Number of triggers: " << trigger_output.size() << endl);
338
339 for (JTriggerOutput::const_iterator event = trigger_output.begin(); event != trigger_output.end(); ++event) {
340
341 timerTX.start();
342
343 JTriggeredEvent tev(*event,
344 timesliceRouter,
345 moduleRouter,
346 parameters.TMaxLocal_ns,
347 getTimeRange(parameters));
348
349 outputFile.put(tev);
350
351 timerTX.stop();
352 }
353
354 if (parameters.writeL0()) {
355
356 timerTW.start();
357
358 outputFile.put(*timeslice);
359
360 timerTW.stop();
361 }
362
363 if (parameters.writeL1()) {
364
365 timerTW.start();
366
367 outputFile.put(JTimesliceL1<JDAQTimesliceL1>(timesliceL1, timesliceRouter, moduleRouter, parameters.TMaxLocal_ns));
368
369 timerTW.stop();
370 }
371
372 if (parameters.writeL2()) {
373
374 timerTW.start();
375
376 outputFile.put(JTimesliceL1<JDAQTimesliceL2>(timesliceL2, timesliceRouter, moduleRouter, parameters.L2.TMaxLocal_ns));
377
378 timerTW.stop();
379 }
380
381 if (parameters.writeSN()) {
382
383 timerTW.start();
384
385 outputFile.put(JTimesliceL1<JDAQTimesliceSN>(timesliceSN, timesliceRouter, moduleRouter, parameters.SN.TMaxLocal_ns));
386
387 timerTW.stop();
388 }
389
390 if (parameters.writeSummary()) {
391
392 timerSW.start();
393
394 outputFile.put(JDAQSummaryslice(*timeslice));
395
396 timerSW.stop();
397 }
398 }
399 STATUS(endl);
400
401 if (debug >= JEEP::notice_t&& counter != 0) {
402
403 const double factor = 1.0 / (double) counter;
404
405 for (const JTimer* p : { &timerCC, &timerL0, &timerL1, &timerL2, &timerSN, &timerRX, &timerTR, &timerTX, &timerTW, &timerSW }) {
406 p->print(cout, factor);
407 }
408
409 NOTICE("Number of trigger/slices " << numberOfTriggers << "/" << counter << endl);
410 NOTICE("Trigger rate [Hz] " << numberOfTriggers * 1.0e9 * factor / getFrameTime() << endl);
411 }
412
414
415 io >> outputFile;
416
417 outputFile.close();
418}
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.
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.
Data structure for a composite optical module.
Definition JModule.hh:76
Auxiliary class for CPU timing and usage.
Definition JTimer.hh:33
static void disable()
Disable timers.
Definition JTimer.hh:84
General exception.
Definition JException.hh:24
Template definition of a multi-dimensional oscillation probability interpolation table.
General purpose class for object reading from a list of file names.
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 KM3NETDAQ::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).
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:14
Detector file.
Definition JHead.hh:227
Match of two events considering overlap in time and position.
Transmission with position.
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.