COSMOS v7.655  COSMOSv7655
(AirShowerMC)
kpoisn.f
Go to the documentation of this file.
1 ! include 'kgauss.f'
2 ! include 'rnd.f'
3 !c test kpoisn
4 ! do i=1, 100000
5 ! call kpoisn(10.0d0, n)
6 ! write(*,*) n
7 ! enddo
8 ! end
9 !c ****************************************************************
10 ! * *
11 ! * kpoisn: Samples a poisson random variable *
12 ! * *
13 ! ********************** tested 86.12.18 *********************k.k*
14 !
15 ! /usage/ call kpoisn(am, n)
16 ! am: real*8. Input. The mean of the poisson distribution.
17 ! n: integer output. integer. A sampled variable.
18 !
19 ! If am >= 20, gaussian approximation is used.
20 !
21 ! subroutine needed. rndc, kgauss.
22 
23 
24  subroutine kpoisn(am, n)
25  implicit none
26  real*8 am
27  integer n
28 !
29  real*8 amsv/-1.98765d37/, ammx/20./
30  real*8 avsv, psv, q, u, sqam, x
31  save amsv, avsv, psv, sqam
32 !
33  logical more
34 !
35  if(am .lt. ammx) then
36  if(amsv .ne. am) then
37  avsv=am
38  psv=exp(-am)
39  endif
40  n=-1
41  q=1.
42  more=.true.
43  do while ( more )
44  n=n+1
45  call rndc(u)
46  q=q*u
47  more= q .ge. psv
48  enddo
49  else
50  if(amsv .ne. am) then
51  amsv=am
52  sqam=sqrt(am)
53  endif
54  more=.true.
55  do while ( more )
56  call kgauss(am, sqam, x)
57  n=x+.5
58  more=n .lt. 0
59  enddo
60  endif
61  end
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
subroutine rndc(u)
Definition: rnd.f:91
subroutine kpoisn(am, n)
Definition: kpoisn.f:25
subroutine kgauss(m, v, g1)
Definition: kgauss.f:10