Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
Functions
JRandomTimesliceWriter.cc File Reference

Auxiliary program to write KM3NETDAQ::JDAQTimeslice with random data. More...

#include <string>
#include <iostream>
#include <fstream>
#include "TRandom3.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/online/JDAQClock.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JK40DefaultSimulator.hh"
#include "JDetector/JPMTDefaultSimulator.hh"
#include "JDetector/JCLBDefaultSimulator.hh"
#include "JDetector/JDetectorSimulator.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JTimeslice/JRandomTimeslice.hh"
#include "JTrigger/JSummaryRouter.hh"
#include "JTrigger/JK40RunByRunSimulator.hh"
#include "JTrigger/JPMTRunByRunSimulator.hh"
#include "JTrigger/JCLBRunByRunSimulator.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JSupportToolkit.hh"
#include "JSupport/JRunByRun.hh"
#include "JROOT/JRandom.hh"
#include "Jeep/JTimer.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to write KM3NETDAQ::JDAQTimeslice with random data.


To pipe data to application JTriggerProcessor.cc whilst maintaining header and meta data, two output files can be specified.
The file names should have extensions ".root" and ".dat", respectively.
The first corresponds to a ROOT formatted file with header and meta data and the second to the pipe with timeslice data.

Author
mdejong

Definition in file software/JTimeslice/JRandomTimesliceWriter.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 53 of file software/JTimeslice/JRandomTimesliceWriter.cc.

54{
55 using namespace std;
56 using namespace JPP;
57 using namespace KM3NETDAQ;
58
60
62 string detectorFile;
63 Long64_t numberOfSlices;
65 JPMTParametersMap pmtParameters;
66 JK40Rates rates_Hz;
67 int run;
70 double sigma_ns;
71 bool fast;
73 int debug;
74
75 try {
76
77 JParser<> zap("Auxiliary program to write time slices with random data.");
78
79 zap['o'] = make_field(outputFile, "output file");
80 zap['n'] = make_field(numberOfSlices);
81 zap['a'] = make_field(detectorFile, "detector.");
82 zap['R'] = make_field(run, "run number") = -1;
83 zap['r'] = make_field(runbyrun, "option for run-by-run mode") = JPARSER::initialised();
84 zap['P'] = make_field(pmtParameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
85 zap['B'] = make_field(rates_Hz, "background rates [Hz]") = JPARSER::initialised();
86 zap['T'] = make_field(TCLB_ns, "CLB state-machine time jitter") = 256; // [ns]
87 zap['N'] = make_field(recycling, "number of recycles / time interval for sampling data [ns]") = make_pair(0, 0.0);
88 zap['s'] = make_field(sigma_ns, "intrinsic time smearing of K40 coincidences [ns]") = JK40DefaultSimulatorInterface::getSigma();
89 zap['F'] = make_field(fast, "fast - disable PMT simulation");
90 zap['S'] = make_field(seed, "seed") = 0;
91 zap['d'] = make_field(debug, "debug") = 0;
92
93 zap(argc, argv);
94 }
95 catch(const exception &error) {
96 FATAL(error.what() << endl);
97 }
98
99
100 if (outputFile.size() != 1 &&
101 outputFile.size() != 2) {
102 FATAL("Invalid number of output files; should be 1 or 2." << endl);
103 }
104
105 seed.set(gRandom);
106
108
109
111
112 if (pmtParameters.getQE() != 1.0) {
113
114 WARNING("Correct background rates with global efficiency " << pmtParameters.getQE() << endl);
115
116 rates_Hz.correct(pmtParameters.getQE());
117 }
118
119 DEBUG("PMT parameters: " << endl << pmtParameters << endl);
120 DEBUG("K40 rates: " << endl << rates_Hz << endl);
121
123
124 try {
126 }
127 catch(const JException& error) {
128 FATAL(error);
129 }
130
132
135
137
138 if (runbyrun.is_valid()) {
139
140 NOTICE("Using run-by-run:" << endl << runbyrun << endl);
141
142 if (!runbyrun.hasNext()) {
143 FATAL("Run-by-run simulation yields no input." << endl);
144 }
145
146 try {
147 simbad.reset(new JK40RunByRunSimulator(summaryRouter, rates_Hz));
148 simbad.reset(new JPMTDefaultSimulator(pmtParameters, detector));
150 }
151 catch(const JException& error) {
152 FATAL(error.what() << endl);
153 }
154
155 } else {
156
157 NOTICE("Using fixed rates [Hz]: " << rates_Hz << endl);
158
159 try {
160 simbad.reset(new JK40DefaultSimulator(rates_Hz));
161 simbad.reset(fast ?
163 new JPMTDefaultSimulator(pmtParameters, detector));
164 simbad.reset(new JCLBDefaultSimulator());
165 }
166 catch(const JException& error) {
167 FATAL(error.what() << endl);
168 }
169 }
170
171
172 JTimer timerco("constructor");
173 JTimer timerrc("recycle");
174 JTimer timerIO("I/O");
175
176 for (size_t i = 0; i != outputFile.size(); ++i) {
177
178 outputFile[i].open();
179
180 if (!outputFile[i].is_open()) {
181 FATAL("Error opening file " << outputFile[i] << endl);
182 }
183 }
184
185 outputFile[0].put(JMeta(argc, argv));
186 outputFile[0].put(*gRandom);
187
188 int counter = 0;
189
190 for ( ; counter != numberOfSlices; ) {
191
192 STATUS("slice: " << setw(10) << counter << '\r'); DEBUG(endl);
193
194 int frame_index = counter + 1;
195
196 JDAQUTCExtended utc(UTC.getTimeNanoSecond() + getTimeOfFrame(frame_index));
197
198 if (runbyrun.hasNext()) {
199
200 summaryRouter.update(runbyrun.next());
201
202 summaryRouter.correct(dynamic_cast<const JPMTDefaultSimulatorInterface&>(simbad.getPMTSimulator()));
203
204 run = summaryRouter.getRunNumber();
205 frame_index = summaryRouter.getFrameIndex();
206 utc = summaryRouter.getTimesliceStart();
207 }
208
209 const JDAQChronometer chronometer(detector.getID(), run, frame_index, utc);
210
211 timerco.start();
212
214
215 timerco.stop();
216
217 timerIO.start();
218
219 outputFile.rbegin()->put(timeslice); ++counter;
220
221 timerIO.stop();
222
223 for (size_t i = 1; i <= recycling.first && counter != numberOfSlices; ++i) {
224
225 STATUS("slice: " << setw(10) << counter << '\r'); DEBUG(endl);
226
227 timerrc.start();
228
229 timeslice.recycle(recycling.second);
230
231 timerrc.stop();
232
233 timerIO.start();
234
235 outputFile.rbegin()->put(timeslice); ++counter;
236
237 timerIO.stop();
238 }
239 }
240 STATUS(endl);
241
242 if (debug >= notice_t) {
243 timerco.print(cout, true);
244 timerrc.print(cout, true);
245 timerIO.print(cout, true);
246 }
247
248 Head header;
249
250 {
251 JHead buffer;
252
253 buffer.DAQ.livetime_s = getLivetime(runbyrun->getFilelist());
254 buffer.K40.livetime_s = counter * getFrameTime() * 1.0e-9;
255
256 buffer.push(&JHead::DAQ);
257 buffer.push(&JHead::K40);
258
259 copy(buffer, header);
260 }
261
262 outputFile[0].put(header);
263 outputFile[0].put(*gRandom);
264
265 for (size_t i = 0; i != outputFile.size(); ++i) {
266 outputFile[i].close();
267 }
268}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define WARNING(A)
Definition JMessage.hh:65
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Monte Carlo run header.
Definition JHead.hh:1236
JAANET::DAQ DAQ
Definition JHead.hh:1625
void push(T JHead::*pd)
Push given data member to Head.
Definition JHead.hh:1374
JAANET::K40 K40
Definition JHead.hh:1626
Detector data structure.
Definition JDetector.hh:96
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.
Auxiliary class for map of PMT parameters.
double getQE(const JPMTIdentifier &id) const
Get QE of given PMT.
Auxiliary class for CPU timing and usage.
Definition JTimer.hh:33
General exception.
Definition JException.hh:24
virtual const char * what() const override
Get error message.
Definition JException.hh:64
static void Throw(const bool option)
Enable/disable throw option.
Definition JThrow.hh:37
Template definition of a multi-dimensional oscillation probability interpolation table.
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
CLB simulation based on run-by-run information.
K40 simulation based on run-by-run information.
Data structure for UTC time.
static const JDAQUTCExtended & getInstance()
Get arbitrary offset (e.g.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
@ debug_t
debug
Definition JMessage.hh:29
@ notice_t
notice
Definition JMessage.hh:32
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getLivetime(const std::string &file_name)
Get data taking live time.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
double getFrameTime()
Get frame time duration.
Definition JDAQClock.hh:162
void setDAQLongprint(const bool option)
Set DAQ print option.
Definition JDAQPrint.hh:28
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition Head.hh:65
double livetime_s
Live time [s].
Definition JHead.hh:1053
double livetime_s
Live time [s].
Definition JHead.hh:1107
Detector file.
Definition JHead.hh:227
Template definition of random value generator.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary class for K40 rates.
Definition JK40Rates.hh:41
void correct(const double QE)
Correct rates for global efficiency,.
Definition JK40Rates.hh:130
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72
Auxiliary class to select summary data (KM3NETDAQ::JDAQSummaryslice) from the specified raw data file...
Definition JRunByRun.hh:34
Timeslice with random data.