MakeClass and Tree Friendship

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;

chain = new TChain(“folder/Tree1”);
TChain* friendChain = new TChain("folder/Tree2);
tree = chain;

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.

What am I missing here?

Cheers, Alexandros


Could you please explain what you mean by a separate file and how fChain connects with ‘tree’ ?
When do you add the files on the chains?

G Ganis

Hi Ganis,

thanx for the reply!

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;

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.


Hi Alexandros,

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:

valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp root.exe -b -l ..... 

which should tell you the reason of the crash.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.