void test()
{
TFile *IFile = new TFile("/mnt/c/Users/mn/root/inte012013.root");
TH1F *det1 = (TH1F *)IFile->Get("det1");
float X[100], Y[100];
int N(0);
for(int n(10); n < 74; n++)
{
X[N] = det1->GetBinCenter(n);
Y[N] = det1->GetBinContent(n);
N++;
}
TF1 *f = new TF1("f", "pol1", 0, 2);
TGraph *g = new TGraph(N, X, Y);
g->SetMarkerStyle(20);
g->Draw("AP");
g->Fit(f, "R");
// Now, to save the TGraph and the fit function to a new ROOT file
TFile *outputFile = new TFile("/mnt/c/Users/mn/root/output.root", "RECREATE");
g->Write("graph");
f->Write("fitFunction");
// Close the files
outputFile->Close();
IFile->Close();
}
Fit is disappearing when changing scale in tbrowser