Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
seeding.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file seeding.py
1 #!/usr/bin/env python3
2 from pathlib import Path
3 from enum import Enum
4 import argparse
5 
6 import acts
7 import acts.examples
8 
9 u = acts.UnitConstants
10 
11 # Graciously taken from https://stackoverflow.com/a/60750535/4280680
12 class EnumAction(argparse.Action):
13  """
14  Argparse action for handling Enums
15  """
16 
17  def __init__(self, **kwargs):
18  # Pop off the type value
19  enum_type = kwargs.pop("enum", None)
20 
21  # Ensure an Enum subclass is provided
22  if enum_type is None:
23  raise ValueError("type must be assigned an Enum when using EnumAction")
24  if not issubclass(enum_type, Enum):
25  raise TypeError("type must be an Enum when using EnumAction")
26 
27  # Generate choices from the Enum
28  kwargs.setdefault("choices", tuple(e.name for e in enum_type))
29 
30  super(EnumAction, self).__init__(**kwargs)
31 
32  self._enum = enum_type
33 
34  def __call__(self, parser, namespace, values, option_string=None):
35  for e in self._enum:
36  if e.name == values:
37  setattr(namespace, self.dest, e)
38  break
39  else:
40  raise ValueError("%s is not a validly enumerated algorithm." % values)
41 
42 
43 from acts.examples.reconstruction import SeedingAlgorithm
44 
45 
46 def runSeeding(
47  trackingGeometry,
48  field,
49  outputDir,
50  s=None,
51  seedingAlgorithm=SeedingAlgorithm.Default,
52 ):
53 
54  from acts.examples.simulation import (
55  addParticleGun,
56  EtaConfig,
57  PhiConfig,
58  ParticleConfig,
59  addFatras,
60  addDigitization,
61  )
62 
63  s = s or acts.examples.Sequencer(
64  events=100, numThreads=-1, logLevel=acts.logging.INFO
65  )
66  rnd = acts.examples.RandomNumbers(seed=42)
67  outputDir = Path(outputDir)
68 
70  s,
71  EtaConfig(-2.0, 2.0),
72  ParticleConfig(4, acts.PdgParticle.eMuon, True),
73  PhiConfig(0.0, 360.0 * u.degree),
74  multiplicity=2,
75  outputDirCsv=outputDir / "csv",
76  outputDirRoot=outputDir,
77  rnd=rnd,
78  )
79 
80  addFatras(
81  s,
82  trackingGeometry,
83  field,
84  outputDirCsv=outputDir / "csv",
85  outputDirRoot=outputDir,
86  rnd=rnd,
87  preSelectParticles=None,
88  )
89 
90  srcdir = Path(__file__).resolve().parent.parent.parent.parent
92  s,
93  trackingGeometry,
94  field,
95  digiConfigFile=srcdir
96  / "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json",
97  rnd=rnd,
98  )
99  from acts.examples.reconstruction import (
100  addSeeding,
101  TruthSeedRanges,
102  ParticleSmearingSigmas,
103  SeedFinderConfigArg,
104  SeedFinderOptionsArg,
105  )
106 
107  addSeeding(
108  s,
109  trackingGeometry,
110  field,
111  TruthSeedRanges(pt=(1.0 * u.GeV, None), eta=(-2.5, 2.5), nHits=(9, None)),
112  ParticleSmearingSigmas(pRel=0.01), # only used by SeedingAlgorithm.TruthSmeared
114  r=(None, 200 * u.mm), # rMin=default, 33mm
115  deltaR=(1 * u.mm, 60 * u.mm),
116  collisionRegion=(-250 * u.mm, 250 * u.mm),
117  z=(-2000 * u.mm, 2000 * u.mm),
118  maxSeedsPerSpM=1,
119  sigmaScattering=50,
120  radLengthPerSeed=0.1,
121  minPt=500 * u.MeV,
122  impactMax=3 * u.mm,
123  ),
125  bFieldInZ=1.99724 * u.T,
126  ),
127  acts.logging.VERBOSE,
128  seedingAlgorithm=seedingAlgorithm,
129  geoSelectionConfigFile=srcdir
130  / "Examples/Algorithms/TrackFinding/share/geoSelection-genericDetector.json",
131  inputParticles="particles_final", # use this to reproduce the original root_file_hashes.txt - remove to fix
132  outputDirRoot=outputDir,
133  )
134  return s
135 
136 
137 if "__main__" == __name__:
138  p = argparse.ArgumentParser(
139  description="Example script to run seed finding",
140  )
141 
142  p.add_argument(
143  "--algorithm",
144  action=EnumAction,
145  enum=SeedingAlgorithm,
146  default=SeedingAlgorithm.Default,
147  help="Select the seeding algorithm to use",
148  )
149 
150  args = p.parse_args()
151  # detector, trackingGeometry, _ = getOpenDataDetector( getOpenDataDetectorDirectory() )
152  detector, trackingGeometry, _ = acts.examples.GenericDetector.create()
153 
154  field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
155 
156  runSeeding(
157  trackingGeometry, field, outputDir=Path.cwd(), seedingAlgorithm=args.algorithm
158  ).run()