94 ?
static_cast<std::unique_ptr<RooAbsDataStore>
>(std::make_unique<RooTreeDataStore>(
name, title, vars))
95 :
static_cast<std::unique_ptr<RooAbsDataStore>
>(std::make_unique<RooVectorDataStore>(
name, title, vars));
169 std::map<string,TH1*> histMap,
double wgt) :
193 std::map<string,RooDataHist*> dhistMap,
double wgt) :
221 std::stringstream errorMsgStream;
222 errorMsgStream <<
"RooDataHist::ctor(" <<
GetName() <<
") ERROR: dimension of input histogram must match "
223 <<
"number of dimension variables";
224 const std::string errorMsg = errorMsgStream.str();
225 coutE(InputArguments) << errorMsg << std::endl;
226 throw std::invalid_argument(errorMsg);
276 RooAbsData(
name,title,
RooArgSet(vars,(
RooAbsArg*)
RooCmdConfig::decodeObjOnTheFly(
"RooDataHist::RooDataHist",
"IndexCat",0,0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)))
284 pc.
defineInt(
"impDens",
"ImportHisto",0) ;
286 pc.
defineObject(
"impSliceHist",
"ImportHistoSlice",0,0,
true) ;
287 pc.
defineString(
"impSliceState",
"ImportHistoSlice",0,
"",
true) ;
288 pc.
defineObject(
"impSliceDHist",
"ImportDataHistSlice",0,0,
true) ;
289 pc.
defineString(
"impSliceDState",
"ImportDataHistSlice",0,
"",
true) ;
293 pc.
defineSet(
"glObs",
"GlobalObservables",0,0) ;
294 pc.
defineMutex(
"ImportHisto",
"ImportHistoSlice",
"ImportDataHistSlice") ;
307 throw std::invalid_argument(
"Invalid command arguments passed to RooDataHist constructor!");
313 bool impDens = pc.
getInt(
"impDens") ;
314 double initWgt = pc.
getDouble(
"weight") ;
315 const char* impSliceNames = pc.
getString(
"impSliceState",
"",
true) ;
318 const char* impSliceDNames = pc.
getString(
"impSliceDState",
"",
true) ;
325 importTH1(vars,*impHist,initWgt, impDens) ;
327 }
else if (indexCat) {
330 if (!impSliceHistos.
empty()) {
333 std::map<std::string,TH1*> hmap ;
334 auto hiter = impSliceHistos.
begin() ;
335 for (
const auto& token :
ROOT::Split(impSliceNames,
",")) {
336 auto histo =
static_cast<TH1*
>(*hiter);
345 std::map<std::string,RooDataHist*> dmap ;
346 auto hiter = impSliceDHistos.
begin() ;
347 for (
const auto& token :
ROOT::Split(impSliceDNames,
",")) {
402 Int_t ix(0),iy(0),iz(0) ;
403 for (ix=0 ; ix < xvar->
getBins() ; ix++) {
406 for (iy=0 ; iy < yvar->
getBins() ; iy++) {
409 for (iz=0 ; iz < zvar->
getBins() ; iz++) {
411 double bv = doDensityCorrection ?
binVolume(vset) : 1;
415 double bv = doDensityCorrection ?
binVolume(vset) : 1;
420 double bv = doDensityCorrection ?
binVolume(vset) : 1 ;
428bool checkConsistentAxes(
const TH1*
first,
const TH1* second) {
444 constexpr double tolerance = 1
e-6;
446 auto const& vars1 = *
h1.get();
447 auto const& vars2 = *h2.
get();
450 if(!vars1.hasSameLayout(vars2)) {
454 for(std::size_t iVar = 0; iVar < vars1.size(); ++iVar) {
455 auto * var1 =
dynamic_cast<RooRealVar*
>(vars1[iVar]);
456 auto * var2 =
dynamic_cast<RooRealVar*
>(vars2[iVar]);
459 if((!var1 && var2) || (var1 && !var2))
return false;
466 auto const& bng2 = var2->getBinning();
469 if(bng1.numBins() != bng2.numBins())
return false;
471 std::size_t nBins = bng1.
numBins();
474 for(std::size_t iBin = 0; iBin < nBins; ++iBin) {
475 double v1 = bng1.binLow(iBin);
476 double v2 = bng2.binLow(iBin);
477 if(std::abs((
v1 -
v2) /
v1) > tolerance)
return false;
479 double v1 = bng1.binHigh(nBins - 1);
480 double v2 = bng2.binHigh(nBins - 1);
481 if(std::abs((
v1 -
v2) /
v1) > tolerance)
return false;
499 for (
const auto& hiter : hmap) {
502 histo = hiter.second;
504 if (!checkConsistentAxes(histo, hiter.second)) {
505 coutE(InputArguments) <<
"Axes of histogram " << hiter.second->
GetName() <<
" are not consistent with first processed "
506 <<
"histogram " << histo->
GetName() << std::endl;
507 throw std::invalid_argument(
"Axes of inputs for RooDataHist are inconsistent");
511 if (!indexCat.
hasLabel(hiter.first)) {
513 coutI(InputArguments) <<
"RooDataHist::importTH1Set(" <<
GetName() <<
") defining state \"" << hiter.first <<
"\" in index category " << indexCat.
GetName() << endl ;
522 coutE(InputArguments) <<
"RooDataHist::importTH1Set(" <<
GetName() <<
"): dimension of input histogram must match "
523 <<
"number of continuous variables" << endl ;
524 throw std::invalid_argument(
"Inputs histograms for RooDataHist are not compatible with dimensions of variables.");
560 Int_t ic(0),ix(0),iy(0),iz(0) ;
561 for (ic=0 ; ic < icat->
numBins(0) ; ic++) {
564 for (ix=0 ; ix < xvar->
getBins() ; ix++) {
567 for (iy=0 ; iy < yvar->
getBins() ; iy++) {
570 for (iz=0 ; iz < zvar->
getBins() ; iz++) {
572 double bv = doDensityCorrection ?
binVolume(vset)/avgBV : 1;
576 double bv = doDensityCorrection ?
binVolume(vset)/avgBV : 1;
581 double bv = doDensityCorrection ?
binVolume(vset)/avgBV : 1;
602 for (
const auto& diter : dmap) {
604 std::string
const& label = diter.first;
607 if(!dhistForBinning) {
608 dhistForBinning = dhist;
611 if(!hasConsistentLayoutAndBinning(*dhistForBinning, *dhist)) {
612 coutE(InputArguments) <<
"Layout or binning of histogram " << dhist->
GetName() <<
" is not consistent with first processed "
613 <<
"histogram " << dhistForBinning->
GetName() << std::endl;
614 throw std::invalid_argument(
"Layout or binning of inputs for RooDataHist is inconsistent");
621 coutI(InputArguments) <<
"RooDataHist::importDHistSet(" <<
GetName() <<
") defining state \"" << label <<
"\" in index category " << indexCat.
GetName() << endl ;
623 if (!icat->hasLabel(label)) {
624 icat->defineType(label) ;
629 for(
auto * theirVar : dynamic_range_cast<RooRealVar*>(dhistForBinning->
_vars)) {
631 if(!theirVar || !ourVar)
continue;
639 for (
const auto& diter : dmap) {
640 std::string
const& label = diter.first;
643 icat->setLabel(label.c_str()) ;
666 coutE(InputArguments) <<
"RooDataHist::adjustBinning(" << ownName <<
") ERROR: dimension " << ourVarName
667 <<
" must be real\n";
668 throw std::logic_error(
"Incorrect type object (" + ourVarName +
669 ") passed as argument to RooDataHist::_adjustBinning. Please report this issue.");
672 const double xlo = theirVar.
getMin();
673 const double xhi = theirVar.
getMax();
678 const double tolerance = 1
e-6 * xbins.averageBinWidth();
681 const double xloAdj = xbins.binLow(xbins.binNumber(xlo + tolerance));
682 const double xhiAdj = xbins.binHigh(xbins.binNumber(xhi - tolerance));
683 xbins.setRange(xloAdj, xhiAdj);
687 if (
true || std::abs(xloAdj - xlo) > tolerance || std::abs(xhiAdj - xhi) > tolerance) {
688 coutI(DataHandling) <<
"RooDataHist::adjustBinning(" << ownName <<
"): fit range of variable " << ourVarName
689 <<
" expanded to nearest bin boundaries: [" << xlo <<
"," << xhi <<
"] --> [" << xloAdj
690 <<
"," << xhiAdj <<
"]"
697 *
offset = xbins.rawBinNumber(xloAdj + tolerance);
703 const double tolerance = 1
e-6 * xbins.averageBinWidth();
706 const double xloAdj = xbins.binLow(xbins.binNumber(xlo + tolerance));
707 const double xhiAdj = xbins.binHigh(xbins.binNumber(xhi - tolerance));
708 xbins.setRange(xloAdj, xhiAdj);
711 if (std::abs(xloAdj - xlo) > tolerance || std::abs(xhiAdj - xhi) > tolerance) {
712 coutI(DataHandling) <<
"RooDataHist::adjustBinning(" << ownName <<
"): fit range of variable " << ourVarName
713 <<
" expanded to nearest bin boundaries: [" << xlo <<
"," << xhi <<
"] --> [" << xloAdj
714 <<
"," << xhiAdj <<
"]"
722 *
offset = xbins.rawBinNumber(xloAdj + tolerance);
758void cloneArray(
double*& ours,
const double* theirs, std::size_t
n) {
759 if (ours)
delete[] ours;
762 ours =
new double[
n];
763 std::copy(theirs, theirs+
n, ours);
767void initArray(
double*& arr, std::size_t
n,
double val) {
768 if (arr)
delete[] arr;
772 std::fill(arr, arr+
n, val);
788 for (
unsigned int i = 0; i <
_vars.
size(); ++i) {
800 const RooAbsBinning* binning = lvarg->getBinningPtr(
nullptr);
801 _lvbins.emplace_back(binning ? binning->
clone() :
nullptr);
810 for (
const auto var :
_vars) {
815 for (
unsigned int i = 0u; i<
n; i++) {
839 if (!fillTree) return ;
845 Int_t j(0), idx(0), tmp(ibin) ;
846 double theBinVolume(1) ;
851 theBinVolume *= arg2->getBinWidth(idx) ;
853 _binv[ibin] = theBinVolume ;
870 std::vector<double>& bounds =
_binbounds.back();
871 bounds.reserve(2 * it->numBins());
872 for (
Int_t i = 0; i < it->numBins(); ++i) {
873 bounds.push_back(it->binLow(i));
874 bounds.push_back(it->binHigh(i));
885 RooAbsData(other,newname),
RooDirItem(), _arrSize(other._arrSize), _idxMult(other._idxMult), _pbinvCache(other._pbinvCache)
896 for (
const auto rvarg :
_vars) {
914 std::size_t nStart, std::size_t nStop)
922 std::unique_ptr<RooArgSet> tmp;
927 coutE(DataHandling) <<
"RooDataHist::reduceEng(" <<
GetName() <<
") Couldn't deep-clone cut variable, abort," << endl ;
935 const std::size_t nevt = nStop < static_cast<std::size_t>(
numEntries()) ? nStop :
static_cast<std::size_t
>(
numEntries());
936 for (
auto i=nStart; i<nevt ; i++) {
939 bool doSelect(
true) ;
941 for (
const auto arg : *row) {
942 if (!arg->inRange(cutRange)) {
948 if (!doSelect) continue ;
950 if (!cloneVar || cloneVar->
getVal()) {
1012 if (&
_vars == &coords)
1015 std::size_t masterIdx = 0;
1017 for (
unsigned int i=0; i <
_vars.
size(); ++i) {
1024 const RooAbsArg* theVar = fast ? coords[i] : coords.
find(*internalVar);
1027 theVar = internalVar;
1037 assert(
dynamic_cast<const RooAbsReal*
>(theVar));
1038 const double val =
static_cast<const RooAbsReal*
>(theVar)->getVal();
1044 masterIdx +=
_idxMult[i] * cat->
getBin(
static_cast<const char*
>(
nullptr));
1070 <<
":plotOn: frame does not specify a plot variable" << endl;
1077 <<
":plotOn: dataset doesn't contain plot frame variable" << endl;
1081 o.
bins = &dataVar->getBinning() ;
1102 bool correctForBinSize,
bool cdfBoundaries)
1105 const std::size_t nEvents = xVals.
size();
1109 auto binIndices =
reinterpret_cast<int*
>(
output + nEvents) - nEvents;
1110 std::fill(binIndices, binIndices + nEvents, 0);
1116 std::vector<double> coordsExt(nBins+3);
1117 double* binCoords = coordsExt.data() + 2;
1119 for (std::size_t binIdx = 1; binIdx < nBins ; ++binIdx) {
1121 double binWidth =
_binv[0];
1122 binCoords[binIdx] = binIdx*binWidth + binCoords[0];
1125 double binCentDiff = 0.5*
_binv[binIdx-1] + 0.5*
_binv[binIdx];
1126 binCoords[binIdx] = binCoords[binIdx-1] + binCentDiff;
1130 std::vector<double> weightsExt(nBins+3);
1132 for (std::size_t binIdx = 0; binIdx < nBins; ++binIdx) {
1133 weightsExt[binIdx+2] = correctForBinSize ?
_wgt[binIdx] /
_binv[binIdx] :
_wgt[binIdx];
1136 if (cdfBoundaries) {
1137 coordsExt[0] = - 1
e-10 + binning.
lowBound();
1143 coordsExt[nBins+2] = binning.
highBound();
1144 weightsExt[nBins+2] = 1.;
1148 coordsExt[0] = binCoords[1] - 2*
_binv[0] -
_binv[1];
1149 weightsExt[0] = weightsExt[3];
1151 coordsExt[1] = binCoords[0] -
_binv[0];
1152 weightsExt[1] = weightsExt[2];
1154 coordsExt[nBins+2] = binCoords[nBins-1] +
_binv[nBins-1];
1155 weightsExt[nBins+2] = weightsExt[nBins+1];
1160 for (std::size_t i = 0; i < nEvents ; ++i) {
1161 double xVal = xVals[i];
1162 std::size_t binIdx = binIndices[i] + 2;
1166 if (xVal > coordsExt[binIdx]) {
1170 double x1 = coordsExt[binIdx-2];
1171 double y1 = weightsExt[binIdx-2];
1173 double x2 = coordsExt[binIdx-1];
1174 double y2 = weightsExt[binIdx-1];
1176 double x3 = coordsExt[binIdx];
1177 double y3 = weightsExt[binIdx];
1180 double quotient = (
x3-
x1) / (
x2-
x1);
1181 double x1Sqrd =
x1*
x1;
1182 double x3Sqrd =
x3*
x3;
1184 double secondCoeff = (y3 -
y1 - (
y2-
y1) * quotient) / (x3Sqrd - x1Sqrd - (
x2*
x2 - x1Sqrd) * quotient);
1185 double firstCoeff = (y3 -
y1 - secondCoeff*(x3Sqrd - x1Sqrd)) / (
x3-
x1);
1186 double zerothCoeff =
y1 - secondCoeff*x1Sqrd - firstCoeff*
x1;
1188 output[i] = secondCoeff * xVal * xVal + firstCoeff * xVal + zerothCoeff;
1209 bool correctForBinSize,
bool cdfBoundaries)
1212 const std::size_t nEvents = xVals.
size();
1216 auto binIndices =
reinterpret_cast<int*
>(
output + nEvents) - nEvents;
1217 std::fill(binIndices, binIndices + nEvents, 0);
1223 std::vector<double> coordsExt(nBins+2);
1224 double* binCoords = coordsExt.data() + 1;
1226 for (std::size_t binIdx = 1; binIdx < nBins ; ++binIdx) {
1228 double binWidth =
_binv[0];
1229 binCoords[binIdx] = binIdx*binWidth + binCoords[0];
1232 double binCentDiff = 0.5*
_binv[binIdx-1] + 0.5*
_binv[binIdx];
1233 binCoords[binIdx] = binCoords[binIdx-1] + binCentDiff;
1237 std::vector<double> weightsExt(nBins+2);
1239 for (std::size_t binIdx = 0; binIdx < nBins; ++binIdx) {
1240 weightsExt[binIdx+1] = correctForBinSize ?
_wgt[binIdx] /
_binv[binIdx] :
_wgt[binIdx];
1244 if (cdfBoundaries) {
1247 coordsExt[nBins+1] = binning.
highBound();
1248 weightsExt[nBins+1] = 1.;
1252 coordsExt[0] = binCoords[0] -
_binv[0];
1253 weightsExt[0] = weightsExt[1];
1254 coordsExt[nBins+1] = binCoords[nBins-1] +
_binv[nBins-1];
1255 weightsExt[nBins+1] = weightsExt[nBins];
1260 for (std::size_t i = 0; i < nEvents ; ++i) {
1261 double xVal = xVals[i];
1262 std::size_t binIdx = binIndices[i] + 1;
1266 if (xVal > coordsExt[binIdx]) { binIdx += 1; }
1268 double x1 = coordsExt[binIdx-1];
1269 double y1 = weightsExt[binIdx-1];
1270 double x2 = coordsExt[binIdx];
1271 double y2 = weightsExt[binIdx];
1274 double firstCoeff = (
y2-
y1) / (
x2-
x1);
1275 double zerothCoeff =
y1 - firstCoeff *
x1;
1277 output[i] = firstCoeff * xVal + zerothCoeff;
1298 auto const nEvents = xVals.
size();
1300 if (intOrder == 0) {
1304 auto binIndices =
reinterpret_cast<int*
>(
output + nEvents) - nEvents;
1305 std::fill(binIndices, binIndices + nEvents, 0);
1308 for (std::size_t i=0; i < nEvents; ++i) {
1309 auto binIdx = binIndices[i];
1313 else if (intOrder == 1) {
1316 else if (intOrder == 2) {
1321 coutE(InputArguments) <<
"RooDataHist::weights(" <<
GetName() <<
") interpolation in "
1322 << intOrder <<
" dimensions not yet implemented" << std::endl ;
1324 weights(
output, xVals, 1, correctForBinSize, cdfBoundaries);
1350 coutE(InputArguments) <<
"RooDataHist::weight(" <<
GetName() <<
") ERROR: interpolation order must be positive" << endl ;
1357 return correctForBinSize ?
_wgt[idx] /
_binv[idx] :
_wgt[idx];
1385 coutE(InputArguments) <<
"RooDataHist::weight(" <<
GetName() <<
") ERROR: interpolation order must be positive" << endl ;
1392 return correctForBinSize ?
_wgt[idx] /
_binv[idx] :
_wgt[idx];
1439 double xval = realX.
getVal() ;
1440 double yval = realY.getVal() ;
1445 int ybinLo = ybinC-intOrder/2 - ((yval<binningY.
binCenter(ybinC))?1:0) ;
1446 int ybinM = binningY.
numBins() ;
1449 auto offsetIdx = centralIdx - idxMultY * ybinC;
1453 double * xarr = yarr + intOrder + 1;
1454 for (
int i=ybinLo ; i<=intOrder+ybinLo ; i++) {
1456 if (i>=0 && i<ybinM) {
1459 xarr[i-ybinLo] = binningY.
binCenter(ibin) ;
1460 }
else if (i>=ybinM) {
1462 ibin = 2*ybinM-i-1 ;
1469 auto centralIdxX = offsetIdx + idxMultY * ibin;
1474 cout <<
"RooDataHist interpolating data is" << endl ;
1476 for (
int q=0;
q<=intOrder ;
q++) cout << xarr[
q] <<
" " ;
1477 cout <<
" yarr = " ;
1478 for (
int q=0;
q<=intOrder ;
q++) cout << yarr[
q] <<
" " ;
1486 coutE(InputArguments) <<
"RooDataHist::weight(" <<
GetName() <<
") interpolation in "
1487 << varInfo.
nRealVars <<
" dimensions not yet implemented" << endl ;
1488 return weightFast(bin,0,correctForBinSize,cdfBoundaries) ;
1522 throw std::invalid_argument(
Form(
"RooDataHist::weightError(%s) error type Auto not allowed here",
GetName())) ;
1526 throw std::invalid_argument(
Form(
"RooDataHist::weightError(%s) error type Expected not allowed here",
GetName())) ;
1584 auto const& binning =
static_cast<RooRealVar&
>(*
_vars[iDim]).getBinning();
1587 int fbinC = binning.binNumber(xval) ;
1588 int fbinLo = fbinC-intOrder/2 - ((xval<binning.binCenter(fbinC))?1:0) ;
1589 int fbinM = binning.numBins() ;
1592 auto offsetIdx = centralIdx - idxMult * fbinC;
1596 double * xarr = yarr + intOrder + 1;
1598 for (
int i=fbinLo ; i<=intOrder+fbinLo ; i++) {
1600 if (i>=0 && i<fbinM) {
1603 xarr[i-fbinLo] = binning.binCenter(ibin) ;
1604 auto idx = offsetIdx + idxMult * ibin;
1605 yarr[i - fbinLo] =
_wgt[idx];
1606 if (correctForBinSize) yarr[i-fbinLo] /=
_binv[idx] ;
1607 }
else if (i>=fbinM) {
1609 ibin = 2*fbinM-i-1 ;
1610 if (cdfBoundaries) {
1611 xarr[i-fbinLo] = binning.highBound()+1
e-10*(i-fbinM+1) ;
1612 yarr[i-fbinLo] = 1.0 ;
1614 auto idx = offsetIdx + idxMult * ibin;
1615 xarr[i-fbinLo] = 2*binning.highBound()-binning.binCenter(ibin) ;
1616 yarr[i - fbinLo] =
_wgt[idx];
1617 if (correctForBinSize)
1618 yarr[i - fbinLo] /=
_binv[idx];
1623 if (cdfBoundaries) {
1624 xarr[i-fbinLo] = binning.lowBound()-ibin*(1
e-10) ;
1625 yarr[i-fbinLo] = 0.0 ;
1627 auto idx = offsetIdx + idxMult * ibin;
1628 xarr[i-fbinLo] = 2*binning.lowBound()-binning.binCenter(ibin) ;
1629 yarr[i - fbinLo] =
_wgt[idx];
1630 if (correctForBinSize)
1631 yarr[i - fbinLo] /=
_binv[idx];
1652 if ((sumw2 > 0. || wgt != 1.) && !
_sumw2) {
1663 if (
_sumw2)
_sumw2[idx] += (sumw2 > 0 ? sumw2 : wgt*wgt);
1701 if (wgtErr > 0. && !
_sumw2) {
1708 _wgt[binNumber] = wgt ;
1722 if (
_curIndex == std::numeric_limits<std::size_t>::max()) {
1749 add(dset,&cutVar,wgt) ;
1763 std::unique_ptr<RooArgSet> tmp;
1768 coutE(DataHandling) <<
"RooDataHist::add(" <<
GetName() <<
") Couldn't deep-clone cut variable, abort," << endl ;
1780 if (!cloneVar || cloneVar->
getVal()) {
1809 const double theBinVolume = correctForBinSize ? (inverseBinCor ? 1/
_binv[i] :
_binv[i]) : 1.0 ;
1810 kahanSum +=
_wgt[i] * theBinVolume;
1817 return kahanSum.
Sum();
1841 sliceOnlySet.
remove(sumSet,
true,
true) ;
1844 std::vector<double>
const * pbinv =
nullptr;
1846 if(correctForBinSize && inverseBinCor) {
1848 }
else if(correctForBinSize && !inverseBinCor) {
1856 for (
unsigned int i = 0; i <
_vars.
size(); ++i) {
1860 if (sumSet.
find(*arg)) {
1864 refBin[i] = argLv->
getBin();
1872 std::size_t tmpibin = ibin;
1876 for (
unsigned int ivar = 0; !skip && ivar <
_vars.
size(); ++ivar) {
1879 if (
mask[ivar] && idx!=refBin[ivar])
1884 const double theBinVolume = correctForBinSize ? (inverseBinCor ? 1/(*pbinv)[ibin] : (*pbinv)[ibin] ) : 1.0 ;
1911 bool correctForBinSize,
bool inverseBinCor,
1912 const std::map<
const RooAbsArg*, std::pair<double, double> >& ranges,
1913 std::function<
double(
int)> getBinScale)
1921 sliceOnlySet.
remove(sumSet,
true,
true);
1929 std::vector<double> rangeLo(
_vars.
size(), -std::numeric_limits<double>::infinity());
1930 std::vector<double> rangeHi(
_vars.
size(), +std::numeric_limits<double>::infinity());
1932 for (std::size_t i = 0; i <
_vars.
size(); ++i) {
1941 refBin[i] = argLV->
getBin();
1944 auto it = ranges.find(sumsetv ? sumsetv : slicesetv);
1945 if (ranges.end() != it) {
1946 rangeLo[i] = it->second.first;
1947 rangeHi[i] = it->second.second;
1956 for (
int ivar = 0, tmp = ibin; !skip && ivar <
int(
_vars.
size()); ++ivar) {
1959 if (
mask[ivar] && idx!=refBin[ivar]) skip =
true;
1968 double binVolumeSumSetFull = 1.;
1969 double binVolumeSumSetInRange = 1.;
1975 const auto arg =
_vars[ivar];
1976 if (!sumSet.
find(*arg)) {
1981 const double binLo =
_binbounds[ivar][2 * idx];
1982 const double binHi =
_binbounds[ivar][2 * idx + 1];
1983 if (binHi < rangeLo[ivar] || binLo > rangeHi[ivar]) {
1985 binVolumeSumSetInRange = 0.;
1989 binVolumeSumSetFull *= binHi - binLo;
1990 binVolumeSumSetInRange *= std::min(rangeHi[ivar], binHi) - std::max(rangeLo[ivar], binLo);
1992 const double corrPartial = binVolumeSumSetInRange / binVolumeSumSetFull;
1993 if (0. == corrPartial)
continue;
1994 const double corr = correctForBinSize ? (inverseBinCor ? binVolumeSumSetFull /
_binv[ibin] : binVolumeSumSetFull ) : 1.0;
1995 total += getBinScale(ibin)*(
_wgt[ibin] * corr * corrPartial);
2016 for (
auto const&
v :
_vars) {
2017 code += ((dimSet.
find(*
v) ? 1 : 0) << i) ;
2023 if(!pbinv.empty()) {
2030 for (std::size_t i = 0; i < selDim.size(); ++i) {
2031 selDim[i] = (code >> i) & 1 ;
2036 Int_t idx(0), tmp(ibin) ;
2037 double theBinVolume(1) ;
2038 for (
unsigned int j=0; j <
_lvvars.size(); ++j) {
2048 pbinv[ibin] = theBinVolume ;
2072 if (cutSpec==0 && cutRange==0) {
2077 std::unique_ptr<RooFormula> select;
2079 select = std::make_unique<RooFormula>(
"select",cutSpec,*
get());
2086 if ((select && select->eval() == 0.) || (cutRange && !
_vars.
allInRange(cutRange)))
2092 return kahanSum.
Sum();
2163 coutE(InputArguments) <<
"RooDataHist::sliceIterator() variable " << sliceArg.
GetName() <<
" is not part of this RooDataHist" << endl ;
2210 for (
const auto arg :
_vars) {
2216 os << arg->GetName() ;
2229 const double wgt =
_wgt[i];
2231 if (std::abs(std::modf(wgt, &intpart)) > 1.E-10)
2250 os <<
indent <<
" Observables " <<
_vars << endl ;
2252 os <<
indent <<
" Observables: " ;
2297 TTree* X_tree(0) ; R__b >> X_tree;
2304 _dstore = std::make_unique<RooTreeDataStore>(X_tree,
_vars);
2375 for (
const auto real :
_vars) {
2377 if(info.nRealVars == 0) info.realVarIdx1 = iVar;
2378 if(info.nRealVars == 1) info.realVarIdx2 = iVar;
2387 for (
unsigned int i=0; i <
_vars.
size(); ++i) {
2396 info.initialized =
true;
static const double x3[11]
static void indent(ostringstream &buf, int indent_level)
static unsigned int total
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
static KahanSum< T, N > Accumulate(Iterator begin, Iterator end, T initialValue=T{})
Iterate over a range and return an instance of a KahanSum.
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
void attachDataSet(const RooAbsData &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
int binNumber(double x) const
Returns the bin number corresponding to the value x.
virtual void binNumbers(double const *x, int *bins, std::size_t n, int coef=1) const =0
Compute the bin indices for multiple values of x.
virtual double binCenter(Int_t bin) const =0
Int_t numBins() const
Return number of bins.
virtual bool isUniform() const
virtual double highBound() const =0
virtual double lowBound() const =0
virtual RooAbsBinning * clone(const char *name=nullptr) const =0
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
Int_t numBins(const char *rangeName=nullptr) const override
Return the number of fit bins ( = number of types )
void setBin(Int_t ibin, const char *rangeName=nullptr) override
Set category to i-th fit bin, which is the i-th registered state.
Int_t getBin(const char *=nullptr) const override
Get the index of the plot bin for the current value of this category.
bool hasLabel(const std::string &label) const
Check if a state with name label exists.
virtual const char * getCurrentLabel() const
Return label string of current state.
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
RooAbsCollection & assignValueOnly(const RooAbsCollection &other, bool forceIfSizeOne=false)
Sets the value of any argument in our set that also appears in the other set.
bool allInRange(const char *rangeSpec) const
Return true if all contained object report to have their value inside the specified range.
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
Storage_t::size_type size() const
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsData is the common abstract base class for binned and unbinned datasets.
virtual double weight() const =0
virtual const RooArgSet * get() const
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Interface for detailed printing of object.
void SetName(const char *name) override
Set the name of the TNamed.
void setGlobalObservables(RooArgSet const &globalObservables)
Sets the global observables stored in this data.
static StorageType defaultStorageType
std::unique_ptr< RooAbsDataStore > _dstore
Data storage implementation.
RooArgSet _vars
Dimensions of this data set.
RooArgSet _cachedVars
! External variables cached with this data set
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
virtual double weightSquared() const =0
void Streamer(TBuffer &) override
Stream an object of class RooAbsData.
Abstract base class for objects that are lvalues, i.e.
virtual Int_t getBin(const char *rangeName=nullptr) const =0
virtual double getBinWidth(Int_t i, const char *rangeName=nullptr) const =0
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual Int_t getBins(const char *name=nullptr) const
Get number of bins of currently defined range.
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
void setBin(Int_t ibin, const char *rangeName=nullptr) override
Set value to center of bin 'ibin' of binning 'rangeName' (or of default binning if no range is specif...
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
void Streamer(TBuffer &) override
Stream an object of class TObject.
Class RooBinning is an implements RooAbsBinning in terms of an array of boundary values,...
RooCategory is an object to represent discrete states.
bool defineType(const std::string &label)
Define a state with given name.
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
bool defineObject(const char *name, const char *argName, Int_t setNum, const TObject *obj=nullptr, bool isArray=false)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
double getDouble(const char *name, double defaultValue=0.0)
Return double property registered with name 'name'.
RooArgSet * getSet(const char *name, RooArgSet *set=nullptr)
Return RooArgSet property registered with name 'name'.
void defineMutex(const char *head, Args_t &&... tail)
Define arguments where any pair is mutually exclusive.
bool process(const RooCmdArg &arg)
Process given RooCmdArg.
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name 'name'.
const RooLinkedList & getObjectList(const char *name)
Return list of objects registered with name 'name'.
void defineDependency(const char *refArgName, const char *neededArgName)
Define that processing argument name refArgName requires processing of argument named neededArgName t...
bool defineInt(const char *name, const char *argName, Int_t intNum, Int_t defValue=0)
Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName...
bool defineString(const char *name, const char *argName, Int_t stringNum, const char *defValue="", bool appendMode=false)
Define double property name 'name' mapped to double in slot 'stringNum' in RooCmdArg with name argNam...
bool ok(bool verbose) const
Return true of parsing was successful.
TObject * getObject(const char *name, TObject *obj=nullptr)
Return TObject property registered with name 'name'.
const char * getString(const char *name, const char *defaultValue="", bool convEmptyToNull=false)
Return string property registered with name 'name'.
bool defineSet(const char *name, const char *argName, Int_t setNum, const RooArgSet *set=nullptr)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
bool defineDouble(const char *name, const char *argName, Int_t doubleNum, double defValue=0.0)
Define double property name 'name' mapped to double in slot 'doubleNum' in RooCmdArg with name argNam...
The RooDataHist is a container class to hold N-dimensional binned data.
double sum(bool correctForBinSize, bool inverseCorr=false) const
Return the sum of the weights of all bins in the histogram.
virtual void add(const RooArgSet &row, double wgt=1.0)
Add wgt to the bin content enclosed by the coordinates passed in row.
RooAbsData * reduceEng(const RooArgSet &varSubset, const RooFormulaVar *cutVar, const char *cutRange=nullptr, std::size_t nStart=0, std::size_t nStop=std::numeric_limits< std::size_t >::max()) override
Implementation of RooAbsData virtual method that drives the RooAbsData::reduce() methods.
static std::unique_ptr< RooAbsDataStore > makeDefaultDataStore(const char *name, const char *title, RooArgSet const &vars)
Int_t _cache_sum_valid
! Is cache sum valid? Needs to be Int_t instead of CacheSumState_t for subclasses.
double interpolateDim(int iDim, double xval, size_t centralIdx, int intOrder, bool correctForBinSize, bool cdfBoundaries)
Perform boundary safe 'intOrder'-th interpolation of weights in dimension 'dim' at current value 'xva...
double weightSquared() const override
Return squared weight of last bin that was requested with get().
friend class RooDataHistSliceIter
void importTH1(const RooArgList &vars, const TH1 &histo, double initWgt, bool doDensityCorrection)
Import data from given TH1/2/3 into this RooDataHist.
void printDataHistogram(std::ostream &os, RooRealVar *obs) const
TClass * IsA() const override
void SetNameTitle(const char *name, const char *title) override
Change the title of this RooDataHist.
double _cache_sum
! Cache for sum of entries ;
void initialize(const char *binningName=nullptr, bool fillTree=true)
Initialization procedure: allocate weights array, calculate multipliers needed for N-space to 1-dim a...
Int_t getIndex(const RooAbsCollection &coord, bool fast=false) const
Calculate bin number of the given coordinates.
const std::vector< double > & calculatePartialBinVolume(const RooArgSet &dimSet) const
Fill the transient cache with partial bin volumes with up-to-date values for the partial volume speci...
void weights(double *output, RooSpan< double const > xVals, int intOrder, bool correctForBinSize, bool cdfBoundaries)
A vectorized version of RooDataHist::weight() for one dimensional histograms with up to one dimension...
double weightInterpolated(const RooArgSet &bin, int intOrder, bool correctForBinSize, bool cdfBoundaries)
Return the weight at given coordinates with interpolation.
RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len, bool sumW2=false) const override
Return event weights of all events in range [first, first+len).
std::unordered_map< int, std::vector< double > > _pbinvCache
! Cache for arrays of partial bin volumes
void checkBinBounds() const
void initializeAsymErrArrays() const
double weight(std::size_t i) const
Return weight of i-th bin.
void set(std::size_t binNumber, double weight, double wgtErr)
Set bin content of bin that was last loaded with get(std::size_t).
void weightError(double &lo, double &hi, ErrorType etype=Poisson) const override
Return the asymmetric errors on the current weight.
double * _errHi
[_arrSize] High-side error on weight array
void importTH1Set(const RooArgList &vars, RooCategory &indexCat, std::map< std::string, TH1 * > hmap, double initWgt, bool doDensityCorrection)
Import data from given set of TH1/2/3 into this RooDataHist.
void adjustBinning(const RooArgList &vars, const TH1 &href, Int_t *offset=nullptr)
Adjust binning specification on first and optionally second and third observable to binning in given ...
double * _binv
[_arrSize] Bin volume array
RooDataHist()
Default constructor.
ULong64_t _curIndex
Current index.
double weightFast(const RooArgSet &bin, int intOrder, bool correctForBinSize, bool cdfBoundaries)
A faster version of RooDataHist::weight that assumes the passed arguments are aligned with the histog...
RooPlot * plotOn(RooPlot *frame, PlotOpt o) const override
Back end function to plotting functionality.
double weight() const override
Return weight of last bin that was requested with get().
std::vector< std::vector< double > > _binbounds
! list of bin bounds per dimension
void printArgs(std::ostream &os) const override
Print argument of dataset, i.e. the observable names.
void importDHistSet(const RooArgList &vars, RooCategory &indexCat, std::map< std::string, RooDataHist * > dmap, double initWgt)
Import data from given set of TH1/2/3 into this RooDataHist.
void _adjustBinning(RooRealVar &theirVar, const TAxis &axis, RooRealVar *ourVar, Int_t *offset)
Helper doing the actual work of adjustBinning().
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Print the details on the dataset contents.
double * _sumw2
[_arrSize] Sum of weights^2
TIterator * sliceIterator(RooAbsArg &sliceArg, const RooArgSet &otherArgs)
Create an iterator over all bins in a slice defined by the subset of observables listed in sliceArg.
void interpolateQuadratic(double *output, RooSpan< const double > xVals, bool correctForBinSize, bool cdfBoundaries)
A vectorized version of interpolateDim for boundary safe quadratic interpolation of one dimensional h...
Int_t calcTreeIndex() const
Legacy overload to calculate the tree index from the current value of _vars.
~RooDataHist() override
Destructor.
bool isNonPoissonWeighted() const override
Returns true if dataset contains entries with a non-integer weight.
std::vector< RooAbsLValue * > _lvvars
! List of observables casted as RooAbsLValue
void SetName(const char *name) override
Change the name of the RooDataHist.
std::vector< std::unique_ptr< const RooAbsBinning > > _lvbins
! List of used binnings associated with lvalues
void Streamer(TBuffer &) override
Stream an object of class RooDataHist.
std::vector< double > _interpolationBuffer
! Buffer to contain values used for weight interpolation
std::vector< Int_t > _idxMult
void registerWeightArraysToDataStore() const
Hand over pointers to our weight arrays to the data store implementation.
void reset() override
Reset all bin weights to zero.
double * _errLo
[_arrSize] Low-side error on weight array
double * _wgt
[_arrSize] Weight array
void printValue(std::ostream &os) const override
Print value of the dataset, i.e. the sum of weights contained in the dataset.
VarInfo const & getVarInfo()
Return reference to VarInfo struct with cached histogram variable information that is frequently used...
const RooArgSet * get() const override
Get bin centre of current bin.
double binVolume() const
Return volume of current bin.
void interpolateLinear(double *output, RooSpan< const double > xVals, bool correctForBinSize, bool cdfBoundaries)
A vectorized version of interpolateDim for boundary safe linear interpolation of one dimensional hist...
double sumEntries() const override
Sum the weights of all bins.
RooDirItem is a utility base class for RooFit objects that are to be attached to ROOT directories.
virtual void Streamer(TBuffer &)
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
TDirectory * _dir
! Associated directory
void appendToDir(TObject *obj, bool forceMemoryResident=false)
Append object to directory.
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called.
bool getPoissonInterval(Int_t n, double &mu1, double &mu2, double nSigma=1) const
Return a confidence interval for the expected number of events given n observed (unweighted) events.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
RooLinkedListIterImpl begin() const
static double interpolate(double yArr[], Int_t nOrder, double x)
A RooPlot is a plot frame and a container for graphics objects within that frame.
RooAbsRealLValue * getPlotVar() const
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
RooRealVar represents a variable that can be changed from the outside.
const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false) const override
Return binning definition with name.
void setBinning(const RooAbsBinning &binning, const char *name=nullptr)
Add given binning under name 'name' with this variable.
void setRange(const char *name, double min, double max)
Set a fit or plotting range.
A simple container to hold a batch of data values.
constexpr std::size_t size() const noexcept
constexpr std::span< T >::pointer data() const
The RooStringView is a wrapper around a C-syle string that can also be constructed from a std::string...
const Double_t * GetArray() const
Class to manage histogram axis.
const TArrayD * GetXbins() const
Buffer base class used for serializing objects.
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
virtual TList * GetList() const
TH1 is the base class of all histogram classes in ROOT.
virtual Int_t GetNbinsY() const
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
virtual Int_t GetNbinsZ() const
virtual Int_t GetDimension() const
virtual Int_t GetNbinsX() const
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Iterator abstract base class.
void Add(TObject *obj) override
TObject * Remove(TObject *obj) override
Remove object from the list.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
Mother of all ROOT objects.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void Streamer(TBuffer &)
Stream a string object.
A TTree represents a columnar dataset.
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Structure to cache information on the histogram variable that is frequently used for histogram weight...