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