60 _pdfObsList(
"pdfObs",
"List of p.d.f. observables",this),
70 coutE(InputArguments) <<
"RooHistPdf::ctor(" <<
GetName()
71 <<
") ERROR variable list and RooDataHist must contain the same variables." << std::endl ;
74 for (
const auto arg : vars) {
75 if (!dvars->
find(arg->GetName())) {
76 coutE(InputArguments) <<
"RooHistPdf::ctor(" <<
GetName()
77 <<
") ERROR variable list and RooDataHist must contain the same variables." << std::endl ;
109 _pdfObsList(
"pdfObs",
"List of p.d.f. observables",this),
118 if (histObs.
size()!=dvars->
size()) {
119 coutE(InputArguments) <<
"RooHistPdf::ctor(" <<
GetName()
120 <<
") ERROR histogram variable list and RooDataHist must contain the same variables." << std::endl ;
121 throw(std::string(
"RooHistPdf::ctor() ERROR: histogram variable list and RooDataHist must contain the same variables")) ;
124 for (
const auto arg : histObs) {
125 if (!dvars->
find(arg->GetName())) {
126 coutE(InputArguments) <<
"RooHistPdf::ctor(" <<
GetName()
127 <<
") ERROR variable list and RooDataHist must contain the same variables." << std::endl ;
128 throw(std::string(
"RooHistPdf::ctor() ERROR: histogram variable list and RooDataHist must contain the same variables")) ;
130 if (!arg->isFundamental()) {
131 coutE(InputArguments) <<
"RooHistPdf::ctor(" <<
GetName()
132 <<
") ERROR all elements of histogram observables set must be of type RooRealVar or RooCategory." << std::endl ;
133 throw(std::string(
"RooHistPdf::ctor() ERROR all elements of histogram observables set must be of type RooRealVar or RooCategory.")) ;
158 std::unique_ptr<RooDataHist> dhist,
int intOrder)
170 _pdfObsList(
"pdfObs",this,other._pdfObsList),
171 _dataHist(other._dataHist),
172 _intOrder(other._intOrder),
173 _cdfBoundaries(other._cdfBoundaries),
174 _totVolume(other._totVolume),
175 _unitNorm(other._unitNorm)
184 std::size_t nNegative = 0;
185 double sumNegative = 0.;
186 for (std::size_t i = 0; i < nBins; ++i) {
192 if (nNegative == 0) {
197 <<
"\" contains " << nNegative
198 <<
" bins with negative content (sum of negative contents: " << sumNegative
199 <<
"). A p.d.f. cannot be negative, so these bins contents are clipped to zero while "
200 "preserving the error. The input "
201 "histogram is not modified. To avoid this message, remove the negative bin contents "
202 "before constructing the RooHistPdf."
213 for (std::size_t i = 0; i < nBins; ++i) {
233 std::span<double> output = ctx.
output();
243 for (
auto &ret : output) {
244 ret = std::max(ret, 0.0);
272 return std::max(ret, 0.0);
307 if (!_x || !_y)
return false;
308 if (!range || !strlen(range) || !_x->
hasRange(range) ||
322 if(lobs ==
nullptr)
return false;
324 bool isOkayForAnalyticalInt =
false;
328 if(!lobs->isJacobianOK(*var))
return false;
329 isOkayForAnalyticalInt =
true;
333 return isOkayForAnalyticalInt;
341 const char* rangeName,
351 bool directSubRange =
false;
352 for (
unsigned int n=0;
n < pdfObsList.
size() &&
n < histObsList.
size(); ++
n) {
353 const auto pa = pdfObsList[
n];
354 const auto ha = histObsList[
n];
356 if (okayForAnalytical(*pa, allVars)) {
359 if (fullRange(*pa, *ha, rangeName)) {
361 }
else if (pa->isFundamental()) {
363 directSubRange =
true;
368 if (code == frcode) {
379 if (intOrder > 0 && directSubRange) {
383 return (code >= 2) ? code : 0;
388 const char* rangeName,
394 if (((2 << histObsList.
size()) - 1) == code) {
401 std::map<const RooAbsArg*, std::pair<double, double> > ranges;
402 for (
unsigned int n=0;
n < pdfObsList.
size() &&
n < histObsList.
size(); ++
n) {
403 const auto pa = pdfObsList[
n];
404 const auto ha = histObsList[
n];
406 if (code & (2 <<
n)) {
416 ha->copyCache(pa,
true);
420 double ret = (code & 1) ?
dataHist.
sum(intSet,histObsList,
true,!histFuncMode) :
421 dataHist.
sum(intSet,histObsList,
true,!histFuncMode, ranges);
452 bool isOkayForAnalyticalInt =
false;
459 if(!(lvalue && lvalue->isJacobianOK(dep)))
return false;
460 isOkayForAnalyticalInt =
true;
464 return isOkayForAnalyticalInt;
486 double xlo,
double xhi)
488 std::vector<double>
result;
494 bool useTransform =
false;
495 for (
unsigned int i = 0; i < pdfObsList.
size(); ++i) {
497 histObs = histObsList[i];
502 for (
unsigned int i = 0; i < pdfObsList.
size(); ++i) {
503 auto *po =
dynamic_cast<RooAbsReal *
>(pdfObsList[i]);
504 if (po && po->dependsOn(obs)) {
505 histObs = histObsList[i];
506 pdfObs = pdfObsList[i];
523 const double *rawBoundaries = binning->
array();
526 result.assign(rawBoundaries, rawBoundaries + nBoundaries);
534 auto *pdfObsReal =
static_cast<RooAbsReal *
>(pdfObs);
535 const double probeLo = std::max(xlo, obs.
getMin());
536 const double probeHi = std::min(xhi, obs.
getMax());
537 if (probeHi > probeLo) {
543 obsLeaves.
snapshot(obsSaved,
false);
544 auto evalAt = [&](
double val) {
546 return pdfObsReal->getVal();
548 const double probeMid = 0.5 * (probeLo + probeHi);
549 const double plo = evalAt(probeLo);
550 const double phi = evalAt(probeHi);
551 const double pmid = evalAt(probeMid);
552 obsLeaves.
assign(obsSaved);
553 const double slope = (phi - plo) / (probeHi - probeLo);
556 const double pmidLinear = plo + slope * (probeMid - probeLo);
557 const double scale = std::max(std::abs(plo), std::abs(phi));
558 if (std::abs(pmid - pmidLinear) > 1
e-7 * (scale > 0.0 ? scale : 1.0)) {
560 <<
"RooHistPdf::histogramBoundariesInPlotObs: the histogram observable '" << pdfObsReal->GetName()
561 <<
"' appears to be a non-linear transformation of the plot observable '" << obs.
GetName()
562 <<
"'. The bin boundaries used for plotting and integration are approximated assuming a linear "
563 "relation and may be placed incorrectly."
568 result.reserve(nBoundaries);
569 for (
int i = 0; i < nBoundaries; ++i) {
570 result.push_back(probeLo + (rawBoundaries[i] - plo) / slope);
605 if (boundaries.empty()) {
625 const std::vector<double> boundaries =
627 if (boundaries.empty()) {
631 auto hint =
new std::list<double>;
632 for (
double b : boundaries) {
633 if (
b >= xlo &&
b <= xhi) {
666 if (wgt>max) max=wgt ;
682 if (std::abs(dh1.
weight(i)-dh2.
weight(i))>1
e-8)
return false ;
718 coutE(ObjectHandling) <<
" RooHistPdf::importWorkspaceHook(" <<
GetName() <<
") unable to import clone of underlying RooDataHist with unique name " << uniqueName <<
", abort" << std::endl ;
730 coutE(ObjectHandling) <<
" RooHistPdf::importWorkspaceHook(" <<
GetName() <<
") unable to import clone of underlying RooDataHist with unique name " << uniqueName <<
", abort" << std::endl ;
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
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 result
Common abstract base class for objects that represent a value and a "shape" in RooFit.
virtual void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValDirty=true)=0
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
virtual void syncCache(const RooArgSet *nset=nullptr)=0
friend void RooRefArray::Streamer(TBuffer &)
virtual bool inRange(const char *) const
void leafNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool recurseNonDerived=false) const
Fill supplied list with all leaf nodes of the arg tree, starting with ourself as top node.
Abstract base class for RooRealVar binning definitions.
virtual bool isParameterized() const
Interface function.
virtual Int_t numBoundaries() const =0
virtual double * array() const =0
Int_t numTypes(const char *=nullptr) const
Return number of types defined (in range named rangeName if rangeName!=nullptr)
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
const char * GetName() const override
Returns name of object.
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.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for binned and unbinned datasets.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract base class for objects that are lvalues, i.e.
Abstract interface for all probability density functions.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual void setVal(double value)=0
Set the current value of the object. Needs to be overridden by implementations.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
const RooAbsBinning * getBinningPtr(const char *rangeName) const override
bool hasRange(const char *name) const override
Check if variable has a binning with given name.
Abstract base class for objects that represent a real value and implements functionality common to al...
virtual void doEval(RooFit::EvalContext &) const
Base function for computing multiple values of a RooAbsReal.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
RooArgSet * selectCommon(const RooAbsCollection &refColl) const
Use RooAbsCollection::selecCommon(), but return as RooArgSet.
Object to represent discrete states.
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
static std::list< double > * plotSamplingHintForBinBoundaries(std::span< const double > boundaries, double xlo, double xhi)
Returns sampling hints for a histogram with given boundaries.
Container class to hold N-dimensional binned data.
void weights(double *output, std::span< double const > xVals, int intOrder, bool correctForBinSize, bool cdfBoundaries)
A vectorized version of RooDataHist::weight() for one dimensional histograms with up to one dimension...
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
double const * sumW2Array() 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).
double weightSquared(std::size_t i) const
Return squared weight sum of i-th bin.
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...
double sum(bool correctForBinSize, bool inverseBinCor=false) const
Return the sum of the weights of all bins in the histogram.
const RooArgSet * get() const override
Get bin centre of current bin.
double sumEntries() const override
Sum the weights of all bins.
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
A probability density function sampled from a multidimensional histogram.
RooArgSet _histObsList
List of observables defining dimensions of histogram.
Int_t _intOrder
Interpolation order.
bool forceAnalyticalInt(const RooAbsArg &dep) const override
bool areIdentical(const RooDataHist &dh1, const RooDataHist &dh2)
RooDataHist * _dataHist
Unowned pointer to underlying histogram.
bool _cdfBoundaries
Use boundary conditions for CDFs.
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Return the histogram bin boundaries in the plot-observable coordinate, used for example by the RooBin...
static std::vector< double > histogramBoundariesInPlotObs(RooDataHist const &dataHist, RooArgSet const &pdfObsList, RooArgSet const &histObsList, RooAbsRealLValue &obs, double xlo, double xhi)
Return the histogram bin boundaries mapped to the coordinates of the plot observable obs.
double totVolume() const
Return the total volume spanned by the observables of the RooHistPdf.
void initializeOwnedDataHist(std::unique_ptr< RooDataHist > &&dataHist)
bool importWorkspaceHook(RooWorkspace &ws) override
Check if our datahist is already in the workspace.
RooSetProxy _pdfObsList
List of observables mapped onto histogram observables.
double maxVal(Int_t code) const override
Return maximum value for set of observables identified by code assigned in getMaxVal.
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Return integral identified by 'code'.
std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const override
Return sampling hint for making curves of (projections) of this function as the recursive division st...
Int_t getMaxVal(const RooArgSet &vars) const override
Only handle case of maximum in all variables.
double _totVolume
! Total volume of space (product of ranges of observables)
std::unique_ptr< RooDataHist > _ownedDataHist
! Owned pointer to underlying histogram
void doEval(RooFit::EvalContext &) const override
Base function for computing multiple values of a RooAbsReal.
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Determine integration scenario.
double evaluate() const override
Return the current value: The value of the bin enclosing the current coordinates of the observables,...
bool _unitNorm
Assume contents is unit normalized (for use as pdf cache)
Variable that can be changed from the outside.
void setRange(const char *name, double min, double max, bool shared=true)
Set a fit or plotting range.
Persistable container for RooFit projects.
RooAbsData * embeddedData(RooStringView name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
std::list< RooAbsData * > allData() const
Return list of all dataset in the workspace.
bool import(const RooAbsArg &arg, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={})
Import a RooAbsArg object, e.g.
Buffer base class used for serializing objects.
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
const char * GetName() const override
Returns name of object.
RooCmdArg Rename(const char *suffix)
RooCmdArg Embedded(bool flag=true)
std::pair< double, double > getRangeOrBinningInterval(RooAbsArg const *arg, const char *rangeName)