Hi PyRoot users,
after a long time googeling and asking around i found still no solution to following problem:
I would like to generate random numbers in an interval [10,30] distributed according to a pdf.
I have a RooAddPdf which bases on two RooHistPdf. If I call the function generate of the RooAddPdf I get random numbers which are not all in [10,30] since the domain of definition is bigger. I tried to call setNormRange(‘obs’) of the RooAddPdf but that does not seem to influence the generate function. I tried the same with the RooHistPdf and the setNormRange(‘obs’) has also no influence on the generate function:
from ROOT import *
wspace=RooWorkspace(‘wspace’)
wspace.factory(“Gaussian::tstat_H1_gauss(tstat_H1[-100,100],tstat_H1_mean[-50,50],tstat_H1_sigma[30])”)
t_H0_set=wspace.pdf(‘tstat_H1_gauss’).generate(RooArgSet(wspace.var(‘tstat_H1’)),10000)
t_H0_hist=RooDataHist(‘t_H0_hist’,‘t_H0_hist’,RooArgSet(wspace.var(‘tstat_H1’)),t_H0_set)
t_H0_pdf=RooHistPdf(‘t_H0_pdf’,‘t_H0_pdf’,RooArgSet(wspace.var(‘tstat_H1’)),t_H0_hist)
wimport = getattr(wspace,‘import’)
wimport(t_H0_pdf)
wspace.var(‘tstat_H1’).setRange(‘obs’,10,30)
wspace.pdf(‘t_H0_pdf’).setNormRange(‘obs’)
result=wspace.pdf(‘t_H0_pdf’).generate(RooArgSet(wspace.var(‘tstat_H1’)),100)
frame=wspace.var(‘tstat_H1’).frame()
result.plotOn(frame)
frame.Draw()
Unfortunately the RooAbsPdf has no reduce function which would be a workaround. I would be very happy for a hint how to generate from RooAbsPdf random numbers in a interval.
Thx you
Ivo