Jpp  18.6.0-rc.1
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"
21 
22 #include "JTrigger/JHit.hh"
23 #include "JTrigger/JFrame.hh"
24 #include "JTrigger/JTimeslice.hh"
26 #include "JTrigger/JHitL0.hh"
27 #include "JTrigger/JHitL1.hh"
28 #include "JTrigger/JBuildL1.hh"
29 #include "JTrigger/JBuildL2.hh"
30 
32 
33 #include "Jeep/JParser.hh"
34 #include "Jeep/JMessage.hh"
35 
36 namespace {
37 
39 
40  /**
41  * Auxiliary data structure for I/O of K40 simulation parameters.
42  */
43  struct JK40DefaultSimulator_t :
45  {
46  /**
47  * Default constructor.
48  */
49  JK40DefaultSimulator_t() :
51  status(false)
52  {}
53 
54 
55  /**
56  * Read object from input.
57  *
58  * \param in input stream
59  * \param object object
60  * \return input stream
61  */
62  friend inline std::istream& operator>>(std::istream& in, JK40DefaultSimulator_t& object)
63  {
64  object.status = true;
65 
66  return in >> static_cast<JK40DefaultSimulator&>(object);
67  }
68 
69 
70  /**
71  * Get clone of this object.
72  *
73  * \return pointer to newly created object if status is okay; else NULL
74  */
75  JK40DefaultSimulator* clone() const
76  {
77  if (status)
78  return new JK40DefaultSimulator(*this);
79  else
80  return NULL;
81  }
82 
83  bool status;
84  };
85 }
86 
87 
88 /**
89  * \file
90  *
91  * Example program to test JTRIGGER::JBuildL1 and JTRIGGER::JBuildL2 hit coincidence building with random data.
92  * \author mdejong
93  */
94 int main(int argc, char **argv)
95 {
96  using namespace std;
97  using namespace JPP;
98 
99  string outputFile;
100  Long64_t numberOfEvents;
101  JPMTParametersMap pmtParameters;
102  JK40DefaultSimulator_t k40Simulator;
103  UInt_t seed;
104  double Tmax_ns;
105  int debug;
106 
107  try {
108 
109  JParser<> zap("Example program to test hit coincidence building with random data.");
110 
111  zap['o'] = make_field(outputFile) = "randomL2.root";
112  zap['n'] = make_field(numberOfEvents);
113  zap['P'] = make_field(pmtParameters) = JPARSER::initialised();
114  zap['B'] = make_field(k40Simulator) = JPARSER::initialised();
115  zap['S'] = make_field(seed) = 0;
116  zap['T'] = make_field(Tmax_ns) = 20.0; // [ns]
117  zap['d'] = make_field(debug) = 0;
118 
119  zap(argc, argv);
120  }
121  catch(const exception &error) {
122  FATAL(error.what() << endl);
123  }
124 
125  gRandom->SetSeed(seed);
126 
127  using namespace KM3NETDAQ;
128 
129 
131 
132  detector.push_back(getModule<JKM3NeT_t>(1001));
133 
135 
136  simbad.reset(new JPMTDefaultSimulator(pmtParameters, detector));
137  simbad.reset(new JCLBDefaultSimulator());
138  simbad.reset(k40Simulator.clone());
139 
140 
141  TFile out(outputFile.c_str(), "recreate");
142 
143  TProfile hn("hn", NULL, 31, 0.5, +31.5);
144  TProfile hc("hc", NULL, 21, -1.05, +1.05);
145  TProfile ht("ht", NULL, 20, 0.5, +20.5);
146 
147 
148  const JModuleRouter moduleRouter(detector);
149 
150  typedef double hit_type;
151  typedef vector <hit_type> JFrameL1_t;
152  typedef JSuperFrame2D<hit_type> JSuperFrame2D_t;
153  typedef JBuildL1 <hit_type> JBuildL1_t;
154 
155 
156  const JBuildL1_t buildL1(JBuildL1Parameters((hit_type) Tmax_ns, true));
157  JSuperFrame2D_t buffer;
158 
159 
160  for (int event_count = 0; event_count < numberOfEvents; ++event_count) {
161 
162  STATUS("event: " << setw(10) << event_count << '\r'); DEBUG(endl);
163 
164  const int frame_index = 1;
165 
166  const JDAQChronometer chronometer(detector.getID(), 1, event_count, JDAQUTCExtended(getTimeOfFrame(frame_index)));
167 
168  JRandomTimeslice timeslice(chronometer, simbad);
169 
170  for (JDAQTimeslice::const_iterator super_frame = timeslice.begin(); super_frame != timeslice.end(); ++super_frame) {
171 
172  if (moduleRouter.hasModule(super_frame->getModuleID())) {
173 
174  // calibration
175 
176  const JModule& module = detector.getModule(moduleRouter.getAddress(super_frame->getModuleID()));
177 
178  buffer(*super_frame, module);
179 
180  JFrameL1_t dataL1;
181 
182  buildL1(buffer, back_inserter(dataL1));
183 
184 
185  if (!dataL1.empty()) {
186 
187  JBuildL2<hit_type> buildL2(JL2Parameters(1, Tmax_ns, -1.0));
188 
189  JFrameL1_t d1(dataL1);
190  JFrameL1_t d2;
191 
192  for (int i = 1; i <= hn.GetNbinsX(); ++i) {
193 
194  buildL2.numberOfHits = (int) hn.GetBinCenter(i);
195 
196  d2.clear();
197 
198  buildL2(buffer, d1, back_inserter(d2));
199 
200  hn.Fill((double) buildL2.numberOfHits, (double) d2.size() / (double) dataL1.size());
201 
202  d1.swap(d2);
203  }
204  }
205 
206 
207  if (!dataL1.empty()) {
208 
209  JBuildL2<hit_type> buildL2(JL2Parameters(2, Tmax_ns, -1.0));
210 
211  JFrameL1_t d1(dataL1);
212  JFrameL1_t d2;
213 
214  for (int i = 1; i <= hc.GetNbinsX(); ++i) {
215 
216  buildL2.ctMin = hc.GetBinCenter(i);
217 
218  d2.clear();
219 
220  buildL2(buffer, d1, back_inserter(d2));
221 
222  hc.Fill(buildL2.ctMin, (double) d2.size() / (double) dataL1.size());
223 
224  d1.swap(d2);
225  }
226  }
227 
228 
229  if (!dataL1.empty()) {
230 
231  JBuildL2<hit_type> buildL2(JL2Parameters(2, 0.0, -1.0));
232 
233  JFrameL1_t d1(dataL1);
234  JFrameL1_t d2;
235 
236  for (int i = ht.GetNbinsX(); i != 0; --i) {
237 
238  buildL2.TMaxLocal_ns = ht.GetBinCenter(i);
239 
240  d2.clear();
241 
242  buildL2(buffer, d1, back_inserter(d2));
243 
244  ht.Fill(buildL2.TMaxLocal_ns, (double) d2.size() / (double) dataL1.size());
245 
246  d1.swap(d2);
247  }
248  }
249  }
250  }
251  }
252  NOTICE(endl);
253 
254  out.Write();
255  out.Close();
256 
257 }
258 
Utility class to parse command line options.
Definition: JParser.hh:1711
int main(int argc, char *argv[])
Definition: Main.cc:15
Default implementation of the simulation of K40 background.
Data structure for a composite optical module.
Definition: JModule.hh:67
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:84
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.
JK40DefaultSimulator()
Default constructor.
Template L2 builder.
Definition: JBuildL2.hh:45
Detector file.
Definition: JHead.hh:226
Detector support kit.
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:2158
#define NOTICE(A)
Definition: JMessage.hh:64
Auxiliary class for map of PMT parameters.
General purpose messaging.
friend std::istream & operator>>(std::istream &in, JK40DefaultSimulator &object)
Read K40 simulator from input.
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.
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
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