A fitting issue

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

Welcome to the root forum.

We cannot try your macro because we do not have the data file.

Does it work if you the output part at the end ?

No it doesn’t work

[can you provide inte012013.root ?

Says new user can’t upload link

Any other way I can share?

No need , I created a simple graph. The following macro is ok:

{
    float X[100], Y[100];
    int N(0);

    for(int n(10); n < 74; n++)
    {
        X[N] = n;
        Y[N] = 2.*n;
        N++;
    }

    TF1 *f = new TF1("f", "pol1", 0, 2);
    TGraph *g = new TGraph(N, X, Y);
    g->SetMarkerStyle(20);
    g->Fit(f);
    g->Draw("AP");
}

this worked. Thank you.
I have one more query but not able to upload script and also it has more character than allowed how should i share?

You are not allowed to attached the file ?

Issue sorted, Thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.