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10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/clhep/src/RandExponential.cc (Version 11.3.0) and /externals/clhep/src/RandExponential.cc (Version 10.6.p3)


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