File indexing completed on 2024-11-16 09:54: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 ProfileLikelihoodTestStat() {
0036
0037 fPdf = nullptr;
0038 fCachedBestFitParams = nullptr;
0039 fLastData = nullptr;
0040 fLimitType = twoSided;
0041 fSigned = false;
0042 fDetailedOutputWithErrorsAndPulls = false;
0043 fDetailedOutputEnabled = false;
0044 fDetailedOutput = nullptr;
0045 fLOffset = RooStats::IsNLLOffset() ;
0046
0047 fVarName = "Profile Likelihood Ratio";
0048 fReuseNll = false;
0049 fStrategy=::ROOT::Math::MinimizerOptions::DefaultStrategy();
0050 fTolerance=TMath::Max(1.,::ROOT::Math::MinimizerOptions::DefaultTolerance());
0051 fPrintLevel=::ROOT::Math::MinimizerOptions::DefaultPrintLevel();
0052 }
0053
0054 ProfileLikelihoodTestStat(RooAbsPdf& pdf) {
0055 fPdf = &pdf;
0056 fCachedBestFitParams = nullptr;
0057 fLastData = nullptr;
0058 fLimitType = twoSided;
0059 fSigned = false;
0060 fDetailedOutputWithErrorsAndPulls = false;
0061 fDetailedOutputEnabled = false;
0062 fDetailedOutput = nullptr;
0063 fLOffset = RooStats::IsNLLOffset() ;
0064
0065 fVarName = "Profile Likelihood Ratio";
0066 fReuseNll = false;
0067 fStrategy=::ROOT::Math::MinimizerOptions::DefaultStrategy();
0068
0069 fTolerance=TMath::Max(1.,::ROOT::Math::MinimizerOptions::DefaultTolerance());
0070 fPrintLevel=::ROOT::Math::MinimizerOptions::DefaultPrintLevel();
0071 }
0072
0073 ~ProfileLikelihoodTestStat() override {
0074 if(fCachedBestFitParams) delete fCachedBestFitParams;
0075 if(fDetailedOutput) delete fDetailedOutput;
0076 }
0077
0078 void SetOneSided(bool flag=true) {fLimitType = (flag ? oneSided : twoSided);}
0079 void SetOneSidedDiscovery(bool flag=true) {fLimitType = (flag ? oneSidedDiscovery : twoSided);}
0080 void SetSigned(bool flag=true) {fSigned = flag;}
0081
0082 bool IsTwoSided() const { return fLimitType == twoSided; }
0083 bool IsOneSidedDiscovery() const { return fLimitType == oneSidedDiscovery; }
0084
0085 static void SetAlwaysReuseNLL(bool flag);
0086
0087 void SetReuseNLL(bool flag) { fReuseNll = flag ; }
0088 void SetLOffset(bool flag=true) { fLOffset = flag ; }
0089
0090 void SetMinimizer(const char* minimizer){ fMinimizer=minimizer;}
0091 void SetStrategy(Int_t strategy){fStrategy=strategy;}
0092 void SetTolerance(double tol){fTolerance=tol;}
0093 void SetPrintLevel(Int_t printlevel){fPrintLevel=printlevel;}
0094
0095
0096 double Evaluate(RooAbsData& data, RooArgSet& paramsOfInterest) override {
0097 return EvaluateProfileLikelihood(0, data, paramsOfInterest);
0098 }
0099
0100
0101 virtual double EvaluateProfileLikelihood(int type, RooAbsData &data, RooArgSet & paramsOfInterest);
0102
0103 virtual void EnableDetailedOutput( bool e=true, bool withErrorsAndPulls=false ) {
0104 fDetailedOutputEnabled = e;
0105 fDetailedOutputWithErrorsAndPulls = withErrorsAndPulls;
0106 delete fDetailedOutput;
0107 fDetailedOutput = nullptr;
0108 }
0109
0110
0111
0112
0113
0114
0115 const RooArgSet* GetDetailedOutput(void) const override {
0116 return fDetailedOutput;
0117 }
0118
0119
0120
0121 void SetConditionalObservables(const RooArgSet& set) override {fConditionalObs.removeAll(); fConditionalObs.add(set);}
0122
0123
0124
0125 void SetGlobalObservables(const RooArgSet& set) override {fGlobalObs.removeAll(); fGlobalObs.add(set);}
0126
0127 virtual void SetVarName(const char* name) { fVarName = name; }
0128 const TString GetVarName() const override {return fVarName;}
0129
0130 virtual RooAbsPdf * GetPdf() const { return fPdf; }
0131
0132 private:
0133
0134 std::unique_ptr<RooFitResult> GetMinNLL();
0135
0136 private:
0137
0138 RooAbsPdf* fPdf;
0139 std::unique_ptr<RooAbsReal> fNll;
0140 const RooArgSet* fCachedBestFitParams;
0141 RooAbsData* fLastData;
0142
0143 LimitType fLimitType;
0144 bool fSigned;
0145
0146
0147
0148 bool fDetailedOutputEnabled;
0149 bool fDetailedOutputWithErrorsAndPulls;
0150 RooArgSet* fDetailedOutput;
0151 RooArgSet fConditionalObs;
0152 RooArgSet fGlobalObs;
0153
0154 TString fVarName;
0155
0156 static bool fgAlwaysReuseNll ;
0157 bool fReuseNll ;
0158 TString fMinimizer;
0159 Int_t fStrategy;
0160 double fTolerance;
0161 Int_t fPrintLevel;
0162 bool fLOffset ;
0163
0164 protected:
0165
0166 ClassDefOverride(ProfileLikelihoodTestStat,10)
0167 };
0168 }
0169
0170
0171 #endif