52 #include "RanecuEngine.h"
53 #if __SUNPRO_CC < 0x500
59 RanecuEngine::RanecuEngine(HepInt index)
60 : ecuyer_a(40014),ecuyer_b(53668),ecuyer_c(12211),
61 ecuyer_d(40692),ecuyer_e(52774),ecuyer_f(3791),
62 shift1(2147483563),shift2(2147483399),maxSeq(215),
65 seq = abs(HepInt(index%maxSeq));
67 for (HepInt i=0; i<2; ++i)
68 for (HepInt j=0; j<maxSeq; ++j)
69 table[j][i] = seedTable[j][i];
70 theSeeds = &table[seq][0];
73 RanecuEngine::~RanecuEngine() {}
76 : ecuyer_a(40014),ecuyer_b(53668),ecuyer_c(12211),
77 ecuyer_d(40692),ecuyer_e(52774),ecuyer_f(3791),
78 shift1(2147483563),shift2(2147483399),maxSeq(215),
81 if ((
this != &p) && (&p)) {
82 theSeed = p.getSeed();
84 for (HepInt i=0; i<2; ++i)
85 for (HepInt j=0; j<maxSeq; ++j)
86 table[j][i] = p.table[j][i];
88 theSeeds = &table[seq][0];
94 if ((
this != &p) && (&p)) {
95 theSeed = p.getSeed();
97 for (HepInt i=0; i<2; ++i)
98 for (HepInt j=0; j<maxSeq; ++j)
99 table[j][i] = p.table[j][i];
101 theSeeds = &table[seq][0];
106 void RanecuEngine::setSeed(
long index, HepInt)
108 seq = abs(HepInt(index%maxSeq));
110 theSeeds = &table[seq][0];
113 void RanecuEngine::setSeeds(
const long* seeds, HepInt pos)
116 seq = abs(HepInt(pos%maxSeq));
119 if ((seeds[0] > 0) && (seeds[1] > 0)) {
120 table[seq][0] = seeds[0];
121 table[seq][1] = seeds[1];
123 theSeeds = &table[seq][0];
126 void RanecuEngine::saveStatus()
const
128 ofstream outFile(
"Ranecu.conf", std::ios::out ) ;
130 if (!outFile.bad()) {
131 outFile << theSeed << endl;
132 for (HepInt i=0; i<2; ++i)
133 outFile << table[theSeed][i] <<
" ";
137 void RanecuEngine::restoreStatus()
139 ifstream inFile(
"Ranecu.conf", std::ios::in);
141 if (!inFile.bad() && !inFile.eof()) {
143 for (HepInt i=0; i<2; ++i)
144 inFile >> table[theSeed][i];
145 seq = HepInt(theSeed);
149 void RanecuEngine::showStatus()
const
152 cout <<
"--------- Ranecu engine status ---------" << endl;
153 cout <<
" Initial seed (index) = " << theSeed << endl;
154 cout <<
" Current couple of seeds = " << table[theSeed][0]
155 <<
", " << table[theSeed][1] << endl;
156 cout <<
"----------------------------------------" << endl;
159 HepDouble RanecuEngine::flat()
161 const HepInt index = seq;
162 long seed1 = table[index][0];
163 long seed2 = table[index][1];
165 HepInt k1 = (HepInt)(seed1/ecuyer_b);
166 HepInt k2 = (HepInt)(seed2/ecuyer_e);
168 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
169 if (seed1 < 0) seed1 += shift1;
170 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
171 if (seed2 < 0) seed2 += shift2;
173 table[index][0] = seed1;
174 table[index][1] = seed2;
176 long diff = seed1-seed2;
178 if (diff <= 0) diff += (shift1-1);
179 return (HepDouble)(diff*prec);
182 void RanecuEngine::flatArray(
const HepInt size, HepDouble* vect)
184 const HepInt index = seq;
185 long seed1 = table[index][0];
186 long seed2 = table[index][1];
190 for (i=0; i<size; ++i)
192 k1 = (HepInt)(seed1/ecuyer_b);
193 k2 = (HepInt)(seed2/ecuyer_e);
195 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
196 if (seed1 < 0) seed1 += shift1;
197 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
198 if (seed2 < 0) seed2 += shift2;
200 long diff = seed1-seed2;
201 if (diff <= 0) diff += (shift1-1);
203 vect[i] = (HepDouble)(diff*prec);
205 table[index][0] = seed1;
206 table[index][1] = seed2;
210 #ifndef ST_NO_TEMPLATE_DEF_ARGS
211 RanecuEngine::flatArray(vector<HepDouble>& vec)
213 RanecuEngine::flatArray(vector<HepDouble,allocator<HepDouble> >& vec)
216 const HepInt index = seq;
217 long seed1 = table[index][0];
218 long seed2 = table[index][1];
221 for (
unsigned int i=0; i<vec.size(); ++i)
223 k1 = (HepInt)(seed1/ecuyer_b);
224 k2 = (HepInt)(seed2/ecuyer_e);
226 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
227 if (seed1 < 0) seed1 += shift1;
228 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
229 if (seed2 < 0) seed2 += shift2;
231 long diff = seed1-seed2;
232 if (diff <= 0) diff += (shift1-1);
234 vec[i] = (HepDouble)(diff*prec);
236 table[index][0] = seed1;
237 table[index][1] = seed2;