Jpp  18.0.0-rc.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRandomL1.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <vector>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TProfile.h"
10 #include "TRandom3.h"
11 
12 #include "JDetector/JDetector.hh"
20 
21 #include "JTrigger/JHit.hh"
22 #include "JTrigger/JFrame.hh"
23 #include "JTrigger/JTimeslice.hh"
25 #include "JTrigger/JHitL0.hh"
26 #include "JTrigger/JHitL1.hh"
27 #include "JTrigger/JBuildL1.hh"
28 #include "JTrigger/JBuildL2.hh"
29 
31 
32 #include "Jeep/JParser.hh"
33 #include "Jeep/JMessage.hh"
34 
35 
36 /**
37  * \file
38  *
39  * Example program to test JTRIGGER::JBuildL1 and JTRIGGER::JBuildL2 hit coincidence building with random data.
40  * \author mdejong
41  */
42 int main(int argc, char **argv)
43 {
44  using namespace std;
45  using namespace JPP;
46 
47  typedef JOption<JK40DefaultSimulator> JK40DefaultSimulator_t;
48 
49  string outputFile;
50  Long64_t numberOfEvents;
51  JPMTParametersMap pmtParameters;
52  JK40DefaultSimulator_t k40Simulator = JK40DefaultSimulator::getInstance();
53  UInt_t seed;
54  double Tmax_ns;
55  int debug;
56 
57  try {
58 
59  JParser<> zap("Example program to test hit coincidence building with random data.");
60 
61  zap['o'] = make_field(outputFile) = "randomL2.root";
62  zap['n'] = make_field(numberOfEvents);
63  zap['P'] = make_field(pmtParameters) = JPARSER::initialised();
64  zap['B'] = make_field(k40Simulator) = JPARSER::initialised();
65  zap['S'] = make_field(seed) = 0;
66  zap['T'] = make_field(Tmax_ns) = 20.0; // [ns]
67  zap['d'] = make_field(debug) = 0;
68 
69  zap(argc, argv);
70  }
71  catch(const exception &error) {
72  FATAL(error.what() << endl);
73  }
74 
75  gRandom->SetSeed(seed);
76 
77  using namespace KM3NETDAQ;
78 
79 
81 
82  detector.push_back(getModule<JKM3NeT_t>(1001));
83 
85 
86  simbad.reset(new JPMTDefaultSimulator(pmtParameters, detector));
87  simbad.reset(new JCLBDefaultSimulator());
88  simbad.reset(k40Simulator.clone());
89 
90 
91  TFile out(outputFile.c_str(), "recreate");
92 
93  TProfile hn("hn", NULL, 31, 0.5, +31.5);
94  TProfile hc("hc", NULL, 21, -1.05, +1.05);
95  TProfile ht("ht", NULL, 20, 0.5, +20.5);
96 
97 
98  const JModuleRouter moduleRouter(detector);
99 
100  typedef double hit_type;
101  typedef vector <hit_type> JFrameL1_t;
102  typedef JSuperFrame2D<hit_type> JSuperFrame2D_t;
103  typedef JBuildL1 <hit_type> JBuildL1_t;
104 
105 
106  const JBuildL1_t buildL1(JBuildL1Parameters((hit_type) Tmax_ns, true));
107  JSuperFrame2D_t buffer;
108 
109 
110  for (int event_count = 0; event_count < numberOfEvents; ++event_count) {
111 
112  STATUS("event: " << setw(10) << event_count << '\r'); DEBUG(endl);
113 
114  const int frame_index = 1;
115 
116  const JDAQChronometer chronometer(detector.getID(), 1, event_count, JDAQUTCExtended(getTimeOfFrame(frame_index)));
117 
118  JRandomTimeslice timeslice(chronometer, simbad);
119 
120  for (JDAQTimeslice::const_iterator super_frame = timeslice.begin(); super_frame != timeslice.end(); ++super_frame) {
121 
122  if (moduleRouter.hasModule(super_frame->getModuleID())) {
123 
124  // calibration
125 
126  const JModule& module = detector.getModule(moduleRouter.getAddress(super_frame->getModuleID()));
127 
128  buffer(*super_frame, module);
129 
130  JFrameL1_t dataL1;
131 
132  buildL1(buffer, back_inserter(dataL1));
133 
134 
135  if (!dataL1.empty()) {
136 
137  JBuildL2<hit_type> buildL2(JL2Parameters(1, Tmax_ns, -1.0));
138 
139  JFrameL1_t d1(dataL1);
140  JFrameL1_t d2;
141 
142  for (int i = 1; i <= hn.GetNbinsX(); ++i) {
143 
144  buildL2.numberOfHits = (int) hn.GetBinCenter(i);
145 
146  d2.clear();
147 
148  buildL2(buffer, d1, back_inserter(d2));
149 
150  hn.Fill((double) buildL2.numberOfHits, (double) d2.size() / (double) dataL1.size());
151 
152  d1.swap(d2);
153  }
154  }
155 
156 
157  if (!dataL1.empty()) {
158 
159  JBuildL2<hit_type> buildL2(JL2Parameters(2, Tmax_ns, -1.0));
160 
161  JFrameL1_t d1(dataL1);
162  JFrameL1_t d2;
163 
164  for (int i = 1; i <= hc.GetNbinsX(); ++i) {
165 
166  buildL2.ctMin = hc.GetBinCenter(i);
167 
168  d2.clear();
169 
170  buildL2(buffer, d1, back_inserter(d2));
171 
172  hc.Fill(buildL2.ctMin, (double) d2.size() / (double) dataL1.size());
173 
174  d1.swap(d2);
175  }
176  }
177 
178 
179  if (!dataL1.empty()) {
180 
181  JBuildL2<hit_type> buildL2(JL2Parameters(2, 0.0, -1.0));
182 
183  JFrameL1_t d1(dataL1);
184  JFrameL1_t d2;
185 
186  for (int i = ht.GetNbinsX(); i != 0; --i) {
187 
188  buildL2.TMaxLocal_ns = ht.GetBinCenter(i);
189 
190  d2.clear();
191 
192  buildL2(buffer, d1, back_inserter(d2));
193 
194  ht.Fill(buildL2.TMaxLocal_ns, (double) d2.size() / (double) dataL1.size());
195 
196  d1.swap(d2);
197  }
198  }
199  }
200  }
201  }
202  NOTICE(endl);
203 
204  out.Write();
205  out.Close();
206 
207 }
208 
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
Data structure for a composite optical module.
Definition: JModule.hh:68
double ctMin
minimal cosine space angle between PMT axes
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
Auxiliary class to handle optional I/O.
Definition: JParser.hh:123
Basic data structure for time and time over threshold information of hit.
string outputFile
Data structure for UTC time.
Data structure for detector geometry and calibration.
int numberOfHits
minimal number of hits
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
Basic data structure for L0 hit.
Template L2 builder.
Definition: JBuildL2.hh:45
Detector file.
Definition: JHead.hh:226
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define NOTICE(A)
Definition: JMessage.hh:64
Auxiliary class for map of PMT parameters.
General purpose messaging.
Template L1 hit builder.
Definition: JBuildL1.hh:85
#define FATAL(A)
Definition: JMessage.hh:67
void reset(JK40Simulator *k40Simulator)
Reset K40 simulator.
Direct access to module in detector data structure.
Data structure for L2 parameters.
Utility class to parse command line options.
const JModuleAddress & getAddress(const JObjectID &id) const
Get address of module.
double TMaxLocal_ns
maximal time difference [ns]
bool hasModule(const JObjectID &id) const
Has module.
Auxiliary data structure for L1 build parameters.
Definition: JBuildL1.hh:37
2-dimensional frame with time calibrated data from one optical module.
do set_variable DETECTOR_TXT $WORKDIR detector
Timeslice with random data.
Basic data structure for L1 hit.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62