Back to home page

EIC code displayed by LXR

 
 

    


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

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_CombinedCalculator
0012 #define ROOSTATS_CombinedCalculator
0013 
0014 
0015 #include "RooStats/IntervalCalculator.h"
0016 
0017 #include "RooStats/HypoTestCalculator.h"
0018 
0019 #include "RooStats/ModelConfig.h"
0020 
0021 #include "RooAbsPdf.h"
0022 
0023 #include "RooAbsData.h"
0024 
0025 #include "RooArgSet.h"
0026 
0027 // #ifndef ROO_WORKSPACE
0028 // #include "RooWorkspace.h"
0029 // #endif
0030 
0031 namespace RooStats {
0032 
0033 /** \class CombinedCalculator
0034    \ingroup Roostats
0035 
0036 CombinedCalculator is an interface class for a tools which can produce both RooStats
0037 HypoTestResults and ConfIntervals. The interface currently assumes that any such
0038 calculator can be configured by specifying:
0039 
0040   - a model common model (eg. a family of specific models which includes both the null and alternate),
0041   - a data set,
0042   - a set of parameters of which specify the null (including values and const/non-const status),
0043   - a set of parameters of which specify the alternate (including values and const/non-const status),
0044   - a set of parameters of nuisance parameters (including values and const/non-const status).
0045 
0046 The interface allows one to pass the model, data, and parameters via a workspace
0047 and then specify them with names. The interface also allows one to pass the model,
0048 data, and parameters without a workspace (which is created internally).
0049 
0050 After configuring the calculator, one only needs to ask GetHypoTest() (which will
0051 return a HypoTestResult pointer) or GetInterval() (which will return an ConfInterval pointer).
0052 
0053 The concrete implementations of this interface should deal with the details of how
0054 the nuisance parameters are dealt with (eg. integration vs. profiling) and which test-statistic is used (perhaps this should be added to the interface).
0055 
0056 The motivation for this interface is that we hope to be able to specify the problem
0057 in a common way for several concrete calculators.
0058 
0059 */
0060 
0061 
0062    class CombinedCalculator : public IntervalCalculator, public HypoTestCalculator {
0063 
0064    public:
0065 
0066       CombinedCalculator() = default;
0067 
0068       CombinedCalculator(RooAbsData& data, RooAbsPdf& pdf, const RooArgSet& paramsOfInterest,
0069                          double size = 0.05, const RooArgSet* nullParams = nullptr, const RooArgSet* altParams = nullptr, const RooArgSet* nuisParams = nullptr) :
0070 
0071          fPdf(&pdf),
0072          fData(&data),
0073          fPOI(paramsOfInterest)
0074       {
0075          if (nullParams) fNullParams.add(*nullParams);
0076          if (altParams) fAlternateParams.add(*altParams);
0077          if (nuisParams) fNuisParams.add(*nuisParams);
0078          SetTestSize(size);
0079       }
0080 
0081       /// constructor from data and model configuration
0082       CombinedCalculator(RooAbsData& data, const ModelConfig& model,
0083                          double size = 0.05) :
0084          fPdf(nullptr),
0085          fData(&data)
0086       {
0087          SetModel(model);
0088          SetTestSize(size);
0089       }
0090 
0091       /// Main interface to get a ConfInterval, pure virtual
0092       ConfInterval* GetInterval() const override = 0;
0093       /// main interface to get a HypoTestResult, pure virtual
0094       HypoTestResult* GetHypoTest() const override = 0;
0095 
0096       /// set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
0097       void SetTestSize(double size) override {fSize = size;}
0098       /// set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
0099       void SetConfidenceLevel(double cl) override {fSize = 1.-cl;}
0100       /// Get the size of the test (eg. rate of Type I error)
0101       double Size() const override {return fSize;}
0102       /// Get the Confidence level for the test
0103       double ConfidenceLevel()  const override {return 1.-fSize;}
0104 
0105       /// Set the DataSet, add to the workspace if not already there
0106       void SetData(RooAbsData & data) override {
0107          fData = &data;
0108       }
0109 
0110       /// set the model (in this case can set only the parameters for the null hypothesis)
0111       void SetModel(const ModelConfig & model) override {
0112          fPdf = model.GetPdf();
0113          if (model.GetParametersOfInterest()) SetParameters(*model.GetParametersOfInterest());
0114          if (model.GetSnapshot()) SetNullParameters(*model.GetSnapshot());
0115          if (model.GetNuisanceParameters()) SetNuisanceParameters(*model.GetNuisanceParameters());
0116          if (model.GetConditionalObservables()) SetConditionalObservables(*model.GetConditionalObservables());
0117          if (model.GetGlobalObservables()) SetGlobalObservables(*model.GetGlobalObservables());
0118       }
0119 
0120       void SetNullModel( const ModelConfig &) override {  // to be understood what to do
0121       }
0122       void SetAlternateModel(const ModelConfig &) override {  // to be understood what to do
0123       }
0124 
0125       /* specific setting - keep for convenience-  some of them could be removed */
0126 
0127       /// Set the Pdf
0128       virtual void SetPdf(RooAbsPdf& pdf) { fPdf = &pdf; }
0129 
0130       /// specify the parameters of interest in the interval
0131       virtual void SetParameters(const RooArgSet& set) { fPOI.removeAll(); fPOI.add(set); }
0132 
0133        /// specify the nuisance parameters (eg. the rest of the parameters)
0134       virtual void SetNuisanceParameters(const RooArgSet& set) {fNuisParams.removeAll(); fNuisParams.add(set);}
0135 
0136       /// set parameter values for the null if using a common PDF
0137       virtual void SetNullParameters(const RooArgSet& set) {fNullParams.removeAll(); fNullParams.add(set);}
0138 
0139       /// set parameter values for the alternate if using a common PDF
0140       virtual void SetAlternateParameters(const RooArgSet& set) {fAlternateParams.removeAll(); fAlternateParams.add(set);}
0141 
0142       /// set conditional observables needed for computing the NLL
0143       virtual void SetConditionalObservables(const RooArgSet& set) {fConditionalObs.removeAll(); fConditionalObs.add(set);}
0144 
0145        /// set global observables needed for computing the NLL
0146       virtual void SetGlobalObservables(const RooArgSet& set) {fGlobalObs.removeAll(); fGlobalObs.add(set);}
0147 
0148 
0149    protected:
0150 
0151       RooAbsPdf * GetPdf() const { return fPdf; }
0152       RooAbsData * GetData() const { return fData; }
0153 
0154       double fSize = 0.0; ///< size of the test (eg. specified rate of Type I error)
0155 
0156       RooAbsPdf  * fPdf = nullptr;
0157       RooAbsData * fData = nullptr;
0158       RooArgSet fPOI;             ///< RooArgSet specifying parameters of interest for interval
0159       RooArgSet fNullParams;      ///< RooArgSet specifying null parameters for hypothesis test
0160       RooArgSet fAlternateParams; ///< RooArgSet specifying alternate parameters for hypothesis test
0161       RooArgSet fNuisParams;      ///< RooArgSet specifying nuisance parameters for interval
0162       RooArgSet fConditionalObs;  ///< RooArgSet specifying the conditional observables
0163       RooArgSet fGlobalObs;       ///< RooArgSet specifying the global observables
0164 
0165 
0166       ClassDefOverride(CombinedCalculator,2) // A base class that is for tools that can be both HypoTestCalculators and IntervalCalculators
0167 
0168    };
0169 }
0170 
0171 
0172 #endif