CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QStatisticalTests.cc
Go to the documentation of this file.
2 #include <TMath.h>
3 
4 using namespace TMath;
5 
6 //---------------------------------------------------------------------------
7 void BinLogLikelihoodRatio(long Nentries, long Nfailures, double epsilon_max,
8  double* S_fail_obs, double* S_pass_obs )
9 {
10 /*--------------------------------------------------------------------------+
11  | Description: Log-likelihood Ratio for Binomial PDF |
12  +--------------------------------------------------------------------------+
13  | Input to this function |
14  +--------------------------------------------------------------------------+
15  |int Nentries : The number of attempts |
16  |int Nfailures : The number of failures |
17  |double epsilon_max, : maximum allowed failure rate fraction |
18  |double* S_fail_obs : uninitialised Significance of failure |
19  |double* S_pass_obs : uninitialised Significance of Success |
20  +--------------------------------------------------------------------------+
21  | Return values for this function |
22  +--------------------------------------------------------------------------+
23  |double* S_fail_obs : the observed Significance of failure |
24  |double* S_pass_obs : the observed Significance of Success |
25  +--------------------------------------------------------------------------+
26  | Author: Richard Cavanaugh, University of Florida |
27  | email: Richard.Cavanaugh@cern.ch |
28  | Creation Date: 11.July.2005 |
29  | Last Modified: 17.Jan.2006 |
30  | Comments: |
31  +--------------------------------------------------------------------------*/
32  long N = Nentries, n = Nfailures;
33  if( n == 0 ) n = 1; //protect against no failures: approx. 0 by 1
34  if( n == N ) n -= 1; //protect against all failures: approx. n by (n - 1)
35  double epsilon_meas = (double) n / (double) N;
36 
37  double LogQ =
38  ((double) n ) * ( Log(epsilon_meas) - Log(epsilon_max) ) +
39  ((double) (N - n)) * ( Log(1.0 - epsilon_meas) - Log(1.0 - epsilon_max) );
40 
41  //x-check: var of binomial = epsilon_max * (1 - epsilon_max) / N
42  if( Nentries <= 1 ) //guard against insufficient entries
43  {
44  *S_fail_obs = 0.0;
45  *S_pass_obs = 0.0;
46  }
47  else if( Nfailures == 0 && ( epsilon_max <= 1.0 / (double) Nentries ) )
48  {
49  *S_fail_obs = 0.0;
50  *S_pass_obs = 0.0;
51  }
52  else if( Nfailures == 0 )
53  {
54  *S_fail_obs = 0.0;
55  *S_pass_obs = sqrt( 2.0 * LogQ );
56  }
57  else if( Nfailures == Nentries )
58  {
59  *S_fail_obs = sqrt( 2.0 * LogQ );
60  *S_pass_obs = 0.0;
61  }
62  else if( epsilon_meas >= epsilon_max )
63  {
64  *S_fail_obs = sqrt( 2.0 * LogQ );
65  *S_pass_obs = 0.0;
66  }
67  else
68  {
69  *S_fail_obs = 0.0;
70  *S_pass_obs = sqrt( 2.0 * LogQ );
71  }
72 }
73 //---------------------------------------------------------------------------
74 
75 //---------------------------------------------------------------------------
76 void PoissionLogLikelihoodRatio(double data, double hypothesis,
77  double epsilon_max, double epsilon_min,
78  double* S_fail_obs, double* S_pass_obs )
79 {
80 /*--------------------------------------------------------------------------+
81  | Description: Log-likelihood Ratio for Poission PDF |
82  +--------------------------------------------------------------------------+
83  | Input to this function |
84  +--------------------------------------------------------------------------+
85  |double data, : The observed number of entries |
86  |double sigma, : The uncertainty on, data, the observed entries |
87  |double hypothesis, : The assumed hypothese, tested against data |
88  |double epsilon_max, : Maximum tolerance above fraction of fitted line |
89  |double epsilon_min, : Minimum tolerance below fraction of fitted line |
90  |double* S_fail_obs : uninitialised Significance of failure |
91  |double* S_pass_obs : uninitialised Significance of Success |
92  +--------------------------------------------------------------------------+
93  | Return values for this function |
94  +--------------------------------------------------------------------------+
95  |double* S_fail_obs : the observed Significance of failure |
96  |double* S_pass_obs : the observed Significance of Success |
97  +--------------------------------------------------------------------------+
98  | Author: Richard Cavanaugh, University of Florida |
99  | email: Richard.Cavanaugh@cern.ch |
100  | Creation Date: 14.Jan.2006 |
101  | Last Modified: 16.Jan.2006 |
102  | Comments: |
103  +--------------------------------------------------------------------------*/
104  double tolerance_min = hypothesis*(1.0-epsilon_min);
105  double tolerance_max = hypothesis*(1.0+epsilon_max);
106  *S_pass_obs = 0.0;
107  *S_fail_obs = 0.0;
108  if( data > tolerance_max )
109  {
110  double Nsig = data - tolerance_max;
111  double Nbak = tolerance_max;
112  double LogQ = (double) (Nsig + Nbak) *
113  Log( 1.0 + (double) Nsig / (double) Nbak ) - (double) Nsig;
114  *S_fail_obs = sqrt( 2.0 * LogQ );
115  }
116  else if( tolerance_min < data && data < tolerance_max )
117  {
118  if( data - hypothesis > 0.0 )
119  {
120  double Nsig = tolerance_max - data;
121  double Nbak = tolerance_max;
122  double LogQ = (double) (Nsig + Nbak) *
123  Log( 1.0 + (double) Nsig / (double) Nbak ) - (double) Nsig;
124  *S_pass_obs = sqrt( 2.0 * LogQ );
125  }
126  else
127  {
128  double Nsig = data - tolerance_min;
129  double Nbak = tolerance_min;
130  double LogQ = (double) (Nsig + Nbak) *
131  Log( 1.0 + (double) Nsig / (double) Nbak ) - (double) Nsig;
132  *S_pass_obs = sqrt( 2.0 * LogQ );
133  }
134  }
135  else // data < tolerance_min
136  {
137  double Nsig = tolerance_min - data;
138  double Nbak = tolerance_min;
139  double LogQ = (double) (Nsig + Nbak) *
140  Log( 1.0 + (double) Nsig / (double) Nbak ) - (double) Nsig;
141  *S_fail_obs = sqrt( 2.0 * LogQ );
142  }
143 }
144 //---------------------------------------------------------------------------
void PoissionLogLikelihoodRatio(double data, double hypothesis, double epsilon_max, double epsilon_min, double *S_fail_obs, double *S_pass_obs)
void BinLogLikelihoodRatio(long Nentries, long Nfailures, double epsilon_max, double *S_fail_obs, double *S_pass_obs)
T sqrt(T t)
Definition: SSEVec.h:48
#define N
Definition: blowfish.cc:9