Counting the number of entries in a TCutG

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.

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,

ROOT Version: 6.24.06
Platform: Linux
Compiler: Not Provided


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.

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.

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