COSMOS v7.655  COSMOSv7655
(AirShowerMC)
cbeginRun.f
Go to the documentation of this file.
1 ! Initialize simulation.
2 #if defined (KEKB) || defined (KEKA)
3 #define DOMPI
4 #endif
5 !
6  subroutine cbeginrun
7  implicit none
8 #include "Zmanagerp.h"
9 #include "Zmanager.h"
10 #include "Zelemagp.h"
11 #include "Zevhnp.h"
12 #include "Ztrack.h"
13 #include "Ztrackv.h"
14 #include "Ztrackp.h"
15 #include "Zincidentp.h"
16 #include "Zprimary.h"
17 #include "Zprimaryv.h"
18 #include "Zcondc.h"
19 #include "Zobs.h"
20 #include "Zobsp.h"
21 #if defined (DOMPI)
22 #include "mpif.h"
23 #include "Zmpi.h"
24  integer intdata
25 #endif
26  character*16 temp
27  integer jold, icon
28  real*8 s1
29 !!!!!!!!!!!!
30 ! after reading input namleist parameter, program flow
31 ! comes here. the work dependent on LatObsSite and
32 ! LongitObsSite must not be done before ciniAtmos,
33 ! if the NRL atmosphere model is to be used by specifing
34 ! AtmosFile="...." in which case, (lat, long) is given
35 ! in that file. So (lat,long) pair is forced to replace
36 ! LatitOfSite and LongitObsSite values.
37 
38  if(cont) then
39 ! restore status at the end of previous run
40  call crestorestatus
41  cont =.true.
42  elseif(job .eq. 'flesh' .or. job .eq. 'newflesh') then
43  temp = job
44  call cgetskelfile
45  job = temp ! keet as now
46  elseif(job .eq. 'skeleton' .or. job .eq. 'newskel' ) then
47 ! to be safe, parameters are written in a file first and read
48 ! again ; this will avoid the possible difference of internal
49 ! parameter values read from original param and SkeletonParam
50 !
51 #ifndef DOMPI
52  temp = job
53  call copennlfw(tempdev, skeletonfile, icon)
54  if(icon .ne. 0) then
55  call cerrormsg(skeletonfile, 1)
56  call cerrormsg('File shown above cannot be opened',0)
57  endif
58 ! at flesh time, you don't need to rewrite Job
59  if(job .eq. 'newskel') then
60  job = 'newflesh'
61  else
62  job = 'flesh'
63  endif
64  call cwriteparam(tempdev, 1)
65  close(tempdev)
66 ! macIFC/MACOSX cannot put correct namelist char data
67 ! (' is missing) so cannot read SkeletonFile
68 ! avoid read it. the user must do the equiv. by hand
69 ! call copenNLf(TempDev, SkeletonFile, icon)
70 ! call creadParam(TempDev)
71 ! close(TempDev)
72 ! restore Job
73  job = temp
74 #endif
75  endif
76 ! reset parameters
77  if(borderheighth .eq. 0.0) then
78  borderheighth = heightofinj + 1.0d0 ! from v6.10
79  endif
80 
81  eventsintherun = 0 ! moved from ciniTracking0. 2001.09/30
82 
83  if(desteventno(2) .eq. 0) then
84  desteventno(2) = desteventno(1)
85  elseif(desteventno(1) .lt. 0) then
86  desteventno(2) = -abs(desteventno(2))
87  endif
88 
89 ! to lower case letters.
90  temp = generate
91  call c2lowercase(temp, generate)
92  temp = job
93  call c2lowercase(temp, job)
94 
95  call rndsw(jold, 1) ! specify random number generator 1.
96 
97 ! Now (v7.651) next random number init is placed before cixsec
98 ! otherwise qgsjetII-03 generates the same event every run,
99 ! (ciniRN was placed inside cwhatJob bef. v7.651)
100  call cinirn
101 
102 ! set Target and do related xsec business; moved before
103 ! cintModels (for qgsjet dummy ptcl generation in cQGSini)
104  call cixsec
105  call chowmcs ! MCSmodel is analysed ...
106  call cinimcs ! init for MCS and set doNewMCS (t/f)
107 
108 ! cintModels probably reads disk file(s) internally,
109 ! we may better to avoid simultaneous access to that disk
110 ! by different ranks; reading starts from rank0, rank1...
111 #if defined DOMPI
112  if(mpirank .eq. 0) then
113  call cintmodels('cosmos') ! analysis of interaction models and init.
114  if(mpisize .gt. 1) then
115  call mpi_send(mpirank, 1, mpi_integer, 1, 1,
116  * mpi_comm_world, mpierr)
117  endif
118  else
119  call mpi_recv(intdata, 1, mpi_integer, mpirank-1, 1,
120  * mpi_comm_world, mpistat, mpierr)
121  call cintmodels('cosmos') ! analysis of interaction models and init.
122  if( mpirank .lt. mpisize-1 ) then
123  call mpi_send(mpirank, 1, mpi_integer, mpirank+1, 1,
124  * mpi_comm_world, mpierr)
125  endif
126  endif
127 #else
128  call cintmodels('cosmos') ! analysis of interaction models and init.
129 #endif
130  ! init for Atmosphere
131  call ciniatmos
132 
133 ! init for geomag
134  call crdgeomag(geomagfile, yearofgeomag)
135 ! init for LPM effect energy sampling.
136  s1 = (targetatomicn**(1./3.d0)/183.d0)**2
137  call csetlpmcnst(s1, log(s1), 1.d-4, x0)
138 ! initialize observation
139  call cinitobs
140 ! init for primary sampling
141  call cinisprim(primaryfile)
142 
143  if(cutofffile .ne. ' ') then
144  call crigcut0(cutofffile) ! read cutoff talbe and init.
145  endif
146 ! init for muon interaction routines; specific for Air.
147  call crdmutab ! set various consts for mu int.
148  call csetmu(targetatomicn, targetmassn)
149  fromepics = .false. ! muon interaction routines for Air are
150  ! inside Cosmos
151  call cinisprimang ! this is in csPrimaAgn.f in Tracking dir.
152 ! check job
153  call cwhatjob
154 ! this is moved here; before v6.10 it was before cwhatJob
155  call cinitracking0 ! init for tracking for all events
156 ! init for knockon process; Knockon below is not used now.
157  if(knockonratio .lt. 1.d0) then
158 ! ********* Knockon is not used now ******
159  if(job .eq. 'newskel') then
160  call cdedxeleci(keminobs(1)*knockonratio, knockon)
161  elseif(keminobs2(1)*knockonratio .gt. 0.) then
162 ! this must come after cwhatJob, since KEminObs2 must
163 ! be fixed. For skeleton-flesh job, KnockOnRatio should be
164 ! small enough so that KEminObs2*KnockOnRatio < KEminObs at
165 ! flesh time
166 
167  call cdedxeleci(keminobs2(1)*knockonratio, knockon)
168  else
169  call cerrormsg('KnockOnRatio<1 and others mismatch', 0)
170  endif
171  else
172 !!! call cdedxEleci(RecoilKineMinE, Knockon) replaced by next few lines
173 !! v7.643
174  if( knockonratio == 1.0d0 .or. recoilkinemine == 0.) then
175  recoilkinemine= keminobs(1)
176  endif
177  call cdedxeleci(recoilkinemine, knockon)
178  endif
179 ! user hook
180  call chookbgrun
181 
182  end
183 
184  subroutine cinitracking0
185  implicit none
186 #include "Zmanager.h"
187 #include "Zmanagerp.h"
188 #include "Zevhnp.h"
189 #include "Ztrack.h"
190 #include "Ztrackv.h"
191 #include "Ztrackp.h"
192 #include "Zprimary.h"
193 #include "Zprimaryv.h"
194 #include "Zobs.h"
195 #include "Zobsv.h"
196 #include "Zincidentp.h"
197 #include "Zheavyv.h"
198 
199 !
200 
201  integer i
202  real*8 dstep
203 !
204 !
205 !
206  observeas = index(generate, 'as') .gt. 0 .or.
207  * index(generate, 'lat') .gt. 0
208  if(index(generate, 'qas') .gt. 0) then
209  skipptclgen = 1 ! quick as generation for heavies.
210  else
211  skipptclgen = 0
212  endif
213 
214 !
215 ! d = min( dZ/2, geneal min) for e+/e- other charged.
216 ! general min = same as so far for e+/e-, p, heavy
217 ! mu, pi, K, --> dE/Ek< 1%; dE=Ek/100.
218 ! min=Ek/100/2e-3 g/cm2 = Ek/10/2e-3 kg/m2
219 ! =Ek/2e-2= 50Ek
220 ! Ek=1 -->50 kg/m2 = 5g/cm2 ~5000cm ~50m
221 ! Ek=0.1-->5 kg/m2=0.5g/cm2 ~ 5m
222 ! 0.01-->0.05kg/m2=0.05g/cm2 ~ 0.5m
223 ! 0.001--> 0.5m
224 !
225 ! ////////
226  do i = 1, noofsites
227  if( i .eq. 1) then
228  dstep = obssites(1)%pos%depth
229  else
230  dstep = obssites(i)%pos%depth - obssites(i-1)%pos%depth
231  endif
232  if(dstep .lt. 15. ) then
233  stepcontrol=2
234  else
235  stepcontrol = dstep/25.0
236  endif
237  maxstep(i) = dstep/stepcontrol
238  enddo
239 ! added v7.651
240  maxstep(0) = maxstep(1)
241  maxstep(noofsites+1) = maxstep(noofsites)
242 
243 ! compute the offset point in 'xyz' system
244 ! the deepest detector origin + Offset is the point
245 ! to which the primary is directed.
246 ! offset in the detector system.
247  offset%r(1) = 0.
248  offset%r(2) = 0.
249  offset%r(3) = offsetheight
250 ! convert it to xyz system.
251  call cdet2xyz(obssites(noofsites)%pos%xyz, offset, offset)
252 ! make it offset
253  do i= 1, 3
254  offset%r(i) = offset%r(i) -
255  * obssites(noofsites)%pos%xyz%r(i)
256  enddo
257 
258  if(eabsorb(1) .ne. 0) then
259  if(eabsorb(2) .le. 0) then
260  eabsorb(2) = noofsites
261  elseif( eabsorb(2) .gt. noofsites) then
262  call cerrormsg("Eabsorb(2) > NoOfSites", 0)
263  endif
264  endif
265  end
266 ! ************
267  subroutine cinirn
268 ! initialize random # generator. This was a part of
269 ! cwhatJob before v7.651 but separated as ciniRN
270 ! and is called from before cixsec.
271 ! ************
272  implicit none
273 #include "Zmanager.h"
274 #include "Zmanagerp.h"
275 !
276 !
277  character*190 msg
278  real*8 u
279  integer::i, now(2)
280 
281 ! move from ciniTracking0
282  refreshir = initrn(1) .lt. 0 .and.
283  * ( job .ne. 'flesh' .and. job .ne. 'newflesh')
284 
285  if(initrn(1) .gt. 0 .and. initrn(2) .gt. 0 ) then
286  call rnd1r(initrn) ! init randeom number generator
287 ! *****************
288  elseif(.not. refreshir .and. initrn(2) .lt. 0) then
289  call cmkseed(0, now) ! make seed using timer and hostname
290  call rnd1r(now)
291 ! dummy use of 1000 times
292  do i = 1, 1000
293  call rndc(u)
294  enddo
295  endif
296 ! this is almost ok but later once more saved.
297  call rnd1s(seedsave)
298  end
299 ! ******************
300  subroutine cwhatjob
301 ! ************
302  implicit none
303 #include "Zmanager.h"
304 #include "Zmanagerp.h"
305 #include "Ztrack.h"
306 #include "Ztrackv.h"
307 #include "Ztrackp.h"
308 #include "Zobs.h"
309 #include "Zobsp.h"
310 #include "Zobsv.h"
311 !
312  integer klena, icon
313  character*8 uid
314  character*16 temp
315 
316  integer i
317  character*190 msg
318 
319  if(keminobs(2) .ne. keminobs(1)) then
320  write(0,*) ' KEminObs(2) is forced to be the same as'
321  write(0,*) ' KEminObs(1)=',keminobs(1)
322  keminobs(2)= keminobs(1)
323  endif
324 
325  if(job .eq. ' ' .or. job .eq. 'skeleton' .or.
326  * job .eq. 'newskel' ) then
327  if(job .ne. 'newskel') then
328 ! save present conditions
329  do i = 1, 8
330  keminobs2(i) = keminobs(i)
331  enddo
332  generate2 = generate
333  EndLevel2 = endlevel
334  elseif(job .eq. 'newskel') then
335  if( keminobs2(1) .ge. keminobs(1) .and.
336  * endlevel2 .le. endlevel .and.
337  * index(generate2,'as') .eq. 0 .and.
338  * index(generate2,'lat') .eq. 0 ) then
339  call cerrormsg(
340  * 'Doing newskel job seems nonsense', 1)
341  call cerrormsg(
342  * 'Check Generate2, KEminObs2(1), EndLevel2',0)
343  endif
344  endif
345  noofsites2 = noofsites ! probably not needed
346  if(job .eq. ' ') then
347  if(seedfile .ne. ' ') then
348 ! open seed file for output
349  write(msg, *) 'opening SeedFile=',
350  * seedfile(1:klena(seedfile))
351  call cerrormsg(msg, 1)
352  call copenfw(seedfiledev, seedfile, icon)
353  if(icon .ne. 0) then
354  call cerrormsg(seedfile, 1)
355  call cerrormsg('File shown above cannot be opened',0)
356  endif
357  if(cont) then
358  call cskiptoeof(seedfiledev)
359  endif
360  endif
361  elseif(job .eq. 'skeleton' .or. job .eq. 'newskel' ) then
362  call
363  * cerrormsg(' ********** skeleton making **********', 1)
364  write(msg, *) ' Generate=', generate
365  call cerrormsg(msg, 1)
366 ! save skeleton inf. in skelotonFile file.
367 ! The file will be modified when the distjob command
368 ! processes Job = 'flesh' later. You need not modify
369 ! skeleton file if distjob is employed.
370  if(.not. cont) then
371  temp = job ! save current Job
372  if(job .eq. 'newskel') then
373  job = 'newflesh'
374  else
375  job = 'flesh'
376  endif
377  call copennlfw(tempdev, skeletonfile, icon)
378  if(icon .ne. 0) then
379  call cerrormsg(skeletonfile, 1)
380  call cerrormsg(
381  * 'File shown above cannot be opened',0)
382  endif
383  call cwriteparam(tempdev, 1)
384  close(tempdev)
385  job = temp
386  endif
387 
388 ! open SeedFile
389  if(seedfile .eq. ' ') then
390 ! error. you need file; not needed actually
391 ! write(msg, *)
392 ! * ' SeedFile must not be blank for skelton making'
393 ! call cerrorMsg(msg, 0)
394  else
395  write(msg, *) 'opening SeedFile=',
396  * seedfile(1:klena(seedfile))
397  call cerrormsg(msg, 1)
398  call copenfw(seedfiledev, seedfile, icon)
399  if(icon .ne. 0) then
400  call cerrormsg(seedfile, 1)
401  call cerrormsg('File shown above cannot be opened',0)
402  endif
403  if(cont) then
404  call cskiptoeof(seedfiledev)
405  endif
406  endif
407  endif
408  elseif(job .eq. 'flesh' .or. job .eq. 'newflesh') then
409 ! don't worry about KEminObs2 etc. They have been read
410 ! from &Hparam
411  call cerrormsg(' ********** fleshing job *********', 1)
412  if(job .eq. 'flesh') then
413  if(endlevel .gt. endlevel2) then
414 ! to deeper detph than skeleton
415  write(msg, *)
416  * ' fleshing will be done to deeper depth than'//
417  * ' skeleton making time'
418  call cerrormsg(msg, 1)
419  write(msg, *) ' No of old levels=', endlevel2,
420  * ' No of new levels=', endlevel
421  call cerrormsg(msg, 1)
422  elseif(endlevel .lt. endlevel2) then
423  call cerrormsg('EndLevel must be >= skelton time', 0)
424  endif
425  write(msg, *) ' Old Generate=', generate2
426  call cerrormsg(msg, 1)
427  write(msg, *) ' New Generate=', generate
428  call cerrormsg(msg, 1)
429  else
430  if(endlevel .lt. endlevel2) then
431 ! to deeper detph than skeleton
432  write(msg, *)
433  * ' fleshing will be done to deeper depth than'//
434  * ' skeleton making time'
435  call cerrormsg(msg, 1)
436  endif
437 !
438 ! copy old Generate, KEminObs2 to current value
439 ! they are future values at newskel time
440  do i = 1, 8
441  keminobs(i) = keminobs2(i)
442  enddo
443  generate = generate2
444  EndLevel = endlevel2
445  endif
446 ! open SeedFile
447  if(seedfile .eq. ' ') then
448 !c write(*, *) ' SeedFile must not be blank for flesh job'
449 !c call cerrorMsg(msg, 0)
450 ! seed will be read from Mdev.
451  else
452  write(msg, *) 'opening SeedFFile=',
453  * seedfile(1:klena(seedfile))
454  call cerrormsg(msg, 1)
455  call copenf(seedfiledev, seedfile, icon)
456  if(icon .ne. 0) then
457  call cerrormsg(seedfile, 0)
458  call cerrormsg('File shown above seems missing',0)
459  endif
460  endif
461  else
462  write(msg,*) ' Job=',job, ' undefined'
463  call cerrormsg(msg, 0)
464  endif
465  if((trace .gt. 0 .and. trace .lt. 60) .or. trace .gt. 100) then
466 ! defalut trace. fix the dirctor
467  if(tracedir .eq. ' ') then
468  call cgetloginn(uid)
469  tracedir = '/tmp/'//uid(1:klena(uid))
470  endif
471  endif
472  end
473 ! **************************************** read cont job info
474  subroutine crestorestatus
475  implicit none
476 #include "Zmanagerp.h"
477  integer icon
478 
479  call copennlf(tempdev, contfile,icon)
480  if(icon .ne. 0) then
481  call cerrormsg(contfile, 1)
482  call cerrormsg('File shown above seems missing',0)
483  endif
484  call creadparam(tempdev)
485  close(tempdev)
486  end
487  subroutine cgetskelfile
488  implicit none
489 #include "Zmanagerp.h"
490  integer icon
491  call copennlf(tempdev, skeletonfile, icon)
492  if(icon .ne. 0 ) then
493  call cerrormsg(skeletonfile, 1)
494  call cerrormsg('File shown above seems missing',0)
495  endif
496 ! read skelton parameters for flesing
497  call creadparam(tempdev)
498  close(tempdev)
499  end
500 
501 
subroutine cmkseed(dummy, seed)
Definition: cmkSeed.f:3
subroutine cerrormsg(msg, needrtn)
Definition: cerrorMsg.f:4
subroutine cwhatjob
Definition: cbeginRun.f:301
subroutine csetlpmcnst(s1in, logs1in, vmin, X0in)
Definition: cmigdFunc.f:255
subroutine ciniatmos
Definition: ciniAtmos.f:3
subroutine c2lowercase(cu, cl)
Definition: c2lowerCase.f:11
subroutine cinitobs
Definition: cinitObs.f:7
nodes i
subroutine cintmodels(from)
Definition: cintModels.f:3
subroutine crdgeomag(filepath, yearin)
Definition: cgeomag.f:133
subroutine cinirn
Definition: cbeginRun.f:268
subroutine crigcut0(file)
Definition: crigCut.f:166
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 rndc(u)
Definition: rnd.f:91
integer mpisize
Definition: Zmpibasic.h:1
subroutine cwriteparam(io, force)
Definition: cwriteParam.f:4
integer mpirank
Definition: Zmpibasic.h:1
subroutine creadparam(io)
Definition: creadParam.f:5
block data cblkEvhnp ! currently usable models data RegMdls ad *special data *Cekaon d0
Definition: cblkEvhnp.h:5
subroutine csetmu(Zeffin, Aeffin)
Definition: cSetMu.f:2
subroutine copenf(io, fnin, icon)
Definition: copenf.f:8
dE dx *! Nuc Int sampling table d
Definition: cblkMuInt.h:130
subroutine copenfw(io, fnin, icon)
Definition: copenf.f:122
subroutine cgetskelfile
Definition: cbeginRun.f:488
subroutine cdet2xyz(det, a, b)
Definition: cxyz2det.f:48
subroutine cdedxeleci(w0in, knck)
Definition: cdedxEleci.f:2
subroutine cinitracking0
Definition: cbeginRun.f:185
integer function klena(cha)
Definition: klena.f:20
subroutine crdmutab
Definition: cRdmuTab.f: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 ! knockon is considered Obsolete *PhotoProd false
Definition: cblkElemag.h:7
subroutine cixsec
Definition: cixsec.f:2
subroutine cskiptoeof(iodev)
Definition: copenf.f:189
subroutine cbeginrun
Definition: cbeginRun.f:7
subroutine cinisprimang
Definition: csPrimAng.f:150
subroutine cinisprim(fn)
Definition: ciniSPrim.f:11
subroutine chookbgrun
Definition: chook.f:15
subroutine crestorestatus
Definition: cbeginRun.f:475
subroutine cgetloginn(userid)
Definition: cgetLoginN.f:29