Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
24
25namespace CLHEP {
26
27std::string RandExponential::name() const {return "RandExponential";}
28HepRandomEngine & RandExponential::engine() {return *localEngine;}
29
31}
32
34 return fire( defaultMean );
35}
36
37double RandExponential::operator()( double mean ) {
38 return fire( mean );
39}
40
42 return -std::log(HepRandom::getTheEngine()->flat());
43}
44
45double RandExponential::shoot(double mean) {
46 return -std::log(HepRandom::getTheEngine()->flat())*mean;
47}
48
49void 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
56void 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
63void RandExponential::fireArray( const int size, double* vect)
64{
65 for( double* v = vect; v != vect+size; ++v )
66 *v = fire( defaultMean );
67}
68
69void 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
76std::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
87std::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
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:114
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:98
static HepRandomEngine * getTheEngine()
Definition: Random.cc:165
double flat()
Definition: Random.cc:96
std::ostream & put(std::ostream &os) const
static void shootArray(const int size, double *vect, double mean=1.0)
std::istream & get(std::istream &is)
std::string name() const
void fireArray(const int size, double *vect)
HepRandomEngine & engine()
Definition: DoubConv.h:17
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167