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");
    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++)

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

        //Set bin weight and hi/lo errors to custom values

        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);

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.