Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
LikelihoodSerial.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * PB, Patrick Bos, Netherlands eScience Center, p.bos@esciencecenter.nl
5 *
6 * Copyright (c) 2021, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#include "LikelihoodSerial.h"
14
16#include "RooRealVar.h"
17#include "RooNaNPacker.h"
18
19#include "TMath.h" // IsNaN
20
21namespace RooFit {
22namespace TestStatistics {
23
24/** \class LikelihoodSerial
25 * \brief Serial likelihood calculation strategy implementation
26 *
27 * This class serves as a baseline reference implementation of the LikelihoodWrapper. It reimplements the previous
28 * RooNLLVar "BulkPartition" single CPU strategy in the new RooFit::TestStatistics framework.
29 *
30 * \note The class is not intended for use by end-users. We recommend to either use RooMinimizer with a RooAbsL derived
31 * likelihood object, or to use a higher level entry point like RooAbsPdf::fitTo() or RooAbsPdf::createNLL().
32 */
33
34LikelihoodSerial::LikelihoodSerial(std::shared_ptr<RooAbsL> likelihood,
35 std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean,
36 SharedOffset offset)
37 : LikelihoodWrapper(std::move(likelihood), std::move(calculation_is_clean), std::move(offset))
38{
39 initVars();
40}
41
42/// \brief Helper function for the constructor.
43///
44/// This is a separate function (instead of just in ctor) for historical reasons.
45/// Its predecessor RooRealMPFE::initVars() was used from multiple ctors, but also
46/// from RooRealMPFE::constOptimizeTestStatistic at the end, which makes sense,
47/// because it might change the set of variables. We may at some point want to do
48/// this here as well.
50{
51 // Empty current lists
52 _vars.removeAll();
53 _saveVars.removeAll();
54
55 // Retrieve non-constant parameters
56 std::unique_ptr<RooArgSet> vars{likelihood_->getParameters()};
57
58 RooArgList varList(*vars);
59
60 // Save in lists
61 _vars.add(varList);
62 _saveVars.addClone(varList);
63}
64
66{
67 if (do_offset_ && shared_offset_.offsets().empty()) {
69 }
70
71 switch (likelihood_type_) {
74 result = likelihood_->evaluatePartition({0, 1}, 0, 0);
75 if (do_offset_) {
76 result -= shared_offset_.offsets()[0];
77 }
78 break;
79 }
81 result = likelihood_->evaluatePartition({0, 1}, 0, 0);
83 result -= shared_offset_.offsets()[0];
84 }
85 break;
86 }
89 RooNaNPacker packedNaN;
90 for (std::size_t comp_ix = 0; comp_ix < likelihood_->getNComponents(); ++comp_ix) {
91 auto component_result = likelihood_->evaluatePartition({0, 1}, comp_ix, comp_ix + 1);
92 packedNaN.accumulate(component_result.Sum());
93
94 if (do_offset_ && shared_offset_.offsets()[comp_ix] != ROOT::Math::KahanSum<double>(0, 0)) {
95 result += (component_result - shared_offset_.offsets()[comp_ix]);
96 } else {
97 result += component_result;
98 }
99 }
100 if (packedNaN.getPayload() != 0) {
102 }
103 break;
104 }
105 }
106
107 if (TMath::IsNaN(result.Sum())) {
108 RooAbsReal::logEvalError(nullptr, GetName().c_str(), "function value is NAN");
109 }
110}
111
112} // namespace TestStatistics
113} // namespace RooFit
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:141
void logEvalError(const char *message, const char *serverValueString=nullptr) const
Log evaluation error message.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgList _saveVars
Copy of variables.
void evaluate() override
Triggers (possibly asynchronous) evaluation of the likelihood.
ROOT::Math::KahanSum< double > result
void initVars()
Helper function for the constructor.
LikelihoodSerial(std::shared_ptr< RooAbsL > _likelihood, std::shared_ptr< WrapperCalculationCleanFlags > calculation_is_clean, SharedOffset offset)
void calculate_offsets()
(Re)calculate (on each worker) all component offsets.
LikelihoodWrapper(std::shared_ptr< RooAbsL > likelihood, std::shared_ptr< WrapperCalculationCleanFlags > calculation_is_clean, SharedOffset offset)
Namespace for new RooFit test statistic calculation.
Definition RooAbsData.h:50
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:72
Bool_t IsNaN(Double_t x)
Definition TMath.h:903
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.