00001 // @(#)root/roostats:$Id: HypoTestResult.h 36602 2010-11-11 16:52:13Z moneta $ 00002 // Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke, Sven Kreiss 00003 /************************************************************************* 00004 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. * 00005 * All rights reserved. * 00006 * * 00007 * For the licensing terms see $ROOTSYS/LICENSE. * 00008 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00009 *************************************************************************/ 00010 00011 #ifndef ROOSTATS_HypoTestResult 00012 #define ROOSTATS_HypoTestResult 00013 00014 #ifndef ROOT_TNamed 00015 #include "TNamed.h" 00016 #endif 00017 00018 #ifndef ROOSTATS_RooStatsUtils 00019 #include "RooStats/RooStatsUtils.h" 00020 #endif 00021 00022 #ifndef ROOSTATS_SamplingDistribution 00023 #include "RooStats/SamplingDistribution.h" 00024 #endif 00025 00026 namespace RooStats { 00027 00028 class HypoTestResult : public TNamed { 00029 00030 public: 00031 00032 // default constructor 00033 explicit HypoTestResult(const char* name = 0); 00034 00035 // constructor from name, null and alternate p values 00036 HypoTestResult(const char* name, Double_t nullp, Double_t altp); 00037 00038 // destructor 00039 virtual ~HypoTestResult(); 00040 00041 // add values from another HypoTestResult 00042 virtual void Append(const HypoTestResult *other); 00043 00044 // Return p-value for null hypothesis 00045 virtual Double_t NullPValue() const { return fNullPValue; } 00046 00047 // Return p-value for alternate hypothesis 00048 virtual Double_t AlternatePValue() const { return fAlternatePValue; } 00049 00050 // Convert NullPValue into a "confidence level" 00051 virtual Double_t CLb() const { return 1.-NullPValue(); } 00052 00053 // Convert AlternatePValue into a "confidence level" 00054 virtual Double_t CLsplusb() const { return AlternatePValue(); } 00055 00056 // CLs is simply CLs+b/CLb (not a method, but a quantity) 00057 virtual Double_t CLs() const { 00058 double thisCLb = CLb(); 00059 if (thisCLb == 0) { 00060 std::cout << "Error: Cannot compute CLs because CLb = 0. Returning CLs = -1\n"; 00061 return -1; 00062 } 00063 double thisCLsb = CLsplusb(); 00064 return thisCLsb / thisCLb; 00065 } 00066 00067 // familiar name for the Null p-value in terms of 1-sided Gaussian significance 00068 virtual Double_t Significance() const {return RooStats::PValueToSignificance( NullPValue() ); } 00069 00070 SamplingDistribution* GetNullDistribution(void) const { return fNullDistr; } 00071 SamplingDistribution* GetAltDistribution(void) const { return fAltDistr; } 00072 Double_t GetTestStatisticData(void) const { return fTestStatisticData; } 00073 Bool_t HasTestStatisticData(void) const; 00074 00075 void SetAltDistribution(SamplingDistribution *alt); 00076 void SetNullDistribution(SamplingDistribution *null); 00077 void SetTestStatisticData(const Double_t tsd); 00078 00079 void SetPValueIsRightTail(Bool_t pr); 00080 Bool_t GetPValueIsRightTail(void) const { return fPValueIsRightTail; } 00081 00082 /// The error on the "confidence level" of the null hypothesis 00083 Double_t CLbError() const; 00084 00085 /// The error on the "confidence level" of the alternative hypothesis 00086 Double_t CLsplusbError() const; 00087 00088 /// The error on the ratio CLs+b/CLb 00089 Double_t CLsError() const; 00090 00091 Double_t NullPValueError() const; 00092 00093 00094 void Print(const Option_t* = "") const { 00095 // Print out some information about the results 00096 00097 cout << endl << "Results " << GetName() << ": " << endl; 00098 if(HasTestStatisticData() && fNullDistr) { 00099 cout << " - Null p-value = " << NullPValue() << " +/- " << NullPValueError() << endl; 00100 cout << " - Significance = " << Significance() << " sigma" << endl; 00101 } 00102 if(fAltDistr) 00103 cout << " - Number of S+B toys: " << fAltDistr->GetSize() << std::endl; 00104 if(fNullDistr) 00105 cout << " - Number of B toys: " << fNullDistr->GetSize() << std::endl; 00106 if(HasTestStatisticData()) 00107 cout << " - Test statistic evaluated on data: " << fTestStatisticData << std::endl; 00108 if(HasTestStatisticData() && fNullDistr) 00109 cout << " - CL_b: " << CLb() << " +/- " << CLbError() << std::endl; 00110 if(HasTestStatisticData() && fAltDistr) 00111 cout << " - CL_s+b: " << CLsplusb() << " +/- " << CLsplusbError() << std::endl; 00112 if(HasTestStatisticData() && fAltDistr && fNullDistr) 00113 cout << " - CL_s: " << CLs() << " +/- " << CLsError() << std::endl; 00114 00115 return; 00116 } 00117 00118 private: 00119 void UpdatePValue(const SamplingDistribution* distr, Double_t *pvalue, Bool_t pIsRightTail); 00120 00121 00122 protected: 00123 00124 mutable Double_t fNullPValue; // p-value for the null hypothesis (small number means disfavored) 00125 mutable Double_t fAlternatePValue; // p-value for the alternate hypothesis (small number means disfavored) 00126 Double_t fTestStatisticData; // result of the test statistic evaluated on data 00127 SamplingDistribution *fNullDistr; 00128 SamplingDistribution *fAltDistr; 00129 Bool_t fPValueIsRightTail; 00130 00131 ClassDef(HypoTestResult,1) // Base class to represent results of a hypothesis test 00132 00133 }; 00134 } 00135 00136 00137 #endif