132{
136
138
141 JLimit_t& numberOfEvents = inputFile.getLimit();
142 string detectorFileA;
143 string detectorFileB;
144 int run;
146 bool triggeredEventsOnly;
150 double sigma_ns;
153
154 try {
155
156 JParser<> zap(
"Auxiliary program to trigger Monte Carlo events.");
157
158 zap[
'f'] =
make_field(inputFile,
"input file (output of detector simulation)");
161 zap[
'a'] =
make_field(detectorFileA,
"detector used for conversion from Monte Carlo truth to raw data.");
162 zap[
'b'] =
make_field(detectorFileB,
"detector used for conversion of raw data to calibrated data.") =
"";
163 zap[
'R'] =
make_field(run,
"run number") = -1;
166 zap[
'O'] =
make_field(triggeredEventsOnly,
"optionally write only triggered events.");
172
173 zap(argc, argv);
174 }
175 catch(const exception &error) {
176 FATAL(error.what() << endl);
177 }
178
179 seed.set(gRandom);
180
182
184
185 if (detectorFileB == "") {
186 detectorFileB = detectorFileA;
187 }
188
189
192
193 try {
194 load(detectorFileA, detectorA);
195 load(detectorFileB, detectorB);
196 }
199 }
200
201 const double TA_ns = getT0(detectorA);
202 const double TB_ns = getT0(detectorB);
203
205
207 FATAL(
"Invalid PMT parameters " << pmtParameters << endl);
208 }
209
210 if (pmtParameters.
getQE() != 1.0) {
211
212 WARNING(
"Correct background rates with global efficiency " << pmtParameters.
getQE() << endl);
213
215 }
216
218
219 try {
221 }
224 }
225
229
231
232 NOTICE(
"Using run-by-run:" << endl << runbyrun << endl);
233
235 FATAL(
"Run-by-run simulation yields no input." << endl);
236 }
237
240 }
241
242 try {
246 }
249 }
250
251 try {
252
254
255 NOTICE(
"Set trigger parameters from run-by-run input." << endl);
256 }
258 WARNING(
"No trigger parameters from run-by-run input;\nrun with default/user input." << endl);
259 }
260
261
262
263 JHead buffer(header);
264
265 buffer.DAQ.livetime_s =
getLivetime(runbyrun->getFilelist());
267
268 copy(buffer, header);
269
270 } else {
271
272 NOTICE(
"Using fixed rates [Hz]: " << rates_Hz << endl);
273
274 try {
278 }
281 }
282 }
283
284
285
286 if (parameters.disableHighRateVeto) {
287
288 NOTICE(
"Disabling high-rate veto of all PMTs." << endl);
289
291 }
292
294
295 DEBUG(
"Trigger:" << endl << parameters << endl);
296 DEBUG(
"PMT parameters:" << endl << pmtParameters << endl);
297
300
301 const JTimeRange period(-(Tmax + parameters.TMaxLocal_ns),
302 +(Tmax + parameters.TMaxLocal_ns));
303
305
308 typedef JTimeslice <hit_type> JTimeslice_t;
309 typedef JBuildL1 <hit_type> JBuildL1_t;
310 typedef JBuildL2 <hit_type> JBuildL2_t;
311
312 const JBuildL1_t buildL1(parameters);
313 const JBuildL2_t buildL2(parameters.L2);
314 const JBuildL2_t buildSN(parameters.SN);
315
317
321
322
323 TH1D h1("Trigger bits", NULL, NUMBER_OF_TRIGGER_BITS, -0.5, NUMBER_OF_TRIGGER_BITS - 0.5);
324
325
327
330 }
331
336
337 JLimit_t limit = inputFile.getLimit();
339 int trigger_counter = 0;
340
342
343 int mc_run_id = 0;
344
345 try {
346
348
349 mc_run_id = head.start_run.run_id;
350 }
353 }
354
356
358
359 for ( ; in.hasNext() && number_of_events != limit; ++number_of_events) {
360
361 STATUS(
"event: " << setw(10) << number_of_events <<
'\r');
DEBUG(endl);
362
363 Evt*
event = in.next();
364
366
367 DEBUG(*event << endl);
368
370
371 if (!event->mc_hits.empty()) {
372
373 int frame_index = (int) in.getCounter() + 1;
374
376
378
380
381 frame_index = summaryRouter.getFrameIndex();
382 run = summaryRouter.getRunNumber();
383 }
384
385
386
388
391 }
392
394 const double t1 = gRandom->Rndm() *
getFrameTime() + TA_ns;
395
396 DEBUG(
"Start time: " <<
FIXED(12,2) << t0 <<
' ' <<
FIXED(12,2) << t1 <<
' ' <<
FIXED(9,2) << TA_ns << endl);
397
399
400 timeRange.
add(event->mc_t);
401 timeRange.
add(period);
402
405
406 if (event->mc_event_time != TTimeStamp(0)) {
408 }
409
410 const JDAQChronometer chronometer(detectorB.
getID(), (run != -1 ? run : mc_run_id), frame_index, utc);
411
413
414 DEBUG(timeslice << endl);
415
416
417 timesliceRouter.configure(timeslice);
418
419 JTimeslice_t timesliceL0(timeslice.getDAQChronometer());
420 JTimeslice_t timesliceL1(timeslice.getDAQChronometer());
421 JTimeslice_t timesliceL2(timeslice.getDAQChronometer());
422 JTimeslice_t timesliceSN(timeslice.getDAQChronometer());
423
424 for (JDAQTimeslice::const_iterator super_frame = timeslice.begin(); super_frame != timeslice.end(); ++super_frame) {
425
426 if (moduleRouter.hasModule(super_frame->getModuleID())) {
427
428
429
430 const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
431 const JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*super_frame, module);
432
433
434
435 timesliceL0.push_back(JSuperFrame1D_t(buffer));
436
437
438
439 timesliceL1.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
440 super_frame->getModuleIdentifier(),
442
443 buildL1(*timesliceL0.rbegin(), back_inserter(*timesliceL1.rbegin()));
444
445
446
447 timesliceL2.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
448 super_frame->getModuleIdentifier(),
450
451 buildL2(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceL2.rbegin()));
452
453
454
455 timesliceSN.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
456 super_frame->getModuleIdentifier(),
458
459 buildSN(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceSN.rbegin()));
460
461 DEBUG(
"L0 " << setw(8) << timesliceL0.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceL0.rbegin()->size() << endl);
462 DEBUG(
"L1 " << setw(8) << timesliceL1.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceL1.rbegin()->size() << endl);
463 DEBUG(
"L2 " << setw(8) << timesliceL2.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceL2.rbegin()->size() << endl);
464 DEBUG(
"SN " << setw(8) << timesliceSN.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceSN.rbegin()->size() << endl);
465 }
466 }
467
468
469
470
473
474 trigger3DMuon (trigger_input, back_inserter(trigger_output));
475 trigger3DShower(trigger_input, back_inserter(trigger_output));
476 triggerMXShower(trigger_input, timesliceL0, back_inserter(trigger_output));
477
479
480 for (JTriggerOutput::const_iterator to = trigger_output.begin(); to != trigger_output.end(); ++to) {
481
482 for (int i = 0; i != h1.GetNbinsX(); ++i) {
483 if (to->hasTriggerBit(i)) {
484 h1.Fill((double) i);
485 }
486 }
487
489
490 eventTime.
add(TA_ns);
491 eventTime.
sub(TB_ns);
492
494 << to->getFrameIndex() << ' '
495 << eventTime << ' '
496 << timeRange << ' '
497 << (timeRange.
overlap(eventTime) ?
"Y" :
"N") << endl);
498
499 if (timeRange.
overlap(eventTime)) {
500
502 timesliceRouter,
503 moduleRouter,
504 parameters.TMaxLocal_ns,
505 getTimeRange(parameters));
506
507
508
509 tev.setCounter(trigger_counter);
510
512
514 }
515 }
516
517
518 if (!triggeredEventsOnly ||
trigger) {
519
520 if (parameters.writeL0()) {
522 }
523
524 if (parameters.writeL1()) {
526 }
527
528 if (parameters.writeL2()) {
530 }
531
532 if (parameters.writeSN()) {
534 }
535
536 if (parameters.writeSummary()) {
538 }
539 }
540 }
541
542 if (!triggeredEventsOnly ||
trigger) {
543
545
546 ++trigger_counter;
547 }
548 }
549 }
551
552
554
556
560}
#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.
Auxiliary data structure for floating point format specification.
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 and position.
Template definition of random value generator.
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.