Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
physmon_ckf_tracking.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file physmon_ckf_tracking.py
1 #!/usr/bin/env python3
2 import tempfile
3 from pathlib import Path
4 import shutil
5 
6 import acts
7 from acts.examples.simulation import (
8  addParticleGun,
9  MomentumConfig,
10  EtaConfig,
11  PhiConfig,
12  ParticleConfig,
13  addFatras,
14  addDigitization,
15 )
16 
17 from acts.examples.reconstruction import (
18  addSeeding,
19  TruthSeedRanges,
20  ParticleSmearingSigmas,
21  SeedFinderConfigArg,
22  SeedFinderOptionsArg,
23  SeedingAlgorithm,
24  TruthEstimatedSeedingAlgorithmConfigArg,
25  addCKFTracks,
26  addAmbiguityResolution,
27  AmbiguityResolutionConfig,
28  addVertexFitting,
29  VertexFinder,
30  TrackSelectorConfig,
31 )
32 
33 from physmon_common import makeSetup
34 
35 u = acts.UnitConstants
36 
37 setup = makeSetup()
38 
39 
40 def run_ckf_tracking(truthSmearedSeeded, truthEstimatedSeeded, label):
41  with tempfile.TemporaryDirectory() as temp:
43  events=500,
44  numThreads=-1,
45  logLevel=acts.logging.INFO,
47  Path(__file__).parent.parent / "fpe_masks.yml"
48  ),
49  )
50 
51  tp = Path(temp)
52 
53  for d in setup.decorators:
54  s.addContextDecorator(d)
55 
56  rnd = acts.examples.RandomNumbers(seed=42)
57 
59  s,
60  MomentumConfig(1.0 * u.GeV, 10.0 * u.GeV, transverse=True),
61  EtaConfig(-3.0, 3.0),
62  PhiConfig(0.0, 360.0 * u.degree),
63  ParticleConfig(4, acts.PdgParticle.eMuon, randomizeCharge=True),
64  vtxGen=acts.examples.GaussianVertexGenerator(
65  mean=acts.Vector4(0, 0, 0, 0),
66  stddev=acts.Vector4(
67  0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 1.0 * u.ns
68  ),
69  ),
70  multiplicity=50,
71  rnd=rnd,
72  )
73 
74  addFatras(
75  s,
76  setup.trackingGeometry,
77  setup.field,
78  enableInteractions=True,
79  rnd=rnd,
80  )
81 
83  s,
84  setup.trackingGeometry,
85  setup.field,
86  digiConfigFile=setup.digiConfig,
87  rnd=rnd,
88  )
89 
90  addSeeding(
91  s,
92  setup.trackingGeometry,
93  setup.field,
94  TruthSeedRanges(pt=(500 * u.MeV, None), nHits=(9, None)),
96  pRel=0.01
97  ), # only used by SeedingAlgorithm.TruthSmeared
99  r=(33 * u.mm, 200 * u.mm),
100  deltaR=(1 * u.mm, 60 * u.mm),
101  collisionRegion=(-250 * u.mm, 250 * u.mm),
102  z=(-2000 * u.mm, 2000 * u.mm),
103  maxSeedsPerSpM=1,
104  sigmaScattering=5,
105  radLengthPerSeed=0.1,
106  minPt=500 * u.MeV,
107  impactMax=3 * u.mm,
108  ),
109  SeedFinderOptionsArg(bFieldInZ=2 * u.T),
110  TruthEstimatedSeedingAlgorithmConfigArg(deltaR=(10.0 * u.mm, None)),
111  seedingAlgorithm=SeedingAlgorithm.TruthSmeared
112  if truthSmearedSeeded
113  else SeedingAlgorithm.TruthEstimated
114  if truthEstimatedSeeded
115  else SeedingAlgorithm.Default
116  if label == "seeded"
117  else SeedingAlgorithm.Orthogonal,
118  geoSelectionConfigFile=setup.geoSel,
119  rnd=rnd, # only used by SeedingAlgorithm.TruthSmeared
120  outputDirRoot=tp,
121  )
122 
123  addCKFTracks(
124  s,
125  setup.trackingGeometry,
126  setup.field,
128  pt=(500 * u.MeV, None),
129  loc0=(-4.0 * u.mm, 4.0 * u.mm),
130  nMeasurementsMin=6,
131  ),
132  outputDirRoot=tp,
133  )
134 
135  if label in ["seeded", "orthogonal"]:
137  s,
138  AmbiguityResolutionConfig(maximumSharedHits=3),
139  outputDirRoot=tp,
140  )
141 
143  s,
144  setup.field,
145  seeder=acts.VertexSeedFinder.GaussianSeeder,
146  outputProtoVertices="ivf_protovertices",
147  outputVertices="ivf_fittedVertices",
148  vertexFinder=VertexFinder.Iterative,
149  outputDirRoot=tp / "ivf",
150  )
151 
153  s,
154  setup.field,
155  seeder=acts.VertexSeedFinder.GaussianSeeder,
156  outputProtoVertices="amvf_protovertices",
157  outputVertices="amvf_fittedVertices",
158  vertexFinder=VertexFinder.AMVF,
159  outputDirRoot=tp / "amvf",
160  )
161 
162  # Use the adaptive grid vertex seeder in combination with the AMVF
163  # To avoid having too many physmon cases, we only do this for the label "seeded"
164  if label == "seeded":
166  s,
167  setup.field,
168  seeder=acts.VertexSeedFinder.AdaptiveGridSeeder,
169  outputProtoVertices="amvf_gridseeder_protovertices",
170  outputVertices="amvf_gridseeder_fittedVertices",
171  vertexFinder=VertexFinder.AMVF,
172  outputDirRoot=tp / "amvf_gridseeder",
173  )
174 
175  s.run()
176  del s
177 
178  for vertexing in ["ivf", "amvf"]:
179  shutil.move(
180  tp / f"{vertexing}/performance_vertexing.root",
181  tp / f"performance_{vertexing}.root",
182  )
183 
184  if label == "seeded":
185  vertexing = "amvf_gridseeder"
186  shutil.move(
187  tp / f"{vertexing}/performance_vertexing.root",
188  tp / f"performance_{vertexing}.root",
189  )
190 
191  for stem in (
192  [
193  "performance_ckf",
194  "tracksummary_ckf",
195  "performance_ivf",
196  "performance_amvf",
197  ]
198  + (["performance_amvf_gridseeder"] if label == "seeded" else [])
199  + (
200  ["performance_seeding", "performance_ambi"]
201  if label in ["seeded", "orthogonal"]
202  else ["performance_seeding"]
203  if label == "truth_estimated"
204  else []
205  )
206  ):
207  perf_file = tp / f"{stem}.root"
208  assert perf_file.exists(), "Performance file not found"
209  shutil.copy(perf_file, setup.outdir / f"{stem}_{label}.root")
210 
211 
212 for truthSmearedSeeded, truthEstimatedSeeded, label in [
213  (True, False, "truth_smeared"), # if first is true, second is ignored
214  (False, True, "truth_estimated"),
215  (False, False, "seeded"),
216  (False, False, "orthogonal"),
217 ]:
218  run_ckf_tracking(truthSmearedSeeded, truthEstimatedSeeded, label)