Using Friends option

Hi, I apologize if this question is answered elsewhere, I haven’t been able to find anything specific enough to help me with what I’m trying to do.

I have a number of root files that I have been chaining together and plotting; each of the files has two trees, each of which I have been able to plot successfully as you would expect.

What I would like to do is to plot a variable from one tree while placing a cut on one of the variables from the other tree.

In trying to set this up, it seemed I should make the two chains friends, so I have this syntax in my code:

ch1.AddFriend(“ch2”);

Both these chains have been declared and I can plot from them just fine. I get this error:

Error in TTreeFormula::Compile: Bad numerical expression : “XVertex”

I am then trying to draw like this:

ch1.Draw(“varch1>>h_1()”, “varch2 > 0”);

which gives an error:

Error in TTreeFormula::Compile: Bad numerical expression : “XVertex”

if I run my .C script with the semicolon off the “AddFriend” line above.

Any advice? I’m not certain that I’m using the correct syntax, but I haven’t been able to find anything more specific to help point me in the right direction. Thank you!

Hi,

Try:ch1.AddFriend(ch2);Cheers,
Philippe.

Hi Phillipe, thanks for the reply. Unfortunately when I take the quotes out it gives me errors like this:

Error: Can’t call TChain::AddFriend(ch2) in current scope makehistos_radius.C:70:
Possible candidates are…
(in TChain)
/net/local/software/RHEL_4.0_amd64/i3ports/v3/root-v5.24.00b/lib/libTree.so -1:-1 0 public: virtual TFriendElement* TChain::AddFriend(const char* chainname,const char* dummy="");
/net/local/software/RHEL_4.0_amd64/i3ports/v3/root-v5.24.00b/lib/libTree.so -1:-1 0 public: virtual TFriendElement* TChain::AddFriend(const char* chainname,TFile* dummy);

Anything else I can try?

Hi,

Try:ch1.AddFriend(&ch2);

Cheers,
Philippe.

That works beautifully, thanks so much! The simplest things that Root demands are so often the hardest to find if you don’t already know. :slight_smile:

Hi @pcanal , I’m having the exact same problem, but in python. I have two trees that work perfectly fine by their own and when I try to add them as friends I get the error

Error in <TTreeFormula::Compile>:  Bad numerical expression : "EventNumber"

as in my case I try to BuildIndex on friend tree using the EventNumber branch. How can I translate that solution to python?

Thank you very much in advance!
Cheers,
Francisco

How are you adding the 2 trees as friends?