COSMOS v7.655  COSMOSv7655
(AirShowerMC)
tranFit.f
Go to the documentation of this file.
1 #include "BlockData/cblkGene.h"
2  include "ZfitBD.h"
3  program tranfit
4  implicit none
5  include "Zfit.h"
6 
7  real*8 xin(maxbin), yin(maxbin)
8  character*128 buf
9  integer nbin0, count, icon, status
10 
11 
12  count = nargs()
13  if(count .ne. 2) then
14  write(0,*) 'Usage: tranaFit... op < inputfile > outfile'
15  write(0,*) "op: 1 stdout: fitted x,y line by line "
16  write(0,*) "op: 2 stdout: fitting coeff. a,s,xmax"
17  write(0,*) "op: 3 stdout: xmax, apparent_xmax"
18  write(0,*)
19  * "op: 4 stdout: xmax, apparent_xmax, a,s,xmax"
20  write(0,*)
21  * "op: 5 stdout: xmax, apparent_xmax, a,s,xmax"
22  write(0,*) " fitted x y line by line "
23  write(0,*) ' inputfile: depth vs flux'
24  stop
25  endif
26  call getarg(1, buf, status)
27  read(buf, *) op
28  nbin0 = 0
29  do while(.true.)
30  read(*,*,end=100) xin(nbin0+1), yin(nbin0+1)
31  nbin0 = nbin0 +1
32  enddo
33 100 continue
34  if(nbin0 .gt. maxbin) then
35  write(0,*) ' too many data> ', maxbin
36  stop
37  endif
38 
39 
40  call copenfw2(minout, "/dev/null", 1, icon)
41 
42 
43  call fittran0(xin, yin, nbin0)
44  end
45 
46  subroutine fittran0(xin, yin, nbin)
47  implicit none
48  include "Zfit.h"
49  integer nbin
50  real*8 xin(nbin), yin(nbin)
51  real*8 xuse(nbin), yuse(nbin)
52  real*8 prmout(nparam)
53 
54  integer i
55  integer n1
56  real*8 xx, f, xb, xmax
57  real*8 a, s, x0
58 
59 
60 
61 
62 ! find max pos and use max of 9 points
63 ! around max.
64 !
65  maxval = yin(1)-1.0e10
66  do i = 1, nbin
67  if(maxval .lt. yin(i)) then
68  maxpos = i
69  maxval = yin(maxpos)
70  endif
71  enddo
72 
73  maxdep = xin(maxpos)
74  from = max(maxpos-2, 1)
75  to = min(maxpos+2, nbin)
76 !
77  write(0,*) ' max depth index and depth=', maxpos, maxdep
78  write(0,*) ' layers for fitting are from', from, ' to ', to
79 ! a* exp(-((x-x0)/s)**2/2)
80 !
81  param(1) = yin(maxpos) ! a
82  param(2) = 50. ! s
83  param(3) = maxdep ! x0
84  n1 = 0
85  do i = from, to
86  n1 = n1 + 1
87  xuse(n1) = xin(i)
88  yuse(n1) = yin(i)
89  enddo
90 !
91  call fittran( xuse, yuse, n1, param, prmout)
92 !
93 
94 ! to see fitted result
95 
96  a = prmout(1)
97  s = prmout(2)
98  x0 = prmout(3)
99 ! coeff is put on stderr
100  write(0,'(3g12.4)') prmout
101  xmax = x0
102  write(0,'("max dep=",g12.3)') x0
103 
104  if(op .eq. 1) then
105  xx = drx1*xmax
106  do while ( xx .le. drx2*xmax )
107  f= a*exp( - ((xx-x0)/s)**2/2.)
108  write(*,*) xx, f
109  xx = xx*10.0**0.002
110  enddo
111  elseif(op .eq. 2) then
112  write(*,'(5G14.4)') a, s, x0
113  elseif(op .eq. 3) then
114  write(*,*) xmax, maxdep
115  elseif(op .eq. 4) then
116  write(*,'(7g14.4)') xmax, maxdep, a,s,x0
117  elseif(op .eq. 5) then
118  write(*,'(7g14.4)') xmax, maxdep, a,s,x0
119  xx = drx1*xmax
120  do while ( xx .le. drx2*xmax )
121  f= a*exp( - ((xx-x0)/s)**2/2.)
122  write(*,*) xx, f
123  xx = xx*10.0**0.002
124  enddo
125  endif
126  end
127 ! ***************************************************
128  subroutine fittran(xin, yin, n, prmin, prmout )
129  implicit none
130  include "Zfit.h"
131  real*8 prmin(nparam), prmout(nparam)
132  integer n
133  real*8 xin(n), yin(n)
134 
135  integer nlabel(nparam)
136  character*10 pname(nparam)
137  real*8 initval(nparam)
138  real*8 step(nparam)
139 
140  data nlabel/ 1, 2, 3/
141  data pname/ 'a', 's', 'x0'/
142  data step/ 10., 1.0, 1.0/
143  real*8 zero, one, three, four, five
144  data zero,one,three,four, five / 0., 1., 3.,4., 5. /
145  real*8 low(nparam), high(nparam)
146  real*8 fval, xx
147  integer i, ierflg
148 
149  external tranfnc
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  enddo
159 
160  do i = 1, nparam
161  initval(i) = prmin(i)
162  enddo
163  low(1) = prmin(1)*0.1
164  high(1) = prmin(1)*4
165  low(2) = prmin(2)*0.1
166  high(2) = prmin(2)*10.
167  low(3) = prmin(3)-12.5
168  high(3) = prmin(3)+12.5
169 
170  call mninit( 5, minout, minsave)
171 
172  do i= 1, nparam
173 ! nprm: a number given to a parameter: (label)
174 ! pnam: name of the parameer
175 ! vstrt: initial value of the parameter
176 ! stp: initial step size of the //
177 ! next two: zero-->the parameter is not bounded (lower or upper)
178 ! ierflg: retrun value; cond code. 0--> ok
179 
180  call mnparm(nlabel(i), pname(i), initval(i), step(i),
181 ! * low(i, code), up(i, code), ierflg)
182  * low(i), high(i), ierflg)
183 
184  if (ierflg .ne. 0) then
185  write (0,'(a,i3)') ' unable to define parameter no.',i
186  stop
187  endif
188  enddo
189 !
190  call mnseti('tranfit')
191 ! request fcn to read in (or generate random) data (iflag=1)
192 ! fcnk0: function to be minimuzed is calculated. also
193 ! there are other funcitons
194 ! one is the argument to fcnk0. seems to be converted to
195 ! integer inside.
196 ! 1 number of argument in one (one could be array)
197 ! ierflf: ouptut. 0-->ok
198 ! 0: no external function is used in fcnk0
199 
200  call mnexcm(tranfnc, 'call fcn', one ,1,ierflg, 0)
201 ! fix the 3,4,5-th parameters,
202 ! call mnexcm(timefnc,'fix', fixlist ,3, ierflg,0)
203 ! print minumum things
204  call mnexcm(tranfnc,'set print', zero ,1,ierflg,0)
205 ! use migrad method for minimization
206 ! with default condtions
207  call mnexcm(tranfnc,'migrad', zero ,0,ierflg,0)
208 ! analysis of errors for all parameters
209  call mnexcm(tranfnc,'minos', zero ,0,ierflg,0)
210 ! call fcn with 3. i.e, ouput etc.
211  call mnexcm(tranfnc,'call fcn', three , 1,ierflg, 0)
212 
213  do i = 1, nparam
214  prmout(i) = oparam(i)
215  enddo
216 
217  end
218 
subroutine fittran(xin, yin, n, prmin, prmout)
Definition: tranFit.f:129
subroutine mnexcm(FCN, COMAND, PLIST, LLIST, IERFLG, FUTIL)
Definition: mnexcm.f:25
integer maxbin nregion c minsave drx2 ! drawing region real maxdep integer maxpos integer op real x1h common Zfitc * maxval
Definition: Zfit.h:15
integer maxright integer maxbin nregion c minsave drx2 ! drawing region real maxdep integer maxpos integer op real x1h common Zfitc op
Definition: Zfit.h:16
integer maxbin nregion c minsave drx2 ! drawing region real maxdep integer maxpos integer op real x1h common Zfitc maxpos
Definition: Zfit.h:15
subroutine fittran0(xin, yin, nbin)
Definition: tranFit.f:47
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
integer maxbin nregion c minsave drx2 ! drawing region real maxdep integer maxpos integer op real x1h common Zfitc maxdep
Definition: Zfit.h:15
program tranfit
Definition: tranFit.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
integer maxbin nregion c minsave drx2 ! drawing region real maxdep integer maxpos integer to
Definition: Zfit.h:15
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
subroutine tranfnc(npar, gin, f, paramx, iflag)
Definition: tranfnc.f:2
*************************block data cblkTracking *************************implicit none data *ExactThick *Freec *RatioToE0 *MagChgDist *TimeStructure *Truncn *Truncx data *IncMuonPolari *KEminObs *ThinSampling *EthinRatio *Generate *LpmEffect *MagPairEmin e10
Definition: cblkTracking.h:9
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
integer maxbin nregion c minsave drx2 ! drawing region real maxdep integer maxpos integer from
Definition: Zfit.h:15
! 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