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 recalibrate PHYSLITE derivations, i.e. run the "
54 "`CP::EgammaCalibrationAndSmearingAlg` on the nominal. If `False` "
55 "the nominal stored in the PHYSLITE is used, and only the "
56 "systematic variations are recomputed.")
57 self.addOption ('minPt', 4.5*GeV, type=float,
58 info=r"the minimum $p_\mathrm{T}$ cut (in MeV) to apply to calibrated electrons.")
59 self.addOption ('maxEta', 2.47, type=float,
60 info=r"maximum electron $\vert\eta\vert$.")
61 self.addOption ('forceFullSimConfigForP4', False, type=bool,
62 info="whether to force the tool to use the configuration meant for "
63 "full simulation samples for 4-vector corrections. Only for testing purposes.")
64 self.addOption ('forceFullSimConfigForIso', False, type=bool,
65 info="whether to force the tool to use the configuration meant for "
66 "full simulation samples for isolation corrections. Only for testing purposes.")
67 self.addOption ('splitCalibrationAndSmearing', False, type=bool,
68 info="whether to split the `EgammaCalibrationAndSmearingTool` "
69 "into two steps. The first step applies a baseline calibration that "
70 "is not affected by systematics. The second step then applies the "
71 "systematics-dependent corrections. The net effect is that the "
72 "slower first step only has to be run once, while the second is run "
73 "once per systematic. On PHYSLITE with `recalibratePhyslite=False` "
74 "the first step is skipped, and for simulation the second step "
75 "starts from the `E_mva_only` stored in the PHYSLITE. ATLASG-2358.")
76 self.addOption ('decorateTruth', False, type=bool,
77 info="decorate truth particle information on the reconstructed one.")
78 self.addOption ('decorateCaloClusterEta', False, type=bool,
79 info=r"decorate the calo cluster $\eta$.")
80 self.addOption ('decorateEmva', False, type=bool,
81 info="decorate `E_mva_only` on the electrons (needed for columnar tools/PHYSLITE).")
82 self.addOption ('decorateSamplingPattern', False, type=bool,
83 info="decorate `samplingPattern` on the clusters (meant for PHYSLITE).")
84 self.addOption ('addGlobalFELinksDep', False, type=bool,
85 info="whether to add dependencies for the global FE links (needed for PHYSLITE production)",
86 expertMode=True)
87

Member Function Documentation

◆ instanceName()

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

Definition at line 88 of file ElectronAnalysisConfig.py.

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

◆ makeAlgs()

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

Definition at line 140 of file ElectronAnalysisConfig.py.

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

◆ 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 92 of file ElectronAnalysisConfig.py.

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

Member Data Documentation

◆ addGlobalFELinksDep

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.addGlobalFELinksDep

Definition at line 179 of file ElectronAnalysisConfig.py.

◆ containerName

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.containerName

Definition at line 134 of file ElectronAnalysisConfig.py.

◆ crackVeto

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.crackVeto

Definition at line 190 of file ElectronAnalysisConfig.py.

◆ decorateCaloClusterEta

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.decorateCaloClusterEta

Definition at line 155 of file ElectronAnalysisConfig.py.

◆ decorateSamplingPattern

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.decorateSamplingPattern

Definition at line 162 of file ElectronAnalysisConfig.py.

◆ ESModel

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.ESModel

Definition at line 103 of file ElectronAnalysisConfig.py.

◆ forceFullSimConfigForP4

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.forceFullSimConfigForP4

Definition at line 142 of file ElectronAnalysisConfig.py.

◆ inputContainer

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.inputContainer

Definition at line 150 of file ElectronAnalysisConfig.py.

◆ isolationCorrection

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.isolationCorrection

Definition at line 271 of file ElectronAnalysisConfig.py.

◆ recalibratePhyslite

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.recalibratePhyslite

Definition at line 211 of file ElectronAnalysisConfig.py.

◆ splitCalibrationAndSmearing

python.ElectronAnalysisConfig.ElectronMomentumCalibrationConfig.splitCalibrationAndSmearing

Definition at line 208 of file ElectronAnalysisConfig.py.


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