Jpp  17.3.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
software/JReconstruction/JMuonStart.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 #include <set>
6 #include <map>
7 #include <algorithm>
8 #include <memory>
9 
14 
15 #include "JDAQ/JDAQEventIO.hh"
16 #include "JDAQ/JDAQTimesliceIO.hh"
18 
20 
21 #include "JDetector/JDetector.hh"
25 
26 #include "JDynamics/JDynamics.hh"
27 
32 #include "JSupport/JSupport.hh"
33 #include "JSupport/JMeta.hh"
34 
35 #include "JReconstruction/JEvt.hh"
39 
40 #include "JPhysics/JK40Rates.hh"
41 #include "JPhysics/KM3NeT.hh"
42 
43 #include "Jeep/JPrint.hh"
44 #include "Jeep/JParser.hh"
45 #include "Jeep/JMessage.hh"
46 
47 /**
48  * \file
49  *
50  * Program to perform JFIT::JRegressor<JEnergy> fit with I/O of JFIT::JEvt data.
51  * \author mdejong, azegarelli, scelli
52  */
53 int main(int argc, char **argv)
54 {
55  using namespace std;
56  using namespace JPP;
57  using namespace KM3NETDAQ;
58 
60  typedef JParallelFileScanner< JTypeList<JDAQEvent, JFIT::JEvt> > JParallelFileScanner_t;
61  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
63  JACOUSTICS::JEvt>::typelist calibration_types;
65 
66  JParallelFileScanner_t inputFile;
68  JLimit_t& numberOfEvents = inputFile.getLimit();
69  string detectorFile;
70  JCalibration_t calibrationFile;
71  double Tmax_s;
72  string pdfFile;
74  JK40Rates rates_Hz;
75  int debug;
76 
77  try {
78 
79  JParser<> zap("Program to perform PDF fit of muon trajectory to data.");
80 
81  zap['f'] = make_field(inputFile);
82  zap['o'] = make_field(outputFile) = "start.root";
83  zap['a'] = make_field(detectorFile);
84  zap['+'] = make_field(calibrationFile) = JPARSER::initialised();
85  zap['T'] = make_field(Tmax_s) = 100.0;
86  zap['n'] = make_field(numberOfEvents) = JLimit::max();
87  zap['P'] = make_field(pdfFile);
89  zap['B'] = make_field(rates_Hz) = KM3NET::getK40Rates();
90  zap['d'] = make_field(debug) = 1;
91 
92  zap(argc, argv);
93  }
94  catch(const exception& error) {
95  FATAL(error.what() << endl);
96  }
97 
98 
100 
101  try {
102  load(detectorFile, detector);
103  }
104  catch(const JException& error) {
105  FATAL(error);
106  }
107 
108 
109  getMechanics.load(detector.getID());
110 
111  unique_ptr<JDynamics> dynamics;
112 
113  try {
114 
115  dynamics.reset(new JDynamics(detector, Tmax_s));
116 
117  dynamics->load(calibrationFile);
118  }
119  catch(const exception& error) {
120  if (!calibrationFile.empty()) {
121  FATAL(error.what());
122  }
123  }
124 
125  const JModuleRouter router(dynamics ? dynamics->getDetector() : detector);
126 
127  JSummaryFileRouter summary(inputFile, parameters.R_Hz);
128 
129  JMuonStart fit(parameters, router, summary, pdfFile, rates_Hz, debug);
130 
131  outputFile.open();
132  outputFile.put(JMeta(argc, argv));
133 
134  while (inputFile.hasNext()) {
135 
136  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
137 
138  multi_pointer_type ps = inputFile.next();
139 
140  const JDAQEvent* tev = ps;
141  const JFIT::JEvt* in = ps;
142 
143  summary.update(*tev);
144 
145  if (dynamics) {
146  dynamics->update(*tev);
147  }
148 
149  // select start values
150 
151  JFIT::JEvt cp = *in;
152 
153  if (parameters.reprocess) {
155  }
156 
157  cp.select(parameters.numberOfPrefits, qualitySorter);
158 
159  if (!cp.empty()) {
160  cp.select(JHistory::is_event(cp.begin()->getHistory()));
161  }
162 
163  // fit
164 
165  JFIT::JEvt out = fit(*tev, cp);
166 
167  if (dynamics) {
168 
169  const JDynamics::coverage_type coverage = dynamics->getCoverage();
170 
171  for (JFIT::JEvt::iterator i = out.begin(); i != out.end(); ++i) {
172  i->setW(JPP_COVERAGE_ORIENTATION, coverage.orientation);
173  i->setW(JPP_COVERAGE_POSITION, coverage.position);
174  }
175  }
176 
177  // apply default sorter
178 
179  sort(out.begin(), out.end(), qualitySorter);
180 
181  copy(in->begin(), in->end(), back_inserter(out));
182 
183  outputFile.put(out);
184  }
185  STATUS(endl);
186 
188 
189  io >> outputFile;
190 
191  outputFile.close();
192 }
static const int JMUONSTART
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1517
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
double position
coverage of detector by available position calibration [0,1]
Definition: JDynamics.hh:558
static JDetectorMechanics getMechanics
Function object to get string mechanics.
Definition: JMechanics.hh:243
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
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.
*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...
Auxiliary class to test history.
Definition: JHistory.hh:153
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
const JK40Rates & getK40Rates()
Get K40 rates.
Definition: KM3NeT.hh:36
string outputFile
Data structure for detector geometry and calibration.
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
double orientation
coverage of detector by available orientation calibration [0,1]
Definition: JDynamics.hh:557
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
Data structure for fit parameters.
Properties of KM3NeT PMT and deep-sea water.
I/O formatting auxiliaries.
Auxiliary class to determine start and end position of muon trajectory.
Definition: JMuonStart.hh:111
Detector file.
Definition: JHead.hh:226
Acoustic event fit.
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:351
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
Auxiliary class to test history.
Definition: JHistory.hh:105
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.
Dynamic detector calibration.
File router for fast addressing of summary data.
void load(const std::string &file_name)
Load mechanical model parameters from file.
Definition: JMechanics.hh:142
General purpose messaging.
Data structure for coverage of dynamic calibrations.
Definition: JDynamics.hh:556
#define FATAL(A)
Definition: JMessage.hh:67
Direct access to module in detector data structure.
static const int JPP_COVERAGE_ORIENTATION
coverage of dynamic orientation calibration from any Jpp application
Dynamic detector calibration.
Definition: JDynamics.hh:63
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Data structure for set of track fit results.
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
then cp
Orientation of module.
Object reading from a list of files.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
void select(const JSelector_t &selector)
Select fits.
int debug
debug level
Auxiliary class for K40 rates.
Definition: JK40Rates.hh:41
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
static const int JPP_COVERAGE_POSITION
coverage of dynamic position calibration from any Jpp application