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