|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | +import acts |
| 5 | +from acts.examples.simulation import ( |
| 6 | + addParticleGun, |
| 7 | + ParticleConfig, |
| 8 | + EtaConfig, |
| 9 | + PhiConfig, |
| 10 | + MomentumConfig, |
| 11 | + addGeant4, |
| 12 | +) |
| 13 | +from physmon_common import makeSetup |
| 14 | + |
| 15 | +u = acts.UnitConstants |
| 16 | +setup = makeSetup() |
| 17 | + |
| 18 | +# Create output directory for simulation files |
| 19 | +outputDir = setup.outdir / "simulation" |
| 20 | +outputDir.mkdir(exist_ok=True) |
| 21 | + |
| 22 | +# Single-threaded sequencer (Geant4 requirement) |
| 23 | +s = acts.examples.Sequencer( |
| 24 | + events=10000, |
| 25 | + numThreads=1, # Geant4 must run single-threaded |
| 26 | + logLevel=acts.logging.INFO, |
| 27 | +) |
| 28 | + |
| 29 | +# Add context decorators |
| 30 | +for d in setup.decorators: |
| 31 | + s.addContextDecorator(d) |
| 32 | + |
| 33 | +rnd = acts.examples.RandomNumbers(seed=42) |
| 34 | + |
| 35 | +# Particle gun: electrons, matching truth_tracking_gsf.py configuration |
| 36 | +addParticleGun( |
| 37 | + s, |
| 38 | + ParticleConfig(num=1, pdg=acts.PdgParticle.eElectron, randomizeCharge=True), |
| 39 | + EtaConfig(-3.0, 3.0, uniform=True), |
| 40 | + MomentumConfig(1.0 * u.GeV, 100.0 * u.GeV, transverse=True), |
| 41 | + PhiConfig(0.0, 360.0 * u.degree), |
| 42 | + vtxGen=acts.examples.GaussianVertexGenerator( |
| 43 | + mean=acts.Vector4(0, 0, 0, 0), |
| 44 | + stddev=acts.Vector4(0, 0, 0, 0), |
| 45 | + ), |
| 46 | + multiplicity=1, |
| 47 | + rnd=rnd, |
| 48 | +) |
| 49 | + |
| 50 | +# Geant4 simulation |
| 51 | +addGeant4( |
| 52 | + s, |
| 53 | + setup.detector, |
| 54 | + setup.trackingGeometry, |
| 55 | + setup.field, |
| 56 | + rnd, |
| 57 | + killVolume=setup.trackingGeometry.highestTrackingVolume, |
| 58 | + killAfterTime=25 * u.ns, |
| 59 | + killSecondaries=True, |
| 60 | + outputDirRoot=outputDir, # Enable ROOT output |
| 61 | +) |
| 62 | + |
| 63 | +# Run simulation |
| 64 | +s.run() |
| 65 | + |
| 66 | +print(f"Simulation complete. Output files:") |
| 67 | +print(f" - {outputDir / 'particles_simulation.root'}") |
| 68 | +print(f" - {outputDir / 'hits.root'}") |
0 commit comments