Geant4 Cross Reference |
1 // -*- C++ -*- 1 2 // 3 // ------------------------------------------- 4 // HEP Random 5 // --- RandExponential - 6 // class implementation f 7 // ------------------------------------------- 8 // This file is part of Geant4 (simulation too 9 10 // =========================================== 11 // Gabriele Cosmo - Created: 17th May 1996 12 // - Added methods to shoot arr 13 // J.Marraffino - Added default mean as attr 14 // operator() with mean: 16th 15 // M Fischler - put and get to/from strea 16 // M Fischler - put/get to/from streams 17 // + storing doubles avoid problems with 18 // 4/14/05 19 // =========================================== 20 21 #include "CLHEP/Random/RandExponential.h" 22 #include "CLHEP/Random/DoubConv.h" 23 #include <cmath> 24 #include <iostream> 25 #include <string> 26 #include <vector> 27 28 namespace CLHEP { 29 30 std::string RandExponential::name() const {ret 31 HepRandomEngine & RandExponential::engine() {r 32 33 RandExponential::~RandExponential() { 34 } 35 36 double RandExponential::operator()() { 37 return fire( defaultMean ); 38 } 39 40 double RandExponential::operator()( double mea 41 return fire( mean ); 42 } 43 44 double RandExponential::shoot() { 45 return -std::log(HepRandom::getTheEngine()-> 46 } 47 48 double RandExponential::shoot(double mean) { 49 return -std::log(HepRandom::getTheEngine()-> 50 } 51 52 void RandExponential::shootArray( const int si 53 double mean 54 { 55 for( double* v = vect; v != vect+size; ++v ) 56 *v = shoot(mean); 57 } 58 59 void RandExponential::shootArray(HepRandomEngi 60 double* vec 61 { 62 for( double* v = vect; v != vect+size; ++v ) 63 *v = shoot(anEngine, mean); 64 } 65 66 void RandExponential::fireArray( const int siz 67 { 68 for( double* v = vect; v != vect+size; ++v ) 69 *v = fire( defaultMean ); 70 } 71 72 void RandExponential::fireArray( const int siz 73 double mean ) 74 { 75 for( double* v = vect; v != vect+size; ++v ) 76 *v = fire( mean ); 77 } 78 79 std::ostream & RandExponential::put ( std::ost 80 long pr=os.precision(20); 81 std::vector<unsigned long> t(2); 82 os << " " << name() << "\n"; 83 os << "Uvec" << "\n"; 84 t = DoubConv::dto2longs(defaultMean); 85 os << defaultMean << " " << t[0] << " " << t 86 os.precision(pr); 87 return os; 88 } 89 90 std::istream & RandExponential::get ( std::ist 91 std::string inName; 92 is >> inName; 93 if (inName != name()) { 94 is.clear(std::ios::badbit | is.rdstate()); 95 std::cerr << "Mismatch when expecting to r 96 << name() << " distribution\n" 97 << "Name found was " << inName 98 << "\nistream is left in the badbit st 99 return is; 100 } 101 if (possibleKeywordInput(is, "Uvec", default 102 std::vector<unsigned long> t(2); 103 is >> defaultMean >> t[0] >> t[1]; default 104 return is; 105 } 106 // is >> defaultMean encompassed by possible 107 return is; 108 } 109 110 111 } // namespace CLHEP 112