Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPath.cc File Reference

Program to perform JFIT::JRegressor<JLine3Z,JGandalf> fit with I/O of JFIT::JEvt data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include "evt/Head.hh"
#include "evt/Evt.hh"
#include "JDAQ/JDAQEvent.hh"
#include "JDAQ/JDAQTimeslice.hh"
#include "JDAQ/JDAQSummaryslice.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JTrigger/JHit.hh"
#include "JTrigger/JFrame.hh"
#include "JTrigger/JTimeslice.hh"
#include "JTrigger/JHitL0.hh"
#include "JTrigger/JBuildL0.hh"
#include "JTrigger/JTriggerParameters.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JParallelFileScanner.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JMeta.hh"
#include "JFit/JHitW0.hh"
#include "JFit/JPMTW0.hh"
#include "JFit/JLine3Z.hh"
#include "JFit/JGandalf.hh"
#include "JFit/JLine3ZRegressor.hh"
#include "JFit/JFitToolkit.hh"
#include "JFit/JEvt.hh"
#include "JFit/JEvtToolkit.hh"
#include "JFit/JFitParameters.hh"
#include "JFit/JModel.hh"
#include "JTools/JConstants.hh"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JPhysics/JPDFTable.hh"
#include "JPhysics/JPDFToolkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program to perform JFIT::JRegressor<JLine3Z,JGandalf> fit with I/O of JFIT::JEvt data.

Author
mdejong

Definition in file JPath.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

< hit selection [m]

< hit selection [ns]

Definition at line 59 of file JPath.cc.

60 {
61  using namespace std;
62  using namespace JPP;
63  using namespace KM3NETDAQ;
64 
65  typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
66  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
68 
69  JParallelFileScanner_t inputFile;
70  JFileRecorder<typelist> outputFile;
71  JLimit_t& numberOfEvents = inputFile.getLimit();
72  string detectorFile;
73  string pdfFile;
74  double roadWidth_m;
75  double R_Hz;
76  size_t numberOfPrefits;
77  double TTS_ns;
78  double E_GeV;
79  int debug;
80 
81  try {
82 
83  JParser<> zap("Program to perform fit of muon path to data.");
84 
85  zap['f'] = make_field(inputFile);
86  zap['o'] = make_field(outputFile) = "path.root";
87  zap['a'] = make_field(detectorFile);
88  zap['n'] = make_field(numberOfEvents) = JLimit::max();
89  zap['P'] = make_field(pdfFile);
90  zap['R'] = make_field(roadWidth_m) = numeric_limits<double>::max();
91  zap['B'] = make_field(R_Hz) = 6.0e3;
92  zap['N'] = make_field(numberOfPrefits) = 1;
93  zap['T'] = make_field(TTS_ns);
94  zap['E'] = make_field(E_GeV) = 1.0e3;
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 
105  cout.tie(&cerr);
106 
107 
108  JDetector detector;
109 
110  try {
111  load(detectorFile, detector);
112  }
113  catch(const JException& error) {
114  FATAL(error);
115  }
116 
117  const JModuleRouter moduleRouter(detector);
118 
119 
120  typedef vector<JHitL0> JDataL0_t;
121  const JBuildL0<JHitL0> buildL0;
122 
123 
124  typedef JRegressor<JLine3Z, JGandalf> JRegressor_t;
125 
127  JRegressor_t::T_ns.setRange(-50.0, +50.0); // ns
128  JRegressor_t::Vmax_npe = 10.0; // npe
129  JRegressor_t::MAXIMUM_ITERATIONS = 10000;
130 
131  JRegressor_t fit(pdfFile, TTS_ns);
132 
133  fit.estimator.reset(new JMEstimatorLorentzian());
134 
135  fit.parameters.resize(4);
136 
137  fit.parameters[0] = JLine3Z::pX();
138  fit.parameters[1] = JLine3Z::pY();
139  fit.parameters[2] = JLine3Z::pDX();
140  fit.parameters[3] = JLine3Z::pDY();
141 
142  if (fit.getRmax() < roadWidth_m) {
143 
144  roadWidth_m = fit.getRmax();
145 
146  WARNING("Set road width to [m] " << roadWidth_m << endl);
147  }
148 
149  const double Rmax_m = 100.0; //!< hit selection [m]
150  const double Tmax_ns = 10.0; //!< hit selection [ns]
151 
152 
153  outputFile.open();
154 
155  outputFile.put(JMeta(argc, argv));
156 
157  while (inputFile.hasNext()) {
158 
159  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
160 
161  multi_pointer_type ps = inputFile.next();
162 
163  JDAQEvent* tev = ps;
164  JEvt* evt = ps;
165  JEvt out;
166 
167  if (!evt->empty()) {
168 
169  JEvt::iterator __end = evt->end();
170 
171  if (numberOfPrefits > 0) {
172  advance(__end = evt->begin(), min(numberOfPrefits, evt->size()));
173  }
174 
175  partial_sort(evt->begin(), __end, evt->end(), qualitySorter);
176 
177 
178  JDataL0_t dataL0;
179 
180  buildL0(*tev, moduleRouter, true, back_inserter(dataL0));
181 
182 
183  if (dataL0.size() >= fit.parameters.size()) {
184 
185  for (JEvt::const_iterator track = evt->begin(); track != __end; ++track) {
186 
187  const JRotation3D R (getDirection(*track));
188  const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
189  const JModel<JLine1Z> match(tz, roadWidth_m, JRegressor_t::T_ns);
190 
191  // hit selection based on start value
192 
194 
195  JRange<double> Z = JRange<double>::DEFAULT_RANGE;
196 
197  for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
198 
199  JHitW0 hit(*i, R_Hz);
200 
201  hit.rotate(R);
202 
203  if (match(hit)) {
204 
205  top.insert(hit.getPMTIdentifier());
206 
207  const double t1 = hit.getT() - tz.getT(hit);
208 
209  if (tz.getDistance(hit) <= Rmax_m && t1 >= -Tmax_ns && t1 <= +Tmax_ns) {
210  Z.include(hit.getZ() - tz.getDistance(hit) / getTanThetaC());
211  }
212  }
213  }
214 
215 
216  vector<JPMTW0> buffer;
217 
218  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
219 
220  JPosition3D pos(module->getPosition());
221 
222  pos.rotate(R);
223 
224  if (tz.getDistance(pos) <= roadWidth_m && Z(pos.getZ() - tz.getDistance(pos) / getTanThetaC())) {
225 
226  for (unsigned int i = 0; i != module->size(); ++i) {
227 
228  const JDAQPMTIdentifier id(module->getID(), i);
229 
230  JPMT pmt(module->getPMT(i));
231 
232  pmt.rotate(R);
233 
234  buffer.push_back(JPMTW0(pmt, R_Hz, top.count(id)));
235  }
236  }
237  }
238 
239 
240  const int NDF = buffer.size() - fit.parameters.size();
241 
242  if (NDF >= 0) {
243 
244  // set fit parameters
245 
246  if (track->getE() > 0.1)
247  fit.E_GeV = track->getE();
248  else
249  fit.E_GeV = E_GeV;
250 
251  const double chi2 = fit(JLine3Z(tz), buffer.begin(), buffer.end());
252 
253  JTrack3D tb(fit.value);
254 
255  tb.rotate_back(R);
256 
257  out.push_back(getFit(JMUONPATH, tb, getQuality(chi2), NDF));
258  }
259  }
260 
261  // apply default sorter
262 
263  sort(out.begin(), out.end(), qualitySorter);
264  }
265  }
266 
267  outputFile.put(out);
268  }
269  STATUS(endl);
270 
271  JSingleFileScanner<JRemove<typelist, JEvt>::typelist> io(inputFile);
272 
273  io >> outputFile;
274 
275  outputFile.close();
276 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
static const JRange< double, std::less< double > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:506
Utility class to parse command line options.
Definition: JParser.hh:1410
#define WARNING(A)
Definition: JMessage.hh:63
#define STATUS(A)
Definition: JMessage.hh:61
string outputFile
JFit getFit(const JHistory &history, const JTrack3D &track, const double Q, const int NDF, const double energy=0.0, const int status=0)
Get fit.
Definition: JEvtToolkit.hh:116
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:214
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
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:59
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
double getQuality(const double chi2, const int NDF)
Get quality of fit.
Definition: JEvtToolkit.hh:195
bool qualitySorter(const JFIT::JFit &first, const JFIT::JFit &second)
Comparison of fit results.
JDirection3D getDirection(const Vec &v)
Get direction.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:72
double getTanThetaC()
Get average tangent of Cherenkov angle of water.
Definition: JConstants.hh:122
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:185
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
JPosition3D getPosition(const Vec &v)
Get position.