56int main(
int argc,
char **argv)
63 typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
64 typedef JToken<
';'> JToken_t;
67 JTriggeredFileScanner_t inputFile;
82 JParser<> zap(
"Utility program to determine energy correction.");
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") =
"";
99 catch(
const exception& error) {
100 FATAL(error.what() << endl);
107 if (inputFile.size() == 1) {
109 in = TFile::Open(inputFile[0].c_str(),
"READ");
111 if (in != NULL && in->IsOpen()) {
112 h2 = (TH2D*) in->Get(
"h2");
120 for (JMultipleFileScanner_t::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
128 if (p == enigma.end())
129 enigma.push_back(head);
133 catch(
const exception& error) {
138 double Emin = numeric_limits<double>::max();
141 for (vector<JHead>::const_iterator i = enigma.begin(); i!= enigma.end(); ++i) {
144 FATAL(
"Missing neutrino parameters." << endl);
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(); }
151 cout <<
"Neutrino energy range: " << i->cut_nu.E << endl;
152 cout <<
"Number of generated events: " << i->genvol.numberOfEvents << endl;
156 const Double_t xmin = log10(Emin);
157 const Double_t xmax = log10(Emax);
163 Vec offset(0.0, 0.0, 0.0);
165 for (
string filename; inputFile.hasNext(); ) {
167 STATUS(
"event: " << setw(10) << inputFile.getCounter() <<
'\r');
DEBUG(endl);
169 if (filename != inputFile.getFilename()) {
171 filename = inputFile.getFilename();
179 vector<JHead>::const_iterator p = find(enigma.begin(), enigma.end(), head);
182 W = 1.0 / (double) p->genvol.numberOfEvents;
185 cout <<
"File: " << filename <<
" weight " << W << endl;
187 catch(
const exception& error) {
192 multi_pointer_type ps = inputFile.next();
201 for (vector<Trk>::const_iterator i = event->mc_trks.begin(); i != event->mc_trks.end(); ++i) {
213 }
else if (
primary == neutrino_t) {
226 if (evt->begin() == __end) {
230 JEvt::iterator p = min_element(evt->begin(), __end,
quality_sorter);
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));
249 const Int_t nx = h2->GetXaxis()->GetNbins();
250 const Double_t xmin = h2->GetXaxis()->GetXmin();
251 const Double_t xmax = h2->GetXaxis()->GetXmax();
253 const Int_t ny = h2->GetYaxis()->GetNbins();
255 TH1D h1(
"h1", NULL, nx, xmin, xmax);
263 for (Int_t ix = 1; ix <= nx; ++ix) {
269 for (
int iy = 1; iy <= ny; ++iy) {
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);
277 h0->SetBinContent(iy, y);
278 h0->SetBinError (iy, z);
290 TF1 f1(
"f1",
"[0]*TMath::Gaus(x,[1],[2]) + [3]");
295 f1.SetParameter(0, Q.
getWmax());
296 f1.SetParameter(1, x0);
297 f1.SetParameter(2, sigma);
298 f1.SetParameter(3, 0.0);
300 TFitResultPtr
result = h0->Fit(&f1,
"SQ",
"same");
302 if (
result.Get() == NULL) {
303 FATAL(
"Invalid TFitResultPtr " << h0->GetName() << endl);
308 << setw(4) << ix <<
' '
309 <<
FIXED(7,3) << h2->GetXaxis()->GetBinCenter(ix) <<
' '
312 << (
result->IsValid() ?
"" :
"failed") << endl;
317 const Double_t x = h2->GetXaxis()->GetBinCenter(ix);
319 h1.SetBinContent(ix, f1.GetParameter(1));
320 h1.SetBinError (ix, f1.GetParError (1));
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));
333 f1 =
new TF1(
"f1", formula.c_str());
335 if (f1->IsZombie()) {
336 FATAL(
"Function: " << formula <<
" is zombie." << endl);
341 for (vector<JToken_t>::const_iterator i = startValues.begin(); i != startValues.end(); ++i) {
345 for (vector<JToken_t>::const_iterator i = fixedValues.begin(); i != fixedValues.end(); ++i) {
350 FATAL(error << endl);
353 if (option.find(
'S') == string::npos) { option +=
"S"; }
359 Double_t x[2] = { xmin, xmax };
360 Double_t y[2] = { xmin, xmax };
361 Double_t z[2] = { 0.00, 0.00 };
367 <<
"x >= " <<
FIXED(5,3) << xmax
373 for (Int_t ix = nx; ix >= 1; --ix) {
375 x[0] = h1.GetXaxis()->GetBinCenter(ix);
376 y[0] = h1.GetBinContent(ix);
377 z[0] = h1.GetBinError (ix);
379 if (z[0] == 0.0 || !X(x[0])) {
385 <<
"x >= " <<
FIXED(5,3) << x[0]
387 <<
"x < " <<
FIXED(5,3) << x[1]
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]) <<
")";
403 <<
"x < " <<
FIXED(5,3) << x[1]
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]) <<
")";
409 string buffer = os.str();
413 for (string::iterator i = buffer.begin(); i != buffer.end(); ++i) {
419 f1 =
new TF1(
"f1", buffer.c_str(), xmin, xmax);
421 h1.GetListOfFunctions()->Add(f1);
427 out <<
JMeta(argc, argv);
429 out << *h2 << H0 << h1;
439 out << *(f1->GetFormula());