101{
105
107
110 JLimit_t& numberOfEvents = inputFile.getLimit();
111 string detectorFileA;
112 string detectorFileB;
113 int run;
115 bool triggeredEventsOnly;
119 double sigma_ns;
120 UInt_t seed;
122
123 try {
124
125 JParser<> zap(
"Auxiliary program to trigger Monte Carlo events.");
126
127 zap[
'f'] =
make_field(inputFile,
"input file (output of detector simulation)");
130 zap[
'a'] =
make_field(detectorFileA,
"detector used for conversion from Monte Carlo truth to raw data.");
131 zap[
'b'] =
make_field(detectorFileB,
"detector used for conversion of raw data to calibrated data.") =
"";
132 zap[
'R'] =
make_field(run,
"run number") = -1;
135 zap[
'O'] =
make_field(triggeredEventsOnly,
"optionally write only triggered events.");
141
142 zap(argc, argv);
143 }
144 catch(const exception &error) {
145 FATAL(error.what() << endl);
146 }
147
148 gRandom->SetSeed(seed);
149
151
153
154 if (detectorFileB == "") {
155 detectorFileB = detectorFileA;
156 }
157
158
161
162 try {
163 load(detectorFileA, detectorA);
164 load(detectorFileB, detectorB);
165 }
168 }
169
171
173 FATAL(
"Invalid PMT parameters " << pmtParameters << endl);
174 }
175
176 if (pmtParameters.
getQE() != 1.0) {
177
178 WARNING(
"Correct background rates with global efficiency " << pmtParameters.
getQE() << endl);
179
181 }
182
184
185 try {
187 }
190 }
191
195
197
198 NOTICE(
"Using run-by-run:" << endl << runbyrun << endl);
199
201 FATAL(
"Run-by-run simulation yields no input." << endl);
202 }
203
206 }
207
208 try {
212 }
215 }
216
217 try {
218
220
221 NOTICE(
"Set trigger parameters from run-by-run input." << endl);
222 }
224 WARNING(
"No trigger parameters from run-by-run input;\nrun with default/user input." << endl);
225 }
226
227
228
229 JHead buffer(header);
230
231 buffer.DAQ.livetime_s =
getLivetime(runbyrun->getFilelist());
233
234 copy(buffer, header);
235
236 } else {
237
238 NOTICE(
"Using fixed rates [Hz]: " << rates_Hz << endl);
239
240 try {
244 }
247 }
248 }
249
250
251
252 if (parameters.disableHighRateVeto) {
253
254 NOTICE(
"Disabling high-rate veto of all PMTs." << endl);
255
257 }
258
260
261 DEBUG(
"Trigger:" << endl << parameters << endl);
262 DEBUG(
"PMT parameters:" << endl << pmtParameters << endl);
263
266
267 const JTimeRange period(-(Tmax + parameters.TMaxLocal_ns),
268 +(Tmax + parameters.TMaxLocal_ns));
269
271
274 typedef JTimeslice <hit_type> JTimeslice_t;
275 typedef JBuildL1 <hit_type> JBuildL1_t;
276 typedef JBuildL2 <hit_type> JBuildL2_t;
277
278 const JBuildL1_t buildL1(parameters);
279 const JBuildL2_t buildL2(parameters.L2);
280 const JBuildL2_t buildSN(parameters.SN);
281
283
287
288
289 TH1D h1("Trigger bits", NULL, NUMBER_OF_TRIGGER_BITS, -0.5, NUMBER_OF_TRIGGER_BITS - 0.5);
290
291
293
296 }
297
302
303 JLimit_t limit = inputFile.getLimit();
305 int trigger_counter = 0;
306
308
309 int mc_run_id = 0;
310
311 try {
312
314
315 mc_run_id = head.start_run.run_id;
316 }
319 }
320
322
324
325 for ( ; in.hasNext() && number_of_events != limit; ++number_of_events) {
326
327 STATUS(
"event: " << setw(10) << number_of_events <<
'\r');
DEBUG(endl);
328
329 Evt*
event = in.next();
330
332
333 DEBUG(*event << endl);
334
336
337 if (!event->mc_hits.empty()) {
338
339 int frame_index = (int) in.getCounter() + 1;
340
342
344
346
347 frame_index = summaryRouter.getFrameIndex();
348 run = summaryRouter.getRunNumber();
349 }
350
351
352
354
357 }
358
361
363
364 timeRange.
add(event->mc_t);
365 timeRange.
add(period);
366
369
370 if (event->mc_event_time != TTimeStamp(0)) {
372 }
373
374 const JDAQChronometer chronometer(detectorB.
getID(), (run != -1 ? run : mc_run_id), frame_index, utc);
375
377
378 DEBUG(timeslice << endl);
379
380
381 timesliceRouter.configure(timeslice);
382
383 JTimeslice_t timesliceL0(timeslice.getDAQChronometer());
384 JTimeslice_t timesliceL1(timeslice.getDAQChronometer());
385 JTimeslice_t timesliceL2(timeslice.getDAQChronometer());
386 JTimeslice_t timesliceSN(timeslice.getDAQChronometer());
387
388 for (JDAQTimeslice::const_iterator super_frame = timeslice.begin(); super_frame != timeslice.end(); ++super_frame) {
389
390 if (moduleRouter.hasModule(super_frame->getModuleID())) {
391
392
393
394 const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
395 const JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*super_frame, module);
396
397
398
399 timesliceL0.push_back(JSuperFrame1D_t(buffer));
400
401
402
403 timesliceL1.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
404 super_frame->getModuleIdentifier(),
406
407 buildL1(*timesliceL0.rbegin(), back_inserter(*timesliceL1.rbegin()));
408
409
410
411 timesliceL2.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
412 super_frame->getModuleIdentifier(),
414
415 buildL2(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceL2.rbegin()));
416
417
418
419 timesliceSN.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
420 super_frame->getModuleIdentifier(),
422
423 buildSN(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceSN.rbegin()));
424
425 DEBUG(
"L0 " << setw(8) << timesliceL0.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceL0.rbegin()->size() << endl);
426 DEBUG(
"L1 " << setw(8) << timesliceL1.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceL1.rbegin()->size() << endl);
427 DEBUG(
"L2 " << setw(8) << timesliceL2.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceL2.rbegin()->size() << endl);
428 DEBUG(
"SN " << setw(8) << timesliceSN.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceSN.rbegin()->size() << endl);
429 }
430 }
431
432
433
434
437
438 trigger3DMuon (trigger_input, back_inserter(trigger_output));
439 trigger3DShower(trigger_input, back_inserter(trigger_output));
440 triggerMXShower(trigger_input, timesliceL0, back_inserter(trigger_output));
441
443
444 for (JTriggerOutput::const_iterator to = trigger_output.begin(); to != trigger_output.end(); ++to) {
445
446 for (int i = 0; i != h1.GetNbinsX(); ++i) {
447 if (to->hasTriggerBit(i)) {
448 h1.Fill((double) i);
449 }
450 }
451
453
455 << to->getFrameIndex() << ' '
456 << eventTime << ' '
457 << timeRange << endl);
458
459 if (timeRange.
overlap(eventTime)) {
460
462 timesliceRouter,
463 moduleRouter,
464 parameters.TMaxLocal_ns,
465 getTimeRange(parameters));
466
467
468
469 tev.setCounter(trigger_counter);
470
472
474 }
475 }
476
477
478 if (!triggeredEventsOnly ||
trigger) {
479
480 if (parameters.writeL0()) {
482 }
483
484 if (parameters.writeL1()) {
486 }
487
488 if (parameters.writeL2()) {
490 }
491
492 if (parameters.writeSN()) {
494 }
495
496 if (parameters.writeSummary()) {
498 }
499 }
500 }
501
502 if (!triggeredEventsOnly ||
trigger) {
503
505
506 ++trigger_counter;
507 }
508 }
509 }
511
512
514
516
520}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
void merge(const JMatch_t &match)
Merge events.
void setPMTStatus(const int bit)
Set status of all PMTs.
static double getSigma()
Get intrinsic time smearing of K40 coincidences.
static void setSigma(const double sigma)
Set intrinsic time smearing of K40 coincidences.
Default implementation of the simulation of K40 background.
Router for direct addressing of module data in detector data structure.
Data structure for a composite optical module.
Default PMT simulation interface.
Auxiliary class for map of PMT parameters.
double getQE(const JPMTIdentifier &id) const
Get QE of given PMT.
bool is_valid() const
Check validity of PMT parameters.
const JPosition3D & getPosition() const
Get position.
virtual const char * what() const override
Get error message.
int getID() const
Get identifier.
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
static void Throw(const bool option)
Enable/disable throw option.
Utility class to parse command line options.
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
void update(const JDAQSummaryslice *ps)
Update router.
CLB simulation based on run-by-run information.
K40 simulation based on run-by-run information.
PMT simulation based on run-by-run information.
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.
Auxiliary class to build JDAQEvent for a triggered event.
Data structure for UTC time.
static const JDAQUTCExtended & getInstance()
Get arbitrary offset (e.g.
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
void copy(const Head &from, JHead &to)
Copy header from from to to.
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.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Long64_t counter_type
Type definition for counter.
double getLivetime(const std::string &file_name)
Get data taking live time.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
KM3NeT DAQ data structures and auxiliaries.
double getFrameTime()
Get frame time duration.
void setDAQLongprint(const bool option)
Set DAQ print option.
double getTimeOfFrame(const int frame_index)
Get start time of frame in ns since start of run for a given frame index.
double getMaximalTime(const double R_Hz)
Get maximal time for given rate.
JDAQUTCExtended getDAQUTCExtended(const TTimeStamp &t0, const double t1=0.0)
Get DAQ UTC time.
static const int HIGH_RATE_VETO_DISABLE
Enable (disable) use of high-rate veto test if this status bit is 0 (1);.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
int mc_run_id
MC run identifier.
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Match of two events considering overlap in time.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Auxiliary class for K40 rates.
double getSinglesRate() const
Get singles rate.
void correct(const double QE)
Correct rates for global efficiency,.
Auxiliary class for defining the range of iterations of objects.
static counter_type max()
Get maximum counter value.
Auxiliary class to select summary data (KM3NETDAQ::JDAQSummaryslice) from the specified raw data file...
bool is_valid() const
Check validity of run by run options.
Router for fast addressing of hits in KM3NETDAQ::JDAQTimeslice data structure as a function of the op...
Timeslice with Monte Carlo event.
Auxiliary class to create summary data.