EvtGen 2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Loading...
Searching...
No Matches
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
22
26
27#include <iostream>
28#include <math.h>
29#include <stdio.h>
30#include <stdlib.h>
31
32using std::endl;
33
34thread_local EvtRandomEngine* EvtRandom::m_randomEngine = nullptr;
35
37{
38 m_randomEngine = randomEngine;
39}
40
42{
43 if ( m_randomEngine == nullptr ) {
44 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
45 << "No random engine available in "
46 << "EvtRandom::random()." << endl;
47 ::abort();
48 }
49
50 return m_randomEngine->random();
51}
52
53void EvtRandom::setSeed( unsigned long int seed )
54{
55 if ( m_randomEngine == nullptr ) {
56 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
57 << "No random engine available in "
58 << "EvtRandom::random()." << endl;
59 ::abort();
60 }
61
62 m_randomEngine->setSeed( seed );
63}
64
65unsigned long int EvtRandom::lastSeed()
66{
67 if ( m_randomEngine == nullptr ) {
68 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
69 << "No random engine available in "
70 << "EvtRandom::random()." << endl;
71 ::abort();
72 }
73
74 return m_randomEngine->lastSeed();
75}
76
77// Random number routine to generate numbers between
78// min and max. By djl on July 27, 1995.
79double EvtRandom::Flat( double min, double max )
80{
81 if ( min > max ) {
82 EvtGenReport( EVTGEN_ERROR, "EvtGen" )
83 << "min>max in EvtRandom::Flat(" << min << "," << max << ")" << endl;
84 ::abort();
85 }
86
87 return EvtRandom::random() * ( max - min ) + min;
88}
89
90double EvtRandom::Flat( double max )
91{
92 return max * EvtRandom::random();
93}
94
96{
97 return EvtRandom::random();
98}
99
101{
102 double x = EvtRandom::random();
103 double y = EvtRandom::random();
104
105 return cos( x * EvtConst::twoPi ) * sqrt( -2.0 * log( 1 - y ) );
106}
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=nullptr)
Definition EvtReport.cpp:32
@ EVTGEN_ERROR
Definition EvtReport.hh:49
static const double twoPi
Definition EvtConst.hh:27
static unsigned long int lastSeed()
Definition EvtRandom.cpp:65
static double random()
Definition EvtRandom.cpp:41
static double Flat()
Definition EvtRandom.cpp:95
static EvtRandomEngine * m_randomEngine
Definition EvtRandom.hh:47
static void setSeed(unsigned long int seed)
Definition EvtRandom.cpp:53
static double Gaussian()
static void setRandomEngine(EvtRandomEngine *randomEngine)
Definition EvtRandom.cpp:36