Re: [ROOT] How to initialize TH1F* aPtr[]?

From: Exaos Lee (schlie@iris.ciae.ac.cn)
Date: Tue Feb 10 2004 - 16:49:23 MET


First, thank you all who has answered my question!

> 
> You can use either STL container classes or ROOT container classes.
> 
>   For example you may define your 
> 
>       stl::vector<TH1F *> pH1Farr;
I use TObjArray and find it is more convinient. :) I can also assign a 
(TTree*) to the TObjArray object:

TObjArray  aaa;
aaa.Add(new TH1F(...));
aaa.Add(new TTree(...));
((TH1F *)aaa[0])->Print();
...

I begin to understand why there are so many container classes.

> 
>   and then use it in your code:
> 
> int ERootAnalysis::InitHist(int n)
> {  
>   for(int i=0;i<n;i++) {
>     TString hName = "h1f_"; hName += i;
>     pH1Farr.push_back(new TH1F(hName.Data(),"",1000,0,1000));
>   }
> 
> 
> I would like to mention your
>     if(!pH1FArr[i]) errNum+=-1;
> 
> is useless because the operator "new" ALWAYS return non-zero pointer.
> 



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