Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
full_chain_odd.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file full_chain_odd.py
1 #!/usr/bin/env python3
2 import os, argparse, pathlib, acts, acts.examples
3 from acts.examples.simulation import (
4  addParticleGun,
5  MomentumConfig,
6  EtaConfig,
7  PhiConfig,
8  ParticleConfig,
9  addPythia8,
10  addFatras,
11  addGeant4,
12  ParticleSelectorConfig,
13  addDigitization,
14 )
15 from acts.examples.reconstruction import (
16  addSeeding,
17  TruthSeedRanges,
18  addCKFTracks,
19  TrackSelectorConfig,
20  addAmbiguityResolution,
21  AmbiguityResolutionConfig,
22  addAmbiguityResolutionML,
23  AmbiguityResolutionMLConfig,
24  addVertexFitting,
25  VertexFinder,
26 )
27 from common import getOpenDataDetectorDirectory
28 from acts.examples.odd import getOpenDataDetector
29 
30 parser = argparse.ArgumentParser(description="Full chain with the OpenDataDetector")
31 
32 parser.add_argument("--events", "-n", help="Number of events", type=int, default=100)
33 parser.add_argument(
34  "--geant4", help="Use Geant4 instead of fatras", action="store_true"
35 )
36 parser.add_argument(
37  "--ttbar",
38  help="Use Pythia8 (ttbar, pile-up 200) instead of particle gun",
39  action="store_true",
40 )
41 parser.add_argument(
42  "--MLSolver",
43  help="Use the Ml Ambiguity Solver instead of the classical one",
44  action="store_true",
45 )
46 
47 args = vars(parser.parse_args())
48 
49 ttbar = args["ttbar"]
50 g4_simulation = args["geant4"]
51 ambiguity_MLSolver = args["MLSolver"]
52 u = acts.UnitConstants
54 outputDir = pathlib.Path.cwd() / "odd_output"
55 # acts.examples.dump_args_calls(locals()) # show python binding calls
56 
57 oddMaterialMap = geoDir / "data/odd-material-maps.root"
58 oddDigiConfig = geoDir / "config/odd-digi-smearing-config.json"
59 oddSeedingSel = geoDir / "config/odd-seeding-config.json"
60 oddMaterialDeco = acts.IMaterialDecorator.fromFile(oddMaterialMap)
61 
62 detector, trackingGeometry, decorators = getOpenDataDetector(
63  geoDir, mdecorator=oddMaterialDeco
64 )
65 field = acts.ConstantBField(acts.Vector3(0.0, 0.0, 2.0 * u.T))
66 rnd = acts.examples.RandomNumbers(seed=42)
67 
69  events=args["events"],
70  numThreads=1,
71  outputDir=str(outputDir),
72 )
73 
74 if not ttbar:
76  s,
77  MomentumConfig(1.0 * u.GeV, 10.0 * u.GeV, transverse=True),
78  EtaConfig(-3.0, 3.0),
79  PhiConfig(0.0, 360.0 * u.degree),
80  ParticleConfig(4, acts.PdgParticle.eMuon, randomizeCharge=True),
81  vtxGen=acts.examples.GaussianVertexGenerator(
82  mean=acts.Vector4(0, 0, 0, 0),
83  stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 1.0 * u.ns),
84  ),
85  multiplicity=200,
86  rnd=rnd,
87  )
88 else:
89  addPythia8(
90  s,
91  hardProcess=["Top:qqbar2ttbar=on"],
92  npileup=50,
93  vtxGen=acts.examples.GaussianVertexGenerator(
94  mean=acts.Vector4(0, 0, 0, 0),
95  stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns),
96  ),
97  rnd=rnd,
98  outputDirRoot=outputDir,
99  # outputDirCsv=outputDir,
100  )
101 if g4_simulation:
102  if s.config.numThreads != 1:
103  raise ValueError("Geant 4 simulation does not support multi-threading")
104 
105  # Pythia can sometime simulate particles outside the world volume, a cut on the Z of the track help mitigate this effect
106  # Older version of G4 might not work, this as has been tested on version `geant4-11-00-patch-03`
107  # For more detail see issue #1578
108  addGeant4(
109  s,
110  detector,
111  trackingGeometry,
112  field,
113  preSelectParticles=ParticleSelectorConfig(
114  rho=(0.0, 24 * u.mm),
115  absZ=(0.0, 1.0 * u.m),
116  eta=(-3.0, 3.0),
117  pt=(150 * u.MeV, None),
118  removeNeutral=True,
119  ),
120  outputDirRoot=outputDir,
121  # outputDirCsv=outputDir,
122  rnd=rnd,
123  killVolume=trackingGeometry.worldVolume,
124  killAfterTime=25 * u.ns,
125  )
126 else:
127  addFatras(
128  s,
129  trackingGeometry,
130  field,
131  preSelectParticles=ParticleSelectorConfig(
132  rho=(0.0, 24 * u.mm),
133  absZ=(0.0, 1.0 * u.m),
134  eta=(-3.0, 3.0),
135  pt=(150 * u.MeV, None),
136  removeNeutral=True,
137  )
138  if ttbar
139  else ParticleSelectorConfig(),
140  enableInteractions=True,
141  outputDirRoot=outputDir,
142  # outputDirCsv=outputDir,
143  rnd=rnd,
144  )
145 
147  s,
148  trackingGeometry,
149  field,
150  digiConfigFile=oddDigiConfig,
151  outputDirRoot=outputDir,
152  # outputDirCsv=outputDir,
153  rnd=rnd,
154 )
155 
156 addSeeding(
157  s,
158  trackingGeometry,
159  field,
160  TruthSeedRanges(pt=(1.0 * u.GeV, None), eta=(-3.0, 3.0), nHits=(9, None))
161  if ttbar
162  else TruthSeedRanges(),
163  geoSelectionConfigFile=oddSeedingSel,
164  outputDirRoot=outputDir,
165 )
166 
168  s,
169  trackingGeometry,
170  field,
172  pt=(1.0 * u.GeV if ttbar else 0.0, None),
173  absEta=(None, 3.0),
174  loc0=(-4.0 * u.mm, 4.0 * u.mm),
175  nMeasurementsMin=7,
176  ),
177  outputDirRoot=outputDir,
178  writeCovMat=True,
179  # outputDirCsv=outputDir,
180 )
181 
182 if ambiguity_MLSolver:
184  s,
186  maximumSharedHits=3, maximumIterations=1000000, nMeasurementsMin=7
187  ),
188  outputDirRoot=outputDir,
189  # outputDirCsv=outputDir,
190  onnxModelFile=os.path.dirname(__file__)
191  + "/MLAmbiguityResolution/duplicateClassifier.onnx",
192  )
193 else:
195  s,
197  maximumSharedHits=3, maximumIterations=1000000, nMeasurementsMin=7
198  ),
199  outputDirRoot=outputDir,
200  writeCovMat=True,
201  # outputDirCsv=outputDir,
202  )
203 
205  s,
206  field,
207  vertexFinder=VertexFinder.Iterative,
208  outputDirRoot=outputDir,
209 )
210 
211 s.run()