47{
51
52
54 JFileRecorder <JTYPELIST<JAAnetTypes_t, JDAQTimesliceL0, JMeta, JRootTypes_t>::typelist>
outputFile;
55 JLimit_t& numberOfEvents = inputFile.getLimit();
56 string detectorFile;
57 int run;
60 double eventRate_Hz;
61 UInt_t seed;
63
64 try {
65
66 JParser<> zap(
"Auxiliary program to convert multiple Monte Carlo events to time slices.");
67
78
79 zap(argc, argv);
80 }
81 catch(const exception &error) {
82 FATAL(error.what() << endl);
83 }
84
85 gRandom->SetSeed(seed);
86
87
89
90 if (pmtParameters.
getQE() != 1.0) {
91
92 WARNING(
"Correct background rates with global efficiency " << pmtParameters.
getQE() << endl);
93
95 }
96
97
98
99 DEBUG(
"PMT paramaters: " << endl << pmtParameters << endl);
100 DEBUG(
"K40 rates: " << endl << rates_Hz << endl);
101
102 if (eventRate_Hz < 0.0) {
103 FATAL(
"Invalid event rate " << eventRate_Hz <<
"; consider using JRandomTimesliceWriter." << endl);
104 }
105
106
107
109
110 try {
112 }
115 }
116
117
118
120
121 try {
123 }
124 catch (const exception& error) {
125 FATAL(
"Monte Carlo header is invalid");
126 }
127
129
130 if (liveTimeMC < 0) {
131 FATAL(
"Monte Carlo live time is negative; input file may be corrupted.");
132 }
133
134
135
137
139
143
144
145
147
150 }
151
155
156
157
158 bool absTime = false;
159
161
162 if (eventRate_Hz == 0.0 && liveTimeMC == 0.0) {
163
164 NOTICE(
"Event will be timed according to absolute MC time." << endl);
165
166 absTime = true;
167
168
171
172 } else {
173
174
177
178 if (eventRate_Hz == 0.0 && liveTimeMC > 0.0) {
179 int nEntries = scan->getEntries();
180 eventRate_Hz = nEntries / liveTimeMC;
181 DEBUG(nEntries <<
" events to be written." << endl);
182 NOTICE(
"MC live time is " << liveTimeMC <<
" s" << endl);
183 NOTICE(
"Event rate set to " << eventRate_Hz <<
" Hz from MC header." << endl);
184 }
185 }
186
187
188
189
190 bool pendingEvt = false;
191 bool pendingTimeslice = false;
192
194
196 double tDAQ = 0;
197 double tOff = 0;
198
199 int frame_index = 0;
202
204
205 while (pendingEvt || scan->hasNext()) {
206
207 if (!pendingTimeslice) {
208
209 frame_index++;
212 DEBUG(
"evt count: " << setw(10) << evtCount << endl);
213 STATUS(
"frame index: " << setw(10) << frame_index <<
" | evt count: " << setw(10) << evtCount <<
"\r");
DEBUG(endl);
214 pendingTimeslice = true;
215 }
216
217 if (!pendingEvt) {
218
219 event = scan->next();
222
223 if (absTime)
225 else
226 tDAQ += gRandom->Exp(1.0e9 / eventRate_Hz);
227
228 DEBUG(
"event time [s] " << setprecision(5) << tDAQ * 1.0e-9 << endl);
229 pendingEvt = true;
230 }
231
232
233 if (getFrameIndex(tDAQ) == frame_index) {
234
235
237 DEBUG(*event << endl);
238
239 event->mc_t = tDAQ - tOff;
241 evtCount++;
242 }
243
245 pendingEvt = false;
246 } else {
247
248 DEBUG(timeslice << endl);
250 pendingTimeslice = false;
251 }
252
253 }
254
255 if (pendingTimeslice) {
256 DEBUG(timeslice << endl);
258 pendingTimeslice = false;
259 }
260
262
265
266 NOTICE(evtCount <<
" events written over " << frame_index <<
" timeslices. " << endl);
267}
#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].
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.