COSMOS v7.655  COSMOSv7655
(AirShowerMC)
cnbdcy.f
Go to the documentation of this file.
1 ! include '../../KKlib/rnd.f'
2 ! include '../../KKlib/kcossn.f'
3 ! include 'cpxyzp.f'
4 ! include 'cmkptc.f'
5 !c ----------------------------------
6 !c to test cnbdcy
7 ! include '../Zptcl.h'
8 ! include '../Zcode.h'
9 ! implicit none
10 ! integer n, i, j, icon
11 ! parameter(n = 10)
12 ! type(ptcl):: p(n)
13 ! real *8 ecm/5./, w, sumx, sumy, sumz, sume
14 ! j = 1
15 ! do i=1, 3
16 ! call cmkptc(kpion, 0, 1, p(j))
17 ! call cmkptc(kkaon, k0s, 0, p(j+1))
18 ! call cmkptc(kpion, 0, 0, p(j+2))
19 ! j = j+3
20 ! enddo
21 ! call cmkptc(komega, 0, 0, p(n))
22 ! do j=1, 100
23 ! call cnbdcy(n, ecm, p, 0, w, icon)
24 ! if(icon .ne. 0) stop 111
25 ! sumx=0.
26 ! sumy=0.
27 ! sumz=0.
28 ! sume=0.
29 ! write(*, *) ' ----------w=', w
30 ! do i=1, n
31 !c ---------------------- to draw momentum balance graph
32 !c write(*,*) 0., 0.
33 !c write(*,*) sngl(p(i).fm.p(1)), sngl(p(i).fm.p(3))
34 !c write(*,*)
35 !c --------------------------
36 !c /////////// to see momentum conservation
37 ! sumx=sumx + p(i).fm.p(1)
38 ! sumy=sumy + p(i).fm.p(2)
39 ! sumz=sumz + p(i).fm.p(3)
40 ! sume=sume + p(i).fm.p(4)
41 !c ///////////////////////
42 ! enddo
43 ! write(*,*) sumx, sumy, sumz, sume
44 ! enddo
45 ! end
46 ! ***********************************************************
47  subroutine cnbdcy(n, ecm, p, jw, w, icon)
48  implicit none
49 ! ***********************************************************
50 !
51 ! ref: CPC. 40(1986)p359. Kleiss, Stirling and Ellis
52 !
53 ! n: input. number of ptcls >=2 (see however, for n=2,
54 ! c2bdcy and for n=3, c3bdcy)
55 ! ecm: input. cms energy.
56 ! p: input. /ptcl/ p(i).mass gives the mass of the i-th ptcl
57 ! in the same unit of ecm.
58 ! output. /ptcl/ p(i).fm.p(1)
59 ! py
60 ! pz
61 ! e of the i-th ptcl
62 ! jw: input. 0--->unweighted event (w=1) obtained. the event
63 ! generated need not be discarded.
64 ! 1--> weighted event( w changes event to event )
65 ! the event must be discarded according to the
66 ! acceptance probability of w=weight/wax weight).
67 ! w: output. see jw
68 ! icon: output. 0-->event generated successfully
69 ! 1-->ecm < sum of mass
70 ! 2-->could not generate (weight problem)
71 ! With n=10 ( 6 pions, 3 kaons, 1 omega ) Ecm=5 GeV,
72 ! to get icon=0 for unweighted events,
73 ! average number of trials is 7; the distribution is
74 ! very well approximated by exp(-ntry/7)dntry
75 ! With Ecm=10 GeV, <ntry> becomes 2.1
76 ! Ecm=4 GeV, <ntry> = 13
77 ! ==============
78 ! With n=4, (2 pions, 1 kaon, 1 omega) Ecm=4 GeV,
79 ! <ntry> is almost 1
80 !---- include '../Zptcl.h'
81 #include "Zptcl.h"
82  integer n, jw, icon
83  type(ptcl):: p(n)
84  real*8 ecm, w
85 ! ------------------
86  real*8 mu(1, 1)/0.d0/, wx, w0, wmax, gzai, u
87 !
88  logical ok
89  integer nc
90 !
91  nc = 0 ! counter to break inf. loop
92 ! *** until loop***
93  do while (.true.)
94 ! generate massless ptcls isotropically without conservation
95  call cnbdc1(n, p)
96 ! conformal transformation to conserve 4-momentum
97  call cnbdc2(n, ecm, p)
98 !$$$$$$$$$$$
99 ! call cnbdct(n, p)
100 !$$$$$$$$$$
101 ! get gzai to transform massive case
102  call cnbdc3(n, ecm, p, mu, 0, gzai, icon)
103 ! **********************
104  if(icon /= 0 ) then !!!!!!!
105  write(0,*) ' icon =',icon, ' from cnbdc3'
106  endif !!!!!!!!
107  if(icon .ne. 0) return
108 ! **********************
109 ! tranform to massive case
110  call cnbdc4(n, p, mu, 0, gzai)
111 !$$$$$$$$$$$
112 ! call cnbdct(n, p)
113 !$$$$$$$$$$
114 ! compute weight for massive case
115  call cnbdc5(n, ecm,p, wx)
116 ! compute weight for massless case
117  call cnbdc6(n, ecm, w0)
118 !$$$$$$$$$$$$$$
119 ! write(*,*) ' wx=',wx,' w0=',w0
120 !$$$$$$$$$$$
121  w=wx*w0
122 ! compute max possible weight
123  call cnbdc7(n, ecm, p, wmax)
124  wmax=wmax*w0
125  if(jw .eq. 0) then
126 !$$$$$$$$$$$$$$
127 ! write(*,*) ' wmax=',wmax
128 !$$$$$$$$$$$
129 ! judge if the event is to be accepted
130  call rndc(u)
131  if(wmax .eq. 0.d0) then
132  ok=.true.
133  else
134  ok = u .lt. w/wmax
135  endif
136  w=1.
137  else
138  if(wmax .eq. 0.d0) then
139  w=1.d0
140  else
141  w=w/wmax
142  endif
143  ok=.true.
144  endif
145  if(ok) goto 100
146  nc = nc +1
147  if(nc .gt. 100) then
148  icon = 2
149  goto 100
150  endif
151  enddo
152  100 continue
153  end
154  subroutine cnbdct(n, p)
155  implicit none
156 !---- include '../Zptcl.h'
157 #include "Zptcl.h"
158  integer n
159  type(ptcl):: p(n)
160 !
161  real*8 sumx, sumy, sumz, sume
162  integer i
163 !
164  sumx=0.d0
165  sumy=0.d0
166  sumz=0.d0
167  sume=0.d0
168  do i=1, n
169  sumx=sumx+p(i)%fm%p(1)
170  sumy=sumy+p(i)%fm%p(2)
171  sumz=sumz+p(i)%fm%p(3)
172  sume=sume+p(i)%fm%p(4)
173  enddo
174  write(*,*) ' sumx,y,z=',sumx, sumy, sumz, ' sume=',sume
175  end
176  subroutine cnbdc1(n, p)
177  implicit none
178 ! generate massless ptcls isotropically without conservation
179 !---- include '../Zptcl.h'
180 #include "Zptcl.h"
181  integer n
182  type(ptcl):: p(n)
183 !
184  integer i
185  real*8 u1, u2, u, cs, sn, cst, snt
186  do i=1, n
187 ! *** until loop***
188  do while (.true.)
189  call rndc(u1)
190  call rndc(u2)
191  u=u1*u2
192  if(u .gt. 0.) goto 10
193  enddo
194  10 continue
195  p(i)%fm%p(4) = -log(u)
196  call kcossn(cs, sn)
197  call rndc(u)
198  cst=2*u-1.d0
199  snt=sqrt(1. - cst**2)
200  p(i)%fm%p(1) = p(i)%fm%p(4)*snt*cs
201  p(i)%fm%p(2) = p(i)%fm%p(4)*snt*sn
202  p(i)%fm%p(3) = p(i)%fm%p(4)*cst
203  enddo
204  end
205  subroutine cnbdc2(n, ecm, p)
206 ! conformal transformation to conserve 4-momentum
207  implicit none
208 !---- include '../Zptcl.h'
209 #include "Zptcl.h"
210  integer n
211  type(ptcl):: p(n)
212  real*8 ecm
213 !
214  real*8 sumx, sumy, sumz, sume, em, g
215  real*8 a, x, bx, by, bz, bq, pe, tmp, px, py, pz
216  integer i
217 !
218  sumx=0.d0
219  sumy=0.d0
220  sumz=0.d0
221  sume=0.d0
222  do i=1, n
223  sumx=sumx+p(i)%fm%p(1)
224  sumy=sumy+p(i)%fm%p(2)
225  sumz=sumz+p(i)%fm%p(3)
226  sume=sume+p(i)%fm%p(4)
227  enddo
228  em=sqrt( sume**2 - (sumx**2+sumy**2+sumz**2) )
229  g=sume/em
230 
231  a=1.d0/(1.d0+g)
232  x=ecm/em
233  bx=-sumx/em
234  by=-sumy/em
235  bz=-sumz/em
236 !
237  do i=1, n
238  bq=bx*p(i)%fm%p(1) + by*p(i)%fm%p(2) + bz*p(i)%fm%p(3)
239  pe=x*(g*p(i)%fm%p(4) +bq)
240  tmp=p(i)%fm%p(4)+a*bq
241  px=x*(p(i)%fm%p(1) + tmp*bx)
242  py=x*(p(i)%fm%p(2) + tmp*by)
243  pz=x*(p(i)%fm%p(3) + tmp*bz)
244  p(i)%fm%p(1)=px
245  p(i)%fm%p(2)=py
246  p(i)%fm%p(3)=pz
247  p(i)%fm%p(4)=pe
248  enddo
249  end
250 ! ***********************************************
251  subroutine cnbdc3(n, ecm, p, mu, inm, gzai, icon)
252 ! get gzai to transform massive case
253 ! put inm=0 if all mu are the same.
254 ! ***********************************************
255  implicit none
256 !---- include '../Zptcl.h'
257 #include "Zptcl.h"
258  integer n, inm, icon
259  type(ptcl):: p(n)
260  real*8 ecm, mu(inm, n), gzai
261 !
262  real*8 eps/1.d-3/, f, fp, fow
263  integer nr
264 ! initial guess of gzai
265  gzai=.85d0
266  nr=0
267 ! *** until loop***
268  do while (.true.)
269  call cnbdcf(n, ecm, p, mu, inm, gzai, f, fp)
270  gzai= gzai - f/fp
271  fow=f
272  nr=nr+1
273 !$$$$$$$$$$$$
274 ! write(*,*) ' fow=',fow
275 !$$$$$$$$$$$$
276  if(abs(fow) .lt. eps .or. nr .gt. 15) goto 100
277  enddo
278  100 continue
279  if(nr .gt. 15) then
280  icon=1
281  else
282  icon=0
283  endif
284  end
285 ! *********************************************
286  subroutine cnbdcf(n, ecm, p,
287  * mu, inm, gzai, f, fp)
288 ! *********************************************
289  implicit none
290 !---- include '../Zptcl.h'
291 #include "Zptcl.h"
292  integer n, inm
293  type(ptcl):: p(n)
294  real*8 gzai, f, fp, mu(inm, n)
295 !
296  real*8 mux, fx, tmp, ecm
297  integer i
298 !
299  fx=0.d0
300  fp=0.d0
301  do i=1, n
302 ! if compiler is good, we can use mu(1,i)
303 ! even for inm=0; next is for safty.
304  if(inm .eq. 0) then
305 ! mux=mu(1,1)
306  mux=0.d0
307  else
308  mux=mu(1,i)
309  endif
310 
311  tmp= sqrt(p(i)%mass**2+
312  * gzai**2 *( p(i)%fm%p(4)**2 -mux**2 ) )
313  fx=fx + tmp
314  fp=fp + ( p(i)%fm%p(4)**2- mux**2)/ tmp
315  enddo
316  f=log(fx/ecm)
317  fp=fp*gzai/fx
318  end
319 ! *********************************************
320  subroutine cnbdc4(n, p, mu, inm, gzai)
321 ! tranform to massive case
322 ! *********************************************
323  implicit none
324 !---- include '../Zptcl.h'
325 #include "Zptcl.h"
326  integer n, inm
327  type(ptcl):: p(n)
328  real*8 mu(inm, n), gzai
329 
330  real*8 mux
331  integer i
332  do i=1,n
333  p(i)%fm%p(1) = gzai*p(i)%fm%p(1)
334  p(i)%fm%p(2) = gzai*p(i)%fm%p(2)
335  p(i)%fm%p(3) = gzai*p(i)%fm%p(3)
336 ! next treatment is for safty
337  if(inm .eq. 0) then
338 ! mux=mu(1,1)
339  mux=0.
340  else
341  mux=mu(1,i)
342  endif
343  p(i)%fm%p(4) = sqrt(p(i)%mass**2 +
344  * gzai**2*( p(i)%fm%p(4)**2-mux**2 ) )
345  enddo
346  end
347  subroutine cnbdc5(n, ecm, p, wx)
348 ! compute weig.p(4) for massive case
349  implicit none
350 !---- include '../Zptcl.h'
351 #include "Zptcl.h"
352  integer n
353  type(ptcl):: p(n)
354  real*8 ecm, wx
355 !
356  real*8 sum1, pro2, sum3, pab
357  integer i
358 !
359  sum1=0.
360  pro2=1.
361  sum3=0.
362  do i=1, n
363  call cpxyzp(p(i)%fm, pab)
364  sum1=sum1+pab
365  pro2=pro2* pab/p(i)%fm%p(4)
366  sum3=sum3+pab**2/p(i)%fm%p(4)
367  enddo
368  wx=(sum1/ecm)**(2*n-3)*pro2 /sum3
369  end
370  subroutine cnbdc6(n, ecm, w0)
371 ! compute weig.p(4) for massless case
372  implicit none
373 !---- include '../Zptcl.h'
374 #include "Zptcl.h"
375  integer n
376  real*8 ecm, w0
377 !
378  real*8 pi, hpi, gn1
379  integer i
380  parameter(pi=3.14159265d0, hpi=pi/2)
381 !
382  gn1=1.
383  do i=1, n-2
384  gn1=gn1*i
385  enddo
386  w0= hpi**(n-1) * ecm**(2*n-4)/(n-1)/gn1/gn1
387  end
388  subroutine cnbdc7(n, ecm, p, wmax)
389 ! compute max possible weig.p(4)
390  implicit none
391 !---- include '../Zptcl.h'
392 #include "Zptcl.h"
393  integer n
394  type(ptcl):: p(n)
395  real*8 ecm, wmax
396 
397  integer idx(2), nm, i
398  real*8 summ, en, beta
399 ! count massive ptcls
400  nm=0
401  do i=1,n
402  if(p(i)%mass .gt. 0.d0) then
403  nm=nm+1
404  if(nm .le. 2) then
405  idx(nm)=i
406  endif
407  endif
408  enddo
409  if(nm .eq. 1) then
410  wmax=(1. - p(idx(1))%mass/ecm)**(2*n-3)
411  elseif(nm .eq. 2) then
412  wmax=
413  * (1. + (p(idx(1))%mass/ecm)**2 -
414  * (p(idx(2))%mass/ecm)**2 )**2
415  * -4*(p(idx(1))%mass/ecm)**2
416  if(wmax .le. 0.d0)then
417  wmax=1.d-30
418  else
419  wmax= wmax**(n-1.5d0)
420  endif
421  else
422  summ=0.d0
423  do i=1, n
424  if(p(i)%mass .gt. 0.d0) then
425  en=p(i)%mass/ecm
426  summ=summ+en
427  endif
428  enddo
429  beta=1. - summ**2
430  if(beta .le. 0.d0) then
431  wmax=1.d-30
432  else
433  wmax=sqrt(beta)**(2*n+nm-5)
434  endif
435  endif
436  end
integer npitbl real *nx parameter(n=101, npitbl=46, nx=n-1) real *8 uconst
subroutine cnbdct(n, p)
Definition: cnbdcy.f:155
subroutine cnbdc4(n, p, mu, inm, gzai)
Definition: cnbdcy.f:321
subroutine cpxyzp(po, pabs)
Definition: cpxyzp.f:3
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 cnbdcy(n, ecm, p, jw, w, icon)
Definition: cnbdcy.f:48
subroutine rndc(u)
Definition: rnd.f:91
block data cblkEvhnp ! currently usable models data RegMdls ad *special data *Cekaon d0
Definition: cblkEvhnp.h:5
subroutine cnbdc7(n, ecm, p, wmax)
Definition: cnbdcy.f:389
subroutine cnbdc5(n, ecm, p, wx)
Definition: cnbdcy.f:348
dE dx *! Nuc Int sampling table d
Definition: cblkMuInt.h:130
subroutine cnbdcf(n, ecm, p,
Definition: cnbdcy.f:287
subroutine cnbdc6(n, ecm, w0)
Definition: cnbdcy.f:371
subroutine cnbdc3(n, ecm, p, mu, inm, gzai, icon)
Definition: cnbdcy.f:252
subroutine kcossn(cs, sn)
Definition: kcossn.f:13
subroutine cnbdc2(n, ecm, p)
Definition: cnbdcy.f:206
Definition: Zptcl.h:75
subroutine cnbdc1(n, p)
Definition: cnbdcy.f:177