77 *(const
RooArgSet*)
RooCmdConfig::decodeObjOnTheFly(
"RooNLLVar::RooNLLVar",
"ProjectedObservables",0,&_emptySet
78 ,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
79 RooCmdConfig::decodeStringOnTheFly(
"RooNLLVar::RooNLLVar",
"RangeWithName",0,
"",arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9).c_str(),
80 RooCmdConfig::decodeStringOnTheFly(
"RooNLLVar::RooNLLVar",
"AddCoefRange",0,
"",arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9).c_str(),
81 RooCmdConfig::decodeIntOnTheFly(
"RooNLLVar::RooNLLVar",
"NumCPU",0,1,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
83 RooCmdConfig::decodeIntOnTheFly(
"RooNLLVar::RooNLLVar",
"Verbose",0,1,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
84 RooCmdConfig::decodeIntOnTheFly(
"RooNLLVar::RooNLLVar",
"SplitRange",0,0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
85 RooCmdConfig::decodeIntOnTheFly(
"RooNLLVar::RooNLLVar",
"CloneData",0,1,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9))
89 pc.defineInt(
"extended",
"Extended",0,
kFALSE) ;
90 pc.defineInt(
"BatchMode",
"BatchMode", 0,
false);
92 pc.process(arg1) ;
pc.process(arg2) ;
pc.process(arg3) ;
93 pc.process(arg4) ;
pc.process(arg5) ;
pc.process(arg6) ;
94 pc.process(arg7) ;
pc.process(arg8) ;
pc.process(arg9) ;
115 Bool_t extended,
const char* rangeName,
const char* addCoefRangeName,
117 RooAbsOptTestStatistic(
name,title,pdf,indata,
RooArgSet(),rangeName,addCoefRangeName,nCPU,interleave,
verbose,splitRange,cloneData),
120 _first(
kTRUE), _offsetSaveW2(0.), _offsetCarrySaveW2(0.)
138 std::list<Double_t>::iterator biter = boundaries->begin() ;
139 _binw.resize(boundaries->size()-1) ;
143 while (biter!=boundaries->end()) {
144 _binw[ibin] = (*biter) - lastBound ;
145 lastBound = (*biter) ;
160 const RooArgSet& projDeps,
Bool_t extended,
const char* rangeName,
const char* addCoefRangeName,
162 RooAbsOptTestStatistic(
name,title,pdf,indata,projDeps,rangeName,addCoefRangeName,nCPU,interleave,
verbose,splitRange,cloneData),
165 _first(
kTRUE), _offsetSaveW2(0.), _offsetCarrySaveW2(0.)
180 std::list<Double_t>::iterator biter = boundaries->begin() ;
181 _binw.resize(boundaries->size()-1) ;
185 while (biter!=boundaries->end()) {
186 _binw[ibin] = (*biter) - lastBound ;
187 lastBound = (*biter) ;
202 _extended(other._extended),
203 _batchEvaluations(other._batchEvaluations),
204 _weightSq(other._weightSq),
205 _first(
kTRUE), _offsetSaveW2(other._offsetSaveW2),
206 _offsetCarrySaveW2(other._offsetCarrySaveW2),
261 double result(0), carry(0), sumWeight(0);
273 double sumWeightCarry = 0.;
274 for (
auto i=firstEvent ; i<lastEvent ; i+=stepSize) {
291 logEvalError(
Form(
"Observed %f events in bin %lu with zero event yield",
N,(
unsigned long)i)) ;
304 Double_t y = eventWeight - sumWeightCarry;
306 sumWeightCarry = (t - sumWeight) -
y;
312 carry = (t - result) -
y;
321 std::tie(result, carry, sumWeight) =
computeBatched(stepSize, firstEvent, lastEvent);
322#ifdef ROOFIT_CHECK_CACHED_VALUES
324 double resultScalar, carryScalar, sumWeightScalar;
325 std::tie(resultScalar, carryScalar, sumWeightScalar) =
328 constexpr bool alwaysPrint =
false;
330 if (alwaysPrint ||
fabs(result - resultScalar)/resultScalar > 1.E-15) {
331 std::cerr <<
"RooNLLVar: result is off\n\t" << std::setprecision(15) << result
332 <<
"\n\t" << resultScalar << std::endl;
335 if (alwaysPrint ||
fabs(carry - carryScalar)/carryScalar > 10.) {
336 std::cerr <<
"RooNLLVar: carry is far off\n\t" << std::setprecision(15) << carry
337 <<
"\n\t" << carryScalar << std::endl;
340 if (alwaysPrint ||
fabs(sumWeight - sumWeightScalar)/sumWeightScalar > 1.E-15) {
341 std::cerr <<
"RooNLLVar: sumWeight is off\n\t" << std::setprecision(15) << sumWeight
342 <<
"\n\t" << sumWeightScalar << std::endl;
347 std::tie(result, carry, sumWeight) =
computeScalar(stepSize, firstEvent, lastEvent);
361 sumW2carry = (t - sumW2) -
y;
391 carry = (t - result) -
y;
396 carry = (t - result) -
y;
408 carry = (t - result) -
y;
424 if (
_offset==0 && result !=0 ) {
425 coutI(
Minimization) <<
"RooNLLVar::evaluatePartition(" <<
GetName() <<
") first = "<< firstEvent <<
" last = " << lastEvent <<
" Likelihood offset now set to " << result << std::endl ;
433 carry = (t - result) -
y;
446 throw std::invalid_argument(std::string(
"Error in ") + __FILE__ +
": Step size for batch computations can only be 1.");
454#ifdef ROOFIT_CHECK_CACHED_VALUES
455 for (std::size_t evtNo = firstEvent; evtNo < lastEvent; ++evtNo) {
461 }
catch (std::exception&
e) {
462 std::cerr <<
"ERROR when checking batch computation for event " << evtNo <<
":\n"
463 <<
e.what() << std::endl;
472 const bool retrieveSquaredWeights =
_weightSq;
473 auto retrieveWeight = [&eventWeights, retrieveSquaredWeights](std::size_t i) {
474 if (retrieveSquaredWeights)
475 return eventWeights[i] * eventWeights[i];
477 return eventWeights[i];
482 if (eventWeights.
size() == 1) {
483 kahanWeight.
Add( (lastEvent - firstEvent) * retrieveWeight(0));
485 for (std::size_t i = 0; i < eventWeights.
size(); ++i) {
493 if (eventWeights.
size() == 1) {
494 const double weight = retrieveWeight(0);
495 for (std::size_t i = 0; i < results.size(); ++i) {
496 kahanProb.
AddIndexed(-weight * results[i], i);
499 for (std::size_t i = 0; i < results.size(); ++i) {
500 kahanProb.
AddIndexed(-retrieveWeight(i) * results[i], i);
505 return std::tuple<double, double, double>{kahanProb.
Sum(), kahanProb.
Carry(), kahanWeight.
Sum()};
509std::tuple<double, double, double>
RooNLLVar::computeScalar(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent)
const {
515 for (
auto i=firstEvent; i<lastEvent; i+=stepSize) {
521 if (0. == eventWeight * eventWeight) continue ;
524 const double term = -eventWeight * pdfClone->getLogVal(
_normSet);
526 kahanWeight.
Add(eventWeight);
530 return std::tuple<double, double, double>{kahanProb.
Sum(), kahanProb.
Carry(), kahanWeight.
Sum()};
char * Form(const char *fmt,...)
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
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
Return the observables of this pdf given a set of observables.
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.
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 Double_t sumEntries() const =0
virtual Bool_t valid() const
virtual Double_t weight() const =0
virtual Double_t weightSquared() const =0
virtual Int_t numEntries() const
virtual RooSpan< const double > getWeightBatch(std::size_t first, std::size_t last) const =0
RooAbsOptTestStatistic is the abstract base class for test statistics objects that evaluate a functio...
RooSpan< const double > getLogValBatch(std::size_t begin, std::size_t batchSize, const RooArgSet *normSet=nullptr) const
Compute the log-likelihoods for all events in the requested batch.
virtual Double_t extendedTerm(Double_t observedEvents, const RooArgSet *nset=0) const
Return the extended likelihood term ( ) of this PDF for the given number of observed events.
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events from this p.d.f for use in extended likelihood calculations.
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
void logEvalError(const char *message, const char *serverValueString=0) const
Log evaluation error message.
Int_t _nGof
Number of designated set to calculated extended term.
Int_t _nCPU
GOF MP Split mode specified by component (when Auto is active)
pRooAbsTestStatistic * _gofArray
GOFOpMode _gofOpMode
Is object initialized
Double_t _evalCarry
avoids loss of precision
pRooRealMPFE * _mpfeArray
Double_t _offsetCarry
Offset.
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 void checkBatchComputation(const RooAbsReal &theReal, std::size_t evtNo, const RooArgSet *normSet=nullptr, double relAccuracy=1.E-13)
Class RooNLLVar implements a -log(likelihood) calculation from a dataset and a PDF.
void applyWeightSquared(Bool_t flag)
RooRealSumPdf * _binnedPdf
static RooArgSet _emptySet
virtual ~RooNLLVar()
Destructor.
std::vector< Double_t > _binw
Double_t _offsetCarrySaveW2
virtual Double_t evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const
Calculate and return likelihood on subset of data.
std::tuple< double, double, double > computeBatched(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent) const
std::tuple< double, double, double > computeScalar(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent) const
The class RooRealSumPdf implements a PDF constructed from a sum of functions:
virtual std::list< Double_t > * binBoundaries(RooAbsRealLValue &, Double_t, Double_t) const
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
virtual const char * GetName() const
Returns name of object.
void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
static constexpr double pc
Double_t LnGamma(Double_t z)
Computation of ln[gamma(z)] for all z.