Chains and Friends

Hi,

I am trying to add Friends to a Tree, and have found very little information on how to do this. I really want to add a Friend to a chain, but will try with a tree first.

My two trees are different, one Truth and one FullRec. Can I access leafs in these two different trees in the same event? Is it correct to use Friends for this?

I at the moment have 2 files, one containng Truth tree, and one containing the FullRec tree. I would like to merge these into one file, and access both trees at once.

This is what I have tried:

TFile *f = new TFile(“parent.root”);
TTree T = (TTree)f->Get(“Truth0”);

TFile *ff = new TFile(“friend.root”);
TTree TF = (TTree)ff->Get(“FullRec0”);

T->AddFriend(“TF”,“friend.root”);

Must the Trees be identlical for this to work?

I would appreciate very explisit help.

Thank you very much.

Hi,

From the name of the TTree(s) I assume those are created in the context of ATLAS.

See this post for some details on using Friends in Atlas.

The short answer is that in your case instead of accessing directly Truth0 and FullRec0, you need to use the ‘CollectionTree’:

TFile f("user.MarijaMilosavljevic.SU1_jimmy_susy.recon.v12000SV_HPTV_12071.AANT1.root") TTree *t = (TTree*)f->Get("CollectionTree"); t->Draw("El_p_T");
or make a TChain of [i]CollectionTree/i.

Cheers,
Philippe.

Hi again,

I looked at the post you refer to, but unfortunately still do not understand.

Right now I have actually cloned a selection of f.ex. FullRec into my own little ntuple. And the same for Truth.

The ideal would be to clone the subset of each tree into one file like this:

TFile *ff = new TFile (“out.root”,“RECREATE”);

 TTree *newTree= oldChain->CloneTree(0);
 newTree->CopyEntries(oldChain);

TTree *newTreeTruth = oldChain2->CloneTree(0);
newTreeTruth->CopyEntries(oldChain2);

ff->Write();

But this has resulted in one file filling up with one tree, e.g. out.root and then the other tree filling up in out_1.root.

My idea was to use CollectionTree to clone this whole Tree into the same file as the two others, if I could just get the subsets of the different trees into one and the same file.

When I use CollectionTree, do I have to do MakeClass with ColllectionTree instead of , say FullRec? And how do I access leafs in two differnt trees with same name, and from same event?

Would be great to understand all this.

Thank you!

Maiken