45#ifdef ROOFIT_CHECK_CACHED_VALUES
55 template<
class ...Args>
98 "RooNLLVar::RooNLLVar",
"ProjectedObservables",0,&_emptySet,
99 arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)),
100 makeRooAbsTestStatisticCfg(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9))
103 pc.allowUndefined() ;
104 pc.defineInt(
"extended",
"Extended",0,
false) ;
105 pc.defineInt(
"BatchMode",
"BatchMode", 0,
false);
107 pc.process(arg1) ;
pc.process(arg2) ;
pc.process(arg3) ;
108 pc.process(arg4) ;
pc.process(arg5) ;
pc.process(arg6) ;
109 pc.process(arg7) ;
pc.process(arg8) ;
pc.process(arg9) ;
152 auto biter = boundaries->begin() ;
153 _binw.reserve(boundaries->size()-1) ;
154 double lastBound = (*biter) ;
156 while (biter!=boundaries->end()) {
157 _binw.push_back((*biter) - lastBound);
158 lastBound = (*biter) ;
172 _extended(other._extended),
173 _batchEvaluations(other._batchEvaluations),
174 _weightSq(other._weightSq),
175 _offsetSaveW2(other._offsetSaveW2),
177 _binnedPdf{other._binnedPdf}
191 auto testStat =
new RooNLLVar(
name, title, thePdf, adata, projDeps, extendedPdf, cfg);
208 for (
int i=0 ; i<
_nCPU ; i++)
211 for (
int i=0 ; i<
_nGof ; i++)
234 double sumWeight{0.0};
247 for (
auto i=firstEvent ; i<lastEvent ; i+=stepSize) {
257 double N = eventWeight ;
264 logEvalError(
Form(
"Observed %f events in bin %lu with zero event yield",
N,(
unsigned long)i)) ;
274 sumWeightKahanSum += eventWeight;
279 sumWeight = sumWeightKahanSum.Sum();
285#ifdef ROOFIT_CHECK_CACHED_VALUES
288 std::tie(resultScalar, sumWeightScalar) =
computeScalar(stepSize, firstEvent, lastEvent);
289 double carryScalar = resultScalar.
Carry();
291 constexpr bool alwaysPrint =
false;
293 if (alwaysPrint ||
std::abs(
result - resultScalar)/resultScalar > 5.E-15) {
294 std::cerr <<
"RooNLLVar: result is off\n\t" << std::setprecision(15) <<
result
295 <<
"\n\t" << resultScalar << std::endl;
298 if (alwaysPrint ||
std::abs(carry - carryScalar)/carryScalar > 500.) {
299 std::cerr <<
"RooNLLVar: carry is far off\n\t" << std::setprecision(15) << carry
300 <<
"\n\t" << carryScalar << std::endl;
303 if (alwaysPrint ||
std::abs(sumWeight - sumWeightScalar)/sumWeightScalar > 1.E-15) {
304 std::cerr <<
"RooNLLVar: sumWeight is off\n\t" << std::setprecision(15) << sumWeight
305 <<
"\n\t" << sumWeightScalar << std::endl;
339 coutI(
Minimization) <<
"RooNLLVar::evaluatePartition(" <<
GetName() <<
") first = "<< firstEvent <<
" last = " << lastEvent <<
" Likelihood offset now set to " <<
result << std::endl ;
367 std::unique_ptr<RooBatchCompute::RunContext> &evalData,
368 RooArgSet *normSet,
bool weightSq, std::size_t stepSize,
369 std::size_t firstEvent, std::size_t lastEvent)
371 const auto nEvents = lastEvent - firstEvent;
374 throw std::invalid_argument(std::string(
"Error in ") + __FILE__ +
": Step size for batch computations can only be 1.");
384 dataClone->
getBatches(*evalData, firstEvent, nEvents);
388#ifdef ROOFIT_CHECK_CACHED_VALUES
390 for (std::size_t evtNo = firstEvent; evtNo < std::min(lastEvent, firstEvent + 10); ++evtNo) {
391 dataClone->
get(evtNo);
392 if (dataClone->
weight() == 0.)
395 assert(dataClone->
valid());
399 }
catch (std::exception&
e) {
400 std::cerr << __FILE__ <<
":" << __LINE__ <<
" ERROR when checking batch computation for event " << evtNo <<
":\n"
401 <<
e.what() << std::endl;
406 }
catch (std::exception& e2) {
420 double uniformSingleEventWeight{0.0};
422 if (eventWeights.
empty()) {
424 sumOfWeights = nEvents * uniformSingleEventWeight;
425 for (std::size_t i = 0; i < results.size(); ++i) {
426 kahanProb.
AddIndexed(-uniformSingleEventWeight * results[i], i);
429 assert(results.size() == eventWeights.
size());
431 for (std::size_t i = 0; i < results.size(); ++i) {
432 const double weight = eventWeights[i];
433 kahanProb.
AddIndexed(-weight * results[i], i);
436 sumOfWeights = kahanWeight.
Sum();
439 if (std::isnan(kahanProb.
Sum())) {
444 for (std::size_t i = 0; i < results.size(); ++i) {
445 double weight = eventWeights.
empty() ? uniformSingleEventWeight : eventWeights[i];
450 if (std::isnan(results[i])) {
453 kahanSanitised += -weight * results[i];
461 return {kahanSanitised, sumOfWeights};
465 return {kahanProb, sumOfWeights};
476 RooArgSet *normSet,
bool weightSq, std::size_t stepSize,
477 std::size_t firstEvent, std::size_t lastEvent)
483 for (
auto i=firstEvent; i<lastEvent; i+=stepSize) {
486 if (!dataClone->
valid())
continue;
488 double eventWeight = dataClone->
weight();
489 if (0. == eventWeight * eventWeight) continue ;
492 const double term = -eventWeight * pdfClone->
getLogVal(normSet);
494 kahanWeight.
Add(eventWeight);
504 return {kahanProb, kahanWeight.
Sum()};
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.
static void checkBatchComputation(const RooAbsReal &theReal, const RooBatchCompute::RunContext &evalData, std::size_t evtNo, const RooArgSet *normSet=nullptr, double relAccuracy=1.E-13)
void AddIndexed(T input, std::size_t index)
Add input to the sum.
void Add(T x)
Single-element accumulation. Will not vectorise.
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Given a set of possible observables, return the observables that this PDF depends on.
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Storage_t::size_type size() const
RooAbsArg * first() const
virtual void recalculateCache(const RooArgSet *, Int_t, Int_t, Int_t, Bool_t)
RooAbsData is the common abstract base class for binned and unbinned datasets.
virtual const RooArgSet * get() const
RooAbsDataStore * store()
virtual Bool_t valid() const
virtual Double_t weight() const =0
virtual Double_t weightSquared() const =0
virtual RooSpan< const double > getWeightBatch(std::size_t first, std::size_t len, bool sumW2=false) const =0
Return event weights of all events in range [first, first+len).
virtual void getBatches(RooBatchCompute::RunContext &evalData, std::size_t first=0, std::size_t len=std::numeric_limits< std::size_t >::max()) const
Write information to retrieve data columns into evalData.spans.
RooAbsOptTestStatistic is the abstract base class for test statistics objects that evaluate a functio...
RooAbsReal * _funcClone
Pointer to internal clone of input function.
RooArgSet * _normSet
Pointer to set with observables used for normalization.
RooAbsData * _dataClone
Pointer to internal clone if input data.
RooArgSet * _projDeps
Set of projected observable.
RooSpan< const double > getLogProbabilities(RooBatchCompute::RunContext &evalData, const RooArgSet *normSet=nullptr) const
Compute the log-likelihoods for all events in the requested batch.
Bool_t canBeExtended() const
If true, PDF can provide extended likelihood term.
virtual Double_t getLogVal(const RooArgSet *set=0) const
Return the log of the current value with given normalization An error message is printed if the argum...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
void logEvalError(const char *message, const char *serverValueString=0) const
Log evaluation error message.
RooAbsTestStatistic is the abstract base class for all test statistics.
Int_t _setNum
Partition number of this instance in parallel calculation mode.
Int_t _nGof
Number of sub-contexts.
Int_t _nCPU
Number of processors to use in parallel calculation mode.
Bool_t _doOffset
Apply interval value offset to control numeric precision?
pRooAbsTestStatistic * _gofArray
! Array of sub-contexts representing part of the combined test statistic
GOFOpMode _gofOpMode
Operation mode of test statistic instance.
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
Double_t _evalCarry
! carry of Kahan sum in evaluatePartition
pRooRealMPFE * _mpfeArray
! Array of parallel execution frond ends
RooArgSet is a container object that can hold multiple RooAbsArg objects.
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.
static double decodeDoubleOnTheFly(const char *callerID, const char *cmdArgName, int idx, double defVal, std::initializer_list< std::reference_wrapper< const RooCmdArg > > args)
Find a given double in a list of RooCmdArg.
static std::string decodeStringOnTheFly(const char *callerID, const char *cmdArgName, Int_t intIdx, const char *defVal, Args_t &&...args)
Static decoder function allows to retrieve string property from set of RooCmdArgs For use in base mem...
static Int_t decodeIntOnTheFly(const char *callerID, const char *cmdArgName, Int_t intIdx, Int_t defVal, Args_t &&...args)
Static decoder function allows to retrieve integer property from set of RooCmdArgs For use in base me...
Class RooNLLVar 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
RooRealSumPdf * _binnedPdf
!
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)
ROOT::Math::KahanSum< double > _offsetSaveW2
!
static RooNLLVar::ComputeResult computeBatchedFunc(const RooAbsPdf *pdfClone, RooAbsData *dataClone, std::unique_ptr< RooBatchCompute::RunContext > &evalData, RooArgSet *normSet, bool weightSq, std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent)
static RooArgSet _emptySet
void applyWeightSquared(bool flag) override
Disables or enables the usage of squared weights.
std::pair< ROOT::Math::KahanSum< double >, double > ComputeResult
std::vector< Double_t > _binw
!
Double_t evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const override
Calculate and return likelihood on subset of data.
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.
std::unique_ptr< RooBatchCompute::RunContext > _evalData
! Struct to store function evaluation workspaces.
Bool_t _weightSq
Apply weights squared?
ComputeResult computeBatched(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent) const
Compute probabilites of all data events.
The class RooRealSumPdf implements a PDF constructed from a sum of functions:
std::list< Double_t > * binBoundaries(RooAbsRealLValue &, Double_t, Double_t) const override
Retrieve bin boundaries if this distribution is binned in obs.
RooRealVar represents a variable that can be changed from the outside.
A simple container to hold a batch of data values.
constexpr std::span< T >::index_type size() const noexcept
constexpr bool empty() const noexcept
const char * GetName() const override
Returns name of object.
RVec< PromoteType< T > > abs(const RVec< T > &v)
RVec< PromoteType< T > > log(const RVec< T > &v)
void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
static constexpr double pc
Double_t LnGamma(Double_t z)
Computation of ln[gamma(z)] for all z.
std::string rangeName
Stores the configuration parameters for RooAbsTestStatistic.
std::string addCoefRangeName
double integrateOverBinsPrecision
RooFit::MPSplit interleave
This struct enables passing computation data around between elements of a computation graph.
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.