Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
15 #include "JDAQ/JDAQClock.hh"
17 
19 #include "JSupport/JSupport.hh"
20 #include "JSupport/JMeta.hh"
21 
22 #include "Jeep/JTimer.hh"
23 #include "Jeep/JParser.hh"
24 #include "Jeep/JMessage.hh"
25 
26 
27 /**
28  * \file
29  *
30  * Auxiliary program to write KM3NETDAQ::JDAQTimeslice with random data.
31  * \author mdejong
32  */
33 int main(int argc, char **argv)
34 {
35  using namespace std;
36  using namespace JPP;
37  using namespace KM3NETDAQ;
38 
39  JFileRecorder<JTYPELIST<JDAQTimeslice, JMeta, JRootTypes_t>::typelist> outputFile;
40  string detectorFile;
41  Long64_t numberOfEvents;
42  JDAQHit::JTDC_t TCLB_ns;
43  JPMTParametersMap pmtParameters;
44  JK40Rates rates_Hz;
45  int run;
46  UInt_t seed;
47  int debug;
48 
49  try {
50 
51  JParser<> zap("Auxiliary program to write time slices with random data.");
52 
53  zap['o'] = make_field(outputFile) = "timeslice.root";
54  zap['a'] = make_field(detectorFile);
55  zap['n'] = make_field(numberOfEvents) = 0;
56  zap['T'] = make_field(TCLB_ns) = 256; // [ns]
57  zap['P'] = make_field(pmtParameters) = JPARSER::initialised();
58  zap['B'] = make_field(rates_Hz) = JPARSER::initialised();
59  zap['R'] = make_field(run) = 1;
60  zap['S'] = make_field(seed) = 0;
61  zap['d'] = make_field(debug) = 0;
62 
63  zap(argc, argv);
64  }
65  catch(const exception &error) {
66  FATAL(error.what() << endl);
67  }
68 
69 
70  gRandom->SetSeed(seed);
71 
72 
73  cout.tie(&cerr);
74 
76 
77  if (pmtParameters.getQE() != 1.0) {
78 
79  WARNING("Correct background rates with global efficiency " << pmtParameters.getQE() << endl);
80 
81  rates_Hz.correct(pmtParameters.getQE());
82  }
83 
84  DEBUG("PMT parameters: " << endl << pmtParameters << endl);
85  DEBUG("K40 rates: " << endl << rates_Hz << endl);
86 
87  JDetector detector;
88 
89  try {
90  load(detectorFile, detector);
91  }
92  catch(const JException& error) {
93  FATAL(error);
94  }
95 
96  JPMTParametersMap::Throw(false);
97 
98  JDetectorSimulator simbad(detector);
99 
100  simbad.reset(new JPMTDefaultSimulator(pmtParameters, detector));
101  simbad.reset(new JK40DefaultSimulator(rates_Hz));
102  simbad.reset(new JCLBDefaultSimulator(TCLB_ns));
103 
104 
105  JTimer timerco("constructor");;
106  JTimer timerIO("I/O");
107 
108  outputFile.open();
109 
110  if (!outputFile.is_open()) {
111  FATAL("Error opening file " << outputFile << endl);
112  }
113 
114  outputFile.put(*gRandom);
115  outputFile.put(JMeta(argc, argv));
116 
117  int frame_index = 1;
118 
119  for ( ; frame_index <= numberOfEvents; ++frame_index) {
120 
121  STATUS("event: " << setw(10) << frame_index << '\r'); DEBUG(endl);
122 
123  JDAQUTCExtended timeOfFrame;
124 
125  timeOfFrame.setTimeNanoSecond(getTimeOfFrame(frame_index));
126 
127  const JDAQChronometer chronometer(detector.getID(), run, frame_index, timeOfFrame);
128 
129  timerco.start();
130 
131  JRandomTimeslice timeslice(chronometer, simbad);
132 
133  timerco.stop();
134 
135  timerIO.start();
136 
137  outputFile.put(timeslice);
138 
139  timerIO.stop();
140  }
141  STATUS(endl);
142 
143  if (debug >= debug_t) {
144 
145  const double factor = 1.0 / (double) (frame_index - 1);
146 
147  timerco.print(cout, factor);
148  timerIO.print(cout, factor);
149  }
150 
151  outputFile.put(*gRandom);
152  outputFile.close();
153 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
Timeslice with random data.
Utility class to parse command line options.
Definition: JParser.hh:1410
#define WARNING(A)
Definition: JMessage.hh:63
debug
Definition: JMessage.hh:27
#define STATUS(A)
Definition: JMessage.hh:61
Recording of objects on file according a format that follows from the file name extension.
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:64
string outputFile
Data structure for UTC time.
Data structure for detector geometry and calibration.
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:41
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
void setDAQLongprint(const bool option)
Set DAQ print option.
Definition: JDAQPrint.hh:28
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
ROOT I/O of application specific meta data.
void setTimeNanoSecond(const double utc_ns)
Set time.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:59
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:65
Utility class to parse command line options.
ROOT TTree parameter settings.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
int main(int argc, char *argv[])
Definition: Main.cpp:15