ATLAS Offline Software
DigitizationConfigFlags.py
Go to the documentation of this file.
1 """Construct ConfigFlags for Digitization
2 
3 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4 """
5 from AthenaConfiguration.AutoConfigFlags import GetFileMD
6 from AthenaConfiguration.AthConfigFlags import AthConfigFlags
7 from AthenaConfiguration.Enums import ProductionStep
8 from SimulationConfig.SimEnums import PixelRadiationDamageSimulationType
9 
10 
11 def constBunchSpacingPattern(constBunchSpacing):
12  """Return a valid value for Digitization.BeamIntensity, which
13  matches the specified constBunchSpacing
14  """
15  if type(constBunchSpacing) is not int:
16  raise TypeError("constBunchSpacing must be int, "
17  "not %s" % type(constBunchSpacing).__name__)
18  if constBunchSpacing % 25 != 0:
19  raise ValueError("constBunchSpacing must be a multiple of 25, "
20  "not %s" % constBunchSpacing)
21 
22  # special case
23  if constBunchSpacing == 25:
24  return [1.0]
25 
26  # general case
27  pattern = [0.0, 1.0]
28  nBunches = (constBunchSpacing//25) - 2
29  pattern += nBunches*[0.0]
30  return pattern
31 
32 
34  """Return an AthConfigFlags object with required flags"""
35  flags = AthConfigFlags()
36  # Digitization Steering - needed for easy comparison with the
37  # old-style configuration, but can potentially drop
38  def _checkDigiSteeringConf(prevFlags):
39  digiSteeringConf = "StandardPileUpToolsAlg"
40  if prevFlags.Input.Files:
41  digiSteeringConf = GetFileMD(prevFlags.Input.Files).get("digiSteeringConf", "StandardPileUpToolsAlg")
42  return digiSteeringConf
43 
44  flags.addFlag("Digitization.DigiSteeringConf", _checkDigiSteeringConf)
45  # Run Inner Detector noise simulation
46  flags.addFlag("Digitization.DoInnerDetectorNoise", lambda prevFlags: not prevFlags.Common.isOverlay)
47  # Run pile-up digitization on one bunch crossing at a time?
48  flags.addFlag("Digitization.DoXingByXingPileUp", False)
49  # Run Calorimeter noise simulation
50  flags.addFlag("Digitization.DoCaloNoise", lambda prevFlags: not prevFlags.Common.isOverlay)
51  # Produce inputs for Calorimeter hard scatter truth reconstruction
52  flags.addFlag("Digitization.EnableCaloHSTruthRecoInputs", False)
53  # Use high-gain Forward Calorimeters
54  flags.addFlag("Digitization.HighGainFCal", False)
55  # Use high-gain ElectroMagnetic EndCap Inner Wheel
56  flags.addFlag("Digitization.HighGainEMECIW", True)
57  # Do global pileup digitization
58  flags.addFlag("Digitization.PileUp",
59  lambda prevFlags: GetFileMD(prevFlags.Input.Files).get("pileUp", "False") != "False")
60  # Temporary TGC flag
61  flags.addFlag("Digitization.UseUpdatedTGCConditions", False)
62  # Write out truth information
63  flags.addFlag("Digitization.EnableTruth", True)
64  # Write out calorimeter digits
65  flags.addFlag("Digitization.AddCaloDigi", False)
66  # Write out thinned calorimeter digits
67  flags.addFlag("Digitization.AddCaloDigiThinned", False)
68  # Integer offset to random seed initialisation
69  flags.addFlag("Digitization.RandomSeedOffset", 0)
70  # Digitization extra input dependencies
71  flags.addFlag("Digitization.ExtraInputs", [("xAOD::EventInfo", "EventInfo")])
72  # Beam spot reweighting (-1 disables it)
73  flags.addFlag("Digitization.InputBeamSigmaZ", -1)
74 
75  # Set the type of the radiation damage simulation type for pixel planar sensors
76  flags.addFlag("Digitization.PixelPlanarRadiationDamageSimulationType",
77  PixelRadiationDamageSimulationType.NoRadiationDamage, type=PixelRadiationDamageSimulationType)
78  # Set the type of the radiation damage simulation type for 3D planar sensors
79  flags.addFlag("Digitization.Pixel3DRadiationDamageSimulationType",
80  PixelRadiationDamageSimulationType.NoRadiationDamage, type=PixelRadiationDamageSimulationType)
81  # Set the flag to tell the code to treat 3D sensors in in Pixel ITk as 3D sensors (instead of planar)
82  # Current default is False as this is what has been used so far for the ITk simulation (treating 3D as Planar)
83  # This is a temporary flag that will be eventually removed FIXME
84  flags.addFlag("Digitization.DigitizeITk3Das3D", False)
85 
86  # for PileUp digitization
87  # Bunch structure configuration
88  flags.addFlag("Digitization.PU.BunchStructureConfig", "")
89  # Pile-up profile configuration
90  flags.addFlag("Digitization.PU.ProfileConfig", "")
91  # Custom pile-up profile configuration - fully custom or for mu range
92  flags.addFlag("Digitization.PU.CustomProfile", "")
93  # Force sequential event numbers
94  flags.addFlag("Digitization.PU.ForceSequentialEventNumbers",
95  lambda prevFlags: prevFlags.Common.ProductionStep == ProductionStep.PileUpPresampling)
96  # Beam Halo input collections
97  flags.addFlag("Digitization.PU.BeamHaloInputCols", [])
98  # LHC Bunch Structure (list of non-negative floats)
99  flags.addFlag("Digitization.PU.BeamIntensityPattern",
100  lambda prevFlags: constBunchSpacingPattern(prevFlags.Beam.BunchSpacing))
101  # Beam Gas input collections
102  flags.addFlag("Digitization.PU.BeamGasInputCols", [])
103  # LHC bunch spacing, in ns, to use in pileup digitization. Only multiples of 25 allowed.
104  # Not necessarily equal to Beam.BunchSpacing
105  flags.addFlag("Digitization.PU.BunchSpacing",
106  lambda prevFlags: prevFlags.Beam.BunchSpacing)
107  # PileUp branch crossing parameters
108  flags.addFlag("Digitization.PU.InitialBunchCrossing", -32)
109  flags.addFlag("Digitization.PU.FinalBunchCrossing", 6)
110  # Add the cavern background every bunch, independent of any bunch structure?
111  flags.addFlag("Digitization.PU.CavernIgnoresBeamInt", False)
112  # Cavern input collections
113  flags.addFlag("Digitization.PU.CavernInputCols", [])
114  # Central bunch crossing location in the BeamIntensityPattern
115  flags.addFlag("Digitization.PU.FixedT0BunchCrossing", 0)
116  # Superimpose mixed high pt minimum bias events (pile-up) on signal events?
117  # If so, set this to a list of: High Pt Mixed ND, SD, DD minimum bias input collections
118  flags.addFlag("Digitization.PU.HighPtMinBiasInputCols", [])
119  # Offset into the input collections of high pt min-bias events
120  flags.addFlag("Digitization.PU.HighPtMinBiasInputColOffset", 0)
121  # Superimpose mixed low pt minimum bias events (pile-up) on signal events?
122  # If so, set this to a list of: Low Pt Mixed ND, SD, DD minimum bias input collections
123  flags.addFlag("Digitization.PU.LowPtMinBiasInputCols", [])
124  # Number of low pt min-bias events to superimpose per signal event per beam crossing
125  flags.addFlag("Digitization.PU.NumberOfLowPtMinBias", 0.0)
126  # Number of high pt min-bias events to superimpose per signal event per beam crossing
127  flags.addFlag("Digitization.PU.NumberOfHighPtMinBias", 0.0)
128  # Number of beam gas events to superimpose per signal event per beam crossing
129  flags.addFlag("Digitization.PU.NumberOfBeamGas", 0.0)
130  # Number of beam halo events to superimpose per signal event per beam crossing
131  flags.addFlag("Digitization.PU.NumberOfBeamHalo", 0.0)
132  # Number of mixed ND, SD, DD min-bias events to superimpose per signal event per beam crossing
133  flags.addFlag("Digitization.PU.NumberOfCollisions", 0.0)
134  # Number of cavern events to superimpose per signal event per beam crossing
135  flags.addFlag("Digitization.PU.NumberOfCavern", 0.0)
136  # Repeating pattern to determine which events to simulate when using Stepping Cache
137  flags.addFlag("Digitization.PU.SignalPatternForSteppingCache", [])
138  # Which sub-systems should use Fast Digitization
139  flags.addFlag("Digitization.DoFastDigi", [])
140  # Set the flag to True if the Common.ProductionStep is not one of the steps in the list
141  flags.addFlag("Digitization.ReadParametersFromDB", lambda prevFlags : prevFlags.Common.ProductionStep in [ProductionStep.Digitization, ProductionStep.PileUpPresampling, ProductionStep.Overlay, ProductionStep.FastChain])
142  # Do TRT high threshold overrides for heay ion runs
143  flags.addFlag("Digitization.TRT.HeavyIonHT", False)
144  return flags
145 
146 
147 def digitizationRunArgsToFlags(runArgs, flags):
148  """Fill digitization configuration flags from run arguments."""
149  # from SimDigi
150  if hasattr(runArgs, "DataRunNumber"):
151  flags.Input.ConditionsRunNumber = runArgs.DataRunNumber
152 
153  # from SimDigi
154  if hasattr(runArgs, "jobNumber"):
155  flags.Input.JobNumber = runArgs.jobNumber
156 
157  if hasattr(runArgs, "PileUpPresampling"):
158  flags.Common.ProductionStep = ProductionStep.PileUpPresampling
159  elif flags.Common.ProductionStep == ProductionStep.Default: # Do not override previous settings
160  flags.Common.ProductionStep = ProductionStep.Digitization
161 
162  if hasattr(runArgs, "doAllNoise"):
163  flags.Digitization.DoInnerDetectorNoise = runArgs.doAllNoise
164  flags.Digitization.DoCaloNoise = runArgs.doAllNoise
165 
166  if hasattr(runArgs, "AddCaloDigi"):
167  flags.Digitization.AddCaloDigi = runArgs.AddCaloDigi
168 
169  if hasattr(runArgs, "digiSeedOffset1") or hasattr(runArgs, "digiSeedOffset2"):
170  flags.Digitization.RandomSeedOffset = 0
171  if hasattr(runArgs, "digiSeedOffset1"):
172  flags.Digitization.RandomSeedOffset += int(runArgs.digiSeedOffset1)
173  if hasattr(runArgs, "digiSeedOffset2"):
174  flags.Digitization.RandomSeedOffset += int(runArgs.digiSeedOffset2)
175  else:
176  flags.Digitization.RandomSeedOffset = 3 # for legacy compatibility
177 
178  if hasattr(runArgs, "digiSteeringConf"):
179  flags.Digitization.DigiSteeringConf = runArgs.digiSteeringConf + "PileUpToolsAlg"
180 
181  # TODO: Not covered yet as no flag equivalents exist yet
182  # '--digiRndmSvc'
183  # '--samplingFractionDbTag'
184 
185 
186 def pileupRunArgsToFlags(runArgs, flags):
187  """Fill pile-up digitization configuration flags from run arguments."""
188  if hasattr(runArgs, "numberOfLowPtMinBias"):
189  flags.Digitization.PU.NumberOfLowPtMinBias = runArgs.numberOfLowPtMinBias
190 
191  if hasattr(runArgs, "numberOfHighPtMinBias"):
192  flags.Digitization.PU.NumberOfHighPtMinBias = runArgs.numberOfHighPtMinBias
193 
194  if hasattr(runArgs, "numberOfBeamHalo"):
195  flags.Digitization.PU.NumberOfBeamHalo = runArgs.numberOfBeamHalo
196 
197  if hasattr(runArgs, "numberOfBeamGas"):
198  flags.Digitization.PU.NumberOfBeamGas = runArgs.numberOfBeamGas
199 
200  if hasattr(runArgs, "numberOfCavernBkg"):
201  flags.Digitization.PU.NumberOfCavern = runArgs.numberOfCavernBkg
202 
203  if hasattr(runArgs, "bunchSpacing"):
204  flags.Digitization.PU.BunchSpacing = runArgs.bunchSpacing
205 
206  if hasattr(runArgs, "pileupInitialBunch"):
207  flags.Digitization.PU.InitialBunchCrossing = runArgs.pileupInitialBunch
208 
209  if hasattr(runArgs, "pileupFinalBunch"):
210  flags.Digitization.PU.FinalBunchCrossing = runArgs.pileupFinalBunch
211 
212  # sanity check
213  if flags.Digitization.PU.InitialBunchCrossing > flags.Digitization.PU.FinalBunchCrossing:
214  raise ValueError("Initial bunch crossing should not be larger than the final one")
215 
216  if hasattr(runArgs, "inputLowPtMinbiasHitsFile"):
217  from RunDependentSimComps.PileUpUtils import generateBackgroundInputCollections
218  flags.Digitization.PU.LowPtMinBiasInputCols = \
219  generateBackgroundInputCollections(flags, runArgs.inputLowPtMinbiasHitsFile,
220  flags.Digitization.PU.NumberOfLowPtMinBias, True)
221 
222  if hasattr(runArgs, "inputHighPtMinbiasHitsFile"):
223  from RunDependentSimComps.PileUpUtils import getInputCollectionOffset, generateBackgroundInputCollections
224  if flags.Digitization.PU.HighPtMinBiasInputColOffset < 0:
225  # Calculate a pseudo random offset into the collection from the jobNumber
226  flags.Digitization.PU.HighPtMinBiasInputColOffset = getInputCollectionOffset(flags, runArgs.inputHighPtMinbiasHitsFile)
227 
228  flags.Digitization.PU.HighPtMinBiasInputCols = \
229  generateBackgroundInputCollections(flags, runArgs.inputHighPtMinbiasHitsFile,
230  flags.Digitization.PU.NumberOfHighPtMinBias, True)
231 
232  if hasattr(runArgs, "inputCavernHitsFile"):
233  from RunDependentSimComps.PileUpUtils import generateBackgroundInputCollections
234  flags.Digitization.PU.CavernInputCols = \
235  generateBackgroundInputCollections(flags, runArgs.inputCavernHitsFile,
236  flags.Digitization.PU.NumberOfCavern, True) # TODO: ignore?
237 
238  if hasattr(runArgs, "inputBeamHaloHitsFile"):
239  from RunDependentSimComps.PileUpUtils import generateBackgroundInputCollections
240  flags.Digitization.PU.BeamHaloInputCols = \
241  generateBackgroundInputCollections(flags, runArgs.inputBeamHaloHitsFile,
242  flags.Digitization.PU.NumberOfBeamHalo, True)
243 
244  if hasattr(runArgs, "inputBeamGasHitsFile"):
245  from RunDependentSimComps.PileUpUtils import generateBackgroundInputCollections
246  flags.Digitization.PU.BeamGasInputCols = \
247  generateBackgroundInputCollections(flags, runArgs.inputBeamGasHitsFile,
248  flags.Digitization.PU.NumberOfBeamGas, True)
249 
250  # TODO: Not covered yet as no flag equivalents exist yet
251  # '--testPileUpConfig'
252 
253 
254 def setupDigitizationFlags(runArgs, flags):
255  """Setup common digitization flags."""
256  # autoconfigure pile-up if inputs are present
257  if (hasattr(runArgs, "inputLowPtMinbiasHitsFile")
258  or hasattr(runArgs, "inputHighPtMinbiasHitsFile")
259  or hasattr(runArgs, "inputCavernHitsFile")
260  or hasattr(runArgs, "inputBeamHaloHitsFile")
261  or hasattr(runArgs, "inputBeamGasHitsFile")):
262  flags.Digitization.PileUp = True
263 
264  if flags.Digitization.PileUp:
265  flags.Input.OverrideRunNumber = True
266  # Needs to be False for MT pileup
267  if flags.Concurrency.NumThreads > 0:
268  flags.Digitization.DoXingByXingPileUp = False
269  else:
270  flags.Digitization.DoXingByXingPileUp = True
271  else:
272  flags.Input.OverrideRunNumber = flags.Input.ConditionsRunNumber > 0
python.AutoConfigFlags.GetFileMD
def GetFileMD(filenames, allowEmpty=True, maxLevel='peeker')
Definition: AutoConfigFlags.py:65
python.DigitizationConfigFlags.digitizationRunArgsToFlags
def digitizationRunArgsToFlags(runArgs, flags)
Definition: DigitizationConfigFlags.py:147
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.PileUpUtils.generateBackgroundInputCollections
def generateBackgroundInputCollections(flags, initialList, nBkgEvtsPerCrossing, correctForEmptyBunchCrossings)
Definition: PileUpUtils.py:66
python.DigitizationConfigFlags.setupDigitizationFlags
def setupDigitizationFlags(runArgs, flags)
Definition: DigitizationConfigFlags.py:254
python.DigitizationConfigFlags.constBunchSpacingPattern
def constBunchSpacingPattern(constBunchSpacing)
Definition: DigitizationConfigFlags.py:11
python.DigitizationConfigFlags.pileupRunArgsToFlags
def pileupRunArgsToFlags(runArgs, flags)
Definition: DigitizationConfigFlags.py:186
python.DigitizationConfigFlags.createDigitizationCfgFlags
def createDigitizationCfgFlags()
Definition: DigitizationConfigFlags.py:33
python.PileUpUtils.getInputCollectionOffset
def getInputCollectionOffset(flags, initialList)
Definition: PileUpUtils.py:43
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127