Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:45

0001 // @(#)root/roostats:$Id$
0002 // Authors: Kyle Cranmer, Sven Kreiss    June 2010
0003 /*************************************************************************
0004  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
0005  * All rights reserved.                                                  *
0006  *                                                                       *
0007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0009  *************************************************************************/
0010 
0011 #ifndef ROOSTATS_RatioOfProfiledLikelihoodsTestStat
0012 #define ROOSTATS_RatioOfProfiledLikelihoodsTestStat
0013 
0014 
0015 #include "Rtypes.h"
0016 
0017 #include "RooStats/TestStatistic.h"
0018 
0019 #include "RooStats/ProfileLikelihoodTestStat.h"
0020 
0021 
0022 namespace RooStats {
0023 
0024    class RatioOfProfiledLikelihoodsTestStat: public TestStatistic {
0025 
0026    public:
0027 
0028       RatioOfProfiledLikelihoodsTestStat(RooAbsPdf& nullPdf, RooAbsPdf& altPdf,
0029                                          const RooArgSet* altPOI=nullptr) :
0030          fNullProfile(nullPdf),
0031          fAltProfile(altPdf),
0032          fSubtractMLE(true),
0033          fDetailedOutputEnabled(false),
0034          fDetailedOutput(nullptr)
0035       {
0036          //  Calculates the ratio of profiled likelihoods.
0037 
0038          if (altPOI) {
0039             fAltPOI = (RooArgSet*) altPOI->snapshot();
0040          } else {
0041             fAltPOI = new RooArgSet(); // empty set
0042          }
0043       }
0044 
0045       //__________________________________________
0046       ~RatioOfProfiledLikelihoodsTestStat(void) override {
0047          if(fAltPOI) delete fAltPOI;
0048          if(fDetailedOutput) delete fDetailedOutput;
0049       }
0050 
0051 
0052       /// returns -logL(poi, conditional MLE of nuisance params)
0053       /// it does not subtract off the global MLE
0054       /// because  nuisance parameters of null and alternate may not
0055       /// be the same.
0056       double ProfiledLikelihood(RooAbsData& data, RooArgSet& poi, RooAbsPdf& pdf);
0057 
0058       /// evaluate the ratio of profile likelihood
0059       double Evaluate(RooAbsData& data, RooArgSet& nullParamsOfInterest) override;
0060 
0061       virtual void EnableDetailedOutput( bool e=true ) {
0062          fDetailedOutputEnabled = e;
0063          fNullProfile.EnableDetailedOutput(fDetailedOutputEnabled);
0064          fAltProfile.EnableDetailedOutput(fDetailedOutputEnabled);
0065       }
0066 
0067       static void SetAlwaysReuseNLL(bool flag);
0068 
0069       void SetReuseNLL(bool flag) {
0070          fNullProfile.SetReuseNLL(flag);
0071          fAltProfile.SetReuseNLL(flag);
0072       }
0073 
0074       void SetMinimizer(const char* minimizer){
0075          fNullProfile.SetMinimizer(minimizer);
0076          fAltProfile.SetMinimizer(minimizer);
0077       }
0078       void SetStrategy(Int_t strategy){
0079          fNullProfile.SetStrategy(strategy);
0080          fAltProfile.SetStrategy(strategy);
0081       }
0082       void SetTolerance(double tol){
0083          fNullProfile.SetTolerance(tol);
0084          fAltProfile.SetTolerance(tol);
0085       }
0086       void SetPrintLevel(Int_t printLevel){
0087          fNullProfile.SetPrintLevel(printLevel);
0088          fAltProfile.SetPrintLevel(printLevel);
0089       }
0090 
0091       /// set the conditional observables which will be used when creating the NLL
0092       /// so the pdf's will not be normalized on the conditional observables when computing the NLL
0093       void SetConditionalObservables(const RooArgSet& set) override {
0094          fNullProfile.SetConditionalObservables(set);
0095          fAltProfile.SetConditionalObservables(set);
0096       }
0097 
0098       /// set the global observables which will be used when creating the NLL
0099       /// so the constraint pdf's will be normalized correctly on the global observables when computing the NLL
0100       void SetGlobalObservables(const RooArgSet& set) override {
0101          fNullProfile.SetGlobalObservables(set);
0102          fAltProfile.SetGlobalObservables(set);
0103       }
0104 
0105       /// Returns detailed output. The value returned by this function is updated after each call to Evaluate().
0106       /// The returned RooArgSet contains the following for the alternative and null hypotheses:
0107       ///  - the minimum nll, fitstatus and convergence quality for each fit
0108       ///  - for each fit and for each non-constant parameter, the value, error and pull of the parameter are stored
0109       const RooArgSet* GetDetailedOutput(void) const override {
0110          return fDetailedOutput;
0111       }
0112 
0113 
0114 
0115 
0116       const TString GetVarName() const override { return "log(L(#mu_{1},#hat{#nu}_{1}) / L(#mu_{0},#hat{#nu}_{0}))"; }
0117 
0118       //    const bool PValueIsRightTail(void) { return false; } // overwrites default
0119 
0120       void SetSubtractMLE(bool subtract){fSubtractMLE = subtract;}
0121 
0122    private:
0123 
0124       ProfileLikelihoodTestStat fNullProfile;
0125       ProfileLikelihoodTestStat fAltProfile;
0126 
0127       RooArgSet* fAltPOI;
0128       bool fSubtractMLE;
0129       static bool fgAlwaysReuseNll ;
0130 
0131       bool fDetailedOutputEnabled;
0132       RooArgSet* fDetailedOutput;
0133 
0134       ClassDefOverride(RatioOfProfiledLikelihoodsTestStat,0)  // implements the ratio of profiled likelihood as test statistic
0135    };
0136 
0137 }
0138 
0139 
0140 #endif