Pipe Draw() to TH2

I’m trying to pipe the output of a Draw() with cuts to a TH2F using the following code:

import ROOT

histo = ROOT.TH2F("histo","MyHistogram",50,0,1000,50,0,1000)
rootfile = ROOT.TFile("data.root","read")
tree = rootfile.Get("MyTree")
tree.Draw("var1:var2 >> histo", weight, "goff")
c = ROOT.TCanvas("MyCanvas","MyCanvas")
c.cd()
histo.Draw("colz")

However, histo seems to be empty; what am I doing wrong?

It could be that “weight” disgard all the entries ? … what is weight ?
What do you get if you do:

tree.Draw(“var1:var2”,weight)

Hi couet,

Yes, I checked that. My weighting works fine, and I get the expected values when I do

print tree.GetEntries(weight)
> correct number

However:

print histo.GetEntries()
> 0.0

seems of for me:

root [0] TH2D *histo = new TH2D("histo","histo",100,0,10,100,0,10)
(TH2D *) 0x7fb9963bec00
root [1] ntuple->Draw("px:py>>histo","px>0 && py>0","goff")
(long long) 6237
root [2] histo->GetEntries()
(double) 6237.00
root [3] 

Opening my data file with ROOT and running these commands works for me too. However, in my PyROOT script it doesn’t! Furthermore, I’ve found that although running the PyROOT lines from my original post give me

print histo.GetEntries()
> 0.0

calling a TBrowser and clicking on histo displays the expected histogram, with the correct number of entries. What is going on??

Seems to be a Python Issue… I will tell the python expert.