Re: [ROOT] how use a string in a loop

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri May 14 2004 - 10:31:15 MEST


Hi Francesco,

Do:

    TH1D *h = Slice->ProjectionY(Form("Slice_%d",i),i,i); 
    h->Fit("myfunc"); 

Rene Brun

<-----At this line I get an errorFrancesco Perfetto wrote:
> 
> Hi Rene,
> 
> I have a problem with Form():
> now I have 30 slice with name slice_1,...,slice_30;
> How Can I take this slice to fit it ?
> 
> ....
> Tf1 *myfunc = new TF1("myfunc","gaus");
> 
> for(Int_t i=1; 1<31; i++){
>     Slice->ProjectionY(Form("Slice_%d",i),i,i);
>     Form("Slice_%d",i)->Fit("myfunc"); <-----At this line I get an error
> ...
> }
> When I run the script I have:
> 
> root [3] .L histo_slice_ris_ene.C
> root [4] slices()
> Error: non class,struct,union object Form("sct_%d",i) used with . or ->
> FILE:histo_slice_ris_ene.C LINE:13
> *** Interpreter error recovered ***
> 
> Thanks
> Francesco.
> 
> Il lun, 2004-04-26 alle 19:49, Rene Brun ha scritto:
> > Francesco,
> >
> > Instead of:
> >     Slice->ProjectionY("Slice_i",i,i);
> > do
> >     Slice->ProjectionY(Form("Slice_%d",i),i,i);
> >
> > Rene Brun
> >
> > On Mon, 26 Apr 2004, Perfetto
> > Francesco wrote:
> >
> > > Hi All,
> > >
> > > I have the following problem:
> > > I have to do many slice of a bidimensional histogram, and I would like to
> > > call it "Slice_1", "Slice_2", ..., etc. etc.
> > >
> > > I make this in my script:
> > >
> > > TFile *f1 = new TFile("MC.root");
> > > TFile *f2 = new TFile("proiezioni_MC_30x70.root","RECREATE");
> > > TTree *t = (TTree*)f1->Get("res");
> > > TH2D *Slice = new TH2D("Slice","Slice",30,0,1,70,-1,2);
> > >
> > > ...
> > >
> > > for(Int_t i=1;i<31;i++)
> > >    Slice->ProjectionY("Slice_i",i,i);
> > >
> > > ...
> > >
> > > f2->Write();
> > >
> > > But I haven't that I want.
> > > Infact all Slice are named Slice_i.
> > > Can anyone help me?
> > >
> > > Thanks
> > > Francesco.
> > >
> > > I use RedHat 9.0 with root 4.00/03
> > >
> >



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:08 MET