evtgen is hosted by Hepforge, IPPP Durham
EvtGen  2.0.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
EvtRandom.cpp
Go to the documentation of this file.
1 
2 /***********************************************************************
3 * Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4 * *
5 * This file is part of EvtGen. *
6 * *
7 * EvtGen is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * EvtGen is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19 ***********************************************************************/
20 
21 #include "EvtGenBase/EvtRandom.hh"
22 
23 #include "EvtGenBase/EvtConst.hh"
24 #include "EvtGenBase/EvtPatches.hh"
26 #include "EvtGenBase/EvtReport.hh"
27 
28 #include <iostream>
29 #include <math.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 
33 using std::endl;
34 
36 
38 {
39  _randomEngine = randomEngine;
40 }
41 
43 {
44  if ( _randomEngine == 0 ) {
45  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
46  << "No random engine available in "
47  << "EvtRandom::random()." << endl;
48  ::abort();
49  }
50 
51  return _randomEngine->random();
52 }
53 
54 // Random number routine to generate numbers between
55 // min and max. By djl on July 27, 1995.
56 double EvtRandom::Flat( double min, double max )
57 {
58  if ( min > max ) {
59  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
60  << "min>max in EvtRandom::Flat(" << min << "," << max << ")" << endl;
61  ::abort();
62  }
63 
64  return EvtRandom::random() * ( max - min ) + min;
65 }
66 
67 double EvtRandom::Flat( double max )
68 {
69  return max * EvtRandom::random();
70 }
71 
73 {
74  return EvtRandom::random();
75 }
76 
78 {
79  double x = EvtRandom::random();
80  double y = EvtRandom::random();
81 
82  return cos( x * EvtConst::twoPi ) * sqrt( -2.0 * log( 1 - y ) );
83 }
static double Gaussian()
Definition: EvtRandom.cpp:77
static double random()
Definition: EvtRandom.cpp:42
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=0)
Definition: EvtReport.cpp:33
static const double twoPi
Definition: EvtConst.hh:27
virtual double random()=0
static double Flat()
Definition: EvtRandom.cpp:72
static EvtRandomEngine * _randomEngine
Definition: EvtRandom.hh:43
static void setRandomEngine(EvtRandomEngine *randomEngine)
Definition: EvtRandom.cpp:37