23 {
24 if (argc !=3) {
25 cout <<
"Usage: " <<
argv[0] <<
" input.root output.root" << endl;
26 return 1;
27 }
28
29 auto fin = make_unique<TFile>(argv[1],
"READ");
30 if (fin == nullptr) {
31 cerr <<
"Could not open input file " <<
argv[1] << endl;
32 return 2;
33 }
34 auto fout = make_unique<TFile>(argv[2],
"RECREATE");
35 if (
fout ==
nullptr) {
36 cerr <<
"Could not open output file " <<
argv[2] << endl;
37 return 2;
38 }
39
40 auto etaLegFunc = [](
double*
x,
double*
par){
41 double tanhEtaSq = std::tanh(
x[0]);
42 tanhEtaSq = tanhEtaSq*tanhEtaSq;
43
44
45 double lp2 = 1.5*tanhEtaSq - 0.5;
46 double lp4 = 0.125*(35.*tanhEtaSq*tanhEtaSq - 30.*tanhEtaSq + 3.);
47 double lp6 = 0.0625*(231*tanhEtaSq*tanhEtaSq*tanhEtaSq - 315*tanhEtaSq*tanhEtaSq + 105*tanhEtaSq - 5);
48 return par[0]*(1. +
par[2]*(lp2-1) +
par[4]*(lp4-1) +
par[6]*(lp6-1)) +
49 par[1]*(1. + par[3]*(lp2-1) + par[5]*(lp4-1) + par[7]*(lp6-1))/
x[1];
50 };
51
52
53 TIter
next(
fin->GetListOfKeys());
54 while (TObject* obj =
next()) {
55 string objName =
obj->GetName();
56 cout << "Fitting " << objName << endl;
57 TGraph2DErrors*
gr =
nullptr;
60 cerr <<
"Could not retrieve " <<
obj->GetName()
61 << " as a TGraph2DErrors." << endl;
62 continue;
63 }
64 TF2* func = new TF2(objName.data(), etaLegFunc, -2.5, 2.5, 0.1, 100.0, 8);
65
66 func->SetNpy(200);
67 func->SetParameters(0.02, 0.1, 0.1, 0.1, 0., 0., 0., 0.);
68 func->SetParLimits(0, 0., 5.);
69 func->SetParLimits(1, 0., 5.);
71 func->SetParLimits(2, -ext, ext);
72 func->SetParLimits(3, -ext, ext);
73 func->SetParLimits(4, -ext, ext);
74 func->SetParLimits(5, -ext, ext);
75 func->SetParLimits(6, -ext, ext);
76 func->SetParLimits(7, -ext, ext);
77
78
79
80 func->FixParameter(6, 0.);
81 func->FixParameter(7, 0.);
83 cout <<
"ndf, g.N = " <<
result->Ndf() <<
", " <<
gr->GetN() << endl;
84 func->Write();
85 }
86
87
88 return 0;
89}