Hi,
I am trying to fill multiple trees having common branches in a single TFile
.
But, I am unable to fill trees with data. Below I am adding an example running code.
Please let me know how I can fill them.
Thanks
Ram
void my_tree() {
TFile *hfile = new TFile("AFile.root","RECREATE","Example");
// Create trees and store in list
TTree *tree = 0;
auto fList = new TList();
fList->Clear();
Int_t Track;
TString name[8] = { "a", "b", "c", "d", "e", "f", "g", "h" };
for (Int_t i=0; i<8; i++) {
tree = new TTree(name[i], "");
tree->Branch( "Track", &Track, "Track/I");
fList->Add(tree);
}
// Fill trees with data
for (Int_t i=0; i<3; i++) { // Loop over number of tree
tree = (TTree*)fList->At(i);
for (Int_t id=0; id<4; id++) { // Loop over event numbers
TBranch *br = tree->FindBranch("Track");
tree->Fill();
}
}
// Write trees to file
for (Int_t i=0; i<8; i++) {
tree = (TTree*)fList->At(i);
// write tree to file
tree->Write("", TObject::kOverwrite);
tree->Delete(""); //delete tree from memory
tree = 0;
}
}
ROOT Version: ROOT 6.12/06
Platform: Mac OS 10.14.5
Compiler: Not Provided