Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JFeedback.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <set>
5
6#include "TROOT.h"
7#include "TFile.h"
8
14
15#include "flux/Flux.hh"
16
17#include "JAAnet/JHead.hh"
18#include "JLang/JManip.hh"
19
21#include "JSupport/JSupport.hh"
23
24#include "Jeep/JParser.hh"
25#include "Jeep/JMessage.hh"
26
27namespace {
28
30
31 const Flux_Atmospheric conventional;
32
33
34 /**
35 * Auxiliary data structure for run statistics.
36 */
37 struct stats_t {
38
39 std::string name;
40 double events = 0; //!< number of events
41 double range_s = 0.0; //!< time difference between first and last event
42 double livetime_s = 0.0; //!< livetime of events
43 double daq_s = 0.0; //!< livetime of data taking run
44 double gap_s = 0.0; //!< maximal time between two consecutive events
45
46 friend inline std::ostream& operator<<(std::ostream& out, const stats_t& object)
47 {
48 using namespace std;
49
50 out << object.name << endl;
51 out << "events: " << FIXED(9,1) << object.events << endl;
52 out << "range: " << FIXED(7,1) << object.range_s << " [s]" << endl;
53 out << "livetime: " << FIXED(7,1) << object.livetime_s << " [s]" << endl;
54 out << "DAQ: " << FIXED(7,1) << object.daq_s << " [s]" << endl;
55 out << "gap: " << FIXED(7,1) << object.gap_s << " [s]" << endl;
56
57 return out;
58 }
59 };
60
61
62 /**
63 * Get run statistics for real data.
64 *
65 * \param head header
66 * \param in event input
67 * \return statistics
68 */
69 inline stats_t getStatsFromData(const JHead& head, JObjectIterator<Evt>& in)
70 {
71 using namespace std;
72 using namespace JPP;
73 using namespace KM3NETDAQ;
74
75 stats_t object;
76
77 set<int> buffer;
78 double events = 0;
79
80 while (in.hasNext()) {
81
82 const Evt* evt = in.next();
83
84 buffer.insert(evt->frame_index);
85
86 events += 1;
87 }
88
89 if (buffer.size() < 2) {
90 FATAL("Insufficient events " << buffer.size() << endl);
91 }
92
93 int gap = 0;
94
95 for (set<int>::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
96 if (*q - *p > gap) {
97 gap = *q - *p;
98 }
99 }
100
101 object.name = "data";
102 object.events = events;
103 object.range_s = (*buffer.rbegin() - *buffer.begin()) * getFrameTime() * 1.0e-9;
104 object.livetime_s = buffer.size() * getFrameTime() * 1.0e-9;
105 object.daq_s = head.DAQ.livetime_s;
106 object.gap_s = gap * getFrameTime() * 1.0e-9;
107
108 return object;
109 }
110
111
112 /**
113 * Get run statistics for MUPAGE.
114 *
115 * \param head header
116 * \param in event input
117 * \return statistics
118 */
119 inline stats_t getStatsFromMUPAGE(const JHead& head, JObjectIterator<Evt>& in)
120 {
121 using namespace std;
122 using namespace JPP;
123
124 stats_t object;
125
126 set<double> buffer;
127 double events = 0;
128
129 while (in.hasNext()) {
130
131 const Evt* evt = in.next();
132
133 buffer.insert(evt->mc_event_time.AsDouble());
134
135 events += 1;
136 }
137
138 if (buffer.size() < 2) {
139 FATAL("Insufficient events " << buffer.size() << endl);
140 }
141
142 double gap = 0;
143
144 for (set<double>::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
145 if (*q - *p > gap) {
146 gap = *q - *p;
147 }
148 }
149
150 object.name = "MUPAGE";
151 object.events = events * head.DAQ.livetime_s / head.livetime.numberOfSeconds;
152 object.range_s = (*buffer.rbegin() - *buffer.begin());
153 object.livetime_s = head.livetime.numberOfSeconds;
154 object.daq_s = head.DAQ.livetime_s;
155 object.gap_s = gap;
156
157 return object;
158 }
159
160
161 /**
162 * Get run statistics for gSeaGen.
163 *
164 * \param head header
165 * \param in event input
166 * \return statistics
167 */
168 inline stats_t getStatsFromGSEAGEN(const JHead& head, JObjectIterator<Evt>& in)
169 {
170 using namespace std;
171 using namespace JPP;
172
173 stats_t object;
174
175 set<double> buffer;
176 double events = 0;
177
178 while (in.hasNext()) {
179
180 const Evt* evt = in.next();
181
182 buffer.insert(evt->mc_event_time.AsDouble());
183
184 const Trk trk = get_neutrino(*evt);
185
186 events += evt->w[WEIGHTLIST_DIFFERENTIAL_EVENT_RATE] * evt->w[WEIGHTLIST_NORMALISATION] * conventional.dNdEdOmega(trk.type, log10(trk.E), trk.dir.z);
187 }
188
189 if (buffer.size() < 2) {
190 FATAL("Insufficient events " << buffer.size() << endl);
191 }
192
193 double gap = 0;
194
195 for (set<double>::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
196 if (*q - *p > gap) {
197 gap = *q - *p;
198 }
199 }
200
201 object.name = "gSeaGen";
202 object.events = events * head.DAQ.livetime_s;
203 object.range_s = (*buffer.rbegin() - *buffer.begin());
204 object.livetime_s = 0.0;
205 object.daq_s = head.DAQ.livetime_s;
206 object.gap_s = gap;
207
208 return object;
209 }
210
211
212 /**
213 * Get run statistics for pure-noise.
214 *
215 * \param head header
216 * \param in event input
217 * \return statistics
218 */
219 inline stats_t getStatsFromK40(const JHead& head, JObjectIterator<Evt>& in)
220 {
221 using namespace std;
222 using namespace JPP;
223
224 stats_t object;
225
226 set<int> buffer;
227 double events = 0;
228
229 while (in.hasNext()) {
230
231 const Evt* evt = in.next();
232
233 buffer.insert(evt->frame_index);
234
235 events += 1;
236 }
237
238 if (buffer.size() < 2) {
239 FATAL("Insufficient events " << buffer.size() << endl);
240 }
241
242 int gap = 0;
243
244 for (set<int>::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
245 if (*q - *p > gap) {
246 gap = *q - *p;
247 }
248 }
249
250 object.name = "noise";
251 object.events = events * head.DAQ.livetime_s / head.K40.livetime_s;
252 object.range_s = (*buffer.rbegin() - *buffer.begin()) * getFrameTime() * 1.0e-9;
253 object.livetime_s = head.K40.livetime_s;
254 object.daq_s = head.DAQ.livetime_s;
255 object.gap_s = gap * getFrameTime() * 1.0e-9;
256
257 return object;
258 }
259
260
261 /**
262 * Get run statistics.
263 *
264 * \param head header
265 * \param in event input
266 * \return statistics
267 */
268 inline stats_t getStats(const JHead& head, JObjectIterator<Evt>& in)
269 {
270 using namespace std;
271 using namespace JPP;
272
273 const bool mupage = is_mupage(head);
274 const bool gseagen = !mupage && head.is_valid(&JHead::depth) && (head.calibration.buffer == calibration::statical());
275 const bool k40 = head.is_valid(&JHead::K40);
276
277 if (mupage)
278 return getStatsFromMUPAGE (head, in);
279 else if (gseagen)
280 return getStatsFromGSEAGEN(head, in);
281 else if (k40)
282 return getStatsFromK40 (head, in);
283 else
284 return getStatsFromData (head, in);
285 }
286}
287
288
289/**
290 * \file
291 *
292 * Example program to analyse track fit results from Evt formatted data.
293 * \author mdejong
294 */
295int main(int argc, char **argv)
296{
297 using namespace std;
298 using namespace JPP;
299
300 JSingleFileScanner<Evt> inputFile;
301 JLimit_t& numberOfEvents = inputFile.getLimit();
302 int debug;
303
304 try {
305
306 JParser<> zap("Example program to analyse track fit results from Evt formatted data.");
307
308 zap['f'] = make_field(inputFile);
309 zap['n'] = make_field(numberOfEvents) = JLimit::max();
310 zap['d'] = make_field(debug) = 2;
311
312 zap(argc, argv);
313 }
314 catch(const exception& error) {
315 FATAL(error.what() << endl);
316 }
317
318
319 const JHead head = getHeader(inputFile);
320 const stats_t stats = getStats(head, inputFile);
321
322 DEBUG(inputFile << endl << head << endl << stats << endl);
323
324 cout << setw(132) << left << inputFile << right << ' '
325 << FIXED(9,1) << stats.events << ' '
326 << FIXED(7,1) << stats.range_s << ' '
327 << FIXED(7,1) << stats.livetime_s << ' '
328 << FIXED(7,1) << stats.daq_s << ' '
329 << FIXED(7,1) << stats.gap_s << endl;
330}
int main(int argc, char **argv)
Definition JFeedback.cc:295
I/O manipulators.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Scanning of objects from a single file according a format that follows from the extension of each fil...
ROOT TTree parameter settings of various packages.
Monte Carlo run header.
Definition JHead.hh:1236
JAANET::livetime livetime
Definition JHead.hh:1622
JAANET::DAQ DAQ
Definition JHead.hh:1625
JAANET::depth depth
Definition JHead.hh:1624
JAANET::K40 K40
Definition JHead.hh:1626
JAANET::calibration calibration
Definition JHead.hh:1610
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition JHead.hh:1319
Interface of object iteration for a single data type.
virtual bool hasNext()=0
Check availability of next element.
virtual const pointer_type & next()=0
Get next element.
Utility class to parse command line options.
Definition JParser.hh:1698
Object reading from a list of files.
bool is_mupage(const JHead &header)
Check for generator.
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
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
double getFrameTime()
Get frame time duration.
Definition JDAQClock.hh:162
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
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]=w3 (see e.g. Tag list or km3net-dataformat/definitions)
Definition Evt.hh:42
int frame_index
from the raw data
Definition Evt.hh:29
TTimeStamp mc_event_time
MC: true generation time (UTC) of the event, (default: 01 Jan 1970 00:00:00)
Definition Evt.hh:46
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
double livetime_s
Live time [s].
Definition JHead.hh:1053
double livetime_s
Live time [s].
Definition JHead.hh:1107
std::string buffer
General purpose name.
Definition JHead.hh:217
static const std::string statical()
Definition JHead.hh:331
double numberOfSeconds
Live time [s].
Definition JHead.hh:896
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15
int type
MC: particle type in PDG encoding.
Definition Trk.hh:24
Vec dir
track direction
Definition Trk.hh:18
double E
Energy [GeV] (either MC truth or reconstructed)
Definition Trk.hh:20
double z
Definition Vec.hh:14
static const int WEIGHTLIST_DIFFERENTIAL_EVENT_RATE
Event rate per unit of flux (c.f. taglist document) [GeV m2 sr].
Definition weightlist.hh:14
static const int WEIGHTLIST_NORMALISATION
Event rate normalisation.
Definition weightlist.hh:16