71 _binnedPdf(cfg.binnedL ? static_cast<
RooRealSumPdf *>(_funcClone) : nullptr)
89 auto biter = boundaries->begin() ;
90 _binw.reserve(boundaries->size()-1) ;
91 double lastBound = (*biter) ;
93 while (biter!=boundaries->end()) {
94 _binw.push_back((*biter) - lastBound);
95 lastBound = (*biter) ;
113 _extended(other._extended),
114 _weightSq(other._weightSq),
115 _offsetSaveW2(other._offsetSaveW2),
117 _binnedPdf{other._binnedPdf}
131 auto testStat =
new RooNLLVar(
name, title, thePdf, adata, projDeps, extendedPdf, cfg);
147 for (
int i=0 ; i<
_nCPU ; i++)
173 double sumWeight{0.0};
181 for (
auto i=firstEvent ; i<lastEvent ; i+=stepSize) {
189 double N = eventWeight ;
196 logEvalError(
Form(
"Observed %f events in bin %lu with zero event yield",
N,(
unsigned long)i)) ;
198 }
else if (std::abs(mu)<1
e-10 && std::abs(
N)<1
e-10) {
207 term -= -mu +
N +
N * (std::log(mu) - std::log(
N));
212 sumWeightKahanSum += eventWeight;
217 sumWeight = sumWeightKahanSum.Sum();
250 coutI(Minimization) <<
"RooNLLVar::evaluatePartition(" <<
GetName() <<
") first = "<< firstEvent <<
" last = " << lastEvent <<
" Likelihood offset now set to " <<
result.Sum() << std::endl ;
268 RooArgSet *normSet,
bool weightSq, std::size_t stepSize,
269 std::size_t firstEvent, std::size_t lastEvent,
RooAbsPdf const* offsetPdf)
275 for (
auto i=firstEvent; i<lastEvent; i+=stepSize) {
278 double weight = dataClone->
weight();
280 if (0. == weight * weight) continue ;
283 double logProba = pdfClone->
getLogVal(normSet);
286 logProba -= offsetPdf->
getLogVal(normSet);
289 const double term = -weight * logProba;
291 kahanWeight.
Add(weight);
301 return {kahanProb, kahanWeight.
Sum()};
323 bool needsResetting =
true;
331 needsResetting =
false;
335 for (
int i = 0; i <
_nCPU; ++i) {
338 needsResetting =
false;
347 std::string
name = std::string{
GetName()} +
"_offsetPdf";
348 std::unique_ptr<RooDataHist> dataTemplate;
350 dataTemplate = std::make_unique<RooDataHist>(*dh);
352 dataTemplate = std::unique_ptr<RooDataHist>(
static_cast<RooDataSet const &
>(*_dataClone).
binnedClone());
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
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...
void Add(T x)
Single-element accumulation. Will not vectorise.
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
Storage_t::size_type size() const
RooAbsArg * first() const
Abstract base class for binned and unbinned datasets.
virtual double weight() const =0
virtual const RooArgSet * get() const
virtual double weightSquared() const =0
Abstract base class for test statistics objects that evaluate a function or PDF at each point of a gi...
bool setDataSlave(RooAbsData &data, bool cloneData=true, bool ownNewDataAnyway=false) override
Change dataset that is used to given one.
RooAbsReal * _funcClone
Pointer to internal clone of input function.
bool _skipZeroWeights
! Whether to skip entries with weight zero in the evaluation
RooArgSet * _funcObsSet
List of observables in the pdf expression.
RooArgSet * _normSet
Pointer to set with observables used for normalization.
RooAbsData * _dataClone
Pointer to internal clone if input data.
Abstract interface for all probability density functions.
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
virtual double getLogVal(const RooArgSet *set=nullptr) const
Return the log of the current value with given normalization An error message is printed if the argum...
Abstract base class for objects that represent a real value and implements functionality common to al...
virtual std::list< double > * binBoundaries(RooAbsRealLValue &obs, double xlo, double xhi) const
Retrieve bin boundaries if this distribution is binned in obs.
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
void logEvalError(const char *message, const char *serverValueString=nullptr) const
Log evaluation error message.
Abstract base class for all test statistics.
Int_t _setNum
Partition number of this instance in parallel calculation mode.
double _evalCarry
! carry of Kahan sum in evaluatePartition
GOFOpMode operMode() const
Int_t _nCPU
Number of processors to use in parallel calculation mode.
GOFOpMode _gofOpMode
Operation mode of test statistic instance.
bool _init
! Is object initialized
Int_t _simCount
Total number of component p.d.f.s in RooSimultaneous (if any)
ROOT::Math::KahanSum< double > _offset
! Offset as KahanSum to avoid loss of precision
Int_t _extSet
! Number of designated set to calculated extended term
std::vector< std::unique_ptr< RooAbsTestStatistic > > _gofArray
! Array of sub-contexts representing part of the combined test statistic
bool initialize()
One-time initialization of the test statistic.
pRooRealMPFE * _mpfeArray
! Array of parallel execution frond ends
bool _doOffset
Apply interval value offset to control numeric precision?
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Container class to hold N-dimensional binned data.
Container class to hold unbinned data.
RooFit::OwningPtr< RooDataHist > binnedClone(const char *newName=nullptr, const char *newTitle=nullptr) const
Return binned clone of this dataset.
Implements a -log(likelihood) calculation from a dataset and a PDF.
ComputeResult computeScalar(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent) const
std::unique_ptr< RooAbsPdf > _offsetPdf
! An optional per-bin likelihood offset
static RooNLLVar::ComputeResult computeScalarFunc(const RooAbsPdf *pdfClone, RooAbsData *dataClone, RooArgSet *normSet, bool weightSq, std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent, RooAbsPdf const *offsetPdf=nullptr)
ROOT::Math::KahanSum< double > _offsetSaveW2
!
void applyWeightSquared(bool flag) override
Disables or enables the usage of squared weights.
std::vector< double > _binw
!
std::pair< ROOT::Math::KahanSum< double >, double > ComputeResult
bool setDataSlave(RooAbsData &data, bool cloneData=true, bool ownNewDataAnyway=false) override
Change dataset that is used to given one.
RooNLLVar(const char *name, const char *title, RooAbsPdf &pdf, RooAbsData &data, bool extended, RooAbsTestStatistic::Configuration const &cfg=RooAbsTestStatistic::Configuration{})
Construct likelihood from given p.d.f and (binned or unbinned dataset) For internal use.
RooAbsTestStatistic * create(const char *name, const char *title, RooAbsReal &pdf, RooAbsData &adata, const RooArgSet &projDeps, RooAbsTestStatistic::Configuration const &cfg) override
Create a test statistic using several properties of the current instance.
void enableBinOffsetting(bool on=true)
bool _weightSq
Apply weights squared?
double evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const override
Calculate and return likelihood on subset of data.
Implements a PDF constructed from a sum of functions:
Variable that can be changed from the outside.
const char * GetName() const override
Returns name of object.
Double_t LnGamma(Double_t z)
Computation of ln[gamma(z)] for all z.
Little struct that can pack a float into the unused bits of the mantissa of a NaN double.
float getPayload() const
Retrieve packed float.
double getNaNWithPayload() const
Retrieve a NaN with the current float payload packed into the mantissa.
void accumulate(double val)
Accumulate a packed float from another NaN into this.