Jpp  15.0.1-rc.1-highqe
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  cout.tie(&cerr);
80 
81 
83 
84  detector.push_back(getModule<JKM3NeT_t>(1001));
85 
87 
88  simbad.reset(new JPMTDefaultSimulator(pmtParameters, detector));
89  simbad.reset(new JCLBDefaultSimulator());
90  simbad.reset(k40Simulator.clone());
91 
92 
93  TFile out(outputFile.c_str(), "recreate");
94 
95  TProfile hn("hn", NULL, 31, 0.5, +31.5);
96  TProfile hc("hc", NULL, 21, -1.05, +1.05);
97  TProfile ht("ht", NULL, 20, 0.5, +20.5);
98 
99 
100  const JModuleRouter moduleRouter(detector);
101 
102  typedef double hit_type;
103  typedef vector <hit_type> JFrameL1_t;
104  typedef JSuperFrame2D<hit_type> JSuperFrame2D_t;
105  typedef JBuildL1 <hit_type> JBuildL1_t;
106 
107 
108  const JBuildL1_t buildL1(JBuildL1Parameters((hit_type) Tmax_ns, true));
109  JSuperFrame2D_t buffer;
110 
111 
112  for (int event_count = 0; event_count < numberOfEvents; ++event_count) {
113 
114  STATUS("event: " << setw(10) << event_count << '\r'); DEBUG(endl);
115 
116  const int frame_index = 1;
117 
118  const JDAQChronometer chronometer(detector.getID(), 1, event_count, JDAQUTCExtended(getTimeOfFrame(frame_index)));
119 
120  JRandomTimeslice timeslice(chronometer, simbad);
121 
122  for (JDAQTimeslice::const_iterator super_frame = timeslice.begin(); super_frame != timeslice.end(); ++super_frame) {
123 
124  if (moduleRouter.hasModule(super_frame->getModuleID())) {
125 
126  // calibration
127 
128  const JModule& module = detector.getModule(moduleRouter.getAddress(super_frame->getModuleID()));
129 
130  buffer(*super_frame, module);
131 
132  JFrameL1_t dataL1;
133 
134  buildL1(buffer, back_inserter(dataL1));
135 
136 
137  if (!dataL1.empty()) {
138 
139  JBuildL2<hit_type> buildL2(JL2Parameters(1, Tmax_ns, -1.0));
140 
141  JFrameL1_t d1(dataL1);
142  JFrameL1_t d2;
143 
144  for (int i = 1; i <= hn.GetNbinsX(); ++i) {
145 
146  buildL2.numberOfHits = (int) hn.GetBinCenter(i);
147 
148  d2.clear();
149 
150  buildL2(buffer, d1, back_inserter(d2));
151 
152  hn.Fill((double) buildL2.numberOfHits, (double) d2.size() / (double) dataL1.size());
153 
154  d1.swap(d2);
155  }
156  }
157 
158 
159  if (!dataL1.empty()) {
160 
161  JBuildL2<hit_type> buildL2(JL2Parameters(2, Tmax_ns, -1.0));
162 
163  JFrameL1_t d1(dataL1);
164  JFrameL1_t d2;
165 
166  for (int i = 1; i <= hc.GetNbinsX(); ++i) {
167 
168  buildL2.ctMin = hc.GetBinCenter(i);
169 
170  d2.clear();
171 
172  buildL2(buffer, d1, back_inserter(d2));
173 
174  hc.Fill(buildL2.ctMin, (double) d2.size() / (double) dataL1.size());
175 
176  d1.swap(d2);
177  }
178  }
179 
180 
181  if (!dataL1.empty()) {
182 
183  JBuildL2<hit_type> buildL2(JL2Parameters(2, 0.0, -1.0));
184 
185  JFrameL1_t d1(dataL1);
186  JFrameL1_t d2;
187 
188  for (int i = ht.GetNbinsX(); i != 0; --i) {
189 
190  buildL2.TMaxLocal_ns = ht.GetBinCenter(i);
191 
192  d2.clear();
193 
194  buildL2(buffer, d1, back_inserter(d2));
195 
196  ht.Fill(buildL2.TMaxLocal_ns, (double) d2.size() / (double) dataL1.size());
197 
198  d1.swap(d2);
199  }
200  }
201  }
202  }
203  }
204  NOTICE(endl);
205 
206  out.Write();
207  out.Close();
208 
209 }
210 
Utility class to parse command line options.
Definition: JParser.hh:1500
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:66
Auxiliary class to handle optional I/O.
Definition: JParser.hh:106
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:196
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:1961
#define NOTICE(A)
Definition: JMessage.hh:64
Auxiliary class for map of PMT parameters.
int debug
debug level
Definition: JSirene.cc:63
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.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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.