Go to the documentation of this file.00001 #include "DQMServices/Core/src/QStatisticalTests.h"
00002 #include <TMath.h>
00003
00004 using namespace TMath;
00005
00006
00007 void BinLogLikelihoodRatio(long Nentries, long Nfailures, double epsilon_max,
00008 double* S_fail_obs, double* S_pass_obs )
00009 {
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 long N = Nentries, n = Nfailures;
00033 if( n == 0 ) n = 1;
00034 if( n == N ) n -= 1;
00035 double epsilon_meas = (double) n / (double) N;
00036
00037 double LogQ =
00038 ((double) n ) * ( Log(epsilon_meas) - Log(epsilon_max) ) +
00039 ((double) (N - n)) * ( Log(1.0 - epsilon_meas) - Log(1.0 - epsilon_max) );
00040
00041
00042 if( Nentries <= 1 )
00043 {
00044 *S_fail_obs = 0.0;
00045 *S_pass_obs = 0.0;
00046 }
00047 else if( Nfailures == 0 && ( epsilon_max <= 1.0 / (double) Nentries ) )
00048 {
00049 *S_fail_obs = 0.0;
00050 *S_pass_obs = 0.0;
00051 }
00052 else if( Nfailures == 0 )
00053 {
00054 *S_fail_obs = 0.0;
00055 *S_pass_obs = sqrt( 2.0 * LogQ );
00056 }
00057 else if( Nfailures == Nentries )
00058 {
00059 *S_fail_obs = sqrt( 2.0 * LogQ );
00060 *S_pass_obs = 0.0;
00061 }
00062 else if( epsilon_meas >= epsilon_max )
00063 {
00064 *S_fail_obs = sqrt( 2.0 * LogQ );
00065 *S_pass_obs = 0.0;
00066 }
00067 else
00068 {
00069 *S_fail_obs = 0.0;
00070 *S_pass_obs = sqrt( 2.0 * LogQ );
00071 }
00072 }
00073
00074
00075
00076 void PoissionLogLikelihoodRatio(double data, double hypothesis,
00077 double epsilon_max, double epsilon_min,
00078 double* S_fail_obs, double* S_pass_obs )
00079 {
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 double tolerance_min = hypothesis*(1.0-epsilon_min);
00105 double tolerance_max = hypothesis*(1.0+epsilon_max);
00106 *S_pass_obs = 0.0;
00107 *S_fail_obs = 0.0;
00108 if( data > tolerance_max )
00109 {
00110 double Nsig = data - tolerance_max;
00111 double Nbak = tolerance_max;
00112 double LogQ = (double) (Nsig + Nbak) *
00113 Log( 1.0 + (double) Nsig / (double) Nbak ) - (double) Nsig;
00114 *S_fail_obs = sqrt( 2.0 * LogQ );
00115 }
00116 else if( tolerance_min < data && data < tolerance_max )
00117 {
00118 if( data - hypothesis > 0.0 )
00119 {
00120 double Nsig = tolerance_max - data;
00121 double Nbak = tolerance_max;
00122 double LogQ = (double) (Nsig + Nbak) *
00123 Log( 1.0 + (double) Nsig / (double) Nbak ) - (double) Nsig;
00124 *S_pass_obs = sqrt( 2.0 * LogQ );
00125 }
00126 else
00127 {
00128 double Nsig = data - tolerance_min;
00129 double Nbak = tolerance_min;
00130 double LogQ = (double) (Nsig + Nbak) *
00131 Log( 1.0 + (double) Nsig / (double) Nbak ) - (double) Nsig;
00132 *S_pass_obs = sqrt( 2.0 * LogQ );
00133 }
00134 }
00135 else
00136 {
00137 double Nsig = tolerance_min - data;
00138 double Nbak = tolerance_min;
00139 double LogQ = (double) (Nsig + Nbak) *
00140 Log( 1.0 + (double) Nsig / (double) Nbak ) - (double) Nsig;
00141 *S_fail_obs = sqrt( 2.0 * LogQ );
00142 }
00143 }
00144