File indexing completed on 2025-07-11 08:44:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOSTATS_ProfileLikelihoodTestStat
0013 #define ROOSTATS_ProfileLikelihoodTestStat
0014
0015
0016 #include "Rtypes.h"
0017
0018 #include "RooStats/TestStatistic.h"
0019
0020
0021 #include "RooRealVar.h"
0022
0023 #include "Math/MinimizerOptions.h"
0024
0025 #include "RooStats/RooStatsUtils.h"
0026
0027
0028 namespace RooStats {
0029
0030 class ProfileLikelihoodTestStat : public TestStatistic{
0031
0032 enum LimitType {twoSided, oneSided, oneSidedDiscovery};
0033
0034 public:
0035
0036 ProfileLikelihoodTestStat()
0037 : fStrategy(::ROOT::Math::MinimizerOptions::DefaultStrategy()),
0038 fTolerance(std::max(1., ::ROOT::Math::MinimizerOptions::DefaultTolerance())),
0039 fPrintLevel(::ROOT::Math::MinimizerOptions::DefaultPrintLevel()),
0040 fLOffset(RooStats::IsNLLOffset())
0041 {
0042 }
0043
0044 ProfileLikelihoodTestStat(RooAbsPdf &pdf)
0045 : fPdf(&pdf),
0046 fStrategy(::ROOT::Math::MinimizerOptions::DefaultStrategy()),
0047 fTolerance(std::max(1., ::ROOT::Math::MinimizerOptions::DefaultTolerance())),
0048 fPrintLevel(::ROOT::Math::MinimizerOptions::DefaultPrintLevel()),
0049 fLOffset(RooStats::IsNLLOffset())
0050 {
0051
0052 }
0053
0054 ~ProfileLikelihoodTestStat() override {
0055 if(fCachedBestFitParams) delete fCachedBestFitParams;
0056 }
0057
0058 void SetOneSided(bool flag=true) {fLimitType = (flag ? oneSided : twoSided);}
0059 void SetOneSidedDiscovery(bool flag=true) {fLimitType = (flag ? oneSidedDiscovery : twoSided);}
0060 void SetSigned(bool flag=true) {fSigned = flag;}
0061
0062 bool IsTwoSided() const { return fLimitType == twoSided; }
0063 bool IsOneSidedDiscovery() const { return fLimitType == oneSidedDiscovery; }
0064
0065 static void SetAlwaysReuseNLL(bool flag);
0066
0067 void SetReuseNLL(bool flag) { fReuseNll = flag ; }
0068 void SetLOffset(bool flag=true) { fLOffset = flag ; }
0069
0070 void SetMinimizer(const char* minimizer){ fMinimizer=minimizer;}
0071 void SetStrategy(Int_t strategy){fStrategy=strategy;}
0072 void SetTolerance(double tol){fTolerance=tol;}
0073 void SetPrintLevel(Int_t printlevel){fPrintLevel=printlevel;}
0074
0075
0076 double Evaluate(RooAbsData& data, RooArgSet& paramsOfInterest) override {
0077 return EvaluateProfileLikelihood(0, data, paramsOfInterest);
0078 }
0079
0080
0081 virtual double EvaluateProfileLikelihood(int type, RooAbsData &data, RooArgSet & paramsOfInterest);
0082
0083 virtual void EnableDetailedOutput( bool e=true, bool withErrorsAndPulls=false ) {
0084 fDetailedOutputEnabled = e;
0085 fDetailedOutputWithErrorsAndPulls = withErrorsAndPulls;
0086 fDetailedOutput = nullptr;
0087 }
0088
0089
0090
0091
0092
0093
0094 const RooArgSet* GetDetailedOutput(void) const override {
0095 return fDetailedOutput.get();
0096 }
0097
0098
0099
0100 void SetConditionalObservables(const RooArgSet& set) override {fConditionalObs.removeAll(); fConditionalObs.add(set);}
0101
0102
0103
0104 void SetGlobalObservables(const RooArgSet& set) override {fGlobalObs.removeAll(); fGlobalObs.add(set);}
0105
0106 virtual void SetVarName(const char* name) { fVarName = name; }
0107 const TString GetVarName() const override {return fVarName;}
0108
0109 virtual RooAbsPdf * GetPdf() const { return fPdf; }
0110
0111 private:
0112
0113 std::unique_ptr<RooFitResult> GetMinNLL();
0114
0115 RooAbsPdf* fPdf = nullptr;
0116 std::unique_ptr<RooAbsReal> fNll;
0117 const RooArgSet* fCachedBestFitParams = nullptr;
0118 RooAbsData* fLastData = nullptr;
0119 LimitType fLimitType = twoSided;
0120 bool fSigned = false;
0121
0122
0123
0124 bool fDetailedOutputEnabled = false;
0125 bool fDetailedOutputWithErrorsAndPulls = false;
0126 std::unique_ptr<RooArgSet> fDetailedOutput;
0127 RooArgSet fConditionalObs;
0128 RooArgSet fGlobalObs;
0129
0130 TString fVarName = "Profile Likelihood Ratio";
0131
0132 static bool fgAlwaysReuseNll ;
0133 bool fReuseNll = false;
0134 TString fMinimizer;
0135 Int_t fStrategy;
0136 double fTolerance;
0137 Int_t fPrintLevel;
0138 bool fLOffset ;
0139
0140 protected:
0141
0142 ClassDefOverride(ProfileLikelihoodTestStat,10)
0143 };
0144 }
0145
0146
0147 #endif