Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintEvt.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <algorithm>
6 #include <vector>
7 #include <map>
8 
9 #include "TROOT.h"
10 #include "TFile.h"
11 
16 
17 #include "JAAnet/JHead.hh"
18 #include "JAAnet/JHeadToolkit.hh"
19 #include "JAAnet/JAAnetToolkit.hh"
20 
21 #include "JDAQ/JDAQEventIO.hh"
22 
24 #include "JSupport/JTreeScanner.hh"
26 #include "JSupport/JSupport.hh"
27 
28 #include "JReconstruction/JEvt.hh"
30 
31 #include "JLang/JVectorize.hh"
32 
33 #include "Jeep/JPrint.hh"
34 #include "Jeep/JParser.hh"
35 #include "Jeep/JMessage.hh"
36 
37 
38 /**
39  * \author mdejong
40  */
41 
42 namespace {
43 
44  /**
45  * Auxiliary data structure for formatted printing.
46  */
47  struct JTrack :
49  {
50  /**
51  * Constructor.
52  *
53  * \param track track
54  */
55  JTrack(const JTrack3E& track) :
56  JGEOMETRY3D::JTrack3E(track)
57  {}
58 
59 
60  /**
61  * Print track.
62  *
63  * \param out output stream
64  * \param track track
65  * \return output stream
66  */
67  friend inline std::ostream& operator<<(std::ostream& out, const JTrack& track)
68  {
69  using namespace JPP;
70 
71  out << FIXED(8,2) << track.getX() << ' '
72  << FIXED(8,2) << track.getY() << ' '
73  << FIXED(8,2) << track.getZ() << ' '
74  << FIXED(7,3) << track.getDX() << ' '
75  << FIXED(7,3) << track.getDY() << ' '
76  << FIXED(7,3) << track.getDZ() << ' '
77  << FIXED(10,1) << track.getT() << ' '
78  << SCIENTIFIC(12,3) << track.getE();
79 
80  return out;
81  }
82  };
83 
84 
85  /**
86  * Auxiliary class to get weight of given fit.
87  */
88  struct JWeight :
89  public std::map<std::string, int>
90  {
91  /**
92  * Default constructor.
93  */
94  JWeight()
95  {
96 #define MAKE_ENTRY(A) std::make_pair(#A, A)
97 
98  this->insert(MAKE_ENTRY(JGANDALF_BETA0_RAD));
99  this->insert(MAKE_ENTRY(JGANDALF_BETA1_RAD));
100  this->insert(MAKE_ENTRY(JGANDALF_CHI2));
101  this->insert(MAKE_ENTRY(JGANDALF_NUMBER_OF_HITS));
102  this->insert(MAKE_ENTRY(JENERGY_ENERGY));
103  this->insert(MAKE_ENTRY(JENERGY_CHI2));
104  this->insert(MAKE_ENTRY(JGANDALF_LAMBDA));
106  this->insert(MAKE_ENTRY(JSTART_NPE_MIP));
107  this->insert(MAKE_ENTRY(JSTART_NPE_MIP_TOTAL));
108  this->insert(MAKE_ENTRY(JSTART_LENGTH_METRES));
109  this->insert(MAKE_ENTRY(JVETO_NPE));
110  this->insert(MAKE_ENTRY(JVETO_NUMBER_OF_HITS));
111  this->insert(MAKE_ENTRY(JENERGY_MUON_RANGE_METRES));
112  this->insert(MAKE_ENTRY(JENERGY_NOISE_LIKELIHOOD));
113  this->insert(MAKE_ENTRY(JENERGY_NDF));
114  this->insert(MAKE_ENTRY(JENERGY_NUMBER_OF_HITS));
115  this->insert(MAKE_ENTRY(JCOPY_Z_M));
116  this->insert(MAKE_ENTRY(JPP_COVERAGE_ORIENTATION));
117  this->insert(MAKE_ENTRY(JPP_COVERAGE_POSITION));
118  this->insert(MAKE_ENTRY(JENERGY_MINIMAL_ENERGY));
119  this->insert(MAKE_ENTRY(JENERGY_MAXIMAL_ENERGY));
120  this->insert(MAKE_ENTRY(JSHOWERFIT_ENERGY));
121  this->insert(MAKE_ENTRY(AASHOWERFIT_ENERGY));
122  this->insert(MAKE_ENTRY(AASHOWERFIT_NUMBER_OF_HITS));
123 
124 #undef MAKE_ENTRY
125  }
126 
127  /**
128  * Get weight.
129  *
130  * \param fit fit
131  * \param key key
132  * \param value default value
133  * \return value
134  */
135  double operator()(const JRECONSTRUCTION::JFit& fit, const std::string& key, const double value) const
136  {
137  const_iterator p = this->find(key);
138 
139  if (p != this->end() && fit.hasW(p->second))
140  return fit.getW(p->second);
141  else
142  return value;
143  }
144 
145  } getWeight;
146 }
147 
148 /**
149  * Auxiliary program to print fit results;
150  */
151 int main(int argc, char **argv)
152 {
153  using namespace std;
154  using namespace JPP;
155  using namespace KM3NETDAQ;
156 
157  typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
158  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
159 
160  JParallelFileScanner_t inputFile;
161  JLimit_t& numberOfEvents = inputFile.getLimit();
163  size_t numberOfFits;
164  vector<string> keys;
165  int debug;
166 
167  try {
168 
169  JParser<> zap("Auxiliary program to print fit results.");
170 
171  zap['f'] = make_field(inputFile);
172  zap['n'] = make_field(numberOfEvents) = JLimit::max();
174  zap['N'] = make_field(numberOfFits) = 1;
175  zap['k'] = make_field(keys, MAKE_STRING("print optional weights: " << get_keys(getWeight))) = JPARSER::initialised();
176  zap['d'] = make_field(debug) = 2;
177 
178  zap(argc, argv);
179  }
180  catch(const exception& error) {
181  FATAL(error.what() << endl);
182  }
183 
184 
185 
186  const int WIDTH = 16;
187 
188  JTreeScanner<Evt> mc(inputFile);
189 
190  JPosition3D center(0,0,0);
191 
192  try {
193  center = get<JPosition3D>(getHeader(inputFile));
194  } catch(const exception& error) {}
195 
196 
197  while (inputFile.hasNext()) {
198 
199  cout << "event: " << setw(10) << inputFile.getCounter() << endl;
200 
201  multi_pointer_type ps = inputFile.next();
202 
203  JDAQEvent* tev = ps;
204  JEvt* evt = ps;
205 
206  if (quality_sorter.is_valid()) {
207  sort(evt->begin(), evt->end(), quality_sorter);
208  }
209 
210  time_converter converter;
211 
212  cout << "trigger: " << setw(10) << tev->getCounter() << ' '
213  << tev->getTimesliceStart() << endl;
214 
215  if (mc.getEntries() != 0) {
216 
217  Evt* event = mc.getEntry(tev->getCounter());
218 
219  if (event != NULL) {
220 
221  converter = time_converter(*event, *tev);
222 
223  if (has_neutrino(*event)) {
224 
225  JTrack ta = getTrack(get_neutrino(*event));
226 
227  ta.add(center);
228 
229  cout << LEFT(WIDTH) << "neutrino" << right << ' ' << ta << endl;
230  }
231 
232 
233  for (vector<Trk>::const_iterator i = event->mc_trks.begin(); i != event->mc_trks.end(); ++i) {
234 
235  JTrack ta = getTrack(*i);
236 
237  ta.add(center);
238 
239  cout << LEFT(WIDTH) << (is_muon (*i) ? "muon" :
240  is_electron(*i) ? "electron" :
241  is_hadron (*i) ? "hadron" : "other") << right << ' ' << ta << endl;
242  }
243  }
244  }
245 
246  cout << "number of fits " << setw(4) << right << evt->size() << endl;
247 
248  for (size_t i = 0; i != min(evt->size(), numberOfFits); ++i) {
249 
250  const JFit& fit = (*evt)[i];
251 
252  JTrack tb = getTrack(fit);
253 
254  tb.sub(converter.putTime());
255 
256  cout << LEFT(WIDTH) << "fit" << right << ' '
257  << tb << ' '
258  << FIXED(7,2) << fit.getQ();
259 
260  for (const auto& key : keys) {
261  cout << ' ' << SCIENTIFIC(12,3) << getWeight(fit, key, 0.0);
262  }
263 
264  cout << endl;
265 
266  for (size_t row = 0; row != fit.getDimensionOfErrorMatrix(); ++row) {
267  for (size_t col = 0; col <= row; ++col) {
268  cout << ' ' << SCIENTIFIC(12,3) << fit.getV(row,col);
269  }
270  cout << endl;
271  }
272 
273  cout << fit.getHistory() << endl;
274  }
275  }
276 }
bool is_electron(const Trk &track)
Test whether given track is a (anti-)electron.
Auxiliary data structure for alignment of data.
Definition: JManip.hh:231
Utility class to parse command line options.
Definition: JParser.hh:1500
static const int JSTART_NPE_MIP_TOTAL
number of photo-electrons along the whole track from JStart.cc
int main(int argc, char *argv[])
Definition: Main.cc:15
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
ROOT TTree parameter settings of various packages.
#define MAKE_ENTRY(A)
static const int JVETO_NPE
number of photo-electrons from JVeto.cc
JTrack3E getTrack(const Trk &track)
Get track.
static const int JENERGY_ENERGY
uncorrected energy [GeV] from JEnergy.cc
static const int JENERGY_MAXIMAL_ENERGY
maximal energy [GeV] from JEnergy.cc
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
General purpose sorter of fit results.
static const int JGANDALF_BETA1_RAD
angular resolution [rad] from JGandalf.cc
static const int AASHOWERFIT_ENERGY
uncorrected energy [GeV]
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:66
Auxiliary class to convert DAQ hit time to/from Monte Carlo hit time.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
static const int JENERGY_CHI2
chi2 from JEnergy.cc
3D track with energy.
Definition: JTrack3E.hh:30
Acoustic single fit.
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
static const int JENERGY_NOISE_LIKELIHOOD
log likelihood of every hit being K40 from JEnergy.cc
static const int JSTART_NPE_MIP
number of photo-electrons up to the barycentre from JStart.cc
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Data structure for track fit results with history and optional associated values. ...
static const int JENERGY_NDF
number of degrees of freedom from JEnergy.cc
static const int JENERGY_MINIMAL_ENERGY
minimal energy [GeV] from JEnergy.cc
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
static const int JCOPY_Z_M
true vertex position along track [m] from JCopy.cc
static const int JGANDALF_NUMBER_OF_HITS
number of hits from JGandalf.cc
static const int JSHOWERFIT_ENERGY
uncorrected energy [GeV] from JShowerFit.cc
I/O formatting auxiliaries.
static const int JGANDALF_LAMBDA
control parameter from JGandalf.cc
bool hasW(const int i) const
Check availability of value.
Acoustic event fit.
static const int JENERGY_NUMBER_OF_HITS
number of hits from JEnergy.cc
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
double getE(const double z) const
Get muon energy at given position.
Parallel scanning of objects from a single file or multiple files according a format that follows fro...
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
static const int JGANDALF_BETA0_RAD
KM3NeT Data Definitions v2.0.0-15-g59d2e2b https://git.km3net.de/common/km3net-dataformat.
double putTime() const
Get Monte Carlo time minus DAQ/trigger time.
Weight calculator.
Definition: JWeight.hh:23
static const int JVETO_NUMBER_OF_HITS
number of hits from JVeto.cc
Muon trajectory.
int debug
debug level
Definition: JSirene.cc:63
Reconstruction type dependent comparison of track quality.
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
General purpose messaging.
Auxiliary include file for time conversion between DAQ/trigger hit and Monte Carlo hit...
#define FATAL(A)
Definition: JMessage.hh:67
static const int JPP_COVERAGE_ORIENTATION
coverage of dynamic orientation calibration from any Jpp application
static const int JSTART_LENGTH_METRES
distance between first and last hits in metres from JStart.cc
Utility class to parse command line options.
static const int JGANDALF_NUMBER_OF_ITERATIONS
number of iterations from JGandalf.cc
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
static const int JGANDALF_CHI2
chi2 from JGandalf.cc
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
bool is_hadron(const Trk &track)
Test whether given track is a hadron.
const std::vector< double > & getW() const
Get associated values.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
JTriggerCounter_t getCounter() const
Get trigger counter.
static const int JENERGY_MUON_RANGE_METRES
range of a muon with the reconstructed energy [m] from JEnergy.cc
const array_type< JKey_t > & get_keys(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of keys of map.
Definition: JVectorize.hh:139
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
static const int AASHOWERFIT_NUMBER_OF_HITS
number of hits used
static const int JPP_COVERAGE_POSITION
coverage of dynamic position calibration from any Jpp application