Re: [ROOT] string in a loop

From: Mike Kordosky (kordosky@mail.hep.utexas.edu)
Date: Mon Apr 26 2004 - 20:25:33 MEST


Hi,

You want to do this:

for(Int_t i=1;i<31;i++){
    TString name="Slice_"; name+=i;    
    TH1* h=Slice->ProjectionY(name.Data(),i,i);
    // the following is not necessary by default
    // it depends on settings in your rootlogon.C file 
    h->SetDirectory(f2);
}

mike

> 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
> 

-- 
Graduate Research Assistant  // High Energy Physics Lab
kordosky@hep.utexas.edu     // University of Texas at Austin
kordosky@fnal.gov	   //
ph: (512) 471-8426 (RLM Lab, Office)
    (512) 475-8673 (ENS Lab)



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