Logo ROOT  
Reference Guide
RooNLLVar.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooNLLVar.cxx
19\class RooNLLVar
20\ingroup Roofitcore
21
22Class RooNLLVar implements a -log(likelihood) calculation from a dataset
23and a PDF. The NLL is calculated as
24\f[
25 \sum_\mathrm{data} -\log( \mathrm{pdf}(x_\mathrm{data}))
26\f]
27In extended mode, a
28\f$ N_\mathrm{expect} - N_\mathrm{observed}*log(N_\mathrm{expect}) \f$ term is added.
29**/
30
31#include "RooNLLVar.h"
32
33#include "RooAbsData.h"
34#include "RooAbsPdf.h"
35#include "RooCmdConfig.h"
36#include "RooMsgService.h"
37#include "RooAbsDataStore.h"
38#include "RooRealMPFE.h"
39#include "RooRealSumPdf.h"
40#include "RooRealVar.h"
41#include "RooProdPdf.h"
42#include "RooNaNPacker.h"
43#include "RunContext.h"
44
45#ifdef ROOFIT_CHECK_CACHED_VALUES
46#include <iomanip>
47#endif
48
49#include "TMath.h"
50#include "Math/Util.h"
51
52#include <algorithm>
53
54namespace {
55 template<class ...Args>
56 RooAbsTestStatistic::Configuration makeRooAbsTestStatisticCfg(Args const& ... args) {
58 cfg.rangeName = RooCmdConfig::decodeStringOnTheFly("RooNLLVar::RooNLLVar","RangeWithName",0,"",args...);
59 cfg.addCoefRangeName = RooCmdConfig::decodeStringOnTheFly("RooNLLVar::RooNLLVar","AddCoefRange",0,"",args...);
60 cfg.nCPU = RooCmdConfig::decodeIntOnTheFly("RooNLLVar::RooNLLVar","NumCPU",0,1,args...);
62 cfg.verbose = static_cast<bool>(RooCmdConfig::decodeIntOnTheFly("RooNLLVar::RooNLLVar","Verbose",0,1,args...));
63 cfg.splitCutRange = static_cast<bool>(RooCmdConfig::decodeIntOnTheFly("RooNLLVar::RooNLLVar","SplitRange",0,0,args...));
64 cfg.cloneInputData = static_cast<bool>(RooCmdConfig::decodeIntOnTheFly("RooNLLVar::RooNLLVar","CloneData",0,1,args...));
65 cfg.integrateOverBinsPrecision = RooCmdConfig::decodeDoubleOnTheFly("RooNLLVar::RooNLLVar", "IntegrateBins", 0, -1., {args...});
66 return cfg;
67 }
68}
69
71
73
75{ }
76
77////////////////////////////////////////////////////////////////////////////////
78/// Construct likelihood from given p.d.f and (binned or unbinned dataset)
79///
80/// Argument | Description
81/// -------------------------|------------
82/// Extended() | Include extended term in calculation
83/// NumCPU() | Activate parallel processing feature
84/// Range() | Fit only selected region
85/// SumCoefRange() | Set the range in which to interpret the coefficients of RooAddPdf components
86/// SplitRange() | Fit range is split by index category of simultaneous PDF
87/// ConditionalObservables() | Define conditional observables
88/// Verbose() | Verbose output of GOF framework classes
89/// CloneData() | Clone input dataset for internal use (default is kTRUE)
90/// BatchMode() | Evaluate batches of data events (faster if PDFs support it)
91/// IntegrateBins() | Integrate PDF within each bin. This sets the desired precision. Only useful for binned fits.
92RooNLLVar::RooNLLVar(const char *name, const char* title, RooAbsPdf& pdf, RooAbsData& indata,
93 const RooCmdArg& arg1, const RooCmdArg& arg2,const RooCmdArg& arg3,
94 const RooCmdArg& arg4, const RooCmdArg& arg5,const RooCmdArg& arg6,
95 const RooCmdArg& arg7, const RooCmdArg& arg8,const RooCmdArg& arg9) :
96 RooAbsOptTestStatistic(name,title,pdf,indata,
97 *static_cast<const RooArgSet*>(RooCmdConfig::decodeObjOnTheFly(
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))
101{
102 RooCmdConfig pc("RooNLLVar::RooNLLVar") ;
103 pc.allowUndefined() ;
104 pc.defineInt("extended","Extended",0,kFALSE) ;
105 pc.defineInt("BatchMode", "BatchMode", 0, false);
106
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) ;
110
111 _extended = pc.getInt("extended") ;
112 _batchEvaluations = pc.getInt("BatchMode");
113 _weightSq = kFALSE ;
114 _first = kTRUE ;
115 _offsetSaveW2 = 0.;
116
117 _binnedPdf = 0 ;
118}
119
120
121
122////////////////////////////////////////////////////////////////////////////////
123/// Construct likelihood from given p.d.f and (binned or unbinned dataset)
124/// For internal use.
125
126RooNLLVar::RooNLLVar(const char *name, const char *title, RooAbsPdf& pdf, RooAbsData& indata,
127 bool extended, RooAbsTestStatistic::Configuration const& cfg) :
128 RooAbsOptTestStatistic(name,title,pdf,indata,RooArgSet(),cfg),
129 _extended(extended),
130 _weightSq(kFALSE),
131 _first(kTRUE)
132{
133 // If binned likelihood flag is set, pdf is a RooRealSumPdf representing a yield vector
134 // for a binned likelihood calculation
136
137 // Retrieve and cache bin widths needed to convert un-normalized binnedPdf values back to yields
138 if (_binnedPdf) {
139
140 // The Active label will disable pdf integral calculations
141 _binnedPdf->setAttribute("BinnedLikelihoodActive") ;
142
144 if (obs->getSize()!=1) {
145 _binnedPdf = 0 ;
146 } else {
147 RooRealVar* var = (RooRealVar*) obs->first() ;
148 std::list<Double_t>* boundaries = _binnedPdf->binBoundaries(*var,var->getMin(),var->getMax()) ;
149 std::list<Double_t>::iterator biter = boundaries->begin() ;
150 _binw.resize(boundaries->size()-1) ;
151 Double_t lastBound = (*biter) ;
152 ++biter ;
153 int ibin=0 ;
154 while (biter!=boundaries->end()) {
155 _binw[ibin] = (*biter) - lastBound ;
156 lastBound = (*biter) ;
157 ibin++ ;
158 ++biter ;
159 }
160 }
161 }
162}
163
164
165
166////////////////////////////////////////////////////////////////////////////////
167/// Construct likelihood from given p.d.f and (binned or unbinned dataset)
168/// For internal use.
169
170RooNLLVar::RooNLLVar(const char *name, const char *title, RooAbsPdf& pdf, RooAbsData& indata,
171 const RooArgSet& projDeps,
172 bool extended, RooAbsTestStatistic::Configuration const& cfg) :
173 RooAbsOptTestStatistic(name,title,pdf,indata,projDeps, cfg),
174 _extended(extended),
175 _weightSq(kFALSE),
176 _first(kTRUE)
177{
178 // If binned likelihood flag is set, pdf is a RooRealSumPdf representing a yield vector
179 // for a binned likelihood calculation
181
182 // Retrieve and cache bin widths needed to convert un-normalized binnedPdf values back to yields
183 if (_binnedPdf) {
184
186 if (obs->getSize()!=1) {
187 _binnedPdf = 0 ;
188 } else {
189 RooRealVar* var = (RooRealVar*) obs->first() ;
190 std::list<Double_t>* boundaries = _binnedPdf->binBoundaries(*var,var->getMin(),var->getMax()) ;
191 std::list<Double_t>::iterator biter = boundaries->begin() ;
192 _binw.resize(boundaries->size()-1) ;
193 Double_t lastBound = (*biter) ;
194 ++biter ;
195 int ibin=0 ;
196 while (biter!=boundaries->end()) {
197 _binw[ibin] = (*biter) - lastBound ;
198 lastBound = (*biter) ;
199 ibin++ ;
200 ++biter ;
201 }
202 }
203 }
204}
205
206
207
208////////////////////////////////////////////////////////////////////////////////
209/// Copy constructor
210
211RooNLLVar::RooNLLVar(const RooNLLVar& other, const char* name) :
213 _extended(other._extended),
214 _batchEvaluations(other._batchEvaluations),
215 _weightSq(other._weightSq),
216 _first(kTRUE),
217 _offsetSaveW2(other._offsetSaveW2),
218 _binw(other._binw) {
220}
221
222
223////////////////////////////////////////////////////////////////////////////////
224/// Create a test statistic using several properties of the current instance. This is used to duplicate
225/// the test statistic in multi-processing scenarios.
226RooAbsTestStatistic* RooNLLVar::create(const char *name, const char *title, RooAbsReal& pdf, RooAbsData& adata,
227 const RooArgSet& projDeps, RooAbsTestStatistic::Configuration const& cfg) {
228 RooAbsPdf & thePdf = dynamic_cast<RooAbsPdf&>(pdf);
229 // check if pdf can be extended
230 bool extendedPdf = _extended && thePdf.canBeExtended();
231
232 auto testStat = new RooNLLVar(name, title, thePdf, adata, projDeps, extendedPdf, cfg);
233 testStat->batchMode(_batchEvaluations);
234 return testStat;
235}
236
237
238////////////////////////////////////////////////////////////////////////////////
239/// Destructor
240
242{
243}
244
245
246
247
248////////////////////////////////////////////////////////////////////////////////
249
251{
252 if (_gofOpMode==Slave) {
253 if (flag != _weightSq) {
254 _weightSq = flag;
256 }
258 } else if ( _gofOpMode==MPMaster) {
259 for (Int_t i=0 ; i<_nCPU ; i++)
260 _mpfeArray[i]->applyNLLWeightSquared(flag);
261 } else if ( _gofOpMode==SimMaster) {
262 for (Int_t i=0 ; i<_nGof ; i++)
263 ((RooNLLVar*)_gofArray[i])->applyWeightSquared(flag);
264 }
265}
266
267
268////////////////////////////////////////////////////////////////////////////////
269/// Calculate and return likelihood on subset of data.
270/// \param[in] firstEvent First event to be processed.
271/// \param[in] lastEvent First event not to be processed, any more.
272/// \param[in] stepSize Steps between events.
273/// \note For batch computations, the step size **must** be one.
274///
275/// If this an extended likelihood, the extended term is added to the return likelihood
276/// in the batch that encounters the event with index 0.
277
278Double_t RooNLLVar::evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const
279{
280 // Throughout the calculation, we use Kahan's algorithm for summing to
281 // prevent loss of precision - this is a factor four more expensive than
282 // straight addition, but since evaluating the PDF is usually much more
283 // expensive than that, we tolerate the additional cost...
285 double sumWeight{0.0};
286
287 RooAbsPdf* pdfClone = (RooAbsPdf*) _funcClone ;
288
289 // cout << "RooNLLVar::evaluatePartition(" << GetName() << ") projDeps = " << (_projDeps?*_projDeps:RooArgSet()) << endl ;
290
291 _dataClone->store()->recalculateCache( _projDeps, firstEvent, lastEvent, stepSize, (_binnedPdf?kFALSE:kTRUE) ) ;
292
293
294
295 // If pdf is marked as binned - do a binned likelihood calculation here (sum of log-Poisson for each bin)
296 if (_binnedPdf) {
297 ROOT::Math::KahanSum<double> sumWeightKahanSum{0.0};
298 for (auto i=firstEvent ; i<lastEvent ; i+=stepSize) {
299
300 _dataClone->get(i) ;
301
302 if (!_dataClone->valid()) continue;
303
304 Double_t eventWeight = _dataClone->weight();
305
306
307 // Calculate log(Poisson(N|mu) for this bin
308 Double_t N = eventWeight ;
309 Double_t mu = _binnedPdf->getVal()*_binw[i] ;
310 //cout << "RooNLLVar::binnedL(" << GetName() << ") N=" << N << " mu = " << mu << endl ;
311
312 if (mu<=0 && N>0) {
313
314 // Catch error condition: data present where zero events are predicted
315 logEvalError(Form("Observed %f events in bin %lu with zero event yield",N,(unsigned long)i)) ;
316
317 } else if (fabs(mu)<1e-10 && fabs(N)<1e-10) {
318
319 // Special handling of this case since log(Poisson(0,0)=0 but can't be calculated with usual log-formula
320 // since log(mu)=0. No update of result is required since term=0.
321
322 } else {
323
324 result += -1*(-mu + N*log(mu) - TMath::LnGamma(N+1));
325 sumWeightKahanSum += eventWeight;
326
327 }
328 }
329
330 sumWeight = sumWeightKahanSum.Sum();
331
332 } else { //unbinned PDF
333
334 if (_batchEvaluations) {
335 std::tie(result, sumWeight) = computeBatched(stepSize, firstEvent, lastEvent);
336#ifdef ROOFIT_CHECK_CACHED_VALUES
337
338 ROOT::Math::KahanSum<double> resultScalar, sumWeightScalar;
339 std::tie(resultScalar, sumWeightScalar) = computeScalar(stepSize, firstEvent, lastEvent);
340 double carryScalar = resultScalar.Carry();
341
342 constexpr bool alwaysPrint = false;
343
344 if (alwaysPrint || fabs(result - resultScalar)/resultScalar > 5.E-15) {
345 std::cerr << "RooNLLVar: result is off\n\t" << std::setprecision(15) << result
346 << "\n\t" << resultScalar << std::endl;
347 }
348
349 if (alwaysPrint || fabs(carry - carryScalar)/carryScalar > 500.) {
350 std::cerr << "RooNLLVar: carry is far off\n\t" << std::setprecision(15) << carry
351 << "\n\t" << carryScalar << std::endl;
352 }
353
354 if (alwaysPrint || fabs(sumWeight - sumWeightScalar)/sumWeightScalar > 1.E-15) {
355 std::cerr << "RooNLLVar: sumWeight is off\n\t" << std::setprecision(15) << sumWeight
356 << "\n\t" << sumWeightScalar << std::endl;
357 }
358
359#endif
360 } else { //scalar mode
361 std::tie(result, sumWeight) = computeScalar(stepSize, firstEvent, lastEvent);
362 }
363
364 // include the extended maximum likelihood term, if requested
365 if(_extended && _setNum==_extSet) {
366 result += pdfClone->extendedTerm(*_dataClone, _weightSq);
367 }
368 } //unbinned PDF
369
370
371 // If part of simultaneous PDF normalize probability over
372 // number of simultaneous PDFs: -sum(log(p/n)) = -sum(log(p)) + N*log(n)
373 if (_simCount>1) {
374 result += sumWeight * log(1.0*_simCount);
375 }
376
377
378 // At the end of the first full calculation, wire the caches
379 if (_first) {
380 _first = kFALSE ;
382 }
383
384
385 // Check if value offset flag is set.
386 if (_doOffset) {
387
388 // If no offset is stored enable this feature now
389 if (_offset==0 && result !=0 ) {
390 coutI(Minimization) << "RooNLLVar::evaluatePartition(" << GetName() << ") first = "<< firstEvent << " last = " << lastEvent << " Likelihood offset now set to " << result << std::endl ;
391 _offset = result ;
392 }
393
394 // Subtract offset
395 result -= _offset;
396 }
397
398 _evalCarry = result.Carry();
399 return result.Sum() ;
400}
401
402
403////////////////////////////////////////////////////////////////////////////////
404/// Compute probabilites of all data events. Use faster batch interface.
405/// \param[in] stepSize Stride when moving through the dataset.
406/// \note For batch computations, the step size **must** be one.
407/// \param[in] firstEvent First event to be processed.
408/// \param[in] lastEvent First event not to be processed.
409/// \return Tuple with (Kahan sum of probabilities, carry of kahan sum, sum of weights)
410RooNLLVar::ComputeResult RooNLLVar::computeBatched(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent) const
411{
412 auto pdfClone = static_cast<const RooAbsPdf*>(_funcClone);
413 return computeBatchedFunc(pdfClone, _dataClone, _evalData, _normSet, _weightSq, stepSize, firstEvent, lastEvent);
414}
415
416// static function, also used from TestStatistics::RooUnbinnedL
418 std::unique_ptr<RooBatchCompute::RunContext> &evalData,
419 RooArgSet *normSet, bool weightSq, std::size_t stepSize,
420 std::size_t firstEvent, std::size_t lastEvent)
421{
422 const auto nEvents = lastEvent - firstEvent;
423
424 if (stepSize != 1) {
425 throw std::invalid_argument(std::string("Error in ") + __FILE__ + ": Step size for batch computations can only be 1.");
426 }
427
428 // Create a RunContext that will own the memory where computation results are stored.
429 // Holding on to this struct in between function calls will make sure that the memory
430 // is only allocated once.
431 if (!evalData) {
432 evalData.reset(new RooBatchCompute::RunContext);
433 }
434 evalData->clear();
435 dataClone->getBatches(*evalData, firstEvent, nEvents);
436
437 auto results = pdfClone->getLogProbabilities(*evalData, normSet);
438
439#ifdef ROOFIT_CHECK_CACHED_VALUES
440
441 for (std::size_t evtNo = firstEvent; evtNo < std::min(lastEvent, firstEvent + 10); ++evtNo) {
442 dataClone->get(evtNo);
443 if (dataClone->weight() == 0.) // 0-weight events are not cached, so cannot compare against them.
444 continue;
445
446 assert(dataClone->valid());
447 try {
448 // Cross check results with strict tolerance and complain
449 BatchInterfaceAccessor::checkBatchComputation(*pdfClone, *evalData, evtNo-firstEvent, normSet, 1.E-13);
450 } catch (std::exception& e) {
451 std::cerr << __FILE__ << ":" << __LINE__ << " ERROR when checking batch computation for event " << evtNo << ":\n"
452 << e.what() << std::endl;
453
454 // It becomes a real problem if it's very wrong. We fail in this case:
455 try {
456 BatchInterfaceAccessor::checkBatchComputation(*pdfClone, *evalData, evtNo-firstEvent, normSet, 1.E-9);
457 } catch (std::exception& e2) {
458 assert(false);
459 }
460 }
461 }
462
463#endif
464
465
466 // Compute sum of event weights. First check if we need squared weights
467 const RooSpan<const double> eventWeights = dataClone->getWeightBatch(firstEvent, nEvents, weightSq);
468
469 //Sum the event weights and probabilities
471 double uniformSingleEventWeight{0.0};
472 double sumOfWeights;
473 if (eventWeights.empty()) {
474 uniformSingleEventWeight = weightSq ? dataClone->weightSquared() : dataClone->weight();
475 sumOfWeights = nEvents * uniformSingleEventWeight;
476 for (std::size_t i = 0; i < results.size(); ++i) { //CHECK_VECTORISE
477 kahanProb.AddIndexed(-uniformSingleEventWeight * results[i], i);
478 }
479 } else {
480 assert(results.size() == eventWeights.size());
482 for (std::size_t i = 0; i < results.size(); ++i) { //CHECK_VECTORISE
483 const double weight = eventWeights[i];
484 kahanProb.AddIndexed(-weight * results[i], i);
485 kahanWeight.AddIndexed(weight, i);
486 }
487 sumOfWeights = kahanWeight.Sum();
488 }
489
490 if (std::isnan(kahanProb.Sum())) {
491 // Special handling of evaluation errors.
492 // We can recover if the bin/event that results in NaN has a weight of zero:
494 RooNaNPacker nanPacker;
495 for (std::size_t i = 0; i < results.size(); ++i) {
496 double weight = eventWeights.empty() ? uniformSingleEventWeight : eventWeights[i];
497
498 if (weight == 0.)
499 continue;
500
501 if (std::isnan(results[i])) {
502 nanPacker.accumulate(results[i]);
503 } else {
504 kahanSanitised += -weight * results[i];
505 }
506 }
507
508 // Some events with evaluation errors. Return "badness" of errors.
509 if (nanPacker.getPayload() > 0.) {
510 return {{nanPacker.getNaNWithPayload()}, sumOfWeights};
511 } else {
512 return {kahanSanitised, sumOfWeights};
513 }
514 }
515
516 return {kahanProb, sumOfWeights};
517}
518
519
520RooNLLVar::ComputeResult RooNLLVar::computeScalar(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent) const {
521 auto pdfClone = static_cast<const RooAbsPdf*>(_funcClone);
522 return computeScalarFunc(pdfClone, _dataClone, _normSet, _weightSq, stepSize, firstEvent, lastEvent);
523}
524
525// static function, also used from TestStatistics::RooUnbinnedL
527 RooArgSet *normSet, bool weightSq, std::size_t stepSize,
528 std::size_t firstEvent, std::size_t lastEvent)
529{
532 RooNaNPacker packedNaN(0.f);
533
534 for (auto i=firstEvent; i<lastEvent; i+=stepSize) {
535 dataClone->get(i) ;
536
537 if (!dataClone->valid()) continue;
538
539 Double_t eventWeight = dataClone->weight(); //FIXME
540 if (0. == eventWeight * eventWeight) continue ;
541 if (weightSq) eventWeight = dataClone->weightSquared() ;
542
543 const double term = -eventWeight * pdfClone->getLogVal(normSet);
544
545 kahanWeight.Add(eventWeight);
546 kahanProb.Add(term);
547 packedNaN.accumulate(term);
548 }
549
550 if (packedNaN.getPayload() != 0.) {
551 // Some events with evaluation errors. Return "badness" of errors.
552 return {{packedNaN.getNaNWithPayload()}, kahanWeight.Sum()};
553 }
554
555 return {kahanProb, kahanWeight.Sum()};
556}
#define e(i)
Definition: RSha256.hxx:103
#define coutI(a)
Definition: RooMsgService.h:30
int Int_t
Definition: RtypesCore.h:45
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:364
#define N
char name[80]
Definition: TGX11.cxx:110
char * Form(const char *fmt,...)
static void checkBatchComputation(const RooAbsReal &theReal, const RooBatchCompute::RunContext &evalData, std::size_t evtNo, const RooArgSet *normSet=nullptr, double relAccuracy=1.E-13)
Definition: RooAbsReal.h:588
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition: Util.h:122
T Sum() const
Definition: Util.h:240
T Carry() const
Definition: Util.h:255
void AddIndexed(T input, std::size_t index)
Add input to the sum.
Definition: Util.h:231
void Add(T x)
Single-element accumulation. Will not vectorise.
Definition: Util.h:165
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Given a set of possible observables, return the observables that this PDF depends on.
Definition: RooAbsArg.h:295
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Definition: RooAbsArg.cxx:291
void wireAllCaches()
Definition: RooAbsArg.cxx:2309
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:491
Int_t getSize() 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.
Definition: RooAbsData.h:79
virtual const RooArgSet * get() const
Definition: RooAbsData.h:125
RooAbsDataStore * store()
Definition: RooAbsData.h:101
virtual void getBatches(RooBatchCompute::RunContext &evalData, std::size_t first=0, std::size_t len=std::numeric_limits< std::size_t >::max()) const =0
Retrieve batches of data for each real-valued variable in this dataset.
virtual Bool_t valid() const
Definition: RooAbsData.h:131
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).
RooAbsOptTestStatistic is the abstract base class for test statistics objects that evaluate a functio...
RooSpan< const double > getLogProbabilities(RooBatchCompute::RunContext &evalData, const RooArgSet *normSet=nullptr) const
Compute the log-likelihoods for all events in the requested batch.
Definition: RooAbsPdf.cxx:758
Bool_t canBeExtended() const
If true, PDF can provide extended likelihood term.
Definition: RooAbsPdf.h:263
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...
Definition: RooAbsPdf.cxx:678
double extendedTerm(double observedEvents, const RooArgSet *nset=0) const
Return the extended likelihood term ( ) of this PDF for the given number of observed events.
Definition: RooAbsPdf.cxx:805
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.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
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 _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
ROOT::Math::KahanSum< double > _offset
Double_t _evalCarry
Offset as KahanSum to avoid loss of precision.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:35
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:27
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
Definition: RooCmdConfig.h:27
static std::string decodeStringOnTheFly(const char *callerID, const char *cmdArgName, Int_t intIdx, const char *defVal, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg())
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, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg())
Static decoder function allows to retrieve integer property from set of RooCmdArgs For use in base me...
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.
Class RooNLLVar implements a -log(likelihood) calculation from a dataset and a PDF.
Definition: RooNLLVar.h:30
ComputeResult computeScalar(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent) const
Definition: RooNLLVar.cxx:520
void applyWeightSquared(Bool_t flag)
Definition: RooNLLVar.cxx:250
RooRealSumPdf * _binnedPdf
Definition: RooNLLVar.h:92
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)
Definition: RooNLLVar.cxx:526
ROOT::Math::KahanSum< double > _offsetSaveW2
Definition: RooNLLVar.h:89
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)
Definition: RooNLLVar.cxx:417
Bool_t _extended
Definition: RooNLLVar.h:85
bool _batchEvaluations
Definition: RooNLLVar.h:86
static RooArgSet _emptySet
Definition: RooNLLVar.h:79
virtual ~RooNLLVar()
Destructor.
Definition: RooNLLVar.cxx:241
Bool_t _first
Definition: RooNLLVar.h:88
std::pair< ROOT::Math::KahanSum< double >, double > ComputeResult
Definition: RooNLLVar.h:64
std::vector< Double_t > _binw
Definition: RooNLLVar.h:91
virtual RooAbsTestStatistic * create(const char *name, const char *title, RooAbsReal &pdf, RooAbsData &adata, const RooArgSet &projDeps, RooAbsTestStatistic::Configuration const &cfg)
Create a test statistic using several properties of the current instance.
Definition: RooNLLVar.cxx:226
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.
Definition: RooNLLVar.cxx:278
std::unique_ptr< RooBatchCompute::RunContext > _evalData
Definition: RooNLLVar.h:93
Bool_t _weightSq
Definition: RooNLLVar.h:87
ComputeResult computeBatched(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent) const
Compute probabilites of all data events.
Definition: RooNLLVar.cxx:410
The class RooRealSumPdf implements a PDF constructed from a sum of functions:
Definition: RooRealSumPdf.h:24
virtual std::list< Double_t > * binBoundaries(RooAbsRealLValue &, Double_t, Double_t) const
Retrieve bin boundaries if this distribution is binned in obs.
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
constexpr std::span< T >::index_type size() const noexcept
Definition: RooSpan.h:121
constexpr bool empty() const noexcept
Definition: RooSpan.h:125
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
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)
@ BulkPartition
Definition: RooGlobalFunc.h:63
@ Minimization
Definition: RooGlobalFunc.h:60
static constexpr double pc
Double_t LnGamma(Double_t z)
Computation of ln[gamma(z)] for all z.
Definition: TMath.cxx:486
std::string rangeName
Stores the configuration parameters for RooAbsTestStatistic.
This struct enables passing computation data around between elements of a computation graph.
Definition: RunContext.h:31
Little struct that can pack a float into the unused bits of the mantissa of a NaN double.
Definition: RooNaNPacker.h:28
float getPayload() const
Retrieve packed float.
Definition: RooNaNPacker.h:85
double getNaNWithPayload() const
Retrieve a NaN with the current float payload packed into the mantissa.
Definition: RooNaNPacker.h:90
void accumulate(double val)
Accumulate a packed float from another NaN into this.
Definition: RooNaNPacker.h:57