Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ParamHistFunc : public RooAbsReal {

RooDataHist const& dataHist() const { return _dataSet; }

double binVolume() const { return _dataSet.binVolume(); }
double binVolume(std::size_t i) const { return _dataSet.binVolume(i); }

bool forceAnalyticalInt(const RooAbsArg&) const override { return true ; }

Expand Down
2 changes: 1 addition & 1 deletion roofit/histfactory/src/RooBarlowBeestonLL.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void RooStats::HistFactory::RooBarlowBeestonLL::initializeBarlowCache() {
cache.bin_center = bin_center;
cache.observables = obsSet;

cache.binVolume = param_func->binVolume();
cache.binVolume = param_func->binVolume(bin_index);

// Delete this part, simply a comment
RooArgList obs_list( *(cache.bin_center) );
Expand Down
6 changes: 3 additions & 3 deletions roofit/roofit/src/RooHistConstraint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ RooHistConstraint::RooHistConstraint(const char *name, const char *title,

// Now populate nominal with parameters
for (int i=0 ; i<phf->_dh.numEntries() ; i++) {
phf->_dh.get(i) ;
if (phf->_dh.weight()<threshold && phf->_dh.weight() != 0.) {
const double wi = phf->_dh.weight(i) ;
if (wi<threshold && wi != 0.) {
const char* vname = Form("%s_nominal_bin_%i",GetName(),i) ;
auto var = std::make_unique<RooRealVar>(vname,vname,0,1.E30);
var->setVal(phf->_dh.weight()) ;
var->setVal(wi) ;
var->setConstant(true);

auto gamma = static_cast<RooRealVar*>(phf->_p.at(i));
Expand Down
14 changes: 8 additions & 6 deletions roofit/roofit/src/RooIntegralMorph.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ void RooIntegralMorph::MorphCacheElem::calculate(TIterator* dIter)
// Zero output histogram below lowest calculable X value
for (int i=0; i<_yatXmin ; i++) {
dIter->Next() ;
//_hist->get(i) ;
hist()->set(0) ;
const std::size_t binIdx = hist()->getIndex(*hist()->get(), /*fast=*/true);
hist()->set(binIdx, 0, -1) ;
}

double x1 = _x->getMin("cache");
Expand All @@ -420,14 +420,16 @@ void RooIntegralMorph::MorphCacheElem::calculate(TIterator* dIter)
double fbarX = f1x1*f2x2 / ( _alpha->getVal()*f2x2 + (1-_alpha->getVal())*f1x1 ) ;

dIter->Next() ;
//_hist->get(i) ;
hist()->set(fbarX) ;
{
const std::size_t binIdx = hist()->getIndex(*hist()->get(), /*fast=*/true);
hist()->set(binIdx, fbarX, -1) ;
}
}
// Zero output histogram above highest calculable X value
for (int i=_yatXmax+1 ; i<nbins ; i++) {
dIter->Next() ;
//_hist->get(i) ;
hist()->set(0) ;
const std::size_t binIdx = hist()->getIndex(*hist()->get(), /*fast=*/true);
hist()->set(binIdx, 0, -1) ;
}

pdf()->setUnitNorm(true) ;
Expand Down
11 changes: 5 additions & 6 deletions roofit/roofit/src/RooLagrangianMorphFunc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2572,12 +2572,12 @@ TH1 *RooLagrangianMorphFunc::createTH1(const std::string &name, bool correlateEr
continue;
}
const RooDataHist &dhist = hf->dataHist();
dhist.get(i);
RooAbsReal *formula = dynamic_cast<RooAbsReal *>(prod->components().find(Form("w_%s", prod->GetName())));
double weight = formula->getVal();
unc2 += dhist.weightSquared() * weight * weight;
unc += sqrt(dhist.weightSquared()) * weight;
val += dhist.weight() * weight;
const double w2 = dhist.weightSquared(i);
unc2 += w2 * weight * weight;
unc += sqrt(w2) * weight;
val += dhist.weight(i) * weight;
}
hist->SetBinContent(i + 1, val);
hist->SetBinError(i + 1, correlateErrors ? unc : sqrt(unc2));
Expand Down Expand Up @@ -2827,8 +2827,7 @@ double RooLagrangianMorphFunc::expectedUncertainty() const
if (hf) {
const RooDataHist &hist = hf->dataHist();
for (Int_t j = 0; j < observable->getBins(); ++j) {
hist.get(j);
newunc2 += hist.weightSquared();
newunc2 += hist.weightSquared(j);
}
} else if (rv) {
newunc2 = pow(rv->getError(), 2);
Expand Down
9 changes: 4 additions & 5 deletions roofit/roofit/src/RooParamHistFunc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ RooParamHistFunc::RooParamHistFunc(const char *name, const char *title, RooDataH
// Now populate p with parameters
RooArgSet allVars;
for (Int_t i = 0; i < _dh.numEntries(); i++) {
_dh.get(i);
const double wi = _dh.weight(i);
const char *vname = Form("%s_gamma_bin_%i", GetName(), i);
RooRealVar *var = new RooRealVar(vname, vname, 0, 1000);
var->setVal(_relParam ? 1 : _dh.weight());
var->setError(_relParam ? 1 / sqrt(_dh.weight()) : sqrt(_dh.weight()));
var->setVal(_relParam ? 1 : wi);
var->setError(_relParam ? 1 / sqrt(wi) : sqrt(wi));
var->setConstant(true);
allVars.add(*var);
_p.add(*var);
Expand Down Expand Up @@ -94,8 +94,7 @@ void RooParamHistFunc::setActual(Int_t ibin, double newVal)

double RooParamHistFunc::getNominal(Int_t ibin) const
{
_dh.get(ibin) ;
return _dh.weight() ;
return _dh.weight(ibin) ;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
22 changes: 11 additions & 11 deletions roofit/roofitcore/src/RooAbsPdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1703,26 +1703,27 @@ RooFit::OwningPtr<RooDataHist> RooAbsPdf::generateBinned(const RooArgSet &whatVa
Int_t histOutSum(0) ;
for (int i=0 ; i<hist->numEntries() ; i++) {
hist->get(i) ;
const double wi = hist->weight(i) ;
if (expectedData) {

// Expected data, multiply p.d.f by nEvents
double w=hist->weight()*nEvents ;
double w=wi*nEvents ;
hist->set(i, w, sqrt(w));

} else if (extended) {

// Extended mode, set contents to Poisson(pdf*nEvents)
double w = RooRandom::randomGenerator()->Poisson(hist->weight()*nEvents) ;
hist->set(w,sqrt(w)) ;
double w = RooRandom::randomGenerator()->Poisson(wi*nEvents) ;
hist->set(i, w, sqrt(w)) ;

} else {

// Regular mode, fill array of weights with Poisson(pdf*nEvents), but to not fill
// histogram yet.
if (hist->weight()>histMax) {
histMax = hist->weight() ;
if (wi>histMax) {
histMax = wi ;
}
histOut[i] = RooRandom::randomGenerator()->Poisson(hist->weight()*nEvents) ;
histOut[i] = RooRandom::randomGenerator()->Poisson(wi*nEvents) ;
histOutSum += histOut[i] ;
}
}
Expand All @@ -1745,7 +1746,7 @@ RooFit::OwningPtr<RooDataHist> RooAbsPdf::generateBinned(const RooArgSet &whatVa
hist->get(ibinRand) ;
double ranY = RooRandom::randomGenerator()->Uniform(histMax) ;

if (ranY<hist->weight()) {
if (ranY<hist->weight(ibinRand)) {
if (wgt==1) {
histOut[ibinRand]++ ;
} else {
Expand All @@ -1768,8 +1769,7 @@ RooFit::OwningPtr<RooDataHist> RooAbsPdf::generateBinned(const RooArgSet &whatVa

// Transfer working array to histogram
for (int i=0 ; i<hist->numEntries() ; i++) {
hist->get(i) ;
hist->set(histOut[i],sqrt(1.0*histOut[i])) ;
hist->set(i, histOut[i], sqrt(1.0*histOut[i])) ;
}

} else if (expectedData) {
Expand All @@ -1779,8 +1779,8 @@ RooFit::OwningPtr<RooDataHist> RooAbsPdf::generateBinned(const RooArgSet &whatVa
// bin average and bin integral in sampling bins
double corr = nEvents/hist->sumEntries() ;
for (int i=0 ; i<hist->numEntries() ; i++) {
hist->get(i) ;
hist->set(hist->weight()*corr,sqrt(hist->weight()*corr)) ;
const double wnew = hist->weight(i)*corr ;
hist->set(i, wnew, sqrt(wnew)) ;
}

}
Expand Down
2 changes: 1 addition & 1 deletion roofit/roofitcore/src/RooAbsReal.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ RooDataHist* RooAbsReal::fillDataHist(RooDataHist *hist, const RooArgSet* normSe
const RooArgSet* obs = hist->get(i) ;
double binVal = theClone->getVal(normSet?normSet:obs)*scaleFactor ;
if (correctForBinSize) {
binVal*= hist->binVolume() ;
binVal*= hist->binVolume(i) ;
}
hist->set(i, binVal, 0.);
}
Expand Down
19 changes: 10 additions & 9 deletions roofit/roofitcore/src/RooBinnedGenContext.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,28 @@ RooDataSet *RooBinnedGenContext::generate(double nEvt, bool /*skipInit*/, bool e
double histMax(-1) ;
Int_t histOutSum(0) ;
for (int i=0 ; i<_hist->numEntries() ; i++) {
_hist->get(i) ;
const RooArgSet* coords = _hist->get(i) ;
const double wi = _hist->weight(i) ;
if (_expectedData) {

// Expected data, multiply p.d.f by nEvents
double w=_hist->weight()*nEvents ;
wudata->add(*_hist->get(),w) ;
double w=wi*nEvents ;
wudata->add(*coords,w) ;

} else if (extended) {

// Extended mode, set contents to Poisson(pdf*nEvents)
double w = RooRandom::randomGenerator()->Poisson(_hist->weight()*nEvents) ;
wudata->add(*_hist->get(),w) ;
double w = RooRandom::randomGenerator()->Poisson(wi*nEvents) ;
wudata->add(*coords,w) ;

} else {

// Regular mode, fill array of weights with Poisson(pdf*nEvents), but to not fill
// histogram yet.
if (_hist->weight()>histMax) {
histMax = _hist->weight() ;
if (wi>histMax) {
histMax = wi ;
}
histOut[i] = RooRandom::randomGenerator()->Poisson(_hist->weight()*nEvents) ;
histOut[i] = RooRandom::randomGenerator()->Poisson(wi*nEvents) ;
histOutSum += histOut[i] ;
}
}
Expand All @@ -182,7 +183,7 @@ RooDataSet *RooBinnedGenContext::generate(double nEvt, bool /*skipInit*/, bool e
_hist->get(ibinRand) ;
double ranY = RooRandom::randomGenerator()->Uniform(histMax) ;

if (ranY<_hist->weight()) {
if (ranY<_hist->weight(ibinRand)) {
if (wgt==1) {
histOut[ibinRand]++ ;
} else {
Expand Down
4 changes: 2 additions & 2 deletions roofit/roofitcore/src/RooChi2Var.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ double RooChi2Var::evaluatePartition(std::size_t firstEvent, std::size_t lastEve
}
if (!doSelect) continue ;

const double nData = hdata->weight() ;
const double nData = hdata->weight(i) ;

const double nPdf = _funcClone->getVal(_normSet) * normFactor * hdata->binVolume() ;
const double nPdf = _funcClone->getVal(_normSet) * normFactor * hdata->binVolume(i) ;

const double eExt = nPdf-nData ;

Expand Down
16 changes: 9 additions & 7 deletions roofit/roofitcore/src/RooDataHist.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ void RooDataHist::importDHistSet(const RooArgList & /*vars*/, RooCategory &index
// Transfer contents
for (Int_t i = 0; i < dhist->numEntries(); i++) {
_vars.assign(*dhist->get(i));
add(_vars, dhist->weight() * initWgt, pow(dhist->weightError(SumW2), 2));
add(_vars, dhist->weight(i) * initWgt, pow(dhist->weightError(SumW2), 2));
}
}
}
Expand Down Expand Up @@ -955,7 +955,7 @@ std::unique_ptr<RooAbsData> RooDataHist::reduceEng(const RooArgSet& varSubset, c

if (!cloneVar || cloneVar->getVal()) {
weightError(lo,hi,SumW2) ;
rdh->add(*row,weight(),lo*lo) ;
rdh->add(*row,weight(i),lo*lo) ;
}
}

Expand Down Expand Up @@ -1572,7 +1572,7 @@ void RooDataHist::weightError(double& lo, double& hi, ErrorType etype) const
throw std::invalid_argument("RooDataHist::weightError(" + std::string(GetName()) + ") error type Expected not allowed here");
break ;

case Poisson:
case Poisson: {
if (_errLo && _errLo[_curIndex] >= 0.0) {
// Weight is preset or precalculated
lo = _errLo[_curIndex];
Expand All @@ -1586,12 +1586,14 @@ void RooDataHist::weightError(double& lo, double& hi, ErrorType etype) const
// Calculate poisson errors
double ym;
double yp;
RooHistError::instance().getPoissonInterval(Int_t(weight()+0.5),ym,yp,1) ;
_errLo[_curIndex] = weight()-ym;
_errHi[_curIndex] = yp-weight();
const double w = weight(_curIndex);
RooHistError::instance().getPoissonInterval(Int_t(w+0.5),ym,yp,1) ;
_errLo[_curIndex] = w-ym;
_errHi[_curIndex] = yp-w;
lo = _errLo[_curIndex];
hi = _errHi[_curIndex];
return ;
}

case SumW2:
lo = std::sqrt(weightSquared(_curIndex));
Expand Down Expand Up @@ -2348,7 +2350,7 @@ void RooDataHist::printContents(std::ostream& os) const

double lo, hi;
weightError(lo, hi, RooAbsData::SumW2);
os << ", weight=" << weight() << " +/- [" << lo << "," << hi << "]"
os << ", weight=" << weight(i) << " +/- [" << lo << "," << hi << "]"
<< std::endl;
}
}
Expand Down
5 changes: 3 additions & 2 deletions roofit/roofitcore/src/RooFFTConvPdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,11 @@ void RooFFTConvPdf::fillCacheSlice(FFTCacheElem& aux, const RooArgSet& slicePos)
while (j>=N2) j-= N2 ;

iter->Next() ;
const std::size_t binIdx = cacheHist.getIndex(*cacheHist.get(), /*fast=*/true);
#ifndef ROOFIT_MATH_FFTW3
cacheHist.set(output[j]);
cacheHist.set(binIdx, output[j], -1.);
#else
cacheHist.set(aux.fftc2r->GetPointReal(j));
cacheHist.set(binIdx, aux.fftc2r->GetPointReal(j), -1.);
#endif
}
}
Expand Down
7 changes: 2 additions & 5 deletions roofit/roofitcore/src/RooHistFunc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ double RooHistFunc::maxVal(Int_t code) const

double max(-1) ;
for (Int_t i=0 ; i<_dataHist->numEntries() ; i++) {
_dataHist->get(i) ;
double wgt = _dataHist->weight() ;
double wgt = _dataHist->weight(i) ;
if (wgt>max) max=wgt ;
}

Expand Down Expand Up @@ -487,9 +486,7 @@ bool RooHistFunc::areIdentical(const RooDataHist& dh1, const RooDataHist& dh2)
if (std::abs(dh1.sumEntries()-dh2.sumEntries())>1e-8) return false ;
if (dh1.numEntries() != dh2.numEntries()) return false ;
for (int i=0 ; i < dh1.numEntries() ; i++) {
dh1.get(i) ;
dh2.get(i) ;
if (std::abs(dh1.weight()-dh2.weight())>1e-8) return false ;
if (std::abs(dh1.weight(i)-dh2.weight(i))>1e-8) return false ;
}
using RooHelpers::getColonSeparatedNameString;
if (getColonSeparatedNameString(*dh1.get()) != getColonSeparatedNameString(*dh2.get())) return false ;
Expand Down
7 changes: 2 additions & 5 deletions roofit/roofitcore/src/RooHistPdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,7 @@ double RooHistPdf::maxVal(Int_t code) const

double max(-1) ;
for (Int_t i=0 ; i<_dataHist->numEntries() ; i++) {
_dataHist->get(i) ;
double wgt = _dataHist->weight() ;
double wgt = _dataHist->weight(i) ;
if (wgt>max) max=wgt ;
}

Expand All @@ -548,9 +547,7 @@ bool RooHistPdf::areIdentical(const RooDataHist& dh1, const RooDataHist& dh2)
if (std::abs(dh1.sumEntries()-dh2.sumEntries())>1e-8) return false ;
if (dh1.numEntries() != dh2.numEntries()) return false ;
for (int i=0 ; i < dh1.numEntries() ; i++) {
dh1.get(i) ;
dh2.get(i) ;
if (std::abs(dh1.weight()-dh2.weight())>1e-8) return false ;
if (std::abs(dh1.weight(i)-dh2.weight(i))>1e-8) return false ;
}
return true ;
}
Expand Down
Loading
Loading