Clone of pdf not depending on observables when reading from file

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

@StephanH Can you help?

Could you Print("T") both pdfs? Then, we could see what observables they depend on.

Hi @StephanH ,

Thanks for looking into this. I didn’t know about Print("T"), seems useful. Here is the output of both pdfs when reading from file. Apart from the order and the suffix simPdf1 in the cloned objects, they seem equivalent. In particular, both should depend on the same obs_x_channel, right? I send the ouptut of Print("T") in the session where the pdfs are created as an attachment, because it’s longer and probably not as relevant. printT.txt (4.7 KB)

root [3] pdf->Print("T")
0x2ef23f0 RooSimultaneous::simPdf = 1 [Auto,Dirty] 
  0x2f97510/V- RooProdPdf::model_channel = 1 [Auto,Dirty] 
    0x2fe8ab0/V- RooGaussian::lumiConstraint = 1 [Auto,Dirty] 
      0x2ff24d0/V- RooConstVar::0.1 = 0.1
      0x2ff9680/V- RooRealVar::Lumi = 1
      0x31a17d0/V- RooRealVar::nominalLumi = 1
    0x302bdf0/V- RooRealSumPdf::channel_model = 1 [Auto,Dirty] 
      0x2ffe8c0/V- RooProduct::L_x_signal_channel_overallSyst_x_Exp = 1 [Auto,Clean] 
        0x2ff9680/V- RooRealVar::Lumi = 1
        0x3005f30/V- RooProduct::signal_channel_overallSyst_x_Exp = 1 [Auto,Clean] 
          0x3006990/V- RooHistFunc::signal_channel_nominal = 1 [Auto,Clean] 
            0x300ec30/V- RooRealVar::obs_x_channel = 1.5
          0x30187d0/V- RooProduct::signal_channel_overallNorm_x_sigma_epsilon = 1 [Auto,Clean] 
            0x3019270/V- RooRealVar::mu = 1
            0x3018120/V- RooConstVar::signal_channel_epsilon = 1
      0x302b670/V- RooRealVar::binWidth_obs_x_channel_0 = 1
  0x2e83860/V- RooCategory::channelCat = channel(idx = 0)

root [4] pdf1->Print("T")
0x3117700 RooSimultaneous::simPdf1 = 1 [Auto,Dirty] 
  0x2e83860/V- RooCategory::channelCat = channel(idx = 0)

  0x3111410/V- RooProdPdf::model_channel_simPdf1 = 1 [Auto,Dirty] 
    0x2fe8ab0/V- RooGaussian::lumiConstraint = 1 [Auto,Dirty] 
      0x2ff24d0/V- RooConstVar::0.1 = 0.1
      0x2ff9680/V- RooRealVar::Lumi = 1
      0x31a17d0/V- RooRealVar::nominalLumi = 1
    0x3021c60/V- RooRealSumPdf::channel_model_simPdf1 = 1 [Auto,Dirty] 
      0x302b670/V- RooRealVar::binWidth_obs_x_channel_0 = 1
      0x30211d0/V- RooProduct::L_x_signal_channel_overallSyst_x_Exp_simPdf1 = 1 [Auto,Clean] 
        0x2ff9680/V- RooRealVar::Lumi = 1
        0x3020740/V- RooProduct::signal_channel_overallSyst_x_Exp_simPdf1 = 1 [Auto,Clean] 
          0x3006990/V- RooHistFunc::signal_channel_nominal = 1 [Auto,Clean] 
            0x300ec30/V- RooRealVar::obs_x_channel = 1.5
          0x3017670/V- RooProduct::signal_channel_overallNorm_x_sigma_epsilon_simPdf1 = 1 [Auto,Clean] 
            0x3018120/V- RooConstVar::signal_channel_epsilon = 1
            0x301f320/V- RooRealVar::mu1 = 1

Ok, so far, they look identical.

and

Did you check that

Actually returns this x?
Try

x->Print("V")

EDIT

I must have fixed this a while ago. Running it with ROOT 6.20 like this:

ssh lxplus.cern.ch
source /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/setup.sh
root.exe WSProblem.C

results in:

[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel_model_Int[obs_x_channel]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel)
0.666667
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel_model_simPdf1_Int[obs_x_channel]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel)
0.666667
0.333333
0.333333

If it doesn’t work with 6.20, let me know.

EDIT 2:

Oh, I missed that the problem only happens in a new session. Let me try …

Hi, did you manage to reproduce the error? Thanks again!

Not yet. Many other things to do at the same time.

I might have fixed it a few weeks ago. See this:

$ source /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/setup.sh 
$ root 'histos.C+g(true)'
[...]
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel_model_Int[obs_x_channel]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel)
0.666667
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel_model_simPdf1_Int[obs_x_channel]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel)
0.666667
0.333333
0.333333
root [1] .q

$ root -l 'histos.C+g(false)'
root [0] 
Processing histos.C+g(false)...
[...]
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel_model_Int[obs_x_channel]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel)
0.666667
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel_model_simPdf1_Int[obs_x_channel]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel)
0.666667
0.333333
0.666667
root [1] .q

OK - bug. Root version:
$ root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.20/02                        https://root.cern |
  | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Mar 15 2020, 15:25:34                 |
  | From tags/v6-20-02@v6-20-02                                      |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] .q

And now with the nightlies, i.e. the soon-to-be-released 6.22:

source /cvmfs/sft-nightlies.cern.ch/lcg/views/dev3/latest/x86_64-centos7-gcc9-opt/setup.sh 
$ root -l 'histos.C+g(true)'
[...]
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel_model_Int[obs_x_channel]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel)
0.666667
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel_model_simPdf1_Int[obs_x_channel]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel)
0.666667
0.333333
0.333333
root [1] .x histos.C+g(false)
Info in <ACLiC>: unmodified script has already been compiled and loaded
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel_model_Int[obs_x_channel]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel)
0.666667
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel_model_simPdf1_Int[obs_x_channel]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel)
0.666667
0.333333
0.333333 

Hi, thanks a lot! I confirm that this is fixed using the nightly release.

1 Like

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