Hi there
I am trying to find the number of counts inside the Graphical cut on my 2D histo which I created using graphical cut in gPad and saved that cut as a cut.c file.
How can I do that, I already tried to use IntegralHist () but failed.
_ROOT Version:6.04/06
Platform: Not Provided
Compiler: Not Provided
here is what I want to say, I want to know, how many events do exist inside this graphical cut .
Hi,
you can just apply the graphical cut created to your data.
Like
tree->Draw("TSd2rEnergy: TSd1rEnergy", "all other cuts +CUTG","goff")
in this way you will get the number of counts inside the CUTG and all the other cuts you applied for drawing the TH2D
Best
Stefano
PS
If you want avoid to overwrite your graphical cut before creating a new one remember to
CUTG->SetName("myCutG1)
and use the new name inside the list of cut.
sorry didn’t understand it.
Here I am attaching the root file which contains TSd1rEnergy:TSd2rEnergy histogram and cut1.c is my graphical cut file.
Help will be appreciated.
cut1.c (638 Bytes)
output.root (34.5 KB)
Try this code
void count_hist()
{
TCutG *cutg = new TCutG("CUTG",10);
cutg->SetVarX("plot");
cutg->SetVarY("");
cutg->SetTitle("Graph");
cutg->SetFillStyle(1000);
cutg->SetPoint(0,2449.88,791.422);
cutg->SetPoint(1,2637.08,840.748);
cutg->SetPoint(2,2637.08,840.748);
cutg->SetPoint(3,2721.62,694.914);
cutg->SetPoint(4,2649.15,568.382);
cutg->SetPoint(5,2471.01,602.696);
cutg->SetPoint(6,2471.01,602.696);
cutg->SetPoint(7,2446.86,787.132);
cutg->SetPoint(8,2449.88,787.132);
cutg->SetPoint(9,2449.88,791.422);
cutg->Draw("");
TFile *f=new TFile("output.root","open");
TH2F *h = (TH2F*)g->Get("h");
int i,j=0;
double sum=0;
for(i=1;i<=h->GetNbinsX();i++)
{
for(j=1;j<=h->GetNbinsY();j++)
{
if(cutg->IsInside())
sum+=h->GetBinContent(i,j);
}
}
cout<<"Event inside the CutG "<<sum;
}
In my previous message I supposed you had the data used to fill the histogram.
So if you had the CutG and the data you can just fill an histogram with data inside the CutG
sorry few small errors
void count_hist()
{
TCutG *cutg = new TCutG("CUTG",10);
cutg->SetVarX("plot");
cutg->SetVarY("");
cutg->SetTitle("Graph");
cutg->SetFillStyle(1000);
cutg->SetPoint(0,2449.88,791.422);
cutg->SetPoint(1,2637.08,840.748);
cutg->SetPoint(2,2637.08,840.748);
cutg->SetPoint(3,2721.62,694.914);
cutg->SetPoint(4,2649.15,568.382);
cutg->SetPoint(5,2471.01,602.696);
cutg->SetPoint(6,2471.01,602.696);
cutg->SetPoint(7,2446.86,787.132);
cutg->SetPoint(8,2449.88,787.132);
cutg->SetPoint(9,2449.88,791.422);
cutg->Draw("");
TFile *f=new TFile("output.root","open");
TH2F *h = (TH2F*)f->Get("h");
int i,j=0;
double sum=0;
for(i=1;i<=h->GetNbinsX();i++)
{
for(j=1;j<=h->GetNbinsY();j++)
{
if(cutg->IsInside( ((TAxis*)h->GetXaxis())->GetBinCenter(i) , ((TAxis*)h->GetYaxis())->GetBinCenter(j) ))
sum+=h->GetBinContent(i,j);
}
}
cout<<"Event inside the CutG "<<sum;
}
Sorry, I am again getting an error
Just change h2 with h inside the if
I did that, but still nothing. Appreciating your help.
Very sorry in the if you need a , instead of &&.
I will edit the code above
Hi there, very big thanks. Code is working now. I have tested it