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

Public Member Functions

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

Public Attributes

 ESModel
 containerName
 forceFullSimConfigForP4
 inputContainer
 decorateCaloClusterEta
 decorateSamplingPattern
 addGlobalFELinksDep
 crackVeto
 splitCalibrationAndSmearing
 recalibratePhyslite
 isolationCorrection

Detailed Description

the ConfigBlock for the electron four-momentum correction

Definition at line 23 of file ElectronAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.__init__ ( self)

Definition at line 26 of file ElectronAnalysisConfig.py.

26 def __init__ (self) :
27 super (ElectronMomentumCalibrationConfig, self).__init__ ()
28 self.setBlockName('Electrons')
29 self.addOption ('inputContainer', '', type=str,
30 info="the name of the input electron container. If left empty, automatically defaults "
31 "to `AnalysisElectrons` for PHYSLITE or `Electrons` otherwise.")
32 self.addOption ('containerName', '', type=str,
33 noneAction='error',
34 info="the name of the output container after calibration.",
35 meta={'role':'container'})
36 self.addOption ('ESModel', '', type=str,
37 info="flag for Egamma calibration. If left empty, use the current recommendations.")
38 self.addOption ('decorrelationModel', '1NP_v1', type=str,
39 info="decorrelation model for the EGamma energy scale. Supported choices are: `1NP_v1`, `FULL_v1`.",
40 meta={'choices':(['1NP_v1','FULL_v1'],1)})
41 self.addOption ('postfix', '', type=str,
42 info="a postfix to apply to decorations and algorithm names. Typically "
43 "not needed here since the calibration is common to all electrons.")
44 self.addOption ('crackVeto', False, type=bool,
45 info=r"whether to perform LAr crack veto based on the cluster $\eta$, "
46 r"i.e. remove electrons within $1.37<\vert\eta\vert<1.52$.")
47 self.addOption ('isolationCorrection', True, type=bool,
48 info="whether or not to perform isolation corrections (leakage "
49 "corrections), i.e. set up an instance of "
50 "`CP::EgammaIsolationCorrectionAlg`.",
51 expertMode=True)
52 self.addOption ('recalibratePhyslite', True, type=bool,
53 info="whether to run the `CP::EgammaCalibrationAndSmearingAlg` on "
54 "PHYSLITE derivations.")
55 self.addOption ('minPt', 4.5*GeV, type=float,
56 info=r"the minimum $p_\mathrm{T}$ cut (in MeV) to apply to calibrated electrons.")
57 self.addOption ('maxEta', 2.47, type=float,
58 info=r"maximum electron $\vert\eta\vert$.")
59 self.addOption ('forceFullSimConfigForP4', False, type=bool,
60 info="whether to force the tool to use the configuration meant for "
61 "full simulation samples for 4-vector corrections. Only for testing purposes.")
62 self.addOption ('forceFullSimConfigForIso', False, type=bool,
63 info="whether to force the tool to use the configuration meant for "
64 "full simulation samples for isolation corrections. Only for testing purposes.")
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 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 electrons (needed for columnar tools/PHYSLITE).")
79 self.addOption ('decorateSamplingPattern', False, type=bool,
80 info="decorate `samplingPattern` on the clusters (meant for PHYSLITE).")
81 self.addOption ('addGlobalFELinksDep', False, type=bool,
82 info="whether to add dependencies for the global FE links (needed for PHYSLITE production)",
83 expertMode=True)
84

Member Function Documentation

◆ instanceName()

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.instanceName ( self)
Return the instance name for this block

Definition at line 85 of file ElectronAnalysisConfig.py.

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

◆ makeAlgs()

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.makeAlgs ( self,
config )

Definition at line 133 of file ElectronAnalysisConfig.py.

133 def makeAlgs (self, config) :
134
135 if self.forceFullSimConfigForP4:
136 warnings.warn_explicit(
137 "You are running ElectronCalibrationConfig forcing full sim"
138 " config. This is only intended to be used for testing"
139 " purposes.",
140 TestingOnlyWarning, filename='', lineno=0)
141
142 inputContainer = "AnalysisElectrons" if config.isPhyslite() else "Electrons"
143 if self.inputContainer:
144 inputContainer = self.inputContainer
145 config.setSourceName (self.containerName, inputContainer)
146
147 # Decorate calo cluster eta if required
148 if self.decorateCaloClusterEta:
149 alg = config.createAlgorithm( 'CP::EgammaCaloClusterEtaAlg',
150 'ElectronEgammaCaloClusterEtaAlg',
151 reentrant=True )
152 alg.particles = config.readName(self.containerName)
153 config.addOutputVar (self.containerName, 'caloEta2', 'caloEta2', noSys=True, auxType='float')
154
155 if self.decorateSamplingPattern:
156 config.createAlgorithm( 'CP::EgammaSamplingPatternDecoratorAlg', 'EgammaSamplingPatternDecoratorAlg' )
157
158 # Set up a shallow copy to decorate
159 if config.wantCopy (self.containerName) :
160 alg = config.createAlgorithm( 'CP::AsgShallowCopyAlg', 'ElectronShallowCopyAlg' )
161 alg.input = config.readName (self.containerName)
162 alg.output = config.copyName (self.containerName)
163 alg.outputType = 'xAOD::ElectronContainer'
164 decorationList = ['DFCommonElectronsLHLoose',
165 'neflowisol20',
166 'ptcone20_Nonprompt_All_MaxWeightTTVALooseCone_pt500',
167 'ptvarcone30_Nonprompt_All_MaxWeightTTVALooseCone_pt500',
168 'ptcone20_Nonprompt_All_MaxWeightTTVALooseCone_pt1000_CloseByCorr',
169 'ptvarcone30_Nonprompt_All_MaxWeightTTVALooseCone_pt1000_CloseByCorr',
170 'topoetcone20_CloseByCorr','DFCommonAddAmbiguity',
171 'PLIT_PLITel_pelxpromp', 'PLIT_PLITel_pnpxall']
172 if self.addGlobalFELinksDep:
173 decorationList += ['neutralGlobalFELinks', 'chargedGlobalFELinks']
174 if config.dataType() is not DataType.Data:
175 decorationList += ['TruthLink']
176 alg.declareDecorations = decorationList
177
178 # Set up the eta-cut on all electrons prior to everything else
179 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronEtaCutAlg' )
180 alg.selectionDecoration = 'selectEta' + self.postfix + ',as_bits'
181 config.addPrivateTool( 'selectionTool', 'CP::AsgPtEtaSelectionTool' )
182 alg.selectionTool.maxEta = self.maxEta
183 if self.crackVeto:
184 alg.selectionTool.etaGapLow = 1.37
185 alg.selectionTool.etaGapHigh = 1.52
186 alg.selectionTool.useClusterEta = True
187 alg.particles = config.readName (self.containerName)
188 alg.preselection = config.getPreselection (self.containerName, '')
189 config.addSelection (self.containerName, '', alg.selectionDecoration)
190
191 # Select electrons only with good object quality.
192 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronObjectQualityAlg' )
193 config.setExtraInputs ({('xAOD::EventInfo', 'EventInfo.RandomRunNumber')})
194 alg.selectionDecoration = 'goodOQ' + self.postfix + ',as_bits'
195 config.addPrivateTool( 'selectionTool', 'CP::EgammaIsGoodOQSelectionTool' )
196 alg.selectionTool.Mask = xAOD.EgammaParameters.BADCLUSELECTRON
197 alg.particles = config.readName (self.containerName)
198 alg.preselection = config.getPreselection (self.containerName, '')
199 config.addSelection (self.containerName, '', alg.selectionDecoration)
200
201 if not self.splitCalibrationAndSmearing :
202 # Set up the calibration and smearing algorithm:
203 alg = self.makeCalibrationAndSmearingAlg (config, 'ElectronCalibrationAndSmearingAlg')
204 if config.isPhyslite() and not self.recalibratePhyslite :
205 alg.skipNominal = True
206 else:
207 # This splits the EgammaCalibrationAndSmearingTool into two
208 # steps. The first step applies a baseline calibration that
209 # is not affected by systematics. The second step then
210 # applies the systematics dependent corrections. The net
211 # effect is that the slower first step only has to be run
212 # once, while the second is run once per systematic.
213 #
214 # For now (22 May 24) this has to happen in the same job, as
215 # the output of the first step is not part of PHYSLITE, and
216 # even for the nominal the output of the first and second
217 # step are different. In the future the plan is to put both
218 # the output of the first and second step into PHYSLITE,
219 # allowing to skip the first step when running on PHYSLITE.
220 #
221 # WARNING: All of this is experimental, see: ATLASG-2358
222
223 # Set up the calibration algorithm:
224 alg = self.makeCalibrationAndSmearingAlg (config, 'ElectronBaseCalibrationAlg')
225 # turn off systematics for the calibration step
226 alg.noToolSystematics = True
227 # turn off smearing for the calibration step
228 alg.calibrationAndSmearingTool.doSmearing = False
229
230 # Set up the smearing algorithm:
231 alg = self.makeCalibrationAndSmearingAlg (config, 'ElectronCalibrationSystematicsAlg')
232 # turn off scale corrections for the smearing step
233 alg.calibrationAndSmearingTool.doScaleCorrection = False
234 alg.calibrationAndSmearingTool.useMVACalibration = False
235 alg.calibrationAndSmearingTool.decorateEmva = False
236
237 if self.minPt > 0 :
238 # Set up the the pt selection
239 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronPtCutAlg' )
240 alg.selectionDecoration = 'selectPt' + self.postfix + ',as_bits'
241 config.addPrivateTool( 'selectionTool', 'CP::AsgPtEtaSelectionTool' )
242 alg.selectionTool.minPt = self.minPt
243 alg.particles = config.readName (self.containerName)
244 alg.preselection = config.getPreselection (self.containerName, '')
245 config.addSelection (self.containerName, '', alg.selectionDecoration,
246 preselection=True)
247
248 # Set up the isolation correction algorithm:
249 if self.isolationCorrection:
250 alg = config.createAlgorithm( 'CP::EgammaIsolationCorrectionAlg',
251 'ElectronIsolationCorrectionAlg' )
252 config.addPrivateTool( 'isolationCorrectionTool',
253 'CP::IsolationCorrectionTool' )
254 alg.isolationCorrectionTool.IsMC = config.dataType() is not DataType.Data
255 alg.isolationCorrectionTool.AFII_corr = (
256 0 if self.forceFullSimConfigForIso
257 else config.dataType() is DataType.FastSim)
258 AODfixes = config.flags.Input.AODFixesDone
259 if "egammatopoIsoFix" in AODfixes:
260 alg.isolationCorrectionTool.FixTimingIssueInCore = False
261 else:
262 alg.isolationCorrectionTool.FixTimingIssueInCore = True
263 alg.isolationCorrectionTool.ToolVer = "REL22"
264 alg.isolationCorrectionTool.CorrFile = "IsolationCorrections/v6/isolation_ptcorrections_rel22_mc20.root"
265 alg.egammas = config.readName (self.containerName)
266 alg.egammasOut = config.copyName (self.containerName)
267 alg.egammasType = 'xAOD::ElectronContainer'
268 alg.preselection = config.getPreselection (self.containerName, '')
269 else:
270 warnings.warn_explicit(
271 "You are not applying the isolation corrections."
272 " This is only intended to be used for testing purposes.",
273 TestingOnlyWarning, filename='', lineno=0)
274
275 alg = config.createAlgorithm( 'CP::AsgEnergyDecoratorAlg', 'EnergyDecorator' )
276 alg.particles = config.readName(self.containerName)
277
278 config.addOutputVar (self.containerName, 'pt', 'pt', auxType='float')
279 config.addOutputVar (self.containerName, 'eta', 'eta', noSys=True, auxType='float')
280 config.addOutputVar (self.containerName, 'phi', 'phi', noSys=True, auxType='float')
281 config.addOutputVar (self.containerName, 'e_%SYS%', 'e', auxType='float')
282 config.addOutputVar (self.containerName, 'charge', 'charge', noSys=True, auxType='float')
283 if self.splitCalibrationAndSmearing or not (config.isPhyslite() and not self.recalibratePhyslite) :
284 config.addOutputVar (self.containerName, 'caloClusterEnergyReso_%SYS%', 'caloClusterEnergyReso', noSys=True, auxType='float')
285
286 # decorate truth information on the reconstructed object:
287 if self.decorateTruth and config.dataType() is not DataType.Data:
288 config.addOutputVar (self.containerName, "truthType", "truth_type", noSys=True, auxType='int')
289 config.addOutputVar (self.containerName, "truthOrigin", "truth_origin", noSys=True, auxType='int')
290
291 config.addOutputVar (self.containerName, "firstEgMotherPdgId", "truth_firstEgMotherPdgId", noSys=True, auxType='int')
292 config.addOutputVar (self.containerName, "firstEgMotherTruthOrigin", "truth_firstEgMotherTruthOrigin", noSys=True, auxType='int')
293 config.addOutputVar (self.containerName, "firstEgMotherTruthType", "truth_firstEgMotherTruthType", noSys=True, auxType='int')
294
295

◆ makeCalibrationAndSmearingAlg()

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.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 89 of file ElectronAnalysisConfig.py.

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

Member Data Documentation

◆ addGlobalFELinksDep

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.addGlobalFELinksDep

Definition at line 172 of file ElectronAnalysisConfig.py.

◆ containerName

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.containerName

Definition at line 127 of file ElectronAnalysisConfig.py.

◆ crackVeto

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.crackVeto

Definition at line 183 of file ElectronAnalysisConfig.py.

◆ decorateCaloClusterEta

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.decorateCaloClusterEta

Definition at line 148 of file ElectronAnalysisConfig.py.

◆ decorateSamplingPattern

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.decorateSamplingPattern

Definition at line 155 of file ElectronAnalysisConfig.py.

◆ ESModel

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.ESModel

Definition at line 100 of file ElectronAnalysisConfig.py.

◆ forceFullSimConfigForP4

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.forceFullSimConfigForP4

Definition at line 135 of file ElectronAnalysisConfig.py.

◆ inputContainer

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.inputContainer

Definition at line 143 of file ElectronAnalysisConfig.py.

◆ isolationCorrection

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.isolationCorrection

Definition at line 249 of file ElectronAnalysisConfig.py.

◆ recalibratePhyslite

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.recalibratePhyslite

Definition at line 204 of file ElectronAnalysisConfig.py.

◆ splitCalibrationAndSmearing

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.splitCalibrationAndSmearing

Definition at line 201 of file ElectronAnalysisConfig.py.


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