Re: [ROOT] PAW to ROOT

From: Valeri Fine (fine@bnl.gov)
Date: Thu Sep 06 2001 - 00:10:37 MEST


Since both classes TH1F as well as TH2F ( http://root.cern.ch/root/htmldoc/TH2F.html )  are
derived from TArrayF (http://root.cern.ch/root/htmldoc/TArrayF.html)
all methods of the last one are available.
This means any histogram is in possession of the 
  public: float *TArrayF::fArray  
and 
  public: float &TArray::operator [] (int i)
as well.
And one can simplify the example below:

> > for a 2D histogram
> 
> The brute force way to do this, if I remember my
> PAW correctly, is:
> 
> TH2 *hist = (TH2*)file->Get("hist_id");
> int dimX = (int)hist->GetNbinsX();
> int dimY = (int)hist->GetNbinsY();
> 
> double vect[dimX][dimY];
> 
> for(int i=1; i <= dimX; i++) {
>    for(int j=1; j <= dimY; j++) {
>       int bin = (int)hist->GetBin(i,j);
>       vect[i][j] = (double)hist->GetBinContent(bin);
>    }
> }
> 

TH2F *hist = (TH2F*)file->Get("hist_id");
int dimX = (int)hist->GetNbinsX();
int dimY = (int)hist->GetNbinsY();

float *vect = new float[dimX*dimY];
memcpy(vect,hist->fArray,sizeof(vector));


> Whether there is a clean, simple function call in a ROOT
> class, I'm not sure (haven't look at recent versions)

One one needs no special function. 
The function "memcpy" can do job.

           Cheers, Valeri

> 
> Cheers,
> -Tim
> 
> P.S. I haven't run the code above, but from first glance
> it looks like it has no bugs (tm).
> 



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:59 MET