57{
61
63 typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
64 typedef JToken<
';'> JToken_t;
66
67 JTriggeredFileScanner_t inputFile;
71 string formula;
75 string option;
79
80 try {
81
82 JParser<> zap(
"Utility program to determine energy correction.");
83
84 zap[
'f'] =
make_field(inputFile,
"event file(s) or histogram file");
88 zap[
'F'] =
make_field(formula,
"fit formula, e.g: \"[0]+[1]*x\"") =
"";
92 zap[
'O'] =
make_field(option,
"Fit option") =
"";
96
97 zap(argc, argv);
98 }
99 catch(const exception& error) {
100 FATAL(error.what() << endl);
101 }
102
103
104 TFile* in = NULL;
105 TH2D* h2 = NULL;
106
107 if (inputFile.size() == 1) {
108
109 in = TFile::Open(inputFile[0].c_str(), "READ");
110
111 if (in != NULL && in->IsOpen()) {
112 h2 = (TH2D*) in->Get("h2");
113 }
114 }
115
116 if (h2 == NULL) {
117
119
120 for (JMultipleFileScanner_t::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
121
122 try {
123
125
127
128 if (p == enigma.end())
129 enigma.push_back(head);
130 else
131 p->add(head);
132 }
133 catch(const exception& error) {
135 }
136 }
137
138 double Emin = numeric_limits<double>::max();
139 double Emax = 0.0;
140
141 for (vector<JHead>::const_iterator i = enigma.begin(); i!= enigma.end(); ++i) {
142
144 FATAL(
"Missing neutrino parameters." << endl);
145 }
146
147 if (i->cut_nu.E.getLowerLimit() < Emin) { Emin = i->cut_nu.E.getLowerLimit(); }
148 if (i->cut_nu.E.getUpperLimit() > Emax) { Emax = i->cut_nu.E.getUpperLimit(); }
149
151 cout << "Neutrino energy range: " << i->cut_nu.E << endl;
152 cout << "Number of generated events: " << i->genvol.numberOfEvents << endl;
153 }
154 }
155
156 const Double_t
xmin = log10(Emin);
157 const Double_t
xmax = log10(Emax);
159
161
162 double W = 1.0;
163 Vec offset(0.0, 0.0, 0.0);
164
165 for (string filename; inputFile.hasNext(); ) {
166
167 STATUS(
"event: " << setw(10) << inputFile.getCounter() <<
'\r');
DEBUG(endl);
168
169 if (filename != inputFile.getFilename()) {
170
171 filename = inputFile.getFilename();
172
173 try {
174
176
178
179 vector<JHead>::const_iterator p = find(enigma.begin(), enigma.end(), head);
180
182 W = 1.0 / (double) p->genvol.numberOfEvents;
183 }
184
185 cout << "File: " << filename << " weight " << W << endl;
186 }
187 catch(const exception& error) {
189 }
190 }
191
192 multi_pointer_type ps = inputFile.next();
193
196
198
200
201 for (vector<Trk>::const_iterator i = event->mc_trks.begin(); i != event->mc_trks.end(); ++i) {
204 t1 = *i;
205 }
206 }
207 }
208
210 continue;
211 }
212
213 }
else if (
primary == neutrino_t) {
214
217 }
218
220 continue;
221 }
222 }
223
225
226 if (evt->begin() == __end) {
227 continue;
228 }
229
230 JEvt::iterator p = min_element(evt->begin(), __end,
quality_sorter);
231
234
236
239
240 if (ta.
getE() > 0.0 && tb.
getE() > 0.0) {
241 h2->Fill(log10(tb.
getE()), log10(ta.
getE()), (enigma.size() > (
size_t) 1 ? W * event->w[2] : 1.0));
242 }
243 }
245 }
246
247
248
249 const Int_t nx = h2->GetXaxis()->GetNbins();
250 const Double_t
xmin = h2->GetXaxis()->GetXmin();
251 const Double_t
xmax = h2->GetXaxis()->GetXmax();
252
253 const Int_t ny = h2->GetYaxis()->GetNbins();
254
255 TH1D h1("h1", NULL, nx, xmin, xmax);
256
258 JGraph_t g2;
260
262
263 for (Int_t ix = 1; ix <= nx; ++ix) {
264
265 TH1D* h0 = H0[ix];
266
268
269 for (int iy = 1; iy <= ny; ++iy) {
270
271 const Double_t
x = h2->GetYaxis()->GetBinCenter(iy);
272 const Double_t
y = h2->GetBinContent(ix,iy);
273 const Double_t z = h2->GetBinError (ix,iy);
274
275 if (y > 0.0) {
276
277 h0->SetBinContent(iy, y);
278 h0->SetBinError (iy, z);
279
280 Q.put(x,y);
281 }
282 }
283
284 if (Q.getCount() >= 3) {
285
287 Q.print(cout);
288 }
289
290 TF1
f1(
"f1",
"[0]*TMath::Gaus(x,[1],[2]) + [3]");
291
292 const double x0 = Q.getQuantile(0.50);
293 const double sigma = 0.5 * (Q.getQuantile(0.66) - Q.getQuantile(0.33));
294
295 f1.SetParameter(0, Q.getWmax());
296 f1.SetParameter(1, x0);
297 f1.SetParameter(2, sigma);
298 f1.SetParameter(3, 0.0);
299
300 TFitResultPtr
result = h0->Fit(&f1,
"SQ",
"same");
301
302 if (
result.Get() == NULL) {
303 FATAL(
"Invalid TFitResultPtr " << h0->GetName() << endl);
304 }
305
307 cout << "Bin: "
308 << setw(4) << ix << ' '
309 <<
FIXED(7,3) << h2->GetXaxis()->GetBinCenter(ix) <<
' '
312 << (
result->IsValid() ?
"" :
"failed") << endl;
313 }
314
316
317 const Double_t
x = h2->GetXaxis()->GetBinCenter(ix);
318
319 h1.SetBinContent(ix,
f1.GetParameter(1));
320 h1.SetBinError (ix,
f1.GetParError (1));
321
322 g1.put(x,
pow(10.0, x) -
pow(10.0,
f1.GetParameter(1)));
323 g2.put(x,
pow(10.0, abs(
f1.GetParameter(2)) -
f1.GetParameter(1)));
324 g3.
put(x,
f1.GetParameter(1), 0.0,
f1.GetParameter(2));
325 }
326 }
327 }
328
330
331 if (formula != "") {
332
333 f1 =
new TF1(
"f1", formula.c_str());
334
335 if (
f1->IsZombie()) {
336 FATAL(
"Function: " << formula <<
" is zombie." << endl);
337 }
338
339 try {
340
341 for (vector<JToken_t>::const_iterator i = startValues.begin(); i != startValues.end(); ++i) {
343 }
344
345 for (vector<JToken_t>::const_iterator i = fixedValues.begin(); i != fixedValues.end(); ++i) {
347 }
348 }
350 FATAL(error << endl);
351 }
352
353 if (option.find('S') == string::npos) { option += "S"; }
354
356
357 } else {
358
361 Double_t z[2] = { 0.00, 0.00 };
362
363 ostringstream os;
364
365 os << " "
366 << "("
368 << ")"
369 << " * "
370 << "(x)";
371 os << "\n";
372
373 for (Int_t ix = nx; ix >= 1; --ix) {
374
375 x[0] = h1.GetXaxis()->GetBinCenter(ix);
376 y[0] = h1.GetBinContent(ix);
377 z[0] = h1.GetBinError (ix);
378
379 if (z[0] == 0.0 || !X(x[0])) {
380 continue;
381 }
382
383 os << " + "
384 << "("
385 <<
"x >= " <<
FIXED(5,3) <<
x[0]
386 << " && "
387 <<
"x < " <<
FIXED(5,3) <<
x[1]
388 << ")"
389 << " * "
390 <<
"(" <<
FIXED(5,3) <<
y[0] <<
" + " <<
FIXED(5,3) << (
y[1] -
y[0]) <<
" * (x - " <<
FIXED(5,3) <<
x[0] <<
") / " <<
FIXED(5,3) << (
x[1] -
x[0]) <<
")";
391 os << "\n";
392
395 z[1] = z[0];
396 }
397
400
401 os << " + "
402 << "("
403 <<
"x < " <<
FIXED(5,3) <<
x[1]
404 << ")"
405 << " * "
406 <<
"(" <<
FIXED(5,3) <<
y[0] <<
" + " <<
FIXED(5,3) << (
y[1] -
y[0]) <<
" * (x - " <<
FIXED(5,3) <<
x[0] <<
") / " <<
FIXED(5,3) << (
x[1] -
x[0]) <<
")";
407 os << "\n";
408
409 string buffer = os.str();
410
412
413 for (string::iterator i = buffer.begin(); i != buffer.end(); ++i) {
414 if (*i == '\n') {
415 *i = ' ';
416 }
417 }
418
419 f1 =
new TF1(
"f1", buffer.c_str(), xmin, xmax);
420
421 h1.GetListOfFunctions()->Add(f1);
422 }
423
424
426
427 out <<
JMeta(argc, argv);
428
429 out << *h2 << H0 << h1;
430
434
435 if (f1 != NULL) {
436
438
439 out << *(
f1->GetFormula());
440 }
441
442 out.Write();
443 out.Close();
444
445 if (in != NULL) {
446 in->Close();
447 }
448}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Double_t g1(const Double_t x)
Function.
int numberOfBins
number of bins for average CDF integral of optical module
static const char * getName()
Get name of energy correction formula.
double getIntersection(const JVector3D &pos) const
Get longitudinal position along axis of position of closest approach with given position.
const JPosition3D & getPosition() const
Get position.
JTime & add(const JTime &value)
Addition operator.
void move(const double step, const double velocity, const JGeane &geane)
Move vertex along this track with given velocity.
void setE(const double E)
Set energy.
double getE() const
Get energy.
Exception for parsing value.
Wrapper class around string.
Utility class to parse command line options.
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
static const int JMUONENERGY
static const int JENERGY_ENERGY
uncorrected energy [GeV] from JEnergy.cc
const JPolynome f1(1.0, 2.0, 3.0)
Function.
JTrack3E getTrack(const Trk &track)
Get track.
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
bool is_neutrino(const Trk &track)
Test whether given track is a 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.
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
int getParameter(const std::string &text)
Get parameter number from text string.
T pow(const T &x, const double y)
Power .
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.
const char *const neutrino_t
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Auxiliary data structure for floating point format specification.
Type definition of range.
Auxiliary class to test history.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
General purpose sorter of fit results.
Data structure for graph data.
void put(const Double_t x, const Double_t y, const Double_t ex, const Double_t ey)
Put data.
Auxiliary data structure to build TGraphErrors.
Auxiliary data structure to build TGraph.
Auxiliary class for defining the range of iterations of objects.
const JLimit & getLimit() const
Get limit.
static counter_type max()
Get maximum counter value.
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
double E
Energy [GeV] (either MC truth or reconstructed)
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Reconstruction type dependent comparison of track quality.