Re: several cuts

From: Rene BRUN <brun_at_mail.cern.ch>
Date: Sun, 13 Mar 2005 00:03:28 +0100 (MET)


Hi Boris,

You can do something like:

char selection[1000]; selection[0] = 0;
char cutname[20];
for(int i = 0; i< 15; i++)
{
 sprintf(cutname,"cut%d",convert(i));
 TCutG *cut[i] = (TCutG*)gPad->WaitPrimitive("CUTG","CutG");

 cut[i] -> SetName(cutname);
 cut[i] -> SetVarX("x");
 cut[i] -> SetVarY("y");

 if (i !=0) strcat(selection," || ");
 strcat(selection,cutname);
}

t->Draw("x >> histo",selection);

Rene Brun

On Sat, 12 Mar
2005, Boris
Skorodumov wrote:

> Thank you Rene,
>
> but the question was about optimal solution to do it. for example, i have 15
> cuts in one plot. it means i should repeat the same peace of code 15 times. is
> it possible to orginize loop somehow ?
>
> i was thinking to do it in the next way:
> ......
>
> for(int i = 0; i< 15; i++)
> {
> string name[i] = "cut" + convert(i);
> TCutG *cut[i] = (TCutG*)gPad->WaitPrimitive("CUTG","CutG");
> cut[i] -> SetName(name[i].c_str()); ??????
> cut[i] -> SetVarX("x");
> cut[i] -> SetVarY("y");
> ??????????????????
> }
>
> t->Draw("x >> histo","???????????????");
>
>
> string convert(int number)
> {
> stringstream s;
> s << number;
> return s.str();
> }
> ..............
>
> Or maybe there is different method to do it ?
>
> Thank you very much,
>
> Boris.
>
> --------------------------------------
> | Boris Skorodumov, Graduate Student |
> | Physics Department |
> | University of Notre Dame |
> | Indiana 46556, USA |
> | WWW: http://www.nd.edu/~bskorodo |
> --------------------------------------
>
>
>
>
> Rene BRUN wrote:
>
> > Hi Boris,
> >
> > See a simple example in the attachement
> >
> > Rene Brun
> >
> > On Fri, 11 Mar 2005, Boris Skorodumov wrote:
> >
> >
> > > Dear Rooters,
> > >
> > > if i would like to make several gcuts on 2d histogram and later to make
> > > some
> > > projection on 1d histo, what is the best way to do it ?
> > >
> > > one way is:
> > >
> > > TCutG *cut1 = (TCutG*)gPad->WaitPrimitive("CUTG","CutG");
> > > cut1 -> SetName("cut1");
> > > cut1 -> SetVarX("x");
> > > cut1 -> SetVarY("y");
> > >
> > > TCutG *cut2 = (TCutG*)gPad->WaitPrimitive("CUTG","CutG");
> > > cut2 -> SetName("cut2");
> > > cut2 -> SetVarX("x");
> > > cut2 -> SetVarY("y");
> > >
> > > ........ and so on
> > >
> > > t->Draw("x >> histo","cut1 || cut2 ||...");
> > >
> > > but i am sure, it should be the way to orginize loop.
> > >
> > > thank you.
> > > boris.
> > >
> > > ------------------------------------------------------------------------
> > >
> > > //file twocuts.C
> > > void twocuts() {
> > > //example of two graphical cuts on a 2-d histogram
> > > //used as cuts when making a Tree projection
> > > //file hsimple.root generated by ROOT tutorial hsimple.C
> > > TFile *f = TFile::Open("hsimple.root");
> > > TH2F *hpxpy = (TH2F*)f->Get("hpxpy");
> > > TCanvas *c1 = new TCanvas("c1","cuts",600,800);
> > > c1->Divide(1,2);
> > > c1->cd(1);
> > > hpxpy->Draw();
> > > TCutG *cut1 = new TCutG("cut1",6);
> > > cut1->SetVarX("px");
> > > cut1->SetVarY("py");
> > > cut1->SetPoint(0,-2.12644,1.37712);
> > > cut1->SetPoint(1,-2.95977,-1.7161);
> > > cut1->SetPoint(2,-0.775862,-2.94492);
> > > cut1->SetPoint(3,-0.114943,-0.423729);
> > > cut1->SetPoint(4,-1.52299,-0.614407);
> > > cut1->SetPoint(5,-2.12644,1.37712);
> > > cut1->Draw("l"); TCutG *cut2 = new TCutG("cut2",7);
> > > cut2->SetVarX("px");
> > > cut2->SetVarY("py");
> > > cut2->SetPoint(0,-0.143678,2.16102);
> > > cut2->SetPoint(1,-0.890805,0.783898);
> > > cut2->SetPoint(2,-0.229885,-2.05508);
> > > cut2->SetPoint(3,1.81034,-1.08051);
> > > cut2->SetPoint(4,1.66667,1.03814);
> > > cut2->SetPoint(5,0.201149,0);
> > > cut2->SetPoint(6,-0.143678,2.16102);
> > > cut2->Draw("l");
> > > c1->cd(2);
> > > TNtuple *ntuple = (TNtuple*)f->Get("ntuple");
> > > ntuple->Draw("px","cut1 || cut2");
> > > }
> > >
Received on Sun Mar 13 2005 - 00:03:35 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:06 MET