Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-16 09:54:50

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_DebuggingSampler
0012 #define ROOSTATS_DebuggingSampler
0013 
0014 /** \class DebuggingSampler
0015     \ingroup Roostats
0016 
0017 DebuggingSampler is a simple implementation of the DistributionCreator interface used for debugging.
0018 The sampling distribution is uniformly random between [0,1] and is INDEPENDENT of the data.  So it is not useful
0019 for true statistical tests, but it is useful for debugging.
0020 
0021 */
0022 
0023 #include "Rtypes.h"
0024 
0025 #include <vector>
0026 
0027 #include "RooStats/TestStatSampler.h"
0028 #include "RooStats/SamplingDistribution.h"
0029 
0030 #include "RooRealVar.h"
0031 #include "TRandom.h"
0032 
0033 namespace RooStats {
0034 
0035  class DebuggingSampler: public TestStatSampler {
0036 
0037    public:
0038      DebuggingSampler() {
0039        fTestStatistic = new RooRealVar("UniformTestStatistic","UniformTestStatistic",0,0,1);
0040        fRand = new TRandom();
0041      }
0042      ~DebuggingSampler() override {
0043        delete fRand;
0044        delete fTestStatistic;
0045      }
0046 
0047      /// Main interface to get a ConfInterval, pure virtual
0048      SamplingDistribution* GetSamplingDistribution(RooArgSet& paramsOfInterest) override  {
0049        (void)paramsOfInterest; // avoid warning
0050        // normally this method would be complex, but here it is simple for debugging
0051        std::vector<double> testStatVec;
0052        testStatVec.reserve(1000);
0053 for(Int_t i=0; i<1000; ++i){
0054     testStatVec.push_back( fRand->Uniform() );
0055        }
0056        return new SamplingDistribution("UniformSamplingDist", "for debugging", testStatVec );
0057      }
0058 
0059      /// Main interface to evaluate the test statistic on a dataset
0060      double EvaluateTestStatistic(RooAbsData& /*data*/, RooArgSet& /*paramsOfInterest*/) override  {
0061        //       data = data; // avoid warning
0062        //       paramsOfInterest = paramsOfInterest; // avoid warning
0063        return fRand->Uniform();
0064      }
0065 
0066       /// Get the TestStatistic
0067       TestStatistic* GetTestStatistic()  const override {
0068          std::cout << "GetTestStatistic() IS NOT IMPLEMENTED FOR THIS SAMPLER. Returning nullptr." << std::endl;
0069          return nullptr; /*fTestStatistic;*/
0070       }
0071 
0072       /// Get the Confidence level for the test
0073       double ConfidenceLevel()  const override {return 1.-fSize;}
0074 
0075       /// Common Initialization
0076       void Initialize(RooAbsArg& /* testStatistic */, RooArgSet& /* paramsOfInterest */, RooArgSet& /* nuisanceParameters */ ) override {
0077       }
0078 
0079       /// Set the Pdf, add to the workspace if not already there
0080       void SetPdf(RooAbsPdf&) override {}
0081 
0082       /// specify the parameters of interest in the interval
0083       virtual void SetParameters(RooArgSet&) {}
0084       /// specify the nuisance parameters (eg. the rest of the parameters)
0085       void SetNuisanceParameters(const RooArgSet&) override {}
0086       /// specify the values of parameters used when evaluating test statistic
0087       void SetParametersForTestStat(const RooArgSet& ) override {}
0088       /// specify the conditional observables
0089       void SetGlobalObservables(const RooArgSet& ) override {}
0090 
0091 
0092       /// set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
0093       void SetTestSize(double size) override {fSize = size;}
0094       /// set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
0095       void SetConfidenceLevel(double cl) override {fSize = 1.-cl;}
0096 
0097       /// Set the TestStatistic (want the argument to be a function of the data & parameter points
0098       void SetTestStatistic(TestStatistic* /*testStatistic*/) override {
0099          std::cout << "SetTestStatistic(...) IS NOT IMPLEMENTED FOR THIS SAMPLER" << std::endl;
0100       }
0101 
0102    private:
0103       double fSize;
0104       RooRealVar* fTestStatistic;
0105       TRandom* fRand;
0106 
0107    protected:
0108       ClassDefOverride(DebuggingSampler,1)   // A simple implementation of the DistributionCreator interface
0109    };
0110 }
0111 
0112 
0113 #endif