Bug on event's error once doing RooDataHist::add method

Hello,

it seems that the error is not preserved when moving from a given RooDataHist source object to a destination one using the ‘add(…’ method.

Here is the proof below with a minimal example.
i fill an histogram with 25 everywhere. The error is sqrt(25)=5 everywhere.
i print the content and error for an initial RooDataHist : it is fine.
Then i create a new RooDataHist, that is empty.
The i add to the new RooDataHist the initial RooDataHist : the errors are not the same as the initial RooDataHist.
I put a solution to this in the mode “MODE_PROBLEM” of 0
while the current problem is the mode with 1.

Do you agree ?
If you agree, could you correct the code and provide a new version.
Do you disagree ?
If you disagree, could you explain why the error is not preserved ? How to preserve it ?

Thank you for everything

//example :

{
//problem : add an initial datahist in an previously empty datahist
//bug : the resulted datahist error is not respecting the error of the initial datahist

#define MODE_PROBLEM 1

RooRealVar *roorealvar_TheVariable=new RooRealVar(“TheVariable”,“TheVariable”,60,160);
roorealvar_TheVariable->setBins(50); //important instructions for plotting

TH1F *hist_bkg_gamgam_bb=new TH1F(“hist_bkg_gamgam_bb”,“hist_bkg_gamgam_bb”,50,60,160);
hist_bkg_gamgam_bb->Sumw2();
for (int i=1;i<=hist_bkg_gamgam_bb->GetNbinsX();i++) {
for (int j=0;j<25;j++)
hist_bkg_gamgam_bb->Fill(hist_bkg_gamgam_bb->GetBinCenter(i));
}

RooDataHist datahist_bkg_gamgam_bb(“datahist_bkg_gamgam_bb”,“datahist_bkg_gamgam_bb”,RooArgList(*roorealvar_TheVariable),RooFit::Import(*hist_bkg_gamgam_bb));

//initial datahist
RooArgSet *myargset=datahist_bkg_gamgam_bb.get(20); //place to mgamgam=101 GeV
cout << “value=” << datahist_bkg_gamgam_bb.weight() << endl;
// cout << “error on value with weightSquared=” << datahist_bkg_gamgam_bb.weightSquared() << endl;
cout << “error on value SumW2=” << datahist_bkg_gamgam_bb.weightError(RooAbsData::SumW2) << endl;
cout << “error on value Poisson=” << datahist_bkg_gamgam_bb.weightError(RooAbsData::Poisson) << endl;

RooDataHist datahist_data(“datahist_data”,“datahist_data”,RooArgList(*roorealvar_TheVariable));
//next line gives crazy results
if (MODE_PROBLEM)
datahist_data.add(datahist_bkg_gamgam_bb); //this gives crazy results
else { //mode ‘patch’ ?
//double wgt=0.1;
double wgt=1;

for (int i=0;i<datahist_bkg_gamgam_bb.numEntries();i++) {
  const RooArgSet *row=datahist_bkg_gamgam_bb.get(i);
 datahist_data.add(*row,wgt*datahist_bkg_gamgam_bb.weight(),wgt*wgt*datahist_bkg_gamgam_bb.weightError(RooAbsData::SumW2)*datahist_bkg_gamgam_bb.weightError(RooAbsData::SumW2));
}

}

//error is not preserved in the mode problem of 1
cout << endl << endl;
RooArgSet *myargset=datahist_data.get(20); //place to mgamgam=101 GeV
cout << “value=” << datahist_data.weight() << endl;
// cout << “error on value weightSquared=” << datahist_data.weightSquared() << endl;
cout << “error on value SumW2=” << datahist_data.weightError(RooAbsData::SumW2) << endl;
cout << “error on value Poisson=” << datahist_data.weightError(RooAbsData::Poisson) << endl;
}