Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
software/JTimeslice/JRandomTimesliceWriter.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <fstream>
5
6#include "TRandom3.h"
7
10
11#include "JAAnet/JHead.hh"
13
21
25
29
31#include "JSupport/JMeta.hh"
32#include "JSupport/JSupport.hh"
34#include "JSupport/JRunByRun.hh"
35
36#include "JROOT/JRandom.hh"
37
38#include "Jeep/JTimer.hh"
39#include "Jeep/JParser.hh"
40#include "Jeep/JMessage.hh"
41
42
43/**
44 * \file
45 *
46 * Auxiliary program to write KM3NETDAQ::JDAQTimeslice with random data.\n
47 * To pipe data to application JTriggerProcessor.cc whilst maintaining header and meta data, two output files can be specified.\n
48 * The file names should have extensions ".root" and ".dat", respectively. \n
49 * The first corresponds to a ROOT formatted file with header and meta data and the second to the pipe with timeslice data.
50 * \author mdejong
51 */
52int main(int argc, char **argv)
53{
54 using namespace std;
55 using namespace JPP;
56 using namespace KM3NETDAQ;
57
59
61 string detectorFile;
62 Long64_t numberOfSlices;
63 JDAQHit::JTDC_t TCLB_ns;
64 JPMTParametersMap pmtParameters;
65 JK40Rates rates_Hz;
66 int run;
67 JRunByRun runbyrun;
68 pair<size_t, double> recycling;
69 double sigma_ns;
70 bool fast;
71 JRandom seed;
72 int debug;
73
74 try {
75
76 JParser<> zap("Auxiliary program to write time slices with random data.");
77
78 zap['o'] = make_field(outputFile, "output file");
79 zap['n'] = make_field(numberOfSlices);
80 zap['a'] = make_field(detectorFile, "detector.");
81 zap['R'] = make_field(run, "run number") = -1;
82 zap['r'] = make_field(runbyrun, "option for run-by-run mode") = JPARSER::initialised();
83 zap['P'] = make_field(pmtParameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
84 zap['B'] = make_field(rates_Hz, "background rates [Hz]") = JPARSER::initialised();
85 zap['T'] = make_field(TCLB_ns, "CLB state-machine time jitter") = 256; // [ns]
86 zap['N'] = make_field(recycling, "number of recycles / time interval for sampling data [ns]") = make_pair(0, 0.0);
87 zap['s'] = make_field(sigma_ns, "intrinsic time smearing of K40 coincidences [ns]") = JK40DefaultSimulatorInterface::getSigma();
88 zap['F'] = make_field(fast, "fast - disable PMT simulation");
89 zap['S'] = make_field(seed, "seed") = 0;
90 zap['d'] = make_field(debug, "debug") = 0;
91
92 zap(argc, argv);
93 }
94 catch(const exception &error) {
95 FATAL(error.what() << endl);
96 }
97
98
99 if (outputFile.size() != 1 &&
100 outputFile.size() != 2) {
101 FATAL("Invalid number of output files; should be 1 or 2." << endl);
102 }
103
104 seed.set(gRandom);
105
107
108
110
111 if (pmtParameters.getQE() != 1.0) {
112
113 WARNING("Correct background rates with global efficiency " << pmtParameters.getQE() << endl);
114
115 rates_Hz.correct(pmtParameters.getQE());
116 }
117
118 DEBUG("PMT parameters: " << endl << pmtParameters << endl);
119 DEBUG("K40 rates: " << endl << rates_Hz << endl);
120
122
123 try {
124 load(detectorFile, detector);
125 }
126 catch(const JException& error) {
127 FATAL(error);
128 }
129
131
133 JSummaryRouter summaryRouter;
134
135 if (runbyrun.is_valid()) {
136
137 NOTICE("Using run-by-run:" << endl << runbyrun << endl);
138
139 if (!runbyrun.hasNext()) {
140 FATAL("Run-by-run simulation yields no input." << endl);
141 }
142
143 if (rates_Hz.getSinglesRate() != 0.0) {
144 WARNING("Run-by-run simulation discards singles rate [Hz] " << rates_Hz.getSinglesRate() << endl);
145 }
146
147 try {
148 simbad.reset(new JK40RunByRunSimulator(summaryRouter, rates_Hz));
149 simbad.reset(new JPMTDefaultSimulator(pmtParameters, detector));
150 simbad.reset(new JCLBDefaultSimulator());
151 }
152 catch(const JException& error) {
153 FATAL(error.what() << endl);
154 }
155
156 } else {
157
158 NOTICE("Using fixed rates [Hz]: " << rates_Hz << endl);
159
160 try {
161 simbad.reset(new JK40DefaultSimulator(rates_Hz));
162 simbad.reset(fast ?
164 new JPMTDefaultSimulator(pmtParameters, detector));
165 simbad.reset(new JCLBDefaultSimulator());
166 }
167 catch(const JException& error) {
168 FATAL(error.what() << endl);
169 }
170 }
171
172
173 JTimer timerco("constructor");
174 JTimer timerrc("recycle");
175 JTimer timerIO("I/O");
176
177 for (size_t i = 0; i != outputFile.size(); ++i) {
178
179 outputFile[i].open();
180
181 if (!outputFile[i].is_open()) {
182 FATAL("Error opening file " << outputFile[i] << endl);
183 }
184 }
185
186 outputFile[0].put(JMeta(argc, argv));
187 outputFile[0].put(*gRandom);
188
189 int counter = 0;
190
191 for ( ; counter != numberOfSlices; ) {
192
193 STATUS("slice: " << setw(10) << counter << '\r'); DEBUG(endl);
194
195 int frame_index = counter + 1;
196
197 if (runbyrun.hasNext()) {
198
199 summaryRouter.update(runbyrun.next());
200
201 summaryRouter.correct(dynamic_cast<const JPMTDefaultSimulatorInterface&>(simbad.getPMTSimulator()));
202
203 frame_index = summaryRouter.getFrameIndex();
204 run = summaryRouter.getRunNumber();
205 }
206
207 JDAQUTCExtended utc(JDAQUTCExtended::getInstance().getTimeNanoSecond() +
208 getTimeOfFrame(frame_index)); // ensure incremental UTC times (e.g. for JDAQSplit.cc)
209
210 const JDAQChronometer chronometer(detector.getID(), run, frame_index, utc);
211
212 timerco.start();
213
214 JRandomTimeslice timeslice(chronometer, simbad);
215
216 timerco.stop();
217
218 timerIO.start();
219
220 outputFile.rbegin()->put(timeslice); ++counter;
221
222 timerIO.stop();
223
224 for (size_t i = 1; i <= recycling.first && counter != numberOfSlices; ++i) {
225
226 STATUS("slice: " << setw(10) << counter << '\r'); DEBUG(endl);
227
228 timerrc.start();
229
230 timeslice.recycle(recycling.second);
231
232 timerrc.stop();
233
234 timerIO.start();
235
236 outputFile.rbegin()->put(timeslice); ++counter;
237
238 timerIO.stop();
239 }
240 }
241 STATUS(endl);
242
243 if (debug >= notice_t) {
244 timerco.print(cout, true);
245 timerrc.print(cout, true);
246 timerIO.print(cout, true);
247 }
248
249 Head header;
250
251 {
252 JHead buffer;
253
254 buffer.DAQ.livetime_s = getLivetime(runbyrun->getFilelist());
255 buffer.K40.livetime_s = counter * getFrameTime() * 1.0e-9;
256
257 buffer.push(&JHead::DAQ);
258 buffer.push(&JHead::K40);
259
260 copy(buffer, header);
261 }
262
263 outputFile[0].put(header);
264 outputFile[0].put(*gRandom);
265
266 for (size_t i = 0; i != outputFile.size(); ++i) {
267 outputFile[i].close();
268 }
269}
string outputFile
Data structure for detector geometry and calibration.
Recording of objects on file according a format that follows from the file name extension.
General purpose messaging.
#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
ROOT I/O of application specific meta data.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Support methods.
ROOT TTree parameter settings of various packages.
Monte Carlo run header.
Definition JHead.hh:1236
JAANET::DAQ DAQ
Definition JHead.hh:1607
void push(T JHead::*pd)
Push given data member to Head.
Definition JHead.hh:1374
JAANET::K40 K40
Definition JHead.hh:1608
void reset(JK40Simulator *k40Simulator)
Reset K40 simulator.
const JPMTSimulator & getPMTSimulator() const
Get PMT simulator.
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
void print(std::ostream &out, const JScale_t scale=milli_t) const
Print timer data.
Definition JTimer.hh:172
void stop()
Stop timer.
Definition JTimer.hh:127
void start()
Start timer.
Definition JTimer.hh:106
General exception.
Definition JException.hh:24
virtual const char * what() const override
Get error message.
Definition JException.hh:64
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
static void Throw(const bool option)
Enable/disable throw option.
Definition JThrow.hh:37
Utility class to parse command line options.
Definition JParser.hh:1698
Object writing to file.
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
void update(const JDAQSummaryslice *ps)
Update router.
K40 simulation based on run-by-run information.
unsigned int JTDC_t
leading edge [ns]
Definition JDAQHit.hh:39
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
double getTimeOfFrame(const int frame_index)
Get start time of frame in ns since start of run for a given frame index.
Definition JDAQClock.hh:185
int main(int argc, char **argv)
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
double getSinglesRate() const
Get singles rate.
Definition JK40Rates.hh:71
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
bool is_valid() const
Check validity of run by run options.
Definition JRunByRun.hh:48
Timeslice with random data.
void recycle(const double T_ns)
Recycle time slice by randomly shuffling time intervals of data.