// @(#)root/roostats:$Id$
// Author: Kyle Cranmer   28/07/2008

/*************************************************************************
 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef RooStats_NumberCountingUtils
#define RooStats_NumberCountingUtils

//_________________________________________________
/*
BEGIN_HTML
<h2>NumberCountingUtils</h2>
<p>
These are  RooStats standalone utilities
that calculate the p-value or Z value (eg. significance in
1-sided Gaussian standard deviations) for a number counting experiment.
This is a hypothesis test between background only and signal-plus-background.
The background estimate has uncertainty derived from an auxiliary or sideband
measurement.
</p>
<p>
This is based on code and comments from Bob Cousins 
and on the following papers:
<p>
<ul>
<li>Evaluation of three methods for calculating statistical significance when incorporating a
systematic uncertainty into a test of the background-only hypothesis for a Poisson process<br />
Authors: Robert D. Cousins, James T. Linnemann, Jordan Tucker<br />
http://arxiv.org/abs/physics/0702156<br />
NIM  A 595 (2008) 480--501</li>

<li>
Statistical Challenges for Searches for New Physics at the LHC<br />
Authors: Kyle Cranmer<br />
http://arxiv.org/abs/physics/0511028
</li>
<li>
 Measures of Significance in HEP and Astrophysics<br />
 Authors: J. T. Linnemann<br />
 http://arxiv.org/abs/physics/0312059
</li>
</ul>
<p>
The problem is treated in a fully frequentist fashion by 
interpreting the relative background uncertainty as
being due to an auxiliary or sideband observation 
that is also Poisson distributed with only background.
Finally, one considers the test as a ratio of Poisson means
where an interval is well known based on the conditioning on the total
number of events and the binomial distribution.
</p>

<p>
In short, this is an exact frequentist solution to the problem of
a main measurement x distributed as a Poisson around s+b and a sideband or 
auxiliary measurement y distributed as a Poisson around tau*b.  Eg. 
</p>
END_HTML
BEGIN_LATEX
L(x,y|s,b,#tau) = Pois(x|s+b) Pois(y|#tau b)
END_LATEX
BEGIN_HTML
<pre>
Naming conventions:
Exp = Expected
Obs = Observed
P   = p-value
Z   = Z-value or significance in sigma (one-sided convention)
</pre>
END_HTML
*/
//

#include "Rtypes.h"


namespace RooStats{

   namespace  NumberCountingUtils {

  
  // Expected P-value for s=0 in a ratio of Poisson means.  
  // Here the background and its uncertainty are provided directly and 
  // assumed to be from the double Poisson counting setup described in the 
  // BinomialWithTau functions.  
  // Normally one would know tau directly, but here it is determiend from
  // the background uncertainty.  This is not strictly correct, but a useful 
  // approximation.
     Double_t BinomialExpZ(Double_t sExp, Double_t bExp, Double_t fractionalBUncertainty);

  // See BinomialWithTauExpP
     Double_t BinomialWithTauExpZ(Double_t sExp, Double_t bExp, Double_t tau);   

  // See BinomialObsP
     Double_t BinomialObsZ(Double_t nObs, Double_t bExp, Double_t fractionalBUncertainty);

  // See BinomialWithTauObsP
     Double_t BinomialWithTauObsZ(Double_t nObs, Double_t bExp, Double_t tau);
     
  // See BinomialExpP
     Double_t BinomialExpP(Double_t sExp, Double_t bExp, Double_t fractionalBUncertainty);

  // Expected P-value for s=0 in a ratio of Poisson means.  
  // Based on two expectations, a main measurement that might have signal
  // and an auxiliarly measurement for the background that is signal free.
  // The expected background in the auxiliary measurement is a factor
  // tau larger than in the main measurement.
     Double_t BinomialWithTauExpP(Double_t sExp, Double_t bExp, Double_t tau);

  // P-value for s=0 in a ratio of Poisson means.  
  // Here the background and its uncertainty are provided directly and 
  // assumed to be from the double Poisson counting setup.  
  // Normally one would know tau directly, but here it is determiend from
  // the background uncertainty.  This is not strictly correct, but a useful 
  // approximation.
     Double_t BinomialObsP(Double_t nObs, Double_t, Double_t fractionalBUncertainty);

  // P-value for s=0 in a ratio of Poisson means.  
  // Based on two observations, a main measurement that might have signal
  // and an auxiliarly measurement for the background that is signal free.
  // The expected background in the auxiliary measurement is a factor
  // tau larger than in the main measurement.
     Double_t BinomialWithTauObsP(Double_t nObs, Double_t bExp, Double_t tau);
      

   }
}

#endif
 NumberCountingUtils.h:1
 NumberCountingUtils.h:2
 NumberCountingUtils.h:3
 NumberCountingUtils.h:4
 NumberCountingUtils.h:5
 NumberCountingUtils.h:6
 NumberCountingUtils.h:7
 NumberCountingUtils.h:8
 NumberCountingUtils.h:9
 NumberCountingUtils.h:10
 NumberCountingUtils.h:11
 NumberCountingUtils.h:12
 NumberCountingUtils.h:13
 NumberCountingUtils.h:14
 NumberCountingUtils.h:15
 NumberCountingUtils.h:16
 NumberCountingUtils.h:17
 NumberCountingUtils.h:18
 NumberCountingUtils.h:19
 NumberCountingUtils.h:20
 NumberCountingUtils.h:21
 NumberCountingUtils.h:22
 NumberCountingUtils.h:23
 NumberCountingUtils.h:24
 NumberCountingUtils.h:25
 NumberCountingUtils.h:26
 NumberCountingUtils.h:27
 NumberCountingUtils.h:28
 NumberCountingUtils.h:29
 NumberCountingUtils.h:30
 NumberCountingUtils.h:31
 NumberCountingUtils.h:32
 NumberCountingUtils.h:33
 NumberCountingUtils.h:34
 NumberCountingUtils.h:35
 NumberCountingUtils.h:36
 NumberCountingUtils.h:37
 NumberCountingUtils.h:38
 NumberCountingUtils.h:39
 NumberCountingUtils.h:40
 NumberCountingUtils.h:41
 NumberCountingUtils.h:42
 NumberCountingUtils.h:43
 NumberCountingUtils.h:44
 NumberCountingUtils.h:45
 NumberCountingUtils.h:46
 NumberCountingUtils.h:47
 NumberCountingUtils.h:48
 NumberCountingUtils.h:49
 NumberCountingUtils.h:50
 NumberCountingUtils.h:51
 NumberCountingUtils.h:52
 NumberCountingUtils.h:53
 NumberCountingUtils.h:54
 NumberCountingUtils.h:55
 NumberCountingUtils.h:56
 NumberCountingUtils.h:57
 NumberCountingUtils.h:58
 NumberCountingUtils.h:59
 NumberCountingUtils.h:60
 NumberCountingUtils.h:61
 NumberCountingUtils.h:62
 NumberCountingUtils.h:63
 NumberCountingUtils.h:64
 NumberCountingUtils.h:65
 NumberCountingUtils.h:66
 NumberCountingUtils.h:67
 NumberCountingUtils.h:68
 NumberCountingUtils.h:69
 NumberCountingUtils.h:70
 NumberCountingUtils.h:71
 NumberCountingUtils.h:72
 NumberCountingUtils.h:73
 NumberCountingUtils.h:74
 NumberCountingUtils.h:75
 NumberCountingUtils.h:76
 NumberCountingUtils.h:77
 NumberCountingUtils.h:78
 NumberCountingUtils.h:79
 NumberCountingUtils.h:80
 NumberCountingUtils.h:81
 NumberCountingUtils.h:82
 NumberCountingUtils.h:83
 NumberCountingUtils.h:84
 NumberCountingUtils.h:85
 NumberCountingUtils.h:86
 NumberCountingUtils.h:87
 NumberCountingUtils.h:88
 NumberCountingUtils.h:89
 NumberCountingUtils.h:90
 NumberCountingUtils.h:91
 NumberCountingUtils.h:92
 NumberCountingUtils.h:93
 NumberCountingUtils.h:94
 NumberCountingUtils.h:95
 NumberCountingUtils.h:96
 NumberCountingUtils.h:97
 NumberCountingUtils.h:98
 NumberCountingUtils.h:99
 NumberCountingUtils.h:100
 NumberCountingUtils.h:101
 NumberCountingUtils.h:102
 NumberCountingUtils.h:103
 NumberCountingUtils.h:104
 NumberCountingUtils.h:105
 NumberCountingUtils.h:106
 NumberCountingUtils.h:107
 NumberCountingUtils.h:108
 NumberCountingUtils.h:109
 NumberCountingUtils.h:110
 NumberCountingUtils.h:111
 NumberCountingUtils.h:112
 NumberCountingUtils.h:113
 NumberCountingUtils.h:114
 NumberCountingUtils.h:115
 NumberCountingUtils.h:116
 NumberCountingUtils.h:117
 NumberCountingUtils.h:118
 NumberCountingUtils.h:119
 NumberCountingUtils.h:120
 NumberCountingUtils.h:121
 NumberCountingUtils.h:122
 NumberCountingUtils.h:123
 NumberCountingUtils.h:124
 NumberCountingUtils.h:125
 NumberCountingUtils.h:126
 NumberCountingUtils.h:127
 NumberCountingUtils.h:128
 NumberCountingUtils.h:129
 NumberCountingUtils.h:130
 NumberCountingUtils.h:131
 NumberCountingUtils.h:132
 NumberCountingUtils.h:133
 NumberCountingUtils.h:134
 NumberCountingUtils.h:135