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