ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaussRandomGen.h
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7  * *
8  **********************************************************************/
9 
10 #ifndef MN_GaussRandomGen_H_
11 #define MN_GaussRandomGen_H_
12 
13 #include <cmath>
14 #include <cstdlib>
15 
16 namespace ROOT {
17 
18  namespace Minuit2 {
19 
20 
22 
23 public:
24 
25  GaussRandomGen() : fMean(0.), fSigma(1.) {}
26 
27  GaussRandomGen(double mean, double sigma) : fMean(mean), fSigma(sigma) {}
28 
30 
31  double Mean() const {return fMean;}
32 
33  double Sigma() const {return fSigma;}
34 
35  double operator()() const {
36  //need to random variables flat in [0,1)
37  double r1 = std::rand()/double(RAND_MAX);
38  double r2 = std::rand()/double(RAND_MAX);
39 
40  //two possibilities to generate a random gauss variable (m=0,s=1)
41  double s = sqrt(-2.*log(1.-r1))*cos(2.*M_PI*r2);
42 // double s = sqrt(-2.*log(1.-r1))*sin(2.*M_PI*r2);
43 
44  //scale to desired gauss
45  return Sigma()*s + Mean();
46  }
47 
48 private:
49 
50  double fMean;
51  double fSigma;
52 
53 };
54 
55  } // namespace Minuit2
56 
57 } // namespace ROOT
58 
59 #endif //MN_GaussRandomGen_H_
double cos(double)
double sqrt(double)
GaussRandomGen(double mean, double sigma)
const Double_t sigma
#define M_PI
Definition: Rotated.cxx:105
unsigned int r1[N_CITIES]
Definition: simanTSP.cxx:321
unsigned int r2[N_CITIES]
Definition: simanTSP.cxx:322
double log(double)