diff --git a/roofit/roostats/inc/RooStats/HypoTestInverterResult.h b/roofit/roostats/inc/RooStats/HypoTestInverterResult.h index bf8977db0527dd5b06bd40ab9653eed9d04f3f9a..a5ba779a7d9d2058a2acc12bbb65268bcb1245c0 100644 --- a/roofit/roostats/inc/RooStats/HypoTestInverterResult.h +++ b/roofit/roostats/inc/RooStats/HypoTestInverterResult.h @@ -43,6 +43,8 @@ public: // merge with the content of another HypoTestInverterResult object bool Add( const HypoTestInverterResult& otherResult ); + //add the result of a single point (an HypoTestRsult) + bool Add( Double_t x, const HypoTestResult & result ); // function to return the value of the parameter of interest for the i^th entry in the results double GetXValue( int index ) const ; diff --git a/roofit/roostats/src/HypoTestInverterResult.cxx b/roofit/roostats/src/HypoTestInverterResult.cxx index 9c2dc0c96089ec35ec97240ce514218ddfebfc09..156baa514983488ff688ff2098a9c5b67f9e5694 100644 --- a/roofit/roostats/src/HypoTestInverterResult.cxx +++ b/roofit/roostats/src/HypoTestInverterResult.cxx @@ -124,6 +124,8 @@ bool HypoTestInverterResult::Add( const HypoTestInverterResult& otherResult ) oocoutI(this,Eval) << "HypoTestInverterResult::Add - merging also the expected p-values from pseudo-data" << std::endl; + // case current result is empty + // just make a simple copy of the other result if (nThis == 0) { fXValues = otherResult.fXValues; for (int i = 0; i < nOther; ++i) @@ -131,15 +133,16 @@ bool HypoTestInverterResult::Add( const HypoTestInverterResult& otherResult ) for (int i = 0; i < fExpPValues.GetSize() ; ++i) fExpPValues.Add( otherResult.fExpPValues.At(i)->Clone() ); } - // now to common merge combining point with same value and adding extra ones - for (int i = 0; i < nOther; ++i) { - double otherVal = otherResult.fXValues[i]; - HypoTestResult * otherHTR = (HypoTestResult*) otherResult.fYObjects.At(i); - if (otherHTR == 0) continue; - bool sameXFound = false; - for (int j = 0; j < nThis; ++j) { - double thisVal = fXValues[j]; - + // now do teh real mergemerge combining point with same value or adding extra ones + else { + for (int i = 0; i < nOther; ++i) { + double otherVal = otherResult.fXValues[i]; + HypoTestResult * otherHTR = (HypoTestResult*) otherResult.fYObjects.At(i); + if (otherHTR == 0) continue; + bool sameXFound = false; + for (int j = 0; j < nThis; ++j) { + double thisVal = fXValues[j]; + // if same value merge the result if ( (std::abs(otherVal) < 1 && TMath::AreEqualAbs(otherVal, thisVal,1.E-12) ) || (std::abs(otherVal) >= 1 && TMath::AreEqualRel(otherVal, thisVal,1.E-12) ) ) { @@ -156,17 +159,18 @@ bool HypoTestInverterResult::Add( const HypoTestInverterResult& otherResult ) } break; } + } + if (!sameXFound) { + // add the new result + fYObjects.Add(otherHTR->Clone() ); + fXValues.push_back( otherVal); + } + // add in any case also when same x found + if (addExpPValues) + fExpPValues.Add( otherResult.fExpPValues.At(i)->Clone() ); + + } - if (!sameXFound) { - // add the new result - fYObjects.Add(otherHTR->Clone() ); - fXValues.push_back( otherVal); - } - // add in any case also when same x found - if (addExpPValues) - fExpPValues.Add( otherResult.fExpPValues.At(i)->Clone() ); - - } if (ArraySize() > nThis) @@ -180,6 +184,22 @@ bool HypoTestInverterResult::Add( const HypoTestInverterResult& otherResult ) return true; } +bool HypoTestInverterResult::Add (Double_t x, const HypoTestResult & res) +{ + // Add a single point result (an HypoTestResult) + int i= FindIndex(x); + if (i<0) { + fXValues.push_back(x); + fYObjects.Add(res.Clone()); + } else { + HypoTestResult* r= GetResult(i); + if (!r) return false; + r->Append(&res); + } + return true; +} + + double HypoTestInverterResult::GetXValue( int index ) const { @@ -296,7 +316,7 @@ int HypoTestInverterResult::FindIndex(double xvalue) const // If no points is found return -1 // Note that a tolerance is used of 10^-12 to find the closest point const double tol = 1.E-12; - for (int i=1; i<ArraySize(); i++) { + for (int i=0; i<ArraySize(); i++) { double xpoint = fXValues[i]; if ( (std::abs(xvalue) > 1 && TMath::AreEqualRel( xvalue, xpoint, tol) ) || (std::abs(xvalue) < 1 && TMath::AreEqualAbs( xvalue, xpoint, tol) ) )