Jpp master_rocky-44-g75b7c4f75
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;
78 int debug;
79
80 try {
81
82 JParser<> zap("Auxiliary program to trigger time slice data.");
83
84 zap['f'] = make_field(inputFile, "input file.");
85 zap['o'] = make_field(outputFile, "output file.") = "trigger_processor.dat";
86 zap['n'] = make_field(numberOfEvents) = JLimit::max();
87 zap['a'] = make_field(detectorFile, "detector file.");
88 zap['@'] = make_field(parameters, "trigger parameters") = JPARSER::initialised();
89 zap['c'] = make_field(clock, "DAQ clock") = JDAQClock::KM3NET, JDAQClock::PPM_DU, JDAQClock::ANTARES;
90 zap['C'] = make_field(selector, "timeslice selector, e.g. JDAQTimesliceL1.") = getROOTClassSelection<JDAQTimesliceTypes_t>();
91 zap['P'] = make_field(profile, "profile CPU");
92 zap['d'] = make_field(debug, "debug flag.") = 1;
93
94 zap(argc, argv);
95 }
96 catch(const exception &error) {
97 FATAL(error.what() << endl);
98 }
99
100
101 clock.set();
102
104
105 if (!profile) {
107 }
108
109 DEBUG("Frame time [ms] " << getFrameTime() * 1e-6 << endl);
110 DEBUG("Reset time [ms] " << getRTS() * 1e-6 << endl);
111 DEBUG("Trigger" << endl << parameters << endl);
112
114
115 try {
116 load(detectorFile, detector);
117 }
118 catch(const JException& error) {
119 FATAL(error);
120 }
121
122 // detector
123
124 if (parameters.disableHighRateVeto) {
125
126 NOTICE("Disabling high-rate veto of all PMTs." << endl);
127
128 detector.setPMTStatus(HIGH_RATE_VETO_DISABLE);
129 }
130
131 parameters.set(getMaximalDistance(detector));
132
133 const JModuleRouter moduleRouter(detector);
134
135 //typedef JHit hit_type;
136 //typedef int hit_type;
137 typedef double hit_type;
138
139 typedef JSuperFrame1D<hit_type> JSuperFrame1D_t;
140 typedef JSuperFrame2D<hit_type> JSuperFrame2D_t;
141 typedef JTimeslice <hit_type> JTimeslice_t;
142 typedef JBuildL1 <hit_type> JBuildL1_t;
143 typedef JBuildL2 <hit_type> JBuildL2_t;
144
145 const JBuildL1_t buildL1(parameters);
146 const JBuildL2_t buildL2(parameters.L2);
147 const JBuildL2_t buildSN(parameters.SN);
148 const JBuildL2_t buildNB(parameters.NB);
149
150 JTimer timerCC("Calibration");
151 JTimer timerL0("L0");
152 JTimer timerL1("L1");
153 JTimer timerL2("L2");
154 JTimer timerSN("SN");
155 JTimer timerRX("Timeslice router");
156 JTimer timerTR("Trigger");
157 JTimer timerTX("Trigger router");
158 JTimer timerTW("Timeslice writer");
159 JTimer timerSW("Summary writer");
160
161 JTimesliceRouter timesliceRouter(parameters.numberOfBins);
162
163 const JTriggerNB triggerNB (parameters);
164 const JTrigger3DMuon trigger3DMuon (parameters);
165 const JTrigger3DShower trigger3DShower(parameters);
166 const JTriggerMXShower triggerMXShower(parameters, detector);
167
168
169 outputFile.open();
170
171 if (!outputFile.is_open()) FATAL("Error opening file " << outputFile << endl);
172
173 outputFile.put(JMeta(argc, argv));
174 outputFile.put(parameters);
175
176 unsigned int numberOfTriggers = 0;
177
179
180 counter_type counter = 0;
181
182 for ( ; in.hasNext() && counter != inputFile.getLimit(); ++counter) {
183
184 STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
185
186 const JDAQTimeslice* timeslice = in.next();
187
188 DEBUG(*timeslice << endl);
189
190 timerRX.start();
191
192 timesliceRouter.configure(*timeslice);
193
194 timerRX.stop();
195
196
197 JTimeslice_t timesliceL0(timeslice->getDAQChronometer());
198 JTimeslice_t timesliceL1(timeslice->getDAQChronometer());
199 JTimeslice_t timesliceL2(timeslice->getDAQChronometer());
200 JTimeslice_t timesliceSN(timeslice->getDAQChronometer());
201 JTimeslice_t timesliceNB(timeslice->getDAQChronometer());
202
203 for (JDAQTimeslice::const_iterator super_frame = timeslice->begin(); super_frame != timeslice->end(); ++super_frame) {
204
205 if (moduleRouter.hasModule(super_frame->getModuleID())) {
206
207 // calibration
208
209 timerCC.start();
210
211 const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
212 JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*super_frame, module);
213
214 timerCC.stop();
215
216 // Apply high-rate veto
217
218 buffer.applyHighRateVeto(parameters.highRateVeto_Hz);
219
220 // L0
221
222 timerL0.start();
223
224 timesliceL0.push_back(JSuperFrame1D_t(buffer));
225
226 timerL0.stop();
227
228 // Nano-beacon trigger
229
230 if (parameters.triggerNB.enabled) {
231
232 JSuperFrame2D_t::iterator __end = partition(buffer.begin(), buffer.end(), parameters.triggerNB.pmts);
233
234 if (buffer.begin() != __end) {
235
236 timesliceNB.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
237 super_frame->getModuleIdentifier(),
238 module.getPosition()));
239
240 JSuperFrame1D_t zbuf;
241
242 buildL1(buffer.begin(), __end , back_inserter(zbuf));
243
244 buildNB(buffer.begin() , __end, zbuf, back_inserter(*timesliceNB.rbegin()));
245 }
246 }
247
248 // L1
249
250 timerL1.start();
251
252 timesliceL1.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
253 super_frame->getModuleIdentifier(),
254 module.getPosition()));
255
256 buildL1(*timesliceL0.rbegin(), back_inserter(*timesliceL1.rbegin()));
257
258 timerL1.stop();
259
260 // L2
261
262 timerL2.start();
263
264 timesliceL2.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
265 super_frame->getModuleIdentifier(),
266 module.getPosition()));
267
268 buildL2(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceL2.rbegin()));
269
270 timerL2.stop();
271
272 // SN
273
274 timerSN.start();
275
276 timesliceSN.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
277 super_frame->getModuleIdentifier(),
278 module.getPosition()));
279
280 buildSN(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceSN.rbegin()));
281
282 timerSN.stop();
283 }
284 }
285
286 // Trigger
287
288 if (parameters.triggerNB.enabled) {
289
290 timerTX.start();
291
292 const JTriggerInput trigger_input(timesliceNB);
293
294 for (JTriggerInput::const_iterator hit = trigger_input.begin(); hit != trigger_input.end(); ++hit) {
295
296 if (parameters.triggerNB.write()) {
297
298 JTriggeredEvent tev(timesliceNB.getDAQChronometer(),
299 getTriggerMask(triggerNB.getTriggerBit()),
300 *hit,
301 timesliceRouter,
302 moduleRouter,
303 parameters.TMaxLocal_ns,
304 parameters.triggerNB.DMax_m,
305 getTimeRange(parameters.triggerNB));
306
307 outputFile.put(tev);
308 }
309 }
310
311 timerTX.stop();
312 }
313
314 timerTR.start();
315
316 JTriggerInput trigger_input(timesliceL2);
317 JTriggerOutput trigger_output;
318
319 trigger3DMuon (trigger_input, back_inserter(trigger_output));
320 trigger3DShower(trigger_input, back_inserter(trigger_output));
321 triggerMXShower(trigger_input, timesliceL0, back_inserter(trigger_output));
322
323 trigger_output.merge(JEventOverlap(parameters.TMaxEvent_ns));
324
325 numberOfTriggers += trigger_output.size();
326
327 timerTR.stop();
328
329 DEBUG("Number of triggers: " << trigger_output.size() << endl);
330
331 for (JTriggerOutput::const_iterator event = trigger_output.begin(); event != trigger_output.end(); ++event) {
332
333 timerTX.start();
334
335 JTriggeredEvent tev(*event,
336 timesliceRouter,
337 moduleRouter,
338 parameters.TMaxLocal_ns,
339 getTimeRange(parameters));
340
341 outputFile.put(tev);
342
343 timerTX.stop();
344 }
345
346 if (parameters.writeL0()) {
347
348 timerTW.start();
349
350 outputFile.put(*timeslice);
351
352 timerTW.stop();
353 }
354
355 if (parameters.writeL1()) {
356
357 timerTW.start();
358
359 outputFile.put(JTimesliceL1<JDAQTimesliceL1>(timesliceL1, timesliceRouter, moduleRouter, parameters.TMaxLocal_ns));
360
361 timerTW.stop();
362 }
363
364 if (parameters.writeL2()) {
365
366 timerTW.start();
367
368 outputFile.put(JTimesliceL1<JDAQTimesliceL2>(timesliceL2, timesliceRouter, moduleRouter, parameters.L2.TMaxLocal_ns));
369
370 timerTW.stop();
371 }
372
373 if (parameters.writeSN()) {
374
375 timerTW.start();
376
377 outputFile.put(JTimesliceL1<JDAQTimesliceSN>(timesliceSN, timesliceRouter, moduleRouter, parameters.SN.TMaxLocal_ns));
378
379 timerTW.stop();
380 }
381
382 if (parameters.writeSummary()) {
383
384 timerSW.start();
385
386 outputFile.put(JDAQSummaryslice(*timeslice));
387
388 timerSW.stop();
389 }
390 }
391 STATUS(endl);
392
393 if (debug >= JEEP::notice_t&& counter != 0) {
394
395 const double factor = 1.0 / (double) counter;
396
397 for (const JTimer* p : { &timerCC, &timerL0, &timerL1, &timerL2, &timerSN, &timerRX, &timerTR, &timerTX, &timerTW, &timerSW }) {
398 p->print(cout, factor);
399 }
400
401 NOTICE("Number of trigger/slices " << numberOfTriggers << "/" << counter << endl);
402 NOTICE("Trigger rate [Hz] " << numberOfTriggers * 1.0e9 * factor / getFrameTime() << endl);
403 }
404
406
407 io >> outputFile;
408
409 outputFile.close();
410}
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:69
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.
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.