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)
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 previous 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..);


Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Minutes
Next Topic: Installation of 'root'
Goto Forum:

Current Time: Sat Jul 20 14:58:09 CEST 2024

Total time taken to generate the page: 0.00814 seconds