RooFit, and how & what to import to use in Python

I’m attempting to write a script in Python, but I’m working off someone’s example in C.

Here’s someone’s RooFit C code I’d like to convert to Python:

using namespace RooFit; RooRealVar x("x","x",dMin,dMax); RooDataHist dh("dh","dh",x,Import(*histData)) ;

Where “histData” is a TH1F*.

My code in python uses the TFile.Get to grab a histogram, and then use that:

import RooDataHist, RooFit, RooRealVar histData = tfile_data.Get('g_pass_Liso_barrel/h_photon_sieie') x = RooRealVar("x","x",data_min,data_max) dh = RooDataHist("dh","dh",x,RooFit.Import(histData))

And I know that RooFit.Import is a valid function which is defined like:

But getting an error with my python code, which makes me wonder if maybe the Get() function is returning a TObject and not a TFile - but there isn’t “casting” in python:

Traceback (most recent call last): ... File "/Users/michaelanderson/Documents/Work/Programming/purity.py", line 28, in get_purity dh = RooDataHist("dh","dh",x,RooFit.Import(hist_DataTemplate)) TypeError: none of the 8 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, const char* binningName = 0) => could not convert argument 3 RooDataHist::RooDataHist(const char* name, const char* title, const RooArgList& vars, RooCmdArg arg1, RooCmdArg arg2 = RooCmdArg(), RooCmdArg arg3 = RooCmdArg(), RooCmdArg arg4 = RooCmdArg(), RooCmdArg arg5 = RooCmdArg(), RooCmdArg arg6 = RooCmdArg(), RooCmdArg arg7 = RooCmdArg(), RooCmdArg arg8 = RooCmdArg()) => could not convert argument 3 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 RooDataHist::RooDataHist(const char* name, const char* title, const RooArgList& vars, RooCategory& indexCat, map<std::string,TH1*> histMap, Double_t initWgt = 1.0) => takes at least 5 arguments (4 given) RooDataHist::RooDataHist(const char* name, const char* title, const RooArgList& vars, RooCategory& indexCat, map<std::string,RooDataHist*> dhistMap, Double_t wgt = 1.0) => takes at least 5 arguments (4 given)

What might I be going wrong here?

Hi,

the RooDataHist ctor that you want to use takes a RooArgList as the third argument. That class as an implicit conversion from RooRealVar, but the python code doesn’t do implicit conversion. So, add an explicit one:

ral = RooArgList( x )and pass that (ral) instead of x.

Cheers,
Wim

1 Like