File indexing completed on 2025-01-18 10:10:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT_ROOFIT_TESTSTATISTICS_LikelihoodWrapper
0014 #define ROOT_ROOFIT_TESTSTATISTICS_LikelihoodWrapper
0015
0016 #include "RooFit/TestStatistics/SharedOffset.h"
0017
0018 #include "RooArgSet.h"
0019 #include "RooAbsArg.h" // enum ConstOpCode
0020
0021 #include <Fit/ParameterSettings.h>
0022 #include <Math/MinimizerOptions.h>
0023 #include <Math/Util.h>
0024
0025 #include <memory> // shared_ptr
0026 #include <string>
0027
0028
0029 class RooMinimizer;
0030
0031 namespace RooFit {
0032 namespace TestStatistics {
0033
0034
0035 class RooAbsL;
0036
0037
0038
0039 struct WrapperCalculationCleanFlags {
0040
0041 bool likelihood = false;
0042 bool gradient = false;
0043
0044 void set_all(bool value)
0045 {
0046 likelihood = value;
0047 gradient = value;
0048 }
0049 };
0050
0051 enum class LikelihoodType { unbinned, binned, subsidiary, sum };
0052
0053 enum class LikelihoodMode { serial, multiprocess };
0054
0055
0056
0057
0058
0059 enum class OffsettingMode { legacy, full };
0060
0061 class LikelihoodWrapper {
0062 protected:
0063 LikelihoodWrapper(std::shared_ptr<RooAbsL> likelihood,
0064 std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean, SharedOffset offset);
0065
0066 public:
0067 virtual ~LikelihoodWrapper() = default;
0068 LikelihoodWrapper(const LikelihoodWrapper &) = delete;
0069 LikelihoodWrapper &operator=(const LikelihoodWrapper &) = delete;
0070
0071 static std::unique_ptr<LikelihoodWrapper> create(LikelihoodMode likelihoodMode, std::shared_ptr<RooAbsL> likelihood,
0072 std::shared_ptr<WrapperCalculationCleanFlags> calculationIsClean,
0073 SharedOffset offset);
0074
0075
0076
0077
0078
0079
0080 virtual void evaluate() = 0;
0081
0082
0083
0084
0085 virtual ROOT::Math::KahanSum<double> getResult() const = 0;
0086
0087
0088 virtual void synchronizeWithMinimizer(const ROOT::Math::MinimizerOptions &options);
0089 virtual void synchronizeParameterSettings(const std::vector<ROOT::Fit::ParameterSettings> ¶meter_settings);
0090
0091
0092
0093 virtual void updateMinuitInternalParameterValues(const std::vector<double> &minuit_internal_x);
0094 virtual void updateMinuitExternalParameterValues(const std::vector<double> &minuit_external_x);
0095
0096
0097 void constOptimizeTestStatistic(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt);
0098 double defaultErrorLevel() const;
0099 virtual std::string GetName() const;
0100 virtual std::string GetTitle() const;
0101 inline virtual bool isOffsetting() const { return do_offset_; }
0102 virtual void enableOffsetting(bool flag);
0103 void setOffsettingMode(OffsettingMode mode);
0104 void setApplyWeightSquared(bool flag);
0105
0106 protected:
0107 std::shared_ptr<RooAbsL> likelihood_;
0108 LikelihoodType likelihood_type_;
0109 std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean_;
0110
0111 bool do_offset_ = false;
0112 SharedOffset shared_offset_;
0113 void calculate_offsets();
0114 OffsettingMode offsetting_mode_ = OffsettingMode::legacy;
0115 };
0116
0117 }
0118 }
0119
0120 #endif