Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include "RooDataHist.h"
45
46#ifdef ROOFIT_CHECK_CACHED_VALUES
47#include <iomanip>
48#endif
49
50#include "TMath.h"
51#include "Math/Util.h"
52
53#include <algorithm>
54
55namespace {
56 template<class ...Args>
57 RooAbsTestStatistic::Configuration makeRooAbsTestStatisticCfg(Args const& ... args) {
59 cfg.rangeName = RooCmdConfig::decodeStringOnTheFly("RooNLLVar::RooNLLVar","RangeWithName",0,"",args...);
60 cfg.addCoefRangeName = RooCmdConfig::decodeStringOnTheFly("RooNLLVar::RooNLLVar","AddCoefRange",0,"",args...);
61 cfg.nCPU = RooCmdConfig::decodeIntOnTheFly("RooNLLVar::RooNLLVar","NumCPU",0,1,args...);
63 cfg.verbose = static_cast<bool>(RooCmdConfig::decodeIntOnTheFly("RooNLLVar::RooNLLVar","Verbose",0,1,args...));
64 cfg.splitCutRange = static_cast<bool>(RooCmdConfig::decodeIntOnTheFly("RooNLLVar::RooNLLVar","SplitRange",0,0,args...));
65 cfg.cloneInputData = static_cast<bool>(RooCmdConfig::decodeIntOnTheFly("RooNLLVar::RooNLLVar","CloneData",0,1,args...));
66 cfg.integrateOverBinsPrecision = RooCmdConfig::decodeDoubleOnTheFly("RooNLLVar::RooNLLVar", "IntegrateBins", 0, -1., {args...});
67 return cfg;
68 }
69}
70
72
75
77
78////////////////////////////////////////////////////////////////////////////////
79/// Construct likelihood from given p.d.f and (binned or unbinned dataset)
80///
81/// Argument | Description
82/// -------------------------|------------
83/// Extended() | Include extended term in calculation
84/// NumCPU() | Activate parallel processing feature
85/// Range() | Fit only selected region
86/// SumCoefRange() | Set the range in which to interpret the coefficients of RooAddPdf components
87/// SplitRange() | Fit range is split by index category of simultaneous PDF
88/// ConditionalObservables() | Define conditional observables
89/// Verbose() | Verbose output of GOF framework classes
90/// CloneData() | Clone input dataset for internal use (default is true)
91/// BatchMode() | Evaluate batches of data events (faster if PDFs support it)
92/// IntegrateBins() | Integrate PDF within each bin. This sets the desired precision. Only useful for binned fits.
93RooNLLVar::RooNLLVar(const char *name, const char* title, RooAbsPdf& pdf, RooAbsData& indata,
94 const RooCmdArg& arg1, const RooCmdArg& arg2,const RooCmdArg& arg3,
95 const RooCmdArg& arg4, const RooCmdArg& arg5,const RooCmdArg& arg6,
96 const RooCmdArg& arg7, const RooCmdArg& arg8,const RooCmdArg& arg9) :
97 RooAbsOptTestStatistic(name,title,pdf,indata,
98 *RooCmdConfig::decodeSetOnTheFly(
99 "RooNLLVar::RooNLLVar","ProjectedObservables",0,&_emptySet,
100 arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
101 makeRooAbsTestStatisticCfg(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9))
102{
103 RooCmdConfig pc("RooNLLVar::RooNLLVar") ;
104 pc.allowUndefined() ;
105 pc.defineInt("extended","Extended",0,false) ;
106 pc.defineInt("BatchMode", "BatchMode", 0, false);
107
108 pc.process(arg1) ; pc.process(arg2) ; pc.process(arg3) ;
109 pc.process(arg4) ; pc.process(arg5) ; pc.process(arg6) ;
110 pc.process(arg7) ; pc.process(arg8) ; pc.process(arg9) ;
111
112 _extended = pc.getInt("extended") ;
113 _batchEvaluations = pc.getInt("BatchMode");
114}
115
116
117////////////////////////////////////////////////////////////////////////////////
118/// Construct likelihood from given p.d.f and (binned or unbinned dataset)
119/// For internal use.
120
121RooNLLVar::RooNLLVar(const char *name, const char *title, RooAbsPdf& pdf, RooAbsData& indata,
122 bool extended, RooAbsTestStatistic::Configuration const& cfg) :
123 RooNLLVar{name, title, pdf, indata, RooArgSet(), extended, cfg} {}
124
125
126////////////////////////////////////////////////////////////////////////////////
127/// Construct likelihood from given p.d.f and (binned or unbinned dataset)
128/// For internal use.
129
130RooNLLVar::RooNLLVar(const char *name, const char *title, RooAbsPdf& pdf, RooAbsData& indata,
131 const RooArgSet& projDeps,
132 bool extended, RooAbsTestStatistic::Configuration const& cfg) :
133 RooAbsOptTestStatistic(name,title,pdf,indata,projDeps, cfg),
134 _extended(extended)
135{
136 // If binned likelihood flag is set, pdf is a RooRealSumPdf representing a yield vector
137 // for a binned likelihood calculation
138 _binnedPdf = cfg.binnedL ? static_cast<RooRealSumPdf*>(_funcClone) : nullptr ;
139
140 // Retrieve and cache bin widths needed to convert un-normalized binnedPdf values back to yields
141 if (_binnedPdf) {
142
143 // The Active label will disable pdf integral calculations
144 _binnedPdf->setAttribute("BinnedLikelihoodActive") ;
145
146 RooArgSet obs;
148 if (obs.size()!=1) {
149 _binnedPdf = nullptr;
150 } else {
151 auto* var = static_cast<RooRealVar*>(obs.first());
152 std::unique_ptr<std::list<double>> boundaries{_binnedPdf->binBoundaries(*var,var->getMin(),var->getMax())};
153 auto biter = boundaries->begin() ;
154 _binw.reserve(boundaries->size()-1) ;
155 double lastBound = (*biter) ;
156 ++biter ;
157 while (biter!=boundaries->end()) {
158 _binw.push_back((*biter) - lastBound);
159 lastBound = (*biter) ;
160 ++biter ;
161 }
162 }
163 }
164}
165
166
167
168////////////////////////////////////////////////////////////////////////////////
169/// Copy constructor
170
171RooNLLVar::RooNLLVar(const RooNLLVar& other, const char* name) :
173 _extended(other._extended),
174 _batchEvaluations(other._batchEvaluations),
175 _weightSq(other._weightSq),
176 _offsetSaveW2(other._offsetSaveW2),
177 _binw(other._binw),
178 _binnedPdf{other._binnedPdf}
179{
180}
181
182
183////////////////////////////////////////////////////////////////////////////////
184/// Create a test statistic using several properties of the current instance. This is used to duplicate
185/// the test statistic in multi-processing scenarios.
186RooAbsTestStatistic* RooNLLVar::create(const char *name, const char *title, RooAbsReal& pdf, RooAbsData& adata,
187 const RooArgSet& projDeps, RooAbsTestStatistic::Configuration const& cfg) {
188 RooAbsPdf & thePdf = dynamic_cast<RooAbsPdf&>(pdf);
189 // check if pdf can be extended
190 bool extendedPdf = _extended && thePdf.canBeExtended();
191
192 auto testStat = new RooNLLVar(name, title, thePdf, adata, projDeps, extendedPdf, cfg);
193 testStat->batchMode(_batchEvaluations);
194 return testStat;
195}
196
197
198////////////////////////////////////////////////////////////////////////////////
199
201{
202 if (_gofOpMode==Slave) {
203 if (flag != _weightSq) {
204 _weightSq = flag;
205 std::swap(_offset, _offsetSaveW2);
206 }
208 } else if ( _gofOpMode==MPMaster) {
209 for (int i=0 ; i<_nCPU ; i++)
210 _mpfeArray[i]->applyNLLWeightSquared(flag);
211 } else if ( _gofOpMode==SimMaster) {
212 for(auto& gof : _gofArray)
213 static_cast<RooNLLVar&>(*gof).applyWeightSquared(flag);
214 }
215}
216
217
218////////////////////////////////////////////////////////////////////////////////
219/// Calculate and return likelihood on subset of data.
220/// \param[in] firstEvent First event to be processed.
221/// \param[in] lastEvent First event not to be processed, any more.
222/// \param[in] stepSize Steps between events.
223/// \note For batch computations, the step size **must** be one.
224///
225/// If this an extended likelihood, the extended term is added to the return likelihood
226/// in the batch that encounters the event with index 0.
227
228double RooNLLVar::evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const
229{
230 // Throughout the calculation, we use Kahan's algorithm for summing to
231 // prevent loss of precision - this is a factor four more expensive than
232 // straight addition, but since evaluating the PDF is usually much more
233 // expensive than that, we tolerate the additional cost...
235 double sumWeight{0.0};
236
237 auto * pdfClone = static_cast<RooAbsPdf*>(_funcClone);
238
239 // cout << "RooNLLVar::evaluatePartition(" << GetName() << ") projDeps = " << (_projDeps?*_projDeps:RooArgSet()) << endl ;
240
241 _dataClone->store()->recalculateCache( _projDeps, firstEvent, lastEvent, stepSize, (_binnedPdf?false:true) ) ;
242
243
244
245 // If pdf is marked as binned - do a binned likelihood calculation here (sum of log-Poisson for each bin)
246 if (_binnedPdf) {
247 ROOT::Math::KahanSum<double> sumWeightKahanSum{0.0};
248 for (auto i=firstEvent ; i<lastEvent ; i+=stepSize) {
249
250 _dataClone->get(i) ;
251
252 double eventWeight = _dataClone->weight();
253
254
255 // Calculate log(Poisson(N|mu) for this bin
256 double N = eventWeight ;
257 double mu = _binnedPdf->getVal()*_binw[i] ;
258 //cout << "RooNLLVar::binnedL(" << GetName() << ") N=" << N << " mu = " << mu << endl ;
259
260 if (mu<=0 && N>0) {
261
262 // Catch error condition: data present where zero events are predicted
263 logEvalError(Form("Observed %f events in bin %lu with zero event yield",N,(unsigned long)i)) ;
264
265 } else if (std::abs(mu)<1e-10 && std::abs(N)<1e-10) {
266
267 // Special handling of this case since log(Poisson(0,0)=0 but can't be calculated with usual log-formula
268 // since log(mu)=0. No update of result is required since term=0.
269
270 } else {
271
272 result += -1*(-mu + N * std::log(mu) - TMath::LnGamma(N+1));
273 sumWeightKahanSum += eventWeight;
274
275 }
276 }
277
278 sumWeight = sumWeightKahanSum.Sum();
279
280 } else { //unbinned PDF
281
282 if (_batchEvaluations) {
283 std::tie(result, sumWeight) = computeBatched(stepSize, firstEvent, lastEvent);
284#ifdef ROOFIT_CHECK_CACHED_VALUES
285
286 ROOT::Math::KahanSum<double> resultScalar, sumWeightScalar;
287 std::tie(resultScalar, sumWeightScalar) = computeScalar(stepSize, firstEvent, lastEvent);
288 double carryScalar = resultScalar.Carry();
289
290 constexpr bool alwaysPrint = false;
291
292 if (alwaysPrint || std::abs(result - resultScalar)/resultScalar > 5.E-15) {
293 std::cerr << "RooNLLVar: result is off\n\t" << std::setprecision(15) << result
294 << "\n\t" << resultScalar << std::endl;
295 }
296
297 if (alwaysPrint || std::abs(carry - carryScalar)/carryScalar > 500.) {
298 std::cerr << "RooNLLVar: carry is far off\n\t" << std::setprecision(15) << carry
299 << "\n\t" << carryScalar << std::endl;
300 }
301
302 if (alwaysPrint || std::abs(sumWeight - sumWeightScalar)/sumWeightScalar > 1.E-15) {
303 std::cerr << "RooNLLVar: sumWeight is off\n\t" << std::setprecision(15) << sumWeight
304 << "\n\t" << sumWeightScalar << std::endl;
305 }
306
307#endif
308 } else { //scalar mode
309 std::tie(result, sumWeight) = computeScalar(stepSize, firstEvent, lastEvent);
310 }
311
312 // include the extended maximum likelihood term, if requested
313 if(_extended && _setNum==_extSet) {
314 result += pdfClone->extendedTerm(*_dataClone, _weightSq, _doBinOffset);
315 }
316 } //unbinned PDF
317
318
319 // If part of simultaneous PDF normalize probability over
320 // number of simultaneous PDFs: -sum(log(p/n)) = -sum(log(p)) + N*log(n)
321 if (_simCount>1) {
322 result += sumWeight * std::log(static_cast<double>(_simCount));
323 }
324
325
326 // At the end of the first full calculation, wire the caches
327 if (_first) {
328 _first = false ;
330 }
331
332
333 // Check if value offset flag is set.
334 if (_doOffset) {
335
336 // If no offset is stored enable this feature now
337 if (_offset.Sum() == 0 && _offset.Carry() == 0 && (result.Sum() != 0 || result.Carry() != 0)) {
338 coutI(Minimization) << "RooNLLVar::evaluatePartition(" << GetName() << ") first = "<< firstEvent << " last = " << lastEvent << " Likelihood offset now set to " << result.Sum() << std::endl ;
339 _offset = result ;
340 }
341
342 // Subtract offset
343 result -= _offset;
344 }
345
346 _evalCarry = result.Carry();
347 return result.Sum() ;
348}
349
350
351////////////////////////////////////////////////////////////////////////////////
352/// Compute probabilites of all data events. Use faster batch interface.
353/// \param[in] stepSize Stride when moving through the dataset.
354/// \note For batch computations, the step size **must** be one.
355/// \param[in] firstEvent First event to be processed.
356/// \param[in] lastEvent First event not to be processed.
357/// \return Tuple with (Kahan sum of probabilities, carry of kahan sum, sum of weights)
358RooNLLVar::ComputeResult RooNLLVar::computeBatched(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent) const
359{
360 auto pdfClone = static_cast<const RooAbsPdf*>(_funcClone);
361 return computeBatchedFunc(pdfClone, _dataClone, _evalData, _normSet, _weightSq, stepSize, firstEvent, lastEvent);
362}
363
364// static function, also used from TestStatistics::RooUnbinnedL
366 std::unique_ptr<RooBatchCompute::RunContext> &evalData,
367 RooArgSet *normSet, bool weightSq, std::size_t stepSize,
368 std::size_t firstEvent, std::size_t lastEvent)
369{
370 const auto nEvents = lastEvent - firstEvent;
371
372 if (stepSize != 1) {
373 throw std::invalid_argument(std::string("Error in ") + __FILE__ + ": Step size for batch computations can only be 1.");
374 }
375
376 // Create a RunContext that will own the memory where computation results are stored.
377 // Holding on to this struct in between function calls will make sure that the memory
378 // is only allocated once.
379 if (!evalData) {
380 evalData = std::make_unique<RooBatchCompute::RunContext>();
381 }
382 evalData->clear();
383 evalData->spans = dataClone->getBatches(firstEvent, nEvents);
384
385 auto results = pdfClone->getLogProbabilities(*evalData, normSet);
386
387#ifdef ROOFIT_CHECK_CACHED_VALUES
388
389 for (std::size_t evtNo = firstEvent; evtNo < std::min(lastEvent, firstEvent + 10); ++evtNo) {
390 dataClone->get(evtNo);
391 if (dataClone->weight() == 0.) // 0-weight events are not cached, so cannot compare against them.
392 continue;
393
394 try {
395 // Cross check results with strict tolerance and complain
396 BatchInterfaceAccessor::checkBatchComputation(*pdfClone, *evalData, evtNo-firstEvent, normSet, 1.E-13);
397 } catch (std::exception& e) {
398 std::cerr << __FILE__ << ":" << __LINE__ << " ERROR when checking batch computation for event " << evtNo << ":\n"
399 << e.what() << std::endl;
400
401 // It becomes a real problem if it's very wrong. We fail in this case:
402 try {
403 BatchInterfaceAccessor::checkBatchComputation(*pdfClone, *evalData, evtNo-firstEvent, normSet, 1.E-9);
404 } catch (std::exception& e2) {
405 assert(false);
406 }
407 }
408 }
409
410#endif
411
412
413 // Compute sum of event weights. First check if we need squared weights
414 const RooSpan<const double> eventWeights = dataClone->getWeightBatch(firstEvent, nEvents, weightSq);
415
416 //Sum the event weights and probabilities
418 double uniformSingleEventWeight{0.0};
419 double sumOfWeights;
420 if (eventWeights.empty()) {
421 uniformSingleEventWeight = weightSq ? dataClone->weightSquared() : dataClone->weight();
422 sumOfWeights = nEvents * uniformSingleEventWeight;
423 for (std::size_t i = 0; i < results.size(); ++i) { //CHECK_VECTORISE
424 kahanProb.AddIndexed(-uniformSingleEventWeight * results[i], i);
425 }
426 } else {
427 assert(results.size() == eventWeights.size());
429 for (std::size_t i = 0; i < results.size(); ++i) { //CHECK_VECTORISE
430 const double weight = eventWeights[i];
431 kahanProb.AddIndexed(-weight * results[i], i);
432 kahanWeight.AddIndexed(weight, i);
433 }
434 sumOfWeights = kahanWeight.Sum();
435 }
436
437 if (std::isnan(kahanProb.Sum())) {
438 // Special handling of evaluation errors.
439 // We can recover if the bin/event that results in NaN has a weight of zero:
441 RooNaNPacker nanPacker;
442 for (std::size_t i = 0; i < results.size(); ++i) {
443 double weight = eventWeights.empty() ? uniformSingleEventWeight : eventWeights[i];
444
445 if (weight == 0.)
446 continue;
447
448 if (std::isnan(results[i])) {
449 nanPacker.accumulate(results[i]);
450 } else {
451 kahanSanitised += -weight * results[i];
452 }
453 }
454
455 // Some events with evaluation errors. Return "badness" of errors.
456 if (nanPacker.getPayload() > 0.) {
457 return {ROOT::Math::KahanSum<double>{nanPacker.getNaNWithPayload()}, sumOfWeights};
458 } else {
459 return {kahanSanitised, sumOfWeights};
460 }
461 }
462
463 return {kahanProb, sumOfWeights};
464}
465
466
467RooNLLVar::ComputeResult RooNLLVar::computeScalar(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent) const {
468 auto pdfClone = static_cast<const RooAbsPdf*>(_funcClone);
469 return computeScalarFunc(pdfClone, _dataClone, _normSet, _weightSq, stepSize, firstEvent, lastEvent, _doBinOffset);
470}
471
472// static function, also used from TestStatistics::RooUnbinnedL
474 RooArgSet *normSet, bool weightSq, std::size_t stepSize,
475 std::size_t firstEvent, std::size_t lastEvent, bool doBinOffset)
476{
479 RooNaNPacker packedNaN(0.f);
480 const double logSumW = std::log(dataClone->sumEntries());
481
482 auto* dataHist = doBinOffset ? static_cast<RooDataHist*>(dataClone) : nullptr;
483
484 for (auto i=firstEvent; i<lastEvent; i+=stepSize) {
485 dataClone->get(i) ;
486
487 double weight = dataClone->weight(); //FIXME
488 const double ni = weight;
489
490 if (0. == weight * weight) continue ;
491 if (weightSq) weight = dataClone->weightSquared() ;
492
493 double logProba = pdfClone->getLogVal(normSet);
494
495 if(doBinOffset) {
496 logProba -= std::log(ni) - std::log(dataHist->binVolume(i)) - logSumW;
497 }
498
499 const double term = -weight * logProba;
500
501 kahanWeight.Add(weight);
502 kahanProb.Add(term);
503 packedNaN.accumulate(term);
504 }
505
506 if (packedNaN.getPayload() != 0.) {
507 // Some events with evaluation errors. Return "badness" of errors.
508 return {ROOT::Math::KahanSum<double>{packedNaN.getNaNWithPayload()}, kahanWeight.Sum()};
509 }
510
511 return {kahanProb, kahanWeight.Sum()};
512}
#define e(i)
Definition RSha256.hxx:103
#define coutI(a)
#define ClassImp(name)
Definition Rtypes.h:377
#define N
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 name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
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:608
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:250
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
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 wireAllCaches()
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:487
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
virtual void recalculateCache(const RooArgSet *, Int_t, Int_t, Int_t, bool)
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:59
virtual double weight() const =0
virtual double sumEntries() const =0
Return effective number of entries in dataset, i.e., sum all weights.
virtual const RooArgSet * get() const
Definition RooAbsData.h:103
RooAbsDataStore * store()
Definition RooAbsData.h:79
RealSpans getBatches(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.
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 double weightSquared() const =0
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 canBeExtended() const
If true, PDF can provide extended likelihood term.
Definition RooAbsPdf.h:278
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...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
void logEvalError(const char *message, const char *serverValueString=nullptr) 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.
double _evalCarry
! carry of Kahan sum in evaluatePartition
Int_t _nCPU
Number of processors to use in parallel calculation mode.
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
std::vector< std::unique_ptr< RooAbsTestStatistic > > _gofArray
! Array of sub-contexts representing part of the combined 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.
Definition RooArgSet.h:55
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition RooCmdArg.h:26
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
bool process(const RooCmdArg &arg)
Process given RooCmdArg.
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name 'name'.
bool defineInt(const char *name, const char *argName, Int_t intNum, Int_t defValue=0)
Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName...
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.
void allowUndefined(bool flag=true)
If flag is true the processing of unrecognized RooCmdArgs is not considered an error.
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...
The RooDataHist is a container class to hold N-dimensional binned data.
Definition RooDataHist.h:39
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
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, bool doBinOffset=false)
RooRealSumPdf * _binnedPdf
!
Definition RooNLLVar.h:97
bool _doBinOffset
Definition RooNLLVar.h:91
ROOT::Math::KahanSum< double > _offsetSaveW2
!
Definition RooNLLVar.h:94
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)
bool _batchEvaluations
Definition RooNLLVar.h:90
static RooArgSet _emptySet
Definition RooNLLVar.h:83
void applyWeightSquared(bool flag) override
Disables or enables the usage of squared weights.
std::vector< double > _binw
!
Definition RooNLLVar.h:96
std::pair< ROOT::Math::KahanSum< double >, double > ComputeResult
Definition RooNLLVar.h:68
bool _extended
Definition RooNLLVar.h:89
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.
~RooNLLVar() override
Definition RooNLLVar.cxx:74
bool _first
!
Definition RooNLLVar.h:93
std::unique_ptr< RooBatchCompute::RunContext > _evalData
! Struct to store function evaluation workspaces.
Definition RooNLLVar.h:98
ComputeResult computeBatched(std::size_t stepSize, std::size_t firstEvent, std::size_t lastEvent) const
Compute probabilites of all data events.
bool _weightSq
Apply weights squared?
Definition RooNLLVar.h:92
double evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const override
Calculate and return likelihood on subset of data.
The class RooRealSumPdf implements a PDF constructed from a sum of functions:
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Retrieve bin boundaries if this distribution is binned in obs.
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:40
A simple container to hold a batch of data values.
Definition RooSpan.h:34
constexpr std::size_t size() const noexcept
Definition RooSpan.h:119
constexpr bool empty() const noexcept
Definition RooSpan.h:124
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
@ BulkPartition
Double_t LnGamma(Double_t z)
Computation of ln[gamma(z)] for all z.
Definition TMath.cxx:509
std::string rangeName
Stores the configuration parameters for RooAbsTestStatistic.
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.