Crash with ToyMCSampler and proof

This code produced a crash when compiled:

root -l problem.C+

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif

#include <TStyle.h>
#include <TLine.h>
#include <TH1F.h>
#include <TH2F.h>
#include <TGraphErrors.h>
#include <TCanvas.h>
#include <RooRealVar.h>
#include <RooDataSet.h>
#include <RooStats/SimpleLikelihoodRatioTestStat.h>
#include <RooStats/ToyMCSampler.h>
#include <RooStats/SamplingDistPlot.h>
#include <RooStats/ProofConfig.h>
#include "RooPlot.h"


using namespace std;
using namespace RooFit;
using namespace RooStats;


void problem(){
    RooWorkspace w("w",kFALSE) ;
 
    w.factory("Gaussian::opal(density[0,100], opal_mean[2.2], resolution[0.2])"); // H0
    w.factory("Gaussian::quartz(density, quartz_density[2.6], resolution)");

    RooAbsPdf* opal_model = w.pdf("opal");
    RooAbsPdf* quartz_model = w.pdf("quartz");
    RooRealVar* density = w.var("density");

    const int total_exp = 20000;
    const int nmeas = 1;

    SimpleLikelihoodRatioTestStat test(*opal_model, *quartz_model);

    RooRealVar q_value("q_value", "q value", -200, 200);
    RooDataSet q_value_given_opal_data("q_value_given_opal_data", "q value given opal", RooArgSet(q_value));
    RooArgSet dummyPOI(0);

    ToyMCSampler sampler(test, total_exp);
    ProofConfig pc(w, 2, "", kTRUE);
    sampler.SetProofConfig(&pc);
    sampler.SetNEventsPerToy(nmeas);
    sampler.SetObservables(RooArgSet(*density));
    sampler.SetParametersForTestStat(dummyPOI);
    sampler.SetPdf(*opal_model);

    SamplingDistribution* sampling_dist = sampler.GetSamplingDistribution(dummyPOI);
    double alpha_cut = sampling_dist->InverseCDF(0.95);
    cout << "alpha cut: " << alpha_cut << endl;
    SamplingDistPlot dist_plot;
    dist_plot.AddSamplingDistributionShaded(sampling_dist, -1000, alpha_cut);
    dist_plot.SetLineColor(kGreen, sampling_dist);

    TCanvas* canvas = new TCanvas();
    canvas->cd();
    dist_plot.Draw();

}

It works when not compiled, even if it crashed when ProofConfig has the flag true for the interface and I plot something before.

ROOT 5.30/03

Hi,

This problem is due to the way yo set the observables in the ToyMCSampler. We will fix this in the ToyMCSampler to copy the passed object, but for the moment instead of

sampler.SetObservables(RooArgSet(*density));

do

RooArgSet  obs(*density);
sampler.SetObservables( obs );

Thank you for reporting this problem

Lorenzo