Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
truth_tracking_gx2f.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file truth_tracking_gx2f.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  outputDir: Path,
16  digiConfigFile: Path,
17  s: acts.examples.Sequencer = None,
18  inputParticlePath: Optional[Path] = None,
19 ):
20  from acts.examples.simulation import (
21  addParticleGun,
22  MomentumConfig,
23  EtaConfig,
24  ParticleConfig,
25  addFatras,
26  addDigitization,
27  )
28  from acts.examples.reconstruction import (
29  addSeeding,
30  SeedingAlgorithm,
31  TruthSeedRanges,
32  addGx2fTracks,
33  )
34 
35  s = s or acts.examples.Sequencer(
36  events=10000, numThreads=-1, logLevel=acts.logging.INFO
37  )
38 
39  rnd = acts.examples.RandomNumbers()
40  outputDir = Path(outputDir)
41 
42  if inputParticlePath is None:
44  s,
45  MomentumConfig(100.0 * u.GeV, 100.0 * u.GeV, transverse=True),
46  EtaConfig(-2.0, 2.0),
47  ParticleConfig(2, acts.PdgParticle.eMuon, False),
48  multiplicity=1,
49  rnd=rnd,
50  outputDirRoot=outputDir,
51  )
52  else:
53  acts.logging.getLogger("Truth tracking example").info(
54  "Reading particles from %s", inputParticlePath.resolve()
55  )
56  assert inputParticlePath.exists()
57  s.addReader(
58  RootParticleReader(
59  level=acts.logging.INFO,
60  filePath=str(inputParticlePath.resolve()),
61  particleCollection="particles_input",
62  orderedEvents=False,
63  )
64  )
65 
66  addFatras(
67  s,
68  trackingGeometry,
69  field,
70  rnd=rnd,
71  enableInteractions=True,
72  )
73 
75  s,
76  trackingGeometry,
77  field,
78  digiConfigFile=digiConfigFile,
79  rnd=rnd,
80  )
81 
82  addSeeding(
83  s,
84  trackingGeometry,
85  field,
86  seedingAlgorithm=SeedingAlgorithm.TruthSmeared,
87  rnd=rnd,
88  truthSeedRanges=TruthSeedRanges(
89  pt=(1 * u.GeV, None),
90  nHits=(9, None),
91  ),
92  )
93 
95  s,
96  trackingGeometry,
97  field,
98  # directNavigation,
99  )
100 
101  # Output
102  s.addWriter(
103  acts.examples.RootTrajectoryStatesWriter(
104  level=acts.logging.INFO,
105  inputTrajectories="trajectories",
106  inputParticles="truth_seeds_selected",
107  inputSimHits="simhits",
108  inputMeasurementParticlesMap="measurement_particles_map",
109  inputMeasurementSimHitsMap="measurement_simhits_map",
110  filePath=str(outputDir / "trackstates_fitter.root"),
111  )
112  )
113 
114  s.addWriter(
115  acts.examples.RootTrajectorySummaryWriter(
116  level=acts.logging.INFO,
117  inputTrajectories="trajectories",
118  inputParticles="truth_seeds_selected",
119  inputMeasurementParticlesMap="measurement_particles_map",
120  filePath=str(outputDir / "tracksummary_fitter.root"),
121  )
122  )
123 
124  # TODO: PerformanceWriters are not tested yet
125  # s.addWriter(
126  # acts.examples.TrackFinderPerformanceWriter(
127  # level=acts.logging.INFO,
128  # inputProtoTracks="truth_particle_tracks",
129  # inputParticles="truth_seeds_selected",
130  # inputMeasurementParticlesMap="measurement_particles_map",
131  # filePath=str(outputDir / "performance_track_finder.root"),
132  # )
133  # )
134  #
135  # s.addWriter(
136  # acts.examples.TrackFitterPerformanceWriter(
137  # level=acts.logging.INFO,
138  # inputTrajectories="trajectories",
139  # inputParticles="truth_seeds_selected",
140  # inputMeasurementParticlesMap="measurement_particles_map",
141  # filePath=str(outputDir / "performance_track_fitter.root"),
142  # )
143  # )
144 
145  return s
146 
147 
148 if "__main__" == __name__:
149  srcdir = Path(__file__).resolve().parent.parent.parent.parent
150 
151  # detector, trackingGeometry, _ = getOpenDataDetector()
152  detector, trackingGeometry, decorators = acts.examples.GenericDetector.create()
153 
154  field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
155 
157  trackingGeometry=trackingGeometry,
158  # decorators=decorators,
159  field=field,
160  digiConfigFile=srcdir
161  / "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json",
162  # "thirdparty/OpenDataDetector/config/odd-digi-smearing-config.json",
163  # outputCsv=True,
164  # inputParticlePath=inputParticlePath,
165  outputDir=Path.cwd(),
166  ).run()