Problem with TTree:AddFriend

Hi,

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.

Here is my code:

[code]> 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”);
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.).

Regards,

Raksapol

Hi,

This is odd :slight_smile:

Can you try with t->AddFriend(g); ?

Do the 2 trees have the same number of entries?

Which version of ROOT are you using?

Can you provide me with your ROOT files?

Cheers,
Philippe

Hi Phillipe,

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.

cheers,

Raksapol

[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?

Cheers,
Philippe

Hi,

I have just copied my .root file to my castor directory at:

/castor/cern.ch/user/r/raksapol

Cheers,

Raksapol

Hi,

I do not use castor (and probably do not have read permission do it).
Could you make the file available somewhere on AFS?

Thanks,
Philippe

Hi Phillipe,

I have managed to put my root data file into my public dir of my afs dir.

/afs/cern.ch/user/r/raksapol/public/scratch0

The file is “user.MarijaMilosavljevic.SU1_jimmy_susy.recon.v12000601.SV_HPTV_12701.AANT1.00001.root”

Hope it’s ok this time,

cheers,

Raksapol

Hi,

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).

Cheers,
Philippe

Hi Phillipe,

I just set a new access to the file at /afs/cern.ch/user/r/raksapol/public/scratch0
cheers,

Raksapol

Hi,

all the different trees in the Atlas event view tuples are already made friends with the “CollectionTree”. Try this:

TFile f("user.MarijaMilosavljevic.SU1_jimmy_susy.recon.v12000SV_HPTV_12071.AANT1.root")
TTree *t = (TTree*)f->Get("CollectionTree");
t->Draw("El_p_T");

Hope this helps,
Oliver

Hi,

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

Thank you very much, Phillipe. The problem is solved now. Also thanks to Oliver, for pointing out how to use the CollectionTree.

Cheers,

Raksapol