Bugfix in AliPoints2Memory
[u/mrichter/AliRoot.git] / GEANT321 / gstrag / gdifmg.F
1 *
2 * $Id$
3 *
4 * $Log$
5 * Revision 1.1.1.1  1999/05/18 15:55:20  fca
6 * AliRoot sources
7 *
8 * Revision 1.1.1.1  1995/10/24 10:21:37  cernlib
9 * Geant
10 *
11 *
12 #include "geant321/pilot.h"
13 #if defined(CERNLIB_ASHO)
14 *CMZ :  3.21/02 29/03/94  15.41.25  by  S.Giani
15 *-- Author :
16       SUBROUTINE GDIFMG(DEL)
17  
18 #include "geant321/gccuts.inc"
19 #include "geant321/gcasho.inc"
20 C-----------------------------------------------------------------------
21 C      This program calculates the final distribution coef-
22 C      ficients until the integral S is more or equal to L2.
23 C      In case of S < L2 or miscalculations due to FORTRAN
24 C      limits DONE = FALSE.
25 C-----------------------------------------------------------------------
26 C      Update history: 10-08-93
27 C
28 C-----------------------------------------------------------------------
29       REAL BN(50),BNA(50),L2
30       INTEGER FLMAX
31       PARAMETER (DL2=.1)
32       DATA CORMAX/80./
33 C-----------------------------------------------------------------------
34 C      Initialization steps
35 C-----------------------------------------------------------------------
36       XX = 0.
37       Z = 1.
38       DO 10 K=1,NOSC
39          BN(K) = BOSC(K)*IOSC(K)
40          BNA(K) = BN(K)*(AOSC(K) - 1.)
41          XX = XX + AOSC(K)*BOSC(K)
42    10 CONTINUE
43 C
44       FLMAX = 0
45       CORR = CORMAX - XX
46       CMGO(1) = EXP(-CORMAX)
47       CMGO(2) = CMGO(1)*BNA(1)
48       Z = Z-(CMGO(1)+CMGO(2))*EXP(CORR)
49 C-----------------------------------------------------------------------
50 C      Calculation of the current Ci
51 C-----------------------------------------------------------------------
52       CALL GRNDM(RNDM,1)
53  
54       L2 = DL2
55       IF (RNDM.GE.L2) THEN
56          L2 = RNDM
57          FLMAX = 1
58       ENDIF
59       DO 40 NMGO=3,NMGOMA
60          CMGO(NMGO) = CMGO(NMGO - 1)*BNA(1)
61          DO 30 J = 1,NMGO - 2
62             M = NMGO - 1 - J
63             X = BOSC(1)/J
64             DO 20 K=2,NOSC
65                IF(MOD(J+1,IOSC(K)).EQ.0) THEN
66                   L = (J+1)/IOSC(K)
67                   IF(L.EQ.1) THEN
68                      X = X + BNA(K)
69                   ELSE
70                      X = X + BN(K)/(L-1)
71                   ENDIF
72                ENDIF
73    20       CONTINUE
74             CMGO(NMGO) = CMGO(NMGO) + X*CMGO(M)
75    30    CONTINUE
76          CMGO(NMGO) = CMGO(NMGO)/(NMGO-1)
77          Z = Z - CMGO(NMGO)*EXP(CORR)
78          IF (Z.LE.L2) GOTO 50
79    40 CONTINUE
80  
81    50 IF (FLMAX.EQ.1) THEN
82          DEL = (NMGO-1)*EOSC(1)
83       ELSE
84          DEL = (NMGO-1)*EOSC(1)*L2/RNDM
85       ENDIF
86       IF (DEL.GE.DCUTE*1E6) DEL = DCUTE*1E6
87  
88       END
89 #else
90       SUBROUTINE GDIFMG_DUMMY
91       END
92 #endif