TChain friends with indexes

Hi all,

I’m not sure if what I’m trying to do is intended to be possible, but I figured I’d see if anyone had any suggestions. I have two sets of trees (for now called cycle1 and cycle2) which can be indexed by run and event ids, but are largely out of order with respect to each other.

If I have two corresponding trees, one from each cycle, I can make comparison plots by, for instance

tree1->BuildIndex("run","event"); tree2->BuildIndex("run","event"); tree1->AddFriend(tree2,"cycle2"); tree1->Draw("energy :");

Now I want to do the same thing with a TChain from each cycle instead of a single TTree. This works with 2 trees, but crashes if the chain contains 3 or more. I’m not sure if the crashing is itself a bug or not, but I gather from the comment in TChain::GetEntryWithIndex that this method isn’t really expected to work.

So my question is: IS there some way of doing this? I thought maybe I could apply a TEntryList to each chain, but only the list of the master seems to matter. I could copy all the trees into a more synchronized format, but each cycle is around 800 GB, and I don’t really have that much extra space lying around for what should be a few simple plots.

Any ideas?


Hi Ben,

The comment in GetEntryWithIndex refers to the friend chain having also some friends.

[quote]This works with 2 trees, but crashes if the chain contains 3 or more.[/quote]This should have worked … well unless you are attempting to build the index on the whole chain and you are running out of memory (the index table are kept in memory). As long as each pair of TTrees match each other (i.e. the other of the events is random only within each tree pairs), you should be able to make it by build the index on each individual tree (as opposed to the whole) and store the TTree object after this index building.

Note that you only need to build the index on the TTree that becomes the friend (i.e. in your example only tree2->BuildIndex(“run”,“event”); is needed).