COSMOS v7.655  COSMOSv7655
(AirShowerMC)
kwhist.f
Go to the documentation of this file.
1 !
2 ! weighted histograming without dynamic memory allocation
3 ! Usage: kwhisti: initialization for one histogram
4 ! kwhistc: clear histogram area
5 ! kwhist: take histogram
6 ! kwhists: compute statistical result
7 ! kwhistp: print statistical resutl
8 !
9 !
10  subroutine kwhisti(h, ixmin, ibin, dummy, itklg )
11  implicit none
12 ! initialize
13  integer dummy ! not used. for the compat. with f90 version.
14  real ixmin ! input. xmin. not in log even itklg ==1
15  real ibin ! input. bin. If log, bin is for log10
16  integer itklg ! input. bit 1: 0--> not take log10
17  ! 1--> take log10
18  ! 2: 0--> ixmin is the min of bin
19  ! 1--> ixmin is the center of the min bin
20  ! 3: 0--> neglect underflow
21  ! 1--> underflow is put in min bin
22  ! mean bin value is affected by
23  ! those with underflowed values
24  ! 4: 0--> neglect overflow
25  ! 1--> overflow is put in the highest bin
26  ! mean bin value is affected by
27  ! overflowed ones
28 ! ******************
29 #include "Zhist.f"
30  type(histogram):: h
31 ! ====================
32  real inorm ! input. used in the normalization as dN/dx/inorm
33  ! if this is 0, area normalization is tried.
34 !
35  real x, w
36  real xx
37  integer isum, i, ndiv
38  logical asmax
39  real isumw
40  real dx
41  character*(*) id
42 
43  h.tklg = ( itklg-(itklg/2)*2 ) .ne. 0
44  h.cent = ( (itklg/2)*2 - (itklg/4)*4)/2
45  h.ufl = ( (itklg/4)*4 - (itklg/8)*8 ) .ne. 0
46  h.ofl = ( (itklg/8)*8 - (itklg/16)*16 ) .ne. 0
47 
48  h.xmin = ixmin ! (not used at present)
49  asmax = ( (itklg/16)*16 - (itklg/32)*32 ) .ne. 0
50  if(asmax) then
51  if(ixmin .ge. ibin) then
52  write(0,*) ' ibin is regarded as ixmax but <= ixmin'
53  stop 99999
54  else
55  if( h.cent .eq. 1 ) then
56  ndiv= ibin - 1
57  else
58  ndiv = ibin
59  endif
60  if(h.tklg) then
61  h.bin = log10(ibin/ixmin)/ndiv
62  else
63  h.bin = (ibin - ixmin )/ndiv
64  endif
65  endif
66  else
67  h.bin = ibin
68  endif
69 
70 
71  h.nhist = nhistp
72  if( h.tklg ) then
73  if(ixmin <= 0.0) then
74  write(0,
75  * '("min must be > 0 for log option")')
76  stop
77  endif
78  h.xm = log10(ixmin) - h.cent * h.bin/2.
79  h.inc = 10.**h.bin
80  else
81  h.xm = ixmin - h.cent * h.bin/2.
82  h.inc = h.bin
83  endif
84  return
85 
86 ! *****************
87  entry kwhistc(h)
88 ! *****************
89  do i = 1, h.nhist
90  h.dn(i) = 0.
91  h.dnw(i) = 0.
92  h.mean(i) = 0.
93  enddo
94  return
95 
96 ! *************************
97  entry kwhist( h, x, w )
98 ! *************************
99  if( h.tklg .and. x .le. 0.) then
100 ! neglect this data
101  else
102  if( h.tklg ) then
103  xx = log10(x)
104  else
105  xx = x
106  endif
107  i = ( xx-h.xm ) / h.bin + 1
108  if(i .le. 0 .and. h.ufl ) then
109  i = 1
110  elseif(i .gt. h.nhist .and. h.ofl ) then
111  i = h.nhist
112  endif
113  if(i .ge. 1 .and. i .le. h.nhist ) then
114  h.dn(i) = h.dn(i) + 1
115  h.dnw(i) = h.dnw(i) + w
116  h.mean(i) = h.mean(i) + x*w
117  endif
118  endif
119  return
120 
121 ! ***********************
122  entry kwhists( h, inorm )
123 ! ************* take statistics
124  h.norm = inorm
125  h.imin = 1
126 
127  do while(h.imin .lt. h.nhist .and. h.dn(h.imin) .eq. 0)
128  h.imin = h.imin + 1
129  enddo
130 
131  h.imax = h.nhist
132  do while ( h.imax .gt. 1 .and. h.dn(h.imax) .eq. 0)
133  h.imax = h.imax -1
134  enddo
135 
136  h.sum= 0
137  do i = h.imin, h.imax
138  h.sum = h.sum + h.dn(i)
139  enddo
140 
141  h.sumw = 0.
142  do i = h.imin, h.imax
143  h.sumw = h.sumw + h.dnw(i)
144  enddo
145 ! bin center value
146  if(h.tklg ) then
147  xx = 10.**( h.xm + h.bin/2.) * h.inc**(h.imin-1)
148  else
149  xx = h.xm + h.bin/2. + h.inc*(h.imin-1)
150  endif
151 
152  dx = h.bin
153 
154  if(h.norm .eq. 0. .and. h.sumw .gt. 0.) then
155  h.norm = h.sumw
156  else(h.norm .eq. 0. ) then
157  h.norm = 1.
158  endif
159 
160  do i = h.imin, h.imax
161  if(h.tklg ) then
162  dx = 10.0**(h.xm + i * h.bin) - 10.0**(h.xm + (i-1)*h.bin)
163  endif
164  if(h.dnw(i) .eq. 0) then
165  h.mean(i) = xx
166  else
167  h.mean(i) = h.mean(i)/h.dnw(i)
168  endif
169  h.dndx(i) = h.dnw(i)/dx/h.norm
170  if(h.tklg ) then
171  xx = xx * h.inc
172  else
173  xx = xx + h.inc
174  endif
175  enddo
176  return
177 ! *********************
178  entry kwhistp(h, id)
179 ! ****************print hist
180  isum = h.sum
181  isumw = h.sumw
182 
183 
184  if(h.tklg ) then
185  xx =10.0**( h.xm + h.bin/2) * h.inc**(h.imin-1)
186  else
187  xx = (h.xm + h.bin/2) + h.inc*(h.imin-1)
188  endif
189 
190  do i = h.imin, h.imax
191  write(*, '(a, " ", i5, 4g14.4, i10, i10, g14.4)') id, i,
192  * xx, h.dndx(i), h.dnw(i), isumw, h.dn(i), isum, h.mean(i)
193  isum = isum - h.dn(i)
194  isumw = isumw - h.dnw(i)
195  if( h.tklg ) then
196  xx = xx * h.inc
197  else
198  xx = xx + h.inc
199  endif
200  enddo
201  end
202 
203 
204 
205 
206 
207 
common ZdedxAir norm
Definition: ZdedxAir.h:2
integer nsites ! max real bin
Definition: Zprivate0.h:2
void kwhistp(struct histogram1 *h, FILE *fno)
void kwhisti(struct histogram1 *h, float ixmin, float ibinORxmax, int inbin, int itklg)
void kwhist(struct histogram1 *h, float x, float w)
void kwhistc(struct histogram1 *h)
void kwhists(struct histogram1 *h, float inorm)