Geant4 Cross Reference |
1 // -*- C++ -*- 1 2 // 3 // ------------------------------------------- 4 // HEP Random 5 // --- RandGeneral -- 6 // class header file 7 // ------------------------------------------- 8 9 // Class defining methods for shooting general 10 // given a user-defined probability distributi 11 12 // =========================================== 13 // S.Magni & G.Pieri - Created: 29 April 1998 14 // G.Cosmo - Added constructor usin 15 // static generator: 20 A 16 // S.Magni & G.Pieri - Added linear interpola 17 // M. Fischler - Added private methods 18 // prepareTables(), useFlatDistribution() 19 // - Added private variable oneOverNb 20 // - Made the warning about shoot 21 // more prominent. 14 May 1999 22 // M Fischler - put and get to/from st 23 // =========================================== 24 25 #ifndef RandGeneral_h 26 #define RandGeneral_h 1 27 28 #include "CLHEP/Random/Random.h" 29 #include "CLHEP/Utility/memory.h" 30 #include <vector> 31 32 namespace CLHEP { 33 34 /** 35 * @author 36 * @ingroup random 37 */ 38 class RandGeneral : public HepRandom { 39 40 public: 41 42 RandGeneral ( const double* aProbFunc, 43 int theProbSize, 44 int IntType=0 ); 45 RandGeneral ( HepRandomEngine& anEngine, 46 const double* aProbFunc, 47 int theProbSize, 48 int IntType=0 ); 49 RandGeneral ( HepRandomEngine* anEngine, 50 const double* aProbFunc, 51 int theProbSize, 52 int IntType=0 ); 53 // These constructors should be used to inst 54 // distribution object defining a local engi 55 // The static generator will be skipped by u 56 // defined below. In case no engine is speci 57 // default engine used by the static generat 58 // If the engine is passed by pointer the co 59 // will be deleted by the RandGeneral destru 60 // If the engine is passed by reference the 61 // will not be deleted by the RandGeneral de 62 // The probability distribution function (Pd 63 // as an array of positive real number. The 64 // provided. The Pdf doesn't need to be norm 65 // if IntType = 0 ( default value ) a unifor 66 // generated using the engine. The uniform n 67 // to the user's distribution using the cumu 68 // distribution constructed from his histogr 69 // distribution is inverted using a binary s 70 // bin boundary and a linear interpolation w 71 // bin. RandGeneral therefore generates a co 72 // each bin. 73 // if IntType = 1 no interpolation is perfor 74 // discrete distribution. 75 76 virtual ~RandGeneral(); 77 // Destructor 78 79 // Methods to shoot random values using the 80 // N.B.: The methods are NOT static since th 81 // theIntegralPdf & nBins 82 83 ///////////////////// 84 // // 85 // BIG RED WARNING // 86 // // 87 ///////////////////// 88 // 89 // The above N.B. is telling users that the 90 // class are NOT STATIC. You cannot do 91 // double x = RandGeneral::shoot(); 92 // It would not make sense to provide a stat 93 // the default probability function look lik 94 95 inline double shoot(); 96 97 inline void shootArray ( const int size, dou 98 99 // Methods to shoot random values using a g 100 // by-passing the static generator. 101 102 double shoot( HepRandomEngine* anEngine ); 103 104 void shootArray ( HepRandomEngine* anEngine, 105 double* vect ); 106 107 // Methods using the localEngine to shoot r 108 // the static generator. 109 110 double fire(); 111 112 void fireArray ( const int size, double* vec 113 114 double operator()(); 115 116 // Save and restore to/from streams 117 118 std::ostream & put ( std::ostream & os ) con 119 std::istream & get ( std::istream & is ); 120 121 std::string name() const; 122 HepRandomEngine & engine(); 123 124 static std::string distributionName() {retur 125 // Provides the name of this distribution cl 126 127 128 private: 129 130 std::shared_ptr<HepRandomEngine> localEngine 131 std::vector<double> theIntegralPdf; 132 int nBins; 133 double oneOverNbins; 134 int InterpolationType; 135 136 // Private methods to factor out replicated 137 void prepareTable(const double* aProbFunc); 138 void useFlatDistribution(); 139 double mapRandom(double rand) const; 140 141 }; 142 143 } // namespace CLHEP 144 145 #include "CLHEP/Random/RandGeneral.icc" 146 147 #endif 148