COSMOS v7.655  COSMOSv7655
(AirShowerMC)
smashSkel.f
Go to the documentation of this file.
1  implicit none
2 !
3 ! read skelton data and store each children as a complete
4 ! track so that each can be put to stack area as incidnet
5 ! particle.
6 ! smashed skeleton data format
7 ! Assume ncpu cpu's; For each cpu, smashed skeleton files will be
8 !
9 ! skeleton001
10 ! cumnum, num, ir, Zfirst
11 ! Np
12 ! observed ptcles 1
13 ! observed ptcles 2
14 !
15 ! observed ptcles Np
16 ! nlowp
17 ! track-1
18 ! track-2
19 ! ...
20 ! track-nlowp
21 ! other skeleton file( skeleton002,...)
22 ! cumnum, num, ir, Zfirst
23 ! 0
24 ! nlowp
25 ! track-1
26 ! track-2
27 ! ...
28 ! track-nlowp
29 ! ....
30 !
31 #include "Ztrack.h"
32 #include "Zearth.h"
33  include "../../SkelFlesh/Zprivate.h"
34  include "Zprivate2.h"
35 
36 
37  type(child):: cc
38  integer icon
39  integer klena
40  integer i, nlow, cumnum, num, ir(2)
41  type(track):: Zfirst
42  character*120 skelefile, outdir
43  character*100 basename
44  character*100 filename
45  character*100 input
46  character*100 hostlist
47  character*15 field(3)
48  integer n, j, k, nr, ll, kgetenv2
49 
50  hostlist = ' '
51 
52  ll = kgetenv2("NCPU", msg)
53  read( msg(1:ll), *) ncpu
54  ll = kgetenv2("SKELETON", msg)
55  skelefile=msg(1:ll)
56  ll = kgetenv2("SKELDIR", msg)
57  outdir = msg(1:ll)
58  ll = kgetenv2("SKELNAME", msg)
59  basename= msg(1:ll)
60  ll = kgetenv2("HOSTLIST", msg)
61  if(ll .gt. 0) hostlist = msg(1:ll)
62 ! binary open
63  call copenfw2(11, skelefile, 2, icon)
64  if(icon .ne. 1) then
65  write(msg,*) skelefile(1:klena(skelefile)),
66  * ' could not be opened properly'
67  call cerrormsg(msg, 0)
68  endif
69  write(msg,*) "# of cpu's=",ncpu
70  call cerrormsg(msg, 1)
71  if(ncpu .lt. 1 .or. ncpu .gt. maxcpu) then
72  call cerrormsg("# of cpu's > MaxCPU <1 ",0)
73  endif
74 
75 ! open output smashed skeleton files
76  k = klena(outdir)
77  if( outdir(k:k) .ne. '/') then
78  k = k + 1
79  outdir(k:k)= '/'
80  endif
81  write(msg, '(a,a)') 'output directory is ',
82  * outdir(1:k)
83  call cerrormsg(msg, 1)
84  write(msg,*) ncpu,
85  * ' files will be created there as '//
86  * basename(1:klena(basename))//'0001 etc'
87  call cerrormsg(msg, 1)
88 
89 !
90  if(hostlist .ne. ' ') then
91  call copenf(12, hostlist, icon)
92  if(icon .ne. 0 ) then
93  call cerrormsg(hostlist, 1)
94  call cerrormsg(' could not be opened', 0)
95  endif
96  do i = 1, ncpu
97  read(12, '(a)') input
98 ! input may be like: 1 hosta 2.5
99  field(1) = ' '
100  field(2) = ' '
101  field(3) = ' '
102  call ksplit(input, 30, 3, field, nr)
103  read(field(1), '(i5)' ) numba(i)
104  if(nr .le. 2) then
105  cpupw(i) = 1.0
106  else
107  read(field(3), * ) cpupw(i)
108  endif
109  enddo
110  close(12)
111  else
112  write(0,*) ' hostlist not given'
113  stop 1234
114  endif
115 
116  do i = 1, ncpu
117  write(filename,'(a,i4.4)')
118  * basename(1:klena(basename)), numba(i)
119  skelefile=outdir(1:klena(outdir))//filename
120  call copenfw2(basefn+i, skelefile, 2, icon)
121  if(icon .ne. 0) then
122  call cerrormsg(skelefile, 1)
123  call cerrormsg('could not be opened properly',1)
124  call cerrormsg('maybe they already exist', 0)
125  endif
126  enddo
127 
128 
129 ! ------------
130 
131 
132  do while(.true.)
133  read(11, end=100) cumnum, num, ir, zfirst
134  do i = 1, ncpu
135  write(basefn+i) cumnum, num, ir, zfirst
136  enddo
137 
138  read(11) np
139  call cerrormsg('------------', 1)
140  write(msg, *) np, ' ptcls are observed ones in skeleton'
141  call cerrormsg(msg, 1)
142  if(np .gt. maxob) then
143  call cerrormsg(
144  * 'It is too large; enlarge Maxob', 0)
145  endif
146 
147  do i = 1, np
148  read(11) oo(i)
149  enddo
150  nlow = 1
151  ctc=0
152  do while (nlow .ge. 0)
153  read(11) nlow, pp
154 ! nlow = 0, if pp.asflag=-1.
155  do i = 1, nlow
156  read(11) cc
157  if(ctc .lt. maxp) then
158  ctc = ctc + 1
159  call movetrack(cc, ct(ctc) )
160  else
161  call cerrormsg(
162  * 'too many particles in skeleton',1)
163  call cerrormsg(
164  * 'Enlarge Maxp in Zprivate2.h', 0)
165  endif
166  enddo
167  enddo
168 
169  write(msg,*)
170  * '# of total ptcls at flesh=',ctc
171  call cerrormsg(msg, 1)
172 
173 ! 1 event data is ready now in oo and ct.
174 ! distribute particles to ncpu
175 ! first sort ct by energy
176  call sortbyerg
177 ! deploy particles to Ncpu so that
178 ! sum energy on each cpu is roughly the same
179  if(ctc .lt. ncpu) then
180  n = ctc
181  write(msg, *) '# of ptcls < Ncpu; only ', ctc,
182  * ' cpu will be used for fleshing'
183  else
184  n = ncpu
185  endif
186 
187  call distribute( n )
188 
189 !
190  call memoforcpu( ncpu )
191 
192  call issuemsg( ncpu )
193 
194  enddo
195 
196  100 continue
197  call cerrormsg('all events have been smashed',1)
198  do i = 1, ncpu
199  close(basefn+i)
200  enddo
201 
202  end
203 ! ----------------------------
204  subroutine distribute( n )
205  implicit none
206 #include "Ztrack.h"
207  include "../../SkelFlesh/Zprivate.h"
208  include "Zprivate2.h"
209  integer i, k
210  integer n, j
211 
212  do i = 1, ncpu
213  sumergi(i)= 0.
214  sumergw(i) = 0.
215  noncpu(i) = 0
216  enddo
217  do i = 1, n
218 ! max energy ptcl for i-th cpu
219  sumergi(i) = erg(idx(i))
220  sumergw(i) = erg(idx(i)) / cpupw(i)
221  noncpu(i) = 1
222  idxlist(1, i) = idx(i)
223  idxlocal(i) = i
224  enddo
225 ! if all cpupw =1, next two not needed
226  call kqsortd(sumergw, idxlocal, n)
227  call ksortinv(idxlocal, n)
228 
229 !///////////
230 ! write(0,*) ' top E=',(sumergi(i), i=1, n)
231 ! write(0,*) ' idx=',(idx(i), i=1, n)
232 !////////
233 ! next explanation is for cpupw = 1
234 ! erg idx sumergi idxlocal nOnCpu idxlist
235 ! 1,1
236 ! 1 9 5 30 1 1 5
237 ! 2 1 3 18 2 1 3
238 ! n 3 18 7 15 3 1 7
239 ! 4 5 8
240 ! 5 30 1
241 ! 6 4 4
242 ! 7 15
243 ! 8 13
244 ! .
245 ! .
246 ! . 6
247 ! ctc . 2
248 !
249 ! after j= 4
250 ! sumergi idxlocal nOnCpu idxlist
251 ! 1 2
252 ! 30 1 1 5
253 ! 18 2 1 3
254 ! 28 3 2 7 8
255 ! after j=5
256 ! sumergi idxlocal nOnCpu idxlist
257 ! 1 2
258 ! 30 1 1 5
259 ! 27 3 2 3 1
260 ! 28 2 2 7 8
261 ! after j=6
262 ! sumergi idxlocal nOnCpu idxlist
263 ! 1 2 3
264 ! 30 1 1 5
265 ! 32 3 3 3 1 4
266 ! 28 2 2 7 8
267 !
268  do j = n+1, ctc
269  if(n .ge. 2) then
270  if( sumergw( idxlocal(n) ) .gt.
271  * sumergw( idxlocal(n-1) ) ) then
272  call kqsortd(sumergw, idxlocal, n)
273  call ksortinv(idxlocal, n)
274  endif
275  endif
276  k = idxlocal(n)
277  noncpu( k ) = noncpu( k ) + 1
278  if( noncpu( k ) .gt. maxptclpercpu ) then
279  write(msg, *)
280  * '# of ptcls on a cpu', k, ' exceeded limit=',
281  * maxptclpercpu
282  call cerrormsg(msg, 1)
283  call cerrormsg('Enlarge MaxPtclPerCpu in Zprivate2.h',0)
284  endif
285  idxlist( noncpu(k), k ) = idx(j)
286  sumergw(k) = sumergw(k) + erg(idx(j))/cpupw(k)
287  sumergi(k) = sumergi(k) + erg(idx(j))
288  enddo
289 
290  end
291 ! *************************
292  subroutine memoforcpu( n )
293  implicit none
294 #include "Ztrack.h"
295  include "../../SkelFlesh/Zprivate.h"
296  include "Zprivate2.h"
297 
298  integer n
299 
300  integer i, j
301 
302  do i = 1, n
303  if(i .eq. 1) then
304 ! for the first skeleton, put observed ptcls
305  write(basefn+i) np
306  do j = 1, np
307  write(basefn+1) oo(j)
308  enddo
309  else
310  write(basefn+i) 0
311  endif
312  write(basefn+i) noncpu(i)
313  do j = 1, noncpu(i)
314  write(basefn+i) ct( idxlist(j, i) )
315  enddo
316  enddo
317  end
318  subroutine issuemsg( n )
319  implicit none
320 #include "Ztrack.h"
321  include "../../SkelFlesh/Zprivate.h"
322  include "Zprivate2.h"
323 
324  integer n
325  integer i
326 
327  msg = ' cpu# cpuPW Sum E # of ptcls'
328 ! msg = 'cpu# Sum E # of ptcls'
329  call cerrormsg(msg, 1)
330  do i = 1, n
331  write(msg,'(i4, f7.1, g16.7, i9)')
332 ! write(msg,'(i3, g16.7, i9)')
333  * i, cpupw(i), sumergi(i), noncpu(i)
334 ! * i, sumergi(i), nOnCpu(i)
335  call cerrormsg(msg, 1)
336  enddo
337  end
338 
339 
340  subroutine sortbyerg
341  implicit none
342 #include "Ztrack.h"
343  include "../../SkelFlesh/Zprivate.h"
344  include "Zprivate2.h"
345 
346  integer i
347 
348  averg = 0.
349  do i = 1, ctc
350  erg(i) = ct(i).p.fm.p(4)
351  averg = averg + erg(i)
352  enddo
353  call kqsortd(erg, idx, ctc)
354 ! high to low
355  call ksortinv(idx, ctc)
356  if(ctc .gt. 0.) then
357 ! average total energy on 1 cpu
358  averg = averg/ctc * ncpu
359  else
360  call cerrormsg('no need to flesh; no child',0)
361  endif
362  if( erg(idx(ctc) ) .gt. averg*1.1 ) then
363 ! max energy is too large. issue
364 ! warning
365  write(msg,*) 'WARGNING: max E=', erg(idx(i)),
366  * ' is > average total energy for 1 cpu=',
367  * averg
368  call cerrormsg(msg, 1)
369  endif
370  end
371 
372 
373 
374  subroutine movetrack(f, t)
375  implicit none
376 #include "Ztrack.h"
377 #include "Zearth.h"
378  include "../../SkelFlesh/Zprivate.h"
379  include "Zprivate2.h"
380 
381  type(child):: f
382  type(track):: t
383 
384  t.p.code = f.code
385  t.p.subcode = f.subcode
386  t.p.charge = f.charge
387  t.p.fm.p(1) = f.fm(1)
388  t.p.fm.p(2) = f.fm(2)
389  t.p.fm.p(3) = f.fm(3)
390  t.p.fm.p(4) = f.fm(4)
391  t.p.mass = f.mass
392  t.pos.xyz.r(1) = pp.posx
393  t.pos.xyz.r(2) = pp.posy
394  t.pos.xyz.r(3) = pp.posz
395 
396  t.pos.depth = pp.depth
397  t.pos.height = pp.height
398  t.pos.colheight = pp.colheight
399  t.t = pp.atime
400  t.where = pp.where
401  t.pos.radiallen =
402  * eradius + pp.height
403  t.pos.xyz.sys = 'xyz'
404  t.vec.w.sys = 'xyz'
405  t.wgt = 1.0
406  t.asflag = 0
407 
408  call cresetdirec( t )
409  end
410 
411 
subroutine ksplit(a, m, n, b, nr)
Definition: ksplit.f:2
*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 issuemsg(n)
Definition: smashSkel.f:503
integer function kgetenv2(envname, envresult)
Definition: cgetLoginN.f:77
*Zfirst p fm *Zfirst p Zfirst p Zfirst p *Zfirst p *Zfirst pos xyz Zfirst pos xyz *Zfirst pos *Zfirst pos Zfirst pos *Zfirst pos colheight
Definition: ZavoidUnionMap.h:1
*Zfirst p fm *Zfirst p Zfirst p Zfirst p *Zfirst p *Zfirst pos xyz r
Definition: ZavoidUnionMap.h:1
nodes i
subroutine movetrack(f, t)
Definition: smashSkel.f:560
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
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
averg real * sumergi(MaxCPU)
*Zfirst p fm *Zfirst p Zfirst p Zfirst p *Zfirst p *Zfirst pos xyz Zfirst pos xyz sys
Definition: ZavoidUnionMap.h:1
averg real MaxCPU integer idx(Maxp)
subroutine cresetdirec(aTrack)
Definition: cresetDirec.f:5
********************block data cblkHeavy ********************integer j data *HeavyG2symbol p
Definition: cblkHeavy.h:7
subroutine copenfw2(io, fnin, form, icon)
Definition: copenf.f:205
subroutine kqsortd(A, ORD, N)
Definition: kqsortd.f:23
*Zfirst p fm *Zfirst p Zfirst p Zfirst p *Zfirst p *Zfirst pos xyz Zfirst pos xyz *Zfirst pos *Zfirst pos Zfirst pos *Zfirst pos *Zfirst Zfirst vec w *Zfirst vec w Zfirst vec *Zfirst Zfirst Zfirst asflag
Definition: ZavoidUnionMap.h:1
*Zfirst p fm *Zfirst p Zfirst p code
Definition: ZavoidUnionMap.h:1
subroutine ksortinv(idx, n)
Definition: ksortinv.f:2
averg real sumergw(MaxCPU)
subroutine distribute(n)
Definition: smashSkel.f:315
subroutine copenf(io, fnin, icon)
Definition: copenf.f:8
subroutine sortbyerg
Definition: smashSkel.f:525
averg real MaxCPU integer idxlocal(MaxCPU) integer numba(MaxCPU) integer ctc
*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
float erg[maxp]
Definition: Zprivate.h:7
*Zfirst p fm *Zfirst p Zfirst p Zfirst p *Zfirst p charge
Definition: ZavoidUnionMap.h:1
integer function klena(cha)
Definition: klena.f:20
Definition: Zprivate.h:25
!onst int maxp
Definition: Zprivate.h:3
*Zfirst p fm *Zfirst p mass
Definition: ZavoidUnionMap.h:1
averg real cpupw(MaxCPU) integer nOnCpu(MaxCPU) integer idxlist(MaxPtclPerCpu
subroutine memoforcpu(n)
Definition: smashSkel.f:403
integer n
Definition: Zcinippxc.h:1
*Zfirst p fm *Zfirst p Zfirst p Zfirst p *Zfirst p *Zfirst pos xyz Zfirst pos xyz *Zfirst pos *Zfirst pos Zfirst pos *Zfirst pos *Zfirst Zfirst vec w *Zfirst vec w Zfirst vec *Zfirst wgt
Definition: ZavoidUnionMap.h:1
*Zfirst p fm *Zfirst p Zfirst p Zfirst p subcode
Definition: ZavoidUnionMap.h:1
*Zfirst p fm *Zfirst p Zfirst p Zfirst p *Zfirst p *Zfirst pos xyz Zfirst pos xyz *Zfirst pos radiallen
Definition: ZavoidUnionMap.h:1