Dividing two branches from different ttrees

I’m new to ROOT and using it to analyse data which I create elsewhere and store in a TTree.

I want to take the signal stored in one TTree and divide it by the signal stored in another TTree and then plot this new signal ie Draw(“x:y”,“signal”,“colz”).

The code I have used to plot each signal individually is included below.

TFile *f = new TFile(“directory/to/file.root”)
TTree *Tree

Where signal is a float value obtained for each “x:y” coordinate.

Thanks in advance for your help!

if the two TTrees have the same number of entries you could add one TTree as a friend of the other, see e.g. TTree::AddFriend.
This essentially “pastes” the TTree together horizontally, making branches of the friend tree available as if they were branches of the main Tree.

Also see the TTree friend tutorial for more information, or search “TTree friend” here on the forum.

BTW if you are producing the TTrees you might want to consider storing everything in one TTree for simplicity.

Hope this helps!

Hi thank you that looks like what I wanted! I do have a question though - both of my TTrees are created with the same names and the same branch names (I have no control over their creation unfortunately). I can’t see an easy way for me to change the name of the branches I want to add. Is there a quick way to change this when moving the branch over?

You can add the friend with an alias and then refer to its branches as "alias.branch".