Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMuonStart.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 #include <algorithm>
8 #include <memory>
9 
13 #include "JDAQ/JDAQEventIO.hh"
14 #include "JDAQ/JDAQTimesliceIO.hh"
16 
17 #include "JDetector/JDetector.hh"
21 #include "JDetector/JK40Rates.hh"
22 
23 #include "JTrigger/JHit.hh"
24 #include "JTrigger/JHitR1.hh"
25 #include "JTrigger/JBuildL0.hh"
27 
31 #include "JSupport/JSupport.hh"
32 #include "JSupport/JMeta.hh"
33 
34 #include "JFit/JLine1Z.hh"
35 #include "JFit/JEnergyRegressor.hh"
36 #include "JFit/JFitToolkit.hh"
37 #include "JFit/JNPEHit.hh"
38 #include "JFit/JMEstimator.hh"
39 #include "JFit/JModel.hh"
40 
41 #include "JReconstruction/JEvt.hh"
45 
46 #include "JTools/JConstants.hh"
47 #include "JTools/JFunction1D_t.hh"
49 
50 #include "JPhysics/JPDFTable.hh"
51 #include "JPhysics/JPDFToolkit.hh"
52 #include "JPhysics/JNPETable.hh"
53 
54 #include "JLang/JComparator.hh"
55 
56 #include "Jeep/JPrint.hh"
57 #include "Jeep/JParser.hh"
58 #include "Jeep/JMessage.hh"
59 
60 
61 /**
62  * \file
63  *
64  * Program to determine start position of muon trajectory.
65  * \author mdejong
66  */
67 int main(int argc, char **argv)
68 {
69  using namespace std;
70  using namespace JPP;
71  using namespace KM3NETDAQ;
72 
73  typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
74  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
76 
77  JParallelFileScanner_t inputFile;
79  JLimit_t& numberOfEvents = inputFile.getLimit();
80  string detectorFile;
81  string pdfFile;
83  int debug;
84 
85  try {
86 
87  JParser<> zap("Program to perform PDF fit of muon trajectory to data.");
88 
89  zap['f'] = make_field(inputFile);
90  zap['o'] = make_field(outputFile) = "start.root";
91  zap['a'] = make_field(detectorFile);
92  zap['n'] = make_field(numberOfEvents) = JLimit::max();
93  zap['P'] = make_field(pdfFile);
95  zap['d'] = make_field(debug) = 1;
96 
97  zap(argc, argv);
98  }
99  catch(const exception& error) {
100  FATAL(error.what() << endl);
101  }
102 
103 
104  cout.tie(&cerr);
105 
106 
108 
109  try {
110  load(detectorFile, detector);
111  }
112  catch(const JException& error) {
113  FATAL(error);
114  }
115 
116  const JModuleRouter router(detector);
117 
118  typedef JHitR1 hit_type;
119 
120  typedef vector<hit_type> buffer_type;
121  const JBuildL0<hit_type> buildL0;
122 
123 
124  typedef JRegressor<JEnergy> JRegressor_t;
125 
127  JRegressor_t::T_ns.setRange(parameters.TMin_ns, parameters.TMax_ns);
128 
129  const JStart start(parameters.Pmin1, parameters.Pmin2);
130 
131  JRegressor_t fit(pdfFile);
132 
133  if (fit.getRmax() < parameters.roadWidth_m) {
134  parameters.roadWidth_m = fit.getRmax();
135  }
136 
137 
138  outputFile.open();
139 
140  outputFile.put(JMeta(argc, argv));
141 
142  while (inputFile.hasNext()) {
143 
144  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
145 
146  multi_pointer_type ps = inputFile.next();
147 
148  const JDAQEvent* tev = ps;
149  const JEvt* in = ps;
150 
151  // select start values
152 
153  JEvt cp = *in;
154  JEvt out;
155 
156  if (parameters.reprocess) {
158  }
159 
160  cp.select(parameters.numberOfPrefits, qualitySorter);
161 
162  if (!cp.empty()) {
163  cp.select(JHistory::is_event(cp.begin()->getHistory()));
164  }
165 
166 
167  buffer_type data;
168 
169  buildL0(*tev, router, true, back_inserter(data));
170 
171 
172  for (JEvt::iterator track = cp.begin(); track != cp.end(); ++track) {
173 
174  const JRotation3D R (getDirection(*track));
175  const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
176  const JModel<JLine1Z> match(tz, parameters.roadWidth_m, JRegressor_t::T_ns);
177 
178 
180 
181  for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
182 
183  hit_type hit(*i);
184 
185  hit.rotate(R);
186 
187  if (match(hit)) {
188  top.insert(hit.getModuleIdentifier());
189  }
190  }
191 
192  vector<JNPEHit> data;
193 
194  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
195 
196  const size_t count = top.count(i->getID());
197 
198  if (count != 0) {
199 
200  JPosition3D pos(i->getPosition());
201 
202  pos.transform(R, tz.getPosition());
203 
204  if (pos.getX() <= parameters.roadWidth_m) {
205 
206  JModule module = *i;
207 
208  module.transform(R, tz.getPosition());
209 
210  data.push_back(JNPEHit(fit.getNPE(module, parameters.R_Hz), count));
211  }
212  }
213  }
214 
215 
216  double Zmin = 0.0; // relative start position [m]
217  double Zmax = 0.0; // relative end position [m]
218  double npe = 0.0; // npe due to mip up to barycenter of hits
219  double npe_total = 0.0; // npe due to mip up to end of track
220 
221 
222  if (!data.empty()) {
223 
224  sort(data.begin(), data.end(), make_comparator(&JNPEHit::getZ));
225 
226  vector<JNPEHit>::const_iterator track_start = start.find(data. begin(), data. end());
227  vector<JNPEHit>::const_reverse_iterator track_end = start.find(data.rbegin(), data.rend());
228 
229  if (track_start == data. end()) { track_start = data. begin(); }
230  if (track_end == data.rend()) { track_end = data.rbegin(); }
231 
232  Zmin = track_start->getZ();
233  Zmax = track_end ->getZ();
234 
235  for (vector<JNPEHit>::const_iterator i = track_start; i != track_end.base(); ++i) {
236 
237  if (i->getZ() <= 0.0) {
238  npe += i->getYA();
239  }
240 
241  npe_total += i->getYA();
242  }
243 
244  DEBUG("vertex " << FIXED(6,1) << track->getW(JCOPY_Z_M, 0.0) << endl);
245 
246  for (vector<JNPEHit>::const_iterator i = data.begin(); i != data.end(); ++i) {
247  DEBUG(FIXED(6,1) << i->getZ() << ' ' <<
248  FIXED(6,4) << i->getY0() << ' ' <<
249  FIXED(6,4) << i->getYA() << ' ' <<
250  setw(1) << i->getN() << ' ' <<
251  FIXED(6,4) << i->getP() << endl);
252  }
253 
254  DEBUG(" --> " << FIXED(6,1) << Zmin << ' ' << FIXED(6,1) << Zmax << endl);
255  }
256 
257  // move track
258 
259  track->move(Zmin, getSpeedOfLight());
260 
261  out.push_back(JFit(*track).add(JMUONSTART));
262 
263  out.rbegin()->setW(track->getW());
264  out.rbegin()->setW(JSTART_NPE_MIP, npe);
265  out.rbegin()->setW(JSTART_NPE_MIP_TOTAL, npe_total);
266  out.rbegin()->setW(JSTART_LENGTH_METRES, Zmax - Zmin);
267  }
268 
269  // apply default sorter
270 
271  sort(out.begin(), out.end(), qualitySorter);
272 
273  copy(in->begin(), in->end(), back_inserter(out));
274 
275  outputFile.put(out);
276  }
277  STATUS(endl);
278 
280 
281  io >> outputFile;
282 
283  outputFile.close();
284 }
Auxiliary methods to evaluate Poisson probabilities and chi2.
static const int JMUONSTART
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
static const int JSTART_NPE_MIP_TOTAL
number of photo-electrons along the whole track from JStart.cc
ROOT TTree parameter settings.
Auxiliary methods for PDF calculations.
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Definition: JComparator.hh:143
Data structure for a composite optical module.
Definition: JModule.hh:50
Auxiliary method to locate start and end point of muon trajectory.
Regressor function object for JEnergy fit.
const double getSpeedOfLight()
Number of bytes in a gigabyte.
Definition: JConstants.hh:89
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
Recording of objects on file according a format that follows from the file name extension.
Router for direct addressing of module data in detector data structure.
Rotation matrix.
Definition: JRotation3D.hh:111
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
General purpose class for parallel reading of objects from a single file or multiple files...
Template specialisation of class JModel to match hit with muon trajectory along z-axis.
Definition: JFit/JModel.hh:34
Auxiliary class to test history.
Definition: JHistory.hh:152
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:63
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
T find(T __begin, T __end) const
Get start or end point of muon trajectory.
Definition: JStart.hh:108
Basic data structure for time and time over threshold information of hit.
JFit & add(const int type)
Add event to history.
Definition: JEvt.hh:137
string outputFile
Data structure for detector geometry and calibration.
void transform(const JRotation3D &R, const JVector3D &pos)
Transform position.
Definition: JPosition3D.hh:330
Various implementations of functional maps.
static const int JSTART_NPE_MIP
number of photo-electrons up to the barycentre from JStart.cc
Type list.
Definition: JTypeList.hh:22
Scanning of objects from a single file according a format that follows from the extension of each fil...
Auxiliary class to extract a subset of optical modules from a detector.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
static const int JCOPY_Z_M
true vertex position along track [m] from JCopy.cc
Data structure for fit parameters.
Constants.
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:130
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
Auxiliary class for start or end point evaluation.
Definition: JStart.hh:21
Auxiliary class to test history.
Definition: JHistory.hh:104
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.
Auxiliary class for simultaneously handling light yields and response of PMT.
Definition: JNPEHit.hh:19
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:61
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:40
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Direct access to module in detector data structure.
Reduced data structure for L1 hit.
static const int JSTART_LENGTH_METRES
distance between first and last hits in metres from JStart.cc
Data structure for set of track fit results.
Definition: JEvt.hh:294
std::vector< int > count
Definition: JAlgorithm.hh:184
Utility class to parse command line options.
void transform(const JRotation3D &R, const JVector3D &pos)
Transformation of geometry (see method JGEOMETRY3D::JPosition3D::transform(const JRotation3D&amp;, const JVector3D&amp;)).
Definition: JModule.hh:273
JFIT::JFit JFit
Definition: JEvt.hh:386
Data structure for fit of straight line paralel to z-axis.
Definition: JLine1Z.hh:27
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:153
Reduced data structure for L1 hit.
Definition: JHitR1.hh:31
JDirection3D getDirection(const Vec &v)
Get direction.
Object reading from a list of files.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
Data regression method for JFIT::JEnergy.
Template L0 hit builder.
Definition: JBuildL0.hh:35
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:185
void select(const JSelector_t &selector)
Select fits.
Definition: JEvt.hh:314
Maximum likelihood estimator (M-estimators).
bool qualitySorter(const JRECONSTRUCTION::JFit &first, const JRECONSTRUCTION::JFit &second)
Comparison of fit results.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
JPosition3D getPosition(const Vec &v)
Get position.
int main(int argc, char *argv[])
Definition: Main.cpp:15