00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <memory>
00012
00013 #ifndef ROOT_Math_GoFTest
00014 #define ROOT_Math_GoFTest
00015
00016 #ifndef ROOT_Math_WrappedFunction
00017 #include "Math/WrappedFunction.h"
00018 #endif
00019 #ifndef ROOT_TMath
00020 #include "TMath.h"
00021 #endif
00022
00023
00024
00025
00026
00027 namespace ROOT {
00028 namespace Math {
00029
00030 class GoFTest {
00031 public:
00032
00033 enum EDistribution {
00034 kUndefined,
00035 kUserDefined,
00036 kGaussian,
00037 kLogNormal,
00038 kExponential
00039 };
00040
00041 enum EUserDistribution {
00042 kCDF,
00043 kPDF
00044 };
00045
00046 enum ETestType {
00047 kAD,
00048 kAD2s,
00049 kKS,
00050 kKS2s
00051 };
00052
00053
00054 GoFTest(UInt_t sample1Size, const Double_t* sample1, UInt_t sample2Size, const Double_t* sample2);
00055
00056
00057 GoFTest(UInt_t sampleSize, const Double_t* sample, EDistribution dist = kUndefined);
00058
00059
00060 template<class Dist>
00061 GoFTest(UInt_t sampleSize, const Double_t* sample, Dist& dist, EUserDistribution userDist = kPDF,
00062 Double_t xmin = 1, Double_t xmax = 0)
00063 {
00064 Instantiate(sample, sampleSize);
00065 SetUserDistribution<Dist>(dist, userDist, xmin, xmax);
00066 }
00067
00068
00069 GoFTest(UInt_t sampleSize, const Double_t* sample, const IGenFunction& dist, EUserDistribution userDist = kPDF,
00070 Double_t xmin = 1, Double_t xmax = 0)
00071 {
00072 Instantiate(sample, sampleSize);
00073 SetUserDistribution(dist, userDist, xmin, xmax);
00074 }
00075
00076
00077 template<class Dist>
00078 void SetUserDistribution(Dist& dist, EUserDistribution userDist = kPDF, Double_t xmin = 1, Double_t xmax = 0) {
00079 WrappedFunction<Dist&> wdist(dist);
00080 SetDistributionFunction(wdist, userDist, xmin, xmax);
00081 }
00082
00083
00084 void SetUserDistribution(const IGenFunction& dist, GoFTest::EUserDistribution userDist = kPDF, Double_t xmin = 1, Double_t xmax = 0) {
00085 SetDistributionFunction(dist, userDist, xmin, xmax);
00086 }
00087
00088
00089 template<class Dist>
00090 void SetUserPDF(Dist& pdf, Double_t xmin = 1, Double_t xmax = 0) {
00091 SetUserDistribution<Dist>(pdf, kPDF, xmin, xmax);
00092 }
00093
00094
00095 void SetUserPDF(const IGenFunction& pdf, Double_t xmin = 1, Double_t xmax = 0) {
00096 SetUserDistribution(pdf, kPDF, xmin, xmax);
00097 }
00098
00099
00100
00101
00102 template<class Dist>
00103 void SetUserCDF(Dist& cdf, Double_t xmin = 1, Double_t xmax = 0) {
00104 SetUserDistribution<Dist>(cdf, kCDF, xmin, xmax);
00105 }
00106
00107
00108 void SetUserCDF(const IGenFunction& cdf, Double_t xmin = 1, Double_t xmax = 0) {
00109 SetUserDistribution(cdf, kCDF, xmin, xmax);
00110 }
00111
00112
00113
00114 void SetDistribution(EDistribution dist);
00115
00116
00117 virtual ~GoFTest();
00118
00119
00120
00121
00122
00123
00124 void AndersonDarling2SamplesTest(Double_t& pvalue, Double_t& testStat) const;
00125 Double_t AndersonDarling2SamplesTest(const Char_t* option = "p") const;
00126
00127
00128
00129
00130
00131
00132
00133
00134 void AndersonDarlingTest(Double_t& pvalue, Double_t& testStat) const;
00135 Double_t AndersonDarlingTest(const Char_t* option = "p") const;
00136
00137
00138
00139
00140
00141
00142 void KolmogorovSmirnov2SamplesTest(Double_t& pvalue, Double_t& testStat) const;
00143 Double_t KolmogorovSmirnov2SamplesTest(const Char_t* option = "p") const;
00144
00145
00146
00147
00148
00149
00150 void KolmogorovSmirnovTest(Double_t& pvalue, Double_t& testStat) const;
00151 Double_t KolmogorovSmirnovTest(const Char_t* option = "p") const;
00152
00153
00154 void operator()(ETestType test, Double_t& pvalue, Double_t& testStat) const;
00155 Double_t operator()(ETestType test = kAD, const Char_t* option = "p") const;
00156
00157 private:
00158
00159 GoFTest();
00160 GoFTest(GoFTest& gof);
00161 GoFTest operator=(GoFTest& gof);
00162
00163 std::auto_ptr<IGenFunction> fCDF;
00164
00165
00166 EDistribution fDist;
00167
00168 Double_t fMean;
00169 Double_t fSigma;
00170
00171 std::vector<Double_t> fCombinedSamples;
00172
00173 std::vector<std::vector<Double_t> > fSamples;
00174
00175 Bool_t fTestSampleFromH0;
00176
00177 void SetCDF();
00178 void SetDistributionFunction(const IGenFunction& cdf, Bool_t isPDF, Double_t xmin, Double_t xmax);
00179
00180 void Instantiate(const Double_t* sample, UInt_t sampleSize);
00181
00182
00183 Double_t LogNormalCDF(Double_t x) const;
00184 Double_t GaussianCDF(Double_t x) const;
00185 Double_t ExponentialCDF(Double_t x) const;
00186
00187 Double_t GetSigmaN(UInt_t N) const;
00188
00189 Double_t InterpolatePValues(Double_t dA2, Int_t bin) const;
00190
00191 Double_t PValueAD2Samples(Double_t& A2, UInt_t N) const;
00192
00193 Double_t PValueAD1Sample(Double_t A2) const;
00194
00195 void LogSample();
00196
00197 void SetSamples(std::vector<const Double_t*> samples, const std::vector<UInt_t> samplesSizes);
00198
00199 void SetParameters();
00200 };
00201
00202
00203 }
00204 }
00205 #endif