ATLAS Offline Software
RecoConfigFlags.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 from AthenaConfiguration.AthConfigFlags import AthConfigFlags
3 from AthenaConfiguration.Enums import HIMode
4 _all_domains = [
5  "Trigger",
6  "BeamSpotDecoration",
7  "Calo", "Tracking",
8  "HGTDExtension",
9  "Muon", "CombinedMuon",
10  "Egamma",
11  "Isolation",
12  "CaloExtension",
13  "TrackCellAssociation",
14  "PFlow", "Jet", "BTagging",
15  "Tau",
16  "GlobalFELinking",
17  "Met",
18  "CaloRinger",
19  "AFP",
20  "HI",
21  "PostProcessing",
22  "TrackOverlay",
23 ]
24 
25 
27  """Return an AthConfigFlags object with required flags"""
28  flags = AthConfigFlags()
29 
30  # The various reconstruction domains/steps.
31  # Note that Calo and Muon System Reconstruction
32  # depend just on the Detector.EnableCalo and
33  # Detector.EnableMuon flags.
34 
35  # Enable Tracking Reconstruction
36  flags.addFlag("Reco.EnableTracking",
37  lambda prevFlags: prevFlags.Detector.EnableID or
38  prevFlags.Detector.EnableITk)
39  # Enable HGTD Reconstruction
40  flags.addFlag("Reco.EnableHGTDExtension",
41  lambda prevFlags: prevFlags.Reco.EnableTracking and
42  prevFlags.Detector.EnableHGTD)
43  # Enable Electron/Photon (EGamma) Reconstruction
44  flags.addFlag("Reco.EnableEgamma",
45  lambda prevFlags: prevFlags.Detector.EnableCalo)
46  # Enable Caching of InDet TrackParticles extension to
47  # Calorimeter. Used by (Muon,PFlow,Tau)
48  flags.addFlag("Reco.EnableCaloExtension", lambda prevFlags: (
49  (
50  prevFlags.Reco.EnablePFlow
51  or prevFlags.Reco.EnableTau
52  or prevFlags.Reco.EnableCombinedMuon
53  )
54  and prevFlags.Detector.EnableCalo
55  and prevFlags.Reco.EnableTracking))
56  # Enable Combined (InDet+MS) Muon Reconstruction
57  flags.addFlag("Reco.EnableCombinedMuon",
58  lambda prevFlags: prevFlags.Detector.EnableMuon and
59  prevFlags.Reco.EnableTracking)
60  # Enable TrackOverlay Reconstruction
61  flags.addFlag("Reco.EnableTrackOverlay", lambda prevFlags: False)
62  # Enable PFlow Reconstruction
63  flags.addFlag("Reco.EnablePFlow", lambda prevFlags: (
64  prevFlags.Reco.EnableTracking
65  and prevFlags.Detector.EnableCalo
66  and prevFlags.Tracking.doVertexFinding))
67  # Enable Isolation Reconstruction
68  flags.addFlag("Reco.EnableIsolation", lambda prevFlags: (
69  prevFlags.Tracking.doVertexFinding
70  and (prevFlags.Reco.EnableCombinedMuon
71  or prevFlags.Reco.EnableEgamma)))
72  # Enable Jet Reconstruction
73  flags.addFlag("Reco.EnableJet", lambda prevFlags: (
74  prevFlags.Detector.EnableCalo
75  and prevFlags.Reco.EnableTracking
76  and prevFlags.Reco.EnableEgamma
77  and prevFlags.Reco.EnableCombinedMuon
78  and prevFlags.Reco.EnablePFlow
79  and prevFlags.Reco.HIMode is not HIMode.HI))
80 
81  # Enable Tau Reconstruction
82  flags.addFlag("Reco.EnableTau", lambda prevFlags: prevFlags.Reco.EnableJet)
83  # Enable BTagging Reconstruction
84  flags.addFlag("Reco.EnableBTagging",
85  lambda prevFlags: prevFlags.Reco.EnableJet or
86  (prevFlags.Reco.EnableHI and prevFlags.HeavyIon.doJet))
87  # Enable MET Reconstruction
88  flags.addFlag("Reco.EnableMet", lambda prevFlags: (
89  prevFlags.Reco.EnableJet
90  and prevFlags.Reco.EnableTau))
91  # Enable the building of links between the newly
92  # created jet constituents (GlobalFE)
93  # and electrons,photons,muons and taus
94  flags.addFlag("Reco.EnableGlobalFELinking",
95  lambda prevFlags: prevFlags.Reco.EnableJet and
96  prevFlags.Reco.EnableTau and prevFlags.Reco.EnablePFlow and
97  prevFlags.Reco.EnableEgamma and
98  prevFlags.Reco.EnableCombinedMuon)
99  # Enable association of calorimeter cells to Tracks
100  flags.addFlag("Reco.EnableTrackCellAssociation",
101  lambda prevFlags: prevFlags.Detector.EnableCalo and
102  prevFlags.Reco.EnableTracking)
103  # Enable creation of "Rings" of calorimeter cells
104  flags.addFlag("Reco.EnableCaloRinger",
105  lambda prevFlags: prevFlags.Reco.EnableEgamma and
106  not prevFlags.Reco.EnableHI)
107 
108  # This flags enables trigger data decoding (not trigger simulation)
109  # EDMVersion > 0 check prevents this flag being true in jobs before
110  # the trigger has executed, or where it was not executed.
111  flags.addFlag("Reco.EnableTrigger",
112  lambda prevFlags: prevFlags.Trigger.EDMVersion > 0)
113 
114  # enable automatically for HI data
115  flags.addFlag("Reco.EnableHI",
116  lambda prevFlags: prevFlags.Reco.HIMode is not HIMode.pp)
117 
118  flags.addFlag("Reco.HIMode", _hiModeChoice, type=HIMode)
119 
120  # Enable alg for decorating EventInfo with BeamSpot info
121  # (maybe not always available for calibration runs, etc)
122  flags.addFlag("Reco.EnableBeamSpotDecoration",
123  lambda prevFlags: not prevFlags.Common.isOnline)
124 
125  # Enable ZDC reconstruction if ZDC data is in Bytestream or simulated
126  flags.addFlag("Reco.EnableZDC",_recoZDC)
127 
128  # Enable common thinning and other post-processing
129  flags.addFlag("Reco.EnablePostProcessing", True)
130  flags.addFlag("Reco.PostProcessing.ThinNegativeClusters",
131  lambda prevFlags: prevFlags.Reco.EnablePostProcessing and
132  prevFlags.Detector.EnableCalo and
133  prevFlags.Output.doWriteAOD and
134  prevFlags.Calo.Thin.NegativeEnergyCaloClusters and
135  not prevFlags.Reco.EnableHI)
136 
137  flags.addFlag("Reco.PostProcessing.TRTAloneThinning",
138  lambda prevFlags: prevFlags.Reco.EnablePostProcessing and
139  prevFlags.Reco.EnableTracking and
140  prevFlags.Output.doWriteAOD)
141  flags.addFlag("Reco.PostProcessing.GeantTruthThinning",
142  lambda prevFlags: prevFlags.Reco.EnablePostProcessing and
143  prevFlags.Input.isMC and
144  prevFlags.Output.doWriteAOD)
145  flags.addFlag("Reco.PostProcessing.InDetForwardTrackParticleThinning",
146  lambda prevFlags: prevFlags.Reco.EnablePostProcessing and
147  prevFlags.Reco.EnableTracking and
148  prevFlags.Reco.EnableCombinedMuon and
149  prevFlags.Output.doWriteAOD)
150  return flags
151 
152 
153 def printRecoFlags(flags):
154  # setup logging
155  from AthenaCommon.Logging import logging
156  log = logging.getLogger('RecoSteering')
157 
158  # load flags
159  flags._loadDynaFlags('Detector')
160  flags._loadDynaFlags('Reco')
161 
162  # generate common formatting string
163  item_len = 7
164  format_common = f'%-{item_len}s'
165 
166  domain_len = 7
167  for d in _all_domains:
168  domain_len = max(domain_len, len(d) + 2)
169 
170  enabled = []
171  for d in _all_domains:
172  if flags.hasFlag(f'Detector.Enable{d}'):
173  name = f'Detector.Enable{d}'
174  elif flags.hasFlag(f'Reco.Enable{d}'):
175  name = f'Reco.Enable{d}'
176  else:
177  raise RuntimeError(f'Unknown reconstruction domain {d}')
178 
179  if flags[name] is not False:
180  enabled.append('ON')
181  else:
182  enabled.append('--')
183 
184  format_header = f'%{domain_len}s ' + format_common
185  format = f'%{domain_len}s : ' + format_common
186  data = [_all_domains, enabled]
187  data = list(map(list, zip(*data)))
188 
189  # print header rows
190  log.info(format_header, *(['', 'Enbl.']))
191  # print data
192  for row in data:
193  log.info(format, *row)
194 
195 
196 def recoRunArgsToFlags(runArgs, flags):
197  if hasattr(runArgs, "runNumber") and not flags.Input.isMC and runArgs.runNumber not in flags.Input.RunNumbers:
198  flags.Input.RunNumbers = [runArgs.runNumber]
199  flags.Input.OverrideRunNumber = True
200 
201  if hasattr(runArgs, "projectName"):
202  flags.Input.projectName = runArgs.projectName
203 
204  # TODO: not handled yet
205  # --autoConfiguration
206  # --trigStream
207  # --topOptions
208  # --valid
209 
210  # --AMITag
211  # --userExec
212  # --triggerConfig
213  # --trigFilterList
214 
215 
216 def _recoZDC(prevFlags):
217  if prevFlags.Input.isMC:
218  return prevFlags.Detector.EnableZDC
219  else:
220  from AthenaConfiguration.AutoConfigFlags import GetFileMD
221  from libpyeformat_helper import SubDetector, DetectorMask
222  maskbits=GetFileMD(prevFlags.Input.Files).get("detectorMask",[0x0])
223  maskbits=maskbits[0] #Check the first input file
224  detMask=DetectorMask(maskbits & 0xFFFFFFFFFFFFFFFF, maskbits >> 64) #DetectorMask constructor swallows two 64bit ints
225  return detMask.is_set(SubDetector.FORWARD_ZDC)
226 
227 
228 
229 def _hiModeChoice(prevFlags):
230 
231  if ("_hip" in prevFlags.Input.ProjectName):
232  return HIMode.HIP
233  elif ("_hi" in prevFlags.Input.ProjectName):
234  if (prevFlags.Input.TriggerStream == "physics_UPC"):
235  return HIMode.UPC
236  else:
237  return HIMode.HI
238  return HIMode.pp
python.AutoConfigFlags.GetFileMD
def GetFileMD(filenames, allowEmpty=True, maxLevel='peeker')
Definition: AutoConfigFlags.py:65
python.RecoConfigFlags._hiModeChoice
def _hiModeChoice(prevFlags)
Definition: RecoConfigFlags.py:229
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
python.RecoConfigFlags.createRecoConfigFlags
def createRecoConfigFlags()
Definition: RecoConfigFlags.py:26
python.RecoConfigFlags.printRecoFlags
def printRecoFlags(flags)
Definition: RecoConfigFlags.py:153
python.RecoConfigFlags.recoRunArgsToFlags
def recoRunArgsToFlags(runArgs, flags)
Definition: RecoConfigFlags.py:196
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.RecoConfigFlags._recoZDC
def _recoZDC(prevFlags)
Definition: RecoConfigFlags.py:216
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127