GSI Helmholtzzentrum für Schwerionenforschung
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.
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
Shouldn't this code be somewhere in the tutorials? Or is it already?
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.