GaussRandomGen.h

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id: GaussRandomGen.h 26442 2008-11-25 10:18:22Z moneta $
00002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005  
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
00007  *                                                                    *
00008  **********************************************************************/
00009 
00010 #ifndef MN_GaussRandomGen_H_
00011 #define MN_GaussRandomGen_H_
00012 
00013 #include <cmath>
00014 #include <cstdlib>
00015 
00016 namespace ROOT {
00017 
00018    namespace Minuit2 {
00019 
00020 
00021 class GaussRandomGen {
00022 
00023 public:
00024 
00025   GaussRandomGen() : fMean(0.), fSigma(1.) {}
00026 
00027   GaussRandomGen(double mean, double sigma) : fMean(mean), fSigma(sigma) {}
00028 
00029   ~GaussRandomGen() {}
00030 
00031   double Mean() const {return fMean;}
00032 
00033   double Sigma() const {return fSigma;}
00034 
00035   double operator()() const {
00036     //need to random variables flat in [0,1)
00037     double r1 = std::rand()/double(RAND_MAX);
00038     double r2 = std::rand()/double(RAND_MAX);
00039 
00040     //two possibilities to generate a random gauss variable (m=0,s=1)
00041     double s = sqrt(-2.*log(1.-r1))*cos(2.*M_PI*r2);
00042 //     double s = sqrt(-2.*log(1.-r1))*sin(2.*M_PI*r2);
00043 
00044     //scale to desired gauss
00045     return Sigma()*s + Mean();
00046   }
00047 
00048 private:
00049 
00050   double fMean;
00051   double fSigma;
00052   
00053 };
00054 
00055   }  // namespace Minuit2
00056 
00057 }  // namespace ROOT
00058 
00059 #endif //MN_GaussRandomGen_H_

Generated on Tue Jul 5 14:37:12 2011 for ROOT_528-00b_version by  doxygen 1.5.1