source: branches/start/MagicSoft/Simulation/Corsika/Mmcs/longft.f@ 10113

Last change on this file since 10113 was 286, checked in by harald, 25 years ago
This is the start point for further developments of the Magic Monte Carlo Simulation written by Jose Carlos Gonzales. Now it is under control of one CVS repository for the whole collaboration. Everyone should use this CVS repository for further developments.
File size: 5.2 KB
Line 
1 SUBROUTINE LONGFT(FPARAM,CHI2)
2
3C-----------------------------------------------------------------------
4C LONG(ITUDINAL) F(I)T
5C
6C THIS ROUTINE PERFORMS A FIT TO THE LONGITUDINAL DISTRIBUTION OF AN
7C AIR SHOWER. DUE TO THE LARGE PARTICLE NUMBERS IN AN AIR SHOWER THE
8C STATISTICAL ERRORS ON THE PARTICLE NUMBER AT A GIVEN LEVEL ARE
9C MINUTE. THIS LEADS TO RATHER LARGE CHI**2/DOF FOR THE FITS EVEN IF
10C THE FITTED FUNCTION MATCHES THE POINTS BETTER THAN SAY 1%.
11C KEEP IN MIND THAT FITTING IS A DIFFICULT TASK AND THE RESULTS DO NOT
12C NECESSARILY REPRESENT THE ABOLUTE MINIMUM OR EVEN A GOOD
13C APPROXIMATION.
14C
15C TRY A 6 PARAMETER FIT BASED ON J. BALL'S PROPOSED CURVE REPLACING HIS
16C CONSTANT WIDTH PARAMETER LAMBDA BY A POLYNOMIAL OF 3. DEGREE.
17C N(T) = NMAX * ((T-T0)/(TMAX-T0))**((TMAX-T)/(P1+P2*T+P3*T**2))
18C T = DEPTH IN G/CM**2
19C T0 = STARTING DEPTH OF SHOWER
20C TMAX = DEPTH OF SHOWER MAXIMUM
21C NMAX = PARTICLE NUMBER AT TMAX
22C P1 .. P3 = PARAMETERS OF A POLYNOMIAL DESCRIBING THE WIDTH
23C
24C THIS SUBROUTINE IS CALLED FROM MAIN
25C-----------------------------------------------------------------------
26
27 IMPLICIT NONE
28*KEEP,CURVE.
29 COMMON /CURVE/ CHAPAR,DEP,ERR,NSTP
30 DOUBLE PRECISION CHAPAR(1100),DEP(1100),ERR(1100)
31 INTEGER NSTP
32*KEEP,RUNPAR.
33 COMMON /RUNPAR/ FIXHEI,THICK0,HILOECM,HILOELB,
34 * STEPFC,NRRUN,NSHOW,PATAPE,MONIIN,
35 * MONIOU,MDEBUG,NUCNUC,
36 * CETAPE,
37 * SHOWNO,ISHW,NOPART,NRECS,NBLKS,MAXPRT,NDEBDL,
38 * N1STTR,MDBASE,
39 * DEBDEL,DEBUG,FDECAY,FEGS,FIRSTI,FIXINC,FIXTAR,
40 * FIX1I,FMUADD,FNKG,FPRINT,FDBASE
41 * ,GHEISH,GHESIG
42 COMMON /RUNPAC/ DSN,HOST,USER
43 DOUBLE PRECISION FIXHEI,THICK0,HILOECM,HILOELB
44 REAL STEPFC
45 INTEGER NRRUN,NSHOW,PATAPE,MONIIN,MONIOU,MDEBUG,NUCNUC,
46 * SHOWNO,ISHW,NOPART,NRECS,NBLKS,MAXPRT,NDEBDL,
47 * N1STTR,MDBASE
48 INTEGER CETAPE
49 CHARACTER*79 DSN
50 CHARACTER*20 HOST,USER
51
52 LOGICAL DEBDEL,DEBUG,FDECAY,FEGS,FIRSTI,FIXINC,FIXTAR,
53 * FIX1I,FMUADD,FNKG,FPRINT,FDBASE
54 * ,GHEISH,GHESIG
55*KEND.
56
57 INTEGER NPAR
58 PARAMETER (NPAR=6)
59 DOUBLE PRECISION F(NPAR),FPARAM(NPAR),CHI2,CHISQ
60 DOUBLE PRECISION P(NPAR+1,NPAR),Y(NPAR+1),EPS
61 DOUBLE PRECISION T0,TMAX,NMAX,FAC
62 INTEGER I,J,JJ,K,ITER,IFLAG
63 EXTERNAL CHISQ
64C-----------------------------------------------------------------------
65
66 IF ( DEBUG ) WRITE(MDEBUG,*) 'LONGFT:'
67
68C FIND GOOD START VALUES FOR XMAX AND FMAX
69 NMAX = 0.D0
70 DO 2 I = 1,NSTP
71 ERR(I) = MAX( 1.D0, SQRT(CHAPAR(I)) )
72 IF ( CHAPAR(I) .GT. NMAX ) THEN
73 NMAX = CHAPAR(I)
74 TMAX = DEP(I)
75 ENDIF
76 2 CONTINUE
77C STARTVALUE FOR X0 IS ABOUT WHERE MORE THAN 1 PARTICLE SHOWS UP
78 DO 3 I = 1,NSTP
79 IF ( CHAPAR(I) .GT. 1.D0 ) GOTO 1
80 3 CONTINUE
81 I = NSTP
82 1 CONTINUE
83 T0 = DEP(I)
84
85C-----------------------------------------------------------------------
86C FIT IS PERFORMED WITH THE ROUTINE AMOEBA FROM:
87C NUMERICAL RECIPES, W.H. PRESS ET AL.,
88C CAMBRIDGE UNIVERSITY PRESS, 1992 ISBN 0 521 43064 X
89C SEE THERE HOW IT HAS TO BE USED.
90
91C CREATE A SET OF NPAR+1 STARTING VERTICES
92C HERE IS THE FIRST ONE
93 P(1,1) = NMAX
94 P(1,2) = T0
95 P(1,3) = TMAX
96 P(1,4) = 200.D0
97 P(1,5) = 1.D-1
98 P(1,6) = 1.D-1
99
100C LOOP OVER THE FITTING ROUTINE (2 TIMES 5 FITS WITH VARYING PRECISION)
101 DO 10 J = 1,2
102 DO 9 JJ = 1,5
103C START WITH CRUDE PRECISION AND IMPROVE STEP BY STEP
104C AFTER FIVE STEPS ENLARGE AGAIN
105 EPS = 10.D0**(-3.D0-JJ*0.5D0)
106 FAC = 1.D0 + 2.D0**(2.1D0*(1.D0-JJ))
107C GO AS WELL IN DIFFERENT DIRECTIONS
108 IF ( J .EQ. 2 ) FAC = 1.D0/FAC
109
110C GET OTHER NPAR STARTING VERTICES FROM THE STARTING POINT BY VARIATION
111C OF ONLY ONE OF THE COORDINATE VALUES
112 DO 5 I = 2,NPAR+1
113 DO 4 K = 1,NPAR
114 P(I,K) = P(1,K)
115 4 CONTINUE
116 IF ( P(I,I-1) .EQ. 0.D0 ) THEN
117 P(I,I-1) = 1.D0
118 ELSE
119 P(I,I-1) = P(I,I-1) * FAC
120 ENDIF
121 5 CONTINUE
122 IF (DEBUG) WRITE(MDEBUG,*) 'LONGFT: TRIAL,FAC,EPS ',J,
123 * SNGL(FAC),SNGL(EPS)
124
125C CALCULATE FUNCTION VALUES AT THE START VERTICES
126 DO 7 I = 1,NPAR+1
127 DO 6 K = 1,NPAR
128 F(K) = P(I,K)
129 6 CONTINUE
130 Y(I) = CHISQ(F)
131 7 CONTINUE
132C PERFORM A FIT
133 CALL AMOEBA(P,Y,NPAR+1,NPAR,NPAR,EPS,CHISQ,ITER,IFLAG)
134 IF ( DEBUG ) THEN
135 WRITE(MDEBUG,*) 'LONGFT: ITER/IFLAG=',ITER,IFLAG
136 WRITE(MDEBUG,*) 'LONGFT: PARAMETERS=',1,(P(1,K),K=1,6)
137 WRITE(MDEBUG,*) 'LONGFT: CHISQ =',SNGL(Y(1))
138 ENDIF
139
140C STORE VALUES AT FIRST TRIAL OR AT IMPROVED RESULT
141 IF ( J .EQ. 1 .OR. Y(1) .LT. CHI2 ) THEN
142 DO 8 I = 1,NPAR
143 FPARAM(I) = P(1,I)
144 8 CONTINUE
145 CHI2 = Y(1)
146 ENDIF
147C END OF LOOPS OVER THE FITTING ROUTINE
148 9 CONTINUE
149 10 CONTINUE
150
151 RETURN
152 END
Note: See TracBrowser for help on using the repository browser.