Some function moved to AliZDC
[u/mrichter/AliRoot.git] / GEANT321 / gstrag / gstren.F
1 *
2 * $Id$
3 *
4 * $Log$
5 * Revision 1.1.1.1  1995/10/24 10:21:39  cernlib
6 * Geant
7 *
8 *
9 #include "geant321/pilot.h"
10 *CMZ :  3.21/02 29/03/94  15.41.25  by  S.Giani
11 *-- Author :
12       FUNCTION GSTREN (GAMMA,ECUT,STEP)
13 C.    ******************************************************************
14 C.    *                                                                *
15 C.    *   Simulation of energy loss straggling in thin layers.         *
16 C.    *   Sampling is done from the tables which are prepared          *
17 C.    *   in GSTINI.                                                   *
18 C.    *                                                                *
19 C.    *   ==> Called by : GTELEC, GTHADR, GTMUON                       *
20 C.    *       Authors   : K. Lassila-Perini, I. Gavrilenko             *
21 C.    *                                                                *
22 C.    ******************************************************************
23 #include "geant321/gcbank.inc"
24 #include "geant321/gcjloc.inc"
25 #include "geant321/gcmate.inc"
26 #include "geant321/gcstra.inc"
27 C
28       DIMENSION ANGL(200),RNDM(2)
29 C...
30 *   Reading the tables, if the medium has not changed
31       NP     = Q(JTSTRA+1)
32 *
33       EC       = 1.E9*ECUT
34       GSTLOC   = 0.
35       IF(STEP.LE.0.) GO TO 90
36 C...
37 *   Interpolate the tables for the current gamma-factor
38       GAML     = LOG(GAMMA)
39       IF(GAML.GT.GAMLOG(21)) THEN
40          DO 10 J=1,NP
41             ANGL(J)=Q(JTSTCO+J*21)
42    10    CONTINUE
43       ELSE
44 C...
45          DO 20 I = 2,21
46             IF(GAML.LE.GAMLOG(I)) THEN
47                DGG = (GAML-GAMLOG(I-1))/(GAMLOG(I)-GAMLOG(I-1))
48                IP=I
49                GO TO 30
50             ENDIF
51    20    CONTINUE
52    30    DG1=1.-DGG
53 C...
54          DO 40 K = 1,NP
55             ANGL(K) = Q(JTSTCO+(K-1)*21+IP-1)*DG1+
56      +                Q(JTSTCO+(K-1)*21+IP  )*DGG
57    40    CONTINUE
58       ENDIF
59 *
60 *    The sampling from the tables
61       ANMIN   = EXP(ANGL(NP))
62       ANMAX   = EXP(ANGL( 1))
63 *
64       DAN      = ANMAX-ANMIN
65       AMU      = DAN*STEP
66       CALL GPOISS(AMU,N,1)
67       NICOLL   = MAX(N,1)
68       DO 80  I  = 1,NICOLL
69    50    K1 = 1
70          K2 = NP
71          CALL GRNDM(RNDM,1)
72          R = LOG(RNDM(1)*DAN+ANMIN)
73    60    K = (K1+K2)/2
74          IF(R.GT.ANGL(K)) THEN
75             K2=K
76          ELSEIF(R.LT.ANGL(K)) THEN
77             K1=K
78          ELSE
79             E=Q(JTSTEN+K)
80             GOTO 70
81          ENDIF
82          IF(K2-K1.GT.1 ) GO TO 60
83 *
84          E = Q(JTSTEN+K2)+(R-ANGL(K2))*
85      +       (Q(JTSTEN+K1)-Q(JTSTEN+K2))/(ANGL(K1)-ANGL(K2))
86    70    EE = EXP(E)
87          IF(EE.GT.EC) GO TO 50
88 *
89 * *** Total energy calculation
90          GSTLOC = GSTLOC+EE
91    80 CONTINUE
92 *
93    90 GSTREN  = GSTLOC*1.E-9
94       END