HybridResult.cxx

Go to the documentation of this file.
00001 // @(#)root/roostats:$Id: HybridResult.cxx 35810 2010-09-27 20:05:22Z moneta $
00002 
00003 /*************************************************************************
00004  * Project: RooStats                                                     *
00005  * Package: RooFit/RooStats                                              *
00006  * Authors:                                                              *
00007  *   Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke       *
00008  *************************************************************************
00009  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00010  * All rights reserved.                                                  *
00011  *                                                                       *
00012  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00013  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00014  *************************************************************************/
00015 
00016 //____________________________________________________________________
00017 /*
00018 HybridResult class: this class is a fresh rewrite in RooStats of
00019         RooStatsCms/LimitResults developped by D. Piparo and G. Schott
00020 New contributions to this class have been written by Matthias Wolf (error estimation)
00021 
00022 The objects of this class store and access with lightweight methods the
00023 information calculated by LimitResults through a Lent calculation using
00024 MC toy experiments.
00025 In some ways can be considered an extended and extensible implementation of the
00026 TConfidenceLevel class (http://root.cern.ch/root/html/TConfidenceLevel.html).
00027 
00028 */
00029 
00030 #include "RooDataHist.h"
00031 #include "RooDataSet.h"
00032 #include "RooGlobalFunc.h" // for RooFit::Extended()
00033 #include "RooNLLVar.h"
00034 #include "RooRealVar.h"
00035 #include "RooAbsData.h"
00036 
00037 #include "RooStats/HybridResult.h"
00038 #include "RooStats/HybridPlot.h"
00039 
00040 
00041 /// ClassImp for building the THtml documentation of the class 
00042 ClassImp(RooStats::HybridResult)
00043 
00044 using namespace RooStats;
00045 
00046 ///////////////////////////////////////////////////////////////////////////
00047 
00048 HybridResult::HybridResult( const char *name) :
00049    HypoTestResult(name),
00050    fTestStat_data(-999.),
00051    fComputationsNulDoneFlag(false),
00052    fComputationsAltDoneFlag(false),
00053    fSumLargerValues(false)
00054 {
00055    // HybridResult default constructor (with name )
00056 }
00057 
00058 ///////////////////////////////////////////////////////////////////////////
00059 
00060 HybridResult::HybridResult( const char *name,
00061                             const std::vector<double>& testStat_sb_vals,
00062                             const std::vector<double>& testStat_b_vals,
00063                             bool sumLargerValues ) :
00064    HypoTestResult(name,0,0),
00065    fTestStat_data(-999.),
00066    fComputationsNulDoneFlag(false),
00067    fComputationsAltDoneFlag(false),
00068    fSumLargerValues(sumLargerValues)
00069 {
00070    // HybridResult constructor (with name, title and vectors of S+B and B values)
00071 
00072    int vector_size_sb = testStat_sb_vals.size();
00073    assert(vector_size_sb>0);
00074 
00075    int vector_size_b = testStat_b_vals.size();
00076    assert(vector_size_b>0);
00077 
00078    fTestStat_sb.reserve(vector_size_sb);
00079    for (int i=0;i<vector_size_sb;++i)
00080       fTestStat_sb.push_back(testStat_sb_vals[i]);
00081 
00082    fTestStat_b.reserve(vector_size_b);
00083    for (int i=0;i<vector_size_b;++i)
00084       fTestStat_b.push_back(testStat_b_vals[i]);
00085 }
00086 
00087 
00088 ///////////////////////////////////////////////////////////////////////////
00089 
00090 HybridResult::~HybridResult()
00091 {
00092    // HybridResult destructor
00093 
00094    fTestStat_sb.clear();
00095    fTestStat_b.clear();
00096 }
00097 
00098 ///////////////////////////////////////////////////////////////////////////
00099 
00100 void HybridResult::SetDataTestStatistics(double testStat_data_val)
00101 {
00102    // set the value of the test statistics on data
00103 
00104    fComputationsAltDoneFlag = false;
00105    fComputationsNulDoneFlag = false;
00106    fTestStat_data = testStat_data_val;
00107    return;
00108 }
00109 
00110 ///////////////////////////////////////////////////////////////////////////
00111 
00112 double HybridResult::NullPValue() const
00113 {
00114    // return 1-CL_b : the B p-value
00115 
00116    if (fComputationsNulDoneFlag==false) {
00117       int nToys = fTestStat_b.size();
00118       if (nToys==0) {
00119          std::cout << "Error: no toy data present. Returning -1.\n";
00120          return -1;
00121       }
00122 
00123       double larger_than_measured=0;
00124       if (fSumLargerValues) {
00125         for (int iToy=0;iToy<nToys;++iToy)
00126           if ( fTestStat_b[iToy] >= fTestStat_data ) ++larger_than_measured;
00127       } else {
00128         for (int iToy=0;iToy<nToys;++iToy)
00129           if ( fTestStat_b[iToy] <= fTestStat_data ) ++larger_than_measured;
00130       }
00131 
00132       if (larger_than_measured==0) std::cout << "Warning: CLb = 0 ... maybe more toys are needed!\n";
00133 
00134       fComputationsNulDoneFlag = true;
00135       fNullPValue = 1-larger_than_measured/nToys;
00136    }
00137 
00138    return fNullPValue;
00139 }
00140 
00141 ///////////////////////////////////////////////////////////////////////////
00142 
00143 double HybridResult::AlternatePValue() const
00144 {
00145    // return CL_s+b : the S+B p-value
00146 
00147    if (fComputationsAltDoneFlag==false) {
00148       int nToys = fTestStat_b.size();
00149       if (nToys==0) {
00150          std::cout << "Error: no toy data present. Returning -1.\n";
00151          return -1;
00152       }
00153 
00154       double larger_than_measured=0;
00155       if (fSumLargerValues) {
00156         for (int iToy=0;iToy<nToys;++iToy)
00157           if ( fTestStat_sb[iToy] >= fTestStat_data ) ++larger_than_measured;
00158       } else {
00159         for (int iToy=0;iToy<nToys;++iToy)
00160           if ( fTestStat_sb[iToy] <= fTestStat_data ) ++larger_than_measured;
00161       }
00162 
00163       if (larger_than_measured==0) std::cout << "Warning: CLsb = 0 ... maybe more toys are needed!\n";
00164 
00165       fComputationsAltDoneFlag = true;
00166       fAlternatePValue = larger_than_measured/nToys;
00167    }
00168 
00169    return fAlternatePValue;
00170 }
00171 
00172 ///////////////////////////////////////////////////////////////////////////
00173 
00174 Double_t HybridResult::CLbError() const
00175 {
00176   // Returns an estimate of the error on CLb assuming a binomial error on
00177   // CLb:
00178   // BEGIN_LATEX
00179   // #sigma_{CL_{b}} &=& #sqrt{CL_{b} #left( 1 - CL_{b} #right) / n_{toys}}
00180   // END_LATEX
00181   unsigned const int n = fTestStat_b.size();
00182   return TMath::Sqrt(CLb() * (1. - CLb()) / n);
00183 }
00184 
00185 ///////////////////////////////////////////////////////////////////////////
00186 
00187 Double_t HybridResult::CLsplusbError() const
00188 {
00189   // Returns an estimate of the error on CLsplusb assuming a binomial
00190   // error on CLsplusb:
00191   // BEGIN_LATEX
00192   // #sigma_{CL_{s+b}} &=& #sqrt{CL_{s+b} #left( 1 - CL_{s+b} #right) / n_{toys}}
00193   // END_LATEX
00194   unsigned const int n = fTestStat_sb.size();
00195   return TMath::Sqrt(CLsplusb() * (1. - CLsplusb()) / n);
00196 }
00197 
00198 ///////////////////////////////////////////////////////////////////////////
00199 
00200 Double_t HybridResult::CLsError() const
00201 {
00202   // Returns an estimate of the error on CLs through combination of the
00203   // errors on CLb and CLsplusb:
00204   // BEGIN_LATEX
00205   // #sigma_{CL_s} &=& CL_s #sqrt{#left( #frac{#sigma_{CL_{s+b}}}{CL_{s+b}} #right)^2 + #left( #frac{#sigma_{CL_{b}}}{CL_{b}} #right)^2}
00206   // END_LATEX
00207   unsigned const int n_b = fTestStat_b.size();
00208   unsigned const int n_sb = fTestStat_sb.size();
00209   
00210   if (CLb() == 0 || CLsplusb() == 0)
00211     return 0;
00212   
00213   double cl_b_err = (1. - CLb()) / (n_b * CLb());
00214   double cl_sb_err = (1. - CLsplusb()) / (n_sb * CLsplusb());
00215   
00216   return CLs() * TMath::Sqrt(cl_b_err + cl_sb_err);
00217 }
00218 
00219 ///////////////////////////////////////////////////////////////////////////
00220 
00221 void HybridResult::Add(HybridResult* other)
00222 {
00223    // add additional toy-MC experiments to the current results
00224    // use the data test statistics of the added object if none is already present (otherwise, ignore the new one)
00225 
00226    int other_size_sb = other->GetTestStat_sb().size();
00227    for (int i=0;i<other_size_sb;++i)
00228       fTestStat_sb.push_back(other->GetTestStat_sb()[i]);
00229 
00230    int other_size_b = other->GetTestStat_b().size();
00231    for (int i=0;i<other_size_b;++i)
00232       fTestStat_b.push_back(other->GetTestStat_b()[i]);
00233 
00234    // if no data is present use the other's HybridResult's data
00235    if (fTestStat_data==-999.)
00236       fTestStat_data = other->GetTestStat_data();
00237 
00238    fComputationsAltDoneFlag = false;
00239    fComputationsNulDoneFlag = false;
00240 
00241    return;
00242 }
00243 
00244 ///////////////////////////////////////////////////////////////////////////
00245 
00246 HybridPlot* HybridResult::GetPlot(const char* name,const char* title, int n_bins)
00247 {
00248    // prepare a plot showing a result and return a pointer to a HybridPlot object
00249    // the needed arguments are: an object name, a title and the number of bins in the plot
00250 
00251    // default plot name
00252    TString plot_name;
00253    if ( TString(name)=="" ) {
00254       plot_name += GetName();
00255       plot_name += "_plot";
00256    } else plot_name = name;
00257 
00258    // default plot title
00259    TString plot_title;
00260    if ( TString(title)=="" ) {
00261       plot_title += GetTitle();
00262       plot_title += "_plot (";
00263       plot_title += fTestStat_b.size();
00264       plot_title += " toys)";
00265    } else plot_title = title;
00266 
00267    HybridPlot* plot = new HybridPlot( plot_name.Data(),
00268                                       plot_title.Data(),
00269                                       fTestStat_sb,
00270                                       fTestStat_b,
00271                                       fTestStat_data,
00272                                       n_bins,
00273                                       true );
00274    return plot;
00275 }
00276 
00277 ///////////////////////////////////////////////////////////////////////////
00278 
00279 void HybridResult::PrintMore(const char* /*options */)
00280 {
00281    // Print out some information about the results
00282 
00283    std::cout << "\nResults " << GetName() << ":\n"
00284              << " - Number of S+B toys: " << fTestStat_b.size() << std::endl
00285              << " - Number of B toys: " << fTestStat_sb.size() << std::endl
00286              << " - test statistics evaluated on data: " << fTestStat_data << std::endl
00287              << " - CL_b " << CLb() << std::endl
00288              << " - CL_s+b " << CLsplusb() << std::endl
00289              << " - CL_s " << CLs() << std::endl;
00290 
00291    return;
00292 }
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00300 
00301 
00302 

Generated on Tue Jul 5 15:14:34 2011 for ROOT_528-00b_version by  doxygen 1.5.1