Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
truth_tracking_kalman.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file truth_tracking_kalman.py
1 #!/usr/bin/env python3
2 
3 from pathlib import Path
4 from typing import Optional
5 
6 import acts
7 import acts.examples
8 
9 u = acts.UnitConstants
10 
11 
13  trackingGeometry: acts.TrackingGeometry,
14  field: acts.MagneticFieldProvider,
15  digiConfigFile: Path,
16  outputDir: Path,
17  inputParticlePath: Optional[Path] = None,
18  decorators=[],
19  directNavigation=False,
20  reverseFilteringMomThreshold=0 * u.GeV,
21  s: acts.examples.Sequencer = None,
22 ):
23  from acts.examples.simulation import (
24  addParticleGun,
25  ParticleConfig,
26  EtaConfig,
27  PhiConfig,
28  MomentumConfig,
29  addFatras,
30  addDigitization,
31  )
32  from acts.examples.reconstruction import (
33  addSeeding,
34  SeedingAlgorithm,
35  TruthSeedRanges,
36  addKalmanTracks,
37  )
38 
39  s = s or acts.examples.Sequencer(
40  events=100, numThreads=-1, logLevel=acts.logging.INFO
41  )
42 
43  for d in decorators:
44  s.addContextDecorator(d)
45 
46  rnd = acts.examples.RandomNumbers(seed=42)
47  outputDir = Path(outputDir)
48 
49  if inputParticlePath is None:
51  s,
52  ParticleConfig(num=1, pdg=acts.PdgParticle.eMuon, randomizeCharge=True),
53  EtaConfig(-3.0, 3.0, uniform=True),
54  MomentumConfig(1.0 * u.GeV, 100.0 * u.GeV, transverse=True),
55  PhiConfig(0.0, 360.0 * u.degree),
56  vtxGen=acts.examples.GaussianVertexGenerator(
57  mean=acts.Vector4(0, 0, 0, 0),
58  stddev=acts.Vector4(0, 0, 0, 0),
59  ),
60  multiplicity=1,
61  rnd=rnd,
62  )
63  else:
64  acts.logging.getLogger("Truth tracking example").info(
65  "Reading particles from %s", inputParticlePath.resolve()
66  )
67  assert inputParticlePath.exists()
68  s.addReader(
69  acts.examples.RootParticleReader(
70  level=acts.logging.INFO,
71  filePath=str(inputParticlePath.resolve()),
72  particleCollection="particles_input",
73  orderedEvents=False,
74  )
75  )
76 
77  addFatras(
78  s,
79  trackingGeometry,
80  field,
81  rnd=rnd,
82  enableInteractions=True,
83  )
84 
86  s,
87  trackingGeometry,
88  field,
89  digiConfigFile=digiConfigFile,
90  rnd=rnd,
91  )
92 
93  addSeeding(
94  s,
95  trackingGeometry,
96  field,
97  rnd=rnd,
98  inputParticles="particles_input",
99  seedingAlgorithm=SeedingAlgorithm.TruthSmeared,
100  particleHypothesis=acts.ParticleHypothesis.muon,
101  truthSeedRanges=TruthSeedRanges(
102  pt=(1 * u.GeV, None),
103  nHits=(7, None),
104  ),
105  )
106 
108  s,
109  trackingGeometry,
110  field,
111  directNavigation,
112  reverseFilteringMomThreshold,
113  )
114 
115  s.addAlgorithm(
116  acts.examples.TrackSelectorAlgorithm(
117  level=acts.logging.INFO,
118  inputTracks="tracks",
119  outputTracks="selected-tracks",
120  selectorConfig=acts.TrackSelector.Config(
121  minMeasurements=7,
122  ),
123  )
124  )
125  s.addAlgorithm(
126  acts.examples.TracksToTrajectories(
127  level=acts.logging.INFO,
128  inputTracks="selected-tracks",
129  outputTrajectories="trajectories-from-tracks",
130  )
131  )
132  s.addWhiteboardAlias("trajectories", "trajectories-from-tracks")
133 
134  s.addWriter(
135  acts.examples.RootTrajectoryStatesWriter(
136  level=acts.logging.INFO,
137  inputTrajectories="trajectories",
138  inputParticles="truth_seeds_selected",
139  inputSimHits="simhits",
140  inputMeasurementParticlesMap="measurement_particles_map",
141  inputMeasurementSimHitsMap="measurement_simhits_map",
142  filePath=str(outputDir / "trackstates_fitter.root"),
143  )
144  )
145 
146  s.addWriter(
147  acts.examples.RootTrajectorySummaryWriter(
148  level=acts.logging.INFO,
149  inputTrajectories="trajectories",
150  inputParticles="truth_seeds_selected",
151  inputMeasurementParticlesMap="measurement_particles_map",
152  filePath=str(outputDir / "tracksummary_fitter.root"),
153  )
154  )
155 
156  s.addWriter(
157  acts.examples.TrackFitterPerformanceWriter(
158  level=acts.logging.INFO,
159  inputTrajectories="trajectories",
160  inputParticles="truth_seeds_selected",
161  inputMeasurementParticlesMap="measurement_particles_map",
162  filePath=str(outputDir / "performance_track_fitter.root"),
163  )
164  )
165 
166  return s
167 
168 
169 if "__main__" == __name__:
170  srcdir = Path(__file__).resolve().parent.parent.parent.parent
171 
172  # detector, trackingGeometry, _ = getOpenDataDetector()
173  detector, trackingGeometry, decorators = acts.examples.GenericDetector.create()
174 
175  field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
176 
178  trackingGeometry,
179  field,
180  digiConfigFile=srcdir
181  / "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json",
182  # "thirdparty/OpenDataDetector/config/odd-digi-smearing-config.json",
183  outputDir=Path.cwd(),
184  ).run()