00001 // @(#)root/mathmore:$Id: VavilovFast.h 34123 2010-06-25 08:21:13Z moneta $ 00002 // Authors: B. List 29.4.2010 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT * 00007 * * 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU General Public License * 00010 * as published by the Free Software Foundation; either version 2 * 00011 * of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this library (see file COPYING); if not, write * 00020 * to the Free Software Foundation, Inc., 59 Temple Place, Suite * 00021 * 330, Boston, MA 02111-1307 USA, or contact the author. * 00022 * * 00023 **********************************************************************/ 00024 00025 // Header file for class VavilovFast 00026 // 00027 // Created by: blist at Thu Apr 29 11:19:00 2010 00028 // 00029 // Last update: Thu Apr 29 11:19:00 2010 00030 // 00031 #ifndef ROOT_Math_VavilovFast 00032 #define ROOT_Math_VavilovFast 00033 00034 00035 /** 00036 @ingroup StatFunc 00037 */ 00038 00039 00040 #include "Math/Vavilov.h" 00041 00042 namespace ROOT { 00043 namespace Math { 00044 00045 //____________________________________________________________________________ 00046 /** 00047 Class describing a Vavilov distribution. 00048 00049 The probability density function of the Vavilov distribution 00050 as function of Landau's parameter is given by: 00051 \f[ p(\lambda_L; \kappa, \beta^2) = 00052 \frac{1}{2 \pi i}\int_{c-i\infty}^{c+i\infty} \phi(s) e^{\lambda_L s} ds\f] 00053 where \f$\phi(s) = e^{C} e^{\psi(s)}\f$ 00054 with \f$ C = \kappa (1+\beta^2 \gamma )\f$ 00055 and \f$\psi(s)= s \ln \kappa + (s+\beta^2 \kappa) 00056 \cdot \left ( \int \limits_{0}^{1} 00057 \frac{1 - e^{\frac{-st}{\kappa}}}{t} \,d t- \gamma \right ) 00058 - \kappa \, e^{\frac{-s}{\kappa}}\f$. 00059 \f$ \gamma = 0.5772156649\dots\f$ is Euler's constant. 00060 00061 For the class VavilovFast, 00062 Pdf returns the Vavilov distribution as function of Landau's parameter 00063 \f$\lambda_L = \lambda_V/\kappa - \ln \kappa\f$, 00064 which is the convention used in the CERNLIB routines, and in the tables 00065 by S.M. Seltzer and M.J. Berger: Energy loss stragglin of protons and mesons: 00066 Tabulation of the Vavilov distribution, pp 187-203 00067 in: National Research Council (U.S.), Committee on Nuclear Science: 00068 Studies in penetration of charged particles in matter, 00069 Nat. Akad. Sci. Publication 1133, 00070 Nucl. Sci. Series Report No. 39, 00071 Washington (Nat. Akad. Sci.) 1964, 388 pp. 00072 Available from 00073 <A HREF="http://books.google.de/books?id=kmMrAAAAYAAJ&lpg=PP9&pg=PA187#v=onepage&q&f=false">Google books</A> 00074 00075 Therefore, for small values of \f$\kappa < 0.01\f$, 00076 pdf approaches the Landau distribution. 00077 00078 For values \f$\kappa > 10\f$, the Gauss approximation should be used 00079 with \f$\mu\f$ and \f$\sigma\f$ given by Vavilov::mean(kappa, beta2) 00080 and sqrt(Vavilov::variance(kappa, beta2). 00081 00082 For values \f$\kappa > 10\f$, the Gauss approximation should be used 00083 with \f$\mu\f$ and \f$\sigma\f$ given by Vavilov::mean(kappa, beta2) 00084 and sqrt(Vavilov::variance(kappa, beta2). 00085 00086 The original Vavilov pdf is obtained by 00087 v.Pdf(lambdaV/kappa-log(kappa))/kappa. 00088 00089 For detailed description see 00090 A. Rotondi and P. Montagna, Fast calculation of Vavilov distribution, 00091 <A HREF="http://dx.doi.org/10.1016/0168-583X(90)90749-K">Nucl. Instr. and Meth. B47 (1990) 215-224</A>, 00092 which has been implemented in 00093 <A HREF="http://wwwasdoc.web.cern.ch/wwwasdoc/shortwrupsdir/g115/top.html"> 00094 CERNLIB (G115)</A>. 00095 00096 The class stores coefficients needed to calculate \f$p(\lambda; \kappa, \beta^2)\f$ 00097 for fixed values of \f$\kappa\f$ and \f$\beta^2\f$. 00098 Changing these values is computationally expensive. 00099 00100 The parameter \f$\kappa\f$ must be in the range \f$0.01 \le \kappa \le 12\f$. 00101 00102 The parameter \f$\beta^2\f$ must be in the range \f$0 \le \beta^2 \le 1\f$. 00103 00104 Average times on a Pentium Core2 Duo P8400 2.26GHz: 00105 - 9.9us per call to SetKappaBeta2 or constructor 00106 - 0.095us per call to Pdf, Cdf 00107 - 3.7us per first call to Quantile after SetKappaBeta2 or constructor 00108 - 0.137us per subsequent call to Quantile 00109 00110 Benno List, June 2010 00111 00112 @ingroup StatFunc 00113 */ 00114 00115 00116 class VavilovFast: public Vavilov { 00117 00118 public: 00119 00120 00121 /** 00122 Initialize an object to calculate the Vavilov distribution 00123 00124 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00125 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00126 */ 00127 00128 VavilovFast(double kappa=1, double beta2=1); 00129 00130 00131 /** 00132 Destructor 00133 */ 00134 virtual ~VavilovFast(); 00135 00136 00137 public: 00138 00139 /** 00140 Evaluate the Vavilov probability density function 00141 00142 @param x The Landau parameter \f$x = \lambda_L\f$ 00143 */ 00144 double Pdf (double x) const; 00145 00146 /** 00147 Evaluate the Vavilov probability density function, 00148 and set kappa and beta2, if necessary 00149 00150 @param x The Landau parameter \f$x = \lambda_L\f$ 00151 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00152 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00153 */ 00154 double Pdf (double x, double kappa, double beta2); 00155 00156 /** 00157 Evaluate the Vavilov cummulative probability density function 00158 00159 @param x The Landau parameter \f$x = \lambda_L\f$ 00160 */ 00161 double Cdf (double x) const; 00162 00163 /** 00164 Evaluate the Vavilov cummulative probability density function, 00165 and set kappa and beta2, if necessary 00166 00167 @param x The Landau parameter \f$x = \lambda_L\f$ 00168 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00169 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00170 */ 00171 double Cdf (double x, double kappa, double beta2); 00172 00173 /** 00174 Evaluate the Vavilov complementary cummulative probability density function 00175 00176 @param x The Landau parameter \f$x = \lambda_L\f$ 00177 */ 00178 double Cdf_c (double x) const; 00179 00180 /** 00181 Evaluate the Vavilov complementary cummulative probability density function, 00182 and set kappa and beta2, if necessary 00183 00184 @param x The Landau parameter \f$x = \lambda_L\f$ 00185 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00186 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00187 */ 00188 double Cdf_c (double x, double kappa, double beta2); 00189 00190 /** 00191 Evaluate the inverse of the Vavilov cummulative probability density function 00192 00193 @param z The argument \f$z\f$, which must be in the range \f$0 \le z \le 1\f$ 00194 */ 00195 double Quantile (double z) const; 00196 00197 /** 00198 Evaluate the inverse of the Vavilov cummulative probability density function, 00199 and set kappa and beta2, if necessary 00200 00201 @param z The argument \f$z\f$, which must be in the range \f$0 \le z \le 1\f$ 00202 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00203 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00204 */ 00205 double Quantile (double z, double kappa, double beta2); 00206 00207 /** 00208 Evaluate the inverse of the complementary Vavilov cummulative probability density function 00209 00210 @param z The argument \f$z\f$, which must be in the range \f$0 \le z \le 1\f$ 00211 */ 00212 double Quantile_c (double z) const; 00213 00214 /** 00215 Evaluate the inverse of the complementary Vavilov cummulative probability density function, 00216 and set kappa and beta2, if necessary 00217 00218 @param z The argument \f$z\f$, which must be in the range \f$0 \le z \le 1\f$ 00219 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00220 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00221 */ 00222 double Quantile_c (double z, double kappa, double beta2); 00223 00224 /** 00225 Change \f$\kappa\f$ and \f$\beta^2\f$ and recalculate coefficients if necessary 00226 00227 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00228 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00229 */ 00230 virtual void SetKappaBeta2 (double kappa, double beta2); 00231 00232 /** 00233 Return the minimum value of \f$\lambda\f$ for which \f$p(\lambda; \kappa, \beta^2)\f$ 00234 is nonzero in the current approximation 00235 */ 00236 virtual double GetLambdaMin() const; 00237 00238 /** 00239 Return the maximum value of \f$\lambda\f$ for which \f$p(\lambda; \kappa, \beta^2)\f$ 00240 is nonzero in the current approximation 00241 */ 00242 virtual double GetLambdaMax() const; 00243 00244 /** 00245 Return the current value of \f$\kappa\f$ 00246 */ 00247 virtual double GetKappa() const; 00248 00249 /** 00250 Return the current value of \f$\beta^2\f$ 00251 */ 00252 virtual double GetBeta2() const; 00253 00254 /** 00255 Returns a static instance of class VavilovFast 00256 */ 00257 static VavilovFast *GetInstance(); 00258 00259 /** 00260 Returns a static instance of class VavilovFast, 00261 and sets the values of kappa and beta2 00262 00263 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00264 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00265 */ 00266 static VavilovFast *GetInstance(double kappa, double beta2); 00267 00268 00269 private: 00270 double fKappa; 00271 double fBeta2; 00272 00273 double fAC[14]; 00274 double fHC[9]; 00275 double fWCM[201]; 00276 int fItype; 00277 int fNpt; 00278 00279 static VavilovFast *fgInstance; 00280 00281 }; 00282 00283 /** 00284 The Vavilov probability density function 00285 00286 @param x The Landau parameter \f$x = \lambda_L\f$ 00287 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00288 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00289 00290 @ingroup PdfFunc 00291 */ 00292 double vavilov_fast_pdf (double x, double kappa, double beta2); 00293 00294 /** 00295 The Vavilov cummulative probability density function 00296 00297 @param x The Landau parameter \f$x = \lambda_L\f$ 00298 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00299 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00300 00301 @ingroup ProbFunc 00302 */ 00303 double vavilov_fast_cdf (double x, double kappa, double beta2); 00304 00305 /** 00306 The Vavilov complementary cummulative probability density function 00307 00308 @param x The Landau parameter \f$x = \lambda_L\f$ 00309 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00310 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00311 00312 @ingroup ProbFunc 00313 */ 00314 double vavilov_fast_cdf_c (double x, double kappa, double beta2); 00315 00316 /** 00317 The inverse of the Vavilov cummulative probability density function 00318 00319 @param z The argument \f$z\f$, which must be in the range \f$0 \le z \le 1\f$ 00320 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00321 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00322 00323 @ingroup QuantFunc 00324 */ 00325 double vavilov_fast_quantile (double z, double kappa, double beta2); 00326 00327 /** 00328 The inverse of the complementary Vavilov cummulative probability density function 00329 00330 @param z The argument \f$z\f$, which must be in the range \f$0 \le z \le 1\f$ 00331 @param kappa The parameter \f$\kappa\f$, which must be in the range \f$0.01 \le \kappa \le 12 \f$ 00332 @param beta2 The parameter \f$\beta^2\f$, which must be in the range \f$0 \le \beta^2 \le 1 \f$ 00333 00334 @ingroup QuantFunc 00335 */ 00336 double vavilov_fast_quantile_c (double z, double kappa, double beta2); 00337 00338 } // namespace Math 00339 } // namespace ROOT 00340 00341 #endif /* ROOT_Math_VavilovFast */