Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:22:12

0001 #!/usr/bin/env python3
0002 
0003 from pathlib import Path
0004 import acts
0005 from acts.examples.simulation import (
0006     addParticleGun,
0007     ParticleConfig,
0008     EtaConfig,
0009     PhiConfig,
0010     MomentumConfig,
0011     addGeant4,
0012 )
0013 from physmon_common import makeSetup
0014 
0015 u = acts.UnitConstants
0016 setup = makeSetup()
0017 
0018 # Create output directory for simulation files
0019 outputDir = setup.outdir / "simulation"
0020 outputDir.mkdir(exist_ok=True)
0021 
0022 # Single-threaded sequencer (Geant4 requirement)
0023 s = acts.examples.Sequencer(
0024     events=10000,
0025     numThreads=1,  # Geant4 must run single-threaded
0026     logLevel=acts.logging.INFO,
0027 )
0028 
0029 # Add context decorators
0030 for d in setup.decorators:
0031     s.addContextDecorator(d)
0032 
0033 rnd = acts.examples.RandomNumbers(seed=42)
0034 
0035 # Particle gun: electrons, matching truth_tracking_gsf.py configuration
0036 addParticleGun(
0037     s,
0038     ParticleConfig(num=1, pdg=acts.PdgParticle.eElectron, randomizeCharge=True),
0039     EtaConfig(-3.0, 3.0, uniform=True),
0040     MomentumConfig(1.0 * u.GeV, 100.0 * u.GeV, transverse=True),
0041     PhiConfig(0.0, 360.0 * u.degree),
0042     vtxGen=acts.examples.GaussianVertexGenerator(
0043         mean=acts.Vector4(0, 0, 0, 0),
0044         stddev=acts.Vector4(0, 0, 0, 0),
0045     ),
0046     multiplicity=1,
0047     rnd=rnd,
0048 )
0049 
0050 # Geant4 simulation
0051 addGeant4(
0052     s,
0053     setup.detector,
0054     setup.trackingGeometry,
0055     setup.field,
0056     rnd,
0057     killVolume=setup.trackingGeometry.highestTrackingVolume,
0058     killAfterTime=25 * u.ns,
0059     killSecondaries=True,
0060     outputDirRoot=outputDir,  # Enable ROOT output
0061 )
0062 
0063 # Run simulation
0064 s.run()
0065 
0066 print(f"Simulation complete. Output files:")
0067 print(f"  - {outputDir / 'particles_simulation.root'}")
0068 print(f"  - {outputDir / 'hits.root'}")