RooFit from Python

Hi !
I’m trying to work through the basic RooFit Tutorial.
I started like this:

from ROOT import gSystem
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 ="data.txt",RooArgList(mass))
frame = mass.frame()
data.plotOn(frame, RooFit.Binning(8))

This is where it dramatically crashed with the following traceback

If there’s nothing obviously wrong with this, I’d be happy to provide more information if you tell me what can be of use.
Is there a reason why no dictionary for RooTreeData::PlotOpt is available ?


there is no dictionary for RooTreeData::PlotOpt, because it is missing in $ROOTSYS/roofit/inc/LinkDef3.h. You can add it by hand, for example just after the entry for RooTreeData itself:

#pragma link C++ class RooTreeData ; #pragma link C++ class RooTreeData::PlotOpt ; #pragma link C++ class RooTruthModel ;
and then that’ll work (this may be worthy of a bug report?).

The crash comes about because once there’s no dictionary available, but the type is a ROOT object nonetheless, PyROOT opts for passing it as a void*. This allows types for which no dictionary can be created (yes, that happens sometimes :slight_smile: ), to be passed around from C++ to C++ through python.
However, at that point, it is up to the user to match types. You try to pass a RooFit through a RooTreeData::PlotOpt and that doesn’t work because there’s no relation between the two. Once the dictionary is created (by adding the line to the linkdef), PyROOT can check the passing and will flag the call as a TypeError.