Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:46

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 from __future__ import absolute_import, unicode_literals
0012 import os
0013 import sys
0014 import time
0015 import DDG4
0016 from DDG4 import OutputLevel as Output
0017 from g4units import GeV, MeV
0018 #
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 def run():
0031   batch = False
0032   kernel = DDG4.Kernel()
0033   install_dir = os.environ['DD4hepExamplesINSTALL']
0034   geometry = "file:" + install_dir + "/examples/ClientTests/compact/MultiSegmentCollections.xml"
0035   kernel.setOutputLevel(str('Geant4Converter'), Output.DEBUG)
0036   kernel.setOutputLevel(str('Gun'), Output.INFO)
0037   for i in range(len(sys.argv)):
0038     if sys.argv[i] == '-compact':
0039       geometry = sys.argv[i + 1]
0040     elif sys.argv[i] == '-input':
0041       geometry = sys.argv[i + 1]
0042     elif sys.argv[i] == '-batch':
0043       batch = True
0044     elif sys.argv[i] == 'batch':
0045       batch = True
0046 
0047   kernel.loadGeometry(str(geometry))
0048   geant4 = DDG4.Geant4(kernel)
0049   geant4.printDetectors()
0050   geant4.setupCshUI()
0051   if batch:
0052     kernel.UI = ''
0053 
0054   # Configure field
0055   geant4.setupTrackingField(prt=True)
0056   # Setup particle gun
0057   geant4.setupGun("Gun", particle='pi-', energy=50 * GeV, multiplicity=1)
0058 
0059   # Now the test calorimeter with multiple collections
0060   seq, act = geant4.setupCalorimeter('TestCal')
0061 
0062   # And handle the simulation particles.
0063   part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0064   kernel.generatorAction().adopt(part)
0065   part.MinimalKineticEnergy = 1 * MeV
0066   part.enableUI()
0067 
0068   # Add the particle dumper to associate the MC truth
0069   evt = DDG4.EventAction(kernel, "Geant4ParticleDumpAction/ParticleDump")
0070   kernel.eventAction().adopt(evt)
0071   evt.enableUI()
0072 
0073   # Add the hit dumper BEFORE any hit truth is fixed
0074   evt = DDG4.EventAction(kernel, "Geant4HitDumpAction/RawDump")
0075   kernel.eventAction().adopt(evt)
0076   evt.enableUI()
0077 
0078   # Add the hit dumper to the event action sequence
0079   evt = DDG4.EventAction(kernel, "Geant4HitTruthHandler/HitTruth")
0080   kernel.eventAction().adopt(evt)
0081   evt.enableUI()
0082 
0083   # Add the hit dumper AFTER any hit truth is fixed. We should see the reduced track references
0084   evt = DDG4.EventAction(kernel, "Geant4HitDumpAction/HitDump")
0085   kernel.eventAction().adopt(evt)
0086   evt.enableUI()
0087 
0088   # Configure I/O
0089   evt_root = geant4.setupROOTOutput('RootOutput', 'Multi_coll_' + time.strftime('%Y-%m-%d_%H-%M'), mc_truth=True)
0090   evt_root.HandleMCTruth = False
0091 
0092   # Now build the physics list:
0093   phys = kernel.physicsList()
0094   phys.extends = 'QGSP_BERT'
0095   phys.enableUI()
0096   phys.dump()
0097   # and run
0098   geant4.execute()
0099 
0100 
0101 if __name__ == "__main__":
0102   run()