SND@LHC Software
Loading...
Searching...
No Matches
g4Ex_gap Namespace Reference

Classes

class  MyEventAction
 
class  MyGeneratorAction
 
class  MyRunAction
 
class  MySteppingAction
 
class  MyTrackingAction
 
class  MyTrackingActionD
 
class  ScoreSD
 

Functions

 get_work_dir (run_number)
 
 init ()
 
 ConstructGeom ()
 

Variables

bool local = False
 
bool debug = False
 
bool particleGun = False
 
bool withStepping = False
 
bool withNtuple = True
 
bool muonNuclear = True
 
str model = "QGSP_BERT_EMV"
 
int runnr = 1
 
int nev = 1000
 
int nevTot = 0
 
int myEventnr = 0
 
int mytrack = 1
 
int scoreLog = 1
 
bool inclusive = True
 
dict myTimer = {'total':0,'pythia':0,'geant4_conv':0}
 
bool tauOnly = False
 
bool JpsiMainly = False
 
bool fullTungsten = False
 
str work_dir = "./"
 
float ecut = 0.5
 
bool allPart = True
 
list qedlist = [22,11,-11,12,-12,14,14,2212,2112,13,-13]
 
bool rangeCut = False
 
dict trackHistory = {}
 
 logger = logging.getLogger(os.path.splitext(os.path.basename(os.sys.argv[0]))[0])
 
 args = init()
 
 pdg = ROOT.TDatabasePDG()
 
 myPythia = ROOT.TPythia8()
 
 rnr = ROOT.TRandom()
 
 R = int(time.time()%900000000)
 
dict h = {}
 
 f = ROOT.TFile.Open('pythia8_Geant4_'+str(runnr)+'_'+str(ecut)+'.root', 'RECREATE')
 
 rand_engine = Ranlux64Engine()
 
int world_r = 200.*m
 
 xx = G4physicslists.GetReferencePhysList(model)
 
 myGE = MyGeneratorAction()
 
 myTA
 
 myRA = MyRunAction()
 
 myEA = MyEventAction()
 
 mySA = MySteppingAction()
 
 sens = ScoreSD('Score')
 
 t0 = time.time()
 
 t1 = time.time()
 
 wrld = snoopyPhys.GetMotherLogical()
 
 parser = G4GDMLParser()
 
str geofile = work_dir+'/g4Geom.gdml'
 
 geomgr = ROOT.gGeoManager
 

Function Documentation

◆ ConstructGeom()

g4Ex_gap.ConstructGeom ( )

Definition at line 408 of file g4Ex_gap.py.

408def ConstructGeom():
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

◆ get_work_dir()

g4Ex_gap.get_work_dir (   run_number)

Definition at line 48 of file g4Ex_gap.py.

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

◆ init()

g4Ex_gap.init ( )

Definition at line 56 of file g4Ex_gap.py.

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

Variable Documentation

◆ allPart

bool g4Ex_gap.allPart = True

Definition at line 35 of file g4Ex_gap.py.

◆ args

g4Ex_gap.args = init()

Definition at line 100 of file g4Ex_gap.py.

◆ debug

bool g4Ex_gap.debug = False

Definition at line 9 of file g4Ex_gap.py.

◆ ecut

float g4Ex_gap.ecut = 0.5

Definition at line 33 of file g4Ex_gap.py.

◆ f

g4Ex_gap.f = ROOT.TFile.Open('pythia8_Geant4_'+str(runnr)+'_'+str(ecut)+'.root', 'RECREATE')

Definition at line 163 of file g4Ex_gap.py.

◆ fullTungsten

bool g4Ex_gap.fullTungsten = False

Definition at line 30 of file g4Ex_gap.py.

◆ geofile

str g4Ex_gap.geofile = work_dir+'/g4Geom.gdml'

Definition at line 582 of file g4Ex_gap.py.

◆ geomgr

g4Ex_gap.geomgr = ROOT.gGeoManager

Definition at line 586 of file g4Ex_gap.py.

◆ h

dict g4Ex_gap.h = {}

Definition at line 161 of file g4Ex_gap.py.

◆ inclusive

bool g4Ex_gap.inclusive = True

Definition at line 26 of file g4Ex_gap.py.

◆ JpsiMainly

bool g4Ex_gap.JpsiMainly = False

Definition at line 29 of file g4Ex_gap.py.

◆ local

g4Ex_gap.local = False

Definition at line 6 of file g4Ex_gap.py.

◆ logger

g4Ex_gap.logger = logging.getLogger(os.path.splitext(os.path.basename(os.sys.argv[0]))[0])

Definition at line 44 of file g4Ex_gap.py.

◆ model

str g4Ex_gap.model = "QGSP_BERT_EMV"

Definition at line 19 of file g4Ex_gap.py.

◆ muonNuclear

bool g4Ex_gap.muonNuclear = True

Definition at line 18 of file g4Ex_gap.py.

◆ myEA

g4Ex_gap.myEA = MyEventAction()

Definition at line 550 of file g4Ex_gap.py.

◆ myEventnr

int g4Ex_gap.myEventnr = 0

Definition at line 23 of file g4Ex_gap.py.

◆ myGE

g4Ex_gap.myGE = MyGeneratorAction()

Definition at line 538 of file g4Ex_gap.py.

◆ myPythia

g4Ex_gap.myPythia = ROOT.TPythia8()

Definition at line 128 of file g4Ex_gap.py.

◆ myRA

g4Ex_gap.myRA = MyRunAction()

Definition at line 547 of file g4Ex_gap.py.

◆ mySA

g4Ex_gap.mySA = MySteppingAction()

Definition at line 553 of file g4Ex_gap.py.

◆ myTA

g4Ex_gap.myTA

Definition at line 541 of file g4Ex_gap.py.

◆ myTimer

dict g4Ex_gap.myTimer = {'total':0,'pythia':0,'geant4_conv':0}

Definition at line 27 of file g4Ex_gap.py.

◆ mytrack

int g4Ex_gap.mytrack = 1

Definition at line 24 of file g4Ex_gap.py.

◆ nev

int g4Ex_gap.nev = 1000

Definition at line 21 of file g4Ex_gap.py.

◆ nevTot

int g4Ex_gap.nevTot = 0

Definition at line 22 of file g4Ex_gap.py.

◆ parser

g4Ex_gap.parser = G4GDMLParser()

Definition at line 581 of file g4Ex_gap.py.

◆ particleGun

bool g4Ex_gap.particleGun = False

Definition at line 10 of file g4Ex_gap.py.

◆ pdg

g4Ex_gap.pdg = ROOT.TDatabasePDG()

Definition at line 120 of file g4Ex_gap.py.

◆ qedlist

g4Ex_gap.qedlist = [22,11,-11,12,-12,14,14,2212,2112,13,-13]

Definition at line 36 of file g4Ex_gap.py.

◆ R

g4Ex_gap.R = int(time.time()%900000000)

Definition at line 148 of file g4Ex_gap.py.

◆ rand_engine

g4Ex_gap.rand_engine = Ranlux64Engine()

Definition at line 172 of file g4Ex_gap.py.

◆ rangeCut

bool g4Ex_gap.rangeCut = False

Definition at line 37 of file g4Ex_gap.py.

◆ rnr

g4Ex_gap.rnr = ROOT.TRandom()

Definition at line 129 of file g4Ex_gap.py.

◆ runnr

int g4Ex_gap.runnr = 1

Definition at line 20 of file g4Ex_gap.py.

◆ scoreLog

int g4Ex_gap.scoreLog = 1

Definition at line 25 of file g4Ex_gap.py.

◆ sens

g4Ex_gap.sens = ScoreSD('Score')

Definition at line 559 of file g4Ex_gap.py.

◆ t0

g4Ex_gap.t0 = time.time()

Definition at line 567 of file g4Ex_gap.py.

◆ t1

g4Ex_gap.t1 = time.time()

Definition at line 569 of file g4Ex_gap.py.

◆ tauOnly

bool g4Ex_gap.tauOnly = False

Definition at line 28 of file g4Ex_gap.py.

◆ trackHistory

dict g4Ex_gap.trackHistory = {}

Definition at line 38 of file g4Ex_gap.py.

◆ withNtuple

bool g4Ex_gap.withNtuple = True

Definition at line 17 of file g4Ex_gap.py.

◆ withStepping

bool g4Ex_gap.withStepping = False

Definition at line 12 of file g4Ex_gap.py.

◆ work_dir

str g4Ex_gap.work_dir = "./"

Definition at line 32 of file g4Ex_gap.py.

◆ world_r

int g4Ex_gap.world_r = 200.*m

Definition at line 175 of file g4Ex_gap.py.

◆ wrld

g4Ex_gap.wrld = snoopyPhys.GetMotherLogical()

Definition at line 580 of file g4Ex_gap.py.

◆ xx

g4Ex_gap.xx = G4physicslists.GetReferencePhysList(model)

Definition at line 531 of file g4Ex_gap.py.