50HypoTestInverterOriginal::HypoTestInverterOriginal( ) :
66 fScannedVariable(&scannedVariable),
73 SetName(
"HypoTestInverterOriginal");
78 Fatal(
"HypoTestInverterOriginal",
"Using non HybridCalculatorOriginal class IS NOT SUPPORTED");
99 results_name +=
"_results";
118 std::cout <<
"Error: problem with the specified range\n";
121 if ( target<=0 || target>=1 ) {
122 std::cout <<
"Error: problem with target value\n";
126 std::cout <<
"Error: problem with error value\n";
129 if ( numAlgorithm!=0 && numAlgorithm!=1 ) {
130 std::cout <<
"Error: invalid interpolation algorithm\n";
137 if (
fabs(1-target/(1-
Size()/2))<DBL_EPSILON ) {
139 std::cout <<
"Target matches lower limit: de-activate interpolation in HypoTestInverterResult\n";
142 if (
fabs(1-target/((
Size()/2)))<DBL_EPSILON ) {
144 std::cout <<
"Target matches upper limit: de-activate interpolation in HypoTestInverterResult\n";
148 const double nSigma = 1;
159 double rightX = xMax;
164 if ( rightCL>target && leftCL>target ) {
165 std::cout <<
"The confidence level at both boundaries are both too large ( " << leftCL <<
" and " << rightCL << std::endl <<
"Run again with other boundaries or larger toy-MC statistics\n";
168 if ( rightCL<target && leftCL<target ) {
169 std::cout <<
"The confidence level at both boundaries are both too small ( " << leftCL <<
" and " << rightCL << std::endl <<
"Run again with other boundaries or larger toy-MC statistics\n";
173 unsigned int nIteration = 2;
174 bool quitThisLoop =
false;
177 double centerCLError = 0;
186 if (leftCL==rightCL) {
187 std::cout <<
"This cannot (and should not) happen... quit\n";
189 }
else if (leftX==rightX) {
190 std::cout <<
"This cannot (and should not) happen... quit\n";
195 if (numAlgorithm==0) {
199 if (!leftCL) leftCL = DBL_EPSILON;
200 if (!rightCL) rightCL = DBL_EPSILON;
202 double a = (
log(leftCL) -
log(rightCL)) / (leftX - rightX);
203 double b = leftCL /
exp(
a * leftX);
208 std::cout <<
"Extrapolated value out of range or nan: exits\n";
211 }
else if (numAlgorithm==1) {
214 double a = (leftCL-rightCL)/(leftX-rightX);
215 double b = leftCL-
a*leftX;
219 std::cout <<
"Extrapolated value out of range or nan: exits\n";
225 if (
x==leftX ||
x==rightX ) {
226 std::cout <<
"Error: exit because interpolated value equals to a previous iteration\n";
231 bool success =
false;
244 if ( (leftCL > target) == (rightCL < target) ) {
245 if ( (centerCL > target) == (leftCL > target) ) {
248 leftCLError = centerCLError;
252 rightCLError = centerCLError;
256 }
else if ( (
fabs(leftCL - target) / leftCLError) >
257 (
fabs(rightCL - target) / rightCLError) ) {
260 leftCLError = centerCLError;
264 rightCLError = centerCLError;
269 if (
fabs(centerCL-target) < nSigma*centerCLError && centerCLError >
epsilon ) {
275 std::cout <<
"Increasing the number of toys to: " << nToysTarget << std::endl;
287 }
while (
fabs(centerCL-target) < nSigma*centerCLError && centerCLError >
epsilon && quitThisLoop==false );
290 if (leftCL==rightCL) {
291 std::cout <<
"Algorithm failed: left and right CL are equal (no interpolation possible or more toy-MC statistics needed)\n";
296 }
while ( (
fabs(centerCL-target) > nSigma*centerCLError || centerCLError >
epsilon ) && quitThisLoop==
false );
301 if ( quitThisLoop==
true ) {
303 std::cout <<
"Aborted the search because something happened\n";
322 std::cout <<
"Please provide nBins>0\n";
325 if ( nBins==1 && xMin!=xMax ) {
326 std::cout <<
"nBins==1 -> I will run for xMin (" << xMin <<
")\n";
328 if ( xMin==xMax && nBins>1 ) {
329 std::cout <<
"xMin==xMax -> I will enforce nBins==1\n";
333 std::cout <<
"Please provide xMin (" << xMin <<
") smaller that xMax (" << xMax <<
")\n";
337 for (
int i=0; i<nBins; i++) {
338 double thisX = xMin+i*(xMax-xMin)/(nBins-1);
342 if ( status==
false ) {
343 std::cout <<
"Loop interrupted because of failed status\n";
360 if ( thisX<fScannedVariable->getMin() ) {
361 std::cout <<
"Out of range: using the lower bound on the scanned variable rather than " << thisX<<
"\n";
365 std::cout <<
"Out of range: using the upper bound on the scanned variable rather than " << thisX<<
"\n";
379 else lastXtested = -999;
381 if ( lastXtested==thisX ) {
383 std::cout <<
"Merge with previous result\n";
386 delete myHybridResult;
double pow(double, double)
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooRealVar represents a fundamental (non-derived) real valued object.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
HybridCalculatorOriginal class.
Class encapsulating the result of the HybridCalculatorOriginal.
void Add(HybridResult *other)
add additional toy-MC experiments to the current results use the data test statistics of the added ob...
HypoTestCalculator is an interface class for a tools which produce RooStats HypoTestResults.
virtual HypoTestResult * GetHypoTest() const =0
This class is now deprecated and to be replaced by the HypoTestInverter.
RooRealVar * fScannedVariable
bool RunFixedScan(int nBins, double xMin, double xMax)
HypoTestInverterResult * fResults
HypoTestInverterOriginal()
bool RunAutoScan(double xMin, double xMax, double target, double epsilon=0.005, unsigned int numAlgorithm=0)
virtual ~HypoTestInverterOriginal()
HypoTestCalculator * fCalculator0
virtual Double_t ConfidenceLevel() const
Get the Confidence level for the test.
bool RunOnePoint(double thisX)
run only one point
virtual Double_t Size() const
Get the size of the test (eg. rate of Type I error)
HypoTestInverterResult class holds the array of hypothesis test results and compute a confidence inte...
bool fInterpolateUpperLimit
double GetYValue(int index) const
function to return the value of the confidence level for the i^th entry in the results
HypoTestResult * GetResult(int index) const
return a pointer to the i^th result object
int ArraySize() const
number of entries in the results array
bool fInterpolateLowerLimit
two sided scan (look for lower/upper limit)
std::vector< double > fXValues
number of points used to build expected p-values
void UseCLs(bool on=true)
flag to switch between using CLsb (default) or CLs as confidence level
double GetXValue(int index) const
function to return the value of the parameter of interest for the i^th entry in the results
double GetYError(int index) const
function to return the estimated error on the value of the confidence level for the i^th entry in the...
HypoTestResult is a base class for results from hypothesis tests.
virtual void Add(TObject *obj)
The TNamed class is the base class for all named ROOT classes.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual const char * GetName() const
Returns name of object.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Namespace for the RooStats classes.
Short_t Max(Short_t a, Short_t b)