Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ckf_tracks.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ckf_tracks.py
1 #!/usr/bin/env python3
2 from pathlib import Path
3 from typing import Optional, Union
4 from collections import namedtuple
5 
6 from acts.examples import Sequencer, GenericDetector, RootParticleReader
7 
8 import acts
9 
10 from acts import UnitConstants as u
11 
12 
13 def runCKFTracks(
14  trackingGeometry,
15  decorators,
16  geometrySelection: Path,
17  digiConfigFile: Path,
18  field,
19  outputDir: Path,
20  truthSmearedSeeded=False,
21  truthEstimatedSeeded=False,
22  outputCsv=True,
23  inputParticlePath: Optional[Path] = None,
24  s=None,
25 ):
26 
27  from acts.examples.simulation import (
28  addParticleGun,
29  EtaConfig,
30  PhiConfig,
31  ParticleConfig,
32  addFatras,
33  addDigitization,
34  )
35 
36  from acts.examples.reconstruction import (
37  addSeeding,
38  TruthSeedRanges,
39  ParticleSmearingSigmas,
40  SeedFinderConfigArg,
41  SeedFinderOptionsArg,
42  SeedingAlgorithm,
43  TruthEstimatedSeedingAlgorithmConfigArg,
44  addCKFTracks,
45  )
46 
47  s = s or acts.examples.Sequencer(
48  events=100, numThreads=-1, logLevel=acts.logging.INFO
49  )
50  for d in decorators:
51  s.addContextDecorator(d)
52  rnd = acts.examples.RandomNumbers(seed=42)
53  outputDir = Path(outputDir)
54 
55  if inputParticlePath is None:
57  s,
58  EtaConfig(-2.0, 2.0),
59  ParticleConfig(4, acts.PdgParticle.eMuon, True),
60  PhiConfig(0.0, 360.0 * u.degree),
61  multiplicity=2,
62  rnd=rnd,
63  )
64  else:
65  acts.logging.getLogger("CKFExample").info(
66  "Reading particles from %s", inputParticlePath.resolve()
67  )
68  assert inputParticlePath.exists()
69  s.addReader(
70  RootParticleReader(
71  level=acts.logging.INFO,
72  filePath=str(inputParticlePath.resolve()),
73  particleCollection="particles_input",
74  orderedEvents=False,
75  )
76  )
77 
78  addFatras(
79  s,
80  trackingGeometry,
81  field,
82  rnd=rnd,
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  TruthSeedRanges(pt=(500.0 * u.MeV, None), nHits=(9, None)),
98  ParticleSmearingSigmas(pRel=0.01), # only used by SeedingAlgorithm.TruthSmeared
100  r=(None, 200 * u.mm), # rMin=default, 33mm
101  deltaR=(1 * u.mm, 60 * u.mm),
102  collisionRegion=(-250 * u.mm, 250 * u.mm),
103  z=(-2000 * u.mm, 2000 * u.mm),
104  maxSeedsPerSpM=1,
105  sigmaScattering=5,
106  radLengthPerSeed=0.1,
107  minPt=500 * u.MeV,
108  impactMax=3 * u.mm,
109  ),
110  SeedFinderOptionsArg(bFieldInZ=1.99724 * u.T, beamPos=(0.0, 0.0)),
111  TruthEstimatedSeedingAlgorithmConfigArg(deltaR=(10.0 * u.mm, None)),
112  seedingAlgorithm=SeedingAlgorithm.TruthSmeared
113  if truthSmearedSeeded
114  else SeedingAlgorithm.TruthEstimated
115  if truthEstimatedSeeded
116  else SeedingAlgorithm.Default,
117  geoSelectionConfigFile=geometrySelection,
118  outputDirRoot=outputDir,
119  rnd=rnd, # only used by SeedingAlgorithm.TruthSmeared
120  )
121 
122  addCKFTracks(
123  s,
124  trackingGeometry,
125  field,
126  outputDirRoot=outputDir,
127  outputDirCsv=outputDir / "csv" if outputCsv else None,
128  )
129 
130  return s
131 
132 
133 if "__main__" == __name__:
134  srcdir = Path(__file__).resolve().parent.parent.parent.parent
135 
136  detector, trackingGeometry, decorators = GenericDetector.create()
137 
138  field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
139 
140  inputParticlePath = Path("particles.root")
141  if not inputParticlePath.exists():
142  inputParticlePath = None
143 
144  runCKFTracks(
145  trackingGeometry,
146  decorators,
147  field=field,
148  geometrySelection=srcdir
149  / "Examples/Algorithms/TrackFinding/share/geoSelection-genericDetector.json",
150  digiConfigFile=srcdir
151  / "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json",
152  outputCsv=True,
153  truthSmearedSeeded=False,
154  truthEstimatedSeeded=False,
155  inputParticlePath=inputParticlePath,
156  outputDir=Path.cwd(),
157  ).run()