COSMOS v7.655  COSMOSv7655
(AirShowerMC)
csampPrimary.f
Go to the documentation of this file.
1 ! *******************************************************
2 ! * csampPrimary: samples a primary particle; its type
3 ! * and energy
4 ! *******************************************************
5 ! Note: Here primary spectrum information is contained in common
6 ! variable Prim (done by init routine).
7 ! If we give it to csampPrimary0 we get
8 ! one sampled priamary of which energy etc is given in
9 ! variable in Prim. Only /ptcl/ information is returned
10 ! to the caller.
11 !
12  subroutine csampprimary(p, fin)
13 ! p: /ptcl/ output. energy, particle code, subcode,
14 ! charge, mass are set.
15 !
16 
17  implicit none
18 #include "Zmanagerp.h"
19 #include "Zptcl.h"
20 #include "Zprimary.h"
21 #include "Zprimaryv.h"
22 
23  type(ptcl):: p
24  integer fin ! output. if no more sim. -->1 else 0
25 
26 
27  fin = 0
28  if( desteventno(2) .lt. 0) then
29  if(abs(desteventno(2)) .le. prim%NoOfSamplings) then
30  fin = 1
31  endif
32  endif
33  if(fin .eq. 0) then
34  call csampprm0(prim)
35 
36 
37 ! call cconv_prim_e(Prim) ! to total energy
38  call cconv_prim_e(prim%each(prim%label), prim%sampled_e,
39  * prim%particle)
40  p = prim%particle
41  prim%NoOfSamplings = prim%NoOfSamplings + 1 ! update counter.
42  prim%NoOfSampComp(prim%label, 1) =
43  * prim%NoOfSampComp(prim%label, 1) +1
44  endif
45  end
46 ! **********************
47  subroutine cupdtprimc
48  implicit none
49 #include "Zptcl.h"
50 #include "Zprimary.h"
51 #include "Zprimaryv.h"
52 
53  prim%NoOfSampComp(prim%label, 2) =
54  * prim%NoOfSampComp(prim%label, 2) +1
55  end
56 
57 ! ************************************
58  subroutine csampprm0(prm)
59  implicit none
60 
61 #include "Zptcl.h"
62 #include "Zprimary.h"
63  type(primaries):: prm
64 
65  real*8 p_or_e
66 !
67  integer i
68  real*8 u
69 !
70 ! select one component
71  call rndc(u)
72 
73  i = 1
74  do while (u .gt. prm%cummInteFlux(i) )
75  i = i + 1
76  enddo
77  prm%label = prm%each(i)%label
78 !
79  call csampprm1(prm%each(prm%label), p_or_e)
80 
81 
82  prm%sampled_e = p_or_e
83  end
84  subroutine csampprm1(each, p_or_e)
85  implicit none
86 
87 #include "Zptcl.h"
88 #include "Zprimary.h"
89  type(component):: each
90  real*8 p_or_e
91 !
92  real*8 e1temp, ombeta, u
93  integer i
94 !
95  if( each%no_of_seg .eq. 0) then
96  p_or_e = each%emin ! = emax
97  else
98  call rndc(u)
99  i = each%no_of_seg
100  do while (u .gt. each%norm_inte(i))
101  i = i - 1
102  enddo
103 ! use i-th segment
104  if(each%diff_or_inte .eq. 'd') then
105  ombeta = (1.d0 - each%beta(i))
106  call rndc(u)
107  if(abs(ombeta) .gt. 1.d-6) then
108  e1temp = each%energy(i)**ombeta
109  p_or_e =( u* (each%energy(i+1)**ombeta - e1temp) +
110  * e1temp )** (1.d0/ombeta)
111  else
112  p_or_e =( each%energy(i)/each%energy(i+1) )**u
113  * * each%energy(i+1)
114  endif
115  elseif(each%diff_or_inte .eq. 'i') then
116  call rndc(u)
117  p_or_e = each%energy(i)* (1.d0 -
118  * u*(1.d0 - each%norm_inte(i+1)/each%norm_inte(i)))
119  * **(-1.d0/each%beta(i))
120  else
121  write(*, *) ' invlid diff_or_inte=',each%diff_or_inte,
122  * ' for primary=',each%symb
123  stop 9999
124  endif
125  endif
126  end
127  subroutine cconv_prim_e(comp, e_or_p, aPtcl)
128  implicit none
129 ! given energy or momentum as given in primary
130 ! specification is converted to total enregy.
131 
132 #include "Zptcl.h"
133 #include "Zcode.h"
134 #include "Zprimary.h"
135  type(component):: comp ! input. primary component
136  real*8 e_or_p ! input. energy or momentum as
137  ! specified in primary data file
138  type(ptcl)::aPtcl ! output. 'partcle' of the primary
139  integer code, massn
140 !
141  real*8 inGeV ! p_or_e in Gev
142  real(8),parameter::hbarc=197.0e6*1e-15/1.e-9 ! hbarc in eV nm
143  real(8),parameter::hc=hbarc*2*3.14159 ! hc/wl = eV
144 !
145  ingev= e_or_p * comp%togev
146  call cmkptc(comp%code,
147  * comp%subcode,
148  * comp%charge,
149  * aptcl)
150 
151  if(comp%code .eq. kmuon) then
152 ! give polarization for muon primary
153  call csetmuonpol(0.d0)
154  endif
155 
156  if(comp%etype .eq. 'e/p' .or.
157  * comp%etype .eq. 'e') then
158  aptcl%fm%p(4) = ingev
159  *
160  elseif(comp%etype .eq.'p/p' .or.
161  * comp%etype .eq. 'p')then
162  aptcl%fm%p(4) = sqrt(aptcl%mass**2 +
163  * ingev**2)
164  elseif(comp%etype .eq. 'ke/p' .or.
165  * comp%etype .eq. 'ke') then
166  aptcl%fm%p(4) = ingev + aptcl%mass
167  elseif(comp%etype .eq. 'e/n') then
168  code = comp%code
169  if(code .eq. kgnuc) then
170  aptcl%fm%p(4) = aptcl%subcode * ingev
171  elseif(code .ge. kalfa .and.
172  * code .le. khvymax) then
173  call cghvm(code, massn)
174  aptcl%fm%p(4) = massn * ingev
175  else
176  aptcl%fm%p(4) = ingev
177  endif
178  elseif(comp%etype .eq. 'ke/n') then
179  code = comp%code
180  if(code .eq. kgnuc) then
181  aptcl%fm%p(4) = aptcl%subcode * ingev +
182  * aptcl%mass
183  elseif(code .ge. kalfa .and.
184  * code .le. khvymax) then
185  call cghvm(code, massn)
186  aptcl%fm%p(4) = massn * ingev +
187  * aptcl%mass
188  else
189  aptcl%fm%p(4) = ingev +
190  * aptcl%mass
191  endif
192  elseif(comp%etype .eq. 'p/n') then
193  code = comp%code
194  if(code .eq. kgnuc) then
195  aptcl%fm%p(4) =
196  * sqrt( (aptcl%subcode * ingev) **2 +
197  * aptcl%mass **2)
198  elseif(code .ge. kalfa .and.
199  * code .le. khvymax) then
200  call cghvm(code, massn)
201  aptcl%fm%p(4) =
202  * sqrt( (massn * ingev) **2 +
203  * aptcl%mass **2)
204  else
205  aptcl%fm%p(4) = sqrt(ingev**2 +
206  * aptcl%mass**2)
207  endif
208  elseif(comp%etype .eq. 'rig') then
209  aptcl%fm%p(4) =sqrt(
210  * ( ingev*aptcl%charge)**2 + aptcl%mass**2 )
211  elseif(comp%etype == 'nm' ) then
212  if(comp%code /= klight ) then
213  write(0,*) ' nm unit can be used only for light'
214  stop
215  endif
216  aptcl%fm%p(4) = hc/e_or_p ! hc/wl --> eV
217  else
218  write(*, *) ' energy type=', comp%etype,
219  * ' invalid. label=', comp%label, ' symb =',
220  * comp%symb
221  stop 9999
222  endif
223  if(comp%code == klight .and. comp%etype /= 'nm' ) then
224  ! energy should be in eV so GeV to eV conversion
225  aptcl%fm%p(4) = aptcl%fm%p(4)*1.d9
226  endif
227  end
228 ! *******************************************************
229  subroutine cconv_prim_e2(comp, E, e_or_p)
230  implicit none
231 ! inverse of cconv_prim_e
232 
233 #include "Zptcl.h"
234 #include "Zcode.h"
235 #include "Zprimary.h"
236  type(component):: comp ! input. primary component
237  real*8 E ! input. total energy of a particle
238  ! of 'comp' primary
239  real*8 e_or_p ! output. e or p (/n, etc) as given
240  ! in primary paticle file.
241  integer code, massn
242 !
243  real*8 Ex ! e_or_p in GeV
244 
245  type(ptcl)::aPtcl
246 
247  call cmkptc(comp%code,
248  * comp%subcode,
249  * comp%charge,
250  * aptcl)
251 
252 
253  if(comp%etype .eq. 'e/p' .or.
254  * comp%etype .eq. 'e') then
255  ex = e
256  elseif(comp%etype .eq.'p/p' .or.
257  * comp%etype .eq. 'p')then
258  ex = sqrt(e**2 - aptcl%mass**2)
259 
260  elseif(comp%etype .eq. 'ke/p' .or.
261  * comp%etype .eq. 'ke') then
262  ex = e - aptcl%mass
263 
264  elseif(comp%etype .eq. 'e/n') then
265  code = comp%code
266  if(code .eq. kgnuc) then
267  ex = e/aptcl%subcode
268  elseif(code .ge. kalfa .and.
269  * code .le. khvymax) then
270  call cghvm(code, massn)
271  ex = e/massn
272  else
273  ex = e
274  endif
275  elseif(comp%etype .eq. 'ke/n') then
276  code = comp%code
277  if( code .eq. kgnuc ) then
278  ex =( e - aptcl%mass)/aptcl%subcode
279  elseif(code .ge. kalfa .and.
280  * code .le. khvymax) then
281  call cghvm(code, massn)
282  ex =( e - aptcl%mass)/massn
283  else
284  ex = e - aptcl%mass
285  endif
286  elseif(comp%etype .eq. 'p/n') then
287  code = comp%code
288  if( code .eq. kgnuc) then
289  ex =sqrt( e**2 - aptcl%mass **2)/aptcl%subcode
290  elseif(code .ge. kalfa .and.
291  * code .le. khvymax) then
292  call cghvm(code, massn)
293  ex =sqrt( e**2 - aptcl%mass **2)/massn
294  else
295  ex = sqrt(e**2 - aptcl%mass**2)
296  endif
297  elseif(comp%etype .eq. 'rig') then
298  ex = sqrt( e**2 - aptcl%mass**2) /aptcl%charge
299  else
300  write(*, *) ' energy type=', comp%etype,
301  * ' invalid. label=', comp%label, ' symb =',
302  * comp%symb
303  stop 9999
304  endif
305  e_or_p = ex/ comp%togev
306  end
307 ! *******************************************************
308 ! * cqPrimE: inquire sampled primary energy or p or rigidity
309 ! * as it is
310 ! *******************************************************
311 !
312  subroutine cqprime(p_or_e)
313 !
314  implicit none
315 
316 #include "Zptcl.h"
317 #include "Zprimary.h"
318 #include "Zprimaryv.h"
319  real*8 p_or_e
320  call cqprime0(prim, p_or_e)
321  end
322 ! *******************************************************
323 ! * cqPrimE0: inquire sampled primary energy or p or rigidity
324 ! * as it is
325 ! *******************************************************
326 !
327  subroutine cqprime0(prm, p_or_e)
328 !
329  implicit none
330 
331 #include "Zptcl.h"
332 #include "Zprimary.h"
333  real*8 p_or_e
334  type(primaries):: prm
335 !
336  p_or_e = prm%sampled_e
337 !
338  end
339 ! *******************************************************
340 ! * cqPrimLabel: inquire sampled primary label
341 
342 ! *******************************************************
343 !
344  subroutine cqprimlabel(label)
345 !
346  implicit none
347 
348 #include "Zptcl.h"
349 #include "Zprimary.h"
350 #include "Zprimaryv.h"
351  integer label
352  call cqprimlabel0(prim, label)
353  end
354 ! ************************ inquire the number of primaries sampled
355  subroutine cqnoofprim(no)
356 ! ************************
357  implicit none
358 #include "Zmanagerp.h"
359  integer no ! output. no. of sampled primaries so far.
360  no = eventno
361  end
362 
363 ! *******************************************************
364 !
365  subroutine cqprimlabel0(prm,label)
366 !
367  implicit none
368 #include "Zptcl.h"
369 #include "Zprimary.h"
370  integer label
371  type(primaries):: prm
372 
373  label = prm%label
374  end
375 ! *******************************************************
376 ! inquire all about current primaries
377  subroutine cqprimary(prm)
378 ! prm /primaires/ output.
379 !
380  implicit none
381 #include "Zptcl.h"
382 #include "Zprimary.h"
383 #include "Zprimaryv.h"
384 
385  type(primaries):: prm
386  prm = prim
387  end
388 
389 
subroutine cqprimlabel(label)
Definition: csampPrimary.f:345
subroutine csampprm1(each, p_or_e)
Definition: csampPrimary.f:85
dE dx *! Nuc Int sampling table e
Definition: cblkMuInt.h:130
subroutine csetmuonpol(val)
Definition: cinteNuc.f:224
max ptcl codes in the kgnuc
Definition: Zcode.h:2
subroutine cqnoofprim(no)
Definition: csampPrimary.f:356
subroutine cconv_prim_e2(comp, E, e_or_p)
Definition: csampPrimary.f:230
subroutine cqprimlabel0(prm, label)
Definition: csampPrimary.f:366
subroutine cconv_prim_e(comp, e_or_p, aPtcl)
Definition: csampPrimary.f:128
********************block data cblkHeavy ********************integer j data *HeavyG2symbol *data *HeavyG2code kalfa
Definition: cblkHeavy.h:7
subroutine rndc(u)
Definition: rnd.f:91
subroutine csampprm0(prm)
Definition: csampPrimary.f:59
block data cblkEvhnp ! currently usable models data RegMdls ad *special data *Cekaon d0
Definition: cblkEvhnp.h:5
subroutine cqprimary(prm)
Definition: csampPrimary.f:378
max ptcl codes in the klight
Definition: Zcode.h:2
dE dx *! Nuc Int sampling table d
Definition: cblkMuInt.h:130
subroutine cupdtprimc
Definition: csampPrimary.f:48
subroutine cmkptc(code, subcode, charge, p)
Definition: cmkptc.f:15
max ptcl codes in the khvymax
Definition: Zcode.h:2
subroutine cqprime(p_or_e)
Definition: csampPrimary.f:313
Definition: Zptcl.h:75
subroutine csampprimary(p, fin)
Definition: csampPrimary.f:13
subroutine cqprime0(prm, p_or_e)
Definition: csampPrimary.f:328
max ptcl codes in the kmuon
Definition: Zcode.h:2
subroutine cghvm(code, massn)
Definition: cmkptc.f:332