Draw two branches from a root file on the same plot

Hello All,

I have two branches of a tree with different pieces of information in a root file. And I wanted to draw them one vs the other.
Is this possible to draw this plot or may I do something before filling it in a tree?

Thank You

   TFile *f = new TFile("myfile.root");
   TTree *t1 = (TTree*)f->Get("mytree");
   Float_t px, py;
   t1->SetBranchAddress("px",&px);
   t1->SetBranchAddress("py",&py);
   t1->Draw("px:py");

https://root.cern/doc/master/tree1_8C.html

Hello,
Sorry, I forgot to mention that the two branches are from two different trees.
Is it possible to plot?

Just duplicate the lines for each tree and instead of tree->Draw, fill and draw a 2D histogram as in the linked tutorial.
More tutorials: ROOT: Tree tutorials

I tried this

Float_t recpt, genpt;
TFile *f = new TFile(“AnalysisResults.root”);
TTree t1 = (TTree)f->Get(“recpt”);
TTree t2 = (TTree)f->Get(“genpt”);
t1->AddFriend(“genpt”,“AnalysisResults.root”);
t1->Draw(“recpt:genpt”);

But still has some issue. Plot not coming right.
What else to do here?

There is example showing how to use Friends tree:
https://root.cern/doc/master/tree3_8C.html
https://root.cern/doc/master/treefriend_8C.html

And a section in the Manual:

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