File indexing completed on 2026-04-09 07:49:29
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <vector>
0017 #include <string>
0018 #include <iostream>
0019 #include <iomanip>
0020 #include <sstream>
0021 #include <cstdlib>
0022 #include <csignal>
0023 #include <cassert>
0024
0025 #include "Randomize.hh"
0026 #include "G4Types.hh"
0027 #include "CLHEP/Random/RandomEngine.h"
0028 #include "NPX.h"
0029
0030 struct S4RandomArray : public CLHEP::HepRandomEngine
0031 {
0032 static constexpr const char* NAME = "S4RandomArray.npy" ;
0033
0034 std::vector<double> m_array ;
0035 CLHEP::HepRandomEngine* m_engine ;
0036
0037 S4RandomArray();
0038 void clear();
0039 NP* serialize() const ;
0040
0041
0042 double flat();
0043 void flatArray(const int size, double* vect);
0044 void setSeed(long seed, int);
0045 void setSeeds(const long * seeds, int);
0046 void saveStatus( const char filename[] = "Config.conf") const ;
0047 void restoreStatus( const char filename[] = "Config.conf" ) ;
0048 void showStatus() const ;
0049 std::string name() const ;
0050
0051 };
0052
0053 inline S4RandomArray::S4RandomArray()
0054 :
0055 m_engine(CLHEP::HepRandom::getTheEngine())
0056 {
0057 CLHEP::HepRandom::setTheEngine(this);
0058 }
0059
0060 inline void S4RandomArray::clear()
0061 {
0062 m_array.clear();
0063 }
0064 inline NP* S4RandomArray::serialize() const
0065 {
0066 return NPX::ArrayFromVec<double, double>(m_array) ;
0067 }
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 inline double S4RandomArray::flat()
0079 {
0080 double d = m_engine->flat();
0081 m_array.push_back(d) ;
0082 return d ;
0083 }
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093 inline void S4RandomArray::flatArray(const int size, double* vect)
0094 {
0095 m_engine->flatArray(size, vect);
0096 for(int i=0 ; i < size ; i++) m_array.push_back(vect[i]) ;
0097 }
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 inline void S4RandomArray::setSeed(long seed, int)
0110 {
0111 assert(0);
0112 }
0113 inline void S4RandomArray::setSeeds(const long * seeds, int)
0114 {
0115 assert(0);
0116 }
0117 inline void S4RandomArray::saveStatus( const char filename[]) const
0118 {
0119 assert(0);
0120 }
0121 inline void S4RandomArray::restoreStatus( const char filename[])
0122 {
0123 assert(0);
0124 }
0125 inline void S4RandomArray::showStatus() const
0126 {
0127 assert(0);
0128 }
0129 inline std::string S4RandomArray::name() const
0130 {
0131 return NAME ;
0132 }
0133