Jpp  17.2.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMuonEnergy.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 <algorithm>
7 #include <limits>
8 #include <map>
9 #include <memory>
10 
11 #include "TMath.h"
12 
17 
18 #include "JDAQ/JDAQEventIO.hh"
19 #include "JDAQ/JDAQTimesliceIO.hh"
21 
23 
24 #include "JAAnet/JAAnetToolkit.hh"
25 
26 #include "JDetector/JDetector.hh"
29 
30 #include "JDynamics/JDynamics.hh"
31 
35 #include "JSupport/JSupport.hh"
36 #include "JSupport/JMeta.hh"
38 
39 #include "JFit/JEnergy.hh"
40 #include "JFit/JEnergyRegressor.hh"
41 
42 #include "JReconstruction/JEvt.hh"
47 
48 #include "Jeep/JParser.hh"
49 #include "Jeep/JMessage.hh"
50 
51 
52 /**
53  * \file
54  *
55  * Program to perform JFIT::JRegressor<JEnergy, JGandalf> fit using I/O of JFIT::JEvt data.
56  * \author mdejong
57  */
58 int main(int argc, char **argv)
59 {
60  using namespace std;
61  using namespace JPP;
62  using namespace KM3NETDAQ;
63 
65  typedef JParallelFileScanner< JTypeList<JDAQEvent, JFIT::JEvt> > JParallelFileScanner_t;
66  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
68  JACOUSTICS::JEvt>::typelist calibration_types;
69  typedef JMultipleFileScanner<calibration_types> JCalibration_t;
70 
71  JParallelFileScanner_t inputFile;
73  JLimit_t& numberOfEvents = inputFile.getLimit();
74  string detectorFile;
75  JCalibration_t calibrationFile;
76  double Tmax_s;
77  string pdfFile;
78  JEnergyCorrection correct;
80  int debug;
81 
82  try {
83 
84  JParser<> zap("Program to perform fit of muon energy to data.");
85 
86  zap['f'] = make_field(inputFile);
87  zap['o'] = make_field(outputFile) = "energy.root";
88  zap['a'] = make_field(detectorFile);
89  zap['+'] = make_field(calibrationFile) = JPARSER::initialised();
90  zap['T'] = make_field(Tmax_s) = 100.0;
91  zap['n'] = make_field(numberOfEvents) = JLimit::max();
92  zap['P'] = make_field(pdfFile);
93  zap['E'] = make_field(correct) = JEnergyCorrection(); // off
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  getMechanics.load(detector.getID());
117 
118  unique_ptr<JDynamics> dynamics;
119 
120  try {
121 
122  dynamics.reset(new JDynamics(detector, Tmax_s));
123 
124  dynamics->load(calibrationFile);
125  }
126  catch(const exception& error) {
127  if (!calibrationFile.empty()) {
128  FATAL(error.what());
129  }
130  }
131 
132  const JModuleRouter router(dynamics ? dynamics->getDetector() : detector);
133 
134  JSummaryFileRouter summary(inputFile, parameters.R_Hz);
135 
136  JMuonEnergy fit(parameters, router, summary, pdfFile, debug);
137 
138  outputFile.open();
139  outputFile.put(JMeta(argc, argv));
140 
141  while (inputFile.hasNext()) {
142 
143  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
144 
145  multi_pointer_type ps = inputFile.next();
146 
147  const JDAQEvent* tev = ps;
148  const JFIT::JEvt* in = ps;
149 
150  summary.update(*tev);
151 
152  if (dynamics) {
153  dynamics->update(*tev);
154  }
155 
156  // select start values
157  JFIT::JEvt cp = *in;
158 
159  if (parameters.reprocess) {
161  }
162 
163  cp.select(parameters.numberOfPrefits, qualitySorter);
164 
165  if (!cp.empty()) {
166  cp.select(JHistory::is_event(cp.begin()->getHistory()));
167  }
168 
169  // fit
170 
171  JFIT::JEvt out = fit(*tev, cp);
172 
173  // set corrected energy
174 
175  for (JFIT::JEvt::iterator i = out.begin(); i != out.end(); ++i) {
176  i->setE(correct(i->getE()));
177  }
178 
179  if (dynamics) {
180 
181  const JDynamics::coverage_type coverage = dynamics->getCoverage();
182 
183  for (JFIT::JEvt::iterator i = out.begin(); i != out.end(); ++i) {
184  i->setW(JPP_COVERAGE_ORIENTATION, coverage.orientation);
185  i->setW(JPP_COVERAGE_POSITION, coverage.position);
186  }
187  }
188 
189  // apply default sorter
190 
191  sort(out.begin(), out.end(), qualitySorter);
192 
193  copy(in->begin(), in->end(), back_inserter(out));
194 
195  outputFile.put(out);
196  }
197  STATUS(endl);
198 
200 
201  io >> outputFile;
202 
203  outputFile.close();
204 }
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
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 for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:226
Auxiliary class for correction of energy determined by JEnergy.cc.
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.
Definition of hit and track types and auxiliary methods for handling Monte Carlo 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
Data structure for fit parameters.
#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:161
then cp
Orientation of module.
Object reading from a list of files.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
Data regression method for JFIT::JEnergy.
Auxiliary class to to determine muon energy.
Definition: JMuonEnergy.hh:58
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.
static const int JMUONENERGY
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
static const int JPP_COVERAGE_POSITION
coverage of dynamic position calibration from any Jpp application