Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // @(#)root/roostats:$Id$
0002 // Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
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_LikelihoodInterval
0012 #define RooStats_LikelihoodInterval
0013 
0014 #include "RooStats/ConfInterval.h"
0015 
0016 #include "RooArgSet.h"
0017 
0018 #include "RooAbsReal.h"
0019 
0020 #include "Math/IFunctionfwd.h"
0021 
0022 #include <map>
0023 #include <memory>
0024 #include <string>
0025 
0026 namespace ROOT {
0027    namespace Math {
0028       class Minimizer;
0029    }
0030 }
0031 
0032 namespace RooStats {
0033 
0034    class LikelihoodInterval : public ConfInterval {
0035 
0036    public:
0037 
0038       /// default constructor
0039       explicit LikelihoodInterval(const char *name = nullptr);
0040 
0041       //// construct the interval from a Profile Likelihood object, parameter of interest and optionally a snapshot of
0042       //// POI with their best fit values
0043       LikelihoodInterval(const char* name, RooAbsReal*, const RooArgSet*,  RooArgSet * = nullptr);
0044 
0045       /// destructor
0046       ~LikelihoodInterval() override;
0047 
0048       /// check if given point is in the interval
0049       bool IsInInterval(const RooArgSet&) const override;
0050 
0051       /// set the confidence level for the interval (e.g 0.682 for a 1-sigma interval)
0052       void SetConfidenceLevel(double cl) override {fConfidenceLevel = cl; ResetLimits(); }
0053 
0054       /// return confidence level
0055       double ConfidenceLevel() const override {return fConfidenceLevel;}
0056 
0057       /// return a cloned list of parameters of interest.  User manages the return object
0058        RooArgSet* GetParameters() const override;
0059 
0060       /// check if parameters are correct (i.e. they are the POI of this interval)
0061       bool CheckParameters(const RooArgSet&) const override ;
0062 
0063 
0064       /// return the lower bound of the interval on a given parameter
0065       double LowerLimit(const RooRealVar& param) { bool ok; return LowerLimit(param,ok); }
0066       double LowerLimit(const RooRealVar& param, bool & status) ;
0067 
0068       /// return the upper bound of the interval on a given parameter
0069       double UpperLimit(const RooRealVar& param) { bool ok; return UpperLimit(param,ok); }
0070       double UpperLimit(const RooRealVar& param, bool & status) ;
0071 
0072       /// find both lower and upper interval boundaries for a given parameter
0073       /// return false if the bounds have not been found
0074       bool FindLimits(const RooRealVar & param, double & lower, double &upper);
0075 
0076       /// return the 2D-contour points for the given subset of parameters
0077       /// by default make the contour using 30 points. The User has to preallocate the x and y array which will return
0078       /// the set of x and y points defining the contour.
0079       /// The return value of the function specify the number of contour point found.
0080       /// In case of error a zero is returned
0081       Int_t GetContourPoints(const RooRealVar & paramX, const RooRealVar & paramY, double * x, double *y, Int_t npoints = 30);
0082 
0083       /// return the profile log-likelihood ratio function
0084       RooAbsReal* GetLikelihoodRatio() {return fLikelihoodRatio;}
0085 
0086       /// return a pointer to a snapshot with best fit parameter of interest
0087       const RooArgSet * GetBestFitParameters() const { return fBestFitParams; }
0088 
0089    protected:
0090 
0091       /// reset the cached limit values
0092       void ResetLimits();
0093 
0094       /// internal function to create the minimizer for finding the contours
0095       bool CreateMinimizer();
0096 
0097    private:
0098 
0099       RooArgSet   fParameters;      ///< parameters of interest for this interval
0100       RooArgSet * fBestFitParams;   ///< snapshot of the model parameters with best fit value (managed internally)
0101       RooAbsReal* fLikelihoodRatio; ///< likelihood ratio function used to make contours (managed internally)
0102       double fConfidenceLevel;    ///< Requested confidence level (eg. 0.95 for 95% CL)
0103       std::map<std::string, double> fLowerLimits; ///< map with cached lower bound values
0104       std::map<std::string, double> fUpperLimits; ///< map with cached upper bound values
0105       std::shared_ptr<ROOT::Math::Minimizer > fMinimizer;      ///<! transient pointer to minimizer class used to find limits and contour
0106       std::shared_ptr<RooFunctor>           fFunctor;          ///<! transient pointer to functor class used by the minimizer
0107       std::shared_ptr<ROOT::Math::IMultiGenFunction> fMinFunc; ///<! transient pointer to the minimization function
0108 
0109       ClassDefOverride(LikelihoodInterval,1)  // Concrete implementation of a ConfInterval based on a likelihood ratio
0110 
0111    };
0112 }
0113 
0114 #endif