COSMOS v7.655  COSMOSv7655
(AirShowerMC)
mnhess.f File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine mnhess (FCN, FUTIL)
 

Function/Subroutine Documentation

◆ mnhess()

subroutine mnhess ( external  FCN,
external  FUTIL 
)

Definition at line 10 of file mnhess.f.

References a, b, c, d, e, f, g, h, softenpik::half, i, j, m, maxp, mnamin(), mndxdi(), mnhes1(), mninex(), mnpsdf(), mnvert(), mnwarn(), n, o, p, parameter(), up(), x, xs, and z.

Referenced by mncntr(), mncuve(), mnexcm(), and mnmigr().

10 *
11 * $Id: d506dp.inc,v 1.1.1.1 1996/03/07 14:31:32 mclareni Exp $
12 *
13 * $Log: d506dp.inc,v $
14 * Revision 1.1.1.1 1996/03/07 14:31:32 mclareni
15 * Minuit
16 *
17 *
18 *
19 *
20 * d506dp.inc
21 *
22 C ************ DOUBLE PRECISION VERSION *************
23  IMPLICIT DOUBLE PRECISION (a-h,o-z)
24 CC Calculates the full second-derivative matrix of FCN
25 CC by taking finite differences. When calculating diagonal
26 CC elements, it may iterate so that step size is nearly that
27 CC which gives function change= UP/10. The first derivatives
28 CC of course come as a free side effect, but with a smaller
29 CC step size in order to obtain a known accuracy.
30 CC
31 *
32 * $Id: d506cm.inc,v 1.1.1.1 1996/03/07 14:31:32 mclareni Exp $
33 *
34 * $Log: d506cm.inc,v $
35 * Revision 1.1.1.1 1996/03/07 14:31:32 mclareni
36 * Minuit
37 *
38 *
39 *
40 *
41 * d506cm.inc
42 *
43  parameter(mne=100 , mni=50)
44  parameter(mnihl=mni*(mni+1)/2)
45  CHARACTER*10 cpnam
46  COMMON
47  1/mn7nam/ cpnam(mne)
48  2/mn7ext/ u(mne) ,alim(mne) ,blim(mne)
49  3/mn7err/ erp(mni) ,ern(mni) ,werr(mni) ,globcc(mni)
50  4/mn7inx/ nvarl(mne) ,niofex(mne),nexofi(mni)
51  5/mn7int/ x(mni) ,xt(mni) ,dirin(mni)
52  6/mn7fx2/ xs(mni) ,xts(mni) ,dirins(mni)
53  7/mn7der/ grd(mni) ,g2(mni) ,gstep(mni) ,gin(mne) ,dgrd(mni)
54  8/mn7fx3/ grds(mni) ,g2s(mni) ,gsteps(mni)
55  9/mn7fx1/ ipfix(mni) ,npfix
56  a/mn7var/ vhmat(mnihl)
57  b/mn7vat/ vthmat(mnihl)
58  c/mn7sim/ p(mni,mni+1),pstar(mni),pstst(mni) ,pbar(mni),prho(mni)
59 C
60  parameter(maxdbg=10, maxstk=10, maxcwd=20, maxp=30, maxcpt=101)
61  parameter(zero=0.0, one=1.0, half=0.5)
62  COMMON
63  d/mn7npr/ maxint ,npar ,maxext ,nu
64  e/mn7iou/ isysrd ,isyswr ,isyssa ,npagwd ,npagln ,newpag
65  e/mn7io2/ istkrd(maxstk) ,nstkrd ,istkwr(maxstk) ,nstkwr
66  f/mn7tit/ cfrom ,cstatu ,ctitl ,cword ,cundef ,cvrsn ,covmes
67  g/mn7flg/ isw(7) ,idbg(0:maxdbg) ,nblock ,icomnd
68  h/mn7min/ amin ,up ,edm ,fval3 ,epsi ,apsi ,dcovar
69  i/mn7cnv/ nfcn ,nfcnmx ,nfcnlc ,nfcnfr ,itaur,istrat,nwrmes(2)
70  j/mn7arg/ word7(maxp)
71  k/mn7log/ lwarn ,lrepor ,limset ,lnolim ,lnewmn ,lphead
72  l/mn7cns/ epsmac ,epsma2 ,vlimlo ,vlimhi ,undefi ,bigedm,updflt
73  m/mn7rpt/ xpt(maxcpt) ,ypt(maxcpt)
74  n/mn7cpt/ chpt(maxcpt)
75  o/mn7xcr/ xmidcr ,ymidcr ,xdircr ,ydircr ,ke1cr ,ke2cr
76  CHARACTER ctitl*50, cword*(maxcwd), cundef*10, cfrom*8,
77  + cvrsn*6, covmes(0:3)*22, cstatu*10, chpt*1
78  LOGICAL lwarn, lrepor, limset, lnolim, lnewmn, lphead
79  EXTERNAL fcn,futil
80  dimension yy(mni)
81  LOGICAL ldebug
82  CHARACTER cbf1*22
83 C
84  ldebug = (idbg(3) .GE. 1)
85  IF (amin .EQ. undefi) CALL mnamin(fcn,futil)
86  IF (istrat .LE. 0) THEN
87  ncyc = 3
88  tlrstp = 0.5
89  tlrg2 = 0.1
90  ELSE IF (istrat .EQ. 1) THEN
91  ncyc = 5
92  tlrstp = 0.3
93  tlrg2 = 0.05
94  ELSE
95  ncyc = 7
96  tlrstp = 0.1
97  tlrg2 = 0.02
98  ENDIF
99  IF (isw(5).GE.2 .OR. ldebug) WRITE (isyswr,'(A)')
100  + ' START COVARIANCE MATRIX CALCULATION.'
101  cfrom = 'HESSE '
102  nfcnfr = nfcn
103  cstatu= 'OK '
104  npard = npar
105 C make sure starting at the right place
106  CALL mninex(x)
107  nparx = npar
108  CALL fcn(nparx,gin,fs1,u,4,futil)
109  nfcn = nfcn + 1
110  IF (fs1 .NE. amin) THEN
111  df = amin - fs1
112  WRITE (cbf1(1:12),'(G12.3)') df
113  CALL mnwarn('D','MNHESS',
114  + 'function value differs from AMIN by '//cbf1(1:12) )
115  ENDIF
116  amin = fs1
117  IF (ldebug) WRITE (isyswr,'(A,A)') ' PAR D GSTEP ',
118  +' D G2 GRD SAG '
119 C . . . . . . diagonal elements .
120 C ISW(2) = 1 if approx, 2 if not posdef, 3 if ok
121 C AIMSAG is the sagitta we are aiming for in second deriv calc.
122  aimsag = sqrt(epsma2)*(abs(amin)+up)
123 C Zero the second derivative matrix
124  npar2 = npar*(npar+1)/2
125  DO 10 i= 1,npar2
126  10 vhmat(i) = 0.
127 C
128 C Loop over variable parameters for second derivatives
129  idrv = 2
130  DO 100 id= 1, npard
131  i = id + npar - npard
132  iext = nexofi(i)
133  IF (g2(i) .EQ. zero) THEN
134  WRITE (cbf1(1:4),'(I4)') iext
135  CALL mnwarn('W','HESSE',
136  + 'Second derivative enters zero, param '//cbf1(1:4) )
137  wint = werr(i)
138  IF (nvarl(iext) .GT. 1) THEN
139  CALL mndxdi(x(i),i,dxdi)
140  IF (abs(dxdi) .LT. .001) THEN
141  wint = .01
142  ELSE
143  wint = wint/abs(dxdi)
144  ENDIF
145  ENDIF
146  g2(i) = up/wint**2
147  ENDIF
148  xtf = x(i)
149  dmin = 8.*epsma2*abs(xtf)
150 C
151 C find step which gives sagitta = AIMSAG
152  d = abs(gstep(i))
153  DO 40 icyc= 1, ncyc
154 C loop here only if SAG=0.
155  DO 25 multpy= 1, 5
156 C take two steps
157  x(i) = xtf + d
158  CALL mninex(x)
159  nparx = npar
160  CALL fcn(nparx,gin,fs1,u,4,futil)
161  nfcn = nfcn + 1
162  x(i) = xtf - d
163  CALL mninex(x)
164  CALL fcn(nparx,gin,fs2,u,4,futil)
165  nfcn = nfcn + 1
166  x(i) = xtf
167  sag = 0.5*(fs1+fs2-2.0*amin)
168  IF (sag .NE. zero) GO TO 30
169  IF (gstep(i) .LT. zero) THEN
170  IF (d .GE. .5) GO TO 26
171  d = 10.*d
172  IF (d .GT. 0.5) d = 0.51
173  GO TO 25
174  ENDIF
175  d = 10.*d
176  25 CONTINUE
177  26 WRITE (cbf1(1:4),'(I4)') iext
178  CALL mnwarn('W','HESSE',
179  + 'Second derivative zero for parameter'//cbf1(1:4) )
180  GO TO 390
181 C SAG is not zero
182  30 g2bfor = g2(i)
183  g2(i) = 2.*sag/d**2
184  grd(i) = (fs1-fs2)/(2.*d)
185  IF (ldebug) WRITE (isyswr,31) i,idrv,gstep(i),d,g2(i),grd(i),sag
186  31 FORMAT (i4,i2,6g12.5)
187  gstep(i) = sign(d,gstep(i))
188  dirin(i) = d
189  yy(i) = fs1
190  dlast = d
191  d = sqrt(2.0*aimsag/abs(g2(i)))
192 C if parameter has limits, max int step size = 0.5
193  stpinm = 0.5
194  IF (gstep(i) .LT. zero) d = min(d,stpinm)
195  IF (d .LT. dmin) d = dmin
196 C see if converged
197  IF (abs((d-dlast)/d) .LT. tlrstp) GO TO 50
198  IF (abs((g2(i)-g2bfor)/g2(i)) .LT. tlrg2 ) GO TO 50
199  d = min(d, 10.*dlast)
200  d = max(d, 0.1*dlast)
201  40 CONTINUE
202 C end of step size loop
203  WRITE (cbf1,'(I2,2E10.2)') iext,sag,aimsag
204  CALL mnwarn('D','MNHESS','Second Deriv. SAG,AIM= '//cbf1)
205 C
206  50 CONTINUE
207  ndex = i*(i+1)/2
208  vhmat(ndex) = g2(i)
209  100 CONTINUE
210 C end of diagonal second derivative loop
211  CALL mninex(x)
212 C refine the first derivatives
213  IF (istrat .GT. 0) CALL mnhes1(fcn,futil)
214  isw(2) = 3
215  dcovar = 0.
216 C . . . . off-diagonal elements
217  IF (npar .EQ. 1) GO TO 214
218  DO 200 i= 1, npar
219  DO 180 j= 1, i-1
220  xti = x(i)
221  xtj = x(j)
222  x(i) = xti + dirin(i)
223  x(j) = xtj + dirin(j)
224  CALL mninex(x)
225  CALL fcn(nparx,gin,fs1,u,4,futil)
226  nfcn = nfcn + 1
227  x(i) = xti
228  x(j) = xtj
229  elem = (fs1+amin-yy(i)-yy(j)) / (dirin(i)*dirin(j))
230  ndex = i*(i-1)/2 + j
231  vhmat(ndex) = elem
232  180 CONTINUE
233  200 CONTINUE
234  214 CALL mninex(x)
235 C verify matrix positive-definite
236  CALL mnpsdf
237  DO 220 i= 1, npar
238  DO 219 j= 1, i
239  ndex = i*(i-1)/2 + j
240  p(i,j) = vhmat(ndex)
241  219 p(j,i) = p(i,j)
242  220 CONTINUE
243  CALL mnvert(p,maxint,maxint,npar,ifail)
244  IF (ifail .GT. 0) THEN
245  CALL mnwarn('W','HESSE', 'Matrix inversion fails.')
246  GO TO 390
247  ENDIF
248 C . . . . . . . calculate e d m
249  edm = 0.
250  DO 230 i= 1, npar
251 C off-diagonal elements
252  ndex = i*(i-1)/2
253  DO 225 j= 1, i-1
254  ndex = ndex + 1
255  ztemp = 2.0 * p(i,j)
256  edm = edm + grd(i)*ztemp*grd(j)
257  225 vhmat(ndex) = ztemp
258 C diagonal elements
259  ndex = ndex + 1
260  vhmat(ndex) = 2.0 * p(i,i)
261  edm = edm + p(i,i) * grd(i)**2
262  230 CONTINUE
263  IF (isw(5).GE.1 .AND. isw(2).EQ.3 .AND. itaur.EQ.0)
264  + WRITE(isyswr,'(A)')' COVARIANCE MATRIX CALCULATED SUCCESSFULLY'
265  GO TO 900
266 C failure to invert 2nd deriv matrix
267  390 isw(2) = 1
268  dcovar = 1.
269  cstatu = 'FAILED '
270  IF (isw(5) .GE. 0) WRITE (isyswr,'(A)')
271  + ' MNHESS FAILS AND WILL RETURN DIAGONAL MATRIX. '
272  DO 395 i= 1, npar
273  ndex = i*(i-1)/2
274  DO 394 j= 1, i-1
275  ndex = ndex + 1
276  394 vhmat(ndex) = 0.0
277  ndex = ndex +1
278  g2i = g2(i)
279  IF (g2i .LE. zero) g2i = 1.0
280  395 vhmat(ndex) = 2.0/g2i
281  900 RETURN
integer npitbl real *nx parameter(n=101, npitbl=46, nx=n-1) real *8 uconst
nodes z
block data include Zlatfit h c fitting region data data data data data d0 data data d0 data data h g *is for param c g data up(2, 1)/7.0d0/
dE dx *! Nuc Int sampling table e
Definition: cblkMuInt.h:130
nodes i
subroutine mnvert(A, L, M, N, IFAIL)
Definition: mnvert.f:25
real(4), dimension(:), allocatable, save h
Definition: cNRLAtmos.f:28
! constants thru Cosmos real ! if multiplied to deg radian Torad ! light velocity m sec ! infinty ! kg m2 *Togpcm2 g cm2 ! g cm2 *Tokgpm2 kg m2 ! cm *Tom m ! m *Tocm cm ! g cm3 *Tokgpm3 kg m3 ! kg m3 *Togpcm3 g cm3 ! sec *Tonsec nsec ! Tesla m ! Avogadro *A2deninv ! mfp *n * xs
Definition: Zglobalc.h:18
subroutine mnamin(FCN, FUTIL)
Definition: mnamin.f:10
********************block data cblkHeavy ********************integer j data *HeavyG2symbol p
Definition: cblkHeavy.h:7
********************block data cblkHeavy ********************integer j data *HeavyG2symbol *data *HeavyG2code kiron data j
Definition: cblkHeavy.h:36
struct ob o[NpMax]
Definition: Zprivate.h:34
subroutine mndxdi(PINT, IPAR, DXDI)
Definition: mndxdi.f:10
subroutine mninex(PINT)
Definition: mninex.f:10
subroutine mnpsdf
Definition: mnpsdf.f:25
dE dx *! Nuc Int sampling table d
Definition: cblkMuInt.h:130
subroutine mnhes1(FCN, FUTIL)
Definition: mnhes1.f:10
block data include Zlatfit h c fitting region data data data data data d0 data data d0 data data m
Definition: ZlatfitBD.h:35
real(4), save a
Definition: cNRLAtmos.f:20
dE dx *! Nuc Int sampling table g
Definition: cblkMuInt.h:130
real(4), save b
Definition: cNRLAtmos.f:21
!onst int maxp
Definition: Zprivate.h:3
subroutine mnwarn(COPT, CORG, CMES)
Definition: mnwarn.f:10
integer n
Definition: Zcinippxc.h:1
integer, parameter half
Definition: csoftenPiK.f:108
! structure defining a particle at production ! Basic idea of what is to be contained in ! the particle structue is that dynamical ones should be included those derivable from the particle code ! is not included ******************************************************type fmom momentum sequence union map real e endmap map real * x
Definition: Zptcl.h:21
dE dx *! Nuc Int sampling table f
Definition: cblkMuInt.h:130
dE dx *! Nuc Int sampling table c
Definition: cblkMuInt.h:130
Here is the call graph for this function:
Here is the caller graph for this function: