RE: [ROOT] matrix in TTree with a C structure

From: Philippe Canal (pcanal@fnal.gov)
Date: Wed Aug 27 2003 - 17:27:04 MEST


Hi Matthieu,

Using a struct in a TTree should be saved for the simplest cases.
In your case you should be better of using a compiled class.
Create a file ENTITE.h:
  const Int_t nmax=250;
  class ENTITE 
  { 
     Int_t   TREEn;
     Float_t TREEpt[nmax], ... ;
     ...
     Float_t TREEmmax[nmax][5],TREEptmax[nmax][5], ... ;
   } ENTITE;
Generate and load the proper shared library:
   gROOT->ProcessLine(".L ENTITE.h+");
Create the branch:
   ENTITE P[n_entite];
   for(int i_P;i_P<n_entite;++i_P)
   {
      TString branchname = suffix[i_P] + ".";
      TTree.Branch(branchname,"ENTITE",&(P[i_P]);
   }

Cheers,
Philippe

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Matthieu Lechowski
Sent: Wednesday, August 27, 2003 3:08 AM
To: roottalk@cern.ch
Subject: [ROOT] matrix in TTree with a C structure


Hello,

I have a problem which is a little hard to explain.

I have a TTree with a C structure:

const Int_t nmax=250;
typedef struct
{
  Int_t   TREEn;
  Float_t TREEpt[nmax], ... ;
  ...
  Float_t TREEmmax[nmax][5],TREEptmax[nmax][5], ... ;
} ENTITE;

ENTITE P[n_entite];

for(int i_P;i_P<n_entite;++i_P)
{
  TREE.Branch("n"+suffix[i_P],&P[i_P].TREEn,"n"+suffix[i_P]+"/I");
  TREE.Branch("pt"+suffix[i_P],P[i_P].TREEpt,
              "pt"+suffix[i_P]+"[n"+suffix[i_P]+"]/F");
  ...
  TREE.Branch("mmax"+suffix[i_P],P[i_P].TREEmmax,
              "mmax"+suffix[i_P]+
              "["+Nsel_str[i_P]+"]["+Nattendu_str[i_P]+"]/F");
  ...
}

As you can see, each object ("ENTITE") has its suffix for the name of
the variables, and its dimensions for the matrixes as mmax (Nsel_str and
Nattendu_str are TString, I did Nsel_str[i_P]+=Nsel[i_P]; where Nsel[]
are integers; I think it was not necessary)

This synthax works with "pt", but not with mmax. Indeed, when I read the
Tree, the variable has the good dimension (2x2 for example), but fields
are empty beyond the first column (or line!), i.e mmax[0][j] are filled,
but mmax[i>0][j] are 0.

I checked, just before filling (function Fill()) the Tree, that my
variables are really filled, and they are, so informations are lost
filling the Tree.
I think my synthax of "Branch(..)" is not correct for matrix.

Have you an idea ?
(I'm using root at cern om lxplus:
ROOTSYS=/afs/cern.ch/sw/root/v3.05.05/rh73_gcc2952/root )

Thank you.


Matthieu Lechowski
LAL Orsay



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:15 MET