SND@LHC Software
Loading...
Searching...
No Matches
g4Ex_gap.py
Go to the documentation of this file.
1#!/usr/bin/env python
2from __future__ import print_function
3import os
4import saveBasicParameters
5
6local = False
7if not os.uname()[1].find('ubuntu')<0: local = True
8
9debug = False
10particleGun = False
11
12withStepping = False
13# if debug: withStepping = True
14
15
16# new attempt, make general Ekin cut at 0.5
17withNtuple = True
18muonNuclear = True
19model = "QGSP_BERT_EMV" # QGSP_BERT_EMV <-- less accurate EM showers, should be fine, otherwise "QGSP_BERT_EMX"
20runnr = 1
21nev = 1000
22nevTot = 0
23myEventnr = 0
24mytrack = 1
25scoreLog = 1
26inclusive = True # write out all particles crossing scoring plane !
27myTimer = {'total':0,'pythia':0,'geant4_conv':0}
28tauOnly = False
29JpsiMainly = False
30fullTungsten = False
31
32work_dir = "./"
33ecut = 0.5 # GeV with 1 : ~1sec / event, with 2: 0.4sec / event, 10: 0.13sec
34 # pythia = geant4 conversion = 0.4/100
35allPart = True
36qedlist = [22,11,-11,12,-12,14,14,2212,2112,13,-13]
37rangeCut = False
38trackHistory = {}
39#----------------------------- Yandex production ------------------------------
40import shutil
41import argparse
42import logging
43logging.info("")
44logger = logging.getLogger(os.path.splitext(os.path.basename(os.sys.argv[0]))[0])
45logger.setLevel(logging.INFO)
46
47
48def get_work_dir(run_number):
49 import socket
50 host = socket.gethostname()
51 job_base_name = os.path.splitext(os.path.basename(os.sys.argv[0]))[0]
52 out_dir = "{host}_{base}_{runnr}".format(host=host, base=job_base_name, runnr=run_number)
53 return out_dir
54
55
56def init():
57 global runnr, nev, ecut, tauOnly,JpsiMainly,fullTungsten, work_dir
58 logger.info("SHiP proton-on-taget simulator (C) Thomas Ruf, 2014")
59
60 ap = argparse.ArgumentParser(
61 description='Run SHiP "pot" simulation')
62 ap.add_argument('-d', '--debug', action='store_true')
63 ap.add_argument('-f', '--force', action='store_true', help="force overwriting output directory")
64 ap.add_argument('-r', '--run-number', type=int, dest='runnr', default=runnr)
65 ap.add_argument('-e', '--ecut', type=float, help="energy cut", dest='ecut', default=ecut)
66 ap.add_argument('-n', '--num-events', type=int, help="number of events to generate", dest='nev', default=nev)
67 ap.add_argument('-t', '--tau-only', action='store_true', dest='tauOnly',default=False)
68 ap.add_argument('-J', '--Jpsi-mainly', action='store_true', dest='JpsiMainly',default=False)
69 ap.add_argument('-W', '--FullTungsten', action='store_true',dest='fullTungsten',default=False)
70 ap.add_argument('-o', '--output', type=str, help="output directory", dest='work_dir', default=None)
71 args = ap.parse_args()
72 if args.debug:
73 logger.setLevel(logging.DEBUG)
74 runnr = args.runnr
75 nev = args.nev
76 ecut = args.ecut
77 tauOnly = args.tauOnly
78 JpsiMainly = args.JpsiMainly
79 fullTungsten = args.fullTungsten
80 if args.work_dir is None:
81 args.work_dir = get_work_dir(runnr)
82 work_dir = args.work_dir
83 logger.debug("work_dir: %s" % work_dir)
84 logger.debug("command line arguments: %s", args)
85 if os.path.exists(work_dir):
86 logger.warn("output directory '%s' already exists." % work_dir)
87 if args.force:
88 logger.warn("...cleaning")
89 for root, dirs, files in os.walk(work_dir):
90 for f in files:
91 os.unlink(os.path.join(root, f))
92 for d in dirs:
93 shutil.rmtree(os.path.join(root, d))
94 else:
95 logger.warn("...use '-f' option to overwrite it")
96 else:
97 os.makedirs(work_dir)
98 return args
99
100args = init()
101
102os.chdir(work_dir)
103# -------------------------------------------------------------------
104
105
106# ==================================================================
107# ROOT IMPORT #
108# ==================================================================
109import ROOT,time
110# ==================================================================
111# GEANT4 IMPORT #
112# ==================================================================
113from Geant4 import *
114import g4py.NISTmaterials
115import g4py.ezgeom
116from g4py.ezgeom import G4EzVolume
117# ==================================================================
118# PYTHIA8 PART #
119# ==================================================================
120pdg = ROOT.TDatabasePDG()
121pdg.AddParticle("Pomeron","Pomeron", 0,False,0,0,'',990)
122pdg.AddParticle("ccbar[1S0(8)]","ccbar[1S0(8)]",0,False,0,0,'',9900441)
123pdg.AddParticle("c~c[3P08]","c~c[3P08]",0,False,0,0,'',9910441)
124
125ROOT.gSystem.Load("libEG")
126ROOT.gSystem.Load("libpythia8")
127ROOT.gSystem.Load("libEGPythia8")
128myPythia = ROOT.TPythia8()
129rnr = ROOT.TRandom()
130myPythia.ReadString("Next:numberCount = 100000")
131myPythia.ReadString("SoftQCD:inelastic = on")
132myPythia.ReadString("PhotonCollision:gmgm2mumu = on")
133myPythia.ReadString("PromptPhoton:all = on")
134myPythia.ReadString("WeakBosonExchange:all = on")
135# http://home.thep.lu.se/~torbjorn/pythia81html/ParticleDecays.html
136if tauOnly :
137 myPythia.ReadString("431:new D_s+ D_s- 1 3 0 1.96849 0.00000 0.00000 0.00000 1.49900e-01 0 1 0 1 0")
138 myPythia.ReadString("431:addChannel = 1 0.0640000 0 -15 16")
139if JpsiMainly :
140 myPythia.ReadString("443:new J/psi J/psi 4 0 0 3.09692 0.00009 3.09602 3.09782 0. 1 1 0 1 0")
141 myPythia.ReadString("443:addChannel = 1 0.1 0 -13 13")
142# make pions/kaons/lambda stable
143for s in [211,321,130,310,3122,3112,3312]: # last two added 18Feb2015
144 myPythia.ReadString(str(s)+':mayDecay = false')
145
146# set random number seed
147myPythia.ReadString("Random:setSeed = On")
148R = int(time.time()%900000000)
149myPythia.ReadString("Random:seed = "+str(R))
150# Initialize proton (400GeV) on proton at rest
151myPythia.Initialize(2212,2212,400.,0.) # required to hack TPythia8 in root !
152# W = 74 protons and 184-74= 110 neutrons
153if tauOnly: myPythia.Plist(431)
154
155# if there is no energy cut, there are no particles to apply it to.
156if ecut == 0: qedlist = []
157# ecut applied to all particles
158if allPart: qedlist = []
159
160# Open an output file
161h = {}
162if withNtuple:
163 f = ROOT.TFile.Open('pythia8_Geant4_'+str(runnr)+'_'+str(ecut)+'.root', 'RECREATE')
164 h['ntuple'] = ROOT.TNtuple("pythia8-Geant4","muon/nu flux","id:px:py:pz:x:y:z:opx:opy:opz:ox:oy:oz:pythiaid:parentid")
165
166# ==================================================================
167# Geant4 PART #
168# ==================================================================
169# ------------------------------------------------------------------
170# randum number
171# ------------------------------------------------------------------
172rand_engine = Ranlux64Engine()
173HepRandom.setTheEngine(rand_engine)
174HepRandom.setTheSeed(runnr)
175world_r = 200.*m
176
177# ==================================================================
178# user actions in python
179# ==================================================================
180
181# ==================================================================
182# visualization
183# ==================================================================
184if local:
185 gVisManager.SetVerboseLevel(2)
186 gVisManager.Initialize()
187 gApplyUICommand('/vis/open OGLIX 1200x400-0+0')
188 gApplyUICommand('/vis/viewer/set/viewpointThetaPhi -90. 90.')
189
190# ------------------------------------------------------------------
191class MyGeneratorAction(G4VUserPrimaryGeneratorAction):
192 " My Generator Action"
193 pos = G4ThreeVector(0*cm, 0*cm, -world_r/2.)
194
195 def GeneratePrimaries(self,anEvent):
196 global debug,nevTot,particleGun,fullTungsten
197 t_0 = time.time()
198 npart = 0
199 if particleGun:
200# to evaluate interaction position
201 ztarget = G4ThreeVector(0*cm, 0*cm, -50.*m)
202 vertex = G4PrimaryVertex(ztarget,0.)
203 G4particle = G4PrimaryParticle( 2212 )
204 G4particle.Set4Momentum( 0,0,400*GeV,400.0011*GeV )
205# store mother ID
206 w = 2212 + 0 * 100000
207 G4particle.SetWeight(w)
208 vertex.SetPrimary( G4particle )
209 npart += 1
210 else:
211 while npart == 0:
212 myPythia.GenerateEvent()
213 nevTot+=1
214 myTimer['pythia']+=time.time()-t_0
215# pythia interaction happens at 0,0,0
216 #x = rnr.Uniform(-3.,3.)
217 #y = rnr.Uniform(-3.,3.)
218 # leave this smearing for later
219 # create new primaries and set them to the vertex
220 particles = myPythia.GetListOfParticles()
221 if fullTungsten: z = rnr.Exp(10*cm) -50.*m # tungsten interaction length
222 else: z = rnr.Exp(16*cm) -50.*m # Mo/H20/W average interaction length
223 ztarget = G4ThreeVector(0*cm, 0*cm, z)
224 vertex = G4PrimaryVertex(ztarget,0.)
225 v = ROOT.TLorentzVector()
226 for p in particles:
227 if p.GetStatusCode()!=1 : continue
228 pid = p.GetPdgCode()
229 mkey = p.GetMother(0)+1
230 mother = myPythia.GetParticle(mkey)
231 if JpsiMainly and abs(pid) != 13 : continue
232 if tauOnly and abs(pid) != 16 : continue
233 if JpsiMainly and mother.GetPdgCode() != 443 : continue
234 if tauOnly :
235 mmkey = mother.GetMother(0)+1
236 mmother = myPythia.GetParticle(mmkey)
237 if abs(mother.GetPdgCode()) != 431 and abs(mmother.GetPdgCode()) != 431 :
238 myPythia.EventListing()
239 continue
240 qed = pid in qedlist # use cut only for photons, leptons/neutrinos, protons and neutrons
241 p.Momentum(v)
242 Ekin = (v.E()-v.M())
243 if Ekin*GeV < ecut and (qed or allPart): continue
244 G4particle = G4PrimaryParticle( pid )
245 G4particle.Set4Momentum( v.Px()*GeV,v.Py()*GeV,v.Pz()*GeV,v.E()*GeV )
246# store mother ID
247 curPid = p.GetPdgCode() + 10000 # make it positive
248 moPid = mother.GetPdgCode() + 10000
249 w = curPid + moPid * 100000
250 G4particle.SetWeight(w)
251 vertex.SetPrimary( G4particle )
252 npart += 1
253 # if debug: myPythia.EventListing()
254 anEvent.AddPrimaryVertex( vertex )
255 if debug and not particleGun: print('new event at ',ztarget.z/m)
256 myTimer['geant4_conv']+=time.time()-t_0
257class MyRunAction(G4UserRunAction):
258 "My Run Action"
259
260 def EndOfRunAction(self, run):
261 global debug,nevTot
262 print("*** End of Run")
263 print("- Run summary : (id= %d, #events= %d)" \
264 % (run.GetRunID(), nevTot))
265 h['ntuple'].Write()
266 print('ecut applied to',allPart,qedlist,' range cut for e,gamma:',rangeCut)
267# ------------------------------------------------------------------
268class MyEventAction(G4UserEventAction):
269 "My Event Action"
270 def EndOfEventAction(self, event):
271 global myEventnr
272 if debug and not particleGun: print('end of event',myEventnr)
273 myEventnr += 1
274 # self.myPrintout(event)
275 def StartOfEventAction(self, event):
276 global trackHistory
277 trackHistory={}
278 def myPrintout(self, event):
279 prim = event.GetPrimaryVertex()
280 print('vertex ',prim.GetX0()/m,prim.GetY0()/m,prim.GetZ0()/m)
281 for k in range( prim.GetNumberOfParticle() ):
282 p = prim.GetPrimary(k)
283 print('event',p.GetPDGcode(),p.GetPx()/GeV,p.GetPy()/GeV,p.GetPz()/GeV)
284# ------------------------------------------------------------------
285class MySteppingAction(G4UserSteppingAction):
286 "My Stepping Action"
287
288 def UserSteppingAction(self, step):
289 preStepPoint = step.GetPreStepPoint()
290 touch = preStepPoint.GetTouchableHandle()
291 volName = touch.GetVolume().GetName().__format__('')
292 pos = preStepPoint.GetPosition()
293 print('stepping name, z pos dedx (MeV): ',volName,pos.z/m,step.GetTotalEnergyDeposit()/MeV)
294# ------------------------------------------------------------------
295class MyTrackingAction(G4UserTrackingAction):
296 def PostUserTrackingAction(self,atrack):
297 pass
298 def PreUserTrackingAction(self,atrack):
299# need to be careful with energy cut, anti-protons and anti-neutrons can always produce pions and kaons
300 part = atrack.GetDynamicParticle()
301 pid = part.GetPDGcode()
302 muCut = JpsiMainly and abs(pid)!=13
303 qed = pid in qedlist # use cut only for photons, electrons, protons and neutrons
304 if (atrack.GetKineticEnergy()/GeV < ecut and (qed or allPart) ) or muCut :
305 G4TrackingManager().SetStoreTrajectory(False)
306 atrack.SetTrackStatus(atrack.GetTrackStatus().fStopAndKill)
307
308# ------------------------------------------------------------------
309class MyTrackingActionD(G4UserTrackingAction):
310 def PostUserTrackingAction(self,atrack):
311 if particleGun and atrack.GetTrackID() == 1:
312 # record dead of 400GeV proton
313 if atrack.GetTrackStatus() != atrack.GetTrackStatus().fAlive :
314 part = atrack.GetDynamicParticle()
315 pid = part.GetPDGcode()
316 vx = atrack.GetVertexPosition()
317 mom = atrack.GetMomentum()
318 ekin = atrack.GetKineticEnergy()/GeV
319 pos = atrack.GetPosition()
320 w = atrack.GetWeight()
321 parentid = int(w)/100000-10000
322 pythiaid = int(w)%100000-10000
323 h['ntuple'].Fill(float(pid), float(mom.x/GeV),float(mom.y/GeV),float(mom.z/GeV),\
324 float(pos.x/m),float(pos.y/m),float(pos.z/m),\
325 float(vx.x/m),float(vx.y/m),float(vx.z/m),pythiaid,parentid)
326
327 def PreUserTrackingAction(self,atrack):
328 global trackHistory
329# need to be careful with energy cut, anti-protons and neutrons can always produce pions and kaons
330 part = atrack.GetDynamicParticle()
331 pid = part.GetPDGcode()
332 # if debug: self.myPrintout(atrack)
333 moid = atrack.GetParentID()
334 trackHistory[atrack.GetTrackID()]=[pid,moid]
335 tmoid = str(moid)
336 if moid in trackHistory:
337 mo = pdg.GetParticle(trackHistory[moid][0])
338 if mo : tmoid = mo.GetName()
339 tid = str(pid)
340 if pdg.GetParticle(pid): tid = pdg.GetParticle(pid).GetName()
341 mom = atrack.GetMomentum()
342 p = ROOT.TMath.Sqrt(mom.x*mom.x+mom.y*mom.y+mom.z*mom.z)
343 if debug and abs(pid)==13: print('track',atrack.GetTrackID(),tid,tmoid,moid,atrack.GetKineticEnergy()/MeV,p/MeV)
344 if pid==12:
345 if moid in trackHistory:
346 gmoid = trackHistory[moid][1]
347 if gmoid in trackHistory:
348 tgmoid = str(gmoid)
349 mo = pdg.GetParticle(trackHistory[gmoid][0])
350 if mo : tgmoid = mo.GetName()
351 print(' <--',gmoid,tgmoid)
352 gmoid = trackHistory[gmoid][1]
353 if gmoid in trackHistory:
354 tgmoid = str(gmoid)
355 mo = pdg.GetParticle(trackHistory[gmoid][0])
356 if mo : tgmoid = mo.GetName()
357 print(' <--',gmoid,tgmoid)
358
359 qed = pid in qedlist # use cut only for photons, electrons, protons and neutrons
360 if atrack.GetKineticEnergy()/GeV < ecut and (qed or allPart):
361 G4TrackingManager().SetStoreTrajectory(False)
362 atrack.SetTrackStatus(atrack.GetTrackStatus().fStopAndKill)
363
364 def myPrintout(self, atrack):
365 part = atrack.GetDynamicParticle()
366 pid = part.GetPDGcode()
367 vx = atrack.GetVertexPosition()
368 pos = atrack.GetPosition()
369 mom = atrack.GetMomentum()
370 print('TA',pid,atrack.GetTotalEnergy()/GeV,ecut*GeV)
371 print('start tracking',atrack.GetDynamicParticle().GetPDGcode(),atrack.GetKineticEnergy()/GeV,vx.z/m,pos.z/m,mom.z/GeV)
372
373# ------------------------------------------------------------------
374class ScoreSD(G4VSensitiveDetector):
375 "SD for score voxels"
376
377 def __init__(self,Name):
378 G4VSensitiveDetector.__init__(self, Name)
379
380 def ProcessHits(self, step, rohist):
381 preStepPoint = step.GetPreStepPoint()
382 track = step.GetTrack()
383 part = track.GetDynamicParticle()
384 pid = part.GetPDGcode()
385 vx = track.GetVertexPosition()
386 pvx = track.GetVertexMomentumDirection()
387 ekinvx = track.GetVertexKineticEnergy()
388 M = part.GetMass()
389 Pvx = ROOT.TMath.Sqrt( ekinvx*(ekinvx+2*M) )
390 mom = track.GetMomentum()
391 ekin = track.GetKineticEnergy()/GeV
392 pos = track.GetPosition()
393#
394 # primPart = part.GetPrimaryParticle()
395 w = track.GetWeight()
396 parentid = int(w)/100000-10000
397 pythiaid = int(w)%100000-10000
398 h['ntuple'].Fill(float(pid), float(mom.x/GeV),float(mom.y/GeV),float(mom.z/GeV),\
399 float(pos.x/m),float(pos.y/m),float(pos.z/m),\
400 float(Pvx*pvx.x/GeV),float(Pvx*pvx.y/GeV),float(Pvx*pvx.z/GeV),\
401 float(vx.x/m),float(vx.y/m),float(vx.z/m),pythiaid,parentid)
402 if debug:
403 print('xxx',pid, float(mom.x/GeV),float(mom.y/GeV),float(mom.z/GeV),\
404 float(pos.x/m),float(pos.y/m),float(pos.z/m),\
405 float(Pvx*pvx.x/GeV),float(Pvx*pvx.y/GeV),float(Pvx*pvx.z/GeV),\
406 float(vx.x/m),float(vx.y/m),float(vx.z/m),pythiaid,parentid)
407
409 print("* Constructing geometry...")
410 # reset world material
411 vac = G4Material.GetMaterial("G4_Galactic")
412 g4py.ezgeom.SetWorldMaterial(vac)
413 g4py.ezgeom.ResizeWorld(world_r/2., world_r/2., world_r)
414 # a snoopy world is placed
415 global snoopy,snoopyPhys,scoreLog
416 snoopy = G4EzVolume("Snoopy")
417 snoopy.CreateTubeVolume(vac, 0., 20*m, world_r/2.)
418 snoopyPhys = snoopy.PlaceIt(G4ThreeVector(0.,0.,0.*m))
419 snoopyLog = snoopyPhys.GetLogicalVolume()
420 snoopy.SetVisibility(False)
421 # a target box is placed
422 global target,targetPhys
423 iron = G4Material.GetMaterial("G4_Fe")
424 air = G4Material.GetMaterial("G4_AIR")
425 water = G4Material.GetMaterial("G4_WATER")
426 tungsten = G4Material.GetMaterial("G4_W")
427 lead = G4Material.GetMaterial("G4_Pb")
428 alum = G4Material.GetMaterial("G4_Al")
429 elementMo = G4Element("Molybdenum","Mo",42., 95.94*g/mole)
430 molybdenum = G4Material("molybdenum", 10.22*g/cm3, 1)
431 molybdenum.AddElement(elementMo, 1.00)
432#
433 if fullTungsten:
434 target = G4EzVolume("Target")
435 slit = G4EzVolume("Slit")
436 slitDZ = 0.5*cm
437 targetDZ = 5.*cm
438# target is sliced, 4 slits of 1cm, 10cm tungsten blocks
439 target.CreateTubeVolume(tungsten, 0., 25.*cm,targetDZ)
440 target.SetColor(G4Color(0.0,0.5,0.5,1.0))
441 target.SetVisibility(True)
442# additional 5 interaction lengths
443 #targetOpt = G4EzVolume("TargetOpt")
444 #targetOpt.CreateTubeVolume(tungsten, 0., 25.*cm, 25.*cm)
445 #targetOpt.SetColor(G4Color(0.0,0.5,0.5,1.0))
446 #targetOpt.SetVisibility(True)
447 slit.CreateTubeVolume(water, 0., 25.*cm, slitDZ)
448 slit.SetVisibility(False)
449 targetPhys = []
450 slitPhys = []
451 targetL = 0*cm
452 z0Pos = -50.*m
453 for i in range(4):
454 targetPhys.append(target.PlaceIt(G4ThreeVector(0.,0.,z0Pos + targetL + targetDZ) ,1,snoopy))
455 slitPhys.append(slit.PlaceIt(G4ThreeVector(0.,0., z0Pos + targetL + 2*targetDZ + slitDZ),1,snoopy))
456 targetL+= 2*(slitDZ+targetDZ)
457 targetPhys.append(target.PlaceIt(G4ThreeVector(0.,0., z0Pos + targetL + targetDZ),1,snoopy))
458 targetL+= 2*(targetDZ)
459 # put iron around
460 moreShielding = G4EzVolume("moreShielding")
461 moreShielding.CreateTubeVolume(iron, 30.*cm, 400.*cm, targetL/2.)
462 moreShieldingPhys = moreShielding.PlaceIt(G4ThreeVector(0.,0.,z0Pos + targetL/2.),1,snoopy)
463#
464 else: # new design with mixture Molybdaen and Tungsten
465 slitDZ = 0.5*cm
466 diameter = 30.*cm
467 spaceTopBot = 10.*cm
468 spaceSide = 5.*cm
469 slit = G4EzVolume("Slit")
470 slit.CreateBoxVolume(water, diameter,diameter,slitDZ)
471 slit.SetVisibility(False)
472 targetPhys = []
473 targetVol = []
474 slitPhys = []
475 targetL = 0*cm
476 z0Pos = -50.*m
477 # material,length
478 layout = {1:[molybdenum,8.*cm],\
479 2:[molybdenum,2.5*cm],3:[molybdenum,2.5*cm],4:[molybdenum,2.5*cm],5:[molybdenum,2.5*cm],\
480 6:[molybdenum,2.5*cm],7:[molybdenum,2.5*cm],8:[molybdenum,2.5*cm],\
481 9:[molybdenum,5.0*cm],10:[molybdenum,5.0*cm],\
482 11:[molybdenum,6.5*cm],\
483 12:[molybdenum,8.0*cm],13:[molybdenum,8.0*cm],\
484 14:[tungsten,5.*cm],15:[tungsten,8.*cm],16:[tungsten,10.*cm],17:[tungsten,35.*cm] }
485 for i in range(1,18):
486 targetVol.append(G4EzVolume("Target_Layer_"+str(i)))
487 targetVol[i-1].CreateBoxVolume(layout[i][0], diameter,diameter,layout[i][1])
488 if layout[i][0]==tungsten: targetVol[i-1].SetColor(G4Color(0.0,0.5,0.5,1.0))
489 else: targetVol[i-1].SetColor(G4Color(0.3,0.2,0.5,1.0))
490 targetVol[i-1].SetVisibility(True)
491 targetPhys.append(targetVol[i-1].PlaceIt(G4ThreeVector(0.,0.,z0Pos + targetL + layout[i][1]/2.),1,snoopy))
492 if i<17:
493 slitPhys.append(slit.PlaceIt( G4ThreeVector(0.,0.,z0Pos + targetL + layout[i][1] + slitDZ/2.),1,snoopy))
494 targetL+= slitDZ+layout[i][1]
495 else: targetL+= layout[i][1]
496 # put iron around
497 xTot = 400.*cm
498 yTot = 400.*cm
499 moreShieldingTopBot = G4EzVolume("moreShieldingTopBot")
500 moreShieldingTopBot.CreateBoxVolume(iron, xTot, yTot/2., targetL)
501 moreShieldingTopPhys = moreShieldingTopBot.PlaceIt(G4ThreeVector(0.,diameter/2. +spaceTopBot+yTot/4.,z0Pos + targetL/2.),1,snoopy)
502 moreShieldingBotPhys = moreShieldingTopBot.PlaceIt(G4ThreeVector(0.,-diameter/2.-spaceTopBot-yTot/4.,z0Pos + targetL/2.),1,snoopy)
503 moreShieldingSide = G4EzVolume("moreShieldingSide")
504 moreShieldingSide.CreateBoxVolume(iron, xTot/2., diameter+1.9*spaceTopBot, targetL)
505 moreShieldingLeftPhys = moreShieldingSide.PlaceIt(G4ThreeVector(diameter/2. +spaceSide+xTot/4.,0.,z0Pos + targetL/2.),1,snoopy)
506 moreShieldingRightPhys = moreShieldingSide.PlaceIt(G4ThreeVector(-diameter/2.-spaceSide-xTot/4.,0.,z0Pos + targetL/2.),1,snoopy)
507 # = 0.1m3 = 2t
508 # a hadron absorber is placed
509 absorberL = 2*150.*cm
510 absorber = G4EzVolume("Absorber")
511 # inner radius outer radius length
512 absorber.CreateTubeVolume(iron, 0., 400.*cm, absorberL/2.)
513 absorberPhys = absorber.PlaceIt(G4ThreeVector(0.,0.,z0Pos+targetL+absorberL/2.+5.*cm),1,snoopy)
514 absorber.SetColor(G4Color(0.898,0.902,0.91,1.0))
515 absorber.SetVisibility(True)
516 xx = G4VisAttributes()
517 xx.SetForceWireframe(True)
518 absorberlog = absorberPhys.GetLogicalVolume()
519 absorberlog.SetVisAttributes(xx)
520# scoring plane
521 afterHadronZ = z0Pos+targetL+absorberL+5.1*cm
522 scorez = afterHadronZ
523 score = G4EzVolume("Score")
524 score.CreateTubeVolume(vac, 0., 20.*m, 1.*mm)
525 scorePhys = score.PlaceIt(G4ThreeVector(0.,0.,scorez),1,snoopy)
526 scoreLog = scorePhys.GetLogicalVolume()
527 g4py.ezgeom.Construct()
528
529g4py.NISTmaterials.Construct()
530#print Geant4.gMaterialTable
531xx = G4physicslists.GetReferencePhysList(model)
532if rangeCut:
533 xx.SetCutValue(10.,'gamma')
534 xx.SetCutValue(10.,'e-')
535 xx.SetCutValue(10.,'e+')
536gRunManager.SetUserInitialization(xx)
537
539gRunManager.SetUserAction(myGE)
540#
541if debug: myTA= MyTrackingActionD()
542else: myTA= MyTrackingAction()
543gRunManager.SetUserAction(myTA)
544#
545
548gRunManager.SetUserAction(myRA)
549
551gRunManager.SetUserAction(myEA)
552
554if withStepping : gRunManager.SetUserAction(mySA)
555
556# initialize
557gRunManager.Initialize()
558# scoring should be set after geometry construction
559sens = ScoreSD('Score')
560scoreLog.SetSensitiveDetector(sens)
561
562if local and not particleGun:
563 gApplyUICommand('/vis/drawVolume')
564 gApplyUICommand('/vis/scene/add/trajectories')
565 gApplyUICommand('/vis/viewer/zoom 1.5')
566
567t0 = time.time()
568gRunManager.BeamOn(nev)
569t1 = time.time()
570print('Time used',t1-t0, ' seconds')
571for x in myTimer:
572 print(x,myTimer[x])
573
574logger.info("output directory: %s" % work_dir)
575# save arguments and GIT tags
576import saveBasicParameters
577saveBasicParameters.execute(f,args,'SHiP-Params')
578
579if local:
580 wrld = snoopyPhys.GetMotherLogical()
581 parser = G4GDMLParser()
582 geofile = work_dir+'/g4Geom.gdml'
583 if os.path.isfile(geofile): os.system('rm '+geofile)
584 parser.Write('g4Geom.gdml',wrld)
585 ROOT.TGeoManager()
586 geomgr = ROOT.gGeoManager
587 geomgr.Import('g4Geom.gdml','world','new')
588 ROOT.gGeoManager.CheckOverlaps()
589 ROOT.gGeoManager.PrintOverlaps()
590 geomgr.GetTopVolume().Draw('ogl')
591
StartOfEventAction(self, event)
Definition g4Ex_gap.py:275
myPrintout(self, event)
Definition g4Ex_gap.py:278
EndOfEventAction(self, event)
Definition g4Ex_gap.py:270
GeneratePrimaries(self, anEvent)
Definition g4Ex_gap.py:195
EndOfRunAction(self, run)
Definition g4Ex_gap.py:260
UserSteppingAction(self, step)
Definition g4Ex_gap.py:288
myPrintout(self, atrack)
Definition g4Ex_gap.py:364
PreUserTrackingAction(self, atrack)
Definition g4Ex_gap.py:327
PostUserTrackingAction(self, atrack)
Definition g4Ex_gap.py:310
PostUserTrackingAction(self, atrack)
Definition g4Ex_gap.py:296
PreUserTrackingAction(self, atrack)
Definition g4Ex_gap.py:298
ProcessHits(self, step, rohist)
Definition g4Ex_gap.py:380
__init__(self, Name)
Definition g4Ex_gap.py:377
get_work_dir(run_number)
Definition g4Ex_gap.py:48
ConstructGeom()
Definition g4Ex_gap.py:408
execute(f, ox, name='ShipGeo')