Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMuonPrefit.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
7 
8 #include "JDAQ/JDAQEventIO.hh"
11 
13 
14 #include "JDetector/JDetector.hh"
17 
18 #include "JSupport/JSupport.hh"
20 #include "JSupport/JFileRecorder.hh"
21 #include "JSupport/JMeta.hh"
22 
23 #include "JReconstruction/JEvt.hh"
26 
27 #include "JLang/JPredicate.hh"
28 #include "JLang/JComparison.hh"
29 
30 #include "Jeep/JParser.hh"
31 #include "Jeep/JMessage.hh"
32 
33 
34 /**
35  * \file
36  *
37  * Program to perform linear fits JFIT::JEstimator<JFIT::JLine1Z> covering the solid angle producing JFIT::JEvt data.
38  *
39  * \author mdejong, gmaggi
40  */
41 int main(int argc, char **argv)
42 {
43  using namespace std;
44  using namespace JPP;
45  using namespace KM3NETDAQ;
46 
49 
50  JSingleFileScanner_t inputFile;
52  JLimit_t& numberOfEvents = inputFile.getLimit();
53  string detectorFile;
55  int debug;
56 
57  try {
58 
59  JParser<> zap("Program to perform pre-fit of muon trajectory to data.");
60 
61  zap['f'] = make_field(inputFile);
62  zap['o'] = make_field(outputFile) = "prefit.root";
63  zap['a'] = make_field(detectorFile);
64  zap['n'] = make_field(numberOfEvents) = JLimit::max();
66  zap['d'] = make_field(debug) = 1;
67 
68  zap(argc, argv);
69  }
70  catch(const exception& error) {
71  FATAL(error.what() << endl);
72  }
73 
74  cout.tie(&cerr);
75 
77 
78  try {
79  load(detectorFile, detector);
80  }
81  catch(const JException& error) {
82  FATAL(error);
83  }
84 
85  const JModuleRouter router(detector);
86 
87  JMuonPrefit fit(parameters, router, debug);
88 
89  outputFile.open();
90  outputFile.put(JMeta(argc, argv));
91 
92  while (inputFile.hasNext()) {
93 
94  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
95 
96  const JDAQEvent* tev = inputFile.next();
97 
98  JEvt out = fit(*tev);
99 
100 
101  if (parameters.numberOfPrefits > 0) {
102 
103 
104  // apply default sorter
105 
106  JEvt::iterator __end = out.end();
107 
108  if (parameters.numberOfPrefits < out.size()) {
109 
110  advance(__end = out.begin(), parameters.numberOfPrefits);
111 
112  partial_sort(out.begin(), __end, out.end(), qualitySorter);
113 
114  } else {
115 
116  sort(out.begin(), __end, qualitySorter);
117  }
118 
119  // add downward pointing solutions if available but not yet sufficient
120 
121  int nz = parameters.numberOfDZMax - count_if(out.begin(), __end, make_predicate(&JFit::getDZ, parameters.DZMax, JComparison::le()));
122 
123  if (nz > 0) {
124 
125  JEvt::iterator __p = __end;
126  JEvt::iterator __q = __end = partition(__p, out.end(), make_predicate(&JFit::getDZ, parameters.DZMax, JComparison::le()));
127 
128  if (nz < distance(__p, __q)) {
129 
130  advance(__end = __p, nz);
131 
132  partial_sort(__p, __end, __q, qualitySorter);
133 
134  } else {
135 
136  sort(__p, __end, qualitySorter);
137  }
138  }
139 
140  out.erase(__end, out.end());
141 
142  } else {
143 
144  sort(out.begin(), out.end(), qualitySorter);
145  }
146 
147  outputFile.put(out);
148  }
149  STATUS(endl);
150 
152 
153  io >> outputFile;
154 
155  outputFile.close();
156 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
Wrapper class to make pre-fit of muon trajectory.
Definition: JMuonPrefit.hh:73
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
ROOT TTree parameter settings.
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
Detector data structure.
Definition: JDetector.hh:80
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.
Data structure for fit parameters.
*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
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:63
string outputFile
Data structure for detector geometry and calibration.
Auxiliary base class for file name.
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:130
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:1954
ROOT I/O of application specific meta data.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:61
General purpose messaging.
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.
Data structure for set of track fit results.
Definition: JEvt.hh:294
Utility class to parse command line options.
Object reading from a list of files.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
bool qualitySorter(const JRECONSTRUCTION::JFit &first, const JRECONSTRUCTION::JFit &second)
Comparison of fit results.
JTriggerCounter_t next()
Increment trigger counter.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
int main(int argc, char *argv[])
Definition: Main.cpp:15