COSMOS v7.655  COSMOSv7655
(AirShowerMC)
ksampLin.f File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine ksamplin (a, b, alpha, beta, x)
 

Function/Subroutine Documentation

◆ ksamplin()

subroutine ksamplin ( real*8  a,
real*8  b,
real*8  alpha,
real*8  beta,
real*8  x 
)

Definition at line 15 of file ksampLin.f.

References rndc().

Referenced by ccomptea(), cmuneudcy(), cresetposang(), and csprimang().

15 ! samples a random variable with density
16 ! f(x)dx = ax + b in x=(alpha, beta); alpha <= beta
17 ! f(x) need not be normalized.
18 ! f(x) > 0 in the region since it is prob. density.
19 !
20  implicit none
21  real*8 a ! input.
22  real*8 b ! input.
23  real*8 alpha ! input
24  real*8 beta ! input. beta > alpha.
25  real*8 x ! output.
26 !
27  real*8 u1, u2, u
28  real*8 fa ! f(alpha)
29  real*8 fb ! f(beta)
30  real*8 ba ! beta -alpha
31 !
32  ba = beta - alpha
33  if(ba .eq. 0.) then
34  x = beta
35  elseif(ba .lt. 0.) then
36  stop 'error input to ksampLin'
37  else
38  fa = a*alpha + b
39  fb = a*beta + b
40  if(fa .lt. 0 .or. fb .lt. 0.) then
41  stop 'bad region to ksampLin'
42  endif
43 
44  call rndc(u)
45  if(u .lt. abs(fb - fa)/(fb + fa)) then
46  call rndc(u1)
47  call rndc(u2)
48  if(fa .lt. fb) then
49  x = max(u1, u2)
50  else
51  x = min(u1, u2)
52  endif
53  x = ba * x + alpha
54  else
55  call rndc(u)
56  x = ba * u + alpha
57  endif
58  endif
subroutine rndc(u)
Definition: rnd.f:91
real(4), save a
Definition: cNRLAtmos.f:20
real(4), save b
Definition: cNRLAtmos.f:21
! 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
Here is the call graph for this function:
Here is the caller graph for this function: