Dear ROOT experts,
I’m using HistFactory to create a RooWorkspace from histograms. After the workspace creation, I need to replace some of the parameters of the pdf. For that effect, I use the RooWorkspace::factory(“EDIT::name(orig,substNode=origNode)”) method to create a clone. The clone seems to work as expected right after creation. However, when the workspace is being read from a file, the clone pdf apparently does not depend on the observables. Below is a simple example that reproduces the issue in a ROOT prompt (input histograms histos.root (4.2 KB) ).
ROOT version 6.18/04, CentOS 7, gcc8
using namespace RooStats;
using namespace HistFactory;
HistFactory::Measurement meas("meas", "meas");
meas.SetOutputFilePrefix("output");
meas.SetPOI("mu");
HistFactory::Channel chan("channel");
chan.SetData("data","histos.root");
HistFactory::Sample sig( "signal", "hsignal", "histos.root" );
sig.AddNormFactor("mu",1,0,3);
chan.AddSample(sig);
meas.AddChannel(chan);
meas.CollectHistograms();
//The fit will return some nonsense, but is irrelevant to the issue
RooWorkspace* w = MakeModelAndMeasurementFast(meas);
RooRealVar mu1("mu1","mu1",1,0,3);
w->import(mu1);
//make a copy of the PDF in which the old mu variable is replaced by the new mu1
w->factory("EDIT::simPdf1(simPdf,mu=mu1)");
w->writeToFile("output_combined_meas_model.root");
//print pdf values per bin for the old and new pdf
pdf = w->pdf("simPdf");
pdf1 = w->pdf("simPdf1");
obs = w->set("observables");
x = (RooRealVar*) obs->first();
x->setBin(0);
cout << pdf->getVal(*obs) << endl;
cout << pdf1->getVal(*obs) << endl;
x->setBin(1);
cout << pdf->getVal(*obs) << endl;
cout << pdf1->getVal(*obs) << endl;
So far so good, the clone pdf behaves like the original. Then, on a new ROOT session, I retrieve the saved workspace
w = (RooWorkspace*) TFile::Open("output_combined_meas_model.root")->Get("combined");
Re-running the previous block of lines for printing the pdf values, I see that the clone pdf now yields the same value for both bins, unlike the original.
Is this expected behaviour? If so, is there a way to save in a file the dependence we see initially?
Thank you, and cheers
Emanuel