45 int main(
int argc,
char **argv)
52 JMultipleFileScanner<JAAnetTypes_t> inputFile;
53 JFileRecorder <JTYPELIST<JAAnetTypes_t, JDAQTimesliceL0, JMeta, JRootTypes_t>::typelist>
outputFile;
57 JPMTParametersMap pmtParameters;
65 JParser<> zap(
"Auxiliary program to convert multiple Monte Carlo events to time slices.");
69 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
80 catch(
const exception &error) {
81 FATAL(error.what() << endl);
84 gRandom->SetSeed(seed);
90 if (pmtParameters.getQE() != 1.0) {
92 WARNING(
"Correct background rates with global efficiency " << pmtParameters.getQE() << endl);
94 rates_Hz.correct(pmtParameters.getQE());
99 DEBUG(
"PMT paramaters: " << endl << pmtParameters << endl);
100 DEBUG(
"K40 rates: " << endl << rates_Hz << endl);
102 if (eventRate_Hz < 0.0) {
103 FATAL(
"Invalid event rate " << eventRate_Hz <<
"; consider using JRandomTimesliceWriter." << endl);
111 load(detectorFile, detector);
113 catch(
const JException& error) {
125 FATAL(
"MC header is invalid");
130 if (liveTimeMC < 0) {
131 FATAL(
"MC live time is negative; input file may be corrupted.");
136 JPMTParametersMap::Throw(
false);
138 JDetectorSimulator simbad(detector);
140 simbad.reset(
new JPMTDefaultSimulator(pmtParameters, detector));
141 simbad.reset(
new JK40DefaultSimulator(rates_Hz));
142 simbad.reset(
new JCLBDefaultSimulator());
156 bool absTime =
false;
158 JTreeScannerInterface<Evt>* scan;
160 if (eventRate_Hz == 0.0 && liveTimeMC == 0.0) {
162 NOTICE(
"Event will be timed according to absolute MC time." << endl);
167 scan =
new JTreeScanner<Evt, JEvtEvaluator>(inputFile);
173 scan =
new JTreeScanner<Evt>(inputFile);
176 if (eventRate_Hz == 0.0 && liveTimeMC > 0.0) {
177 int nEntries = scan->getEntries();
178 eventRate_Hz = nEntries / liveTimeMC;
179 DEBUG(nEntries <<
" events to be written." << endl);
180 NOTICE(
"MC live time is " << liveTimeMC <<
" s" << endl);
181 NOTICE(
"Event rate set to " << eventRate_Hz <<
" Hz from MC header." << endl);
188 bool pendingEvt =
false;
189 bool pendingTimeslice =
false;
203 while (pendingEvt || scan->hasNext()) {
205 if (!pendingTimeslice) {
210 DEBUG(
"evt count: " << setw(10) << evtCount << endl);
211 STATUS(
"frame index: " << setw(10) << frame_index <<
" | evt count: " << setw(10) << evtCount <<
"\r");
DEBUG(endl);
212 pendingTimeslice =
true;
217 event = scan->next();
219 tOff = timeRange.is_valid() ? timeRange.getLowerLimit() : 0;
224 tDAQ += gRandom->Exp(1.0e9 / eventRate_Hz);
226 DEBUG(
"event time [s] " << setprecision(5) << tDAQ * 1.0e-9 << endl);
234 if (timeRange.is_valid()) {
235 DEBUG(*event << endl);
237 event->mc_t = tDAQ - tOff;
246 DEBUG(timeslice << endl);
248 pendingTimeslice =
false;
253 if (pendingTimeslice) {
254 DEBUG(timeslice << endl);
256 pendingTimeslice =
false;
264 NOTICE(evtCount <<
" events written over " << frame_index <<
" timeslices. " << endl);