66 #define NaN numeric_limits<float>::quiet_NaN()
67 #define IsNaN(a) TMath::IsNaN(a)
69 ClassImp(RooStats::HypoTestResult); ;
71 using namespace RooStats;
77 HypoTestResult::HypoTestResult(
const char* name) :
79 fNullPValue(NaN), fAlternatePValue(NaN),
80 fNullPValueError(0), fAlternatePValueError(0),
81 fTestStatisticData(NaN),
82 fAllTestStatisticsData(NULL),
83 fNullDistr(NULL), fAltDistr(NULL),
84 fNullDetailedOutput(NULL), fAltDetailedOutput(NULL), fFitInfo(NULL),
85 fPValueIsRightTail(kTRUE),
86 fBackgroundIsAlt(kFALSE)
93 HypoTestResult::HypoTestResult(
const char* name, Double_t nullp, Double_t altp) :
95 fNullPValue(nullp), fAlternatePValue(altp),
96 fNullPValueError(0), fAlternatePValueError(0),
97 fTestStatisticData(NaN),
98 fAllTestStatisticsData(NULL),
99 fNullDistr(NULL), fAltDistr(NULL),
100 fNullDetailedOutput(NULL), fAltDetailedOutput(NULL), fFitInfo(NULL),
101 fPValueIsRightTail(kTRUE),
102 fBackgroundIsAlt(kFALSE)
109 HypoTestResult::HypoTestResult(
const HypoTestResult& other) :
111 fNullPValue(NaN), fAlternatePValue(NaN),
112 fNullPValueError(0), fAlternatePValueError(0),
113 fTestStatisticData(NaN),
114 fAllTestStatisticsData(NULL),
115 fNullDistr(NULL), fAltDistr(NULL),
116 fNullDetailedOutput(NULL), fAltDetailedOutput(NULL), fFitInfo(NULL),
117 fPValueIsRightTail( other.GetPValueIsRightTail() ),
118 fBackgroundIsAlt( other.GetBackGroundIsAlt() )
120 this->Append( &other );
126 HypoTestResult::~HypoTestResult()
128 if( fNullDistr )
delete fNullDistr;
129 if( fAltDistr )
delete fAltDistr;
131 if( fNullDetailedOutput )
delete fNullDetailedOutput;
132 if( fAltDetailedOutput )
delete fAltDetailedOutput;
134 if( fAllTestStatisticsData )
delete fAllTestStatisticsData;
140 HypoTestResult & HypoTestResult::operator=(
const HypoTestResult& other) {
141 if (
this == &other)
return *
this;
142 SetName(other.GetName());
143 SetTitle(other.GetTitle());
144 fNullPValue = other.fNullPValue;
145 fAlternatePValue = other.fAlternatePValue;
146 fNullPValueError = other.fNullPValueError;
147 fAlternatePValueError = other.fAlternatePValueError;
148 fTestStatisticData = other.fTestStatisticData;
150 if( fAllTestStatisticsData )
delete fAllTestStatisticsData;
151 fAllTestStatisticsData = NULL;
152 if( fNullDistr ) {
delete fNullDistr; fNullDistr = NULL; }
153 if( fAltDistr ) {
delete fAltDistr; fAltDistr = NULL; }
154 if( fNullDetailedOutput ) {
delete fNullDetailedOutput; fNullDetailedOutput = NULL; }
155 if( fAltDetailedOutput ) {
delete fAltDetailedOutput; fAltDetailedOutput = NULL; }
156 if (fFitInfo) {
delete fFitInfo; fFitInfo = NULL; }
158 fPValueIsRightTail = other.GetPValueIsRightTail();
159 fBackgroundIsAlt = other.GetBackGroundIsAlt();
161 this->Append( &other );
171 void HypoTestResult::Append(
const HypoTestResult* other) {
173 fNullDistr->Add(other->GetNullDistribution());
175 if(other->GetNullDistribution()) fNullDistr =
new SamplingDistribution( *other->GetNullDistribution() );
178 fAltDistr->Add(other->GetAltDistribution());
180 if(other->GetAltDistribution()) fAltDistr =
new SamplingDistribution( *other->GetAltDistribution() );
183 if( fNullDetailedOutput ) {
184 if( other->GetNullDetailedOutput() ) fNullDetailedOutput->append( *other->GetNullDetailedOutput() );
186 if( other->GetNullDetailedOutput() ) fNullDetailedOutput =
new RooDataSet( *other->GetNullDetailedOutput() );
189 if( fAltDetailedOutput ) {
190 if( other->GetAltDetailedOutput() ) fAltDetailedOutput->append( *other->GetAltDetailedOutput() );
192 if( other->GetAltDetailedOutput() ) fAltDetailedOutput =
new RooDataSet( *other->GetAltDetailedOutput() );
196 if( other->GetFitInfo() ) fFitInfo->append( *other->GetFitInfo() );
198 if( other->GetFitInfo() ) fFitInfo =
new RooDataSet( *other->GetFitInfo() );
202 if(IsNaN(fTestStatisticData)) fTestStatisticData = other->GetTestStatisticData();
204 UpdatePValue(fNullDistr, fNullPValue, fNullPValueError, kTRUE);
205 UpdatePValue(fAltDistr, fAlternatePValue, fAlternatePValueError, kFALSE);
210 void HypoTestResult::SetAltDistribution(SamplingDistribution *alt) {
212 UpdatePValue(fAltDistr, fAlternatePValue, fAlternatePValueError, kFALSE);
217 void HypoTestResult::SetNullDistribution(SamplingDistribution *null) {
219 UpdatePValue(fNullDistr, fNullPValue, fNullPValueError, kTRUE);
224 void HypoTestResult::SetTestStatisticData(
const Double_t tsd) {
225 fTestStatisticData = tsd;
227 UpdatePValue(fNullDistr, fNullPValue, fNullPValueError, kTRUE);
228 UpdatePValue(fAltDistr, fAlternatePValue, fAlternatePValueError, kFALSE);
233 void HypoTestResult::SetAllTestStatisticsData(
const RooArgList* tsd) {
234 if (fAllTestStatisticsData) {
235 delete fAllTestStatisticsData;
236 fAllTestStatisticsData = 0;
238 if (tsd) fAllTestStatisticsData = (
const RooArgList*)tsd->snapshot();
240 if( fAllTestStatisticsData && fAllTestStatisticsData->getSize() > 0 ) {
241 RooRealVar* firstTS = (RooRealVar*)fAllTestStatisticsData->at(0);
242 if( firstTS ) SetTestStatisticData( firstTS->getVal() );
248 void HypoTestResult::SetPValueIsRightTail(Bool_t pr) {
249 fPValueIsRightTail = pr;
251 UpdatePValue(fNullDistr, fNullPValue, fNullPValueError, kTRUE);
252 UpdatePValue(fAltDistr, fAlternatePValue, fAlternatePValueError, kFALSE);
257 Bool_t HypoTestResult::HasTestStatisticData(
void)
const {
258 return !IsNaN(fTestStatisticData);
263 Double_t HypoTestResult::NullPValueError()
const {
265 return fNullPValueError;
273 Double_t HypoTestResult::CLbError()
const {
274 return fBackgroundIsAlt ? fAlternatePValueError : fNullPValueError;
279 Double_t HypoTestResult::CLsplusbError()
const {
280 return fBackgroundIsAlt ? fNullPValueError : fAlternatePValueError;
286 Double_t HypoTestResult::SignificanceError()
const {
287 return NullPValueError() / ROOT::Math::normal_pdf(Significance());
298 Double_t HypoTestResult::CLsError()
const {
299 if(!fAltDistr || !fNullDistr)
return 0.0;
305 if (CLb() == 0 )
return -1;
307 double cl_b_err2 = pow(CLbError(),2);
308 double cl_sb_err2 = pow(CLsplusbError(),2);
310 return TMath::Sqrt(cl_sb_err2 + cl_b_err2 * pow(CLs(),2))/CLb();
316 void HypoTestResult::UpdatePValue(
const SamplingDistribution* distr, Double_t &pvalue, Double_t &perror, Bool_t ) {
317 if(IsNaN(fTestStatisticData))
return;
324 if(fPValueIsRightTail) {
325 pvalue = distr->IntegralAndError(perror, fTestStatisticData, RooNumber::infinity(), kTRUE,
329 pvalue = distr->IntegralAndError(perror, -RooNumber::infinity(), fTestStatisticData, kTRUE,
339 void HypoTestResult::Print(Option_t * )
const
341 bool fromToys = (fAltDistr || fNullDistr);
343 std::cout << std::endl <<
"Results " << GetName() <<
": " << endl;
344 std::cout <<
" - Null p-value = " << NullPValue();
345 if (fromToys) std::cout <<
" +/- " << NullPValueError();
346 std::cout << std::endl;
347 std::cout <<
" - Significance = " << Significance();
348 if (fromToys) std::cout <<
" +/- " << SignificanceError() <<
" sigma";
349 std::cout << std::endl;
351 std::cout <<
" - Number of Alt toys: " << fAltDistr->GetSize() << std::endl;
353 std::cout <<
" - Number of Null toys: " << fNullDistr->GetSize() << std::endl;
355 if (HasTestStatisticData() ) std::cout <<
" - Test statistic evaluated on data: " << fTestStatisticData << std::endl;
356 std::cout <<
" - CL_b: " << CLb();
357 if (fromToys) std::cout <<
" +/- " << CLbError();
358 std::cout << std::endl;
359 std::cout <<
" - CL_s+b: " << CLsplusb();
360 if (fromToys) std::cout <<
" +/- " << CLsplusbError();
361 std::cout << std::endl;
362 std::cout <<
" - CL_s: " << CLs();
363 if (fromToys) std::cout <<
" +/- " << CLsError();
364 std::cout << std::endl;