Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JVeto.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <vector>
6 #include <set>
7 
8 #include "evt/Head.hh"
9 #include "evt/Evt.hh"
10 #include "JDAQ/JDAQEvent.hh"
11 #include "JDAQ/JDAQTimeslice.hh"
12 #include "JDAQ/JDAQSummaryslice.hh"
13 
14 #include "JDetector/JDetector.hh"
17 
18 #include "JTrigger/JHit.hh"
19 #include "JTrigger/JFrame.hh"
20 #include "JTrigger/JTimeslice.hh"
21 #include "JTrigger/JHitL0.hh"
22 #include "JTrigger/JHitL1.hh"
23 #include "JTrigger/JHitR1.hh"
24 #include "JTrigger/JBuildL0.hh"
26 
30 #include "JSupport/JSupport.hh"
31 #include "JSupport/JMeta.hh"
32 
33 #include "JFit/JLine1Z.hh"
34 #include "JFit/JFitToolkit.hh"
35 #include "JFit/JFitParameters.hh"
36 #include "JFit/JTimeRange.hh"
37 #include "JFit/JEvt.hh"
38 #include "JFit/JEvtToolkit.hh"
39 
40 #include "Jeep/JParser.hh"
41 #include "Jeep/JMessage.hh"
42 
43 
44 /**
45  * \file
46  *
47  * Program to determine veto of muon trajectory.
48  * \author mdejong
49  */
50 int main(int argc, char **argv)
51 {
52  using namespace std;
53  using namespace JPP;
54  using namespace KM3NETDAQ;
55 
56  typedef vector<JTimeRange> JVeto_t;
57  typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
58  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
60 
61  JParallelFileScanner_t inputFile;
62  JFileRecorder<typelist> outputFile;
63  JLimit_t& numberOfEvents = inputFile.getLimit();
64  string detectorFile;
65  double roadWidth_m;
66  double R_Hz;
67  size_t numberOfPrefits;
68  JVeto_t veto;
69  bool reprocess;
70  int debug;
71 
72  try {
73 
74  JParser<> zap("Program to determine veto of muon trajectory.");
75 
76  zap['f'] = make_field(inputFile);
77  zap['o'] = make_field(outputFile) = "veto.root";
78  zap['a'] = make_field(detectorFile);
79  zap['n'] = make_field(numberOfEvents) = JLimit::max();
80  zap['R'] = make_field(roadWidth_m) = numeric_limits<double>::max();
81  zap['B'] = make_field(R_Hz) = 6.0e3;
82  zap['N'] = make_field(numberOfPrefits) = 1;
83  zap['V'] = make_field(veto);
84  zap['r'] = make_field(reprocess);
85  zap['d'] = make_field(debug) = 1;
86 
87  zap(argc, argv);
88  }
89  catch(const exception& error) {
90  FATAL(error.what() << endl);
91  }
92 
93 
94  cout.tie(&cerr);
95 
96  JDetector detector;
97 
98  try {
99  load(detectorFile, detector);
100  }
101  catch(const JException& error) {
102  FATAL(error);
103  }
104 
105  const JModuleRouter moduleRouter(detector);
106 
107  typedef vector<JHitL0> JDataL0_t;
108  const JBuildL0<JHitL0> buildL0;
109 
110  double VS = 0.0; // veto [s]
111 
112  for (vector<JTimeRange>::const_iterator vs = veto.begin(); vs != veto.end(); ++vs) {
113  VS += vs->getLength() * 1.0e-9;
114  }
115 
116 
117  outputFile.open();
118 
119  outputFile.put(JMeta(argc, argv));
120 
121  while (inputFile.hasNext()) {
122 
123  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
124 
125  multi_pointer_type ps = inputFile.next();
126 
127  JDAQEvent* tev = ps;
128  JEvt* evt = ps;
129  JEvt out = *evt;
130 
131  JEvt::iterator __end = evt->end();
132 
133  if (reprocess) {
134  __end = partition(evt->begin(), __end, JHistory::is_not_event(JMUONVETO));
135  }
136 
137  if (evt->begin() != __end) {
138 
139  copy(evt->begin(), __end, back_inserter(out));
140 
141  if (numberOfPrefits > 0) {
142  advance(__end = evt->begin(), min(numberOfPrefits, out.size()));
143  }
144 
145  partial_sort(evt->begin(), __end, evt->end(), qualitySorter);
146 
147  __end = partition(evt->begin(), __end, JHistory::is_event(evt->begin()->getHistory()));
148 
149 
150  JDataL0_t dataL0;
151 
152  buildL0(*tev, moduleRouter, true, back_inserter(dataL0));
153 
154 
155  for (JEvt::iterator track = evt->begin(); track != __end; ++track) {
156 
157  const JRotation3D R (getDirection(*track));
158  const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
159 
160  // hit selection based on start value
161 
163 
164  for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
165 
166  JHitL0 hit(*i);
167 
168  hit.rotate(R);
169 
170  bool is_veto = false;
171 
172  if (tz.getDistance(hit) <= roadWidth_m) {
173 
174  const double t1 = hit.getT() - tz.getT(hit);
175 
176  for (vector<JTimeRange>::const_iterator vs = veto.begin(); vs != veto.end() && !is_veto; ++vs) {
177  is_veto = (*vs)(t1);
178  }
179  }
180 
181  if (is_veto) {
182  top.insert(hit.getPMTIdentifier());
183  }
184  }
185 
186 
187  double npe = 0.0;
188  int count = 0;
189 
190  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
191 
192  JPosition3D pos(module->getPosition());
193 
194  pos.rotate(R);
195 
196  if (tz.getDistance(pos) <= roadWidth_m) {
197 
198  for (unsigned int i = 0; i != module->size(); ++i) {
199 
200  const JDAQPMTIdentifier id(module->getID(), i);
201 
202  npe += R_Hz * VS;
203  count += top.count(id);
204  }
205  }
206  }
207 
208  out.push_back(JFit(*track).add(JMUONVETO));
209 
210  out.rbegin()->setW(JVETO_NPE, npe);
211  out.rbegin()->setW(JVETO_NUMBER_OF_HITS, count);
212  }
213 
214  // apply default sorter
215 
216  sort(out.begin(), out.end(), qualitySorter);
217  }
218 
219  outputFile.put(out);
220  }
221  STATUS(endl);
222 
223  JSingleFileScanner<JRemove<typelist, JEvt>::typelist> io(inputFile);
224 
225  io >> outputFile;
226 
227  outputFile.close();
228 }
Auxiliary methods to evaluate Poisson probabilities and chi2.
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
Utility class to parse command line options.
Definition: JParser.hh:1410
number of photo-electrons from JVeto.cc
#define STATUS(A)
Definition: JMessage.hh:61
Recording of objects on file according a format that follows from the file name extension.
string outputFile
Data structure for detector geometry and calibration.
number of hits from JVeto.cc
Basic data structure for L0 hit.
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:214
Definition of fit parameters from various applications.
Basic data structure for time and time over threshold information of hit.
Type list.
Definition: JTypeList.hh:22
const_iterator< T > end() const
Get end of data.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
Parallel scanning of objects from a single file or multiple files according a format that follows fro...
ROOT I/O of application specific meta data.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:59
General purpose messaging.
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
Definition: JCounter.hh:35
#define FATAL(A)
Definition: JMessage.hh:65
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Direct access to module in detector data structure.
Reduced data structure for L1 hit.
Utility class to parse command line options.
ROOT TTree parameter settings.
bool qualitySorter(const JFIT::JFit &first, const JFIT::JFit &second)
Comparison of fit results.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:40
JDirection3D getDirection(const Vec &v)
Get direction.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:72
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:185
Basic data structure for L1 hit.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
JPosition3D getPosition(const Vec &v)
Get position.
int main(int argc, char *argv[])
Definition: Main.cpp:15