Re: 2 questions about TH1 class

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Jun 01 1998 - 10:25:39 MEST


Diego Casadei wrote:
> 
> Hello Rooters,
> I'd like to have a 2-index array of pointers to TH1 objects.
> 
> I write:
> 
>   static TH1* (histvec[12][6]);
> 
>   for(int i=0;i<6;i++){// don't worry about the sprintf: it does work
>     sprintf(string,"h%d",startvec[i]+30*(ilay-1)+ibar-1+14*isid);
>     histvec[max%12][i]=new TH1*((TH1*)gAMSDisplay->GetRootFile()->Get(string));
>     if(histvec[max%12][i]){
>       // do something
>     }
>   }
> 

Diego,
TH1 is the base class for all histogram classes. You cannot make
an instance of this class directly. Use TH1F, etc.
If you want to create an array of pointers to histograms, use
something like
  TH1F *hlist = new TH1F*[number_of_histograms]

> but I get an error:
> 
> cxx: Error: AMSTOFHist.cxx, line 667: In this statement, the referenced
> type of the pointer value
> "new TH1 ...((TH1 ...)gAMSDisplay->GetRootFile()->Get(string))" is
> "pointer to TH1", which is not compatible with "TH1".
>     histvec[max%12][i]=new
> TH1*((TH1*)gAMSDisplay->GetRootFile()->Get(string));
> ----^
> 
> Another question.
> If I understand, each TH1 object has a unique string identifier.
> I create with "new" many TH1 objects, within different calls of a static
> function.  I guess that if I create an object of TH1 with the same name
> (string) as an existing one, I will not allocate additional space with
> "new" but I will overwrite the existing one.  At least I hope... if not my
> application will use more and more memory...
> 

When an histogram is created with the name of an already existing
histogram, the old histogram is replaced by the new definition
and a WARNING message is printed. This only in the case of
histograms in the same directory. You can have histograms
with the same name in different directories.

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:33 MET