Can't access TH1F constructors of a RooDataSet using Pyroot; Only the TH2F constructors work

I have a workspace containing a RooDataSet, and I would like to get a TH1F from it. If I do the following in the interpreter, everything works:

root [2] w->data("data_obs")->createHistogram( "name", *w->var("xVar") )
(class TH1 *) 0x38727b0

However if I try to do practically the same thing in python I get the following error:

>>> w.data('data_obs').createHistogram('name', w.var('xVar') )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: none of the 2 overloaded methods succeeded. Full details:
  TH2F* RooDataSet::createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, const char* cuts = """", const char* name = ""hist"") =>
    could not convert argument 1
  TH2F* RooDataSet::createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, int nx, int ny, const char* cuts = """", const char* name = ""hist"") =>
    takes at least 4 arguments (2 given)

Only the TH2F constructors from RooDataSet are available (https://root.cern.ch/doc/master/classRooDataSet.html), but I would like to use the TH1F constructors that are inherited from RooAbsData (https://root.cern.ch/doc/master/classRooAbsData.html). In the interpreter this doesn’t seem to be an issue.

Is there any trick to access the TH1F constructors, ignoring the TH2F constructors from RooDataSet?

I found the way:

>>> ROOT.RooAbsData.createHistogram( w.data('data_obs'), 'name', w.var('xVar') )

does the trick.

2 Likes

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