Cannot access RooMCStudy::genParDataSet

I want to access the values assigned to various parameters in the generated datasets, but I cannot figure out how. genParDataSet should hold these values, but it only returns a null pointer, even when I save the generated data and when I use a constraint. Is this a bug or am I missing something? Reproducer follows.


import ROOT as r

ws = r.RooWorkspace("workspace")
x = ws.factory("x[-10, 10]")
pdf1 = ws.factory("Gaussian::pdf1(x, m[-1, 1], s[5, 10])")
pdf2 = ws.factory("Gaussian::pdf2(x, m, s)")
pdf = ws.factory("SUM::pdf(N1[0, 100] * pdf1, N2[0, 100] * pdf2)")

constraint = ws.factory("Gaussian::constraint(s, cm[7], cs[1])")

mcstudy = r.RooMCStudy(pdf, r.RooArgSet(x), r.RooFit.ExternalConstraints(constraint))
mcstudy.generate(1, 1000, True)

gen_ds = mcstudy.genParDataSet()
print("yes" if gen_ds else "no")

Output:

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

[#0] WARNING:InputArguments -- The parameter 'cs' with range [-1e+30, 1e+30] of the RooGaussian 'constraint' exceeds the safe range of (0, inf). Advise to limit its range.
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 0
[#0] PROGRESS:Generation -- RooMCStudy: now generating 1000 events
no

Notice that the statement
RooMCStudy::RooMCStudy: INFO have pdf with constraints, will generate parameters from constraint pdf for each experiment
is not printed, despite the presence of a constraint. See source code.

Hi @mwilkins,

I am sure @moneta knows the answer to your question.

Cheers,
J.

Hi @moneta/@moneta2,

Any word on this? I don’t want the topic to close…

Apologies for the late reply. I will investigate it…

I think the problem is that the constraints are not recognised. Instead of using ExternalConstraint, can you do as in the tutorial ROOT: tutorials/roofit/rf804_mcstudy_constr.C File Reference
pass them in the full pdf and use the Constrain command option ?

It is maybe a bug in dealing with ExternalConstraint in the RooMCStudy class

Lorenzo

Hi, @moneta,

That fixes it, though I get an error about differently sized datasets that I don’t understand:

import ROOT as r

ws = r.RooWorkspace("workspace")
x = ws.factory("x[-10, 10]")
pdf1 = ws.factory("Gaussian::pdf1(x, m[-1, 1], s[5, 10])")
pdf2 = ws.factory("Gaussian::pdf2(x, m, s)")
pdf = ws.factory("SUM::pdf(N1[0, 100] * pdf1, N2[0, 100] * pdf2)")

constraint = ws.factory("Gaussian::constraint(s, cm[7], cs[1])")

prodpdf = ws.factory("PROD::prodpdf({pdf,constraint})")

mcstudy = r.RooMCStudy(prodpdf, r.RooArgSet(x), r.RooFit.Constrain(s))
mcstudy.generate(1, 1000, True)

gen_ds = mcstudy.genParDataSet()
print("yes" if gen_ds else "no")

output:

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

[#0] WARNING:InputArguments -- The parameter 'cs' with range [-1e+30, 1e+30] of the RooGaussian 'constraint' exceeds the safe range of (0, inf). Advise to limit its range.
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 0
[#0] PROGRESS:Generation -- RooMCStudy: now generating 1000 events
[#0] ERROR:InputArguments -- RooDataSet::merge(fitParData_prodpdf) ERROR: datasets have different size
yes

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