RE: Root Tuples with variable dimension of Arrays.

From: Rene Brun <brun_at_pcroot.cern.ch>
Date: Wed, 8 Jun 2005 18:56:46 +0200 (MEST)


Use a class instead of a struct. In this case one single call will be required to create the top branch.

Rene Brun

On
Wed, 8 Jun 2005, Ahsan, Mahsana wrote:

>
> Hi Rene,
>
> Thanks again for reply. I still curious to know about the case where I can put all the
> variables in one Branch as
>
> mytree->Branch("jet",&jet.njets,"njets/I":eta[njets]/F:phi[njets]/F");
>
> This will create a branch named as "jet" and leaves named as "njets", "eta", "phi"
> within the branch
> Instead of creating different branches as
>
> mytree->Branch("njets",&jet.njets,"njets/I");
> mytree->Branch("eta",jet.eta,"eta[njets]/F");
> mytree->Branch("phi",jet.phi,"phi[njets]/F");
>
> which will create leaves named as "njets", "eta", "phi", that I don't need.
>
> The problem is that I have lots of variables that I wanted to distribute in set of branches
> for easy browsing and analysing. I might be doing wrong way what I actually need. There certainly be better and elegant way to do this.
>
> Thanks again,
> Mahsana
>
>
>
> -----Original Message-----
> From: Rene Brun [mailto:brun_at_pcroot.cern.ch]
> Sent: Wed 6/8/2005 2:04 AM
> To: Ahsan, Mahsana
> Cc: roottalk_at_pcroot.cern.ch
> Subject: RE: [ROOT] Root Tuples with variable dimension of Arrays.
>
> The tree2.C example is very relevant for yur case. It shows how
> to create the branches in case of variable length arrays in C structs.
> Create a branch for each member
>
> struct Jet{
>
> int njets;
> float eta[10];
> float phi[10];
> float e[10];
> float pt[10];
> }
>
> Jet jet;
>
> TFile *hfile = new TFile("example.root","RECREATE","TTree root file");
> hfile->SetCompressionLevel(1);
> TTree *mytree = new TTree("mytree","Reconst tuple");
>
> mytree->Branch("njets",&jet.njets,"njets/I");
> mytree->Branch("eta",jet.eta,"eta[njets]/F");
> mytree->Branch("phi",jet.phi,"phi[njets]/F");
> etc
>
> Rene
>
>
> On
> Tue, 7
> Jun 2005, Ahsan, Mahsana wrote:
>
>> Hi Rene,
>>
>> Thank for the reply. I looked at the tutorial "tree2.C" but unfornately that does not provide what I need. The method "tree2w()" in this macro creates root file containing a "tree" with "leaves" but does not go through different "branches" before creating leaves. What I need is to create "leaves" from different "branches" from a "tree" which does not work when I set the arrays of variable sizes as described in the last email. It works with fixed size of the arrays but not with variable size of array. Is there an example that does this way?
>> Please let me know if I am still missing something.
>>
>> Thank you so much for help,
>> Mahsana
>>
>>
>> ________________________________
>>
>> From: Rene Brun [mailto:brun_at_pcroot.cern.ch]
>> Sent: Tue 6/7/2005 2:51 PM
>> To: Ahsan, Mahsana
>> Cc: roottalk_at_pcroot.cern.ch
>> Subject: Re: [ROOT] Root Tuples with variable dimension of Arrays.
>>
>>
>>
>> See example in tutorial tree2.C
>>
>> Rene Brun
>>
>> On Tue, 7 Jun 2005, Ahsan, Mahsana wrote:
>>
>>> Hello Rooter;
>>>
>>>
>>> Please find below my short example for creating root tuples. I am having a problem in getting right informtion when I fill the tree. Only the first leaf
>>> "njets" is OK while all others are quite corrupted. Can somebody please
>>> point me out what I am doing wrong. I want to get tuples as
>>>
>>> "tree->branch1->leaves
>>> ->branch2->leaves
>>> ->branch3->leaves
>>> ....."
>>>
>>> However the "tree->leaves" works even with variable dimension of array.
>>> The root version is 4.00/04.
>>> -----------------------------------------------------------------------
>>> struct Jet{
>>>
>>> int njets;
>>> float eta[10];
>>> float phi[10];
>>> float e[10];
>>> float pt[10];
>>> }
>>>
>>> Jet jet;
>>> TFile *hfile = new TFile("example.root","RECREATE","TTree root file");
>>> hfile->SetCompressionLevel(1);
>>> TTree *mytree = new TTree("mytree","Reconst tuple");
>>>
>>> mytree->Branch("jet",&jet.njets,"njets/I:ntracks[njets]/I:eta[njets]/F:phi[njets]/F:e[njets]/F");
>>>
>>> int nentries = 500;
>>> TCloneArray fJets;
>>>
>>> for(int ii=0;ii<nentries;ii++){
>>>
>>> for(int ijet=0;ijet<fJets->GetLast()+1;ijet++){
>>> jet.njets = ijet;
>>> jet.pt[ijet] = cj->Pt();
>>> jet.eta[ijet] = cj->Eta();
>>> jet.phi[ijet] = cj->Phi();
>>> jet.e[ijet] = cj->E();
>>>
>>> }
>>> mytree->Fill();
>>>
>>> }
>>> --------------------------------------------------------------------------
>>>
>>> Thank you very much for help,
>>> Mahsana
>>>
>>
>>
>>
>
>
Received on Wed Jun 08 2005 - 18:56:52 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:09 MET