# Trouble with Integral() method for ROC curves

**URL:** <https://root-forum.cern.ch/t/trouble-with-integral-method-for-roc-curves/56182>\
**Category:** Newbie\
**Tags:** root\
**Created:** [August 28, 2023, 8:11pm UTC](https://root-forum.cern.ch/t/trouble-with-integral-method-for-roc-curves/56182 "2023-08-28T20:11:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TPeters1996](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@TPeters1996](https://root-forum.cern.ch/u/TPeters1996)\
**Post date:** [August 28, 2023, 8:11pm UTC](https://root-forum.cern.ch/t/trouble-with-integral-method-for-roc-curves/56182/1 "2023-08-28T20:11:22Z")

</div>

I am trying to calculate the integral of my ROC curves for background rejection vs signal efficiency using the Integral() method described in the ROOT TH1:Integral reference guide.  
Instead of returning values between 0 and 1. For values around 0.5, indicating a straight line ROC curve, I am instead receiving values around 0 with values trending upwards towards some value from there. I am not sure why the integral method would read out 0 for what is basically a triangle.

Here is the code I am using:

```
                    // Calculate Background Vs. Signal Efficiency
                    int nSigBins = hist->GetNbinsX();
                    int nBkgBins = bkghist->GetNbinsX();

                    double TSigIntegral = hist->Integral();
                    double TBkgIntegral = bkghist->Integral();

                    std::vector<double> LeftSigEff(nSigBins, 0.0);
                    std::vector<double> RightSigEff(nSigBins, 0.0);
                    std::vector<double> LeftBkgEff(nBkgBins, 0.0);
                    std::vector<double> RightBkgEff(nBkgBins, 0.0);

                    for (int i = 0; i < nSigBins; i++) {
                        LeftSigEff[i] = (hist->Integral(0, i) / TSigIntegral);
                        RightSigEff[i] = (hist->Integral(i, nSigBins) / TSigIntegral);
                    }

                    for (int i = 0; i < nBkgBins; i++) {
                        LeftBkgEff[i] = 1 - (bkghist->Integral(0, i) / TBkgIntegral);
                        RightBkgEff[i] = 1 - (bkghist->Integral(i, nBkgBins) / TBkgIntegral);
                    }

                    // Plot Efficiency Comparison of Background and Signal
                    TCanvas *LeftCanvas = new TCanvas("LeftCanvas", "LeftCanvas", 800, 600);
                    TLegend *LeftLegend = new TLegend(0.6, 0.6, 0.9, 0.9);
                    LeftCanvas->cd();
                    
                    auto g = new TGraph(nSigBins, &LeftBkgEff[0], &LeftSigEff[0]);
                    LeftCanvas->SetTitle("Left Cut Efficiency Comparison");
                    g->GetXaxis()->SetTitle("#epsilon_{Sig}");  
                    g->GetYaxis()->SetTitle("1 - #epsilon_{Bkg}");
                    g->GetYaxis()->SetRangeUser(0, 1);
                    g->GetXaxis()->SetRangeUser(0, 1);
                    std::cout << "----------------------------------------" << std::endl;
                    std::cout << "Left Cut Efficiency Comparison" << std::endl;
                    std::cout << "Decay Channel: " << decayinfo << std::endl;
                    std::cout << "Observable: " << obs << std::endl;
                    std::cout << "Particle: " << part << std::endl;
                    std::cout << "ROC Curve Plot Integral: " << 100*g->Integral() << std::endl;
                    g->Draw("AC*");
                    LeftCanvas->SaveAs(("Output/RequestAnalysis/AllSMass/" + decayinfo + "_" + part + "_" + obs + "_LeftEfficiencyComparison.png").c_str());

```

Where hist and bkghist are histograms loaded in separately.

## Here is some of my output: Left Cut Efficiency Comparison Decay Channel: ttbb Observable: jet Particle: N ROC Curve Plot Integral: 31.4656

## Left Cut Efficiency Comparison Decay Channel: ttbb Observable: jet Particle: pt ROC Curve Plot Integral: 2.94997

## Left Cut Efficiency Comparison Decay Channel: ttbb Observable: E Particle: met ROC Curve Plot Integral: 27.6885

## Left Cut Efficiency Comparison Decay Channel: ttbb Observable: E Particle: st ROC Curve Plot Integral: 2.8683

Left Cut Efficiency Comparison  
Decay Channel: ttbb  
Observable: N  
Particle: tau  
ROC Curve Plot Integral: 0

I multiplied the output by 100 simply for readability.

\_ROOT Version: 6.24/06  
\_Platform: lxplus  
_Compiler:_ Not Provided

* * *

---

<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:** [August 29, 2023, 6:09am UTC](https://root-forum.cern.ch/t/trouble-with-integral-method-for-roc-curves/56182/2 "2023-08-29T06:09:48Z")

</div>

The histogram bins go from 1 to nbins (included), not 0 to nbins-1 (bin = 0 and nbins+1 are under/overflow), so that may be an issue in your loops and integrals.
