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_NeymanConstruction
0012 #define ROOSTATS_NeymanConstruction
0013 
0014 
0015 #include "Rtypes.h"
0016 
0017 #include "RooStats/IntervalCalculator.h"
0018 
0019 #include "RooStats/TestStatSampler.h"
0020 #include "RooStats/ModelConfig.h"
0021 #include "RooStats/ConfidenceBelt.h"
0022 #include "RooStats/PointSetInterval.h"
0023 
0024 #include "RooAbsData.h"
0025 #include "RooAbsPdf.h"
0026 #include "RooArgSet.h"
0027 
0028 #include <map>
0029 
0030 class RooAbsData;
0031 
0032 namespace RooStats {
0033 
0034    class ConfInterval;
0035 
0036    class NeymanConstruction : public IntervalCalculator{
0037 
0038    public:
0039 
0040      NeymanConstruction(RooAbsData& data, ModelConfig& model);
0041 
0042      ~NeymanConstruction() override;
0043 
0044       /// Main interface to get a ConfInterval (will be a PointSetInterval)
0045      PointSetInterval* GetInterval() const override;
0046 
0047       /// in addition to interface we also need:
0048       /// Set the TestStatSampler (eg. ToyMC or FFT, includes choice of TestStatistic)
0049       void SetTestStatSampler(TestStatSampler& sampler) {fTestStatSampler = &sampler;}
0050       /// fLeftSideTailFraction*fSize defines lower edge of acceptance region.
0051       /// Unified limits use 0, central limits use 0.5,
0052       /// for upper/lower limits it is 0/1 depends on sign of test statistic w.r.t. parameter
0053       void SetLeftSideTailFraction(double leftSideFraction = 0.) {fLeftSideFraction = leftSideFraction;}
0054 
0055       /// User-defined set of points to test
0056       void SetParameterPointsToTest(RooAbsData& pointsToTest) {
0057    fPointsToTest = &pointsToTest;
0058         fConfBelt = new ConfidenceBelt("ConfBelt",pointsToTest);
0059       }
0060       /// This class can make regularly spaced scans based on range stored in RooRealVars.
0061       /// Choose number of steps for a rastor scan (common for each dimension)
0062       ///      void SetNumSteps(Int_t);
0063       /// This class can make regularly spaced scans based on range stored in RooRealVars.
0064       /// Choose number of steps for a rastor scan (specific for each dimension)
0065       ///      void SetNumSteps(std::map<RooAbsArg, Int_t>)
0066 
0067       /// Get the size of the test (eg. rate of Type I error)
0068       double Size() const override {return fSize;}
0069 
0070       /// Get the Confidence level for the test
0071       double ConfidenceLevel()  const override {return 1.-fSize;}
0072 
0073       /// Set ModelConfig
0074       void SetModel(const ModelConfig &model) override {fModel = model;}
0075 
0076       /// Set the DataSet
0077       void SetData(RooAbsData& data) override { fData = data; }
0078 
0079       /// set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
0080       void SetTestSize(double size) override {fSize = size;}
0081       /// set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
0082       void SetConfidenceLevel(double cl) override {fSize = 1.-cl;}
0083 
0084       /// Get confidence belt. This requires that CreateConfBelt() has been called.
0085       ConfidenceBelt* GetConfidenceBelt() {return fCreateBelt ? fConfBelt : nullptr;}
0086 
0087       /// adaptive sampling algorithm to speed up interval calculation
0088       void UseAdaptiveSampling(bool flag=true){fAdaptiveSampling=flag;}
0089 
0090       /// give user ability to ask for more toys
0091       void AdditionalNToysFactor(double fact){fAdditionalNToysFactor = fact;}
0092 
0093       /// save the confidence belt to a file
0094       void SaveBeltToFile(bool flag=true){
0095          fSaveBeltToFile = flag;
0096          if(flag) fCreateBelt = true;
0097       }
0098       /// should create confidence belt
0099       void CreateConfBelt(bool flag=true){fCreateBelt = flag;}
0100 
0101       /// Returns instance of TestStatSampler. Use to change properties of
0102       /// TestStatSampler, e.g. GetTestStatSampler.SetTestSize(double size);
0103       TestStatSampler* GetTestStatSampler(void) { return fTestStatSampler; }
0104 
0105 
0106    private:
0107 
0108       double fSize;    ///< size of the test (eg. specified rate of Type I error)
0109       RooAbsData& fData; ///< data set
0110       ModelConfig &fModel;
0111 
0112       TestStatSampler* fTestStatSampler;
0113       RooAbsData* fPointsToTest;
0114       double fLeftSideFraction;
0115       ConfidenceBelt* fConfBelt;
0116       bool fAdaptiveSampling;          ///< controls use of adaptive sampling algorithm
0117       double fAdditionalNToysFactor; ///< give user ability to ask for more toys
0118       bool fSaveBeltToFile;            ///< controls use if ConfidenceBelt should be saved to a TFile
0119       bool fCreateBelt;                ///< controls use if ConfidenceBelt should be saved to a TFile
0120 
0121    protected:
0122       ClassDefOverride(NeymanConstruction,0)   ///< Interface for tools setting limits (producing confidence intervals)
0123    };
0124 }
0125 
0126 
0127 #endif