Geant4 Cross Reference |
1 // 1 2 // -*- C++ -*- 3 // 4 // ------------------------------------------- 5 // HEP Random 6 // --- RanluxppEngine -- 7 // class header file 8 // ------------------------------------------- 9 // Implementation of the RANLUX++ generator 10 // 11 // RANLUX++ is an LCG equivalent of RANLUX usi 12 // 13 // References: 14 // A. Sibidanov 15 // A revision of the subtract-with-borrow ra 16 // Computer Physics Communications, 221(2017 17 // 18 // J. Hahnfeld, L. Moneta 19 // A Portable Implementation of RANLUX++ 20 // vCHEP2021 21 22 #ifndef RanluxppEngine_h 23 #define RanluxppEngine_h 24 25 #include "CLHEP/Random/RandomEngine.h" 26 27 #include <cstdint> 28 29 namespace CLHEP { 30 31 /** 32 * @author Jonas Hahnfeld 33 * @ingroup random 34 */ 35 class RanluxppEngine final : public HepRandomE 36 37 public: 38 RanluxppEngine(); 39 RanluxppEngine(long seed); 40 RanluxppEngine(std::istream &is); 41 virtual ~RanluxppEngine(); 42 // Constructors and destructor 43 44 double flat() override; 45 // It returns a pseudo random number between 46 // excluding the end points. 47 48 void flatArray(const int size, double *vect) 49 // Fills the array "vect" of specified size 50 51 void setSeed(long seed, int dummy = 0) overr 52 // Sets the state of the algorithm according 53 54 void setSeeds(const long *seeds, int dummy = 55 // Sets the state of the algorithm according 56 // array of seeds. Only the first seed is u 57 58 void skip(uint64_t n); 59 // Skip `n` random numbers without generatin 60 61 void saveStatus(const char filename[] = "Ran 62 // Saves in named file the current engine st 63 64 void restoreStatus(const char filename[] = " 65 // Reads from named file the last saved engi 66 67 void showStatus() const override; 68 // Dumps the engine status on the screen. 69 70 std::string name() const override; 71 72 // Optional methods to serialize the engine' 73 static std::string engineName(); 74 static std::string beginTag(); 75 76 std::ostream &put(std::ostream &os) const ov 77 std::istream &get(std::istream &is) override 78 79 std::istream &getState(std::istream &is) ove 80 81 std::vector<unsigned long> put() const overr 82 bool get(const std::vector<unsigned long> &v 83 bool getState(const std::vector<unsigned lon 84 85 // Save and restore to/from streams 86 operator double() override { return flat(); 87 operator float() override { return float(fla 88 operator unsigned int() override { return (u 89 90 // 1 value for the engine ID, 2 * 9 values f 91 // for the carry bit and the position. 92 static const unsigned int VECTOR_STATE_SIZE 93 94 private: 95 void advance(); 96 uint64_t nextRandomBits(); 97 98 uint64_t fState[9]; ///< RANLUX state of the 99 unsigned fCarry; ///< Carry bit of the RA 100 int fPosition = 0; ///< Current position in 101 102 }; // RanluxppEngine 103 104 } // namespace CLHEP 105 106 #endif 107