Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
physmon_simulation.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file physmon_simulation.py
1 #!/usr/bin/env python3
2 
3 import tempfile
4 from pathlib import Path
5 import shutil
6 
7 import acts
8 from acts.examples.simulation import (
9  addFatras,
10  addGeant4,
11  ParticleSelectorConfig,
12 )
13 
14 from physmon_common import makeSetup
15 
16 u = acts.UnitConstants
17 
18 setup = makeSetup()
19 
20 
21 with tempfile.TemporaryDirectory() as temp:
22  tp = Path(temp)
23 
24  rnd = acts.examples.RandomNumbers(seed=42)
25 
27  events=1000,
28  numThreads=1,
29  logLevel=acts.logging.INFO,
31  Path(__file__).parent.parent / "fpe_masks.yml"
32  ),
33  )
34 
35  for d in setup.decorators:
36  s.addContextDecorator(d)
37 
38  s.addReader(
39  acts.examples.EventGenerator(
40  level=acts.logging.INFO,
41  generators=[
42  acts.examples.EventGenerator.Generator(
43  multiplicity=acts.examples.FixedMultiplicityGenerator(n=1),
44  vertex=acts.examples.GaussianVertexGenerator(
45  mean=acts.Vector4(0, 0, 0, 0),
46  stddev=acts.Vector4(10 * u.um, 10 * u.um, 50 * u.mm, 1 * u.ns),
47  ),
48  particles=acts.examples.ParametricParticleGenerator(
49  p=(1 * u.GeV, 100 * u.GeV),
50  pTransverse=True,
51  eta=(-3.0, 3.0),
52  phi=(0.0 * u.degree, 360.0 * u.degree),
53  pdg=pdg,
54  randomizeCharge=True,
55  ),
56  )
57  for pdg in [
58  acts.PdgParticle.eMuon,
59  acts.PdgParticle.ePionPlus,
60  acts.PdgParticle.eElectron,
61  ]
62  ],
63  outputParticles="particles_input",
64  randomNumbers=rnd,
65  )
66  )
67 
68  addFatras(
69  s,
70  setup.trackingGeometry,
71  setup.field,
72  rnd,
73  enableInteractions=True,
74  preSelectParticles=None,
75  postSelectParticles=ParticleSelectorConfig(removeSecondaries=True),
76  inputParticles="particles_input",
77  outputParticlesInitial="particles_initial_fatras",
78  outputParticlesFinal="particles_final_fatras",
79  outputSimHits="simhits_fatras",
80  outputDirRoot=tp / "fatras",
81  )
82 
83  addGeant4(
84  s,
85  setup.detector,
86  setup.trackingGeometry,
87  setup.field,
88  rnd,
89  preSelectParticles=None,
90  postSelectParticles=ParticleSelectorConfig(removeSecondaries=True),
91  killVolume=setup.trackingGeometry.worldVolume,
92  killAfterTime=25 * u.ns,
93  killSecondaries=True,
94  inputParticles="particles_input",
95  outputParticlesInitial="particles_initial_geant4",
96  outputParticlesFinal="particles_final_geant4",
97  outputSimHits="simhits_geant4",
98  outputDirRoot=tp / "geant4",
99  )
100 
101  s.run()
102  del s
103 
104  for file, name in [
105  (tp / "fatras" / "particles_initial.root", "particles_initial_fatras.root"),
106  (tp / "fatras" / "particles_final.root", "particles_final_fatras.root"),
107  (tp / "geant4" / "particles_initial.root", "particles_initial_geant4.root"),
108  (tp / "geant4" / "particles_final.root", "particles_final_geant4.root"),
109  ]:
110  assert file.exists(), "file not found"
111  shutil.copy(file, setup.outdir / name)