Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ranluxint.h
Go to the documentation of this file.
1#ifndef RANLUXINT_H
2#define RANLUXINT_H
3
4#ifdef GARFIELD_HEED_INTERFACE
5
6#include "Random.hh"
7
8inline double SRANLUX() { return Garfield::RndmUniform(); }
9
10#else
11
12#ifdef USE_CPP_SRANLUX
13// If this is the case
14// ranluxint.f is unnecessary
15// SRANLUX is a function returning double.
16// (In the case of fortran SRANLUX is function returning float.)
17
18#include "wcpplib/random/WRandomEngine.h"
19//#include <CLHEP/Random/RandomEngine.h>
20
21//using namespace CLHEP; // uncomment if below is CLHEP variant.
22
23extern WHepRandomEngine& random_engine;
24
25inline double SRANLUX(void) // trying double
26 {
27 return random_engine.flat();
28}
29
30#else // for ifdef USE_CPP_RANLUX
31 // getting rid of everything else
32
33#include "wcpplib/cfortran/ftypes.h"
34//#include <string.h>
35
36//#define RANF_INSTEAD_OF_RNDM
37#define RANLUX_INSTEAD_OF_RNDM // currently only this option works
38
39//#define PRINT_RANLUX // for debug, allows to print in mcout
40// sequencial random number which is returned and the number(index) of
41// this number, which allows to check random generator and program
42/* Operation with seed for RANLUX:
43There is a file with a fixed name ranluxsd.dat.
44This name is fixed in fortran subroutines which write or read it:
45myiniteranlux - reads,
46mysaveranlux - writes.
47There is also third subroutine which simply fills a vector:
48myextractranlux(vector).
49With it the seed can be extracted into the program and written into its
50output stream in order to grant to the user the possibility
51to re-start calculations from any point.
52From C++ these functions are available through:
53inline void INITE_RANLUX(void);
54inline void SAVE_RANLUX(void);
55inline void EXTRACT_RANLUX(fint* ivec);
56where ivec has to have length 25 words.
57For example, you can insert in the program the line:
58fint ranlux_seed[25];
59
60To put in the beginning:
61 INITE_RANLUX();
62In the end:
63 SAVE_RANLUX();
64
65and insert into the event loop the following sequence:
66 if(eventcount.Gn()%1000 == 0)
67 {
68 EXTRACT_RANLUX(ranlux_seed);
69 mcout<<"ranlux seed:";
70 int n;
71 for(n=0; n<25; n++)
72 {
73 //if(n % 8 == 0)
74 mcout<<'\n';
75 mcout<< ranlux_seed[n]<<' ';
76 }
77 mcout<<'\n';
78 mcout.flush();
79 }
80
81*/
82
83#ifdef PRINT_RANLUX
84#include <iomanip.h>
85#include <values.h>
87extern unsigned long num_ranlux;
88const long step_of_print_ranlux = 1000; // step of printing
89#endif
90
91#ifdef FORT_UNDERSCORES_02
92#ifdef RANLUX_INSTEAD_OF_RNDM
93extern "C" void myiniteranlux__(void);
94extern "C" void mysaveranlux__(void);
95extern "C" void myextractranlux__(fint* ivec);
96extern "C" void ranlux__(ffloat* rvec, fint* len);
97extern "C" ffloat sranlux__(void);
98#else
99#ifndef RANF_INSTEAD_OF_RNDM
100extern "C" ffloat rndm__(fint* arg);
101#else
102extern "C" ffloat ranfl__(void);
103#endif
104extern "C" void myiniterndm__(void);
105extern "C" void mysaverndm__(void);
106extern "C" void myextractrndm__(fint* iseed);
107#endif
108extern "C" ffloat lranor__(ffloat* arg1, ffloat* arg2);
109extern "C" void lspois__(ffloat* amu, fint* n, fint* ierror);
110extern "C" void hisran__(ffloat* y, fint* n, ffloat* xlo, ffloat* xwid,
111 ffloat* xran);
112extern "C" ffloat flande__(ffloat* x);
113
114#elif FORT_UNDERSCORES_01
115#ifdef RANLUX_INSTEAD_OF_RNDM
116extern "C" void myiniteranlux_(void);
117extern "C" void mysaveranlux_(void);
118extern "C" void myextractranlux_(fint* ivec);
119extern "C" void ranlux_(ffloat* rvec, fint* len);
120extern "C" ffloat sranlux_(void);
121#else
122#ifndef RANF_INSTEAD_OF_RNDM
123extern "C" ffloat rndm_(fint* arg);
124#else
125extern "C" ffloat ranfl_(void);
126#endif
127extern "C" void myiniterndm_(void);
128extern "C" void mysaverndm_(void);
129extern "C" void myextractrndm_(fint* iseed);
130#endif
131extern "C" ffloat lranor_(ffloat* arg1, ffloat* arg2);
132extern "C" void lspois_(ffloat* amu, fint* n, fint* ierror);
133extern "C" void hisran_(ffloat* y, fint* n, ffloat* xlo, ffloat* xwid,
134 ffloat* xran);
135extern "C" ffloat flande_(ffloat* x);
136
137#elif FORT_UNDERSCORES_11
138#ifdef RANLUX_INSTEAD_OF_RNDM
139extern "C" void _myiniteranlux_(void);
140extern "C" void _mysaveranlux_(void);
141extern "C" void _myextractranlux_(fint* ivec);
142extern "C" void _ranlux_(ffloat* rvec, fint* len);
143extern "C" ffloat _sranlux_(void);
144#else
145#ifndef RANF_INSTEAD_OF_RNDM
146extern "C" ffloat _rndm_(fint* arg);
147#else
148extern "C" ffloat _ranfl_(void);
149#endif
150extern "C" void _myiniterndm_(void);
151extern "C" void _mysaverndm_(void);
152extern "C" void _myextractrndm_(fint* iseed);
153#endif
154extern "C" void _lspois_(ffloat* amu, fint* n, fint* ierror);
155extern "C" ffloat _lranor_(ffloat* arg1, ffloat* arg2);
156extern "C" void _hisran_(ffloat* y, fint* n, ffloat* xlo, ffloat* xwid,
157 ffloat* xran);
158extern "C" ffloat _flande_(ffloat* x);
159
160#else
161#ifdef RANLUX_INSTEAD_OF_RNDM
162extern "C" void myiniteranlux(void);
163extern "C" void mysaveranlux(void);
164extern "C" void myextractranlux(fint* ivec);
165extern "C" void ranlux(ffloat* rvec, fint* len);
166extern "C" ffloat sranlux(void);
167#else
168#ifndef RANF_INSTEAD_OF_RNDM
169extern "C" ffloat rndm(fint* arg);
170#else
171extern "C" ffloat ranfl(void);
172#endif
173extern "C" void myiniterndm(void);
174extern "C" void mysaverndm(void);
175extern "C" void myextractrndm(fint* iseed);
176#endif
177extern "C" void lspois(ffloat* amu, fint* n, fint* ierror);
178extern "C" ffloat lranor(ffloat* arg1, ffloat* arg2);
179extern "C" void hisran(ffloat* y, fint* n, ffloat* xlo, ffloat* xwid,
180 ffloat* xran);
181extern "C" ffloat flande(ffloat* x);
182
183#endif
184
185#ifdef RANLUX_INSTEAD_OF_RNDM
186
187inline void INITE_RANLUX(void) {
188#ifdef FORT_UNDERSCORES_02
189 myiniteranlux__();
190#elif FORT_UNDERSCORES_01
191 myiniteranlux_();
192#elif FORT_UNDERSCORES_11
193 _myiniteranlux_();
194#else
196#endif
197}
198
199inline void SAVE_RANLUX(void) {
200#ifdef FORT_UNDERSCORES_02
201 mysaveranlux__();
202#elif FORT_UNDERSCORES_01
203 mysaveranlux_();
204#elif FORT_UNDERSCORES_11
205 _mysaveranlux_();
206#else
207 mysaveranlux();
208#endif
209}
210
211inline void EXTRACT_RANLUX(fint* ivec) {
212#ifdef FORT_UNDERSCORES_02
213 myextractranlux__(ivec);
214#elif FORT_UNDERSCORES_01
215 myextractranlux_(ivec);
216#elif FORT_UNDERSCORES_11
217 _myextractranlux_(ivec);
218#else
219 myextractranlux(ivec);
220#endif
221}
222
223inline void RANLUX(ffloat* vec, fint len) {
224#ifdef FORT_UNDERSCORES_02
225 ranlux__(vec, &len);
226#elif FORT_UNDERSCORES_01
227 ranlux_(vec, &len);
228#elif FORT_UNDERSCORES_11
229 _ranlux_(vec, &len);
230#else
231 ranlux(vec, &len);
232#endif
233#ifdef PRINT_RANLUX
234 if (step_of_print_ranlux > 1) {
235 int n;
236 for (n = 0; n < len; n++) {
237 long rest = num_ranlux % step_of_print_ranlux;
238 if (rest == 0) {
239 int qp = mcout.precision();
240 mcout.precision(FLT_DIG);
241 mcout << "RANLUX: num_ranlux=" << num_ranlux << " r=" << vec[n] << '\n';
242 mcout.precision(qp);
243 }
244 num_ranlux++;
245 }
246 } else {
247 mcout << "RANLUX: len = " << len << '\n';
248 indn.n += 2;
249 int n;
250 int qp = mcout.precision();
251 mcout.precision(FLT_DIG);
252 for (n = 0; n < len; n++) {
253 mcout << "n=" << n << "num_ranlux=" << num_ranlux++
254 << " vec[n]=" << vec[n] << '\n';
255 }
256 mcout.precision(qp);
257 indn.n -= 2;
258 }
259#endif
260}
261
262inline ffloat SRANLUX(void) {
263#ifndef PRINT_RANLUX
264
265#ifdef FORT_UNDERSCORES_02
266 return sranlux__();
267#elif FORT_UNDERSCORES_01
268 return sranlux_();
269#elif FORT_UNDERSCORES_11
270 return _sranlux_();
271#else
272 return sranlux();
273#endif
274
275#else // PRINT_RANLUX
276
277#ifdef FORT_UNDERSCORES_02
278 float r = sranlux__();
279#elif FORT_UNDERSCORES_01
280 float r = sranlux_();
281#elif FORT_UNDERSCORES_11
282 float r = _sranlux_();
283#else
284 float r = sranlux();
285#endif
286 long rest = 0;
287 if (step_of_print_ranlux > 1) {
288 rest = num_ranlux % step_of_print_ranlux;
289 }
290 if (rest == 0) {
291 int qp = mcout.precision();
292 mcout.precision(FLT_DIG);
293 mcout << "SRANLUX: num_ranlux=" << num_ranlux << " r=" << r << '\n';
294 mcout.precision(qp);
295 }
296 num_ranlux++;
297 return r;
298
299#endif
300}
301
302#else // ifdef RANLUX_INSTEAD_OF_RNDM
303
304#ifndef RANF_INSTEAD_OF_RNDM
305
306inline ffloat RNDM(void) {
307#ifdef FORT_UNDERSCORES_02
308 return rndm__(0);
309#elif FORT_UNDERSCORES_01
310 return rndm_(0);
311#elif FORT_UNDERSCORES_11
312 return _rndm_(0);
313#else
314 return rndm(0);
315#endif
316}
317#else
318inline ffloat RNDM(void) {
319#ifdef FORT_UNDERSCORES_02
320 return ranfl__();
321#elif FORT_UNDERSCORES_01
322 return ranfl_();
323#elif FORT_UNDERSCORES_11
324 return _ranfl_();
325#else
326 return ranfl();
327#endif
328}
329#endif
330inline void INITE_RNDM(void) {
331#ifdef FORT_UNDERSCORES_02
332 myiniterndm__();
333#elif FORT_UNDERSCORES_01
334 myiniterndm_();
335#elif FORT_UNDERSCORES_11
336 _myiniterndm_();
337#else
338 myiniterndm();
339#endif
340}
341inline void SAVE_RNDM(void) {
342#ifdef FORT_UNDERSCORES_02
343 mysaverndm__();
344#elif FORT_UNDERSCORES_01
345 mysaverndm_();
346#elif FORT_UNDERSCORES_11
347 _mysaverndm_();
348#else
349 mysaverndm();
350#endif
351}
352
353inline void EXTRACT_RNDM(fint* iseed) {
354#ifdef FORT_UNDERSCORES_02
355 myextractrndm__(iseed);
356#elif FORT_UNDERSCORES_01
357 myextractrndm_(iseed);
358#elif FORT_UNDERSCORES_11
359 _myextractrndm_(iseed);
360#else
361 myextractrndm(iseed);
362#endif
363}
364
365#endif // ifdef RANLUX_INSTEAD_OF_RNDM
366
367inline ffloat LRANOR(ffloat* arg1, ffloat* arg2) {
368#ifdef FORT_UNDERSCORES_02
369 return lranor__(arg1, arg2);
370#elif FORT_UNDERSCORES_01
371 return lranor_(arg1, arg2);
372#elif FORT_UNDERSCORES_11
373 return _lranor_(arg1, arg2);
374#else
375 return lranor(arg1, arg2);
376#endif
377}
378
379inline void LSPOIS(ffloat* amu, fint& n, fint& ierror) {
380#ifdef FORT_UNDERSCORES_02
381 lspois__(amu, &n, &ierror);
382#elif FORT_UNDERSCORES_01
383 lspois_(amu, &n, &ierror);
384#elif FORT_UNDERSCORES_11
385 _lspois_(amu, &n, &ierror);
386#else
387 lspois(amu, &n, &ierror);
388#endif
389}
390
391inline void HISRAN(ffloat* y, fint n, ffloat xlo, ffloat xwid, ffloat& xran) {
392#ifdef FORT_UNDERSCORES_02
393 hisran__(y, &n, &xlo, &xwid, &xran);
394#elif FORT_UNDERSCORES_01
395 hisran_(y, &n, &xlo, &xwid, &xran);
396#elif FORT_UNDERSCORES_11
397 _hisran_(y, &n, &xlo, &xwid, &xran);
398#else
399 hisran(y, &n, &xlo, &xwid, &xran);
400#endif
401}
402
403inline ffloat FLANDE(ffloat* x) {
404#ifdef FORT_UNDERSCORES_02
405 return flande__(x);
406#elif FORT_UNDERSCORES_01
407 return flande_(x);
408#elif FORT_UNDERSCORES_11
409 return _flande_(x);
410#else
411 return flande(x);
412#endif
413}
414
415#endif // for ifdef USE_CPP_RANLUX
416
417#endif
418
419#endif
Definition: vec.h:248
double RndmUniform()
Definition: Random.hh:16
indentation indn
Definition: prstream.cpp:13
#define mcout
Definition: prstream.h:133
void lspois(ffloat *amu, fint *n, fint *ierror)
ffloat LRANOR(ffloat *arg1, ffloat *arg2)
Definition: ranluxint.h:367
void hisran(ffloat *y, fint *n, ffloat *xlo, ffloat *xwid, ffloat *xran)
void mysaveranlux(void)
void myiniteranlux(void)
ffloat FLANDE(ffloat *x)
Definition: ranluxint.h:403
void EXTRACT_RANLUX(fint *ivec)
Definition: ranluxint.h:211
ffloat SRANLUX(void)
Definition: ranluxint.h:262
void INITE_RANLUX(void)
Definition: ranluxint.h:187
ffloat flande(ffloat *x)
void myextractranlux(fint *ivec)
void HISRAN(ffloat *y, fint n, ffloat xlo, ffloat xwid, ffloat &xran)
Definition: ranluxint.h:391
void LSPOIS(ffloat *amu, fint &n, fint &ierror)
Definition: ranluxint.h:379
void ranlux(ffloat *rvec, fint *len)
void RANLUX(ffloat *vec, fint len)
Definition: ranluxint.h:223
ffloat sranlux(void)
ffloat lranor(ffloat *arg1, ffloat *arg2)
void SAVE_RANLUX(void)
Definition: ranluxint.h:199
HepRandomEngine & random_engine