49{
   53 
   54 
   56  JFileRecorder       <JTYPELIST<JAAnetTypes_t, JDAQTimesliceL0, JMeta, JRootTypes_t>::typelist>  
outputFile;
 
   57  JLimit_t&              numberOfEvents = inputFile.getLimit();
 
   58  string                 detectorFile;
   59  int                    run;
   62  double                 eventRate_Hz;
   65 
   66  try { 
   67 
   68    JParser<> zap(
"Auxiliary program to convert multiple Monte Carlo events to time slices.");
 
   69    
   80    
   81    zap(argc, argv);
   82  }
   83  catch(const exception &error) {
   84    FATAL(error.what() << endl);
 
   85  }
   86 
   87  seed.set(gRandom);
   88 
   90  
   91  if (pmtParameters.
getQE() != 1.0) {
 
   92 
   93    WARNING(
"Correct background rates with global efficiency " << pmtParameters.
getQE() << endl);
 
   94    
   96  }
   97 
   98  
   99 
  100  DEBUG(
"PMT paramaters: " << endl << pmtParameters << endl);
 
  101  DEBUG(
"K40 rates:      " << endl << rates_Hz      << endl);
 
  102 
  103  if (eventRate_Hz < 0.0) {
  104    FATAL(
"Invalid event rate " << eventRate_Hz << 
"; consider using JRandomTimesliceWriter." << endl);
 
  105  }
  106  
  107  
  108  
  110 
  111  try {
  113  }
  116  }
  117  
  118  
  119  
  121  
  122  try {
  124  }
  125  catch (const exception& error) {
  126    FATAL(
"Monte Carlo header is invalid");
 
  127  }
  128  
  130 
  131  if (liveTimeMC < 0) {
  132    FATAL(
"Monte Carlo live time is negative; input file may be corrupted.");
 
  133  }
  134 
  135  
  136 
  138 
  140 
  144 
  145  
  146  
  148 
  151  }
  152  
  156 
  157  
  158  
  159  bool absTime = false;
  160  
  162 
  163  if (eventRate_Hz == 0.0 && liveTimeMC == 0.0) {
  164    
  165    NOTICE(
"Event will be timed according to absolute MC time." << endl);
 
  166    
  167    absTime = true;
  168    
  169    
  172    
  173  } else {
  174    
  175    
  178    
  179    if (eventRate_Hz == 0.0 && liveTimeMC > 0.0) {
  180      int nEntries = scan->getEntries();
  181      eventRate_Hz = nEntries / liveTimeMC;
  182      DEBUG(nEntries << 
" events to be written." << endl);
 
  183      NOTICE(
"MC live time is " << liveTimeMC << 
" s" << endl);
 
  184      NOTICE(
"Event rate set to " <<  eventRate_Hz << 
" Hz from MC header." << endl);
 
  185    } 
  186  }
  187  
  188  
  189  
  190  
  191  bool pendingEvt       = false;
  192  bool pendingTimeslice = false;
  193  
  195  
  197  double tDAQ = 0; 
  198  double tOff = 0; 
  199  
  200  int frame_index = 0;
  203  
  205 
  206  while (pendingEvt || scan->hasNext()) {
  207 
  208    if (!pendingTimeslice) {
  209      
  210      frame_index++;
  213      DEBUG(
"evt count: " << setw(10) << evtCount << endl); 
 
  214      STATUS(
"frame index: " << setw(10) << frame_index << 
" | evt count: " << setw(10) << evtCount << 
"\r"); 
DEBUG(endl);
 
  215      pendingTimeslice = true;
  216    }
  217    
  218    if (!pendingEvt) {
  219      
  220      event = scan->next();
  223      
  224      if (absTime)
  226      else
  227        tDAQ += gRandom->Exp(1.0e9 / eventRate_Hz);
  228      
  229      DEBUG(
"event time [s] " << setprecision(5) << tDAQ * 1.0e-9 << endl);
 
  230      pendingEvt = true;
  231    }
  232    
  233    
  234    if (getFrameIndex(tDAQ) == frame_index) {
  235      
  236      
  238        DEBUG(*event << endl);
 
  239        
  240        event->mc_t = tDAQ - tOff;
  242        evtCount++;
  243      }
  244      
  246      pendingEvt = false;
  247    } else {
  248      
  249      DEBUG(timeslice << endl);
 
  251      pendingTimeslice = false;
  252    }
  253    
  254  }
  255  
  256  if (pendingTimeslice) {
  257    DEBUG(timeslice << endl);
 
  259    pendingTimeslice = false;
  260  }
  261  
  263 
  266  
  267  NOTICE(evtCount << 
" events written over " << frame_index << 
" timeslices. " << endl);
 
  268}
#define DEBUG(A)
Message macros.
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
JAANET::livetime livetime
 
Default implementation of the simulation of K40 background.
 
Auxiliary class for map of PMT parameters.
 
double getQE(const JPMTIdentifier &id) const
Get QE of given PMT.
 
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.
 
Auxiliary interface for direct access of elements in ROOT TChain.
 
Template definition for direct access of elements in ROOT TChain.
 
JDAQTimeslice & add(const JDAQTimeslice ×lice)
Add another timeslice.
 
Data structure for UTC time.
 
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
 
static const JEvtEvaluator getEvtValue
Function object for evaluation of DAQ objects.
 
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
Long64_t counter_type
Type definition for counter.
 
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
 
KM3NeT DAQ data structures and auxiliaries.
 
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.
 
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
 
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
 
double numberOfSeconds
Live time [s].
 
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 defining the range of iterations of objects.
 
static counter_type max()
Get maximum counter value.
 
Timeslice with Monte Carlo event.
 
Timeslice with random data.