# Problem of Using StandardHypoTestInvDemo.C to Calculate the Upper-limit of Feldman-cousins methods

**URL:** <https://root-forum.cern.ch/t/problem-of-using-standardhypotestinvdemo-c-to-calculate-the-upper-limit-of-feldman-cousins-methods/54745>\
**Category:** Roofit and RooStats\
**Tags:** root\
**Created:** [May 5, 2023, 4:28am UTC](https://root-forum.cern.ch/t/problem-of-using-standardhypotestinvdemo-c-to-calculate-the-upper-limit-of-feldman-cousins-methods/54745 "2023-05-05T04:28:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![huyuxiang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/9de0a6/32.png) [@huyuxiang](https://root-forum.cern.ch/u/huyuxiang)\
**Post date:** [May 5, 2023, 4:28am UTC](https://root-forum.cern.ch/t/problem-of-using-standardhypotestinvdemo-c-to-calculate-the-upper-limit-of-feldman-cousins-methods/54745/1 "2023-05-05T04:28:21Z")

</div>

Hi,  
I want to use StandardHypoTestInvDemo.C to calculate upper-limit properly but I find some difference between the result of StandardHypoTestInvDemo.C and the result of original paper of Feldman-Cousins.

The CountingModel is below:

```cpp
using namespace RooFit;
using namespace RooStats;

void CountingModel( int nobs = 3, // number of observed events
                     double b = 1, // number of background events
                     double sigmab = 0.01) // relative uncertainty in b
{
   RooWorkspace w("w");
   
// make Poisson model * Gaussian constraint
   w.factory("sum:nexp(s[3,0,15],b[1,0,10])");
// Poisson of (n | s+b)
   w.factory("Poisson:pdf(nobs[0,50],nexp)");
   w.factory("Gaussian:constraint(b0[0,10],b,sigmab[1])");
   w.factory("PROD:model(pdf,constraint)");

   w.var("b0")->setVal(b);
   w.var("b0")->setConstant(true); // needed for being treated as global observables
   w.var("sigmab")->setVal(sigmab*b);  
   

   ModelConfig mc("ModelConfig",&w);
   mc.SetPdf(*w.pdf("model"));
   mc.SetParametersOfInterest(*w.var("s"));
   mc.SetObservables(*w.var("nobs"));
   mc.SetNuisanceParameters(*w.var("b"));

   // these are needed for the hypothesis tests
   mc.SetSnapshot(*w.var("s"));
   mc.SetGlobalObservables(*w.var("b0"));

   mc.Print();
   // import model in the workspace 
   w.import(mc);

   // make data set with the namber of observed events
   RooDataSet data("data","", *w.var("nobs"));
   w.var("nobs")->setVal(nobs);
 

  data.add(*w.var("nobs") );
   // import data set in workspace and save it in a file
   w.import(data);

   w.Print();

   TString fileName = "CountingModel.root"; 

   // write workspace in the file (recreate file if already existing)
   w.writeToFile(fileName, true);

}

```

I give the smaller uncertainty since I want to match the result of Feldman-Cousins paper

Then  
I use the command below:

`StandardHypoTestInvDemo("CountingModel.root", "w", "ModelConfig"," " , "data", 0, 2, false, 200, 0, 8, 2000, true)`

The output is below:

```plaintext
The computed lower limit is: 0.385632 +/- 0.0317312
The computed upper limit is: 6.00396 +/- 0.104173
Expected upper limits, using the B (alternate) model : 
 expected limit (median) 2.57069
 expected limit (-1 sig) 1.23237
 expected limit (+1 sig) 4.5014
 expected limit (-2 sig) 0.146673
 expected limit (+2 sig) 6.02079

```

does it mean the interval is [0.38, 6.00] ?

the plot is

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/a/5/a573c49ffe5999364ef13eb706a2108ab1dc6064.png)

---

<div class="post-metadata">

**Author:** ![huyuxiang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/9de0a6/32.png) [@huyuxiang](https://root-forum.cern.ch/u/huyuxiang)\
**Post date:** [May 5, 2023, 4:31am UTC](https://root-forum.cern.ch/t/problem-of-using-standardhypotestinvdemo-c-to-calculate-the-upper-limit-of-feldman-cousins-methods/54745/2 "2023-05-05T04:31:05Z")

</div>

Hi  
if the interval is [0.38,6.00] but the FC paper gives the result [0.10, 6.42] when obs = 3, n\_bkg =1. I can’t understand the difference.

---

<div class="post-metadata">

**Author:** ![huyuxiang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/9de0a6/32.png) [@huyuxiang](https://root-forum.cern.ch/u/huyuxiang)\
**Post date:** [May 6, 2023, 9:06am UTC](https://root-forum.cern.ch/t/problem-of-using-standardhypotestinvdemo-c-to-calculate-the-upper-limit-of-feldman-cousins-methods/54745/3 "2023-05-06T09:06:04Z")

</div>

Hi @moneta ， Could you give some comments on this problems? Thanks !

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 20, 2023, 9:06am UTC](https://root-forum.cern.ch/t/problem-of-using-standardhypotestinvdemo-c-to-calculate-the-upper-limit-of-feldman-cousins-methods/54745/4 "2023-05-20T09:06:59Z")

</div>

Closed on May 20, 2023, 9:06am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [June 2, 2023, 3:31pm UTC](https://root-forum.cern.ch/t/problem-of-using-standardhypotestinvdemo-c-to-calculate-the-upper-limit-of-feldman-cousins-methods/54745/5 "2023-06-02T15:31:01Z")

</div>

Hi,

Apologies for the late reply. A small difference between the two is expected, also by giving a systematic uncertainty, although with a small uncertaintie, it smooths the discontinuities in the test statistics (likelihood ratio) given by the discrete data. This is probably the cause of the observed difference.

Lorenzo
