Integral not working?

I am trying to compute the integral of my data by running the following script:

auto graph = new TGraphErrors("./true_spectra_110deg_28.txt","%lg %lg %lg %lg");
        graph->SetTitle("Compton Scattering for CS-137 (Actual-Background 110 Degrees); Energy (keV); Number of Photons");
        graph->SetMarkerStyle(8);
        graph->SetMarkerSize(.5);
        graph->SetMarkerColor(1);
        graph->GetYaxis()->SetTitleOffset(1.3);
        graph->Draw("PEASAME"); //PEASame
    cout<<graph->Integral(24,1622)<<endl;       //16825.4
    cout<<graph->Integral(24,400)<<endl;        //4661.11
    cout<<graph->Integral(401,1600)<<endl;      //30675.6 

I don’t know why I get the values that are in the comments, it doesn’t make any sense when looking at the data. My objective is to simply integrate the data, but I don’t know if this script gives the right result. Any suggestions are much appreciated.

true_spectra_110deg_28.txt (73.3 KB)

Read what Integral does for TGraphs. Maybe you want the integral of histograms, not TGraph (or try forcing first and last points at y=0).

1 Like

Yes indeed, I convert my data to a histogram and the integral works just fine, thank you for explaining!