13 std::vector<Double_t> xx(
n);
14 std::vector<Double_t> ww(
n);
16 double true_mean = 10;
17 double true_sigma = 1;
18 double eps1 = 5*true_sigma/
sqrt(
double(
n));
19 double eps2 = 5*true_sigma/
sqrt(
double(2.*
n));
23 for (
Int_t i = 0; i <
n; i++) {
24 xx[i] = rand3.
Gaus(true_mean, true_sigma);
25 ww[i] = rand3.
Uniform(0.01, 3.00);
32 printf(
"\nTest without using weights : ");
36 if (!
TMath::AreEqualAbs(st0.GetMean(),true_mean, eps1) ) {
Error(
"TestTStatistic-GetMean",
"Different value obtained for the unweighted data"); error =
true; }
37 if (!
TMath::AreEqualAbs(st0.GetRMS(),true_sigma, eps2) ) {
Error(
"TestTStatistic-GetRMS",
"Different value obtained for the unweighted data"); error =
true; }
39 if (error) printf(
"Failed\n");
47 printf(
"\nTest using TMath: ");
51 double rms =
TMath::RMS(xx.begin(), xx.end() );
53 if (!
TMath::AreEqualAbs(mean,true_mean, eps1) ) {
Error(
"TestTStatistic::TMath::Mean",
"Different value obtained for the unweighted data"); error =
true; }
54 if (!
TMath::AreEqualAbs(rms,true_sigma, eps2) ) {
Error(
"TestTStatistic::TMath::RMS",
"Different value obtained for the unweighted data"); error =
true; }
56 if (error) printf(
"Failed\n");
60 printf(
" TMATH mu = %.5g +- %.4g \t RMS = %.5g \n",mean, rms/
sqrt(
double(xx.size()) ), rms);
64 printf(
"\nTest using Weights : ");
67 TStatistic st1(
"st1", n, xx.data(), ww.data());
70 if (!
TMath::AreEqualAbs(st1.GetMean(),true_mean, eps1) ) {
Error(
"TestTStatistic-GetMean",
"Different value obtained for the weighted data"); error =
true; }
71 if (!
TMath::AreEqualAbs(st1.GetRMS(),true_sigma, eps2) ) {
Error(
"TestTStatistic-GetRMS",
"Different value obtained for the weighted data"); error =
true; }
73 if (error) printf(
"Failed\n");
82 printf(
"\nTest incremental filling : ");
86 for (
Int_t i = 0; i <
n; i++) {
87 st2.
Fill(xx[i], ww[i]);
91 if (!
TMath::AreEqualRel(st1.GetMean(),st2.
GetMean(), 1.E-15) ) {
Error(
"TestTStatistic-GetMean",
"2 Different values obtained for the weighted data"); error =
true; }
92 if (!
TMath::AreEqualRel(st1.GetRMS(),st2.
GetRMS(), 1.E-15) ) {
Error(
"TestTStatistic-GetRMS",
"2 Different values obtained for the weighted data"); error =
true; }
94 if (error) printf(
"Failed\n");
103 int n1 = rand3.
Uniform(10,n-10);
106 std::sort(xx.begin(), xx.end() );
109 printf(
"\nTest merge : ");
114 for (
int i = 0; i <
n ; ++i) {
115 if (i < n1) sta.
Fill(xx[i],ww[i] );
116 else stb.
Fill(xx[i],ww[i] );
123 if (!
TMath::AreEqualAbs(sta.
GetMean(),true_mean, eps1) ) {
Error(
"TestTStatistic-GetMean",
"Different value obtained for the merged data"); error =
true; }
124 if (!
TMath::AreEqualAbs(sta.
GetRMS(),true_sigma, eps2) ) {
Error(
"TestTStatistic-GetRMS",
"Different value obtained for the merged data"); error =
true; }
126 if (error) printf(
"Failed\n");
133 printf(
"\nTest sorted data : ");
136 TStatistic st3(
"st3", n, xx.data(), ww.data());
139 if (!
TMath::AreEqualAbs(st3.GetMean(), sta.
GetMean(), 1.E-10 ) ) {
Error(
"TestTStatistic-GetMean",
"Different value obtained for the sorted data"); error =
true; }
140 if (!
TMath::AreEqualAbs(st3.GetRMS(), sta.
GetRMS() , 1.E-10 ) ) {
Error(
"TestTStatistic-GetRMS",
"Different value obtained for the sorted data"); error =
true; }
142 if (error) printf(
"Failed\n");
151 printf(
"\nTest TMath with weights : ");
154 double meanw =
TMath::Mean(xx.begin(), xx.end(), ww.begin() );
155 double rmsw =
TMath::RMS(xx.begin(), xx.end(), ww.begin() );
159 if (!
TMath::AreEqualAbs(meanw,true_mean, eps1) ) {
Error(
"TestTStatistic::TMath::Mean",
"Different value obtained for the weighted data"); error =
true; }
160 if (!
TMath::AreEqualAbs(rmsw,true_sigma, eps2) ) {
Error(
"TestTStatistic::TMath::RMS",
"Different value obtained for the weighted data"); error =
true; }
162 if (error) printf(
"Failed\n");
166 printf(
" TMATH mu = %.5g +- %.4g \t RMS = %.5g \n",meanw, rmsw/
sqrt(neff ), rmsw);
172 int main(
int argc,
char **argv)
175 for (
Int_t i=1 ; i<argc ; i++) {
176 std::string arg = argv[i] ;
181 std::cout <<
"Usage: " << argv[0] <<
" [-v]\n";
182 std::cout <<
" where:\n";
183 std::cout <<
" -v : verbose mode";
184 std::cout << std::endl;
Random number generator class based on M.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
void Print(Option_t *="") const
This method must be overridden when a class wants to print itself.
Double_t RMS(Long64_t n, const T *a, const Double_t *w=0)
void Stop()
Stop the stopwatch.
Statistical variable, defined by its mean and variance (RMS).
void Error(const char *location, const char *msgfmt,...)
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)
Bool_t AreEqualRel(Double_t af, Double_t bf, Double_t relPrec)
Double_t Mean(Long64_t n, const T *a, const Double_t *w=0)
int main(int argc, char **argv)
void Fill(Double_t val, Double_t w=1.)
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Int_t Merge(TCollection *in)
void testTStatistic(Int_t n=10000)
virtual void Add(TObject *obj)