Understanding RooFit

Hi Forum,

apologies for crossposting, but the RooFit support mailing list doesn’t have enough subscribers.
I would like to get RooFit working with PyRoot, so I started to translate the Getting Started script from the wiki.
Unfortunately, I fail.
The line that causes the script to break is this:
data->plotOn(frame,Binning(8)); // plot data histogram using 8 bins

Obviously Python and I don’t understand the API very well.
PlotOn requires either a RooLinkedList or a PlotOpt struct as the second argument, but Binning returns a RooCmdArg.
Now neither the RooLinkedList or the PlotOpt has a constructor that would accept a RooCmdArg. So I don’t really understand how this works in the first place.

Could anybody more comfortable with the API explain this a bit more, so that I could try and get this working with PyRoot. (Which I would of course contribute to the WIKI)

Thank you,

Hi Jan,

The function you call with

data->plotOn(frame,Binning(8)); // plot data histogram using 8 bins

is this one

RooAbsData* reduce(RooCmdArg arg1,RooCmdArg arg2=RooCmdArg(),RooCmdArg arg3=RooCmdArg(),RooCmdArg arg4=RooCmdArg(),
RooCmdArg arg5=RooCmdArg(),RooCmdArg arg6=RooCmdArg(),RooCmdArg arg7=RooCmdArg(),RooCmdArg arg8=RooCmdArg()) ;

which is implemented in base class RooAbsData of base case RooTreeData of class RooDataSet. This method is imported in RooTreeData with a 'using RooAbsData::plotOn’
and inherited by RooDataSet. The main purpose of this api is interactive convenience. Its implementation collects the non-dummy RooCmdArgs in a list and passes that to

virtual RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const = 0 ;

Does this clarify things?


Hi Wouter,

thanks for your reply.
Unfortunately, I still can’t get it to work with python. I don’t see how it turns into a RooLinkedList.
Looks like I have to stick with C++ until I have time to study the API a bit more.



the example is confusing me, too, but if I have to make a guess, then the C++ code has an implicit conversion somewhere that python is missing. My online access is flaky for the next week or so, but can you post, or send to me, your python example so far for me to debug?


Hi Wim,
thanks for looking into this. And thanks for making PyRoot, by the way. It increases my productivity quite a bit !

The python code so far is quite simple

from ROOT import gSystem gSystem.Load('libRooFit') from ROOT import RooFit, RooRealVar, RooGaussian, RooDataSet, RooArgList, RooTreeData mass = RooRealVar("mass","Reconstructed Candidate Mass",0.0,8.0,"GeV") mean = RooRealVar("mean","Peak Mass",4.0,2.0,6.0,"GeV") sigma = RooRealVar("sigma","Peak Width",1.0,0.1,2.0,"GeV") gauss = RooGaussian("gauss","Gaussian Peak Model",mass,mean,sigma) data = RooDataSet.read("data.txt",RooArgList(mass)) gauss.fitTo(data) frame = mass.frame() data.plotOn(frame, RooFit.Binning(8))
I have tried various ways to incorporate the information that I got from Wouter.

data.plotOn(frame, data.reduce(RooFit.Binning(8)))

doesn’t work, either, and neither does

data.plotOn(frame, RooLinkedList(data.reduce(RooFit.Binning(8))))

That’s where I left it.
Since the Roofit wiki seems to be down, I have attached data.txt and the CINT Macro version of the program, which works just fine, by the way.

fitMassPeak.c (847 Bytes)
data.txt (159 Bytes)


[back online from vacation :slight_smile:]

thanks for the code. The ‘using RooAbsData::PlotOn’ does not result in getting that overload in the dictionary for RooTreeData. Not sure yet how to get ‘using’ statements from CINT, nor from where I should pick it up, but that’s for later. For now, here’s a workaround:

from ROOT import RooAbsData RooAbsData.plotOn(data, frame, RooFit.Binning(8))

Hi Wim,

very cool ! Interesting that it works with the base class, but not the derived class. Thanks a lot for finding this out !