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

Public Member Functions

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

Public Attributes

 ESModel
 forceFullSimConfigForP4
 inputContainer
 containerName
 decorateCaloClusterEta
 decorateSamplingPattern
 crackVeto
 splitCalibrationAndSmearing
 recalibratePhyslite
 isolationCorrection
 writeTrackD0Z0
 runTrackBiasing

Detailed Description

the ConfigBlock for the electron four-momentum correction

Definition at line 18 of file ElectronAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronCalibrationConfig.__init__ ( self)

Definition at line 21 of file ElectronAnalysisConfig.py.

21 def __init__ (self) :
22 super (ElectronCalibrationConfig, self).__init__ ()
23 self.setBlockName('Electrons')
24 self.addOption ('inputContainer', '', type=str,
25 info="the name of the input electron container. If left empty, automatically defaults "
26 "to `AnalysisElectrons` for PHYSLITE or `Electrons` otherwise.")
27 self.addOption ('containerName', '', type=str,
28 noneAction='error',
29 info="the name of the output container after calibration.")
30 self.addOption ('ESModel', '', type=str,
31 info="flag for Egamma calibration. If left empty, use the current recommendations.")
32 self.addOption ('decorrelationModel', '1NP_v1', type=str,
33 info="decorrelation model for the EGamma energy scale. Supported choices are: `1NP_v1`, `FULL_v1`.")
34 self.addOption ('postfix', '', type=str,
35 info="a postfix to apply to decorations and algorithm names. Typically "
36 "not needed here since the calibration is common to all electrons.")
37 self.addOption ('crackVeto', False, type=bool,
38 info=r"whether to perform LAr crack veto based on the cluster $\eta$, "
39 r"i.e. remove electrons within $1.37<\vert\eta\vert<1.52$.")
40 self.addOption ('isolationCorrection', True, type=bool,
41 info="whether or not to perform isolation corrections (leakage "
42 "corrections), i.e. set up an instance of "
43 "`CP::EgammaIsolationCorrectionAlg`.",
44 expertMode=True)
45 self.addOption ('recalibratePhyslite', True, type=bool,
46 info="whether to run the `CP::EgammaCalibrationAndSmearingAlg` on "
47 "PHYSLITE derivations")
48 self.addOption ('minPt', 4.5*GeV, type=float,
49 info="the minimum pT cut to apply to calibrated electrons.")
50 self.addOption ('maxEta', 2.47, type=float,
51 info=r"maximum electron $\vert\eta\vert$.")
52 self.addOption ('forceFullSimConfigForP4', False, type=bool,
53 info="whether to force the tool to use the configuration meant for "
54 "full simulation samples for 4-vector corrections. Only for testing purposes.")
55 self.addOption ('forceFullSimConfigForIso', False, type=bool,
56 info="whether to force the tool to use the configuration meant for "
57 "full simulation samples for isolation corrections. Only for testing purposes.")
58 self.addOption ('splitCalibrationAndSmearing', False, type=bool,
59 info="EXPERIMENTAL: This splits the `EgammaCalibrationAndSmearingTool` "
60 " into two steps. The first step applies a baseline calibration that "
61 "is not affected by systematics. The second step then applies the "
62 "systematics-dependent corrections. The net effect is that the "
63 "slower first step only has to be run once, while the second is run "
64 "once per systematic. ATLASG-2358.",
65 expertMode=True)
66 self.addOption ('runTrackBiasing', False, type=bool,
67 info="EXPERIMENTAL: This enables the `InDetTrackBiasingTool`, for "
68 "tracks associated to electrons. The tool does not have Run 3 "
69 "recommendations yet.",
70 expertMode=True)
71 self.addOption ('decorateTruth', False, type=bool,
72 info="decorate truth particle information on the reconstructed one.")
73 self.addOption ('decorateCaloClusterEta', False, type=bool,
74 info=r"decorate the calo cluster $\eta$.")
75 self.addOption ('writeTrackD0Z0', False, type = bool,
76 info=r"save the $d_0$ significance and $z_0\sin\theta$ variables.")
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

Member Function Documentation

◆ instanceName()

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

Definition at line 82 of file ElectronAnalysisConfig.py.

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

◆ makeAlgs()

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

Definition at line 123 of file ElectronAnalysisConfig.py.

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

◆ makeCalibrationAndSmearingAlg()

python.ElectronAnalysisConfig.ElectronCalibrationConfig.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 86 of file ElectronAnalysisConfig.py.

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

Member Data Documentation

◆ containerName

python.ElectronAnalysisConfig.ElectronCalibrationConfig.containerName

Definition at line 134 of file ElectronAnalysisConfig.py.

◆ crackVeto

python.ElectronAnalysisConfig.ElectronCalibrationConfig.crackVeto

Definition at line 158 of file ElectronAnalysisConfig.py.

◆ decorateCaloClusterEta

python.ElectronAnalysisConfig.ElectronCalibrationConfig.decorateCaloClusterEta

Definition at line 137 of file ElectronAnalysisConfig.py.

◆ decorateSamplingPattern

python.ElectronAnalysisConfig.ElectronCalibrationConfig.decorateSamplingPattern

Definition at line 144 of file ElectronAnalysisConfig.py.

◆ ESModel

python.ElectronAnalysisConfig.ElectronCalibrationConfig.ESModel

Definition at line 98 of file ElectronAnalysisConfig.py.

◆ forceFullSimConfigForP4

python.ElectronAnalysisConfig.ElectronCalibrationConfig.forceFullSimConfigForP4

Definition at line 127 of file ElectronAnalysisConfig.py.

◆ inputContainer

python.ElectronAnalysisConfig.ElectronCalibrationConfig.inputContainer

Definition at line 132 of file ElectronAnalysisConfig.py.

◆ isolationCorrection

python.ElectronAnalysisConfig.ElectronCalibrationConfig.isolationCorrection

Definition at line 223 of file ElectronAnalysisConfig.py.

◆ recalibratePhyslite

python.ElectronAnalysisConfig.ElectronCalibrationConfig.recalibratePhyslite

Definition at line 178 of file ElectronAnalysisConfig.py.

◆ runTrackBiasing

python.ElectronAnalysisConfig.ElectronCalibrationConfig.runTrackBiasing

Definition at line 247 of file ElectronAnalysisConfig.py.

◆ splitCalibrationAndSmearing

python.ElectronAnalysisConfig.ElectronCalibrationConfig.splitCalibrationAndSmearing

Definition at line 175 of file ElectronAnalysisConfig.py.

◆ writeTrackD0Z0

python.ElectronAnalysisConfig.ElectronCalibrationConfig.writeTrackD0Z0

Definition at line 243 of file ElectronAnalysisConfig.py.


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