135{
139
141
144 JLimit_t& numberOfEvents = inputFile.getLimit();
145 string detectorFileA;
146 string detectorFileB;
147 int run;
149 bool triggeredEventsOnly;
153 string runbyrun;
154 double sigma_ns;
157
158 try {
159
160 JParser<> zap(
"Auxiliary program to trigger Monte Carlo events.");
161
162 zap[
'f'] =
make_field(inputFile,
"input file (output of detector simulation)");
165 zap[
'a'] =
make_field(detectorFileA,
"detector used for conversion from Monte Carlo truth to raw data.");
166 zap[
'b'] =
make_field(detectorFileB,
"detector used for conversion of raw data to calibrated data.") =
"";
167 zap[
'R'] =
make_field(run,
"run number") = -1;
170 zap[
'O'] =
make_field(triggeredEventsOnly,
"optionally write only triggered events.");
177
178 zap(argc, argv);
179 }
180 catch(const exception &error) {
181 FATAL(error.what() << endl);
182 }
183
184 seed.set(gRandom);
185
187
189
190 if (detectorFileB == "") {
191 detectorFileB = detectorFileA;
192 }
193
194
197
198 try {
199 load(detectorFileA, detectorA);
200 load(detectorFileB, detectorB);
201 }
204 }
205
206 const double TA_ns = getT0(detectorA);
207 const double TB_ns = getT0(detectorB);
208
210
212 FATAL(
"Invalid PMT parameters " << pmtParameters << endl);
213 }
214
215 if (pmtParameters.
getQE() != 1.0) {
216
217 WARNING(
"Correct background rates with global efficiency " << pmtParameters.
getQE() << endl);
218
220 }
221
223
224 try {
226 }
229 }
230
234
236
238
240
241 if (runbyrun != "") {
242
243 NOTICE(
"Using run-by-run: " << runbyrun << endl);
244
245 scanner.configure(runbyrun);
246
247 if (!scanner.empty()) {
248 UTC = scanner.begin()->getTimesliceStart();
249 } else {
250 FATAL(
"Run-by-run simulation misses summary data." << endl);
251 }
252
253 try {
257 }
260 }
261
262 try {
263
265
266 NOTICE(
"Set trigger parameters from run-by-run input." << endl);
267 }
269 WARNING(
"No trigger parameters from run-by-run input;\nrun with default/user input." << endl);
270 }
271
272
273
274 JHead buffer(header);
275
278
279 copy(buffer, header);
280
281 } else {
282
283 NOTICE(
"Using fixed rates [Hz]: " << rates_Hz << endl);
284
285 try {
289 }
292 }
293 }
294
295
296
297 if (parameters.disableHighRateVeto) {
298
299 NOTICE(
"Disabling high-rate veto of all PMTs." << endl);
300
302 }
303
305
306 DEBUG(
"Trigger:" << endl << parameters << endl);
307 DEBUG(
"PMT parameters:" << endl << pmtParameters << endl);
308
311
312 const JTimeRange period(-(Tmax + parameters.TMaxLocal_ns),
313 +(Tmax + parameters.TMaxLocal_ns));
314
316
318
321 typedef JTimeslice <hit_type> JTimeslice_t;
322 typedef JBuildL1 <hit_type> JBuildL1_t;
323 typedef JBuildL2 <hit_type> JBuildL2_t;
324
325 const JBuildL1_t buildL1(parameters);
326 const JBuildL2_t buildL2(parameters.L2);
327 const JBuildL2_t buildSN(parameters.SN);
328
330
334
335
336 TH1D h1("Trigger bits", NULL, NUMBER_OF_TRIGGER_BITS, -0.5, NUMBER_OF_TRIGGER_BITS - 0.5);
337
338
340
343 }
344
349
351 int trigger_counter = 0;
352
353 for (
string file_name; inputFile.
hasNext(); ) {
354
356
358
359 DEBUG(*event << endl);
360
362
365 }
366
368
369 if (run == -1) {
370 run = event->mc_run_id;
371 }
372
376
378
379 if (runbyrun != "") {
380
381 if (event->mc_event_time == TTimeStamp(0)) {
382 FATAL(
"Monte Carlo event time undefined." << endl);
383 }
384
387
388 if (!frame_time(t1)) {
389
390 const Long64_t index = scanner.find(utc);
392
394 p = scanner.getEntry(index - 1);
395 }
396
399 }
400
402
406
408 <<
FIXED(15,3) << event->mc_event_time.AsDouble() <<
" [s] "
409 << utc << ' '
410 <<
FIXED(12,0) << t1 <<
" [ns] "
411 << frame_time(t1) << endl);
412 }
413
414 if (!event->mc_hits.empty() && frame_time(t1)) {
415
417
419
420 DEBUG(
"Start time: " <<
FIXED(12,2) << t0 <<
' ' <<
FIXED(12,2) << t1 <<
' ' <<
FIXED(9,2) << TA_ns << endl);
421
422 t1 += TA_ns;
423
425
426 timeRange.
add(event->mc_t);
427 timeRange.
add(period);
428
430
432
433 DEBUG(timeslice << endl);
434
435
436 timesliceRouter.configure(timeslice);
437
438 JTimeslice_t timesliceL0(timeslice.getDAQChronometer());
439 JTimeslice_t timesliceL1(timeslice.getDAQChronometer());
440 JTimeslice_t timesliceL2(timeslice.getDAQChronometer());
441 JTimeslice_t timesliceSN(timeslice.getDAQChronometer());
442
443 for (JDAQTimeslice::const_iterator super_frame = timeslice.begin(); super_frame != timeslice.end(); ++super_frame) {
444
445 if (moduleRouter.hasModule(super_frame->getModuleID())) {
446
447
448
449 const JModule& module = moduleRouter.getModule(super_frame->getModuleID());
450 const JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*super_frame, module);
451
452
453
454 timesliceL0.push_back(JSuperFrame1D_t(buffer));
455
456 DEBUG(
"L0 " << setw(8) << timesliceL0.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceL0.rbegin()->size() << endl);
457
458
459
460 timesliceL1.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
461 super_frame->getModuleIdentifier(),
463
464 buildL1(*timesliceL0.rbegin(), back_inserter(*timesliceL1.rbegin()));
465
466 DEBUG(
"L1 " << setw(8) << timesliceL1.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceL1.rbegin()->size() << endl);
467
468
469
470 timesliceL2.push_back(JSuperFrame1D_t(super_frame->getDAQChronometer(),
471 super_frame->getModuleIdentifier(),
473
474 buildL2(buffer, *timesliceL1.rbegin(), back_inserter(*timesliceL2.rbegin()));
475
476 DEBUG(
"L2 " << setw(8) << timesliceL2.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceL2.rbegin()->size() << endl);
477
478
479 {
480 JTimeslice_t::value_type tv(super_frame->getDAQChronometer(),
481 super_frame->getModuleIdentifier(),
483
484 buildSN(buffer, *timesliceL1.rbegin(), back_inserter(tv));
485
486 if (!tv.empty()) {
487
488 timesliceSN.push_back(tv);
489
490 DEBUG(
"SN " << setw(8) << timesliceSN.rbegin()->getModuleID() <<
' ' << setw(8) << timesliceSN.rbegin()->size() << endl);
491 }
492 }
493 }
494 }
495
496
497
498
501
502 trigger3DMuon (trigger_input, back_inserter(trigger_output));
503 trigger3DShower(trigger_input, back_inserter(trigger_output));
504 triggerMXShower(trigger_input, timesliceL0, back_inserter(trigger_output));
505
507
508 for (JTriggerOutput::const_iterator to = trigger_output.begin(); to != trigger_output.end(); ++to) {
509
510 for (int i = 0; i != h1.GetNbinsX(); ++i) {
511 if (to->hasTriggerBit(i)) {
512 h1.Fill((double) i);
513 }
514 }
515
517
518 eventTime.
add(TA_ns);
519 eventTime.
sub(TB_ns);
520
522 cout << "Event time: "
523 << to->getFrameIndex() << ' '
524 << eventTime << ' '
525 << timeRange << ' '
526 << (timeRange.
overlap(eventTime) ?
"Y" :
"N") << endl;
527 }
528
529 if (timeRange.
overlap(eventTime)) {
530
532 timesliceRouter,
533 moduleRouter,
534 parameters.TMaxLocal_ns,
535 getTimeRange(parameters));
536
537 tev.setCounter(trigger_counter);
538
540
542 }
543 }
544
545
546 if (!triggeredEventsOnly ||
trigger) {
547
548 if (parameters.writeL0()) {
550 }
551
552 if (parameters.writeL1()) {
554 }
555
556 if (parameters.writeL2()) {
558 }
559
560 if (parameters.writeSN()) {
562 }
563
564 if (parameters.writeSummary()) {
565
566 if (fs.count(chronometer.getFrameIndex()) == 0) {
567
569
570 fs.insert(chronometer.getFrameIndex());
571 }
572 }
573 }
574 }
575
576 if (!triggeredEventsOnly ||
trigger) {
577
579
580 ++trigger_counter;
581 }
582 }
584
585 {
587
589 }
590
594}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
JAANET::start_run start_run
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.
static void Throw(const bool option)
Enable/disable throw option.
Utility class to parse command line options.
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
counter_type getCounter() const
Get counter.
virtual const pointer_type & next() override
Get next element.
const std::string & getFilename() const
Get current file name.
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
void update(const JDAQSummaryslice *ps)
Update router.
Template definition for direct access of elements in ROOT TChain.
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 KM3NETDAQ::JDAQEvent for a triggered event.
int getRunNumber() const
Get run number.
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
int getFrameIndex() const
Get frame index.
Data structure for UTC time.
static const JDAQUTCExtended & getInstance()
Get arbitrary offset (e.g.
double getTimeNanoSecond() const
Get time (limited to 16 ns cycles).
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).
double getTimeDuration(const JDAQUTCTimeRange &utc)
Get time duration of given UTC time range.
JDAQUTCTimeRange getUTCTimeRange()
Get UTC time range.
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.
double getTimeDifference(const JDAQChronometer &first, const JDAQChronometer &second)
Get time difference between two chronometers.
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.
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.
Transmission with 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.
void correct(const double QE)
Correct rates for global efficiency,.
Auxiliary class for mixed-L1/L0 K40 rates.
Auxiliary class for defining the range of iterations of objects.
static counter_type max()
Get maximum counter value.
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.