Home | News | Documentation | Download

RooDataHist Type Error in pyRoot

hi,
I use the RooDataHist to import TH1F data in pyRoot,but there have an error:(it is nothing for C++)
TypeError Traceback (most recent call last)
in
----> 1 data_hist=RooDataHist(“data_hist”,"",x,h1)

TypeError: none of the 8 overloaded methods succeeded. Full details:
RooDataHist::RooDataHist(const char* name, const char* title, const RooArgList& vars, const RooCmdArg& arg1, const RooCmdArg& arg2 = RooCmdArg(), const RooCmdArg& arg3 = RooCmdArg(), const RooCmdArg& arg4 = RooCmdArg(), const RooCmdArg& arg5 = RooCmdArg(), const RooCmdArg& arg6 = RooCmdArg(), const RooCmdArg& arg7 = RooCmdArg(), const RooCmdArg& arg8 = RooCmdArg()) =>
TypeError: could not convert argument 3
RooDataHist::RooDataHist(const RooDataHist& other, const char* newname = 0) =>
TypeError: takes at most 2 arguments (4 given)
RooDataHist::RooDataHist() =>
TypeError: takes at most 0 arguments (4 given)
RooDataHist::RooDataHist(const char* name, const char* title, const RooArgSet& vars, const char* binningName = 0) =>
TypeError: could not convert argument 3
RooDataHist::RooDataHist(const char* name, const char* title, const RooArgList& vars, const TH1* hist, double initWgt = 1.) =>
TypeError: could not convert argument 3
RooDataHist::RooDataHist(const char* name, const char* title, const RooArgSet& vars, const RooAbsData& data, double initWgt = 1.) =>
TypeError: could not convert argument 3
RooDataHist::RooDataHist(const char* name, const char* title, const RooArgList& vars, RooCategory& indexCat, map<string,TH1*> histMap, double initWgt = 1.) =>
TypeError: takes at least 5 arguments (4 given)
RooDataHist::RooDataHist(const char* name, const char* title, const RooArgList& vars, RooCategory& indexCat, map<string,RooDataHist*> dhistMap, double wgt = 1.) =>
TypeError: takes at least 5 arguments (4 given)

from ROOT import *

h1=TFile(“rawE1.1_1.2.root”).Get(“rawE”)

x=RooRealVar(“x”,"",0,2.5)

mean=RooRealVar(“mean”,"",0)
sig=RooRealVar(“sig”,"",0.11)
gauss=RooGaussian(“gauss”,"",x,mean,sig)

data_hist=RooDataHist(“data_hist”,"",RooArgList(x),h1)
data_pdf=RooHistPdf(“data_pdf”,"",x,data_hist)

Hi @Kane_Jay!

You need to keep the TFile alive as long as you use objects in it, like the histogram. You can do this by assigning it to a Python variable:

from ROOT import *

f1 = TFile("rawE1.1_1.2.root")

h1 = f.Get("rawE")

x=RooRealVar("x","",0,2.5)

mean=RooRealVar("mean","",0)
sig=RooRealVar("sig","",0.11)
gauss=RooGaussian("gauss","",x,mean,sig)

data_hist=RooDataHist("data_hist","",RooArgList(x),h1)
data_pdf=RooHistPdf("data_pdf","",x,data_hist)

Hope that works for you!

Jonas

1 Like

hi,
Thank you , Jonas. Your suggestion sloved the problem perfectly.
best regards
kane

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