# Counting the number of entries in a TCutG

**URL:** <https://root-forum.cern.ch/t/counting-the-number-of-entries-in-a-tcutg/51731>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [September 27, 2022, 6:33pm UTC](https://root-forum.cern.ch/t/counting-the-number-of-entries-in-a-tcutg/51731 "2022-09-27T18:33:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![asanch25](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/asanch25/32/20206_2.png) [@asanch25](https://root-forum.cern.ch/u/asanch25)\
**Post date:** [September 27, 2022, 6:33pm UTC](https://root-forum.cern.ch/t/counting-the-number-of-entries-in-a-tcutg/51731/1 "2022-09-27T18:33:14Z")

</div>

Hi, I am having issues with getting the number of entries within a graphical cut. The histogram I am looking at is within a directory in the root file, that is the reason for cd’ing into a directory at the beginning. My cut does not seem to report the number of counts within the cut region, but rather the total number of entries in the entire histogram. All of the tutorials I’ve seen online have done this automatically, so I’m not sure what I’m missing.

```auto
void alpha_cut()
{
    //open the file and cd into the directory where the tof vs energy histogram is
    TFile *sfile = TFile::Open("run2241_raw_histograms.root");
    sfile->cd("focal_plane_detector_time_vs_energy");

    //get the tof vs energy histogram
    TH2F *tof = (TH2F*)gDirectory->Get("h_tof_e");

    //define the cut we want
    TCutG *cutg = new TCutG("ilikeurcutg",5);
    cutg->SetVarX("h_tof_e_../../output/run2241_raw_histograms.root");
    cutg->SetVarY("");
    cutg->SetTitle("Graph");
    cutg->SetFillStyle(1000);
    cutg->SetPoint(0,4560,24);
    cutg->SetPoint(1,4440,24);
    cutg->SetPoint(2,4440,27);
    cutg->SetPoint(3,4560,27);
    cutg->SetPoint(4,4560,24);

    //draw the plot and the cut region
    tof->Draw("[ilikeurcutg]");
    cutg->Draw("l");
    tof->GetXaxis()->SetRangeUser(4000,4600);
    tof->GetYaxis()->SetRangeUser(20,30);
}

```

and here is the output of running this macro in root,

 ![tcutattempt](https://root-forum.cern.ch/uploads/default/original/3X/7/a/7a078b231743e9f8459708c02a3c4703ae861c47.png)

_ROOT Version:_ 6.24.06  
_Platform:_ Linux  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 28, 2022, 7:19am UTC](https://root-forum.cern.ch/t/counting-the-number-of-entries-in-a-tcutg/51731/2 "2022-09-28T07:19:22Z")

</div>

```auto
cutg->SetVarX("h_tof_e_../../output/run2241_raw_histograms.root");

```

Did you really set VarX to a root file? what does that mean ?

In any case, according to your plot, your cut is a square containing all the histogram data.

---

<div class="post-metadata">

**Author:** ![asanch25](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/asanch25/32/20206_2.png) [@asanch25](https://root-forum.cern.ch/u/asanch25)\
**Post date:** [September 28, 2022, 7:32pm UTC](https://root-forum.cern.ch/t/counting-the-number-of-entries-in-a-tcutg/51731/3 "2022-09-28T19:32:20Z")

</div>

The portion of the code where the cut is done is something I just copied and pasted after creating a cut in the TBrowser and generating the .C file. Also I should have mentioned that the number of entries listed in the legend is the number of entries in the entire histogram, not just in my cut. I want the number of entries just within the cut.

I’ve figured out a way to print out the number of counts in the region (~3000), but I was just wondering if there was a way for that to show up graphically.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 29, 2022, 7:56am UTC](https://root-forum.cern.ch/t/counting-the-number-of-entries-in-a-tcutg/51731/4 "2022-09-29T07:56:18Z")

</div>

Ok, can you post the data so we can run your code and see what’s wrong ?
