File indexing completed on 2025-01-18 09:54:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #ifndef RandGaussZiggurat_h
0025 #define RandGaussZiggurat_h 1
0026
0027 #include "cmath"
0028 #include "CLHEP/Random/defs.h"
0029 #include "CLHEP/Random/RandGauss.h"
0030 #include "CLHEP/Utility/thread_local.h"
0031
0032 namespace CLHEP {
0033
0034
0035
0036
0037
0038 class RandGaussZiggurat : public RandGauss {
0039
0040 public:
0041
0042 inline RandGaussZiggurat ( HepRandomEngine& anEngine, double mean=0.0, double stdDev=1.0 );
0043 inline RandGaussZiggurat ( HepRandomEngine* anEngine, double mean=0.0, double stdDev=1.0 );
0044
0045
0046 virtual ~RandGaussZiggurat();
0047
0048
0049
0050 static inline float shoot() {return ziggurat_RNOR(HepRandom::getTheEngine());};
0051 static inline float shoot( float mean, float stdDev ) {return shoot()*stdDev + mean;};
0052
0053 static void shootArray ( const int size, float* vect, float mean=0.0, float stdDev=1.0 );
0054 static void shootArray ( const int size, double* vect, double mean=0.0, double stdDev=1.0 );
0055
0056
0057
0058
0059 static inline float shoot( HepRandomEngine* anotherEngine ) {return ziggurat_RNOR(anotherEngine);};
0060 static inline float shoot( HepRandomEngine* anotherEngine, float mean, float stdDev ) {return shoot(anotherEngine)*stdDev + mean;};
0061
0062 static void shootArray ( HepRandomEngine* anotherEngine, const int size, float* vect, float mean=0.0, float stdDev=1.0 );
0063 static void shootArray ( HepRandomEngine* anotherEngine, const int size, double* vect, double mean=0.0, double stdDev=1.0 );
0064
0065
0066
0067
0068 inline float fire() {return ziggurat_RNOR(localEngine.get()) * defaultStdDev + defaultMean;};
0069
0070 inline float fire ( float mean, float stdDev ) {return ziggurat_RNOR(localEngine.get()) * stdDev + mean;};
0071
0072 void fireArray ( const int size, float* vect);
0073 void fireArray ( const int size, double* vect);
0074 void fireArray ( const int size, float* vect, float mean, float stdDev );
0075 void fireArray ( const int size, double* vect, double mean, double stdDev );
0076
0077 virtual double operator()();
0078 virtual double operator()( double mean, double stdDev );
0079
0080
0081
0082 std::ostream & put ( std::ostream & os ) const;
0083 std::istream & get ( std::istream & is );
0084
0085 std::string name() const;
0086 HepRandomEngine & engine();
0087
0088 static std::string distributionName() {return "RandGaussZiggurat";}
0089
0090
0091 static bool ziggurat_init();
0092 protected:
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 static CLHEP_THREAD_LOCAL unsigned long kn[128], ke[256];
0110 static CLHEP_THREAD_LOCAL float wn[128],fn[128], we[256],fe[256];
0111
0112 static CLHEP_THREAD_LOCAL bool ziggurat_is_init;
0113
0114 static inline unsigned long ziggurat_SHR3(HepRandomEngine* anEngine) {return (unsigned int)(*anEngine);};
0115 static inline float ziggurat_UNI(HepRandomEngine* anEngine) {return anEngine->flat();};
0116 static inline float ziggurat_RNOR(HepRandomEngine* anEngine) {
0117 if(!ziggurat_is_init) ziggurat_init();
0118 long hz=(signed)ziggurat_SHR3(anEngine);
0119 unsigned long iz=hz&127;
0120 return ((unsigned long)std::abs(hz)<kn[iz]) ? hz*wn[iz] : ziggurat_nfix(hz,anEngine);
0121 };
0122 static float ziggurat_nfix(long hz,HepRandomEngine* anEngine);
0123
0124 private:
0125
0126
0127 RandGaussZiggurat(const RandGaussZiggurat& d);
0128
0129
0130
0131
0132 };
0133
0134 }
0135
0136 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0137
0138 using namespace CLHEP;
0139 #endif
0140
0141 namespace CLHEP {
0142
0143 RandGaussZiggurat::RandGaussZiggurat(HepRandomEngine & anEngine, double mean,double stdDev ): RandGauss(anEngine, mean, stdDev)
0144 {
0145 }
0146
0147 RandGaussZiggurat::RandGaussZiggurat(HepRandomEngine * anEngine, double mean,double stdDev ): RandGauss(anEngine, mean, stdDev)
0148 {
0149 }
0150
0151 }
0152
0153 #endif