GSI Forum - RDF feed
type: channel
description: GSI Helmholtzzentrum für Schwerionenforschung
items: Tree with arrays in the leafs
items: Re: Tree with arrays in the leafs

Tree with arrays in the leafs
type: item
description: 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.
creator: C. A. Douma
date: 2016-01-18T13:21:06-00:00

Re: Tree with arrays in the leafs
type: item
description: 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
creator: Dmytro Kresan
date: 2016-01-18T15:35:10-00:00

Re: Tree with arrays in the leafs
type: item
description: Thank you!
creator: C. A. Douma
date: 2016-01-18T15:37:51-00:00

Re: Tree with arrays in the leafs
type: item
description: Shouldn't this code be somewhere in the tutorials? Or is it already?
creator: Bastian Löher
date: 2016-01-18T16:03:00-00:00

Re: Tree with arrays in the leafs
type: item
description: 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.
creator: Dmytro Kresan
date: 2016-01-18T16:22:38-00:00