CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

RandExponential.cc
Go to the documentation of this file.
1 // $Id: RandExponential.cc,v 1.6 2010/06/16 17:24:53 garren Exp $
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/defs.h"
23 #include "CLHEP/Random/RandExponential.h"
24 #include "CLHEP/Random/DoubConv.hh"
25 
26 namespace CLHEP {
27 
28 std::string RandExponential::name() const {return "RandExponential";}
29 HepRandomEngine & RandExponential::engine() {return *localEngine;}
30 
32 }
33 
35  return fire( defaultMean );
36 }
37 
38 double RandExponential::operator()( double mean ) {
39  return fire( mean );
40 }
41 
43  return -std::log(HepRandom::getTheEngine()->flat());
44 }
45 
46 double RandExponential::shoot(double mean) {
47  return -std::log(HepRandom::getTheEngine()->flat())*mean;
48 }
49 
50 void RandExponential::shootArray( const int size, double* vect,
51  double mean )
52 {
53  for( double* v = vect; v != vect+size; ++v )
54  *v = shoot(mean);
55 }
56 
58  double* vect, double mean )
59 {
60  for( double* v = vect; v != vect+size; ++v )
61  *v = shoot(anEngine, mean);
62 }
63 
64 void RandExponential::fireArray( const int size, double* vect)
65 {
66  for( double* v = vect; v != vect+size; ++v )
67  *v = fire( defaultMean );
68 }
69 
70 void RandExponential::fireArray( const int size, double* vect,
71  double mean )
72 {
73  for( double* v = vect; v != vect+size; ++v )
74  *v = fire( mean );
75 }
76 
77 std::ostream & RandExponential::put ( std::ostream & os ) const {
78  int pr=os.precision(20);
79  std::vector<unsigned long> t(2);
80  os << " " << name() << "\n";
81  os << "Uvec" << "\n";
82  t = DoubConv::dto2longs(defaultMean);
83  os << defaultMean << " " << t[0] << " " << t[1] << "\n";
84  os.precision(pr);
85  return os;
86 #ifdef REMOVED
87  int pr=os.precision(20);
88  os << " " << name() << "\n";
89  os << defaultMean << "\n";
90  os.precision(pr);
91  return os;
92 #endif
93 }
94 
95 std::istream & RandExponential::get ( std::istream & is ) {
96  std::string inName;
97  is >> inName;
98  if (inName != name()) {
99  is.clear(std::ios::badbit | is.rdstate());
100  std::cerr << "Mismatch when expecting to read state of a "
101  << name() << " distribution\n"
102  << "Name found was " << inName
103  << "\nistream is left in the badbit state\n";
104  return is;
105  }
106  if (possibleKeywordInput(is, "Uvec", defaultMean)) {
107  std::vector<unsigned long> t(2);
108  is >> defaultMean >> t[0] >> t[1]; defaultMean = DoubConv::longs2double(t);
109  return is;
110  }
111  // is >> defaultMean encompassed by possibleKeywordInput
112  return is;
113 }
114 
115 
116 } // namespace CLHEP
CLHEP::RandExponential::engine
HepRandomEngine & engine()
Definition: RandExponential.cc:29
CLHEP::RandExponential::fire
double fire()
CLHEP::HepRandomEngine
Definition: Matrix/CLHEP/Random/RandomEngine.h:55
CLHEP::RandExponential::~RandExponential
virtual ~RandExponential()
Definition: RandExponential.cc:31
is
HepRotation and so forth isNear() norm2() rectify() static Rotation row1 row4(To avoid bloat in the code pulled in for programs which don 't use all these features, we split the implementation .cc files. Only isNear() goes into the original Rotation.cc) --------------------------------------- HepAxisAngle and HepEulerAngles classes --------------------------------------- These classes are very useful and simple structures for holding the result of a nice intuituve decomposition of a rotation there is no longer much content in the distinct ZOOM PhysicsVectors library The only content left in the library is the object files representing the various Exception objects When we build the CLHEP classes for the ZOOM we will set up so as to use ZOOM SpaceVector is(but we can disable namespace usage and most of our users do so at this point). What I do is leave Hep3Vector in the global namespace
CLHEP::RandExponential::operator()
double operator()()
Definition: RandExponential.cc:34
CLHEP::DoubConv::longs2double
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:106
CLHEP::RandExponential::fireArray
void fireArray(const int size, double *vect)
Definition: RandExponential.cc:64
size
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno size() Return the(integer) number of ZMthrow 'n exceptions currently recorded. 5) ZMerrno.clear() Set an internal counter to zero. This counter is available(see next function) to user code to track ZMthrow 'n exceptions that have occurred during any arbitrary time interval. 6) ZMerrno.countSinceCleared() Return the(integer) number of ZMthrow 'n exceptions that have been recorded via ZMerrno.write()
CLHEP::RandExponential::shoot
static double shoot()
Definition: RandExponential.cc:42
CLHEP
Definition: ClhepVersion.h:13
v
they are gone ZOOM Features Discontinued The following features of the ZOOM package were felt to be extreme overkill These have been after checking that no existing user code was utilizing as in SpaceVector v
Definition: keyMergeIssues.doc:324
CLHEP::possibleKeywordInput
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: Matrix/CLHEP/Random/RandomEngine.h:168
CLHEP::RandExponential::get
std::istream & get(std::istream &is)
Definition: RandExponential.cc:95
CLHEP::DoubConv::dto2longs
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:90
CLHEP::RandExponential::shootArray
static void shootArray(const int size, double *vect, double mean=1.0)
Definition: RandExponential.cc:50
CLHEP::HepRandom::getTheEngine
static HepRandomEngine * getTheEngine()
Definition: Random.cc:166
CLHEP::HepRandom::flat
double flat()
Definition: Random.cc:97
CLHEP::RandExponential::name
std::string name() const
Definition: RandExponential.cc:28
CLHEP::RandExponential::put
std::ostream & put(std::ostream &os) const
Definition: RandExponential.cc:77