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,
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
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_) {
77 }
78 break;
79 }
81 result = likelihood_->evaluatePartition({0, 1}, 0, 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
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
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:122
T Sum() const
Definition Util.h:240
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
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)
Virtual base class for implementation of likelihood calculation strategies.
void calculate_offsets()
(Re)calculate (on each worker) all component offsets.
OffsetVec & offsets()
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
Bool_t IsNaN(Double_t x)
Definition TMath.h:892
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.