Re: [ROOT] 2-dimensional array branches

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Sep 07 2001 - 05:15:50 MEST


Hi Glen,
Multi-dimensional arrays are supported but only one variable dimension
is allowed.

Rene Brun

On Thu, 6 Sep 2001, Glen R. Salo wrote:

> Hello,
> 
> I don't understand why the following scripts fail (I patterned it off of
> tree3.C).  If the statements which refer to px2 are removed, it runs just
> fine.  But I want to be able to have multiple 2 dimensional branches
> within the same tree.  Is this possible?  I'm running version 3.02/00 (as
> of August 29th) on an updated RedHat 7.1 x86 machine.
> 
> Thanks,
> 
> Glen
> 
> void twodw() {
> 
>    const Int_t kMaxDim = 50;
>    Int_t nx;
>    Int_t ny;
>    Double_t px1[kMaxDim][kMaxDim]; 
>    Double_t px2[kMaxDim][kMaxDim]; 
>      
>    TFile f("twod.root","recreate");
>    TTree *twod = new TTree("twod","Reconst ntuple");
>    twod->Branch("nx",&nx,"nx/I");
>    twod->Branch("ny",&ny,"ny/I");
>    twod->Branch("px1",px1,"px1[nx][ny]/D");
>    twod->Branch("px2",px2,"px2[nx][ny]/D");
> 
>    nx = gRandom->Rndm()*(kMaxDim-1);
>    ny = gRandom->Rndm()*(kMaxDim-1);  
>    for (Int_t i=0;i<100;i++) {
>       for (Int_t j=0;j<nx;j++) {
>         for (Int_t k=0;k<ny;k++) {
>           px1[j][k] = gRandom->Gaus(0,1);
>           px2[j][k] = gRandom->Gaus(0,1);
>         }
>       }
>       twod->Fill();
>    }   
>    twod->Print();
>    f.cd();
>    twod->Write();
> }
> 
> void twodr()
> {
>    TFile *f = new TFile("twod.root");
>    TTree *twod = (TTree*)f->Get("twod");
>    twod->Draw("px1");
> }
> 
> void twod()
> {
>    twodw();
>    twodr();
> }      
> 



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