COSMOS v7.655  COSMOSv7655
(AirShowerMC)
latFit.f
Go to the documentation of this file.
1 #include "BlockData/cblkGene.h"
2  include "ZlatfitBD.h"
3  program latfit
4  implicit none
5  include "Zlatfit.h"
6 
7  real*8 xin(maxbin), yin(maxbin)
8  character*128 buf
9  integer nbin0, icon, code, tcode
10  integer count, status, cond
11  nbin0 = 0
12  count = nargs()
13  if(count .eq. 3) cond=1
14  if(count .eq. 2) cond=0
15  if( count .ne. 2 .and. count .ne. 3 ) then
16  write(0,*) 'Usage: latFit.. code [c] < inputfile > outfile'
17  write(0,*) ' code = particle code,',
18  * ' inputfile is output from splitLat.csh '
19  write(0,*) ' c: if exists, write only coeff. on stdout '
20  write(0,*) ' if omitted, coeff. is output on stderr,',
21  * ' fitted (x,y) on stdout'
22  stop 123
23  endif
24  call getarg(1, buf, status)
25  read(buf, *) code
26  tcode=code
27 c if(code .le. 3) then
28 c code = 1
29 c else
30 c code = 2
31 c with negative c hadron can be treated same as e,g,mu
32 c
33 c code = 1
34 c endif
35 
36  do while(.true.)
37  read(*,*,end=100) xin(nbin0+1), yin(nbin0+1)
38  nbin0 = nbin0 +1
39  enddo
40 100 continue
41  if(nbin0 .gt. maxbin) then
42  write(0,*) ' too many lat data> ', maxbin
43  stop
44  endif
45 
46 c call copenfw2(minout, "./minout_@_#_%", 1, icon)
47  call copenfw2(minout, "/dev/null", 1, icon)
48 cccc call copenfw2(minsave, "./minsave_@_#_%", 1, icon) !!!
49 
50 
51  call fitlat0(cond, tcode, code, xin, yin, nbin0)
52  end
53 
54  subroutine fitlat0(cond, tcode, code, xin, yin, nbin)
55  implicit none
56  include "Zlatfit.h"
57  integer cond
58  integer nbin, code, tcode
59  real*8 xin(nbin), yin(nbin)
60  real*8 xuse(nbin), yuse(nbin)
61  real*8 prmout(nparam, nregion)
62 
63  integer i
64  integer n1, n2, region
65  real*8 xx, f, xb
66 
67 c fitting at region
68  do region=1, nregion
69 c if(tcode .eq. 3 .and. region .eq. 4) then
70 c pw = 0.5 ! %pw% <--this %pw% is needed blanks/ = /
71  ! Used by mkLDD/Util/Lat/
72 c else
73 c pw = 0.5
74 c endif
75 
76  n1 =0
77  do i = 1, nbin
78  if(xin(i) .gt. x2(region) ) exit
79  if(xin(i) .lt. x1(region) ) cycle
80  n1 = n1 +1
81  xuse(n1) = xin(i)
82  yuse(n1) = yin(i)
83  enddo
84 c////////////
85 c write(0,*) ' region=',region, ' points=', n1
86 c write(0,*) ' param(1,region)=', param(1, region)
87 c write(0,*) ' param(2,region)=', param(2, region)
88 c write(0,*) ' param(3,region)=', param(3, region)
89 c//////////
90 c region, x, y, #, output param
91  call fitlat1(region, code, xuse, yuse, n1, param(1, region),
92  * prmout(1, region))
93 
94  if(cond .eq. 1) then
95 c only coeff. is put on stdout
96  write(*,'(4g12.4)') prmout(1, region), prmout(2, region),
97  * prmout(3, region), prmout(4, region)
98 c if(code .eq. 2) then
99 cc for hadron, region 1 is mssing so we repeat region 2 data
100 c write(*,'(3g12.4)')
101 c * prmout(1, region), prmout(2, region), prmout(3, region)
102 c endif
103  else
104 c coeff is put on stderr
105  write(0,'(4g12.4)') prmout(1, region), prmout(2, region),
106  * prmout(3, region), prmout(4,region)
107  endif
108  if(cond .eq. 0) then
109 c to see fitted result (r, t) is put on stdout
110  xx = drx1( region)
111  pw = prmout(4,region)
112  do while ( xx .le. drx2(region) )
113  f=prmout(1,region)/xx**(prmout(2,region) +
114 c * prmout(3,region)* log(xx) )
115  * prmout(3,region)* xx**pw )
116  write(*,*) xx, f
117  xx = xx*10.0**0.02
118  enddo
119  endif
120  enddo
121  end
122 c ***************************************************
123  subroutine fitlat1(region, code, xin, yin, n, prmin, prmout )
124  implicit none
125  include "Zlatfit.h"
126  integer region, code
127  real*8 prmin(nparam), prmout(nparam)
128  integer n
129  real*8 xin(n), yin(n)
130 
131  integer nlabel(nparam)
132  character*10 pname(nparam)
133  real*8 initval(nparam)
134  real*8 step(nparam)
135 
136  data nlabel/ 1, 2, 3, 4/
137  data pname/ 'p', 'q', 'r', 'pw'/
138  data step/ 1., 0.001d0, 0.0001d0, 0.1d0/
139  real*8 zero, one, three, four, five
140  data zero,one,three,four, five / 0., 1., 3.,4., 5. /
141  real*8 fval, xx
142  integer i, ierflg
143 
144  external latfnc
145 
146 c
147 c in fortran mode, this must be called for a new fnc
148 c
149  npoint = n
150  do i = 1, npoint
151  x(i) = xin(i)
152  y(i) = yin(i)
153 c*************
154  badindex(i)=i
155 c***************
156  enddo
157 
158  do i = 1, nparam
159  initval(i) = prmin(i)
160  enddo
161 
162  call mninit( 5, minout, minsave)
163 
164  do i= 1, nparam
165 c nprm: a number given to a parameter: (label)
166 c pnam: name of the parameer
167 c vstrt: initial value of the parameter
168 c stp: initial step size of the //
169 c next two: zero-->the parameter is not bounded (lower or upper)
170 c ierflg: retrun value; cond code. 0--> ok
171 
172  call mnparm(nlabel(i), pname(i), initval(i), step(i),
173  * low(i, code), up(i, code), ierflg)
174 
175  if (ierflg .ne. 0) then
176  write (0,'(a,i3)') ' unable to define parameter no.',i
177  stop
178  endif
179  enddo
180 c
181  call mnseti('lat as a function of core distance')
182 c request fcn to read in (or generate random) data (iflag=1)
183 c fcnk0: function to be minimuzed is calculated. also
184 c there are other funcitons
185 c one is the argument to fcnk0. seems to be converted to
186 c integer inside.
187 c 1 number of argument in one (one could be array)
188 c ierflf: ouptut. 0-->ok
189 c 0: no external function is used in fcnk0
190  limit = 0.
191  call mnexcm(latfnc, 'call fcn', one ,1,ierflg, 0)
192 c fix the 3,4,5-th parameters,
193 c call mnexcm(timefnc,'fix', fixlist ,3, ierflg,0)
194 c print minumum things
195  call mnexcm(latfnc,'set print', zero ,1,ierflg,0)
196 c use migrad method for minimization
197 c with default condtions
198  call mnexcm(latfnc,'migrad', zero ,0,ierflg,0)
199 c analysis of errors for all parameters
200  call mnexcm(latfnc,'minos', zero ,0,ierflg,0)
201 
202 
203  if(region .eq. 4 ) then
204 c if max diff is < 10% no more trial
205 c log(1.1)**2 = 0.009
206  if(maxdiff .gt. 0.01) then
207  badindex(maxindex)= -maxindex
208  call mnexcm(latfnc,'migrad', zero ,0,ierflg,0)
209 c analysis of errors for all parameters
210  call mnexcm(latfnc,'minos', zero ,0,ierflg,0)
211 c if there is still 20 % diff.. remove it
212  if(maxdiff .gt. 0.033) then
213 c write(0,*) ' maxdiff=',maxdiff,
214 c * ' idx=',maxindex
215  badindex(maxindex)= -maxindex
216  call mnexcm(latfnc,'migrad', zero ,0,ierflg,0)
217 c analysis of errors for all parameters
218  call mnexcm(latfnc,'minos', zero ,0,ierflg,0)
219  endif
220  endif
221  endif
222 
223 c
224 c call fcn with 3. i.e, ouput etc.
225  call mnexcm(latfnc,'call fcn', three , 1,ierflg, 0)
226 
227  do i = 1, nparam
228  prmout(i) = oparam(i)
229  enddo
230 
231  end
block data include Zlatfit h c fitting region data x1(1)/0.03/
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/
subroutine mnexcm(FCN, COMAND, PLIST, LLIST, IERFLG, FUTIL)
Definition: mnexcm.f:25
subroutine fitlat1(region, code, xin, yin, n, prmin, prmout)
Definition: latFit.f:129
subroutine mnseti(TIT)
Definition: mnseti.f:10
block data cblkElemag data *AnihiE ! Eposi< 1 TeV, anihilation considered *X0/365.667/, ! radiation length of air in kg/m2 *Ecrit/81.e-3/, ! critical energy of air in GeV *MaxComptonE/1./, ! compton is considered below 1 GeV *MaxPhotoE/1.e-3/, ! above this, PhotoElectric effect neg. *MinPhotoProdE/153.e-3/, ! below 153 MeV, no gp --> hadrons ! scattering const not MeV *Knockon true
Definition: cblkElemag.h:7
program latfit
Definition: latFit.f:3
subroutine copenfw2(io, fnin, form, icon)
Definition: copenf.f:205
integer maxbin nregion c minsave drx2 ! drawing region real maxdep integer maxpos integer op real x1h common Zfitc * param
Definition: Zfit.h:15
integer maxbin nregion c minsave drx2 ! drawing region real maxdep integer maxpos integer op real x1h common Zfitc drx1
Definition: Zfit.h:15
real(8), save pw
Definition: csoftenPiK.f:36
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 low(1, 1)/1.d-5/
block data cblkEvhnp ! currently usable models data RegMdls ad *special data *Cekaon d0
Definition: cblkEvhnp.h:5
integer maxbin nregion c minsave drx2 ! drawing region real maxdep integer maxpos integer npoint
Definition: Zfit.h:15
latitude latitude this system is used *****************************************************************! type coord sequence union map real y
Definition: Zcoord.h:25
subroutine mnparm(K, CNAMJ, UK, WK, A, B, IERFLG)
Definition: mnparm.f:25
block data include Zlatfit h c fitting region data x2(1)/0.5/data x1(2)/0.3/
subroutine mninit(I1, I2, I3)
Definition: mninit.f:34
integer maxbin nregion c minsave drx2 ! drawing region real maxdep integer maxpos integer op real x1h common Zfitc * oparam
Definition: Zfit.h:15
integer maxbin nregion c minsave drx2 ! drawing region real maxdep integer maxpos integer op real x1h common Zfitc drx2
Definition: Zfit.h:15
subroutine latfnc(npar, gin, f, paramx, iflag)
Definition: latfnc.f:2
! 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
subroutine fitlat0(cond, tcode, code, xin, yin, nbin)
Definition: latFit.f:55