Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JRandomL1.cc File Reference

Example program to test JTRIGGER::JBuildL1 and JTRIGGER::JBuildL2 hit coincidence building with random data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TProfile.h"
#include "TRandom3.h"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorSupportkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JDetectorSimulator.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JK40DefaultSimulator.hh"
#include "JDetector/JPMTDefaultSimulator.hh"
#include "JDetector/JCLBDefaultSimulator.hh"
#include "JTrigger/JHit.hh"
#include "JTrigger/JFrame.hh"
#include "JTrigger/JTimeslice.hh"
#include "JTrigger/JSuperFrame2D.hh"
#include "JTrigger/JHitL0.hh"
#include "JTrigger/JHitL1.hh"
#include "JTrigger/JBuildL1.hh"
#include "JTrigger/JBuildL2.hh"
#include "JTimeslice/JRandomTimeslice.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test JTRIGGER::JBuildL1 and JTRIGGER::JBuildL2 hit coincidence building with random data.

Author
mdejong

Definition in file JRandomL1.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 43 of file JRandomL1.cc.

44 {
45  using namespace std;
46  using namespace JPP;
47 
48  typedef JOption<JK40DefaultSimulator> JK40DefaultSimulator_t;
49 
50  string outputFile;
51  Long64_t numberOfEvents;
52  JPMTParametersMap pmtParameters;
53  JK40DefaultSimulator_t k40Simulator = JK40DefaultSimulator::getInstance();
54  UInt_t seed;
55  double Tmax_ns;
56  int debug;
57 
58  try {
59 
60  JParser<> zap("Example program to test hit coincidence building with random data.");
61 
62  zap['o'] = make_field(outputFile) = "randomL2.root";
63  zap['n'] = make_field(numberOfEvents);
64  zap['P'] = make_field(pmtParameters) = JPARSER::initialised();
65  zap['B'] = make_field(k40Simulator) = JPARSER::initialised();
66  zap['S'] = make_field(seed) = 0;
67  zap['T'] = make_field(Tmax_ns) = 20.0; // [ns]
68  zap['d'] = make_field(debug) = 0;
69 
70  zap(argc, argv);
71  }
72  catch(const exception &error) {
73  FATAL(error.what() << endl);
74  }
75 
76  gRandom->SetSeed(seed);
77 
78  using namespace KM3NETDAQ;
79 
80 
82 
83  detector.push_back(getModule<JKM3NeT_t>(1001));
84 
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;
102  typedef vector <hit_type> JFrameL1_t;
103  typedef JSuperFrame2D<hit_type> JSuperFrame2D_t;
104  typedef JBuildL1 <hit_type> JBuildL1_t;
105 
106 
107  const JBuildL1_t buildL1(JBuildL1Parameters((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(JL2Parameters(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(JL2Parameters(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(JL2Parameters(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 }
Utility class to parse command line options.
Definition: JParser.hh:1514
Data structure for a composite optical module.
Definition: JModule.hh:67
#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
string outputFile
Data structure for UTC time.
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
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.
Template L1 hit builder.
Definition: JBuildL1.hh:85
#define FATAL(A)
Definition: JMessage.hh:67
Data structure for L2 parameters.
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.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62