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 ! if(code .le. 3) then
28 ! code = 1
29 ! else
30 ! code = 2
31 ! with negative c hadron can be treated same as e,g,mu
32 !
33 ! code = 1
34 ! 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 ! call copenfw2(minout, "./minout_@_#_%", 1, icon)
47  call copenfw2(minout, "/dev/null", 1, icon)
48 !ccc 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, 4, nregion)
62 
63  integer i
64  integer n1, n2, region
65  real*8 xx, f, xb
66 
67 ! fitting at region
68  do region=1, nregion
69 ! if(tcode .eq. 3 .and. region .eq. 4) then
70 ! pw = 0.5 ! %pw% <--this %pw% is needed blanks/ = /
71  ! Used by mkLDD/Util/Lat/
72 ! else
73 ! pw = 0.5
74 ! 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 !////////////
85 ! write(0,*) ' region=',region, ' points=', n1
86 ! write(0,*) ' param(1,region)=', param(1, region)
87 ! write(0,*) ' param(2,region)=', param(2, region)
88 ! write(0,*) ' param(3,region)=', param(3, region)
89 !//////////
90 ! region, x, y, #, output param
91  call fitlat1(region, code, xuse, yuse, n1,
92  * param(1, code, region), prmout(1, code,region))
93 
94  if(cond .eq. 1) then
95 ! only coeff. is put on stdout
96  write(*,'(5g12.4)') prmout(1, code,region),
97  * prmout(2,code, region),
98  * prmout(3, code, region), prmout(4,code, region),
99  * maxdiff
100 ! if(code .eq. 2) then
101 !c for hadron, region 1 is mssing so we repeat region 2 data
102 ! write(*,'(3g12.4)')
103 ! * prmout(1, region), prmout(2, region), prmout(3, region)
104 ! endif
105  else
106 ! coeff is put on stderr
107  write(0,'(5g12.4)') prmout(1,code, region),
108  * prmout(2, code, region),
109  * prmout(3, code, region), prmout(4, code,region),
110  * maxdiff
111  endif
112  if(cond .eq. 0) then
113 ! to see fitted result (r, t) is put on stdout
114  xx = drx1( region)
115  pw = prmout(4,code, region)
116  do while ( xx .le. drx2(region) )
117  f=prmout(1,code,region)/
118  * xx**(prmout(2,code, region) +
119 ! * prmout(3,region)* log(xx) )
120  * prmout(3,code, region)* xx**pw )
121  write(*,*) xx, f
122  xx = xx*10.0**0.02
123  enddo
124  endif
125  enddo
126  end
127 ! ***************************************************
128  subroutine fitlat1(region, code, xin, yin, n, prmin, prmout )
129  implicit none
130  include "Zlatfit.h"
131  integer region, code
132  real*8 prmin(nparam), prmout(nparam)
133  integer n
134  real*8 xin(n), yin(n)
135 
136  integer nlabel(nparam)
137  character*10 pname(nparam)
138  real*8 initval(nparam)
139  real*8 step(nparam)
140 
141  data nlabel/ 1, 2, 3, 4/
142  data pname/ 'p', 'q', 'r', 'pw'/
143  data step/ 1., 0.001d0, 0.0001d0, 0.1d0/
144  real*8 zero, one, three, four, five
145  data zero,one,three,four, five / 0., 1., 3.,4., 5. /
146  real*8 fval, xx
147  integer i, ierflg
148 
149  external latfnc
150 
151 !
152 ! in fortran mode, this must be called for a new fnc
153 !
154  npoint = n
155  do i = 1, npoint
156  x(i) = xin(i)
157  y(i) = yin(i)
158 !*************
159  badindex(i)=i
160 !***************
161  enddo
162 
163  do i = 1, nparam
164  initval(i) = prmin(i)
165  enddo
166 
167  call mninit( 5, minout, minsave)
168 
169  do i= 1, nparam
170 ! nprm: a number given to a parameter: (label)
171 ! pnam: name of the parameer
172 ! vstrt: initial value of the parameter
173 ! stp: initial step size of the //
174 ! next two: zero-->the parameter is not bounded (lower or upper)
175 ! ierflg: retrun value; cond code. 0--> ok
176 
177  call mnparm(nlabel(i), pname(i), initval(i), step(i),
178  * low(i, code,region), up(i, code,region), ierflg)
179 
180  if (ierflg .ne. 0) then
181  write (0,'(a,i3)') ' unable to define parameter no.',i
182  stop
183  endif
184  enddo
185 !
186  call mnseti('lat as a function of core distance')
187 ! request fcn to read in (or generate random) data (iflag=1)
188 ! fcnk0: function to be minimuzed is calculated. also
189 ! there are other funcitons
190 ! one is the argument to fcnk0. seems to be converted to
191 ! integer inside.
192 ! 1 number of argument in one (one could be array)
193 ! ierflf: ouptut. 0-->ok
194 ! 0: no external function is used in fcnk0
195  limit = 0.
196  call mnexcm(latfnc, 'call fcn', one ,1,ierflg, 0)
197 ! fix the 3,4,5-th parameters,
198 ! call mnexcm(timefnc,'fix', fixlist ,3, ierflg,0)
199 ! print minumum things
200  call mnexcm(latfnc,'set print', zero ,1,ierflg,0)
201 ! use migrad method for minimization
202 ! with default condtions
203  call mnexcm(latfnc,'migrad', zero ,0,ierflg,0)
204 ! analysis of errors for all parameters
205  call mnexcm(latfnc,'minos', zero ,0,ierflg,0)
206 
207 
208  if(region .eq. 4 ) then
209 ! if max diff is < 10% no more trial
210 ! log(1.1)**2 = 0.009
211  if(maxdiff .gt. 0.01) then
212  badindex(maxindex)= -maxindex
213  call mnexcm(latfnc,'migrad', zero ,0,ierflg,0)
214 ! analysis of errors for all parameters
215  call mnexcm(latfnc,'minos', zero ,0,ierflg,0)
216 ! if there is still 20 % diff.. remove it
217  if(maxdiff .gt. 0.033) then
218 ! write(0,*) ' maxdiff=',maxdiff,
219 ! * ' idx=',maxindex
220  badindex(maxindex)= -maxindex
221  call mnexcm(latfnc,'migrad', zero ,0,ierflg,0)
222 ! analysis of errors for all parameters
223  call mnexcm(latfnc,'minos', zero ,0,ierflg,0)
224  endif
225  endif
226  endif
227 
228 !
229 ! call fcn with 3. i.e, ouput etc.
230  call mnexcm(latfnc,'call fcn', three , 1,ierflg, 0)
231 
232  do i = 1, nparam
233  prmout(i) = oparam(i)
234  enddo
235 
236  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