Re: [ROOT] problem over iterating over cuts

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sun Dec 02 2001 - 19:23:41 MET


Hi Aron,
   
   I cannot test your script. However, I see a big bug. Replace the lines:
   
   TCut cut[0] = "TKR_Fit_Type==22+(10**MC_logE)<10";
   TCut cut[1] = "TKR_Fit_Type==22+(10**MC_logE)<20";
   TCut cut[2] = "TKR_Fit_Type==22+(10**MC_logE)<30";
   TCut cut[3] = "TKR_Fit_Type==22+(10**MC_logE)<40";
   TCut cut[4] = "TKR_Fit_Type==22+(10**MC_logE)<50";
   TCut cut[5] = "TKR_Fit_Type==22+(10**MC_logE)<60";
   TCut cut[6] = "TKR_Fit_Type==22+(10**MC_logE)<70";
   TCut cut[7] = "TKR_Fit_Type==22+(10**MC_logE)<80";
   TCut cut[8] = "TKR_Fit_Type==22+(10**MC_logE)<90";
   TCut cut[9] = "TKR_Fit_Type==22+(10**MC_logE)<100";
by
   TCut cut[1];
   cut[0] = "TKR_Fit_Type==22+(10**MC_logE)<10";
   cut[1] = "TKR_Fit_Type==22+(10**MC_logE)<20";
   cut[2] = "TKR_Fit_Type==22+(10**MC_logE)<30";
   cut[3] = "TKR_Fit_Type==22+(10**MC_logE)<40";
   cut[4] = "TKR_Fit_Type==22+(10**MC_logE)<50";
   cut[5] = "TKR_Fit_Type==22+(10**MC_logE)<60";
   cut[6] = "TKR_Fit_Type==22+(10**MC_logE)<70";
   cut[7] = "TKR_Fit_Type==22+(10**MC_logE)<80";
   cut[8] = "TKR_Fit_Type==22+(10**MC_logE)<90";
   cut[9] = "TKR_Fit_Type==22+(10**MC_logE)<100";
      
Rene Brun


On Fri, 30 Nov 2001, Aron, Navneet wrote:

> Hi All,
> I am working at SLAC in experiment group. I am having the following problem with interating over cuts.
> scenario: we have two root files -say one is a signal root file and other a background root file.
> i want to find out the number of  events in each of the two root files..(the signal  root file and background root file)  when a particular variable say "REC_Outside_Hit_Ratio"
> takes certain values...So we apply cuts for various valures of this variable and for each cut we assemble the number of  events.
> Now doing it manually takes a lot of effort. So in order to automate, we need to apply cuts iteratively  (please refer the  inline attached macro) where cuts are applied one after the another in the same macro and at every cut we capture the number of events  and other statistical valures in a  data file.
> Please let me know what is wron with the approach that I am following .And what could be a way to do it?
> Thanks a lot.
> Yours sincerely,
> Navneet
> 
> PS: please forgive me if this is not the right way to write to this mailing list
> 
> 
> 
> 
> ***********************************************************************************************************************************************************************
> {
> 
> //TTree *sig = (TTree*) f1->Get("t1");
> TTree *sig = (TTree*) f1->Get("PDR/t1");
> TTree *back = (TTree*) f2->Get("PDR/t1");
> 
>   TCanvas *c1 = new TCanvas("c1","",0,10,700,700);
>   TText *c1title = new TText(0.2,0.96,"MC Energy [all gamma]");
>   c1title->SetTextSize(0.03);
>   c1title->Draw();
> c1->SetFillColor(10);
> 
> 
>   TPad *hpad[13];
> 
>   hpad[0]  = new TPad( "pad0","This is  pad0" ,0.02,0.02,0.95,0.91,21);
>   hpad[1]  = new TPad( "pad1","This is  pad1" ,0.51,0.47,0.98,0.91,21);
> 
> 
> 
>   TH1F *h[4];
> 
>   /*****
>   *****/
> 
> Int_t NUMPLOT = 1;
> Float_t xmax = 10.5;
> Float_t xmin = 0.5;
> Int_t xbins = 50; 
>   h[0]  = new TH1F( "0", "p0" ,xbins,xmin,xmax);
>   h[1]  = new TH1F( "1", "p1" ,xbins,xmin,xmax);
> 
> 
>   hpad[0]->Draw();
>   hpad[0]->cd();
> 
> TCut cut[0] = "TKR_Fit_Type==22+(10**MC_logE)<10";
> TCut cut[1] = "TKR_Fit_Type==22+(10**MC_logE)<20";
> TCut cut[2] = "TKR_Fit_Type==22+(10**MC_logE)<30";
> TCut cut[3] = "TKR_Fit_Type==22+(10**MC_logE)<40";
> TCut cut[4] = "TKR_Fit_Type==22+(10**MC_logE)<50";
> TCut cut[5] = "TKR_Fit_Type==22+(10**MC_logE)<60";
> TCut cut[6] = "TKR_Fit_Type==22+(10**MC_logE)<70";
> TCut cut[7] = "TKR_Fit_Type==22+(10**MC_logE)<80";
> TCut cut[8] = "TKR_Fit_Type==22+(10**MC_logE)<90";
> TCut cut[9] = "TKR_Fit_Type==22+(10**MC_logE)<100";
> 
> 
> 
> for (int i=0;i<10;i++)
>  {
>  sig->Draw("REC_Outside_Hit_Ratio>>0",cut[i]);
>   back->Draw("REC_Outside_Hit_Ratio>>1",cut[i]);
> /* i am closing the loop here just to verify if this doesn't result in a crash. but it does crash!!
> }
> //  gStyle->SetOptStat(0000);
>   gStyle->SetOptStat(1100);
>   gStyle->SetStatW(0.25);
>   gStyle->SetStatH(0.17);
>   gStyle->SetTitleH(0.06);  // Fraction of title box hight
>   gStyle->SetTitleW(0.30); // Fraction of title box width
>   gStyle->SetTitleX(0.1); // X position of the title box from left
>   gStyle->SetTitleY(1.0); // Y position of the title box from bottom
> 
> 
>  double nsig = h[0]->GetEntries();
> double nback = h[1]->GetEntries();
> 
> h[1]->Draw();
> h[1]->Scale(nsig/nback);
> //h[0]->Scale(nback/nsig);
> 
> h[0]->Draw("same");
> 
> Float_t h0mean =h[0]->GetMean();
> Float_t h0rms  =h[0]->GetRMS();
> Int_t h0events =h[0]->GetEntries();
> Float_t h1mean =h[1]->GetMean();
> Float_t h1rms  =h[1]->GetRMS();
> Int_t h1events =h[1]->GetEntries();
> printf("data \t\t mean \t\t rms \t\t entries \n");
> printf("signal %f \t\t %f \t\t %d \n",h0mean, h0rms, h0events);
> printf("back %f \t\t %f \t\t %d \n",h1mean, h1rms, h1events);
> 
> for(int i=0; i<NUMPLOT; i++) {
>   hpad[i]->GetFrame()->SetFillColor(10); 
>    hpad[i]->SetLogy(1); // log scale
>    hpad[i]->SetLogx(0); // linear scale
>    hpad[i]->SetFillColor(10);
>    hpad[i]->Draw();
>    h[i]->SetLineWidth(2);
>    h[1]->SetLineColor(4);
>    h[0]->SetLineColor(2); // h0 is gamma,
> 
>    hpad[i]->cd();
>  }
> 
> /*   h[0]->SetXTitle("REC_Outside_Hit_Ratio");
>    h[0]->SetYTitle("Nevents");
>    h[0]->SetLabelSize(0.03,"X");
>    h[0]->SetLabelSize(0.03,"Y");
>    h[0]->SetMaximum(2000);  //  zoom
> //   h[0]->SetMinimum(0.5);
>    h[0]->SetXTitle("REC_Outside_Hit_Ratio");
>    h[0]->SetYTitle("Nevents");
>    h[0]->SetTitleSize(0.03,"X");
>    h[0]->SetTitleSize(0.03,"Y");
>    h[0]->SetTitleOffset(1.0,"X");
>    h[0]->SetTitleOffset(1.2,"Y");
> */
> 
> // c1->Print(i.gif);
> 
> 
> 
> }
> 
> 



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:10 MET