Jpp
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 
8 #include "JDetector/JDetector.hh"
17 #include "JDAQ/JDAQClock.hh"
18 #include "JDAQ/JDAQSummaryslice.hh"
19 #include "JDAQ/JDAQTimeslice.hh"
22 #include "JTrigger/JRunByRun.hh"
25 #include "JSupport/JSupport.hh"
26 #include "JSupport/JMeta.hh"
27 
28 #include "Jeep/JTimer.hh"
29 #include "Jeep/JParser.hh"
30 #include "Jeep/JMessage.hh"
31 
32 
33 /**
34  * \file
35  *
36  * Auxiliary program to write KM3NETDAQ::JDAQTimeslice with random data.
37  * \author mdejong
38  */
39 int main(int argc, char **argv)
40 {
41  using namespace std;
42  using namespace JPP;
43  using namespace KM3NETDAQ;
44 
45  JFileRecorder<JTYPELIST<JDAQTimesliceL0, JMeta, JRootTypes_t>::typelist> outputFile;
46  string detectorFile;
47  Long64_t numberOfEvents;
48  JDAQHit::JTDC_t TCLB_ns;
49  JPMTParametersMap pmtParameters;
50  JK40Rates rates_Hz;
51  int run;
52  JRunByRun runbyrun;
53  UInt_t seed;
54  int debug;
55 
56  try {
57 
58  JParser<> zap("Auxiliary program to write time slices with random data.");
59 
60  zap['o'] = make_field(outputFile, "output file") = "timeslice.root";
61  zap['n'] = make_field(numberOfEvents) = JLimit::max();
62  zap['a'] = make_field(detectorFile, "detecto.");
63  zap['R'] = make_field(run, "run number") = -1;
64  zap['r'] = make_field(runbyrun, "option for run-by-run mode") = JPARSER::initialised();
65  zap['P'] = make_field(pmtParameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
66  zap['B'] = make_field(rates_Hz, "background rates [Hz]") = JPARSER::initialised();
67  zap['T'] = make_field(TCLB_ns) = 256; // [ns]
68  zap['S'] = make_field(seed, "seed") = 0;
69  zap['d'] = make_field(debug, "debug") = 0;
70 
71  zap(argc, argv);
72  }
73  catch(const exception &error) {
74  FATAL(error.what() << endl);
75  }
76 
77 
78  gRandom->SetSeed(seed);
79 
80 
81  cout.tie(&cerr);
82 
84 
85  if (pmtParameters.getQE() != 1.0) {
86 
87  WARNING("Correct background rates with global efficiency " << pmtParameters.getQE() << endl);
88 
89  rates_Hz.correct(pmtParameters.getQE());
90  }
91 
92  DEBUG("PMT parameters: " << endl << pmtParameters << endl);
93  DEBUG("K40 rates: " << endl << rates_Hz << endl);
94 
95  JDetector detector;
96 
97  try {
98  load(detectorFile, detector);
99  }
100  catch(const JException& error) {
101  FATAL(error);
102  }
103 
104  JPMTParametersMap::Throw(false);
105 
106  JDetectorSimulator simbad(detector);
107  JSummaryRouter summaryRouter;
108 
109  if (runbyrun.is_valid()) {
110 
111  NOTICE("Using run-by-run:" << endl << runbyrun << endl);
112 
113  if (!runbyrun.hasNext()) {
114  FATAL("Run-by-run simulation yields no input." << endl);
115  }
116 
117  if (rates_Hz.getSinglesRate() != 0.0) {
118  WARNING("Run-by-run simulation discards singles rate [Hz] " << rates_Hz.getSinglesRate() << endl);
119  }
120 
121  try {
122  simbad.reset(new JK40RunByRunSimulator(summaryRouter, rates_Hz));
123  simbad.reset(new JPMTRunByRunSimulator(summaryRouter, pmtParameters, detector, runbyrun.range_Hz));
124  simbad.reset(new JCLBDefaultSimulator());
125  }
126  catch(const JException& error) {
127  FATAL(error.what() << endl);
128  }
129 
130  } else {
131 
132  NOTICE("Using fixed rates [Hz]: " << rates_Hz << endl);
133 
134  try {
135  simbad.reset(new JK40DefaultSimulator(rates_Hz));
136  simbad.reset(new JPMTDefaultSimulator(pmtParameters, detector));
137  simbad.reset(new JCLBDefaultSimulator());
138  }
139  catch(const JException& error) {
140  FATAL(error.what() << endl);
141  }
142  }
143 
144 
145  JTimer timerco("constructor");
146  JTimer timerIO("I/O");
147 
148 
149  outputFile.open();
150 
151  if (!outputFile.is_open()) {
152  FATAL("Error opening file " << outputFile << endl);
153  }
154 
155  outputFile.put(*gRandom);
156  outputFile.put(JMeta(argc, argv));
157 
158  int count = 1;
159 
160  for ( ; count <= numberOfEvents; ++count) {
161 
162  STATUS("event: " << setw(10) << count << '\r'); DEBUG(endl);
163 
164  int frame_index = count;
165 
166  if (runbyrun.hasNext()) {
167 
168  summaryRouter.update(runbyrun.next());
169 
170  summaryRouter.correct(dynamic_cast<const JPMTDefaultSimulatorInterface&>(simbad.getPMTSimulator()));
171 
172  frame_index = summaryRouter.getFrameIndex();
173  run = summaryRouter.getRunNumber();
174  }
175 
176  const JDAQChronometer chronometer(detector.getID(), run, frame_index, JDAQUTCExtended(getTimeOfFrame(frame_index)));
177 
178  timerco.start();
179 
180  JRandomTimeslice timeslice(chronometer, simbad);
181 
182  timerco.stop();
183 
184  timerIO.start();
185 
186  outputFile.put(timeslice);
187 
188  timerIO.stop();
189  }
190  STATUS(endl);
191 
192  if (debug >= debug_t && count > 1) {
193 
194  const double factor = 1.0 / (double) (count - 1);
195 
196  timerco.print(cout, factor);
197  timerIO.print(cout, factor);
198  }
199 
200  outputFile.put(*gRandom);
201  outputFile.close();
202 }
JPMTParametersMap.hh
JMeta.hh
JK40DefaultSimulator.hh
JSingleFileScanner.hh
JFileRecorder.hh
JRunByRun.hh
JMessage.hh
KM3NETDAQ::JDAQUTCExtended
Data structure for UTC time.
Definition: JDAQUTCExtended.hh:27
JK40RunByRunSimulator.hh
main
int main(int argc, char **argv)
Definition: JRandomTimesliceWriter.cc:39
JRandomTimeslice.hh
JPARSER::initialised
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:63
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JDAQClock.hh
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JDAQTimeslice.hh
JDAQSummaryslice.hh
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JPMTRunByRunSimulator.hh
JDetectorSimulator.hh
WARNING
#define WARNING(A)
Definition: JMessage.hh:65
JCLBDefaultSimulator.hh
debug
int debug
debug level
Definition: JSirene.cc:59
KM3NETDAQ::JRandomTimeslice
Timeslice with random data.
Definition: JRandomTimeslice.hh:29
JSummaryRouter.hh
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JParser.hh
JDetectorToolkit.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
KM3NETDAQ::JDAQHit::JTDC_t
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:45
JSUPPORT::JMeta
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JPMTDefaultSimulator.hh
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
JTimer.hh
KM3NETDAQ::setDAQLongprint
void setDAQLongprint(const bool option)
Set DAQ print option.
Definition: JDAQPrint.hh:28
JDetector.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JEEP::debug_t
debug
Definition: JMessage.hh:29
KM3NETDAQ::getTimeOfFrame
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
KM3NETDAQ::JDAQChronometer
DAQ chronometer.
Definition: JDAQChronometer.hh:26