ATLAS Offline Software
Functions | Variables
python.OverlayMetadata Namespace Reference

Functions

def validateGeometryTag (logger, target, value)
 
def overlayInputMetadataCheck (flags, simDict, tagInfoDict)
 
def simulationMetadataCheck (sigdict, pudict)
 
def tagInfoMetadataCheck (sigdict, pudict)
 
def overlayMetadataCheck (flags)
 
def fastChainOverlayMetadataCheck (flags)
 
def writeOverlayDigitizationMetadata (flags, pileupDict)
 

Variables

 logger
 

Function Documentation

◆ fastChainOverlayMetadataCheck()

def python.OverlayMetadata.fastChainOverlayMetadataCheck (   flags)
Check fastchain overlay metadata

Definition at line 212 of file OverlayMetadata.py.

213  """Check fastchain overlay metadata"""
214  if flags.Overlay.ByteStream:
215  filesPileup = flags.Input.SecondaryFiles
216  else:
217  filesPileup = flags.Input.Files
218 
219  # pile-up check
220  if not flags.Overlay.DataOverlay and filesPileup:
221  pileupMetaDataCheck = GetFileMD(filesPileup, maxLevel="full")
222  pileupDigitizationMetadata = pileupMetaDataCheck.get("/Digitization/Parameters", {})
223  pileupSimulationMetadata = pileupMetaDataCheck.get("/Simulation/Parameters", {})
224  pileupTagInfoMetadata = pileupMetaDataCheck.get("/TagInfo", {})
225 
226  logger.info("Checking Presampled pile-up metadata against configuration of jobs (i.e. flags)...")
227  overlayInputMetadataCheck(flags, pileupSimulationMetadata, pileupTagInfoMetadata)
228  logger.info("Completed all checks against Presampled pile-up Simulation metadata.")
229 
230  if pileupDigitizationMetadata:
231  writeOverlayDigitizationMetadata(flags,pileupDigitizationMetadata)
232 
233 

◆ overlayInputMetadataCheck()

def python.OverlayMetadata.overlayInputMetadataCheck (   flags,
  simDict,
  tagInfoDict 
)
Check the metadata for signal HITS or presampled pileup RDO file

Definition at line 28 of file OverlayMetadata.py.

28 def overlayInputMetadataCheck(flags, simDict, tagInfoDict):
29  """Check the metadata for signal HITS or presampled pileup RDO file"""
30  logger.info("Checking Overlay configuration against Signal or presampled pileup RDO metadata...")
31 
32  simKeys = simDict.keys()
33  tagInfoKeys = tagInfoDict.keys()
34 
35  # Check the PhysicsList set agrees with that used in the simulation
36  if "PhysicsList" in simKeys:
37  if re.match(simDict["PhysicsList"], flags.Sim.PhysicsList):
38  logger.debug("Overlay configuration matches Signal Simulation metadata. [Sim.PhysicsList = %s]", flags.Sim.PhysicsList)
39  else:
40  flags.Sim.PhysicsList = simDict["PhysicsList"]
41  logger.warning("Overlay Sim.PhysicsList does not match the PhysicsList used in the Signal Simulation step! Assume the value from the Signal Simulation step is correct!")
42  logger.warning("Set Sim.PhysicsList = %s", flags.Sim.PhysicsList)
43  else:
44  logger.error("'PhysicsList' key not found in Signal Simulation metadata!")
45  raise AssertionError("Signal Simulation metadata key not found")
46 
47  # Check the DetDescrVersion set agrees with that used in the simulation
48  if "SimLayout" in simKeys:
49  if validateGeometryTag(logger, simDict["SimLayout"], flags.GeoModel.AtlasVersion):
50  logger.debug("Overlay configuration matches Signal Simulation metadata. [Geomodel.AtlasVersion = %s]",
51  flags.GeoModel.AtlasVersion)
52  else:
53  flags.GeoModel.AtlasVersion = simDict["SimLayout"]
54  logger.warning("Overlay Geomodel.AtlasVersion does not match the value used in the Signal Simulation step! Assume the value from the Signal Simulation step is correct!")
55  logger.warning("Set Geomodel.AtlasVersion = %s", flags.GeoModel.AtlasVersion)
56  else:
57  logger.error("'SimLayout' key not found in Signal Simulation metadata!")
58  raise AssertionError("Signal Simulation metadata key not found")
59 
60  # Check the Conditions Tag set against that used in the simulation
61  if "IOVDbGlobalTag" in tagInfoKeys:
62  if not re.match(tagInfoDict["IOVDbGlobalTag"], flags.IOVDb.GlobalTag):
63  logger.debug("Overlay configuration: [IOVDb.GlobalTag = %s], Signal Simulation metadata: [IOVDb.GlobalTag = %s]",
64  flags.IOVDb.GlobalTag, tagInfoDict['IOVDbGlobalTag'])
65  else:
66  logger.error("'IOVDbGlobalTag' key not found in Signal Simulation metadata!")
67  raise AssertionError("Signal Simulation metadata key not found")
68 
69  # Set the TRTRangeCut digitizationFlag based on what was used during the simulation.
70  if "TRTRangeCut" in simKeys:
71  if not re.match(simDict["TRTRangeCut"], str(flags.Sim.TRTRangeCut)):
72  flags.Sim.TRTRangeCut = simDict["TRTRangeCut"]
73  logger.warning("Overlay Sim.TRTRangeCut does not match the value used in the Signal Simulation step! Assume the value from the Signal Simulation step is correct!")
74  logger.warning("Set Sim.TRTRangeCut = %s", flags.Sim.TRTRangeCut)
75  else:
76  logger.warning("'TRTRangeCut' key not found in Signal Simulation metadata!")
77 
78  # Check which sub-detectors were simulated
79  # TODO: needed?
80 
81  logger.info("Completed checks of Overlay configuration against Signal Simulation metadata.")
82 
83 

◆ overlayMetadataCheck()

def python.OverlayMetadata.overlayMetadataCheck (   flags)
Check overlay metadata

Definition at line 176 of file OverlayMetadata.py.

176 def overlayMetadataCheck(flags):
177  """Check overlay metadata"""
178  if flags.Overlay.ByteStream:
179  files = flags.Input.Files
180  filesPileup = flags.Input.SecondaryFiles
181  else:
182  files = flags.Input.SecondaryFiles
183  filesPileup = flags.Input.Files
184 
185  if files:
186  signalMetadata = GetFileMD(files, maxLevel="full")
187  signalSimulationMetadata = signalMetadata.get("/Simulation/Parameters", {})
188  signalTagInfoMetadata = signalMetadata.get("/TagInfo", {})
189  # signal check
190  overlayInputMetadataCheck(flags, signalSimulationMetadata, signalTagInfoMetadata)
191  else:
192  # This can be the case for the FastChain with overlay
193  # It is not an error.
194  logger.info("Simulation metadata check not done due to no inputs")
195 
196  # pile-up check
197  if not flags.Overlay.DataOverlay and filesPileup:
198  pileupMetaDataCheck = GetFileMD(filesPileup, maxLevel="full")
199  pileupDigitizationMetadata = pileupMetaDataCheck.get("/Digitization/Parameters", {})
200  pileupSimulationMetadata = pileupMetaDataCheck.get("/Simulation/Parameters", {})
201  pileupTagInfoMetadata = pileupMetaDataCheck.get("/TagInfo", {})
202 
203  logger.info("Checking Presampled pile-up metadata against Signal Simulation metadata...")
204  simulationMetadataCheck(signalSimulationMetadata, pileupSimulationMetadata)
205  tagInfoMetadataCheck(signalTagInfoMetadata, pileupTagInfoMetadata)
206  logger.info("Completed all checks against Presampled pile-up Simulation metadata.")
207 
208  if pileupDigitizationMetadata:
209  writeOverlayDigitizationMetadata(flags,pileupDigitizationMetadata)
210 
211 

◆ simulationMetadataCheck()

def python.OverlayMetadata.simulationMetadataCheck (   sigdict,
  pudict 
)
Check the simulation metadata for presampled pileup RDO file

Definition at line 84 of file OverlayMetadata.py.

84 def simulationMetadataCheck(sigdict, pudict):
85  """Check the simulation metadata for presampled pileup RDO file"""
86  sigkeys = sigdict.keys()
87  pukeys = pudict.keys()
88 
89  # Loop over metadata keys which must have matching values
90  warningKeys = ['G4Version']
91  sigKeysToCheck = ['PhysicsList', 'SimLayout', 'MagneticField', 'hitFileMagicNumber'] + warningKeys
92  for o in sigKeysToCheck:
93  try:
94  assert o in pukeys
95  except AssertionError:
96  logger.error("%s key missing from Presampled pile-up Simulation metadata!", o)
97  raise AssertionError("Presampled pile-up Simulation metadata key not found")
98  try:
99  assert o in sigkeys
100  except AssertionError:
101  logger.error("%s key missing from Signal Simulation metadata!", o)
102  raise AssertionError("Signal Simulation metadata key not found")
103  try:
104  if o == "SimLayout": # allow last part of the simulation tag to differ
105  assert validateGeometryTag(logger, sigdict[o], pudict[o])
106  elif not isinstance(pudict[o], type(sigdict[o])):
107  assert re.match(str(pudict[o]), str(sigdict[o]))
108  else:
109  if isinstance(pudict[o], str):
110  assert re.match(pudict[o], sigdict[o])
111  elif isinstance(pudict[o], int):
112  assert (pudict[o] == sigdict[o])
113  else:
114  assert re.match(str(pudict[o]), str(sigdict[o]))
115  except AssertionError:
116  if o in warningKeys:
117  logger.warning("Simulation metadata mismatch! Presampled pile-up: [%s = %s] Signal: [%s = %s]", o, pudict[o], o, sigdict[o])
118  else:
119  logger.error("Simulation metadata mismatch! Presampled pile-up: [%s = %s] Signal: [%s = %s]", o, pudict[o], o, sigdict[o])
120  raise AssertionError("Simulation metadata mismatch")
121 
122 

◆ tagInfoMetadataCheck()

def python.OverlayMetadata.tagInfoMetadataCheck (   sigdict,
  pudict 
)
Check the tag info metadata for presampled pileup RDO File

Definition at line 123 of file OverlayMetadata.py.

123 def tagInfoMetadataCheck(sigdict, pudict):
124  """Check the tag info metadata for presampled pileup RDO File"""
125  sigkeys = sigdict.keys()
126  pukeys = pudict.keys()
127 
128  logger.debug("Signal /TagInfo ", sigdict)
129  logger.debug("Pileup /TagInfo ", pudict)
130 
131  sigOnlyDict = dict()
132  sigOnlyKeySet = set(sigkeys).difference(set(pukeys))
133  logger.debug("The following keys only appear in Signal /TagInfo metadata:")
134  logger.debug(sigOnlyKeySet)
135  for key in sigOnlyKeySet:
136  sigOnlyDict[key] = sigdict[key]
137  logger.debug(" key: ", key, "value: ", sigdict[key])
138  pass
139  # TODO: extra
140  keysToCompareSet = set(sigkeys).intersection(set(pukeys))
141  logger.debug("The following keys appear in Signal and Presampled pile-up /TagInfo metadata:")
142  logger.debug(keysToCompareSet)
143 
144  # Loop over metadata keys which must have matching values
145  warningKeys = ['IOVDbGlobalTag']
146  sigKeysToCheck = warningKeys
147  for o in sigKeysToCheck:
148  try:
149  assert o in pukeys
150  except AssertionError:
151  logger.error("%s key missing from Presampled pile-up Simulation metadata!", o)
152  raise AssertionError("Presampled pile-up Simulation metadata key not found")
153  try:
154  assert o in sigkeys
155  except AssertionError:
156  logger.error("%s key missing from Signal Simulation metadata!", o)
157  raise AssertionError("Signal Simulation metadata key not found")
158  try:
159  if not isinstance(pudict[o], type(sigdict[o])):
160  assert re.match(str(pudict[o]), str(sigdict[o]))
161  else:
162  if isinstance(pudict[o], str):
163  assert re.match(pudict[o], sigdict[o])
164  elif isinstance(pudict[o], int):
165  assert (pudict[o] == sigdict[o])
166  else:
167  assert re.match(str(pudict[o]), str(sigdict[o]))
168  except AssertionError:
169  if o in warningKeys:
170  logger.warning("Simulation metadata mismatch! Presampled pile-up: [%s = %s] Signal: [%s = %s]", o, pudict[o], o, sigdict[o])
171  else:
172  logger.error("Simulation metadata mismatch! Presampled pile-up: [%s = %s] Signal: [%s = %s]", o, pudict[o], o, sigdict[o])
173  raise AssertionError("Simulation metadata mismatch")
174 
175 

◆ validateGeometryTag()

def python.OverlayMetadata.validateGeometryTag (   logger,
  target,
  value 
)
Validate geometry tag so it is the same as target

Definition at line 11 of file OverlayMetadata.py.

11 def validateGeometryTag(logger, target, value):
12  """Validate geometry tag so it is the same as target"""
13  target_layout = target.split('-')
14  value_layout = value.split('-')
15  if len(target_layout) != len(value_layout):
16  return False
17 
18  for p, s in zip(target_layout[:-1], value_layout[:-1]):
19  if not re.match(p, s):
20  return False
21 
22  if not re.match(target_layout[-1], value_layout[-1]):
23  logger.warning("Simulation geometry tag mismatch! %s vs %s", target, value)
24 
25  return True
26 
27 

◆ writeOverlayDigitizationMetadata()

def python.OverlayMetadata.writeOverlayDigitizationMetadata (   flags,
  pileupDict 
)

Definition at line 234 of file OverlayMetadata.py.

234 def writeOverlayDigitizationMetadata(flags,pileupDict):
235  from IOVDbMetaDataTools import ParameterDbFiller
236  dbFiller = ParameterDbFiller.ParameterDbFiller()
237  runNumber = flags.Input.RunNumbers[0]
238  runNumberEnd = flags.Input.RunNumbers[-1]
239  if runNumberEnd == runNumber:
240  runNumberEnd += 1
241  logger.debug('ParameterDbFiller BeginRun = %s', str(runNumber) )
242  dbFiller.setBeginRun(runNumber)
243  logger.debug('ParameterDbFiller EndRun = %s', str(runNumberEnd) )
244  dbFiller.setEndRun(runNumberEnd)
245 
246  logger.info('Filling Digitization MetaData')
247 
248  # Copy over pileup dictionary
249  for key in pileupDict:
250  value = str(pileupDict[key])
251  logger.info('DigitizationMetaData: setting "%s" to be %s', key, value)
252  if key in ["BeamIntensityPattern"]:
253  dbFiller.addDigitParam64(key, value)
254  else:
255  dbFiller.addDigitParam(key, value)
256 
257  # Make the MetaData Db
258  dbFiller.genDigitDb()

Variable Documentation

◆ logger

python.OverlayMetadata.logger

Definition at line 8 of file OverlayMetadata.py.

python.AutoConfigFlags.GetFileMD
def GetFileMD(filenames, allowEmpty=True, maxLevel='peeker')
Definition: AutoConfigFlags.py:65
python.OverlayMetadata.overlayMetadataCheck
def overlayMetadataCheck(flags)
Definition: OverlayMetadata.py:176
python.OverlayMetadata.validateGeometryTag
def validateGeometryTag(logger, target, value)
Definition: OverlayMetadata.py:11
intersection
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
Definition: compareFlatTrees.cxx:25
python.OverlayMetadata.simulationMetadataCheck
def simulationMetadataCheck(sigdict, pudict)
Definition: OverlayMetadata.py:84
python.OverlayMetadata.fastChainOverlayMetadataCheck
def fastChainOverlayMetadataCheck(flags)
Definition: OverlayMetadata.py:212
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
python.OverlayMetadata.tagInfoMetadataCheck
def tagInfoMetadataCheck(sigdict, pudict)
Definition: OverlayMetadata.py:123
python.OverlayMetadata.writeOverlayDigitizationMetadata
def writeOverlayDigitizationMetadata(flags, pileupDict)
Definition: OverlayMetadata.py:234
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.OverlayMetadata.overlayInputMetadataCheck
def overlayInputMetadataCheck(flags, simDict, tagInfoDict)
Definition: OverlayMetadata.py:28
str
Definition: BTagTrackIpAccessor.cxx:11