Roofit and PyROot

Hello

I’m trying some basic stuff with Roofit through PyRoot.

>>> hh=TH1F("hh", "test histo", 100, -5, 5)
>>> hh.FillRandom("gaus", 10000)
>>> hh.Draw()
>>> x=RooRealVar("x", "x", -5, 5)

RooFit v2.10 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2005 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

>>> data=RooDataHist("data", "dataset with x", x, hh)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: none of the 5 overloaded methods succeeded. Full details:
  RooDataHist::RooDataHist() =>
    takes at most 0 arguments (4 given)
  RooDataHist::RooDataHist(const char* name, const char* title, const RooArgSet& vars) =>
    takes at most 3 arguments (4 given)
  RooDataHist::RooDataHist(const RooDataHist& other, const char* newname = 0) =>
    takes at most 2 arguments (4 given)
  RooDataHist::RooDataHist(const char* name, const char* title, const RooArgSet& vars, const RooAbsData& data, Double_t initWgt = 1.0) =>
    could not convert argument 3
  RooDataHist::RooDataHist(const char* name, const char* title, const RooArgList& vars, const TH1* hist, Double_t initWgt = 1.0) =>
    could not convert argument 3

Equivalent code in bare root works but apparently there’s some problem with type, I proceeded as follows,

>>> data=RooDataHist("data", "dataset with x", RooArgList(x), hh)
>>> frame=x.frame()
>>> data.plotOn(frame)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: RooPlot* RooDataHist(RooPlot* frame, RooTreeData::PlotOpt o) =>
    takes at least 2 arguments (1 given)

at this point I don’t really know what to do… Could you tell me where I’m doing wrong?

Cheers
Akira

Akira,

not an expert on RooFit myself, but the error says that the constructor will accept a RooArgList or RooArgSet as the third argument, but not just a RooRealVar. Hence, I’d argue that this would be the way to go:[code]>>> l = RooArgList(x)

data=RooDataHist(“data”, “dataset with x”, l, hh)[/code]

(See help(RooArgList) for its available constructors.) Presumably, you took the code from a C++ example? There I’d expect that the RooRealVar can be implicitly converted to a RooArgList, which can be passed through the const-ref. Allowing implicit conversions in PyROOT (something that has no equivalent in the python language) has been on my TODO list for a long time. :slight_smile:

HTH,
Wim

Hi Wim

OK, that explains the first part of my problem. In the second bit of my code, though, I have actually tried that and I managed to go pass that line. Then I’m trying to plot it on a frame and get "takes at least 2 arguments (1 given) " error. The problem is that this is an internal error and I have no way of passing this missing argument from plotOn() method. I guess this may be more of a RooFit issue but this problem is specific to using pyRoot as the same (equivalent) thing works on CINT.

Cheers
Akira

Akira,

not sure how you think it’s an internal error (then again, the error message is misleading: it is missing “::plotOn”; there’s one ROOT release out there that suffers from this). Here, too, the C++ version is using a feature that isn’t readily ported to python, in this case “using RooAbsData::plotOn”. The line, therefore, should be replaced by a direct call to the function in that base class:>>> RooAbsData.plotOn(data,frame)Clumsy, yes, but I don’t know anything better. :frowning:

Cheers,
Wim