COSMOS v7.655  COSMOSv7655
(AirShowerMC)
cmPairE.f
Go to the documentation of this file.
1 !c tseting sampling of magnetic pair production spectrum.
2 !c
3 ! implicit none
4 ! integer i, nc, imax
5 ! imax = 20000
6 ! real*8 xai, ee
7 ! read(*,*) xai, imax
8 ! do i =1, imax
9 ! call cmPairE(xai, ee, nc)
10 ! write(*,*) sngl(ee), nc
11 ! enddo
12 ! end
13  subroutine cmpaire(xai, ee, nc)
14  implicit none
15  real*8 xai ! input. xai = Bsin/Bc * Eg/m/2
16  real*8 ee ! output. fractional electron energy >= 0.5
17  integer nc ! output. nubmer of retrial for rejection method.
18 !
19  real*8 v, maxf, ve, xs5, xs, vx, a, b, beta, xse
20  real*8 u, cmPairSpec
21  integer i, j
22  real*8 xaisave, sigma
23  save xaisave, maxf, vx
24  save a, b, xs5
25  data xaisave/0./
26 
27  if(xai .ne. xaisave ) then
28  xs5 = cmpairspec(xai, 0.5d0)
29  if(xai .gt. 4.526) then
30 ! find peak which is not 0.5
31  v = .5d0
32  maxf = 0.
33  do while (v .lt. .999d0)
34  xs = cmpairspec(xai, v)
35  if(xs .gt. maxf) then
36  maxf = xs
37  vx = v
38  endif
39  v = v + .005d0
40  enddo
41  a = (maxf - xs5)/(vx - 0.5)
42  b = -0.5 * a + xs5
43  else
44  vx = 0.5d0
45  maxf = xs5
46  endif
47  xaisave = xai
48  endif
49  if(vx .ne. .5d0) then
50  do i = 1, 1000
51  call rndc(u)
52  beta = (3./8.*a + b/2)* u - (a/2 + b)
53  ve = (- b + sqrt(b**2 - 2*a*beta))/a
54 ! write(*, *) ' beta, ve', beta, ve, ' b^2-2beta',
55 ! * b**2 - 2*beta
56  call rndc(u)
57  xse = cmpairspec(xai, ve)
58 ! write(*,*) ' xse=',xse, ' a*ve+b=', a*ve+b
59  if(u .lt. xse/(a*ve + b)) goto 10
60  enddo
61  stop 9875
62  10 continue
63  ee = ve
64  elseif(xai .lt. .005) then
65  ee = .5
66  nc = 1
67  elseif(xai .lt. 1.) then
68 ! envelop is close to Gausssian of
69 ! sigma= .50/root(2)*xai**.53
70  sigma= .50/1.4142*xai**0.53
71  do j = 1, 1000
72  do i = j, 1000
73  call kgauss(0.5d0, sigma, ve)
74  if(ve .gt. 0. .and. ve .lt. 1.) goto 5
75  enddo
76  5 continue
77  xse = cmpairspec(xai, ve)
78  call rndc(u)
79  if(u .lt.
80  * xse /( ( exp(-((ve - 0.5)/sigma)**2/2) * maxf)))
81  * goto 8
82  enddo
83  8 continue
84  ee = ve
85  if(ee .lt. 0.5) ee = 1. - ee
86  else
87  do i =1, 1000
88  call rndc(u)
89  ve = u/2.+ 0.5
90  xse = cmpairspec(xai, ve)
91  call rndc(u)
92  if(u .lt. xse/maxf) goto 20
93  enddo
94  stop 1234
95  20 continue
96  ee =ve
97  endif
98  nc = i
99  end
subroutine cmpaire(xai, ee, nc)
Definition: cmPairE.f:14
subroutine rndc(u)
Definition: rnd.f:91
subroutine kgauss(m, v, g1)
Definition: kgauss.f:10
block data cblkEvhnp ! currently usable models data RegMdls ad *special data *Cekaon d0
Definition: cblkEvhnp.h:5