Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
LikelihoodGradientWrapper.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
14#include "RooMinimizer.h"
15
16// including derived classes for factory method
17#ifdef ROOFIT_MULTIPROCESS
19#endif // ROOFIT_MULTIPROCESS
20
21namespace RooFit {
22namespace TestStatistics {
23
24/** \class LikelihoodGradientWrapper
25 * \brief Virtual base class for implementation of likelihood gradient calculation strategies
26 *
27 * This class provides the interface necessary for RooMinimizer (through MinuitFcnGrad) to get the likelihood gradient
28 * values it needs for fitting the pdf to the data. The strategy by which these values are obtained is up to the
29 * implementer of this class. Its intended purpose was mainly to allow for parallel calculation strategies.
30 *
31 * \note The class is not intended for use by end-users. We recommend to either use RooMinimizer with a RooAbsL derived
32 * likelihood object, or to use a higher level entry point like RooAbsPdf::fitTo() or RooAbsPdf::createNLL().
33 */
34
35/*
36 * \param[in] likelihood Shared pointer to the likelihood that must be evaluated
37 * \param[in] calculation_is_clean Shared pointer to the object that keeps track of what has been evaluated for the
38 * current parameter set provided by Minuit. This information can be used by different calculators, so must be shared
39 * between them. \param[in] minimizer Raw pointer to the minimizer that owns the MinuitFcnGrad object that owns this
40 * wrapper object.
41 */
42LikelihoodGradientWrapper::LikelihoodGradientWrapper(std::shared_ptr<RooAbsL> likelihood,
43 std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean,
44 std::size_t /*N_dim*/, RooMinimizer *minimizer)
45 : likelihood_(std::move(likelihood)), minimizer_(minimizer), calculation_is_clean_(std::move(calculation_is_clean))
46{
47 // Note to future maintainers: take care when storing the minimizer_fcn pointer. The
48 // RooAbsMinimizerFcn subclasses may get cloned inside MINUIT, which means the pointer
49 // should also somehow be updated in this class.
50}
51
53
55 const std::vector<ROOT::Fit::ParameterSettings> &parameter_settings)
56{
58}
59
60void LikelihoodGradientWrapper::updateMinuitInternalParameterValues(const std::vector<double> & /*minuit_internal_x*/)
61{
62}
63void LikelihoodGradientWrapper::updateMinuitExternalParameterValues(const std::vector<double> & /*minuit_external_x*/)
64{
65}
66
67/// Factory method.
68std::unique_ptr<LikelihoodGradientWrapper>
69LikelihoodGradientWrapper::create(LikelihoodGradientMode likelihoodGradientMode, std::shared_ptr<RooAbsL> likelihood,
70 std::shared_ptr<WrapperCalculationCleanFlags> calculationIsClean, std::size_t nDim,
71 RooMinimizer *minimizer)
72{
73 switch (likelihoodGradientMode) {
75#ifdef ROOFIT_MULTIPROCESS
76 return std::make_unique<LikelihoodGradientJob>(std::move(likelihood), std::move(calculationIsClean), nDim,
77 minimizer);
78#else
79 (void) likelihood;
80 (void) calculationIsClean;
81 (void) nDim;
82 (void) minimizer;
83 throw std::runtime_error("MinuitFcnGrad ctor with LikelihoodGradientMode::multiprocess is not available in this "
84 "build without RooFit::Multiprocess!");
85#endif
86 break;
87 }
88 default: {
89 throw std::logic_error("In MinuitFcnGrad constructor: likelihoodGradientMode has an unsupported value!");
90 }
91 }
92}
93
94} // namespace TestStatistics
95} // namespace RooFit
LikelihoodGradientWrapper(std::shared_ptr< RooAbsL > likelihood, std::shared_ptr< WrapperCalculationCleanFlags > calculation_is_clean, std::size_t N_dim, RooMinimizer *minimizer)
virtual void synchronizeWithMinimizer(const ROOT::Math::MinimizerOptions &options)
Synchronize minimizer settings with calculators in child classes.
virtual void updateMinuitInternalParameterValues(const std::vector< double > &minuit_internal_x)
Minuit passes in parameter values that may not conform to RooFit internal standards (like applying ra...
static std::unique_ptr< LikelihoodGradientWrapper > create(LikelihoodGradientMode likelihoodGradientMode, std::shared_ptr< RooAbsL > likelihood, std::shared_ptr< WrapperCalculationCleanFlags > calculationIsClean, std::size_t nDim, RooMinimizer *minimizer)
Factory method.
virtual void synchronizeParameterSettings(const std::vector< ROOT::Fit::ParameterSettings > &parameter_settings)
virtual void updateMinuitExternalParameterValues(const std::vector< double > &minuit_external_x)
Wrapper class around ROOT::Fit:Fitter that provides a seamless interface between the minimizer functi...
ROOT::Math::IMultiGenFunction * getMultiGenFcn() const
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26