Way to apply cut on histogram

Hello all,

I am reading histogram from a root file like

                tf[i] = new TFile(fname[i]);
		th[i] = (TH1F*)tf[i]->Get(Form("%s",var1.c_str()));
		th[i]->SetTitle("");
		th[i]->Rebin(nbins);
		th[i]->GetXaxis()->SetRangeUser(min,max);

Is there any way to apply cut directly here like when we apply cut while reading the branch of a tree like

		tt[i] = (TTree*) tf[i]->Get("demo/tree");
		th[i] = new TH1F(Form("th%i",i),"",nbins,min,max);
		tt[i]->Draw(Form("%s>>th%i",var1.c_str(),i), [b]cut.c_str()[/b], "goff");

Hi,

no this is not possible. Once the histogram is filled, the data has been “reduced”.

Danilo

No information about any “cut” is present in the histogram (note that a “cut” often uses different TTree leaves than the ones that are used to fill the histogram).

The only cuts you can apply on histogram are the graphical cuts:

{
   TCanvas *c = new TCanvas("c","example",0,0,700,600);
   c->Divide(1,2);

   TCutG *gcut1 = new TCutG("gcut1",8);
   gcut1->SetPoint(0,-0.646552,0.932203);
   gcut1->SetPoint(1,-1.26437,0.105932);
   gcut1->SetPoint(2,-0.574713,-1.10169);
   gcut1->SetPoint(3,0.948276,-0.338983);
   gcut1->SetPoint(4,1.07759,0.720339);
   gcut1->SetPoint(5,-0.316092,-0.0847458);
   gcut1->SetPoint(6,-0.45977,0.402542);
   gcut1->SetPoint(7,-0.646552,0.932203);

   TFile f("hsimple.root");
   TH2F *hpxpy = (TH2F*)f.Get("hpxpy");
   TH1D *hppx = hpxpy->ProjectionX("ProjectionX",22,23,"[gcut1]");

   printf("Number of entries = %d\n",hppx->GetEntries());

   c->cd(1);
   hpxpy->SetFillColor(kBlue);
   hpxpy->DrawCopy("box");
   hpxpy->SetFillColor(kRed);
   hpxpy->Draw("same box [gcut1]");

   c->cd(2);
   hppx->Draw();
}