Jpp
Functions
JPath.cc File Reference
#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

◆ main()

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  for (int i = 0; i != JRegressor_t::NUMBER_OF_PDFS; ++i) {
134  fit.npe[i].transform(JRegressor_t::JNPE_t::transformer_type::getDefaultTransformer()); // get rid of R-dependent weight function
135  }
136 
137  fit.estimator.reset(new JMEstimatorLorentzian());
138 
139  fit.parameters.resize(4);
140 
141  fit.parameters[0] = JLine3Z::pX();
142  fit.parameters[1] = JLine3Z::pY();
143  fit.parameters[2] = JLine3Z::pDX();
144  fit.parameters[3] = JLine3Z::pDY();
145 
146  if (fit.getRmax() < roadWidth_m) {
147 
148  roadWidth_m = fit.getRmax();
149 
150  WARNING("Set road width to [m] " << roadWidth_m << endl);
151  }
152 
153  const double Rmax_m = 100.0; //!< hit selection [m]
154  const double Tmax_ns = 10.0; //!< hit selection [ns]
155 
156 
157  outputFile.open();
158 
159  outputFile.put(JMeta(argc, argv));
160 
161  while (inputFile.hasNext()) {
162 
163  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
164 
165  multi_pointer_type ps = inputFile.next();
166 
167  JDAQEvent* tev = ps;
168  JEvt* evt = ps;
169  JEvt out;
170 
171  if (!evt->empty()) {
172 
173  JEvt::iterator __end = evt->end();
174 
175  if (numberOfPrefits > 0) {
176  advance(__end = evt->begin(), min(numberOfPrefits, evt->size()));
177  }
178 
179  partial_sort(evt->begin(), __end, evt->end(), qualitySorter);
180 
181 
182  JDataL0_t dataL0;
183 
184  buildL0(*tev, moduleRouter, true, back_inserter(dataL0));
185 
186 
187  if (dataL0.size() >= fit.parameters.size()) {
188 
189  for (JEvt::const_iterator track = evt->begin(); track != __end; ++track) {
190 
191  const JRotation3D R (getDirection(*track));
192  const JLine1Z tz(getPosition (*track).rotate(R), track->getT());
193  const JModel<JLine1Z> match(tz, roadWidth_m, JRegressor_t::T_ns);
194 
195  // hit selection based on start value
196 
198 
199  JRange<double> Z = JRange<double>::DEFAULT_RANGE;
200 
201  for (JDataL0_t::const_iterator i = dataL0.begin(); i != dataL0.end(); ++i) {
202 
203  JHitW0 hit(*i, R_Hz);
204 
205  hit.rotate(R);
206 
207  if (match(hit)) {
208 
209  top.insert(hit.getPMTIdentifier());
210 
211  const double t1 = hit.getT() - tz.getT(hit);
212 
213  if (tz.getDistance(hit) <= Rmax_m && t1 >= -Tmax_ns && t1 <= +Tmax_ns) {
214  Z.include(hit.getZ() - tz.getDistance(hit) / getTanThetaC());
215  }
216  }
217  }
218 
219 
220  vector<JPMTW0> buffer;
221 
222  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
223 
224  JPosition3D pos(module->getPosition());
225 
226  pos.rotate(R);
227 
228  if (tz.getDistance(pos) <= roadWidth_m && Z(pos.getZ() - tz.getDistance(pos) / getTanThetaC())) {
229 
230  for (unsigned int i = 0; i != module->size(); ++i) {
231 
232  const JDAQPMTIdentifier id(module->getID(), i);
233 
234  JPMT pmt(module->getPMT(i));
235 
236  pmt.rotate(R);
237 
238  buffer.push_back(JPMTW0(pmt, R_Hz, top.count(id)));
239  }
240  }
241  }
242 
243 
244  const int NDF = buffer.size() - fit.parameters.size();
245 
246  if (NDF >= 0) {
247 
248  // set fit parameters
249 
250  if (track->getE() > 0.1)
251  fit.E_GeV = track->getE();
252  else
253  fit.E_GeV = E_GeV;
254 
255  const double chi2 = fit(JLine3Z(tz), buffer.begin(), buffer.end());
256 
257  JTrack3D tb(fit.value);
258 
259  tb.rotate_back(R);
260 
261  out.push_back(getFit(JMUONPATH, tb, getQuality(chi2), NDF));
262 
263  out.rbegin()->setW(track->getW());
264  }
265  }
266 
267  // apply default sorter
268 
269  sort(out.begin(), out.end(), qualitySorter);
270  }
271  }
272 
273  outputFile.put(out);
274  }
275  STATUS(endl);
276 
277  JSingleFileScanner<JRemove<typelist, JEvt>::typelist> io(inputFile);
278 
279  io >> outputFile;
280 
281  outputFile.close();
282 }
KM3NETDAQ::JDAQEvent
DAQ Event.
Definition: JDAQEvent.hh:34
JTOOLS::pX
pX
Definition: JPolint.hh:625
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
qualitySorter
bool qualitySorter(const JFIT::JFit &first, const JFIT::JFit &second)
Comparison of fit results.
Definition: quality_sorter.cc:10
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
std::vector< JHitL0 >
JSUPPORT::JLimit_t
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:215
JTOOLS::JRange< double >::DEFAULT_RANGE
static const JRange< double, std::less< double > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:558
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JGEOMETRY3D::JPosition3D::rotate
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:185
KM3NETDAQ::JDAQEvent::end
const_iterator< T > end() const
Get end of data.
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
WARNING
#define WARNING(A)
Definition: JMessage.hh:65
debug
int debug
debug level
Definition: JSirene.cc:59
JSUPPORT::JLimit::getLimit
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
std::multiset
Definition: JSTDTypes.hh:14
JLANG::JTypeList
Type list.
Definition: JTypeList.hh:22
JFIT::JMUONPATH
JPath.cc.
Definition: JFitApplications.hh:41
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JAANET::getDirection
JDirection3D getDirection(const Vec &v)
Get direction.
Definition: JAAnetToolkit.hh:221
JTOOLS::getTanThetaC
double getTanThetaC()
Get average tangent of Cherenkov angle of water.
Definition: JConstants.hh:133
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
KM3NETDAQ::JDAQPMTIdentifier
PMT identifier.
Definition: JDAQPMTIdentifier.hh:25
JAANET::getPosition
JPosition3D getPosition(const Vec &v)
Get position.
Definition: JAAnetToolkit.hh:197
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
JFIT::getFit
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
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JFIT::getQuality
double getQuality(const double chi2, const int NDF)
Get quality of fit.
Definition: JEvtToolkit.hh:195