Hi all,
I am using ROOT 6.0.8/06. I have a makeClass-derived code that accesses a Tree in a ROOT file. I have now added another Tree in the ROOT files and I would like to make the two Tree friends so that I can access them easily. The way i’ve done this is:
TTree tree = chain;
…
TChain chain = new TChain(“folder/Tree1”);
TChain* friendChain = new TChain("folder/Tree2);
tree = chain;
tree->AddFriend(friendChain);
…
In a separate file I have also declared the TBranches and set the address, as normal:
fChain->SetBranchAddress(“Var1”, &Var1, &b_Var1);
fChain->SetBranchAddress(“Var2”, &Var2, &b_Var2);
where Var1 is a branch element in Tree1 and Var2 a branch element Tree2.
When I run a simple Loop to access the variables, those from Tree1 are accessible while those from Tree2 (e.g. Var2->size() ) give me *** Break *** segmentation violation.
The files are added to the TChain as soon as the TChains are declared:
TChain* chain = new TChain(“folder/Tree1”);
TChain* friendChain = new TChain("folder/Tree2);
// Add the Files
std::cout << “\tWill get the ROOT files and add them to the TChain(s).” << std::endl;
OpenFile(SamplePath, SampleName, chain); // simply looks for file to add to TChain
OpenFile(SamplePath, SampleName, friendChain); // simply looks for file to add to TChain
Immediately after that the friendship is established:
tree = chain;
tree->AddFriend(friendChain);
Then the initialisation of all (primary) tree variables is made with a dedicated function defined in separate header file. This is where all the TBranches, vectors and and containers (e.g. vector<double) are declared and initialised, and the appropriate branch addresses are set with:
fChain->SetBranchAddress(“BranchName”, container, branch);
Inside the same header file the assignment “fChain = tree;” is made. The fChain is then accessible in the macro that does all the plotting etc…
I should mention that the code is a modified MakeClass code, so the only thing new is the friendship really. The segmentation fault only happens when I try to access a variable from the “friend” tree. Otherwise works smoothly.
To debug this problem I recommend that you first compile all your code with ACliC (you may have to add missing header files, etc.). If the problem persist, run the example under valgrind: