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

Go to the source code of this file.

Functions/Subroutines

subroutine xbgrun
 

Function/Subroutine Documentation

◆ xbgrun()

subroutine xbgrun ( )

Definition at line 10 of file interface.f.

References cdedxinair(), cerrormsg(), charge, cmudedx(), copenfw2(), cqincident(), csortstack(), d, d0, depth, e, false, height, kelec, kmuon, kphoton, mass, ne, ng, nmu, p, subcode, t, true, x, xyz, and y.

Referenced by chookbgrun().

10  implicit none
11 #include "Zmaxdef.h"
12 #include "Zmanagerp.h"
13 #include "Ztrack.h"
14 #include "Ztrackv.h"
15 #include "Ztrackp.h"
16 #include "Zcode.h"
17 #include "Zheavyp.h"
18 #include "Zobs.h"
19 #include "Zobsp.h"
20 #include "Zobsv.h"
21 #include "Zstackv.h"
22 #include "Zincidentv.h"
23 
24 #include "Zprivate.f"
25 #ifdef USEHISTO
26 #include "Zprivate1.f"
27 #include "Zprivate2.f"
28 #include "Zprivate3.f"
29  save rspec, lossrspec, arspec, respec
30  save rzspec, zfspec, rtspec1, rtspec2, retspec1, retspec2
31  save rezspec, rzfspec, rfspec, efspec, refspec
32 #endif
33 
34  type(track):: incident
35  type(coord):: angleatobs
36 
37  logical heobs ! if T, currently observing
38  common /zheobs/ heobs ! particle is the one obsrved at skeelton making time
39 
40 
41 
42 
43  integer id ! input. 1 ==> aTrack is going out from
44 ! outer boundery.
45 ! 2 ==> reached at an observation level
46 ! 3 ==> reached at inner boundery.
47  type(track):: atrack
48 
49  type(track):: inci
50  type(coord):: angle
51  type(coord):: tetafai
52 
53  character*128 input
54  character*64 dirstr
55  real sr, dr
56  integer i, j, k, icon, ir, l
57  integer nn
58  integer iij, code, codex
59  integer i1, i2, ic
60 
61  real*8 r, eloss, rinmu, cosang
62  real*8 dedt, rho, dist, disto, dedxmu
63  real*8 fai, rminm
64 
65  real*8 u
66  logical accept
67  real*8 wx, wy, wz, temp
68  real za
69  real de, ek, f, molu
70  real*8 cvh2den
71  integer ldep, ridx, faiidx
72  integer lengenv
73  integer ncpu ! # of smashed skeletons
74  integer mcpu ! and skeletons to be used actully
75  integer margin ! # of additional skeletons fleshed for safety
76  real*4 enhance ! since we use only mcpu, the result must be enhanced
77  ! by a factor of ncpu/mcpu
78  integer binw
79  character*9 ptcl(4)
80  data ptcl/"Photons", "Electrons","Muons", "hadrons"/
81  character*9 ptcl2(3)
82  data ptcl2/"Electrons", "Muons","All"/
83  real power(3)
84  integer nstr
85  real e0, cosz, limit, limite
86  data power/2.,2.,1./
87  real power2(3)
88  data power2/2.,1.,2./
89  character*128 title
90  character*96 evid(nsites)
91  real*8 cog, cog2, sumne, obstimes, savederg(5)
92  real*8 firstz, dd
93  logical dosort
94  character*2 kd(3)
95  integer kgetenv2
96  integer leng, lengn, lengid
97  character*5 numb
98  character*64 execid
99  character*128 msg
100 
101  save
102 
103 #ifdef USEHISTO
104 #include "interfaceHBGR.f"
105 #endif
106 ! used only if enhace >1; but the value may be different
107  limit = 20000
108  lengenv = kgetenv2("NCPU", input)
109  read(input(1:lengenv),*) ncpu
110  lengenv = kgetenv2("MCPU", input)
111  read(input(1:lengenv),*) mcpu
112  lengenv = kgetenv2("MARGIN", input)
113  read(input(1:lengenv),*) margin
114  enhance = ncpu
115  enhance = enhance/mcpu
116  limite = limit * enhance ! this must be enhanced from the first.
117  write(0,*) ' *** ncpu=',ncpu,
118  * ' mcpu=',mcpu, ' enhance factor=',enhance
119  write(0,*) ' margin=',margin
120  input = ' '
121  lengn = kgetenv2("NUMB", numb)
122  leng = kgetenv2("OUTDIR", input)
123  lengid = kgetenv2("EXECID", execid)
124 
125  if(observeas) then
126  msg =input(1:leng)//"/"//execid(1:lengid)//
127  * "-@."//numb(1:lengn)//".hyb"
128  call copenfw2(fnob, msg, 1, icon)
129  if(icon .gt. 1) then
130  write(0,*) ' icon=', icon
131  call cerrormsg(msg, 1)
132  call cerrormsg('could not be opened', 0)
133  endif
134  endif
135  return
136 ! *********************************** hook for Beginning of 1 event
137 ! * All system-level initialization for 1 event generation has been
138 ! * eneded at this moment.
139 ! * After this is executed, event generation starts.
140 ! *
141  entry xbgevent
142 
143  obstimes = 0.
144  call cqincident(inci, angle)
145 
146  cosz = -angle.r(3)
147  e0 = inci.p.fm.p(4)
148  if(inci.p.code .eq. 9) then
149  nn= inci.p.subcode
150  elseif(inci.p.code .eq. 1) then
151  nn=0
152  else
153  nn=1
154  endif
155 ! next is only available for parallel job. For normal job,
156 ! fisrt col.depth is not yet fixed.
157  firstz= zfirst.pos.depth*0.1
158  write(0,'(a,1pE11.3,a,E11.3,a,E11.3,a)')
159  * ' E0=',e0, ' cosz=',cosz, ' firstz=',
160  * firstz, ' g/cm2'
161 !
162  do i = 1, noofassites
163  sumeloss(i) = 0.
164  ng(i) = 0.
165  ne(i) = 0.
166  nmu(i) = 0.
167  nhad(i) = 0.
168  enddo
169 #ifdef USEHISTO
170 #include "interfaceHBGE.f"
171 #endif
172  return
173 ! ***************
174  entry xobs(atrack, id)
175 !
176 ! For id =2, you need not output the z value, because it is always
177 ! 0 (within the computational accuracy).
178 !
179 ! **************************
180 ! to be able to see the job is really running (i.e, no loop)
181 ! we write messages every 500000 calls.
182 !
183  obstimes = obstimes + 1.d0
184  if(mod(obstimes, 500000.d0) .eq. 0. ) then
185  dosort=.false.
186  do i = 1, min(4,stack_pos)
187  if(stack(i).p.fm.p(4) .ne. savederg(i)) then
188  savederg(i)=stack(i).p.fm.p(4)
189  dosort=.true.
190  endif
191  enddo
192  if(dosort) then
193  call csortstack
194  endif
195  write(0, *) ' obstimes=', obstimes, ' ptclE=',atrack.p.fm.p(4)
196  do i = 1, min(4,stack_pos)
197  write(0,*)' stack tops=', stack(i).p.fm.p(4)
198  enddo
199  endif
200 ! ***************
201  code = atrack.p.code
202  if(id .eq. 2 .and. code .le. 6 ) then
203  codex=min(code, 4)
204  wz = atrack.vec.w.r(3) ! downgoing < 0
205  if(wz .gt. 0) return
206  wz = -wz
207  ldep = atrack.where
208 
209  if(code .eq. kphoton) then
210  ng(ldep) = ng(ldep) + enhance
211  elseif(code .eq. kelec) then
212  ne(ldep) = ne(ldep) + enhance
213  elseif(code .eq. kmuon) then
214  nmu(ldep) = nmu(ldep) + enhance
215  else
216  nhad(ldep)=nhad(ldep) + enhance
217  endif
218 
219  ek = atrack.p.fm.p(4) -atrack.p.mass
220 
221 ! ---------- compute energy loss rate
222  if(atrack.p.charge .ne. 0 ) then
223  rho = cvh2den(atrack.pos.height)
224 ! get energy loss when aTrack goes 1 g/cm2 along the
225 ! primary direction. Gramage the particle can run is
226 ! 1/cos where cos is the cos of angle relative to the
227 ! primary angle . 1g/cm^2 = 10-3kg/10-4 m^2 =10 kg/m^2.
228 ! To travel 1 g/cm^2 along shower axis, the ptcl must
229 ! run dist kg/m^2
230  if(abs(wz) .gt. 1.d-2) then
231  dist =10./wz ! in kg/m2/(g/cm2)
232  else
233 ! for safety
234  dist =1000.
235  endif
236  if( heobs ) then
237 ! the ptcls is the one obsrved at skeleton making time
238 ! we must compute dedt here
239  call cdedxinair(atrack.p, rho, dedt) ! dedt; GeV/(kg/m2)
240  if(atrack.p.code .eq. kmuon ) then
241 ! dE/dx due to muon pair, brem, nuc.i
242  call cmudedx(muni, mubr, mupr, atrack.p.fm.p(4),
243  * dedxmu) ! dedxmu in GeV/(g/cm2)
244  dedxmu = dedxmu /10. ! GeV/(kg/m2)
245  dedt = dedt + dedxmu
246  endif
247  else
248 ! we can use already computed one
249  call cqelossrate(dedt) ! loss rate GeV/(kg/m^2)
250  endif
251 ! energy loss rate
252  eloss = dedt*dist*enhance ! GeV/(g/cm2)
253 
254  sumeloss(ldep)=sumeloss(ldep) + eloss
255  else
256  eloss=0.
257  endif
258  if(atrack.where .eq. 6) then
259  write(*,
260  * '(4i3, 1p4E11.3, 0p, 2f8.4,f10.6)')
261  * ldep, code, atrack.p.subcode, atrack.p.charge,
262  * ek, atrack.t,
263  * atrack.pos.xyz.x, atrack.pos.xyz.y,
264  * -atrack.vec.w.r(1), -atrack.vec.w.r(2), wz
265  endif
266  endif
267 #ifdef USEHISTO
268 #include "interfaceHOBS.f"
269 #endif
270  return
271 ! **************
272  entry xenevent
273 ! **************
274  firstz= zfirst.pos.depth*0.1
275  if(observeas) then
276  cog = 0.
277  sumne = 0.
278 
279  do i = 1, noofassites
280  asobssites(i).esize = asobssites(i).esize* enhance
281  if(i .gt. 1 .and. i .lt. noofassites ) then
282  dd =(asdepthlist(i+1) - asdepthlist(i-1))/2.0
283  elseif(i .eq. 1) then
284  dd =(asdepthlist(2) - asdepthlist(1))
285  else
286  dd =(asdepthlist(noofassites) -
287  * asdepthlist(noofassites-1))
288  endif
289  cog = cog + asobssites(i).esize*dd*asdepthlist(i)
290  sumne= sumne +asobssites(i).esize*dd
291  enddo
292 ! 0.1 is for g/cm2
293  cog = cog*0.1/sumne
294  cog2 = 0.
295  sumne = 0.
296  do i = 1, noofassites
297  if( asobssites(i).age .gt.
298  * (2.0-asobssites(noofassites).age)) then
299  if(i .gt. 1 .and. i .lt. noofassites ) then
300  dd =( asdepthlist(i+1) - asdepthlist(i-1))/2.0
301  elseif(i .eq. 1) then
302  dd =(asdepthlist(2) - asdepthlist(1))
303  else
304  dd =(asdepthlist(noofassites) -
305  * asdepthlist(noofassites-1))
306  endif
307  dd = dd
308  cog2 = cog2 + asobssites(i).esize*asdepthlist(i)*dd
309  sumne= sumne +asobssites(i).esize*dd
310  endif
311  enddo
312  if(sumne .gt. 0.) then
313  cog2 = cog2*0.1/sumne
314  else
315 ! too deep penetration
316  cog2 = asdepthlist(noofassites)*0.1
317  endif
318 
319  if(fnob .ge. 0 ) then
320  write(fnob,
321  * '("h ", i4, 3i3, 1pE11.3, 0p 3f11.7, f7.2, 2f7.0)')
322  * eventno, inci.p.code,
323  * inci.p.subcode, inci.p.charge,
324  * inci.p.fm.e, -angle.r(1), -angle.r(2), -angle.r(3),
325  * firstz, cog, cog2
326  endif
327  do i = 1, noofassites
328  if(fnob .ge. 0) then
329  write(fnob, '("t ", i3, 2f7.1, 2f6.3,
330  * 1p6E11.3)')
331  * i,
332  * asdepthlist(i)*0.1, asobssites(i).mu,
333  * asobssites(i).age, asdepthlist(i)*0.1/cog2,
334  * ng(i), ne(i), nmu(i), nhad(i),
335  * asobssites(i).esize, sumeloss(i)
336  endif
337  enddo
338  if(fnob .gt. 0 ) then
339  write(fnob,*)
340  endif
341  endif
342 #ifdef USEHISTO
343 #include "interfaceHENE.f"
344 #endif
*Zfirst p fm *Zfirst p Zfirst p Zfirst p *Zfirst p *Zfirst pos xyz Zfirst pos xyz *Zfirst pos *Zfirst pos depth
Definition: ZavoidUnionMap.h:1
subroutine cerrormsg(msg, needrtn)
Definition: cerrorMsg.f:4
subroutine cqincident(incident, AngleAtObs)
Definition: cmkIncident.f:486
integer function kgetenv2(envname, envresult)
Definition: cgetLoginN.f:77
dE dx *! Nuc Int sampling table e
Definition: cblkMuInt.h:130
others if is ng
Definition: cblkManager.h:9
*Zfirst p fm *Zfirst p Zfirst p Zfirst p *Zfirst p *Zfirst pos xyz r
Definition: ZavoidUnionMap.h:1
nodes i
integer lengn
Definition: interface2.h:1
const int kphoton
Definition: Zcode.h:6
latitude latitude this system is used *****************************************************************! type coord sequence union map real z z in m endmap xyz map real ! latitude in deg is to the north ! longitude in deg is to the east *h ! height in m endmap llh map real ! polar angle ! azimuthal angle *radius ! radial distance endmap sph endunion character *sys ! which system xyz
Definition: Zcoord.h:25
Definition: Ztrack.h:44
int nmu[nl][nth]
Definition: Zprivate.h:12
subroutine cmudedx(flagN, flagBr, flagPr, Emu, dEdx, dEdxF)
Definition: cmudEdx.f:2
max ptcl codes in the kelec
Definition: Zcode.h:2
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
integer leng
Definition: interface2.h:1
int ne[nl][nth]
Definition: Zprivate.h:11
********************block data cblkHeavy ********************integer j data *HeavyG2symbol p
Definition: cblkHeavy.h:7
********************block data cblkHeavy ********************integer j data *HeavyG2symbol *data *HeavyG2code kiron data j
Definition: cblkHeavy.h:36
subroutine copenfw2(io, fnin, form, icon)
Definition: copenf.f:205
real(4), dimension(:), allocatable, save temp
Definition: cNRLAtmos.f:29
subroutine cdedxinair(aPtcl, rhoin, dedt, dedtF)
Definition: cdedxInAir.f:49
*Zfirst p fm *Zfirst p Zfirst p code
Definition: ZavoidUnionMap.h:1
block data cblkEvhnp ! currently usable models data RegMdls ad *special data *Cekaon d0
Definition: cblkEvhnp.h:5
*Zfirst p fm *Zfirst p Zfirst p Zfirst p *Zfirst p *Zfirst pos xyz Zfirst pos xyz *Zfirst pos *Zfirst pos Zfirst pos height
Definition: ZavoidUnionMap.h:1
latitude latitude this system is used *****************************************************************! type coord sequence union map real y
Definition: Zcoord.h:25
dE dx *! Nuc Int sampling table d
Definition: cblkMuInt.h:130
real *8 function cvh2den(z)
Definition: ciniSegAtoms.f:54
*Zfirst p fm *Zfirst p Zfirst p Zfirst p *Zfirst p charge
Definition: ZavoidUnionMap.h:1
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 ! knockon is considered Obsolete *PhotoProd false
Definition: cblkElemag.h:7
subroutine csortstack
Definition: cstack.f:102
nodes t
Definition: Zptcl.h:75
Definition: Zcoord.h:43
*Zfirst p fm *Zfirst p mass
Definition: ZavoidUnionMap.h:1
max ptcl codes in the kmuon
Definition: Zcode.h:2
! 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
*Zfirst p fm *Zfirst p Zfirst p Zfirst p subcode
Definition: ZavoidUnionMap.h:1
dE dx *! Nuc Int sampling table f
Definition: cblkMuInt.h:130
Here is the call graph for this function:
Here is the caller graph for this function: