Make each tree of a file friends with each other

I have a file with several trees: ch0, ch1, ch2,…ch23

In an steering file I give the user the possibility to make a selection of the events based on some variables ot the trees. My compiled code reads that string during execution and applies the selection. For example:

TString Selection=“ch0->Temp>0 && ch1->Voltage<200&&ch15->Amplitude>0.03”

Since the selection can refer to any tree in the file, I need to make each tree friends with each other. This means ch0 is friends of ch1,…ch23. Then ch1 is friends with ch0,ch2,…ch23, and so on.

The problem is that, if I make the above friendships, then a code like:

vector<TTree*> vtree;
vtree.push_back( ch0 ) ;vtree.push_back( ch1 ) ; //...I push_back here each of the Trees
vtree[0]->Draw( ">>myList" , Selection ) ;
TEventList *acclist = (TEventList*) gDirectory->Get("myList") ;
acclist->SetDirectory(0);    

gets “infinitely” long.

Is there a smarter/faster way of doing this with trees?

Otherwise the only thing I can make is parse the selection string, identify the trees involved and only make a reduced number of friendships. But I was wondering if there is a more efficient way of doing it in ROOT.

Thank you very much


Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.

_ROOT Version:6.24/08
_Platform: Ubuntu 22.04
_Compiler: 11.4.0


A priori you just need:

ch0->AddFriend(ch1);
ch0->AddFriend(ch2);
...
ch0->AddFriend(chN);
ch0->Draw( ">>myList" , Selection );
TEventList *acclist = (TEventList*) gDirectory->Get("myList") ;
acclist->SetDirectory(0); 

should be enough …

Also, friend of a friend is a friend, so this should also work:

ch0->AddFriend(ch1);
ch1->AddFriend(ch2);
ch2->AddFriend(ch3);

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