Geant4
9.6.p02
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
geant4_9_6_p02
source
externals
clhep
src
RandExponential.cc
Go to the documentation of this file.
1
// $Id:$
2
// -*- C++ -*-
3
//
4
// -----------------------------------------------------------------------
5
// HEP Random
6
// --- RandExponential ---
7
// class implementation file
8
// -----------------------------------------------------------------------
9
// This file is part of Geant4 (simulation toolkit for HEP).
10
11
// =======================================================================
12
// Gabriele Cosmo - Created: 17th May 1996
13
// - Added methods to shoot arrays: 28th July 1997
14
// J.Marraffino - Added default mean as attribute and
15
// operator() with mean: 16th Feb 1998
16
// M Fischler - put and get to/from streams 12/15/04
17
// M Fischler - put/get to/from streams uses pairs of ulongs when
18
// + storing doubles avoid problems with precision
19
// 4/14/05
20
// =======================================================================
21
22
#include "
CLHEP/Random/RandExponential.h
"
23
#include "
CLHEP/Random/DoubConv.h
"
24
25
namespace
CLHEP {
26
27
std::string
RandExponential::name
()
const
{
return
"RandExponential"
;}
28
HepRandomEngine
&
RandExponential::engine
() {
return
*localEngine;}
29
30
RandExponential::~RandExponential
() {
31
}
32
33
double
RandExponential::operator()
() {
34
return
fire
( defaultMean );
35
}
36
37
double
RandExponential::operator()
(
double
mean ) {
38
return
fire
( mean );
39
}
40
41
double
RandExponential::shoot
() {
42
return
-std::log(
HepRandom::getTheEngine
()->
flat
());
43
}
44
45
double
RandExponential::shoot
(
double
mean) {
46
return
-std::log(
HepRandom::getTheEngine
()->
flat
())*mean;
47
}
48
49
void
RandExponential::shootArray
(
const
int
size,
double
* vect,
50
double
mean )
51
{
52
for
(
double
*
v
= vect;
v
!= vect+size; ++
v
)
53
*
v
=
shoot
(mean);
54
}
55
56
void
RandExponential::shootArray
(
HepRandomEngine
* anEngine,
const
int
size,
57
double
* vect,
double
mean )
58
{
59
for
(
double
*
v
= vect;
v
!= vect+size; ++
v
)
60
*
v
=
shoot
(anEngine, mean);
61
}
62
63
void
RandExponential::fireArray
(
const
int
size,
double
* vect)
64
{
65
for
(
double
*
v
= vect;
v
!= vect+size; ++
v
)
66
*
v
=
fire
( defaultMean );
67
}
68
69
void
RandExponential::fireArray
(
const
int
size,
double
* vect,
70
double
mean )
71
{
72
for
(
double
*
v
= vect;
v
!= vect+size; ++
v
)
73
*
v
=
fire
( mean );
74
}
75
76
std::ostream &
RandExponential::put
( std::ostream & os )
const
{
77
int
pr
=os.precision(20);
78
std::vector<unsigned long> t(2);
79
os <<
" "
<<
name
() <<
"\n"
;
80
os <<
"Uvec"
<<
"\n"
;
81
t =
DoubConv::dto2longs
(defaultMean);
82
os << defaultMean <<
" "
<< t[0] <<
" "
<< t[1] <<
"\n"
;
83
os.precision(pr);
84
return
os;
85
}
86
87
std::istream &
RandExponential::get
( std::istream & is ) {
88
std::string inName;
89
is >> inName;
90
if
(inName !=
name
()) {
91
is.clear(std::ios::badbit | is.rdstate());
92
std::cerr <<
"Mismatch when expecting to read state of a "
93
<<
name
() <<
" distribution\n"
94
<<
"Name found was "
<< inName
95
<<
"\nistream is left in the badbit state\n"
;
96
return
is;
97
}
98
if
(
possibleKeywordInput
(is,
"Uvec"
, defaultMean)) {
99
std::vector<unsigned long> t(2);
100
is >> defaultMean >> t[0] >> t[1]; defaultMean =
DoubConv::longs2double
(t);
101
return
is;
102
}
103
// is >> defaultMean encompassed by possibleKeywordInput
104
return
is;
105
}
106
107
108
}
// namespace CLHEP
Generated on Sat May 25 2013 14:33:07 for Geant4 by
1.8.4