Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F8308939
CRandom.cpp
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
CRandom.cpp
View Options
#include
"CRandom.h"
float
const
CRandom
::
pi
=
acos
(
-
1.
);
bool
CRandom
::
one
=
1
;
float
CRandom
::
angle
=
0.
;
float
CRandom
::
x
=
0.
;
/**
* Returns a random number with uniform distribution between 0 and 1
*/
double
CRandom
::
Rndm
()
{
return
(
float
)
rand
()
/
(
float
)
RAND_MAX
;
}
//***********************
/**
* Returns random number with Gaussian distribution
\param mean is the mean value of the Gaussian distribution
\param sigma is the standard deviation of the distribution
*/
float
CRandom
::
Gaus
(
float
mean
,
float
sigma
)
{
float
r
;
if
(
one
)
{
x
=
sqrt
(
-
2.
*
log
(
Rndm
()
+
1.e-37
));
angle
=
2.
*
pi
*
Rndm
();
one
=
0
;
r
=
x
*
cos
(
angle
);
}
else
{
r
=
x
*
sin
(
angle
);
one
=
1
;
}
return
sigma
*
r
+
mean
;
}
//*************************
/**
* returns a decay time in zs sampled from a exponential distribution
\param width is the total decay width in MeV
*/
float
CRandom
::
expDecayTime
(
float
width
)
{
// returns a time from an exponential decay distribution
//consistent with the total decay width
return
-
0.65824
*
log
(
Rndm
()
+
1.0e-37
)
/
width
;
}
//****************************************
/**
* Returns a random number with a BreitWigner distribution
\param mean is the mean value of the distribution
\param width is the Full Width Half max of the distribution
*/
float
CRandom
::
BreitWigner
(
float
mean
,
float
width
)
{
float
xx
=
(
1.
-
2.
*
Rndm
())
*
pi
/
2.
;
float
yy
=
tan
(
xx
)
/
2.
;
return
yy
*
width
+
mean
;
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sat, Dec 21, 1:40 PM (15 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4003201
Default Alt Text
CRandom.cpp (1 KB)
Attached To
rSARTRESVN sartresvn
Event Timeline
Log In to Comment