Jpp
JSignalL1.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 
14 #include "JDAQ/JDAQTimesliceIO.hh"
15 
16 #include "JAAnet/JAAnetToolkit.hh"
18 
19 #include "JDetector/JDetector.hh"
26 
27 #include "JTrigger/JHit.hh"
28 #include "JTrigger/JFrame.hh"
29 #include "JTrigger/JTimeslice.hh"
31 #include "JTrigger/JHitL0.hh"
32 #include "JTrigger/JHitL1.hh"
33 #include "JTrigger/JBuildL1.hh"
34 #include "JTrigger/JBuildL2.hh"
35 
38 #include "JSupport/JSupport.hh"
39 
40 #include "Jeep/JParser.hh"
41 #include "Jeep/JMessage.hh"
42 
43 
44 /**
45  * \file
46  *
47  * Example program to test JTRIGGER::JBuildL1 and JTRIGGER::JBuildL2 hit coincidence building with Monte Carlo events.
48  * \author mdejong
49  */
50 int main(int argc, char **argv)
51 {
52  using namespace std;
53  using namespace JPP;
54 
55  JMultipleFileScanner<Evt> inputFile;
56  JLimit_t& numberOfEvents = inputFile.getLimit();
57  string outputFile;
58  string detectorFile;
59  JPMTParametersMap pmtParameters;
60  double Tmax_ns;
61  int debug;
62 
63  try {
64 
65  JParser<> zap("Example program to test hit coincidence building with Monte Carlo events.");
66 
67  zap['f'] = make_field(inputFile);
68  zap['o'] = make_field(outputFile) = "buildL2.root";
69  zap['n'] = make_field(numberOfEvents) = JLimit::max();
70  zap['a'] = make_field(detectorFile);
71  zap['P'] = make_field(pmtParameters) = JPARSER::initialised();
72  zap['T'] = make_field(Tmax_ns) = 20.0; // [ns]
73  zap['d'] = make_field(debug) = 0;
74 
75  zap(argc, argv);
76  }
77  catch(const exception &error) {
78  FATAL(error.what() << endl);
79  }
80 
81 
82  using namespace KM3NETDAQ;
83 
84  cout.tie(&cerr);
85 
86 
88 
89  try {
90  load(detectorFile, detector);
91  }
92  catch(const JException& error) {
93  FATAL(error);
94  }
95 
97 
98  simbad.reset(new JPMTDefaultSimulator(pmtParameters, detector));
99  simbad.reset(new JCLBDefaultSimulator());
100 
101 
102  TFile out(outputFile.c_str(), "recreate");
103 
104  TProfile hn("hn", NULL, 31, 0.5, +31.5);
105  TProfile hc("hc", NULL, 21, -1.05, +1.05);
106  TProfile ht("ht", NULL, 20, 0.5, +20.5);
107 
108 
109  const JModuleRouter moduleRouter(detector);
110 
111  typedef double hit_type;
112  typedef vector <hit_type> JFrameL1_t;
113  typedef JSuperFrame2D<hit_type> JSuperFrame2D_t;
114  typedef JBuildL1 <hit_type> JBuildL1_t;
115 
116 
117  const JBuildL1_t buildL1(JBuildL1Parameters((hit_type) Tmax_ns, true));
118  JSuperFrame2D_t buffer;
119 
120 
121  for (JMultipleFileScanner<Evt>& in = inputFile; in.hasNext(); ) {
122 
123  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
124 
125  Evt* event = in.next();
126 
127  const int frame_index = 1;
128 
129  event->mc_t = 0.5 * getFrameTime();
130 
131  const JDAQChronometer chronometer(detector.getID(), 1, frame_index, JDAQUTCExtended(getTimeOfFrame(frame_index)));
132 
133  JEventTimeslice timeslice(chronometer, simbad, *event);
134 
135  for (JDAQTimeslice::const_iterator super_frame = timeslice.begin(); super_frame != timeslice.end(); ++super_frame) {
136 
137  if (moduleRouter.hasModule(super_frame->getModuleID())) {
138 
139  // calibration
140 
141  const JModule& module = detector.getModule(moduleRouter.getAddress(super_frame->getModuleID()));
142 
143  buffer(*super_frame, module);
144 
145  JFrameL1_t dataL1;
146 
147  buildL1(buffer, back_inserter(dataL1));
148 
149  if (!dataL1.empty()) {
150 
151  JBuildL2<hit_type> buildL2(JL2Parameters(1, Tmax_ns, -1.0));
152 
153  JFrameL1_t d1(dataL1);
154  JFrameL1_t d2;
155 
156  for (int i = 1; i <= hn.GetNbinsX(); ++i) {
157 
158  buildL2.numberOfHits = (int) hn.GetBinCenter(i);
159 
160  d2.clear();
161 
162  buildL2(buffer, d1, back_inserter(d2));
163 
164  hn.Fill((double) buildL2.numberOfHits, (double) d2.size() / (double) dataL1.size());
165 
166  d1.swap(d2);
167  }
168  }
169 
170 
171  if (!dataL1.empty()) {
172 
173  JBuildL2<hit_type> buildL2(JL2Parameters(2, Tmax_ns, -1.0));
174 
175  JFrameL1_t d1(dataL1);
176  JFrameL1_t d2;
177 
178  for (int i = 1; i <= hc.GetNbinsX(); ++i) {
179 
180  buildL2.ctMin = hc.GetBinCenter(i);
181 
182  d2.clear();
183 
184  buildL2(buffer, d1, back_inserter(d2));
185 
186  hc.Fill(buildL2.ctMin, (double) d2.size() / (double) dataL1.size());
187 
188  d1.swap(d2);
189  }
190  }
191 
192 
193  if (!dataL1.empty()) {
194 
195  JBuildL2<hit_type> buildL2(JL2Parameters(2, 0.0, -1.0));
196 
197  JFrameL1_t d1(dataL1);
198  JFrameL1_t d2;
199 
200  for (int i = ht.GetNbinsX(); i != 0; --i) {
201 
202  buildL2.TMaxLocal_ns = ht.GetBinCenter(i);
203 
204  d2.clear();
205 
206  buildL2(buffer, d1, back_inserter(d2));
207 
208  ht.Fill(buildL2.TMaxLocal_ns, (double) d2.size() / (double) dataL1.size());
209 
210  d1.swap(d2);
211  }
212  }
213  }
214  }
215  }
216  NOTICE(endl);
217 
218  out.Write();
219  out.Close();
220 }
JPMTParametersMap.hh
Head.hh
KM3NETDAQ::JEventTimeslice
Timeslice with Monte Carlo event.
Definition: JEventTimeslice.hh:33
JSuperFrame2D.hh
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
JMessage.hh
JTRIGGER::JL2Parameters
Data structure for L2 parameters.
Definition: JTriggerParameters.hh:33
JDETECTOR::JCLBDefaultSimulator
Default CLB simulation.
Definition: JCLBDefaultSimulator.hh:139
KM3NETDAQ::JDAQUTCExtended
Data structure for UTC time.
Definition: JDAQUTCExtended.hh:22
JTRIGGER::JL2Parameters::numberOfHits
int numberOfHits
minimal number of hits
Definition: JTriggerParameters.hh:107
JTimeslice.hh
JTRIGGER::JBuildL1
Template L1 hit builder.
Definition: JBuildL1.hh:85
JPARSER::initialised
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:63
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:476
std::vector
Definition: JSTDTypes.hh:12
Evt
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
Evt.hh
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
KM3NETDAQ::getFrameTime
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JBuildL1.hh
JTRIGGER::JL2Parameters::ctMin
double ctMin
minimal cosine space angle between PMT axes
Definition: JTriggerParameters.hh:109
Hit.hh
JDetectorSimulator.hh
JTRIGGER::JBuildL1Parameters
Auxiliary data structure for L1 build parameters.
Definition: JBuildL1.hh:37
JDAQTimesliceIO.hh
JCLBDefaultSimulator.hh
debug
int debug
debug level
Definition: JSirene.cc:59
JAAnetToolkit.hh
JHit.hh
JDETECTOR::JPMTParametersMap
Auxiliary class for map of PMT parameters.
Definition: JPMTParametersMap.hh:88
JModuleRouter.hh
JDETECTOR::JModule
Data structure for a composite optical module.
Definition: JModule.hh:49
JMultipleFileScanner.hh
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JSUPPORT::JMultipleFileScanner::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JMultipleFileScanner.hh:350
JBuildL2.hh
JParser.hh
JDetectorToolkit.hh
JDETECTOR::JModuleRouter
Router for direct addressing of module data in detector data structure.
Definition: JModuleRouter.hh:34
JHitL1.hh
JDETECTOR::JPMTDefaultSimulator
Default PMT simulation.
Definition: JPMTDefaultSimulator.hh:54
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JSUPPORT::JMultipleFileScanner
General purpose class for object reading from a list of file names.
Definition: JMultipleFileScanner.hh:167
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JDETECTOR::JModuleRouter::getAddress
const JModuleAddress & getAddress(const JObjectID &id) const
Get address of module.
Definition: JModuleRouter.hh:77
JAANET::detector
Detector file.
Definition: JHead.hh:130
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JDETECTOR::JDetectorSimulator
Detector simulation.
Definition: JDetectorSimulator.hh:33
JDETECTOR::JModuleRouter::hasModule
bool hasModule(const JObjectID &id) const
Has module.
Definition: JModuleRouter.hh:101
JPMTDefaultSimulator.hh
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
main
int main(int argc, char **argv)
Definition: JSignalL1.cc:50
JEventTimeslice.hh
JMonteCarloFileSupportkit.hh
JDetector.hh
JHitL0.hh
JTRIGGER::JSuperFrame2D
2-dimensional frame with time calibrated data from one optical module.
Definition: JSuperFrame2D.hh:41
Evt::mc_t
double mc_t
MC: time of the mc event.
Definition: Evt.hh:43
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JLANG::JException
General exception.
Definition: JException.hh:23
JTRIGGER::JL2Parameters::TMaxLocal_ns
double TMaxLocal_ns
maximal time difference [ns]
Definition: JTriggerParameters.hh:108
JDETECTOR::JDetectorSimulator::reset
void reset(JK40Simulator *k40Simulator)
Reset K40 simulator.
Definition: JDetectorSimulator.hh:144
KM3NETDAQ::getTimeOfFrame
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
JFrame.hh
KM3NETDAQ::JDAQChronometer
DAQ chronometer.
Definition: JDAQChronometer.hh:21
JTRIGGER::JBuildL2
Template L2 builder.
Definition: JBuildL2.hh:45