106 cout <<
"*Zeta(x)* Wrong argument x = " << x << endl;
112 for (Int_t i=1; i<=nterms; i++)
138 cout <<
"*Gamma(z)* Wrong argument z = " << z << endl;
170 cout <<
"*Gamma(a,x)* Invalid argument a = " << a << endl;
176 if (x<0) cout <<
"*Gamma(a,x)* Invalid argument x = " << x << endl;
189 if (mode) value=value*
Gamma(a);
212 cout <<
"*LnGamma(z)* Wrong argument z = " << z << endl;
218 c[0]= 2.5066282746310005;
219 c[1]= 76.18009172947146;
220 c[2]=-86.50532032941677;
221 c[3]= 24.01409824083091;
222 c[4]= -1.231739572450155;
223 c[5]= 0.1208650973866179e-2;
224 c[6]= -0.5395239384953e-5;
229 tmp=(x+0.5)*log(tmp)-tmp;
230 Double_t ser=1.000000000190015;
231 for (Int_t i=1; i<7; i++)
236 Double_t v=tmp+log(c[0]*ser/x);
265 if (mode) value=value+
LnGamma(a);
290 cout <<
"*GamSer(a,x)* Invalid argument a = " << a << endl;
296 if (x<0) cout <<
"*GamSer(a,x)* Invalid argument x = " << x << endl;
304 for (Int_t n=1; n<=itmax; n++)
309 if (fabs(del)<fabs(sum*eps))
break;
310 if (n==itmax) cout <<
"*GamSer(a,x)* a too large or itmax too small" << endl;
312 Double_t v=sum*exp(-x+a*log(x)-gln);
332 Double_t fpmin=1.e-30;
336 cout <<
"*GamCf(a,x)* Invalid argument a = " << a << endl;
342 if (x<0) cout <<
"*GamCf(a,x)* Invalid argument x = " << x << endl;
352 for (Int_t i=1; i<=itmax; i++)
354 an=double(-i)*(double(i)-a);
357 if (fabs(d)<fpmin) d=fpmin;
359 if (fabs(c)<fpmin) c=fpmin;
363 if (fabs(del-1.)<eps)
break;
364 if (i==itmax) cout <<
"*GamCf(a,x)* a too large or itmax too small" << endl;
366 Double_t v=exp(-x+a*log(x)-gln)*h;
399 const Double_t ka1=-1.26551223, ka2=1.00002368,
400 ka3= 0.37409196, ka4=0.09678418,
401 ka5=-0.18628806, ka6=0.27886807,
402 ka7=-1.13520398, ka8=1.48851587,
403 ka9=-0.82215223, ka10=0.17087277;
409 if (z <= 0.)
return v;
411 Double_t t=1./(1.+0.5*z);
414 +ka1+t*(ka2+t*(ka3+t*(ka4+t*(ka5+t*(ka6+t*(ka7+t*(ka8+t*(ka9+t*ka10)))))))));
455 if (ndf <= 0)
return 0;
474 if (ndf==1) v=1.-
Erf(sqrt(chi2)/sqrt(2.));
480 Double_t q=sqrt(2.*chi2)-sqrt(
double(2*ndf-1));
481 if (q>0.) v=0.5*(1.-
Erf(q/sqrt(2.)));
489 Double_t a=double(ndf)/2.;
514 const Double_t kp1=1.0, kp2=3.5156229, kp3=3.0899424,
515 kp4=1.2067492, kp5=0.2659732, kp6=3.60768e-2, kp7=4.5813e-3;
517 const Double_t kq1= 0.39894228, kq2= 1.328592e-2, kq3= 2.25319e-3,
518 kq4=-1.57565e-3, kq5= 9.16281e-3, kq6=-2.057706e-2,
519 kq7= 2.635537e-2, kq8=-1.647633e-2, kq9= 3.92377e-3;
523 Double_t y=0,result=0;
528 result=kp1+y*(kp2+y*(kp3+y*(kp4+y*(kp5+y*(kp6+y*kp7)))));
533 result=(exp(ax)/sqrt(ax))
534 *(kq1+y*(kq2+y*(kq3+y*(kq4+y*(kq5+y*(kq6+y*(kq7+y*(kq8+y*kq9))))))));
557 const Double_t kp1=-0.57721566, kp2=0.42278420, kp3=0.23069756,
558 kp4= 3.488590e-2, kp5=2.62698e-3, kp6=1.0750e-4, kp7=7.4e-6;
560 const Double_t kq1= 1.25331414, kq2=-7.832358e-2, kq3= 2.189568e-2,
561 kq4=-1.062446e-2, kq5= 5.87872e-3, kq6=-2.51540e-3, kq7=5.3208e-4;
565 cout <<
" *BesselK0* Invalid argument x = " << x << endl;
569 Double_t y=0,result=0;
575 +(kp1+y*(kp2+y*(kp3+y*(kp4+y*(kp5+y*(kp6+y*kp7))))));
580 result=(exp(-x)/sqrt(x))
581 *(kq1+y*(kq2+y*(kq3+y*(kq4+y*(kq5+y*(kq6+y*kq7))))));
604 const Double_t kp1=0.5, kp2=0.87890594, kp3=0.51498869,
605 kp4=0.15084934, kp5=2.658733e-2, kp6=3.01532e-3, kp7=3.2411e-4;
607 const Double_t kq1= 0.39894228, kq2=-3.988024e-2, kq3=-3.62018e-3,
608 kq4= 1.63801e-3, kq5=-1.031555e-2, kq6= 2.282967e-2,
609 kq7=-2.895312e-2, kq8= 1.787654e-2, kq9=-4.20059e-3;
613 Double_t y=0,result=0;
618 result=x*(kp1+y*(kp2+y*(kp3+y*(kp4+y*(kp5+y*(kp6+y*kp7))))));
623 result=(exp(ax)/sqrt(ax))
624 *(kq1+y*(kq2+y*(kq3+y*(kq4+y*(kq5+y*(kq6+y*(kq7+y*(kq8+y*kq9))))))));
625 if (x < 0) result=-result;
648 const Double_t kp1= 1., kp2= 0.15443144, kp3=-0.67278579,
649 kp4=-0.18156897, kp5=-1.919402e-2, kp6=-1.10404e-3, kp7=-4.686e-5;
651 const Double_t kq1= 1.25331414, kq2= 0.23498619, kq3=-3.655620e-2,
652 kq4= 1.504268e-2, kq5=-7.80353e-3, kq6= 3.25614e-3, kq7=-6.8245e-4;
656 cout <<
" *BesselK1* Invalid argument x = " << x << endl;
660 Double_t y=0,result=0;
666 +(1./x)*(kp1+y*(kp2+y*(kp3+y*(kp4+y*(kp5+y*(kp6+y*kp7))))));
671 result=(exp(-x)/sqrt(x))
672 *(kq1+y*(kq2+y*(kq3+y*(kq4+y*(kq5+y*(kq6+y*kq7))))));
697 cout <<
" *BesselK* Invalid argument(s) (n,x) = (" << n <<
" , " << x <<
")" << endl;
710 for (Int_t j=1; j<n; j++)
712 bkp=bkm+double(j)*tox*bk;
738 Double_t bigno=1.e10, bigni=1.e-10;
742 cout <<
" *BesselI* Invalid argument (n,x) = (" << n <<
" , " << x <<
")" << endl;
750 if (fabs(x) < 1.e-10)
return 0;
752 Double_t tox=2./fabs(x);
753 Double_t bip=0,bim=0;
756 Int_t m=2*((n+int(sqrt(
float(iacc*n)))));
757 for (Int_t j=m; j<=1; j--)
759 bim=bip+double(j)*tox*bi;
762 if (fabs(bi) > bigno)
768 if (j==n) result=bip;
772 if ((x < 0) && (n%2 == 1)) result=-result;
790 TF1 pdf(
"Chi2PDF",
"1./(TMath::Gamma([0]/2.)*pow(2,[0]/2.))*pow(x,[0]/2.-1.)*exp(-x/2.)");
791 pdf.SetParName(0,
"ndf");
792 pdf.SetParameter(0,ndf);
793 TString title=
"#chi^{2} PDF (ndf=";
795 title+=
");#chi^{2};p(#chi^{2}|ndf)";
796 pdf.SetTitle(title.Data());
813 TF1 cdf(
"Chi2CDF",
"1.-TMath::Prob(x,[0])");
814 cdf.SetParName(0,
"ndf");
815 cdf.SetParameter(0,ndf);
816 TString title=
"#chi^{2} CDF (ndf=";
818 title+=
");#chi^{2};CDF for p(#chi^{2}|ndf)";
819 cdf.SetTitle(title.Data());
846 TF1 pdf(
"StudentPDF",
"(TMath::Gamma(([0]+1.)/2.)/(sqrt(pi*[0])*TMath::Gamma([0]/2.)))*pow(1.+x*x/[0],-([0]+1.)/2.)");
847 pdf.SetParName(0,
"ndf");
848 pdf.SetParameter(0,ndf);
849 TString title=
"Student's T PDF (ndf=";
851 title+=
");T;p(T|ndf)";
852 pdf.SetTitle(title.Data());
878 TF1 cdf(
"StudentCDF",
"TMath::StudentI(x,[0])");
879 cdf.SetParName(0,
"ndf");
880 cdf.SetParameter(0,ndf);
881 TString title=
"Student's T CDF (ndf=";
883 title+=
");T;CDF for p(T|ndf)";
884 cdf.SetTitle(title.Data());
911 "(TMath::Gamma(([0]+[1])/2.)/(TMath::Gamma([0]/2.)*TMath::Gamma([1]/2.)))*pow([0]/[1],[0]/2.)*pow(x,([0]-2.)/2.)/pow(1.+x*[0]/[1],([0]+[1])/2.)");
912 pdf.SetParName(0,
"ndf1");
913 pdf.SetParameter(0,ndf1);
914 pdf.SetParName(1,
"ndf2");
915 pdf.SetParameter(1,ndf2);
916 TString title=
"F(ratio) PDF (ndf1=";
920 title+=
");F;p(F|ndf1,ndf2)";
921 pdf.SetTitle(title.Data());
945 TF1 cdf(
"FratioCDF",
"TMath::FDistI(x,[0],[1])");
946 cdf.SetParName(0,
"ndf1");
947 cdf.SetParameter(0,ndf1);
948 cdf.SetParName(1,
"ndf2");
949 cdf.SetParameter(1,ndf2);
950 TString title=
"F(ratio) CDF (ndf1=";
954 title+=
");F;CDF for p(F|ndf1,ndf2)";
955 cdf.SetTitle(title.Data());
977 TF1 pdf(
"BinomialPDF",
"TMath::Binomial(int([0]),int(x))*pow([1],int(x))*pow(1.-[1],int([0])-int(x))");
978 pdf.SetParName(0,
"n");
979 pdf.SetParameter(0,n);
980 pdf.SetParName(1,
"p");
981 pdf.SetParameter(1,p);
982 TString title=
"Binomial PDF for n=";
984 title+=
" and p=%-10.3g";
985 title+=
";k;p(k|n,p)";
986 TString s=title.Format(title.Data(),p);
987 pdf.SetTitle(s.Data());
1007 TF1 cdf(
"BinomialCDF",
"1.-TMath::BetaIncomplete([1],(x+1.),([0]-x))");
1008 cdf.SetParName(0,
"n");
1009 cdf.SetParameter(0,n);
1010 cdf.SetParName(1,
"p");
1011 cdf.SetParameter(1,p);
1012 TString title=
"Binomial CDF for n=";
1014 title+=
" and p=%-10.3g";
1015 title+=
";k;CDF for p(k|n,p)";
1016 TString s=title.Format(title.Data(),p);
1017 cdf.SetTitle(s.Data());
1039 TF1 pdf(
"NegBinomialnPDF",
"TMath::Binomial(int(x)-1,int([0])-1)*pow([1],int([0]))*pow(1.-[1],int(x)-int([0]))");
1040 pdf.SetParName(0,
"k");
1041 pdf.SetParameter(0,k);
1042 pdf.SetParName(1,
"p");
1043 pdf.SetParameter(1,p);
1044 TString title=
"Negative Binomial PDF for k=";
1046 title+=
" and p=%-10.3g";
1047 title+=
";Number of trials n;p(n|k,p)";
1048 TString s=title.Format(title.Data(),p);
1049 pdf.SetTitle(s.Data());
1069 TF1 cdf(
"NegBinomialnCDF",
"TMath::BetaIncomplete([1],[0],x-[0]+1.)");
1070 cdf.SetParName(0,
"k");
1071 cdf.SetParameter(0,k);
1072 cdf.SetParName(1,
"p");
1073 cdf.SetParameter(1,p);
1074 TString title=
"Negative Binomial CDF for k=";
1076 title+=
" and p=%-10.3g";
1077 title+=
";Number of trials n;CDF for p(n|k,p)";
1078 TString s=title.Format(title.Data(),p);
1079 cdf.SetTitle(s.Data());
1103 TF1 pdf(
"NegBinomialxPDF",
"TMath::Binomial(int(x)+[0]-1,int([0])-1)*pow([1],int([0]))*pow(1.-[1],int(x))");
1104 pdf.SetParName(0,
"k");
1105 pdf.SetParameter(0,k);
1106 pdf.SetParName(1,
"p");
1107 pdf.SetParameter(1,p);
1108 TString title=
"Negative Binomial PDF for k=";
1110 title+=
" and p=%-10.3g";
1111 title+=
";Number of failures x;p(x|k,p)";
1112 TString s=title.Format(title.Data(),p);
1113 pdf.SetTitle(s.Data());
1135 TF1 cdf(
"NegBinomialxCDF",
"TMath::BetaIncomplete([1],[0],x+1.)");
1136 cdf.SetParName(0,
"k");
1137 cdf.SetParameter(0,k);
1138 cdf.SetParName(1,
"p");
1139 cdf.SetParameter(1,p);
1140 TString title=
"Negative Binomial CDF for k=";
1142 title+=
" and p=%-10.3g";
1143 title+=
";Number of failures x;CDF for p(x|k,p)";
1144 TString s=title.Format(title.Data(),p);
1145 cdf.SetTitle(s.Data());
1166 TF1 pdf(
"PoissPDFmu",
"exp(-[0])*pow([0],int(x))/TMath::Factorial(int(x))");
1167 pdf.SetParName(0,
"mu");
1168 pdf.SetParameter(0,mu);
1169 TString title=
"Poisson PDF for #mu=%-10.3g";
1170 title+=
";n;p(n|#mu)";
1171 TString s=title.Format(title.Data(),mu);
1172 pdf.SetTitle(s.Data());
1191 TF1 cdf(
"PoissCDFmu",
"1.-TMath::Gamma(x,[0])");
1192 cdf.SetParName(0,
"mu");
1193 cdf.SetParameter(0,mu);
1194 TString title=
"Poisson PDF for #mu=%-10.3g";
1195 title+=
";n;CDF for p(n|#mu)";
1196 TString s=title.Format(title.Data(),mu);
1197 cdf.SetTitle(s.Data());
1218 TF1 pdf(
"PoissPDFrdt",
"exp(-[0]*[1])*pow(([0]*[1]),int(x))/TMath::Factorial(int(x))");
1219 pdf.SetParName(0,
"r");
1220 pdf.SetParameter(0,r);
1221 pdf.SetParName(1,
"dt");
1222 pdf.SetParameter(1,dt);
1223 TString title=
"Poisson PDF for r=%-10.3g";
1224 title+=
" dt=%-10.3g";
1225 title+=
";n;p(n|r,dt)";
1226 TString s=title.Format(title.Data(),r,dt);
1227 pdf.SetTitle(s.Data());
1246 TF1 cdf(
"PoissCDFrdt",
"1.-TMath::Gamma(x,[0]*[1])");
1247 cdf.SetParName(0,
"r");
1248 cdf.SetParameter(0,r);
1249 cdf.SetParName(1,
"dt");
1250 cdf.SetParameter(1,dt);
1251 TString title=
"Poisson CDF for r=%-10.3g";
1252 title+=
" dt=%-10.3g";
1253 title+=
";n;CDF for p(n|r,dt)";
1254 TString s=title.Format(title.Data(),r,dt);
1255 cdf.SetTitle(s.Data());
1278 TF1 pdf(
"PoissDtPDF",
"exp(-[0]*x)*pow(([0]),[1])*pow(x,([1]-1.))/TMath::Factorial(int([1]-1.))");
1279 pdf.SetParName(0,
"r");
1280 pdf.SetParameter(0,r);
1281 pdf.SetParName(1,
"n");
1282 pdf.SetParameter(1,n);
1283 TString title=
"Poisson related dt PDF for n=";
1285 title+=
" and r=%-10.3g";
1286 title+=
";dt;p(dt|r,n)";
1287 TString s=title.Format(title.Data(),r);
1288 pdf.SetTitle(s.Data());
1309 TF1 cdf(
"PoissDtCDF",
"TMath::Gamma([1],[0]*x)");
1310 cdf.SetParName(0,
"r");
1311 cdf.SetParameter(0,r);
1312 cdf.SetParName(1,
"n");
1313 cdf.SetParameter(1,n);
1314 TString title=
"Poisson related dt CDF for n=";
1316 title+=
" and r=%-10.3g";
1317 title+=
";dt;CDF for p(dt|r,n)";
1318 TString s=title.Format(title.Data(),r);
1319 cdf.SetTitle(s.Data());
1343 TF1 pdf(
"GammaDtPDF",
"exp(-[0]*x)*pow([0],[1])*pow(x,([1]-1.))/TMath::Gamma([1])");
1344 pdf.SetParName(0,
"r");
1345 pdf.SetParameter(0,r);
1346 pdf.SetParName(1,
"z");
1347 pdf.SetParameter(1,z);
1348 TString title=
"Gamma related dt PDF for r=%-10.3g";
1349 title+=
" z=%-10.3g";
1350 title+=
";dt;p(dt|r,z)";
1351 TString s=title.Format(title.Data(),r,z);
1352 pdf.SetTitle(s.Data());
1373 TF1 pdf(
"GaussPDF",
"TMath::Gaus(x,[0],[1],1)");
1374 pdf.SetParName(0,
"mu");
1375 pdf.SetParameter(0,mu);
1376 pdf.SetParName(1,
"sigma");
1377 pdf.SetParameter(1,sigma);
1378 TString title=
"Gaussian PDF for #mu=%-10.3g";
1379 title+=
" #sigma=%-10.3g";
1380 title+=
";x;p(x|#mu,#sigma)";
1381 TString s=title.Format(title.Data(),mu,sigma);
1382 pdf.SetTitle(s.Data());
1401 TF1 cdf(
"GaussCDF",
"0.5*(1.+TMath::Erf((x-[0])/([1]*sqrt(2.))))");
1402 cdf.SetParName(0,
"mu");
1403 cdf.SetParameter(0,mu);
1404 cdf.SetParName(1,
"sigma");
1405 cdf.SetParameter(1,sigma);
1406 TString title=
"Gaussian CDF for #mu=%-10.3g";
1407 title+=
" #sigma=%-10.3g";
1408 title+=
";x;CDF for p(x|#mu,#sigma)";
1409 TString s=title.Format(title.Data(),mu,sigma);
1410 cdf.SetTitle(s.Data());
1458 TF1 pdf(
"RayleighPDF",
"x*exp(-pow(x,2)/(2.*pow([0],2)))/pow([0],2)");
1459 pdf.SetParName(0,
"sigma");
1460 pdf.SetParameter(0,sigma);
1462 title.Form(
"Rayleigh PDF for sigma=%-g;r;p(r|sigma)",sigma);
1463 pdf.SetTitle(title);
1480 TF1 cdf(
"RayleighCDF",
"1.-exp(-pow(x,2)/(2.*pow([0],2)))");
1481 cdf.SetParName(0,
"sigma");
1482 cdf.SetParameter(0,sigma);
1484 title.Form(
"Rayleigh CDF for sigma=%-g;r;CDF for p(r|sigma)",sigma);
1485 cdf.SetTitle(title);
1531 TF1 pdf(
"3D-RayleighPDF",
"2*pow(x,2)*pow(2*pi,-0.5)*exp(-pow(x,2)/(2.*pow([0],2)))/pow([0],3)");
1532 pdf.SetParName(0,
"sigma");
1533 pdf.SetParameter(0,sigma);
1535 title.Form(
"3D-Rayleigh PDF for sigma=%-g;r;p(r|sigma)",sigma);
1536 pdf.SetTitle(title);
1579 Double_t xmin=f.GetXmin();
1580 Double_t xmax=f.GetXmax();
1584 if (name==
"mode") val=f.GetMaximumX(xmin,xmax);
1585 if (name==
"mean") val=f.Mean(xmin,xmax);
1586 if (name==
"var") val=f.Variance(xmin,xmax);
1589 val=f.Variance(xmin,xmax);
1601 Double_t p[1]={0.5};
1603 Int_t nq=f.GetQuantiles(1,q,p);
1606 if (name==
"mom" || name==
"cmom")
1610 printf(
" *NcMath::GetStatistic* Inconsistent input n=%-i for statistic %-s. \n",n,name.Data());
1613 if (name==
"mom") val=f.Moment(n,xmin,xmax);
1614 if (name==
"cmom") val=f.CentralMoment(n,xmin,xmax);
1616 if (name==
"skew" || name==
"kurt")
1619 if (name==
"skew" && std>0) val=f.CentralMoment(3,xmin,xmax)/pow(std,3);
1620 if (name==
"kurt" && std>0) val=-3.+f.CentralMoment(4,xmin,xmax)/pow(std,4);
1626 printf(
" *NcMath::GetStatistic* Inconsistent input n=%-i for statistic %-s. \n",n,name.Data());
1630 if (n==1) vref=f.Mean(xmin,xmax);
1631 Double_t step=fabs(xmax-xmin)/double(npx);
1638 weight=fabs(f.Eval(x));
1639 val+=weight*fabs(vref-x);
1668 TString ftitle=f.GetTitle();
1671 TString saxes=
";x;CDF";
1672 Int_t j1=ftitle.First(
';');
1676 Int_t j2=ftitle.Last(
';');
1679 ftitle.Insert(j2+1,
"CDF for ");
1687 gtitle.Form(
"Original function : %-s%-s",ftitle.Data(),saxes.Data());
1691 gtitle.Form(
"Original function : f(x)=%-s%-s",(f.GetExpFormula(
"p")).Data(),saxes.Data());
1694 gr.SetTitle(gtitle);
1695 gr.SetDrawOption(
"AL");
1723 val=
Erf(fabs(q-mean)/(sigma*sqrt(2.)));
1727 val=
Erf(fabs(q)/sqrt(2.));
1773 val=
Erfc(fabs(q-mean)/(sigma*sqrt(2.)));
1777 if (isig==1) val=
Erfc(fabs(q)/sqrt(2.));
1778 if (isig==-1) val=(q-mean)/sigma;
1780 if (sides==1 && isig!=-1) val/=2.;
1836 if (ndf<=0)
return 0;
1843 if (chi2<mean) sides=-1;
1849 if (chi2<mean) sides=-2;
1855 Double_t s=sqrt(
double(2*ndf));
1862 val=
Prob(chi2,ndf,mode);
1866 val=1.-
Prob(chi2,ndf,mode);
1870 if (abs(sides)==2) val=val*2.;
1921 if (ndf<=0)
return 0;
1928 if (t<mean) sides=-1;
1934 if (t<mean) sides=-2;
1942 Double_t s=sqrt(ndf/(ndf-2.));
1950 val=1.-TMath::StudentI(t,ndf);
1954 val=TMath::StudentI(t,ndf);
1958 if (abs(sides)==2) val=val*2.;
2013 if (ndf1<=0 || ndf2<=0 || f<=0)
return 0;
2015 Double_t mean=double(ndf2/(ndf2-2));
2020 if (f<mean) sides=-1;
2026 if (f<mean) sides=-2;
2035 Double_t s=sqrt(
double(ndf2*ndf2*(2*ndf2+2*ndf1-4))/
double(ndf1*pow(
double(ndf2-1),2)*(ndf2-4)));
2043 val=1.-TMath::FDistI(f,ndf1,ndf2);
2047 val=TMath::FDistI(f,ndf1,ndf2);
2051 if (abs(sides)==2) val=val*2.;
2102 Double_t mean=double(n)*p;
2107 if (k<mean) sides=-1;
2113 if (k<mean) sides=-2;
2120 Double_t s=sqrt(
double(n)*p*(1.-p));
2121 val=(double(k)-mean)/s;
2129 val=TMath::BetaIncomplete(p,k,n-k+1);
2133 for (Int_t i=k; i<=n; i++)
2135 val+=TMath::Binomial(n,i)*pow(p,i)*pow(1.-p,n-i);
2143 val=1.-TMath::BetaIncomplete(p,k+1,n-k);
2147 for (Int_t j=0; j<=k; j++)
2149 val+=TMath::Binomial(n,j)*pow(p,j)*pow(1.-p,n-j);
2155 if (abs(sides)==2) val=val*2.;
2211 if (k<mean) sides=-1;
2217 if (k<mean) sides=-2;
2224 Double_t s=sqrt(mu);
2225 val=(double(k)-mean)/s;
2239 if (abs(sides)==2) val=val*2.;
2345 if (n<=0 || r<=0)
return val;
2347 Double_t mean=double(n)/r;
2348 Double_t sig=sqrt(
double(n)/(r*r));
2353 if (dt<mean) sides=-1;
2359 if (dt<mean) sides=-2;
2372 val=1.-
Gamma(n,r*dt);
2380 if (abs(sides)==2) val=val*2.;
2435 Double_t mean=double(k)/p;
2440 if (n<mean) sides=-1;
2446 if (n<mean) sides=-2;
2453 Double_t s=sqrt(
double(k)*(1.-p)/(p*p));
2454 val=(double(n)-mean)/s;
2463 val=cdf.Eval(
double(n-1));
2468 for (Int_t i=1; i<n; i++)
2470 val+=TMath::Binomial(i-1,k-1)*pow(p,k)*pow(1.-p,i-k);
2480 val=cdf.Eval(
double(n));
2485 for (Int_t j=1; j<=n; j++)
2487 val+=TMath::Binomial(j-1,k-1)*pow(p,k)*pow(1.-p,j-k);
2493 if (abs(sides)==2) val=val*2.;
2550 Double_t mean=double(x)*(1.-p)/p;
2555 if (x<mean) sides=-1;
2561 if (x<mean) sides=-2;
2568 Double_t s=sqrt(
double(k)*(1.-p)/(p*p));
2569 val=(double(x)-mean)/s;
2578 val=cdf.Eval(
double(x-1));
2583 for (Int_t i=0; i<x; i++)
2585 val+=TMath::Binomial(i+k-1,k-1)*pow(p,k)*pow(1.-p,i);
2595 val=cdf.Eval(
double(x));
2600 for (Int_t j=0; j<=x; j++)
2602 val+=TMath::Binomial(j+k-1,k-1)*pow(p,k)*pow(1.-p,j);
2608 if (abs(sides)==2) val=val*2.;
2625 if (B<=1 || x<=0)
return val;
2653 if (n==0 || n==1)
return 1;
2655 Double_t twopi=2.*acos(-1.);
2672 nfac=sqrt(twopi)*pow(z,z+0.5)*exp(-z)*(1.+1./(12.*z));
2711 Double_t twopi=2.*acos(-1.);
2724 lognfac=0.5*log(twopi)+(z+0.5)*log(z)-z+1./(12.*z);
2758 Double_t val=
LnNfac(n,mode);
2780 if (r==0 || r==1)
return 1;
2799 if (r<=0 || r==1)
return 0;
2819 if (r<=0 || r==1)
return 0;
2874 if (m<=0 || !n)
return psi;
2877 for (Int_t j=0; j<m; j++)
2879 if (n[j]>0) ntot+=n[j];
2883 Double_t pk=1./float(m);
2884 for (Int_t i=0; i<m; i++)
2891 psi+=double(n[i])*log10(pk)-
LogNfac(n[i]);
2895 if (ntot>0) psi+=double(n[i])*log10(
double(n[i])/(
double(ntot)*pk));
2963 if (m<=0 || !n)
return psi;
2966 for (Int_t j=0; j<m; j++)
2968 if (n[j]>0) ntot+=n[j];
2972 Double_t pk=1./float(m);
2973 for (Int_t i=0; i<m; i++)
2980 psi+=n[i]*log10(pk)-
LogRfac(n[i]);
2984 if (ntot>0) psi+=n[i]*log10(n[i]/(ntot*pk));
3051 if (!his)
return psi;
3053 TAxis* xaxis=his->GetXaxis();
3054 Double_t xmin=xaxis->GetXmin();
3055 Double_t xmax=xaxis->GetXmax();
3056 Double_t range=xmax-xmin;
3057 Int_t nbins=his->GetNbinsX();
3058 Double_t nensig=his->GetSumOfWeights();
3060 if (nbins<=0 || nensig<=0 || range<=0)
return psi;
3062 Double_t* n=
new Double_t[nbins];
3063 Double_t* p=
new Double_t[nbins];
3070 for (Int_t i=1; i<=nbins; i++)
3072 nk=his->GetBinContent(i);
3073 pk=his->GetBinWidth(i)/range;
3076 if (nk>0) n[i-1]=nk;
3077 if (pk>0) p[i-1]=pk;
3085 pdf->SetRange(xmin,xmax);
3086 Double_t ftot=pdf->Integral(xmin,xmax);
3090 for (Int_t ipdf=1; ipdf<=nbins; ipdf++)
3092 nk=his->GetBinContent(ipdf);
3093 x1=his->GetBinLowEdge(ipdf);
3094 x2=x1+his->GetBinWidth(ipdf);
3095 pk=pdf->Integral(x1,x2)/ftot;
3098 if (nk>0) n[ipdf-1]=nk;
3099 if (pk>0) p[ipdf-1]=pk;
3108 TH1* href=(TH1*)his->Clone(
"href");
3112 for (Int_t ihyp=1; ihyp<=hyp->GetNbinsX(); ihyp++)
3114 x=hyp->GetBinCenter(ihyp);
3115 y=hyp->GetBinContent(ihyp);
3119 for (Int_t j=1; j<=nbins; j++)
3121 nk=his->GetBinContent(j);
3122 pk=href->GetBinContent(j)/nenhyp;
3125 if (nk>0) n[j-1]=nk;
3126 if (pk>0) p[j-1]=pk;
3198 if (m<=0 || n<=0 || k<-2 || k>m)
return psi;
3201 Double_t pk=1./double(m);
3237 for (Int_t j=0; j<m; j++)
3239 if (p[j]>0 && p[j]<pmin)
3244 if (p[j]>0 && p[j]>pmax)
3253 if (jmin<0 || jmax<0)
return psi;
3262 psi+=n*log10(pmin)-
LogRfac(n);
3279 for (Int_t i=0; i<m; i++)
3285 psi+=nk*log10(pk)-
LogRfac(nk);
3299 Double_t* narr=
new Double_t[m];
3302 for (Int_t i=0; i<m; i++)
3306 if (pk>0) narr[i]=n*pk;
3307 ndisc+=int(narr[i]);
3322 for (Int_t ient=0; ient<ndiff; ient++)
3333 for (Int_t i=0; i<m; i++)
3336 if (pk>0) narr[i]+=pk;
3337 ndisc+=int(narr[i]);
3356 for (Int_t i=0; i<m; i++)
3359 if (
int(narr[i])>0 && pk<pmin)
3371 for (Int_t i=0; i<m; i++)
3377 psi+=nk*log10(pk)-
LogRfac(nk);
3452 if (!his)
return psi;
3454 TAxis* xaxis=his->GetXaxis();
3455 Double_t xmin=xaxis->GetXmin();
3456 Double_t xmax=xaxis->GetXmax();
3457 Double_t range=xmax-xmin;
3458 Int_t nbins=his->GetNbinsX();
3459 Double_t nensig=his->GetSumOfWeights();
3461 if (nbins<=0 || nensig<=0 || range<=0)
return psi;
3463 Double_t* p=
new Double_t[nbins];
3469 for (Int_t i=1; i<=nbins; i++)
3471 pk=his->GetBinWidth(i)/range;
3473 if (pk>0) p[i-1]=pk;
3481 pdf->SetRange(xmin,xmax);
3482 Double_t ftot=pdf->Integral(xmin,xmax);
3486 for (Int_t ipdf=1; ipdf<=nbins; ipdf++)
3488 x1=his->GetBinLowEdge(ipdf);
3489 x2=x1+his->GetBinWidth(ipdf);
3490 pk=pdf->Integral(x1,x2)/ftot;
3492 if (pk>0) p[ipdf-1]=pk;
3501 TH1* href=(TH1*)his->Clone(
"href");
3506 for (Int_t ihyp=1; ihyp<=hyp->GetNbinsX(); ihyp++)
3508 x=hyp->GetBinCenter(ihyp);
3509 y=hyp->GetBinContent(ihyp);
3513 for (Int_t j=1; j<=nbins; j++)
3515 pk=href->GetBinContent(j)/nenhyp;
3517 if (pk>0) p[j-1]=pk;
3528Double_t
NcMath::PsiPvalue(Double_t psi0,Double_t nr,Double_t n,Int_t m,Double_t* p,Int_t f,Double_t* na,TH1F* psih,Int_t ncut,Double_t* nrx,Int_t mark)
3620 if (psi0<0 || nr<0 || (nr>0 && nr<2))
return -1;
3627 Double_t val=q.
RanBm(nr,n,m,p,na,0,psi0,f,psih,ncut,&nrused);
3628 if (val>=0) pval=val/nrused;
3629 if (nrx) (*nrx)=nrused;
3634 TString title=
"#psi value in dB";
3635 TString s=
"Counts after ";
3637 s+=
" randomisations";
3639 psih->GetXaxis()->SetTitle(title.Data());
3640 psih->GetYaxis()->SetTitle(s.Data());
3648 Float_t ymax=psih->GetMaximum();
3650 TLine* vline=
new TLine(x,ymin,x,ymax);
3651 vline->SetLineStyle(2);
3652 vline->SetLineWidth(2);
3653 vline->SetLineColor(4);
3655 title=
"P-value : %-10.3g";
3656 s=title.Format(title.Data(),pval);
3658 TLegend* leg=
new TLegend(0.6,0.8,0.8,0.9);
3659 leg->SetFillColor(0);
3660 leg->SetHeader(s.Data());
3661 leg->AddEntry(vline,
"Observed #psi",
"L");
3663 TList* hlist=psih->GetListOfFunctions();
3673Double_t
NcMath::PsiPvalue(Double_t psi0,Double_t nr,TH1* his,TH1* hyp,TF1* pdf,Int_t f,Double_t* na,TH1F* psih,Int_t ncut,Double_t* nrx,Int_t mark)
3778 if (!his)
return pval;
3780 TAxis* xaxis=his->GetXaxis();
3781 Double_t xmin=xaxis->GetXmin();
3782 Double_t xmax=xaxis->GetXmax();
3783 Double_t range=xmax-xmin;
3784 Int_t nbins=his->GetNbinsX();
3785 Double_t nensig=his->GetSumOfWeights();
3787 if (nbins<=0 || nensig<=0 || range<=0)
return pval;
3789 if (psi0<0) psi0=
PsiValue(his,hyp,pdf,f);
3791 Double_t* n=
new Double_t[nbins];
3792 Double_t* p=
new Double_t[nbins];
3799 for (Int_t i=1; i<=nbins; i++)
3801 nk=his->GetBinContent(i);
3802 pk=his->GetBinWidth(i)/range;
3805 if (nk>0) n[i-1]=nk;
3806 if (pk>0) p[i-1]=pk;
3808 pval=
PsiPvalue(psi0,nr,nensig,nbins,p,f,na,psih,ncut,nrx,mark);
3814 pdf->SetRange(xmin,xmax);
3815 Double_t ftot=pdf->Integral(xmin,xmax);
3819 for (Int_t ipdf=1; ipdf<=nbins; ipdf++)
3821 nk=his->GetBinContent(ipdf);
3822 x1=his->GetBinLowEdge(ipdf);
3823 x2=x1+his->GetBinWidth(ipdf);
3824 pk=pdf->Integral(x1,x2)/ftot;
3827 if (nk>0) n[ipdf-1]=nk;
3828 if (pk>0) p[ipdf-1]=pk;
3830 pval=
PsiPvalue(psi0,nr,nensig,nbins,p,f,na,psih,ncut,nrx,mark);
3837 TH1* href=(TH1*)his->Clone(
"href");
3841 for (Int_t ihyp=1; ihyp<=hyp->GetNbinsX(); ihyp++)
3843 x=hyp->GetBinCenter(ihyp);
3844 y=hyp->GetBinContent(ihyp);
3848 for (Int_t j=1; j<=nbins; j++)
3850 nk=his->GetBinContent(j);
3851 pk=href->GetBinContent(j)/nenhyp;
3854 if (nk>0) n[j-1]=nk;
3855 if (pk>0) p[j-1]=pk;
3857 pval=
PsiPvalue(psi0,nr,nensig,nbins,p,f,na,psih,ncut,nrx,mark);
3901 if (m<=0 || !n)
return chi;
3904 for (Int_t j=0; j<m; j++)
3906 if (n[j]>0) ntot+=n[j];
3910 Double_t pk=1./float(m);
3911 for (Int_t i=0; i<m; i++)
3914 if (n[i]>0 && pk>0 && ntot>0)
3916 chi+=pow(
double(n[i])-
double(ntot)*pk,2)/(double(ntot)*pk);
3917 if (ndf) (*ndf)=(*ndf)+1;
3963 if (m<=0 || !n)
return chi;
3966 for (Int_t j=0; j<m; j++)
3968 if (n[j]>0) ntot+=n[j];
3972 Double_t pk=1./float(m);
3973 for (Int_t i=0; i<m; i++)
3976 if (n[i]>0 && pk>0 && ntot>0)
3978 chi+=pow(n[i]-ntot*pk,2)/(ntot*pk);
3979 if (ndf) (*ndf)=(*ndf)+1;
4022 if (!his)
return chi;
4024 TAxis* xaxis=his->GetXaxis();
4025 Double_t xmin=xaxis->GetXmin();
4026 Double_t xmax=xaxis->GetXmax();
4027 Double_t range=xmax-xmin;
4028 Int_t nbins=his->GetNbinsX();
4029 Double_t nensig=his->GetSumOfWeights();
4031 if (nbins<=0 || nensig<=0 || range<=0)
return chi;
4033 Double_t* n=
new Double_t[nbins];
4034 Double_t* p=
new Double_t[nbins];
4041 for (Int_t i=1; i<=nbins; i++)
4043 nk=his->GetBinContent(i);
4044 pk=his->GetBinWidth(i)/range;
4047 if (nk>0) n[i-1]=nk;
4048 if (pk>0) p[i-1]=pk;
4056 pdf->SetRange(xmin,xmax);
4057 Double_t ftot=pdf->Integral(xmin,xmax);
4061 for (Int_t ipdf=1; ipdf<=nbins; ipdf++)
4063 nk=his->GetBinContent(ipdf);
4064 x1=his->GetBinLowEdge(ipdf);
4065 x2=x1+his->GetBinWidth(ipdf);
4066 pk=pdf->Integral(x1,x2)/ftot;
4069 if (nk>0) n[ipdf-1]=nk;
4070 if (pk>0) p[ipdf-1]=pk;
4079 TH1* href=(TH1*)his->Clone(
"href");
4083 for (Int_t ihyp=1; ihyp<=hyp->GetNbinsX(); ihyp++)
4085 x=hyp->GetBinCenter(ihyp);
4086 y=hyp->GetBinContent(ihyp);
4090 for (Int_t j=1; j<=nbins; j++)
4092 nk=his->GetBinContent(j);
4093 pk=href->GetBinContent(j)/nenhyp;
4096 if (nk>0) n[j-1]=nk;
4097 if (pk>0) p[j-1]=pk;
4109Double_t
NcMath::MeanMu(Double_t cl,Double_t nbkg,Int_t mode,TF1* fw,TFeldmanCousins* fc,Int_t nmax)
const
4137 TFeldmanCousins* f=fc;
4138 if (!f) f=
new TFeldmanCousins();
4142 if (!nmax) nmax=int(nbkg+10.*sqrt(nbkg));
4148 for (Int_t nobs=0; nobs<=nmax; nobs++)
4152 mu=f->CalculateLowerLimit(nobs,nbkg);
4156 mu=f->CalculateUpperLimit(nobs,nbkg);
4160 muav+=mu*fw->Eval(nobs);
4164 muav+=mu*pow(nbkg,nobs)*exp(-nbkg)/
Rfac(nobs);
4203 if (Non<=0 || Noff<=0 || Ton<=0 || Toff<=0 || Ra<=0 || Re<=0)
return -1;
4205 Double_t sum=Non+Noff;
4207 Double_t a=Ra*Re*Ton/Toff;
4209 s=2.*(Non*log((1.+a)*Non/(a*sum))+Noff*log((1.+a)*Noff/sum));
Various mathematical tools for scientific analysis.
Double_t StudentPvalue(Double_t t, Double_t ndf, Int_t sides=0, Int_t sigma=0) const
Double_t PsiValue(Int_t m, Int_t *n, Double_t *p=0, Int_t f=0) const
TF1 PoissonCDF(Double_t mu) const
Double_t GetStatistic(TF1 f, TString name, Int_t n=0, Double_t vref=0, Int_t npx=1000) const
Double_t BesselK(Int_t n, Double_t x) const
Double_t Log(Double_t B, Double_t x) const
TF1 Chi2CDF(Int_t ndf) const
Double_t NegBinomialnPvalue(Int_t n, Int_t k, Double_t p, Int_t sides=0, Int_t sigma=0, Int_t mode=0) const
TF1 StudentDist(Double_t ndf) const
Double_t GaussPvalue(Double_t q, Double_t mean=0, Double_t sigma=1, Int_t sides=2, Int_t isig=0) const
TF1 PoissonDist(Double_t mu) const
TF1 PoissonDtCDF(Double_t r, Int_t n) const
Double_t LnGamma(Double_t z) const
Double_t BinomialPvalue(Int_t k, Int_t n, Double_t p, Int_t sides=0, Int_t sigma=0, Int_t mode=0) const
Double_t Chi2Pvalue(Double_t chi2, Int_t ndf, Int_t sides=0, Int_t sigma=0, Int_t mode=1) const
TF1 Chi2Dist(Int_t ndf) const
TF1 NegBinomialxCDF(Int_t k, Double_t p) const
Double_t PoissonDtPvalue(Double_t dt, Double_t r, Int_t n, Int_t sides=0, Int_t sigma=0) const
TF1 BinomialCDF(Int_t n, Double_t p) const
Double_t Nfac(Int_t n, Int_t mode=0) const
Double_t MeanMu(Double_t cl, Double_t nbkg, Int_t mode, TF1 *w=0, TFeldmanCousins *f=0, Int_t nmax=0) const
Double_t BesselI0(Double_t x) const
Double_t PoissonPvalue(Int_t k, Double_t mu, Int_t sides=0, Int_t sigma=0) const
Double_t LiMaSignificance(Double_t Non, Double_t Ton, Double_t Noff, Double_t Toff, Double_t Ra=1, Double_t Re=1) const
Double_t Gamma(Double_t z) const
Double_t LnRfac(Double_t r) const
TF1 GammaDtDist(Double_t r, Double_t z) const
Double_t GaussProb(Double_t q, Double_t mean=0, Double_t sigma=1, Int_t isig=0) const
Double_t Erfc(Double_t x) const
TF1 BinomialDist(Int_t n, Double_t p) const
Double_t BesselI(Int_t n, Double_t x) const
Double_t FratioPvalue(Double_t f, Int_t ndf1, Int_t ndf2, Int_t sides=0, Int_t sigma=0) const
Double_t LnNfac(Int_t n, Int_t mode=2) const
Double_t Rfac(Double_t r) const
Double_t Zeta(Double_t x, Int_t nterms=100000) const
TF1 Rayleigh3Dist(Double_t sigma) const
Double_t PsiExtreme(Double_t n, Int_t m, Double_t *p=0, Int_t k=0) const
TF1 NegBinomialxDist(Int_t k, Double_t p) const
Double_t BesselK0(Double_t x) const
TF1 RayleighCDF(Double_t sigma) const
TGraph GetCDF(TF1 f, Int_t npx=1000) const
Double_t LogRfac(Double_t r) const
Double_t Prob(Double_t chi2, Int_t ndf, Int_t mode=1) const
TF1 GaussCDF(Double_t mu, Double_t sigma) const
Double_t NegBinomialxPvalue(Int_t x, Int_t k, Double_t p, Int_t sides=0, Int_t sigma=0, Int_t mode=0) const
Double_t BesselK1(Double_t x) const
Double_t Erf(Double_t x) const
TF1 RayleighDist(Double_t sigma) const
TF1 GaussDist(Double_t mu, Double_t sigma) const
TF1 NegBinomialnCDF(Int_t k, Double_t p) const
TF1 NegBinomialnDist(Int_t k, Double_t p) const
Double_t PsiPvalue(Double_t psi0, Double_t nr, Double_t n, Int_t m, Double_t *p=0, Int_t f=0, Double_t *na=0, TH1F *psih=0, Int_t ncut=0, Double_t *nrx=0, Int_t mark=1)
TF1 FratioCDF(Int_t ndf1, Int_t ndf2) const
TF1 PoissonDtDist(Double_t r, Int_t n) const
Double_t LogNfac(Int_t n, Int_t mode=2) const
TF1 FratioDist(Int_t ndf1, Int_t ndf2) const
Double_t GamSer(Double_t a, Double_t x) const
TF1 StudentCDF(Double_t ndf) const
Double_t Chi2Value(Int_t m, Int_t *n, Double_t *p=0, Int_t *ndf=0) const
Double_t GamCf(Double_t a, Double_t x) const
Double_t BesselI1(Double_t x) const
Generate universal random numbers and sequences on all common machines.
Double_t RanBm(Double_t nr, Double_t n, Int_t m, Double_t *p=0, Double_t *na=0, Double_t *psia=0, Double_t psi0=-1, Int_t f=0, TH1 *psih=0, Int_t ncut=0, Double_t *nrx=0)