Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 08:25:14

0001 # ==========================================================================
0002 #  AIDA Detector description implementation
0003 # --------------------------------------------------------------------------
0004 # Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 # All rights reserved.
0006 #
0007 # For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 # For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 #
0010 # ==========================================================================
0011 import sys
0012 import logging
0013 import DDG4
0014 from DDG4 import OutputLevel as Output
0015 from g4units import GeV, MeV
0016 
0017 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0018 logger = logging.getLogger(__name__)
0019 
0020 """
0021 
0022    dd4hep example setup using the python configuration
0023 
0024    \author  M.Frank
0025    \version 1.0
0026 
0027 """
0028 
0029 
0030 class Setup:
0031   def __init__(self, geometry_file, macro=None, vis=None):
0032     self.kernel = DDG4.Kernel()
0033     self.kernel.setOutputLevel(str('Geant4Converter'), Output.DEBUG)
0034     self.kernel.setOutputLevel(str('Gun'), Output.INFO)
0035     self.description = self.kernel.detectorDescription()
0036     self.kernel.loadGeometry(str(geometry_file))
0037     self.geant4 = DDG4.Geant4(self.kernel)
0038     self.geant4.printDetectors()
0039     self.ui = self.geant4.setupCshUI(macro=macro, vis=vis)
0040 
0041   def configure(self):
0042     # Configure field
0043     self.field = self.geant4.setupTrackingField(prt=True)
0044     return self
0045 
0046   def defineOutput(self, output):
0047     # Configure I/O
0048     evt_write = self.geant4.setupROOTOutput('RootOutput', output, mc_truth=True)
0049     return evt_write
0050 
0051   def defineEdm4hepOutput(self, output):
0052     # Configure I/O
0053     evt_write = self.geant4.setupEDM4hepOutput('Edm4hepOutput', output)
0054     return evt_write
0055 
0056   def setupGun(self, name="Gun", particle='pi-', energy=100 * GeV, multiplicity=1):
0057     # Setup particle gun
0058     return self.geant4.setupGun(name, particle=particle, energy=energy, multiplicity=multiplicity)
0059 
0060   def setupInput(self, spec, mask=1):
0061     input_action = DDG4.GeneratorAction(self.kernel, "Geant4InputAction/Input")
0062     input_action.Input = spec
0063     input_action.MomentumScale = 1.0
0064     input_action.Mask = mask
0065     self.geant4.buildInputStage([input_action])
0066 
0067   def setupGenerator(self):
0068     # And handle the simulation particles.
0069     part = DDG4.GeneratorAction(self.kernel, "Geant4ParticleHandler/ParticleHandler")
0070     self.kernel.generatorAction().adopt(part)
0071     part.SaveProcesses = ['conv', 'Decay']
0072     part.MinimalKineticEnergy = 1 * MeV
0073     part.OutputLevel = 5  # generator_output_level
0074     part.enableUI()
0075     return part
0076 
0077   def setupPhysics(self, model='QGSP_BERT', dump=False):
0078     # Now build the physics list:
0079     self.phys = self.kernel.physicsList()
0080     self.phys.extends = model
0081     self.phys.decays = True
0082     self.phys.enableUI()
0083     if dump:
0084       self.phys.dump()
0085     return self
0086 
0087   def run(self, num_events=None):
0088     # and run
0089     self.geant4.execute(num_events)
0090     return self
0091 
0092   # Stop the entire excercise
0093   def terminate(self):
0094     self.kernel.terminate()
0095     logger.info('+++++ All Done....\n\nTEST_PASSED')
0096     sys.exit(0)
0097 
0098   # Test the configuration
0099   def test_config(self, have_geo=True):
0100     self.kernel.configure()
0101     if have_geo:
0102       self.kernel.initialize()
0103 
0104   # Test runner
0105   def test_run(self, have_geo=True, have_physics=False):
0106     self.test_config(have_geo)
0107     if have_geo:
0108       self.kernel.UI = ''
0109       self.kernel.NumEvents = 0
0110       self.kernel.run()
0111     self.terminate()