Jpp  18.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JShowerEnergyPrefit.cc
Go to the documentation of this file.
1 #include <string>
2 #include <limits>
3 
7 
8 #include "JDAQ/JDAQEventIO.hh"
11 
14 
15 #include "JDynamics/JDynamics.hh"
16 
18 
20 #include "JSupport/JSupport.hh"
22 #include "JSupport/JMeta.hh"
23 #include "JSupport/JTreeScanner.hh"
25 
26 #include "Jeep/JParser.hh"
27 #include "Jeep/JMessage.hh"
28 
29 #include "JReconstruction/JEvt.hh"
32 
33 #include "JLang/JSharedPointer.hh"
34 
35 /**
36  * \file
37  *
38  * Program to perform EM Shower Fit for ORCA with I/O of JFIT::JEvt data.
39  * The reconstruction is made at the PMT level.
40  *
41  * \author adomi
42  */
43 int main(int argc, char** argv){
44 
45  using namespace std;
46  using namespace JPP;
47  using namespace KM3NETDAQ;
48 
50  typedef JParallelFileScanner< JTypeList<JDAQEvent, JFIT::JEvt> > JParallelFileScanner_t;
51  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
53  JACOUSTICS::JEvt>::typelist calibration_types;
54  typedef JMultipleFileScanner<calibration_types> JCalibration_t;
55 
56 
57  JParallelFileScanner_t inputFile;
60  JLimit_t& numberOfEvents = inputFile.getLimit();
61  string detectorFile;
62  JCalibration_t calibrationFile;
63  double Tmax_s;
64  string pdfFile;
65  int debug;
66 
67  try {
68 
69  JParser<> zap;
70 
71  zap['f'] = make_field(inputFile) ;
72  zap['o'] = make_field(outputFile) = "JORCAShowerFit_Output.root";
73  zap['a'] = make_field(detectorFile) ;
74  zap['+'] = make_field(calibrationFile) = JPARSER::initialised();
75  zap['T'] = make_field(Tmax_s) = 100.0;
76  zap['F'] = make_field(pdfFile) ;
78  zap['n'] = make_field(numberOfEvents) = JLimit::max();
79  zap['d'] = make_field(debug) = 2;
80 
81  zap(argc, argv);
82  }
83  catch(const exception& error) {
84  FATAL(error.what() << endl);
85  }
86 
88 
89  try {
90  load(detectorFile, detector);
91  }
92  catch(const JException& error) {
93  FATAL(error);
94  }
95 
96  unique_ptr<JDynamics> dynamics;
97 
98  try {
99 
100  dynamics.reset(new JDynamics(detector, Tmax_s));
101 
102  dynamics->load(calibrationFile);
103  }
104  catch(const exception& error) {
105  if (!calibrationFile.empty()) {
106  FATAL(error.what());
107  }
108  }
109 
110  const JModuleRouter router(dynamics ? dynamics->getDetector() : detector);
111 
112  outputFile.open();
113  outputFile.put(JMeta(argc, argv));
114 
115  JSummaryFileRouter summary(inputFile, parameters.R_Hz);
116 
117  JShowerEnergyPrefit fit(parameters, router, summary, pdfFile, debug);
118 
119  while (inputFile.hasNext()) {
120 
121  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
122 
123  multi_pointer_type ps = inputFile.next();
124 
125  JDAQEvent* tev = ps;
126  JFIT::JEvt* in = ps;
127 
128  summary.update(*tev);
129 
130  if (dynamics) {
131  dynamics->update(*tev);
132  }
133 
134  // select start values
135  JFIT::JEvt cp = *in;
136 
137  cp.select(parameters.numberOfPrefits, qualitySorter);
138 
139  if (!cp.empty()) {
140  cp.select(JHistory::is_event(cp.begin()->getHistory()));
141  }
142 
143  // fit
144 
145  JFIT::JEvt out = fit(*tev, cp);
146 
147  if (dynamics) {
148 
149  const JDynamics::coverage_type coverage = dynamics->getCoverage();
150 
151  for (JFIT::JEvt::iterator i = out.begin(); i != out.end(); ++i) {
152  i->setW(JPP_COVERAGE_ORIENTATION, coverage.orientation);
153  i->setW(JPP_COVERAGE_POSITION, coverage.position);
154  }
155  }
156 
157  // apply default sorter
158 
159  sort(out.begin(), out.end(), qualitySorter);
160 
161  // reduce output fits
162 
163  JFIT::JEvt::iterator __end = out.end();
164 
165  advance(__end = out.begin(), min(parameters.numberOfOutfits, (size_t) distance(out.begin(), out.end())));
166 
167  JFIT::JEvt reduced_out;
168 
169  copy(out.begin(), __end, back_inserter(reduced_out));
170 
171  copy(in->begin(), in->end(), back_inserter(reduced_out));
172 
173  outputFile.put(reduced_out);
174 
175  }
176  STATUS(endl);
177 
179 
180  io >> outputFile;
181 
182  outputFile.close();
183 }
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:1514
General exception.
Definition: JException.hh:24
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:575
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
#define STATUS(A)
Definition: JMessage.hh:63
void update(const JDAQHeader &header)
Update router.
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...
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
string outputFile
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:574
Type list.
Definition: JTypeList.hh:22
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:226
class to handle the third step of the shower reconstruction, mainly dedicated for ORCA ...
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:1989
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.
General purpose messaging.
Data structure for coverage of dynamic calibrations.
Definition: JDynamics.hh:573
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
#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:81
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.
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:48
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:84
do set_variable DETECTOR_TXT $WORKDIR detector
void select(const JSelector_t &selector)
Select fits.
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