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
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #ifndef RandExpZiggurat_h
0038 #define RandExpZiggurat_h 1
0039
0040 #include "CLHEP/Random/defs.h"
0041 #include "CLHEP/Random/Random.h"
0042 #include "CLHEP/Utility/memory.h"
0043 #include "CLHEP/Utility/thread_local.h"
0044
0045 namespace CLHEP {
0046
0047
0048
0049
0050
0051 class RandExpZiggurat : public HepRandom {
0052
0053 public:
0054
0055 inline RandExpZiggurat ( HepRandomEngine& anEngine, double mean=1.0 );
0056 inline RandExpZiggurat ( HepRandomEngine* anEngine, double mean=1.0 );
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 virtual ~RandExpZiggurat();
0067
0068
0069
0070
0071 static float shoot() {return shoot(HepRandom::getTheEngine());};
0072 static float shoot( float mean ) {return shoot(HepRandom::getTheEngine(),mean);};
0073
0074
0075
0076
0077
0078
0079 static void shootArray ( const int size, float* vect, float mean=1.0 );
0080 static void shootArray ( const int size, double* vect, double mean=1.0 );
0081
0082
0083
0084
0085 static inline float shoot( HepRandomEngine* anEngine ) {return ziggurat_REXP(anEngine);};
0086 static inline float shoot( HepRandomEngine* anEngine, float mean ) {return shoot(anEngine)*mean;};
0087
0088
0089
0090
0091
0092
0093
0094 static void shootArray ( HepRandomEngine* anEngine, const int size, float* vect, float mean=1.0 );
0095 static void shootArray ( HepRandomEngine* anEngine, const int size, double* vect, double mean=1.0 );
0096
0097
0098
0099
0100 inline float fire() {return fire(defaultMean);};
0101 inline float fire( float mean ) {return ziggurat_REXP(localEngine.get())*mean;};
0102
0103
0104
0105
0106
0107
0108 void fireArray ( const int size, float* vect );
0109 void fireArray ( const int size, double* vect );
0110 void fireArray ( const int size, float* vect, float mean );
0111 void fireArray ( const int size, double* vect, double mean );
0112
0113 virtual double operator()();
0114 inline float operator()( float mean ) {return fire( mean );};
0115
0116
0117
0118 std::ostream & put ( std::ostream & os ) const;
0119 std::istream & get ( std::istream & is );
0120
0121 std::string name() const;
0122 HepRandomEngine & engine();
0123
0124 static std::string distributionName() {return "RandExpZiggurat";}
0125
0126
0127 static bool ziggurat_init();
0128 protected:
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145 static CLHEP_THREAD_LOCAL unsigned long kn[128], ke[256];
0146 static CLHEP_THREAD_LOCAL float wn[128],fn[128], we[256],fe[256];
0147
0148 static CLHEP_THREAD_LOCAL bool ziggurat_is_init;
0149
0150 static inline unsigned long ziggurat_SHR3(HepRandomEngine* anEngine) {return (unsigned int)(*anEngine);};
0151 static inline float ziggurat_UNI(HepRandomEngine* anEngine) {return anEngine->flat();};
0152 static inline float ziggurat_REXP(HepRandomEngine* anEngine) {
0153 if(!ziggurat_is_init) ziggurat_init();
0154 unsigned long jz=ziggurat_SHR3(anEngine);
0155 unsigned long iz=jz&255;
0156 return (jz<ke[iz]) ? jz*we[iz] : ziggurat_efix(jz,anEngine);
0157 };
0158 static float ziggurat_efix(unsigned long jz,HepRandomEngine* anEngine);
0159
0160 private:
0161
0162
0163 RandExpZiggurat(const RandExpZiggurat& d);
0164
0165 std::shared_ptr<HepRandomEngine> localEngine;
0166 double defaultMean;
0167 };
0168
0169 }
0170
0171 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0172
0173 using namespace CLHEP;
0174 #endif
0175
0176 namespace CLHEP {
0177
0178 inline RandExpZiggurat::RandExpZiggurat(HepRandomEngine & anEngine, double mean ) : localEngine(&anEngine, do_nothing_deleter()), defaultMean(mean)
0179 {
0180 }
0181
0182 inline RandExpZiggurat::RandExpZiggurat(HepRandomEngine * anEngine, double mean ) : localEngine(anEngine), defaultMean(mean)
0183 {
0184 }
0185
0186 }
0187
0188 #endif