# Integral not working?

**URL:** <https://root-forum.cern.ch/t/integral-not-working/42329>\
**Category:** Newbie\
**Created:** [November 16, 2020, 9:57pm UTC](https://root-forum.cern.ch/t/integral-not-working/42329 "2020-11-16T21:57:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [November 16, 2020, 9:57pm UTC](https://root-forum.cern.ch/t/integral-not-working/42329/1 "2020-11-16T21:57:45Z")

</div>

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

```auto
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](https://root-forum.cern.ch/uploads/short-url/h0iAHdZA04EQqw1uv8qy0V9XSLb.txt) (73.3 KB)

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [November 17, 2020, 5:14am UTC](https://root-forum.cern.ch/t/integral-not-working/42329/2 "2020-11-17T05:14:39Z")

</div>

Read what [Integral](https://root.cern/doc/master/classTGraph.html#a06b6dfc69d4fe9336ade71a47864f974) does for TGraphs. Maybe you want the integral of histograms, not TGraph (or try forcing first and last points at y=0).

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [November 18, 2020, 4:33am UTC](https://root-forum.cern.ch/t/integral-not-working/42329/3 "2020-11-18T04:33:33Z")

</div>

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