GSI Forum
GSI Helmholtzzentrum für Schwerionenforschung

Home » R3BRoot » General Discussions » Tree with arrays in the leafs (How to get multiple numbers in a leaf within an event)
Tree with arrays in the leafs [message #18896] Mon, 18 January 2016 14:21 Go to next message
C. A. Douma is currently offline  C. A. Douma
Messages: 88
Registered: September 2015
Location: Groningen
continuous participant
From: *kvi-cart.rug.nl
Dear Mr. Kresan,

How is the cbmsim tree created? I am trying to create a tree myself where I need to store multiple
numbers per event inside a leaf, but I cannot get it done. Can you tell me exactly how this is
done when the cbmsim tree is created?

Thank you in advance!
Christiaan Douma.
Re: Tree with arrays in the leafs [message #18897 is a reply to message #18896] Mon, 18 January 2016 16:35 Go to previous messageGo to next message
Dmytro Kresan is currently offline  Dmytro Kresan
Messages: 166
Registered: June 2004
first-grade participant
From: 93.77.23*
Hello Christiaan,

Here is the sample code, in case you want to store arrays of objects inheriting from TObject. For arrays of simple numbers you can use TArrayI or TArrayF instead of TClonesArray.

TFile *file = new TFile("filename.root", "RECREATE");
TTree *tree = new TTree("tree_name", "Title");
TClonesArray *myarray = new TClonesArray("NameOfYourClass");
tree->Branch("mybranch", "TClonesArray", &myarray);

// Event loop
for(Int_t i = 0; i < 100; i++)
{
    // Data loop
    for(Int_t k = 0; k < 20; k++)
    {
        new ((*myarray)[k]) ConstructorOfYourClass(..parameters..);
    }

    tree->Fill();
    myarray->Clear();
}
tree->Write();
file->Close();



Cheers,
Dima
Re: Tree with arrays in the leafs [message #18899 is a reply to message #18897] Mon, 18 January 2016 16:37 Go to previous messageGo to next message
C. A. Douma is currently offline  C. A. Douma
Messages: 88
Registered: September 2015
Location: Groningen
continuous participant
From: *kvi-cart.rug.nl
Thank you!
Re: Tree with arrays in the leafs [message #18900 is a reply to message #18899] Mon, 18 January 2016 17:03 Go to previous messageGo to next message
Bastian Löher is currently offline  Bastian Löher
Messages: 8
Registered: October 2015
occasional visitor
From: *gsi.de
Shouldn't this code be somewhere in the tutorials? Or is it already?
Re: Tree with arrays in the leafs [message #18902 is a reply to message #18900] Mon, 18 January 2016 17:22 Go to previous message
Dmytro Kresan is currently offline  Dmytro Kresan
Messages: 166
Registered: June 2004
first-grade participant
From: 93.77.23*
To my opinion this is not really R3BRoot related. This functionality is implemented in the FairRootManager:: Register() and GetObject() methods.

In addition, as far as I remember, this is part of ROOT tutorials.
Previous Topic: Minutes
Next Topic: Installation of 'root'
Goto Forum:
  


Current Time: Mon Oct 14 05:13:21 CEST 2024

Total time taken to generate the page: 0.00844 seconds