Forcing return type of RooFit Method RooAbsReal->createHistogram() to be TH1D or TH2D

How can I set the type of the histogram returned by the method
RooAbsReal->createHistogram() in pyroot?

root.cern.ch/doc/master/classRo … a97333fd38

I would like to create a histogram with double precision (TH1D or TH2D in other cases), but when I call the method, I always get a TH1F only:

from ROOT import RooWorkspace
w = RooWorkspace("w")
x = w.factory("x[0.,10.]")
pdf = w.factory("Gaussian::pdf(x,5.,1.)")
hist = pdf.createHistogram("hist", x)
print type(hist)

Hi,

can you post a reproducer?
In PyROOT everything seems fine:

import ROOT

code='''
TH1* getTH1F(){return new TH1F();}
TH1* getTH2F(){return new TH2F();}
'''

ROOT.gInterpreter.Declare(code)
h1 = ROOT.getTH1F()
h2 = ROOT.getTH2F()

print type(h1)
print type(h2)

outputs

<class '__main__.TH1F'>
<class '__main__.TH2F'>

as expected.

Cheers,
Danilo

Follow the lapin blanc, get here: https://root.cern.ch/doc/master/RooAbsRealLValue_8h_source.html so all histo is THF. Type is type. Can force cast, but is ask memory issue.

-Dom

Hi,

Sorry, I misread your post. The answer of dom is appropriate.

Cheers,
Danilo

Thanks a lot for the quick answer!
So the return type is a TH1F anyway and the precision will not increase by forcing it to be a double.

Hi,

that’s correct.

Cheers,
Danilo