ATLAS Offline Software
parseRunArgs.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 '''
3 @file parseRunArgs.py
4 @author Riley Xu - riley.xu@cern.ch
5 @date July 30, 2020
6 @brief Configuration file that parses run arguments from transforms
7 
8 This file collects all transform run argument parsing into a centralized area
9 for configuring various FPGATrackSim transforms.
10 
11 Note that the parse functions return a dictionary that contain keys to correspond
12 to those in the various package tags. We don't want to use the tags directly here
13 to maintain good factorization. However, any changes to the tag keys must now be
14 copied to this file.
15 
16 Usage:
17  transform:
18  addFPGATrackSimBanksArgs(trf.parser)
19  skeleton:
20  opts = parseFPGATrackSimArgs(runArgs)
21  FPGATrackSimTagConfig.getTags(opts)
22 '''
23 
24 import itertools
25 import PyJobTransforms.trfArgClasses as trfArgClasses
26 from PyJobTransforms.trfLogger import msg
27 
28 
31 
32 _FPGATrackSimMapsArgs = [
33  ('mapTag', trfArgClasses.argString, 'Switch to a different tag than the default listed in FPGATrackSimMapTags'),
34  ('region', trfArgClasses.argString, 'Region index or name'),
35  ('pmap', trfArgClasses.argString, "plane map (first stage)"),
36  ('layerOverride', trfArgClasses.argIntList, "Overrides the selection of the 1st stage logical layers in the plane map. Each entry declares a detector layer to use as a logical layer. Specify a detector layer with { SilictonTech * 1000 + DetectorZone * 100 + PhysicalLayer }"),
37  ('rmap', trfArgClasses.argString, "region map"),
38  ('subrmap', trfArgClasses.argString, "Subregion (slice) map"),
39  ('NNmap', trfArgClasses.argString, "NN weighting map"),
40  ("sampleType", trfArgClasses.argString, "Specify the type of sample being used"),
41  ("withPU", trfArgClasses.argBool, "specify if sample has pile-up or not"),
42 ]
43 
44 
46  '''
47  Adds arguments used by FPGATrackSimMaps to a transform parser.
48  '''
49 
50  parser.defineArgGroup('FPGATrackSimMaps', 'Options for FPGATrackSimMaps. '
51  'These options will override the default configuration specified in FPGATrackSimMapTags.')
52 
53  def addArg(argName, argType, helpText=""):
54  parser.add_argument('--' + argName,
55  type=trfArgClasses.argFactory(argType, runarg=True),
56  help=helpText,
57  group='FPGATrackSimMaps')
58 
59  for arg in _FPGATrackSimMapsArgs:
60  addArg(*arg)
61 
62 
65 
66 _FPGATrackSimBanksArgs = [
67  ("bankTag", trfArgClasses.argString, "Switch to a different tag than the default listed in FPGATrackSimBankTags"),
68  ("bankDir", trfArgClasses.argString, "Common directory path to be prepended to all filenames below. If not all files are in the same directory, you can change bankDir to a common parent directory or just '' and use fully-qualified paths for the individual filenames."),
69  ("constants_1st", trfArgClasses.argString, "Filename of the 1st stage constants"),
70  ("constants_2nd", trfArgClasses.argString, "Filename of the 2nd stage constants"),
71  ("sectorBank_1st", trfArgClasses.argString, "Filename of the first stage sector bank"),
72  ("sectorBank_2nd", trfArgClasses.argString, "Filename of the second stage sector bank"),
73  ("sectorSlices", trfArgClasses.argString, "Filename of the sector slices")
74 ]
75 
76 
78  '''
79  Adds arguments used by FPGATrackSimBanks to a transform parser.
80  '''
81 
82  parser.defineArgGroup('FPGATrackSimBanks', 'Optional overrides for FPGATrackSimBanks. '
83  'These options will override the default configuration specified in FPGATrackSimBankTags.')
84 
85  def addArg(argName, argType, helpText=""):
86  parser.add_argument('--' + argName,
87  type=trfArgClasses.argFactory(argType, runarg=True),
88  help=helpText,
89  group='FPGATrackSimBanks')
90 
91  for arg in _FPGATrackSimBanksArgs:
92  addArg(*arg)
93 
94 
95 
98 
99 _FPGATrackSimAlgorithmsArgs = [
100  ("algoTag", trfArgClasses.argString, "Tag to use for algorithm configuration"),
101  ("FirstInputToolN", trfArgClasses.argInt, "number of times to reuse each event in first input tool, i.e. for overlaying"),
102  ("realHitsOverlay", trfArgClasses.argBool, "Use a second real hits tool"),
103  ("hough", trfArgClasses.argBool, "Use Hough transform for road finding"),
104  ("hough_1d", trfArgClasses.argBool, "Use Elliot's Hough transform for road finding"),
105  ("hough_d0phi0", trfArgClasses.argBool, "Use 2d accumulator in d0 vs phi0 for road finding"),
106  ("hough_rootoutput", trfArgClasses.argBool, "Output root output from the Hough transform"),
107  ("fastMon", trfArgClasses.argBool, "only do fast monitoring"),
108  ("canExtendHistRanges", trfArgClasses.argBool, "set kCanExtend bit on some monitoring histograms"),
109  ("HitFiltering", trfArgClasses.argBool, "do hit / cluster filtering"),
110  ("SpacePoints", trfArgClasses.argBool, "do spacepoint formation"),
111  ("SpacePointFiltering", trfArgClasses.argBool, "remove hits not part of a spacepoint"),
112  ("TrackNNAnalysis", trfArgClasses.argBool, "Do NN track filtering"),
113  ("doFastOR", trfArgClasses.argBool, "Use fast overlap removal algorithm instead of default"),
114  ("doTracking", trfArgClasses.argBool, "Do the track fitting"),
115  ("secondStage", trfArgClasses.argBool, "Run second stage fitting"),
116  ("EtaPatternRoadFilter", trfArgClasses.argString, "Apply a road filter"),
117  ("PhiRoadFilter", trfArgClasses.argString, "Turn on PhiRoad filter with window sizes given as a list of nLayers numbers"),
118  ("IdealCoordFitType", trfArgClasses.argInt, "Do ideal coordinate fits? 0 means don't do this, 1 means yes with 1st order correction, 2 means yes with 2nd order correction"),
119  ("DoDeltaGPhis", trfArgClasses.argBool, "Do the track fitting based on the Hough transform, idealized geometry and delta phis"),
120  ("outputHitTxt", trfArgClasses.argBool, "write out road hits to text file"),
121  ("barcodeFracMatch", trfArgClasses.argFloat, "barcode fraction at which we accept a truth match"),
122  ("writeOutputData", trfArgClasses.argBool, "write out Tree in the output file")
123 ]
124 
125 _FPGATrackSimHoughTransformArgs = [
126  ('phi_min', trfArgClasses.argFloat),
127  ('phi_max', trfArgClasses.argFloat),
128  ('qpt_min', trfArgClasses.argFloat),
129  ('qpt_max', trfArgClasses.argFloat),
130  ('d0_min', trfArgClasses.argFloat),
131  ('d0_max', trfArgClasses.argFloat),
132  ('d0_slices', trfArgClasses.argIntList, "Create separate accumulators for each of the specified d0"),
133  ('xBins', trfArgClasses.argInt),
134  ('yBins', trfArgClasses.argInt),
135  ('xBufferBins', trfArgClasses.argInt),
136  ('yBufferBins', trfArgClasses.argInt),
137  ('slicing', trfArgClasses.argBool),
138  ('IdealGeoRoads', trfArgClasses.argBool),
139  ('threshold', trfArgClasses.argIntList),
140  ('convolution', trfArgClasses.argIntList),
141  ('convSize_x', trfArgClasses.argInt),
142  ('convSize_y', trfArgClasses.argInt),
143  ('hitExtend_x', trfArgClasses.argString, "Hit lines will fill extra bins in x by this amount on each side, size == nLayers"),
144  ('roadSliceOR', trfArgClasses.argBool, "Do slice-wise road overlap removal"),
145  ('phiRangeCut', trfArgClasses.argBool),
146  ('localMaxWindowSize', trfArgClasses.argInt, "Only create roads that are a local maximum within this window size. Set this to 0 to turn off local max filtering"),
147  ("splitpt", trfArgClasses.argInt, "divide into multiple pt ranges"),
148  ("radiiFile", trfArgClasses.argString, "file with mean layer radii for Hough1D"),
149  ("fieldCorrection", trfArgClasses.argBool, "Apply corrections to hough equation due to field nonuniformity"),
150 ]
151 
152 _FPGATrackSimLRTArgs = [
153  ('lrt', trfArgClasses.argBool, "Enable LRT stage"),
154  ('lrt_use_basicHitFilter', trfArgClasses.argBool, "Enable basic hits filtering"),
155  ('lrt_use_mlHitFilter', trfArgClasses.argBool, "Enable ML ts filtering"),
156  ('lrt_use_straightTrackHT', trfArgClasses.argBool, "Use stright track approximation HT"),
157  ('lrt_use_doubletHT', trfArgClasses.argBool, "Use hits doublet HT"),
158  ('lrt_skip_hit_filtering', trfArgClasses.argBool, "Skip hit filtering"),
159  ('lrt_straighttrack_slicing', trfArgClasses.argBool, "Turn off slicing for straight track HT"),
160  ('lrt_doublet_d0_range', trfArgClasses.argFloat, "coverage in d0"),
161  ('lrt_doublet_d0_bins', trfArgClasses.argInt, "number of bins in d0 dimenstion"),
162  ('lrt_doublet_qpt_range', trfArgClasses.argFloat, "coverage of q/pT - effectively min pt limit"),
163  ('lrt_doublet_qpt_bins', trfArgClasses.argInt, "number of bins in q/pt"),
164  ('lrt_ptmin',trfArgClasses.argFloat, "minimum pT to use in evaluating efficiencies"),
165  ('m_LRT_pdgID',trfArgClasses.argInt, "if only some PDGID desired in truth matching, add it here."),
166  ('allowHighTruthBarcode', trfArgClasses.argBool, "Allow truth matching to take place for truth particles with barcodes > 200000. This is important for some LLP samples where the LLP decays in Geant.")
167  #TODO add options for stright track HT and hit filter tools
168 ]
169 
171  '''
172  Adds arguments used by FPGATrackSimAlgorithms to a transform parser.
173  '''
174 
175  parser.defineArgGroup('FPGATrackSimAlgorithms', 'Options for FPGATrackSimAlgorithms configuration')
176  parser.defineArgGroup('FPGATrackSimHoughTransform', 'Options for FPGATrackSim Hough transform')
177  parser.defineArgGroup('FPGATrackSimLRT', 'Options for FPGATrackSim Hough transform')
178 
179  def addArg(group, argName, argType, helpText=""):
180  parser.add_argument('--' + argName,
181  type=trfArgClasses.argFactory(argType, runarg=True),
182  help=helpText,
183  group=group)
184 
185  for arg in _FPGATrackSimAlgorithmsArgs:
186  addArg('FPGATrackSimAlgorithms', *arg)
187 
188  for arg in _FPGATrackSimHoughTransformArgs:
189  addArg('FPGATrackSimHoughTransform', *arg)
190 
191  for arg in _FPGATrackSimLRTArgs:
192  addArg('FPGATrackSimLRT', *arg)
193 
194 _FPGATrackSimHitFilteringArgs = [
195  ('doRandomRemoval', trfArgClasses.argBool),
196  ('pixelHitRmFrac', trfArgClasses.argFloat),
197  ('pixelClusRmFrac', trfArgClasses.argFloat),
198  ('stripHitRmFrac', trfArgClasses.argFloat),
199  ('stripClusRmFrac', trfArgClasses.argFloat),
200 
201  ('doStubs', trfArgClasses.argBool),
202  ('stubCutsFile', trfArgClasses.argString),
203  ('barrelStubDphiCut', trfArgClasses.argFloat),
204  ('endcapStubDphiCut', trfArgClasses.argFloat),
205  ('useNstrips', trfArgClasses.argBool),
206 ]
207 
209  '''
210  Adds arguments used by FPGATrackSimHitFiltering to a transform parser.
211  '''
212 
213  parser.defineArgGroup('FPGATrackSimHitFiltering', 'Options for FPGATrackSimHitFiltering configuration')
214 
215  def addArg(group, argName, argType, helpText=""):
216  parser.add_argument('--' + argName,
217  type=trfArgClasses.argFactory(argType, runarg=True),
218  help=helpText,
219  group=group)
220 
221  for arg in _FPGATrackSimHitFilteringArgs:
222  addArg('FPGATrackSimHitFiltering', *arg)
223 
224 
225 
226 
229 
231  '''
232  Collects FPGATrackSim arguments from runArgs into a dictionary of (parameter: value) pairs.
233  Use the corresponding add***Args() functions above to add arguments to a transform parser.
234  '''
235  opts = {}
236  for arg in itertools.chain(_FPGATrackSimMapsArgs, _FPGATrackSimBanksArgs, _FPGATrackSimAlgorithmsArgs, _FPGATrackSimHoughTransformArgs, _FPGATrackSimHitFilteringArgs, _FPGATrackSimLRTArgs):
237  key = arg[0]
238  if hasattr(runArgs, key):
239  opts[key] = getattr(runArgs, key)
240  msg.info("Final pars: ", opts)
241  return opts
python.parseRunArgs.addFPGATrackSimHitFilteringArgs
def addFPGATrackSimHitFilteringArgs(parser)
Definition: parseRunArgs.py:208
PyJobTransforms.trfArgClasses
Transform argument class definitions.
python.trfArgClasses.argFloat
Float type argument.
Definition: trfArgClasses.py:261
python.parseRunArgs.parseFPGATrackSimArgs
def parseFPGATrackSimArgs(runArgs)
Parsing.
Definition: parseRunArgs.py:230
python.trfArgClasses.argFactory
Factory class used to generate argument class instances for argparse.
Definition: trfArgClasses.py:31
python.trfArgClasses.argBool
Boolean type argument.
Definition: trfArgClasses.py:317
python.parseRunArgs.addFPGATrackSimBanksArgs
def addFPGATrackSimBanksArgs(parser)
Definition: parseRunArgs.py:77
python.trfArgClasses.argString
String type argument.
Definition: trfArgClasses.py:174
python.parseRunArgs.addFPGATrackSimAlgorithmsArgs
def addFPGATrackSimAlgorithmsArgs(parser)
Definition: parseRunArgs.py:170
python.parseRunArgs.addFPGATrackSimMapsArgs
def addFPGATrackSimMapsArgs(parser)
Definition: parseRunArgs.py:45
PyJobTransforms.trfLogger
Logging configuration for ATLAS job transforms.
python.trfArgClasses.argIntList
List of int arguments.
Definition: trfArgClasses.py:414
python.trfArgClasses.argInt
Int type argument.
Definition: trfArgClasses.py:225