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