ATLAS Offline Software
Loading...
Searching...
No Matches
python.PhotonAnalysisConfig.PhotonCalibrationConfig Class Reference
Inheritance diagram for python.PhotonAnalysisConfig.PhotonCalibrationConfig:
Collaboration diagram for python.PhotonAnalysisConfig.PhotonCalibrationConfig:

Public Member Functions

 __init__ (self)
 instanceName (self)
 makeCalibrationAndSmearingAlg (self, config, name)
 makeAlgs (self, config)

Public Attributes

 ESModel
 containerName
 forceFullSimConfigForP4
 decorateCaloClusterEta
 addGlobalFELinksDep
 crackVeto
 enableCleaning
 splitCalibrationAndSmearing
 recalibratePhyslite
 applyIsolationCorrection
 forceFullSimConfigForIso

Detailed Description

the ConfigBlock for the photon four-momentum correction

Definition at line 20 of file PhotonAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.PhotonAnalysisConfig.PhotonCalibrationConfig.__init__ ( self)

Definition at line 23 of file PhotonAnalysisConfig.py.

23 def __init__ (self) :
24 super (PhotonCalibrationConfig, self).__init__ ()
25 self.setBlockName('Photons')
26 self.addOption ('containerName', '', type=str,
27 noneAction='error',
28 info="the name of the output container after calibration.",
29 meta={'role':'container'})
30 self.addOption ('ESModel', '', type=str,
31 info="flag for EGamma calibration. If left empty, uses the current recommendations.")
32 self.addOption ('decorrelationModel', '1NP_v1', type=str,
33 info="decorrelation model for the EGamma energy scale. Supported choices are: `FULL_v1`, `1NP_v1`.",
34 meta={'choices':(['FULL_v1','1NP_v1'],1)})
35 self.addOption ('postfix', '', type=str,
36 info="a postfix to apply to decorations and algorithm names. "
37 "Typically not needed here since the calibration is common to "
38 "all photons.")
39 self.addOption ('crackVeto', False, type=bool,
40 info=r"whether to perform LAr crack veto based on the cluster $\eta$, "
41 r"i.e. remove photons within $1.37<\vert\eta\vert<1.52$.")
42 self.addOption ('enableCleaning', True, type=bool,
43 info="whether to enable photon cleaning (`DFCommonPhotonsCleaning`).")
44 self.addOption ('cleaningAllowLate', False, type=bool,
45 info="whether to ignore timing information in cleaning "
46 "(`DFCommonPhotonsCleaningNoTime`).")
47 self.addOption ('recomputeIsEM', False, type=bool,
48 info="whether to recompute the photon shower shape fudge "
49 "corrections (sets up an instance of `CP::PhotonShowerShapeFudgeAlg`) or rely on derivation flags.")
50 self.addOption ('recalibratePhyslite', True, type=bool,
51 info="whether to run the `CP::EgammaCalibrationAndSmearingAlg` on "
52 "PHYSLITE derivations.")
53 self.addOption ('minPt', 10*GeV, type=float,
54 info=r"the minimum $p_\mathrm{T}$ cut (in MeV) to apply to calibrated photons.")
55 self.addOption ('maxEta', 2.37, type=float,
56 info=r"maximum photon $\vert\eta\vert$.")
57 self.addOption ('forceFullSimConfigForP4', False, type=bool,
58 info="whether to force the tool to use the configuration meant for "
59 "full simulation samples for 4-vector corrections. Only for testing purposes.")
60 self.addOption ('forceFullSimConfigForIso', False, type=bool,
61 info="whether to force the tool to use the configuration meant for "
62 "full simulation samples for isolation corrections. Only for testing purposes.")
63 self.addOption ('applyIsolationCorrection', True, type=bool,
64 info="whether to apply the isolation corrections.")
65 self.addOption ('splitCalibrationAndSmearing', False, type=bool,
66 info="EXPERIMENTAL: This splits the `EgammaCalibrationAndSmearingTool` "
67 " into two steps. The first step applies a baseline calibration that "
68 "is not affected by systematics. The second step then applies the "
69 "systematics dependent corrections. The net effect is that the "
70 "slower first step only has to be run once, while the second is run "
71 "once per systematic. ATLASG-2358.",
72 expertMode=True)
73 self.addOption ('decorateTruth', False, type=bool,
74 info="decorate the truth particle information on the reconstructed one.")
75 self.addOption ('decorateCaloClusterEta', False, type=bool,
76 info=r"decorate the calo-cluster $\eta$.")
77 self.addOption ('decorateEmva', False, type=bool,
78 info="decorate `E_mva_only` on the photons (needed for columnar tools/PHYSLITE).")
79 self.addOption ('addGlobalFELinksDep', False, type=bool,
80 info="whether to add dependencies for the global FE links (needed for PHYSLITE production)",
81 expertMode=True)
82

Member Function Documentation

◆ instanceName()

python.PhotonAnalysisConfig.PhotonCalibrationConfig.instanceName ( self)
Return the instance name for this block

Definition at line 83 of file PhotonAnalysisConfig.py.

83 def instanceName (self) :
84 """Return the instance name for this block"""
85 return self.containerName + self.postfix
86
87

◆ makeAlgs()

python.PhotonAnalysisConfig.PhotonCalibrationConfig.makeAlgs ( self,
config )

Definition at line 130 of file PhotonAnalysisConfig.py.

130 def makeAlgs (self, config) :
131
132 postfix = self.postfix
133 if postfix != '' and postfix[0] != '_' :
134 postfix = '_' + postfix
135
136 if self.forceFullSimConfigForP4:
137 warnings.warn_explicit(
138 "You are running PhotonCalibrationConfig forcing"
139 " full sim config for P4 corrections."
140 " This is only intended to be used for testing purposes.",
141 TestingOnlyWarning, filename='', lineno=0)
142
143 if config.isPhyslite() :
144 config.setSourceName (self.containerName, "AnalysisPhotons")
145 else :
146 config.setSourceName (self.containerName, "Photons")
147
148 cleaningWP = 'NoTime' if self.cleaningAllowLate else ''
149
150 # Decorate calo cluster eta if required
151 if self.decorateCaloClusterEta:
152 alg = config.createAlgorithm( 'CP::EgammaCaloClusterEtaAlg',
153 'PhotonEgammaCaloClusterEtaAlg',
154 reentrant=True )
155 alg.particles = config.readName(self.containerName)
156 config.addOutputVar (self.containerName, 'caloEta2', 'caloEta2', noSys=True)
157
158 # Set up a shallow copy to decorate
159 if config.wantCopy (self.containerName) :
160 alg = config.createAlgorithm( 'CP::AsgShallowCopyAlg', 'PhotonShallowCopyAlg' )
161 alg.input = config.readName (self.containerName)
162 alg.output = config.copyName (self.containerName)
163 alg.outputType = 'xAOD::PhotonContainer'
164 decorationList = ['DFCommonPhotonsCleaning',
165 'ptcone20_CloseByCorr',
166 'topoetcone20_CloseByCorr',
167 'topoetcone40_CloseByCorr']
168 if self.addGlobalFELinksDep:
169 decorationList += ['neutralGlobalFELinks', 'chargedGlobalFELinks']
170 if config.dataType() is not DataType.Data:
171 decorationList += ['TruthLink']
172 alg.declareDecorations = decorationList
173
174 # Set up the eta-cut on all photons prior to everything else
175 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'PhotonEtaCutAlg' )
176 alg.selectionDecoration = 'selectEta' + postfix + ',as_bits'
177 config.addPrivateTool( 'selectionTool', 'CP::AsgPtEtaSelectionTool' )
178 alg.selectionTool.maxEta = self.maxEta
179 if self.crackVeto:
180 alg.selectionTool.etaGapLow = 1.37
181 alg.selectionTool.etaGapHigh = 1.52
182 alg.selectionTool.useClusterEta = True
183 alg.particles = config.readName (self.containerName)
184 alg.preselection = config.getPreselection (self.containerName, '')
185 config.addSelection (self.containerName, '', alg.selectionDecoration)
186
187 # Setup shower shape fudge
188 if self.recomputeIsEM and config.dataType() is DataType.FullSim:
189 alg = config.createAlgorithm( 'CP::PhotonShowerShapeFudgeAlg',
190 'PhotonShowerShapeFudgeAlg' )
191 config.addPrivateTool( 'showerShapeFudgeTool',
192 'ElectronPhotonVariableCorrectionTool' )
193 if config.geometry() is LHCPeriod.Run2:
194 alg.showerShapeFudgeTool.ConfigFile = \
195 'EGammaVariableCorrection/TUNE25/ElPhVariableNominalCorrection.conf'
196 if config.geometry() is LHCPeriod.Run3:
197 if config.campaign() in (Campaign.MC23a, Campaign.MC23d):
198 alg.showerShapeFudgeTool.ConfigFile = \
199 'EGammaVariableCorrection/TUNE28AD/ElPhVariableNominalCorrection.conf'
200 else:
201 alg.showerShapeFudgeTool.ConfigFile = \
202 'EGammaVariableCorrection/TUNE28EG/ElPhVariableNominalCorrection.conf'
203 alg.photons = config.readName (self.containerName)
204 alg.photonsOut = config.copyName (self.containerName)
205 alg.preselection = config.getPreselection (self.containerName, '')
206
207 # Select photons only with good object quality.
208 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'PhotonObjectQualityAlg' )
209 config.setExtraInputs ({('xAOD::EventInfo', 'EventInfo.RandomRunNumber')})
210 alg.selectionDecoration = 'goodOQ' + postfix + ',as_bits'
211 config.addPrivateTool( 'selectionTool', 'CP::EgammaIsGoodOQSelectionTool' )
212 alg.selectionTool.Mask = xAOD.EgammaParameters.BADCLUSPHOTON
213 alg.particles = config.readName (self.containerName)
214 alg.preselection = config.getPreselection (self.containerName, '')
215 config.addSelection (self.containerName, '', alg.selectionDecoration)
216
217 # Select clean photons
218 if self.enableCleaning:
219 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'PhotonCleaningAlg' )
220 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
221 alg.selectionDecoration = 'isClean' + postfix + ',as_bits'
222 alg.selectionTool.selectionFlags = ['DFCommonPhotonsCleaning' + cleaningWP]
223 alg.particles = config.readName (self.containerName)
224 alg.preselection = config.getPreselection (self.containerName, '')
225 config.addSelection (self.containerName, '', alg.selectionDecoration)
226
227 # Change the origin of Photons from (0,0,0) to (0,0,z)
228 # where z comes from the position of a vertex
229 # Default the one tagged as Primary
230 alg = config.createAlgorithm( 'CP::PhotonOriginCorrectionAlg',
231 'PhotonOriginCorrectionAlg',
232 reentrant=True )
233 alg.photons = config.readName (self.containerName)
234 alg.photonsOut = config.copyName (self.containerName)
235 alg.preselection = config.getPreselection (self.containerName, '')
236
237 if not self.splitCalibrationAndSmearing :
238 # Set up the calibration and smearing algorithm:
239 alg = self.makeCalibrationAndSmearingAlg (config, 'PhotonCalibrationAndSmearingAlg')
240 if config.isPhyslite() and not self.recalibratePhyslite :
241 alg.skipNominal = True
242 else:
243 # This splits the EgammaCalibrationAndSmearingTool into two
244 # steps. The first step applies a baseline calibration that
245 # is not affected by systematics. The second step then
246 # applies the systematics dependent corrections. The net
247 # effect is that the slower first step only has to be run
248 # once, while the second is run once per systematic.
249 #
250 # For now (22 May 24) this has to happen in the same job, as
251 # the output of the first step is not part of PHYSLITE, and
252 # even for the nominal the output of the first and second
253 # step are different. In the future the plan is to put both
254 # the output of the first and second step into PHYSLITE,
255 # allowing to skip the first step when running on PHYSLITE.
256 #
257 # WARNING: All of this is experimental, see: ATLASG-2358
258
259 # Set up the calibration algorithm:
260 alg = self.makeCalibrationAndSmearingAlg (config, 'PhotonBaseCalibrationAlg')
261 # turn off systematics for the calibration step
262 alg.noToolSystematics = True
263 # turn off smearing for the calibration step
264 alg.calibrationAndSmearingTool.doSmearing = False
265
266 # Set up the smearing algorithm:
267 alg = self.makeCalibrationAndSmearingAlg (config, 'PhotonCalibrationSystematicsAlg')
268 # turn off scale corrections for the smearing step
269 alg.calibrationAndSmearingTool.doScaleCorrection = False
270 alg.calibrationAndSmearingTool.useMVACalibration = False
271 alg.calibrationAndSmearingTool.decorateEmva = False
272
273 if not self.applyIsolationCorrection:
274 warnings.warn_explicit(
275 "You are not applying the isolation corrections."
276 " This is only intended to be used for testing purposes.",
277 TestingOnlyWarning, filename='', lineno=0)
278
279 if self.minPt > 0:
280
281 # Set up the the pt selection
282 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'PhotonPtCutAlg' )
283 alg.selectionDecoration = 'selectPt' + postfix + ',as_bits'
284 config.addPrivateTool( 'selectionTool', 'CP::AsgPtEtaSelectionTool' )
285 alg.selectionTool.minPt = self.minPt
286 alg.particles = config.readName (self.containerName)
287 alg.preselection = config.getPreselection (self.containerName, '')
288 config.addSelection (self.containerName, '', alg.selectionDecoration,
289 preselection=True)
290
291 # Set up the isolation correction algorithm.
292 if self.applyIsolationCorrection:
293
294 if self.forceFullSimConfigForIso:
295 warnings.warn_explicit(
296 "You are running PhotonCalibrationConfig forcing"
297 " full sim config for isolation corrections."
298 " This is only intended to be used for testing purposes.",
299 TestingOnlyWarning, filename='', lineno=0)
300
301 alg = config.createAlgorithm( 'CP::EgammaIsolationCorrectionAlg',
302 'PhotonIsolationCorrectionAlg' )
303 config.addPrivateTool( 'isolationCorrectionTool',
304 'CP::IsolationCorrectionTool' )
305 alg.isolationCorrectionTool.IsMC = config.dataType() is not DataType.Data
306 alg.isolationCorrectionTool.AFII_corr = (
307 0 if self.forceFullSimConfigForIso
308 else config.dataType() is DataType.FastSim)
309 AODfixes = config.flags.Input.AODFixesDone
310 if "egammatopoIsoFix" in AODfixes:
311 alg.isolationCorrectionTool.FixTimingIssueInCore = False
312 else:
313 alg.isolationCorrectionTool.FixTimingIssueInCore = True
314 alg.egammas = config.readName (self.containerName)
315 alg.egammasOut = config.copyName (self.containerName)
316 alg.preselection = config.getPreselection (self.containerName, '')
317
318 # Additional decorations
319 alg = config.createAlgorithm( 'CP::AsgEnergyDecoratorAlg', 'EnergyDecorator' )
320 alg.particles = config.readName (self.containerName)
321
322 config.addOutputVar (self.containerName, 'pt', 'pt')
323 config.addOutputVar (self.containerName, 'eta', 'eta', noSys=True)
324 config.addOutputVar (self.containerName, 'phi', 'phi', noSys=True)
325 config.addOutputVar (self.containerName, 'e_%SYS%', 'e')
326 if self.splitCalibrationAndSmearing or not (config.isPhyslite() and not self.recalibratePhyslite) :
327 config.addOutputVar (self.containerName, 'caloClusterEnergyReso_%SYS%', 'caloClusterEnergyReso', noSys=True)
328
329 # decorate truth information on the reconstructed object:
330 if self.decorateTruth and config.dataType() is not DataType.Data:
331 config.addOutputVar (self.containerName, "truthType", "truth_type", noSys=True)
332 config.addOutputVar (self.containerName, "truthOrigin", "truth_origin", noSys=True)
333
334

◆ makeCalibrationAndSmearingAlg()

python.PhotonAnalysisConfig.PhotonCalibrationConfig.makeCalibrationAndSmearingAlg ( self,
config,
name )
Create the calibration and smearing algorithm

Factoring this out into its own function, as we want to
instantiate it in multiple places

Definition at line 88 of file PhotonAnalysisConfig.py.

88 def makeCalibrationAndSmearingAlg (self, config, name) :
89 """Create the calibration and smearing algorithm
90
91 Factoring this out into its own function, as we want to
92 instantiate it in multiple places"""
93
94 # Set up the calibration and smearing algorithm:
95 alg = config.createAlgorithm( 'CP::EgammaCalibrationAndSmearingAlg', name )
96 config.addPrivateTool( 'calibrationAndSmearingTool',
97 'CP::EgammaCalibrationAndSmearingTool' )
98 # Set default ESModel per period
99 if self.ESModel:
100 alg.calibrationAndSmearingTool.ESModel = self.ESModel
101 else:
102 if config.geometry() is LHCPeriod.Run2:
103 alg.calibrationAndSmearingTool.ESModel = 'es2023_R22_Run2_v1'
104 elif config.geometry() is LHCPeriod.Run3:
105 alg.calibrationAndSmearingTool.ESModel = 'es2024_Run3_v0'
106 elif config.geometry() is LHCPeriod.Run4:
107 warnings.warn_explicit(
108 "No ESModel set for Run4, using Run3 model",
109 Run4FallbackWarning, filename='', lineno=0)
110 alg.calibrationAndSmearingTool.ESModel = 'es2024_Run3_v0'
111 else:
112 raise ValueError (f"Can't set up the PhotonCalibrationConfig with {config.geometry().value}, "
113 "there must be something wrong!")
114
115 alg.calibrationAndSmearingTool.decorrelationModel = self.decorrelationModel
116 alg.calibrationAndSmearingTool.useFastSim = (
117 0 if self.forceFullSimConfigForP4
118 else int( config.dataType() is DataType.FastSim ))
119 alg.calibrationAndSmearingTool.decorateEmva = self.decorateEmva
120 alg.egammas = config.readName (self.containerName)
121 alg.egammasOut = config.copyName (self.containerName)
122 alg.preselection = config.getPreselection (self.containerName, '')
123
124 config.setContainerMeta (self.containerName, 'ESModel', alg.calibrationAndSmearingTool.ESModel, allowOverwrite=True)
125 config.setContainerMeta (self.containerName, 'decorrelationModel', alg.calibrationAndSmearingTool.decorrelationModel, allowOverwrite=True)
126
127 return alg
128
129

Member Data Documentation

◆ addGlobalFELinksDep

python.PhotonAnalysisConfig.PhotonCalibrationConfig.addGlobalFELinksDep

Definition at line 168 of file PhotonAnalysisConfig.py.

◆ applyIsolationCorrection

python.PhotonAnalysisConfig.PhotonCalibrationConfig.applyIsolationCorrection

Definition at line 273 of file PhotonAnalysisConfig.py.

◆ containerName

python.PhotonAnalysisConfig.PhotonCalibrationConfig.containerName

Definition at line 124 of file PhotonAnalysisConfig.py.

◆ crackVeto

python.PhotonAnalysisConfig.PhotonCalibrationConfig.crackVeto

Definition at line 179 of file PhotonAnalysisConfig.py.

◆ decorateCaloClusterEta

python.PhotonAnalysisConfig.PhotonCalibrationConfig.decorateCaloClusterEta

Definition at line 151 of file PhotonAnalysisConfig.py.

◆ enableCleaning

python.PhotonAnalysisConfig.PhotonCalibrationConfig.enableCleaning

Definition at line 218 of file PhotonAnalysisConfig.py.

◆ ESModel

python.PhotonAnalysisConfig.PhotonCalibrationConfig.ESModel

Definition at line 99 of file PhotonAnalysisConfig.py.

◆ forceFullSimConfigForIso

python.PhotonAnalysisConfig.PhotonCalibrationConfig.forceFullSimConfigForIso

Definition at line 294 of file PhotonAnalysisConfig.py.

◆ forceFullSimConfigForP4

python.PhotonAnalysisConfig.PhotonCalibrationConfig.forceFullSimConfigForP4

Definition at line 136 of file PhotonAnalysisConfig.py.

◆ recalibratePhyslite

python.PhotonAnalysisConfig.PhotonCalibrationConfig.recalibratePhyslite

Definition at line 240 of file PhotonAnalysisConfig.py.

◆ splitCalibrationAndSmearing

python.PhotonAnalysisConfig.PhotonCalibrationConfig.splitCalibrationAndSmearing

Definition at line 237 of file PhotonAnalysisConfig.py.


The documentation for this class was generated from the following file: