Drawing 2D Histogram with Color Bar Using data from leaves

Hello everyone.

I am new to ROOT.
I have a root file called “test1.root” in which there is a tree called “A”. Under “A” there are some leaves. I would like to use information from 2 leaves called “P” and “D” to build a 2D histogram with a log scale color bar.

Would anyone please help?

Thank you.

Hi,

You can do something like this, using for example the hsimple.root file generated when running the tutorial $ROOTSYS/tutorials/hsimple.C

auto f = TFile::Open("hsimple.root");
auto ntuple = (TTree*) f->Get("ntuple");
auto h2 = new TH2F("h2","My histogram",100,1,0,100,1,0);
ntuple->Draw("px:py >> h2");
gPad->SetLogz(true);
h2->Draw("COLZ");

Lorenzo

Thank you Lorenzo, you’ve saved my day!

You can also do:

auto f = TFile::Open("hsimple.root");
auto ntuple = (TTree*) f->Get("ntuple");
auto h2 = new TH2F("h2","My histogram",100,1,0,100,1,0);
ntuple->Draw("px:py >> h2", "", "goff");
h2->Draw("COLZ");
gPad->SetLogz();

To create gPad only when needed.

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