Dear experts,
I’m trying to run a script using the FrequentistCalculator Class and i get this error:
cppyy.gbl.std.runtime_error: RooStats::HypoTestInverterResult* RooStats::HypoTestInverter::GetInterval() =>
runtime_error: Error in RooAbsReal::setData(): only resetting with same-structured data is supported.
A snippet of the code is here:
import ROOT
import globalConstants as ctes
import math
if ctes.do_sys:
if ctes.do_sys_Ek:
fInput = ROOT.TFile(f"{ctes.WS_NAME}_Ek.root")
ws = fInput.Get(ctes.WS_FILE)
ws.Print()
poi_name = "NSIG_var"
model_name = "model_mass_sys_gaus_Ek"
data_name = "data_minv_sys_Ek"
constaint_name = "alpha_sys_Ek"
obs_name = "m2inv"
elif ctes.do_sys_Ep:
fInput = ROOT.TFile(f"{ctes.WS_NAME}_Ep.root")
ws = fInput.Get(ctes.WS_FILE)
ws.Print()
poi_name = "NSIG_var"
model_name = "model_mass_sys_gaus_Ep"
data_name = "data_minv_sys_Ep"
constaint_name = "alpha_sys_Ep"
obs_name = "m2inv"
elif ctes.do_sys_Ang:
fInput = ROOT.TFile(f"{ctes.WS_NAME}_Ang.root")
ws = fInput.Get(ctes.WS_FILE)
ws.Print()
poi_name = "NSIG_var"
model_name = "model_mass_sys_gaus_Ang"
data_name = "data_minv_sys_Ang"
constaint_name = "alpha_sys_Ang"
obs_name = "m2inv"
else:
print("Error: choose do_sys_Ek, do_sys_Ep or do_sys_Ang")
exit()
else:
fInput = ROOT.TFile(f"{ctes.WS_NAME}.root")
ws = fInput.Get(ctes.WS_FILE)
ws.Print()
if ctes.onlyMASS:
poi_name = "NSIG_var"
model_name = "model_mass"
data_name = "data_minv"
obs_name = "m2inv"
elif ctes.onlyANG:
poi_name = "NSIG_var"
model_name = "model_ang"
data_name = "data_ang"
obs_name = "dphi"
elif ctes.bothMASS_ANGLE:
poi_name = "NSIG_var"
model_name = "model_ma"
data_name = "data_ma"
obs_mass = "m2inv"
obs_ang = "dphi"
else:
print("Error: choose onlyMASS, onlyANG or bothMASS_ANGLE")
exit()
# Configure the signal-plus-background model
sbModel = ROOT.RooStats.ModelConfig("S+B Model", ws)
sbModel.SetPdf(model_name)
poi = ws.var(poi_name)
sbModel.SetParametersOfInterest([poi])
if ctes.do_sys:
observable = ws.var(obs_name)
observable.setConstant(True)
else:
if ctes.onlyMASS or ctes.onlyANG:
observable = ws.var(obs_name)
observable.setConstant(True)
elif ctes.bothMASS_ANGLE:
observable1, observable2 = ws.var(obs_mass), ws.var(obs_ang)
observable1.setConstant(True)
observable2.setConstant(True)
observable = ROOT.RooArgSet(observable1, observable2)
else:
print("Error: choose onlyMASS, onlyANG or bothMASS_ANGLE")
exit()
sbModel.SetObservables([observable])
# Clone the signal-plus-background model to create the background-only model
bModel = sbModel.Clone("S+B Model_with_poi_0")
poi.setVal(0)
bModel.SetSnapshot([poi])
data = ws.data(data_name)
# First example is with a frequentist approach
fc = ROOT.RooStats.FrequentistCalculator(data, bModel, sbModel)
fc.SetToys(1000, 1000)
# Configure ToyMC Sampler of the frequentist calculator
toymcs = fc.GetTestStatSampler()
profll = ROOT.RooStats.ProfileLikelihoodTestStat(sbModel.GetPdf())
profll.SetOneSided(1)
toymcs.SetTestStatistic(profll)
# Create hypotest inverter passing the desired calculator
calc = ROOT.RooStats.HypoTestInverter(fc)
calc.SetConfidenceLevel(ctes.CL)
calc.UseCLs(1)
calc.SetVerbose(0)
'''
npoints = 30 # Number of points to scan
# min and max for the scan (better to choose smaller intervals)
poimin = 0
poimax = 2e-3
print("Doing a fixed scan in interval:", poimin, ",", poimax)
calc.SetFixedScan(npoints, poimin, poimax)
'''
calc.SetAutoScan()
result = calc.GetInterval()
the last line is where I get the error.
The case I’m studying is with the flag “ctes.do_sys == False” and “ctes.onlyMASS == True” so you can go through the if sentences.
Attached there is the workspace and a config. file I am using.
globalConstants.py (774 Bytes)
Workspace.root (48.2 KB)
Thanks in advance,
Elia
ROOT version 6.32.02