#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include "TFile.h"
#include "TGraph2DErrors.h"
#include "TF2.h"
#include "TFitResult.h"
Go to the source code of this file.
|
int | main (int argc, char **argv) |
|
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 23 of file graph_to_function.cxx.
25 cout <<
"Usage: " <<
argv[0] <<
" input.root output.root" << endl;
29 auto fin = make_unique<TFile>(
argv[1],
"READ");
31 cerr <<
"Could not open input file " <<
argv[1] << endl;
34 auto fout = make_unique<TFile>(
argv[2],
"RECREATE");
35 if (
fout ==
nullptr) {
36 cerr <<
"Could not open output file " <<
argv[2] << endl;
40 auto etaLegFunc = [](
double*
x,
double*
par){
41 double tanhEtaSq = std::tanh(
x[0]);
42 tanhEtaSq = tanhEtaSq*tanhEtaSq;
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];
53 TIter
next(
fin->GetListOfKeys());
55 string objName =
obj->GetName();
56 cout <<
"Fitting " << objName << endl;
57 TGraph2DErrors*
gr =
nullptr;
60 cerr <<
"Could not retrive " <<
obj->GetName()
61 <<
" as a TGraph2DErrors." << endl;
64 TF2* func =
new TF2(objName.data(), etaLegFunc, -2.5, 2.5, 0.1, 100.0, 8);
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);
80 func->FixParameter(6, 0.);
81 func->FixParameter(7, 0.);
83 cout <<
"ndf, g.N = " <<
result->Ndf() <<
", " <<
gr->GetN() << endl;