I was trying to use the function TTree:AddFriend in order to compare some variables between two trees, but I keep failing, i.e. getting a blank draw of histogram of data from the added tree. I have been searching through all the discussions and tried to follow through, but still cannot get it works. I know the codes are very easy, but maybe there is just one minor bug. Please help.
TTree t = (TTree)f->Get(“Truth0”);
TTree g = (TTree)f->Get(“FullRec0”);
t->AddFriend(“FullRec0”) // or t->AddFriend(g)? This line, the added tree’s name is “FullRec0” which is in the same root file as the tree named “Truth0”
t->Draw(“FullRec0.El_p_T”) // Draw electron Pt of the added tree [/code]
After executing the last line to Draw, I always get an empty canvas. No matter what variables from the added tree (FullRec0) I draw (e.g. El_N, El_eta, etc.).
Thanks for the reply. To answer you question, I have already tried the
t->AddFriend(g); but still get the same error result (blank canvas after t->Draw(addedtree.El_p_T) ).
The two trees – Truth and FullRec – those I used have different numbers and types of entries. I’m using ROOT 5.16.0.
My root file is 400 MB. I don’t know if I can upload it here.
[quote]those I used have different numbers [/quote]Different ‘type’ of entries, but different number is usually odd (unless you have create an index on the friend tree and in this case the error might be that there is no match between the 2 trees).
For providing the file, can you make them available through a web or ftp site?
Humm, you will also need to give me (pcanal) read access to that directory
(I can read /afs/cern.ch/user/r/raksapol/public but not the scratch0 subdirectory).
In your file the tree FullRec0 is strored with a tree index (see g->GetTreeIndex), if this index exist, ROOT is using it to match
the 2 trees. However in your case, the information in the index
(“FullRecRunNumber:FullRecCounter”) does not exist in the main
tree and hence no good match can be done to read the right values.
Assuming that the entries in both of your tree are to be matched
row by row (entry X in both tree is about the same event), then you
can use:
TFile f("user.MarijaMilosavljevic.SU1_jimmy_susy.recon.v12000SV_HPTV_12071.AANT1.root")
TTree *t = (TTree*)f->Get("Truth0");
TTree *g = (TTree*)f->Get("FullRec0");
g->SetTreeIndex(0); // remove the index, match by entry number instead.
t->AddFriend("FullRec0") // or t->AddFriend(g)? This line, the added tree's name is "FullRec0" which is in the same root file as the tree named "Truth0"
t->Draw("FullRec0.El_p_T") // Draw electron Pt of the added tree