Back to home page

EIC code displayed by LXR

 
 

    


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

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 #
0012 #
0013 from __future__ import absolute_import, unicode_literals
0014 import os
0015 import time
0016 import DDG4
0017 from DDG4 import OutputLevel as Output
0018 from g4units import GeV, MeV, m
0019 #
0020 #
0021 """
0022 
0023    dd4hep simulation example setup using the python configuration
0024 
0025    @author  M.Frank
0026    @version 1.0
0027 
0028 """
0029 
0030 
0031 def run():
0032   args = DDG4.CommandLine()
0033   kernel = DDG4.Kernel()
0034   logger = DDG4.Logger('BoxOfStraws')
0035   install_dir = os.environ['DD4hepExamplesINSTALL']
0036 
0037   if args.sensitive:
0038     kernel.loadGeometry(str('file:' + install_dir + '/examples/ClientTests/compact/BoxOfStraws_sensitive.xml'))
0039   else:
0040     kernel.loadGeometry(str('file:' + install_dir + '/examples/ClientTests/compact/BoxOfStraws.xml'))
0041 
0042   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0043   geant4 = DDG4.Geant4(kernel)
0044   geant4.printDetectors()
0045   # Configure UI
0046   if args.macro:
0047     ui = geant4.setupCshUI(macro=args.macro)
0048   else:
0049     ui = geant4.setupCshUI()
0050   if args.batch:
0051     ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0052   #
0053   # Configure field
0054   geant4.setupTrackingField(prt=True)
0055   #
0056   prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0057   prt.OutputLevel = Output.DEBUG
0058   prt.OutputType = 3  # Print both: table and tree
0059   kernel.eventAction().adopt(prt)
0060   #
0061   seq, act = geant4.addDetectorConstruction('Geant4DetectorConstructionResources/ResourcesBeforeConstruction')
0062   act.When = "geometry"
0063   #
0064   # Configure G4 geometry setup
0065   seq, act = geant4.addDetectorConstruction('Geant4DetectorGeometryConstruction/ConstructGeo')
0066   act.DebugVolumes = True
0067   #
0068   if args.sensitive:
0069     # Assign sensitive detectors according to the declarations 'tracker' or 'calorimeter', etc
0070     seq, act = geant4.addDetectorConstruction('Geant4DetectorSensitivesConstruction/ConstructSD')
0071   else:
0072     # Assign sensitive detectors in Geant4 by matching a regular expression in the detector sub-tree
0073     seq, act = geant4.addDetectorConstruction('Geant4RegexSensitivesConstruction/ConstructSDRegEx')
0074     act.Detector = 'BoxOfStrawsDet'
0075     act.OutputLevel = Output.ALWAYS
0076     act.Match = ['gas_']
0077   #
0078   seq, act = geant4.addDetectorConstruction('Geant4DetectorConstructionResources/ResourcesAfterConstruction')
0079   act.When = "sensitives"
0080   #
0081   # Configure I/O
0082   geant4.setupROOTOutput('RootOutput', 'BoxOfStraws_' + time.strftime('%Y-%m-%d_%H-%M'))
0083   #
0084   # Setup particle gun
0085   gun = geant4.setupGun('Gun', particle='pi+', energy=10 * GeV, multiplicity=1)
0086   gun.OutputLevel = Output.INFO
0087   gun.enableUI()
0088   #
0089   # And handle the simulation particles.
0090   part = DDG4.GeneratorAction(kernel, 'Geant4ParticleHandler/ParticleHandler')
0091   kernel.generatorAction().adopt(part)
0092   part.SaveProcesses = ['Decay']
0093   part.MinimalKineticEnergy = 50 * MeV
0094   user = DDG4.Action(kernel, 'Geant4TCUserParticleHandler/UserParticleHandler')
0095   user.TrackingVolume_Zmax = 2.5 * m
0096   user.TrackingVolume_Rmax = 2.5 * m
0097   part.adopt(user)
0098   #
0099   # Map sensitive detectors of type 'BoxOfStraws' to Geant4CalorimeterAction
0100   sd = geant4.description.sensitiveDetector(str('BoxOfStrawsDet'))
0101   logger.info(f'+++ BoxOfStraws: SD type: {str(sd.type())}')
0102   energy_filter = DDG4.Filter(kernel, 'EnergyDepositMinimumCut')
0103   energy_filter.Cut = 1.0 * MeV
0104   energy_filter.enableUI()
0105   kernel.registerGlobalFilter(energy_filter)
0106   seq, act = geant4.setupDetector(name='BoxOfStrawsDet', action='MyTrackerSDAction')
0107   seq.adopt(energy_filter)
0108   act.HaveCellID = False
0109   #
0110   # Now build the physics list:
0111   phys = geant4.setupPhysics(str('QGSP_BERT'))
0112   phys.dump()
0113   if args.simultate:
0114     geant4.execute()
0115   else:
0116     geant4.kernel().configure()
0117     geant4.kernel().initialize()
0118     geant4.kernel().terminate()
0119 
0120 
0121 if __name__ == "__main__":
0122   run()