Namespace using by Draw in PyROOT

Hi All,

I tried to draw the data of a TTree directly into a TH1* object. In C++ version, the code writes as

TH1D *h1 = new TH1D("h1", "title" , nbins, xmin, xmax)
TTree->Draw("x>>h1", TCut)     // x is a branch of TTree

It works perfectly.

However, in PyROOT, the following code

h1 = TH1D("h1", "title" , nbins, xmin, xmax)
TTree.Draw("x>>h1", TCut)    # x is a branch of TTree

does NOT change h1 at all, even the one on TCanvas GUI is surely h1.
My guess is that the namespace Draw function uses is not the general one, thus h1 stays untouched.

What should I do to let Draw use the general h1? Or am I misunderstanding anything here?

Many Thanks,

ROOT Version: 6.22/02
Platform: macOS + Python 2.7
Compiler: Clang 12.0

Right before these two lines, try to add: gROOT->cd(); // newly created histograms should go here

1 Like

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