Add 2D plot in a tree branch

Hi,

Is there any way to draw a 2D (variables (var1, 2, 3) of which are being calculated inside a loop) in a tree branch?

I can do that through root prompt…doing something like the following…

tree->Draw(“var3:var1>>name1(1000,0,50,1000,0,70)”,"",“col”, 50000, 0);
tree->Draw(“var3:var2>>name2(1000,0,50,1000,0,70)”,"",“col”, 50000, 0);
name1->Add(name2,1);
name1->Draw(“colz”);

Now, if I want to do the same thing from inside the C++ code, then how should it be? Any idea?


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


TH2D *name1 = new TH2D("name1", "", 1000, 0., 50., 1000, 0., 70.);
TH2D *name2 = new TH2D("name2", "", 1000, 0., 50., 1000, 0., 70.);
tree->Draw("var3:var1>>name1", "", "col", 50000, 0);
tree->Draw("var3:var2>>name2", "", "col", 50000, 0);
name1->Add(name2, 1.);
name1->Draw("colz");

Hi @Wile_E_Coyote, thanks.
For that how do I create that tree branch?

For 1D, I did like:

tree-> Branch ("var1",&var1,"var1/d");

TTree

Everywhere, I am seeing only the examples of 1D plots in the tree (in https://root.cern.ch/doc/master/classTTree.html). It seems by default it takes only 1D.

When I tried to insert your part, it gave error:

Warning in TFile::Append: Replacing existing TH1: name2 (Potential memory leak).

TTree::Draw

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