File indexing completed on 2025-09-12 09:09:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "Config.h"
0013
0014
0015
0016
0017 #ifdef XROOFIT_USE_PRAGMA_ONCE
0018 #pragma once
0019 #endif
0020 #if (!defined(XROOFIT_USE_PRAGMA_ONCE) && !defined(XROOFIT_XROOFIT_H)) || \
0021 (defined(XROOFIT_USE_PRAGMA_ONCE) && !defined(XROOFIT_XROOFIT_H_XROOFIT))
0022 #ifndef XROOFIT_USE_PRAGMA_ONCE
0023 #define XROOFIT_XROOFIT_H
0024 #else
0025 #define XROOFIT_XROOFIT_H_XROOFIT
0026
0027
0028
0029
0030
0031 #endif
0032
0033
0034
0035
0036
0037
0038 class RooAbsData;
0039 class RooAbsCollection;
0040 class RooFitResult;
0041 class RooAbsPdf;
0042 class RooAbsReal;
0043 class RooLinkedList;
0044 class RooWorkspace;
0045
0046 #include "Fit/FitConfig.h"
0047
0048 #include "RooCmdArg.h"
0049 #include "TNamed.h"
0050
0051 class TCanvas;
0052
0053 #include <memory>
0054
0055 BEGIN_XROOFIT_NAMESPACE
0056
0057 class xRooNLLVar;
0058
0059 class xRooFit {
0060
0061 public:
0062 static const char *GetVersion();
0063 static const char *GetVersionDate();
0064
0065
0066 static RooCmdArg ReuseNLL(bool flag);
0067 static RooCmdArg Tolerance(double value);
0068 static RooCmdArg StrategySequence(const char *stratSeq);
0069 static RooCmdArg MaxIterations(int nIterations);
0070
0071 static constexpr double OBS = std::numeric_limits<double>::quiet_NaN();
0072
0073
0074 static std::pair<double, double> matchPrecision(const std::pair<double, double> &in);
0075
0076
0077
0078
0079
0080
0081
0082
0083 static std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
0084 generateFrom(RooAbsPdf &pdf, const RooFitResult &fr, bool expected = false, int seed = 0);
0085 static std::shared_ptr<const RooFitResult>
0086 fitTo(RooAbsPdf &pdf, const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &data,
0087 const RooLinkedList &nllOpts, const ROOT::Fit::FitConfig &fitConf);
0088 static std::shared_ptr<const RooFitResult> fitTo(RooAbsPdf &pdf,
0089 const std::pair<RooAbsData *, const RooAbsCollection *> &data,
0090 const RooLinkedList &nllOpts, const ROOT::Fit::FitConfig &fitConf);
0091
0092 static xRooNLLVar createNLL(const std::shared_ptr<RooAbsPdf> pdf, const std::shared_ptr<RooAbsData> data,
0093 const RooLinkedList &nllOpts);
0094 static xRooNLLVar createNLL(RooAbsPdf &pdf, RooAbsData *data, const RooLinkedList &nllOpts);
0095 static xRooNLLVar createNLL(RooAbsPdf &pdf, RooAbsData *data, const RooCmdArg &arg1 = RooCmdArg::none(),
0096 const RooCmdArg &arg2 = RooCmdArg::none(), const RooCmdArg &arg3 = RooCmdArg::none(),
0097 const RooCmdArg &arg4 = RooCmdArg::none(), const RooCmdArg &arg5 = RooCmdArg::none(),
0098 const RooCmdArg &arg6 = RooCmdArg::none(), const RooCmdArg &arg7 = RooCmdArg::none(),
0099 const RooCmdArg &arg8 = RooCmdArg::none());
0100
0101 static std::shared_ptr<ROOT::Fit::FitConfig> createFitConfig();
0102 static std::shared_ptr<RooLinkedList> createNLLOptions();
0103 static std::shared_ptr<RooLinkedList> defaultNLLOptions();
0104 static std::shared_ptr<ROOT::Fit::FitConfig> defaultFitConfig();
0105 static ROOT::Math::IOptions *defaultFitConfigOptions();
0106
0107 static std::shared_ptr<const RooFitResult> minimize(RooAbsReal &nll,
0108 const std::shared_ptr<ROOT::Fit::FitConfig> &fitConfig = nullptr,
0109 const std::shared_ptr<RooLinkedList> &nllOpts = nullptr);
0110 static int minos(RooAbsReal &nll, const RooFitResult &ufit, const char *parName = "",
0111 const std::shared_ptr<ROOT::Fit::FitConfig> &_fitConfig = nullptr);
0112
0113
0114
0115 class StoredFitResult : public TNamed {
0116 public:
0117 StoredFitResult(RooFitResult *_fr);
0118 StoredFitResult(const std::shared_ptr<RooFitResult> &_fr);
0119
0120 public:
0121 std::shared_ptr<RooFitResult> fr;
0122 ClassDef(StoredFitResult, 0)
0123 };
0124
0125
0126 class TestStatistic {
0127 public:
0128 enum Type {
0129
0130 tmu = -1,
0131
0132 qmu = -2,
0133 qmutilde = -3,
0134
0135 q0 = -4,
0136 uncappedq0 = -5,
0137 u0 = -5
0138 };
0139 };
0140
0141 class Asymptotics {
0142
0143 public:
0144 typedef std::vector<std::pair<double, int>> IncompatFunc;
0145
0146 enum PLLType {
0147 TwoSided = 0,
0148 OneSidedPositive,
0149 OneSidedNegative,
0150 OneSidedAbsolute,
0151 Uncapped,
0152 Unknown
0153 };
0154
0155
0156
0157
0158
0159 static IncompatFunc IncompatibilityFunction(const PLLType &type, double mu)
0160 {
0161 std::vector<std::pair<double, int>> out;
0162 if (type == TwoSided) {
0163
0164 } else if (type == OneSidedPositive) {
0165 out.emplace_back(std::make_pair(mu, 0));
0166 } else if (type == OneSidedNegative) {
0167 out.emplace_back(std::make_pair(-std::numeric_limits<double>::infinity(), 0));
0168 out.emplace_back(std::make_pair(mu, 1));
0169 } else if (type == OneSidedAbsolute) {
0170 out.emplace_back(std::make_pair(-std::numeric_limits<double>::infinity(), 0));
0171 out.emplace_back(std::make_pair(-mu, 1));
0172 out.emplace_back(std::make_pair(mu, 0));
0173 } else if (type == Uncapped) {
0174 out.emplace_back(std::make_pair(-std::numeric_limits<double>::infinity(), -1));
0175 out.emplace_back(std::make_pair(mu, 1));
0176 } else {
0177 throw std::runtime_error("Unknown PLL Type");
0178 }
0179 return out;
0180 }
0181
0182
0183 static double k(const IncompatFunc &compatRegions, double pValue, double poiVal, double poiPrimeVal,
0184 double sigma_mu = 0, double mu_low = -std::numeric_limits<double>::infinity(),
0185 double mu_high = std::numeric_limits<double>::infinity());
0186
0187 static double k(const PLLType &pllType, double pValue, double mu, double mu_prime, double sigma_mu = 0,
0188 double mu_low = -std::numeric_limits<double>::infinity(),
0189 double mu_high = std::numeric_limits<double>::infinity())
0190 {
0191 return k(IncompatibilityFunction(pllType, mu), pValue, mu, mu_prime, sigma_mu, mu_low, mu_high);
0192 }
0193
0194
0195 static double PValue(const IncompatFunc &compatRegions, double k, double mu, double mu_prime, double sigma_mu = 0,
0196 double mu_low = -std::numeric_limits<double>::infinity(),
0197 double mu_high = std::numeric_limits<double>::infinity());
0198
0199 static double PValue(const PLLType &pllType, double k, double mu, double mu_prime, double sigma_mu = 0,
0200 double mu_low = -std::numeric_limits<double>::infinity(),
0201 double mu_high = std::numeric_limits<double>::infinity())
0202 {
0203 return PValue(IncompatibilityFunction(pllType, mu), k, mu, mu_prime, sigma_mu, mu_low, mu_high);
0204 }
0205
0206 static double Phi_m(double mu, double mu_prime, double a, double sigma, const IncompatFunc &compatRegions);
0207
0208 static int CompatFactor(const IncompatFunc &func, double mu_hat);
0209
0210 static int CompatFactor(int type, double mu, double mu_hat)
0211 {
0212 return CompatFactor(IncompatibilityFunction((PLLType)type, mu), mu_hat);
0213 }
0214
0215
0216
0217
0218 };
0219
0220 static std::shared_ptr<RooLinkedList> sDefaultNLLOptions;
0221 static std::shared_ptr<ROOT::Fit::FitConfig> sDefaultFitConfig;
0222
0223
0224
0225
0226
0227 static TCanvas *
0228 hypoTest(RooWorkspace &w, const xRooFit::Asymptotics::PLLType &pllType = xRooFit::Asymptotics::Unknown)
0229 {
0230 return hypoTest(w, 0, 0, pllType);
0231 }
0232 static TCanvas *hypoTest(RooWorkspace &w, int nToysNull, int nToysAlt,
0233 const xRooFit::Asymptotics::PLLType &pllType = xRooFit::Asymptotics::Unknown);
0234 };
0235
0236 END_XROOFIT_NAMESPACE
0237
0238 #include "xRooHypoSpace.h"
0239 #include "xRooNLLVar.h"
0240 #include "xRooNode.h"
0241
0242 #endif