Change errors on RooDataHist

Dear RooFitters,

I cannot, for the life of me, figure out how to change the errors associated with bins of a RooDataHist. Here is a minimal example where I try looping over bins and using RooDataHist::set (…) to define new errors.

using namespace RooFit;

void RooDataHistErrors()
{
    //Generate some data
    RooWorkspace *wksp = new RooWorkspace("wksp");
    wksp->factory("Exponential::exp(x[0.,1.],k[-13])");
    RooDataHist* myHist = wksp->pdf("exp")->generateBinned(*wksp->var("x"),10000,ExpectedData(true));

    //Plot the data
    RooPlot* plot = wksp->var("x")->frame();
    myHist->plotOn(plot, DataError(RooAbsData::SumW2), MarkerColor(kRed), LineColor(kRed));

    //Loop over bins
    for(int i=0; i < myHist->numEntries(); i++)
    {
        wksp->var("x")->setVal(myHist->get(i)->getRealValue("x"));

        double errLo; double errHi;
        myHist->weightError(errLo,errHi);
        cout << "\nbin " << i << " before: " << myHist->weight() << " +" << errHi << " -" << errLo << endl;

        //Set bin weight and hi/lo errors to custom values
        myHist->set(RooArgSet(*wksp->var("x")),1.,0.5,0.25);

        myHist->weightError(errLo,errHi);
        cout << "bin " << i << " after: " << myHist->weight() << " +" << errHi << " -" << errLo << endl;
    }

    //Plot the data after setting the content
    myHist->plotOn(plot, DataError(RooAbsData::SumW2), MarkerColor(kBlue), LineColor(kBlue));
    TCanvas* can = new TCanvas("can", "can", 800, 600);
    plot->Draw();
    can->Print("RooDataHistErrors.root","root");
}


As you can see, the printout seems to indicate that each bin remains unchanged whereas the plot shows the content is being changed as desired. In any case, the errors are not affected.

Please let me know how to perform this simple task (preferably without changing to TH1 and back).

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