00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 #include "RooDataHist.h"
00031 #include "RooDataSet.h"
00032 #include "RooGlobalFunc.h" 
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 
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    
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    
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    
00093 
00094    fTestStat_sb.clear();
00095    fTestStat_b.clear();
00096 }
00097 
00098 
00099 
00100 void HybridResult::SetDataTestStatistics(double testStat_data_val)
00101 {
00102    
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    
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    
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   
00177   
00178   
00179   
00180   
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   
00190   
00191   
00192   
00193   
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   
00203   
00204   
00205   
00206   
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    
00224    
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    
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    
00249    
00250 
00251    
00252    TString plot_name;
00253    if ( TString(name)=="" ) {
00254       plot_name += GetName();
00255       plot_name += "_plot";
00256    } else plot_name = name;
00257 
00258    
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* )
00280 {
00281    
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