File indexing completed on 2025-01-30 09:17:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 from __future__ import absolute_import, unicode_literals
0013 import sys
0014 import logging
0015 import DDG4
0016
0017 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0018 logger = logging.getLogger(__name__)
0019
0020
0021 class CLICSid:
0022 def __init__(self, tracker='Geant4TrackerCombineAction', no_physics=True):
0023 self.kernel = DDG4.Kernel()
0024 self.description = self.kernel.detectorDescription()
0025 self.geant4 = DDG4.Geant4(self.kernel, tracker=tracker)
0026 self.kernel.UI = ""
0027 if no_physics:
0028 self.noPhysics()
0029
0030 def loadGeometry(self, file=None):
0031 import os
0032 if file is None:
0033 install_dir = os.environ['DD4hepINSTALL']
0034 level = DDG4.printLevel()
0035 DDG4.setPrintLevel(DDG4.OutputLevel.WARNING)
0036 self.kernel.loadGeometry(str("file:" + install_dir + "/DDDetectors/compact/SiD.xml"))
0037 DDG4.setPrintLevel(level)
0038 else:
0039 ui = DDG4.DD4hepUI(self.description)
0040 ui.importROOT(file)
0041 return self
0042
0043
0044 def setupField(self, quiet=True):
0045 return self.geant4.setupTrackingField(prt=True)
0046
0047
0048 def setupRandom(self, name, type=None, seed=None, quiet=True):
0049 rndm = DDG4.Action(self.kernel, 'Geant4Random/' + name)
0050 if seed:
0051 rndm.Seed = seed
0052 if type:
0053 rndm.Type = type
0054 rndm.initialize()
0055 if not quiet:
0056 rndm.showStatus()
0057 return rndm
0058
0059
0060 def setupPhysics(self, model):
0061 phys = self.geant4.setupPhysics(model)
0062 ph = DDG4.PhysicsList(self.kernel, str('Geant4PhysicsList/Myphysics'))
0063
0064 ph.addParticleGroup(str('G4BosonConstructor'))
0065
0066 ph.addParticleGroup(str('G4LeptonConstructor'))
0067
0068 ph.addParticleProcess(str('e[+-]'), str('G4eMultipleScattering'), -1, 1, 1)
0069
0070 ph.addPhysicsConstructor(str('G4OpticalPhysics'))
0071
0072 ph.enableUI()
0073 phys.adopt(ph)
0074 phys.dump()
0075 return phys
0076
0077
0078 def noPhysics(self):
0079 self.geant4.setupPhysics('')
0080 return self
0081
0082 def setupDetectors(self):
0083 logger.info("# First the tracking detectors")
0084 seq, act = self.geant4.setupTracker('SiVertexBarrel')
0085 seq, act = self.geant4.setupTracker('SiVertexEndcap')
0086 seq, act = self.geant4.setupTracker('SiTrackerBarrel')
0087 seq, act = self.geant4.setupTracker('SiTrackerEndcap')
0088 seq, act = self.geant4.setupTracker('SiTrackerForward')
0089 logger.info("# Now setup the calorimeters")
0090 seq, act = self.geant4.setupCalorimeter('EcalBarrel')
0091 seq, act = self.geant4.setupCalorimeter('EcalEndcap')
0092 seq, act = self.geant4.setupCalorimeter('HcalBarrel')
0093 seq, act = self.geant4.setupCalorimeter('HcalEndcap')
0094 seq, act = self.geant4.setupCalorimeter('HcalPlug')
0095 seq, act = self.geant4.setupCalorimeter('MuonBarrel')
0096 seq, act = self.geant4.setupCalorimeter('MuonEndcap')
0097 seq, act = self.geant4.setupCalorimeter('LumiCal')
0098 seq, act = self.geant4.setupCalorimeter('BeamCal')
0099 return self
0100
0101
0102 def test_config(self, have_geo=True):
0103 self.kernel.configure()
0104 if have_geo:
0105 self.kernel.initialize()
0106 return self
0107
0108
0109 def test_run(self, have_geo=True, have_physics=False, num_events=0):
0110 self.test_config(have_geo)
0111 if have_geo:
0112 self.kernel.NumEvents = num_events
0113 self.kernel.run()
0114 self.kernel.terminate()
0115 logger.info('+++++ All Done....\n\nTEST_PASSED')
0116 sys.exit(0)