StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
photos-random.h
1  SUBROUTINE PHORIN
2 C.----------------------------------------------------------------------
3 C.
4 C. PHOTOS: PHOton radiation in decays RANdom number generator init
5 C.
6 C. Purpose: Initialse PHORAN with the user specified seeds in the
7 C. array ISEED. For details see also: F. James CERN DD-
8 C. Report November 1988.
9 C.
10 C. Input Parameters: ISEED(*)
11 C.
12 C. Output Parameters: URAN, CRAN, CDRAN, CMRAN, I97, J97
13 C.
14 C. Author(s): B. van Eijk and F. James Created at: 27/09/89
15 C. Last Update: 22/02/90
16 C.
17 C.----------------------------------------------------------------------
18  IMPLICIT NONE
19  DOUBLE PRECISION DATA
20  REAL*8 S,T
21  INTEGER I,IS1,IS2,IS3,IS4,IS5,J
22  INTEGER ISEED,I97,J97
23  REAL*8 URAN,CRAN,CDRAN,CMRAN
24  COMMON/PHSEED/ISEED(2),I97,J97,URAN(97),CRAN,CDRAN,CMRAN
25 C--
26 C-- Check value range of seeds
27  IF ((ISEED(1).LT.0).OR.(ISEED(1).GE.31328)) THEN
28  DATA=ISEED(1)
29  CALL PHOERR(8,'PHORIN',DATA)
30  ENDIF
31  IF ((ISEED(2).LT.0).OR.(ISEED(2).GE.30081)) THEN
32  DATA=ISEED(2)
33  CALL PHOERR(9,'PHORIN',DATA)
34  ENDIF
35 C--
36 C-- Calculate Marsaglia and Zaman seeds (by F. James)
37  IS1=MOD(ISEED(1)/177,177)+2
38  IS2=MOD(ISEED(1),177)+2
39  IS3=MOD(ISEED(2)/169,178)+1
40  IS4=MOD(ISEED(2),169)
41  DO 20 I=1,97
42  S=0.D0
43  T=0.5D0
44  DO 10 J=1,24
45  IS5=MOD (MOD(IS1*IS2,179)*IS3,179)
46  IS1=IS2
47  IS2=IS3
48  IS3=IS5
49  IS4=MOD(53*IS4+1,169)
50  IF (MOD(IS4*IS5,64).GE.32) S=S+T
51  10 T=0.5D0*T
52  20 URAN(I)=S
53  CRAN=362436.D0/16777216.D0
54  CDRAN=7654321.D0/16777216.D0
55  CMRAN=16777213.D0/16777216.D0
56  I97=97
57  J97=33
58  RETURN
59  END
60  FUNCTION PHORAN(IDUM)
61 C.----------------------------------------------------------------------
62 C.
63 C. PHOTOS: PHOton radiation in decays RANdom number generator based
64 C. on Marsaglia Algorithm
65 C.
66 C. Purpose: Generate uniformly distributed random numbers between
67 C. 0 and 1. Super long period: 2**144. See also:
68 C. G. Marsaglia and A. Zaman, FSU-SCR-87-50, for seed mo-
69 C. difications to this version see: F. James DD-Report,
70 C. November 1988. The generator has to be initialized by
71 C. a call to PHORIN.
72 C.
73 C. Input Parameters: IDUM (integer dummy)
74 C.
75 C. Output Parameters: Function value
76 C.
77 C. Author(s): B. van Eijk, G. Marsaglia and Created at: 27/09/89
78 C. A. Zaman Last Update: 27/09/89
79 C.
80 C.----------------------------------------------------------------------
81  IMPLICIT NONE
82  REAL*8 PHORAN
83  INTEGER IDUM
84  INTEGER ISEED,I97,J97
85  REAL*8 URAN,CRAN,CDRAN,CMRAN
86  COMMON/PHSEED/ISEED(2),I97,J97,URAN(97),CRAN,CDRAN,CMRAN
87  10 PHORAN=URAN(I97)-URAN(J97)
88  IF (PHORAN.LT.0.D0) PHORAN=PHORAN+1.D0
89  URAN(I97)=PHORAN
90  I97=I97-1
91  IF (I97.EQ.0) I97=97
92  J97=J97-1
93  IF (J97.EQ.0) J97=97
94  CRAN=CRAN-CDRAN
95  IF (CRAN.LT.0.D0) CRAN=CRAN+CMRAN
96  PHORAN=PHORAN-CRAN
97  IF (PHORAN.LT.0.D0) PHORAN=PHORAN+1.D0
98  IF (PHORAN.LE.0.D0) GOTO 10
99  RETURN
100  END