Jpp
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 
10 #include "JDAQ/JDAQEventIO.hh"
11 #include "JDAQ/JDAQTimesliceIO.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;
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 
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(track->getW());
211  out.rbegin()->setW(JVETO_NPE, npe);
212  out.rbegin()->setW(JVETO_NUMBER_OF_HITS, count);
213  }
214 
215  // apply default sorter
216 
217  sort(out.begin(), out.end(), qualitySorter);
218  }
219 
220  outputFile.put(out);
221  }
222  STATUS(endl);
223 
225 
226  io >> outputFile;
227 
228  outputFile.close();
229 }
JMeta.hh
Head.hh
KM3NETDAQ::JDAQEvent
DAQ Event.
Definition: JDAQEvent.hh:30
JTriggerParameters.hh
JFileRecorder.hh
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
JMessage.hh
JROOT::advance
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
JFitToolkit.hh
qualitySorter
bool qualitySorter(const JFIT::JFit &first, const JFIT::JFit &second)
Comparison of fit results.
Definition: quality_sorter.cc:10
JFIT::JFit::add
JFit & add(const int type)
Add event to history.
Definition: JEvt.hh:136
JTimeslice.hh
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
JEvtToolkit.hh
Evt.hh
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JFIT::JEvt
Data structure for set of track fit results.
Definition: JEvt.hh:293
JAANET::copy
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:152
JGEOMETRY3D::JPosition3D::rotate
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:185
KM3NETDAQ::JDAQPMTIdentifier::getPMTIdentifier
const JDAQPMTIdentifier & getPMTIdentifier() const
Get PMT identifier.
Definition: JDAQPMTIdentifier.hh:56
JTRIGGER::JHit::getT
double getT() const
Get calibrated time of hit.
Definition: JHit.hh:143
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JEvt.hh
JBuildL0.hh
JDAQEventIO.hh
JDAQTimesliceIO.hh
debug
int debug
debug level
Definition: JSirene.cc:59
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JSUPPORT::JLimit::getLimit
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
std::multiset
Definition: JSTDTypes.hh:14
JHit.hh
JMUONVETO
static const int JMUONVETO
Definition: reconstruction.hh:39
JModuleRouter.hh
JFIT::JHistory::is_event
Auxiliary class to test history.
Definition: JHistory.hh:101
JGEOMETRY3D::JAxis3D::rotate
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition: JAxis3D.hh:236
JParallelFileScanner.hh
JHitR1.hh
JMultipleFileScanner.hh
JTimeRange.hh
JLANG::JTypeList
Type list.
Definition: JTypeList.hh:22
main
int main(int argc, char **argv)
Definition: JVeto.cc:50
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JParser.hh
JDetectorToolkit.hh
JFIT::JLine1Z
Data structure for fit of straight line paralel to z-axis.
Definition: JLine1Z.hh:27
JFIT::JHistory::is_not_event
Auxiliary class to test history.
Definition: JHistory.hh:149
JDETECTOR::JModuleRouter
Router for direct addressing of module data in detector data structure.
Definition: JModuleRouter.hh:34
JHitL1.hh
JAANET::getDirection
JDirection3D getDirection(const Vec &v)
Get direction.
Definition: JAAnetToolkit.hh:221
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JFitParameters.hh
JSUPPORT::JParallelFileScanner
General purpose class for parallel reading of objects from a single file or multiple files.
Definition: JParallelFileScanner.hh:31
KM3NETDAQ::JDAQPMTIdentifier
PMT identifier.
Definition: JDAQPMTIdentifier.hh:20
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JAANET::getPosition
JPosition3D getPosition(const Vec &v)
Get position.
Definition: JAAnetToolkit.hh:197
JTRIGGER::JHitL0
Data structure for L0 hit.
Definition: JHitL0.hh:27
JAANET::detector
Detector file.
Definition: JHead.hh:130
JSUPPORT::JMeta
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
JDAQSummarysliceIO.hh
JVETO_NPE
static const int JVETO_NPE
number of photo-electrons from JVeto.cc
Definition: fitparameters.hh:23
JTRIGGER::JBuildL0< JHitL0 >
Template specialisation of L0 builder for JHitL0 data type.
Definition: JBuildL0.hh:101
JDetector.hh
JHitL0.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JVETO_NUMBER_OF_HITS
static const int JVETO_NUMBER_OF_HITS
number of hits from JVeto.cc
Definition: fitparameters.hh:24
JSUPPORT::JFileRecorder
Object writing to file.
Definition: JFileRecorder.hh:41
JLANG::JException
General exception.
Definition: JException.hh:23
JGEOMETRY3D::JRotation3D
Rotation matrix.
Definition: JRotation3D.hh:111
JSUPPORT::JSingleFileScanner
Object reading from a list of files.
Definition: JSingleFileScanner.hh:75
JFrame.hh
JLine1Z.hh
JFIT::JFit
Data structure for track fit results.
Definition: JEvt.hh:31