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 23 of file PhotonAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.PhotonAnalysisConfig.PhotonCalibrationConfig.__init__ ( self)

Definition at line 26 of file PhotonAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 89 of file PhotonAnalysisConfig.py.

89 def instanceName (self) :
90 """Return the instance name for this block"""
91 return self.containerName + self.postfix
92
93

◆ makeAlgs()

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

Definition at line 142 of file PhotonAnalysisConfig.py.

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

◆ 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 94 of file PhotonAnalysisConfig.py.

94 def makeCalibrationAndSmearingAlg (self, config, name) :
95 """Create the calibration and smearing algorithm
96
97 Factoring this out into its own function, as we want to
98 instantiate it in multiple places"""
99
100 # Set up the calibration and smearing algorithm:
101 alg = config.createAlgorithm( 'CP::EgammaCalibrationAndSmearingAlg', name )
102 config.addPrivateTool( 'calibrationAndSmearingTool',
103 'CP::EgammaCalibrationAndSmearingTool' )
104 # Set default ESModel per period
105 if self.ESModel:
106 alg.calibrationAndSmearingTool.ESModel = self.ESModel
107 else:
108 if config.geometry() is LHCPeriod.Run2:
109 alg.calibrationAndSmearingTool.ESModel = 'es2023_R22_Run2_v1'
110 elif config.geometry() is LHCPeriod.Run3:
111 alg.calibrationAndSmearingTool.ESModel = 'es2024_Run3_v0'
112 elif config.geometry() is LHCPeriod.Run4:
113 warnings.warn_explicit(
114 "No ESModel set for Run4, using Run3 model",
115 Run4FallbackWarning, filename='', lineno=0)
116 alg.calibrationAndSmearingTool.ESModel = 'es2024_Run3_v0'
117 else:
118 raise ValueError (f"Can't set up the PhotonCalibrationConfig with {config.geometry().value}, "
119 "there must be something wrong!")
120
121 alg.calibrationAndSmearingTool.decorrelationModel = self.decorrelationModel
122 alg.calibrationAndSmearingTool.useFastSim = (
123 0 if self.forceFullSimConfigForP4
124 else int( config.dataType() is DataType.FastSim ))
125 alg.calibrationAndSmearingTool.decorateEmva = self.decorateEmva
126 # only photons are calibrated here, so skip loading the electron BDTs
127 alg.calibrationAndSmearingTool.DoElectronMVACalibration = False
128 # the tool must not re-add the cells lost to the timing cut if the
129 # egamma AODFix already corrected the clusters upstream
130 if 'egClusterL2_3Fix' in config.flags.Input.AODFixesDone :
131 alg.calibrationAndSmearingTool.FixForMissingCells = False
132 alg.egammas = config.readName (self.containerName)
133 alg.egammasOut = config.copyName (self.containerName)
134 alg.preselection = config.getPreselection (self.containerName, '')
135
136 config.setContainerMeta (self.containerName, 'ESModel', alg.calibrationAndSmearingTool.ESModel, allowOverwrite=True)
137 config.setContainerMeta (self.containerName, 'decorrelationModel', alg.calibrationAndSmearingTool.decorrelationModel, allowOverwrite=True)
138
139 return alg
140
141

Member Data Documentation

◆ addGlobalFELinksDep

python.PhotonAnalysisConfig.PhotonCalibrationConfig.addGlobalFELinksDep

Definition at line 180 of file PhotonAnalysisConfig.py.

◆ applyIsolationCorrection

python.PhotonAnalysisConfig.PhotonCalibrationConfig.applyIsolationCorrection

Definition at line 300 of file PhotonAnalysisConfig.py.

◆ containerName

python.PhotonAnalysisConfig.PhotonCalibrationConfig.containerName

Definition at line 136 of file PhotonAnalysisConfig.py.

◆ crackVeto

python.PhotonAnalysisConfig.PhotonCalibrationConfig.crackVeto

Definition at line 191 of file PhotonAnalysisConfig.py.

◆ decorateCaloClusterEta

python.PhotonAnalysisConfig.PhotonCalibrationConfig.decorateCaloClusterEta

Definition at line 163 of file PhotonAnalysisConfig.py.

◆ enableCleaning

python.PhotonAnalysisConfig.PhotonCalibrationConfig.enableCleaning

Definition at line 230 of file PhotonAnalysisConfig.py.

◆ ESModel

python.PhotonAnalysisConfig.PhotonCalibrationConfig.ESModel

Definition at line 105 of file PhotonAnalysisConfig.py.

◆ forceFullSimConfigForIso

python.PhotonAnalysisConfig.PhotonCalibrationConfig.forceFullSimConfigForIso

Definition at line 321 of file PhotonAnalysisConfig.py.

◆ forceFullSimConfigForP4

python.PhotonAnalysisConfig.PhotonCalibrationConfig.forceFullSimConfigForP4

Definition at line 148 of file PhotonAnalysisConfig.py.

◆ recalibratePhyslite

python.PhotonAnalysisConfig.PhotonCalibrationConfig.recalibratePhyslite

Definition at line 252 of file PhotonAnalysisConfig.py.

◆ splitCalibrationAndSmearing

python.PhotonAnalysisConfig.PhotonCalibrationConfig.splitCalibrationAndSmearing

Definition at line 249 of file PhotonAnalysisConfig.py.


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