ATLAS Offline Software
Loading...
Searching...
No Matches
PhotonAnalysisConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3# AnaAlgorithm import(s):
4from AnalysisAlgorithmsConfig.ConfigBlock import ConfigBlock
5from AnalysisAlgorithmsConfig.ConfigSequence import groupBlocks
6from AthenaCommon.SystemOfUnits import GeV
7from AthenaConfiguration.Enums import LHCPeriod
8from Campaigns.Utils import Campaign
9from AnalysisAlgorithmsConfig.ConfigAccumulator import (
10 DataType, Run4FallbackWarning, TestingOnlyWarning)
11import warnings
12
13import ROOT
14
15# E/gamma import(s).
16from xAODEgamma.xAODEgammaParameters import xAOD
17
19
20class PhotonCalibrationConfig (ConfigBlock) :
21 """the ConfigBlock for the photon four-momentum correction"""
22
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
83 def instanceName (self) :
84 """Return the instance name for this block"""
85 return self.containerName + self.postfix
86
87
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 = (
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
130 def makeAlgs (self, config) :
131
132 postfix = self.postfix
133 if postfix != '' and postfix[0] != '_' :
134 postfix = '_' + postfix
135
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
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']
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
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
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
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.
293
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 = (
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
336 """the ConfigBlock for the photon working point selection"""
337
338 def __init__ (self) :
339 super (PhotonWorkingPointSelectionConfig, self).__init__ ()
340 self.setBlockName('PhotonWorkingPointSelection')
341 self.addOption ('containerName', '', type=str,
342 noneAction='error',
343 info="the name of the input container.",
344 meta={'role':'containerRef'})
345 self.addOption ('selectionName', '', type=str,
346 noneAction='error',
347 info="the name of the photon selection to define (e.g. `tight` or "
348 "`loose`).",
349 meta={'role':'selection'})
350 self.addOption ('postfix', None, type=str,
351 info="a postfix to apply to decorations and algorithm names. "
352 "Typically not needed here as `selectionName` is used internally.")
353 self.addOption ('qualityWP', None, type=str,
354 info="the ID WP to use. Supported ID WPs: `Tight`, `Medium`, `Loose`.",
355 meta={'choices':(['Tight','Medium','Loose'],1)})
356 self.addOption ('isolationWP', None, type=str,
357 info="the isolation WP to use. Supported isolation WPs: "
358 "`FixedCutLoose`, `FixedCutTight`, `TightCaloOnly`, `NonIso`.",
359 meta={'choices':(['FixedCutLoose','FixedCutTight','TightCaloOnly','NonIso'],1)})
360 self.addOption ('addSelectionToPreselection', True, type=bool,
361 info="whether to retain only photons satisfying the working point "
362 "requirements.")
363 self.addOption ('closeByCorrection', False, type=bool,
364 info="whether to use close-by-corrected isolation working points.")
365 self.addOption ('recomputeIsEM', False, type=bool,
366 info="whether to rerun the cut-based selection (`True`), or rely on derivation flags (`False`).")
367 self.addOption ('doFSRSelection', False, type=bool,
368 info="whether to accept additional photons close to muons for the "
369 "purpose of FSR corrections to these muons. Expert feature "
370 "requested by the H4l analysis running on PHYSLITE.",
371 expertMode=True)
372 self.addOption ('muonsForFSRSelection', None, type=str,
373 info="the name of the muon container to use for the FSR selection. "
374 "If not specified, AnalysisMuons is used.",
375 expertMode=True,
376 meta={'role':'containerRef'})
377
378 def instanceName (self) :
379 """Return the instance name for this block"""
380 if self.postfix is not None :
381 return self.containerName + '_' + self.selectionName + self.postfix
382 return self.containerName + '_' + self.selectionName
383
384 def makeAlgs (self, config) :
385
386 # The setup below is inappropriate for Run 1
387 if config.geometry() is LHCPeriod.Run1:
388 raise ValueError ("Can't set up the PhotonWorkingPointConfig with %s, there must be something wrong!" % config.geometry().value)
389
390 postfix = self.postfix
391 if postfix is None :
392 postfix = self.selectionName
393 if postfix != '' and postfix[0] != '_' :
394 postfix = '_' + postfix
395
396 if self.qualityWP == 'Tight' :
397 quality = ROOT.egammaPID.PhotonTight
398 elif self.qualityWP == 'Medium' :
399 quality = ROOT.egammaPID.PhotonMedium
400 elif self.qualityWP == 'Loose' :
401 quality = ROOT.egammaPID.PhotonLoose
402 else :
403 raise Exception (f'unknown photon quality working point "{self.qualityWP}" should be Tight, Medium or Loose')
404
405 # Set up the photon selection algorithm:
406 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'PhotonIsEMSelectorAlg' )
407 alg.selectionDecoration = 'selectEM' + postfix + ',as_char'
409 # Rerun the cut-based ID
410 config.addPrivateTool( 'selectionTool', 'AsgPhotonIsEMSelector' )
411 alg.selectionTool.isEMMask = quality
412 if config.geometry() is LHCPeriod.Run2:
413 if self.qualityWP == 'Tight':
414 alg.selectionTool.ConfigFile = 'ElectronPhotonSelectorTools/offline/mc20_20240510/PhotonIsEMTightSelectorCutDefs_pTdep_mc20_smooth.conf'
415 elif self.qualityWP == 'Loose':
416 alg.selectionTool.ConfigFile = 'ElectronPhotonSelectorTools/offline/mc15_20150712/PhotonIsEMLooseSelectorCutDefs.conf'
417 elif self.qualityWP == 'Medium':
418 alg.selectionTool.ConfigFile = 'ElectronPhotonSelectorTools/offline/mc20_20240510/PhotonIsEMMediumSelectorCutDefs_pTdep_smooth.conf'
419 if config.geometry() is LHCPeriod.Run3:
420 if self.qualityWP == 'Tight':
421 alg.selectionTool.ConfigFile = 'ElectronPhotonSelectorTools/offline/mc23_20260924/PhotonIsEMTightSelectorCutDefs.conf'
422 elif self.qualityWP == 'Loose':
423 alg.selectionTool.ConfigFile = 'ElectronPhotonSelectorTools/offline/mc15_20150712/PhotonIsEMLooseSelectorCutDefs.conf'
424 elif self.qualityWP == 'Medium':
425 raise ValueError('No Medium menu available for Run-3. Please get in contact with egamma')
426 else:
427 # Select from Derivation Framework flags
428 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
429 dfFlag = 'DFCommonPhotonsIsEM' + self.qualityWP
430 alg.selectionTool.selectionFlags = [ dfFlag ]
431 alg.particles = config.readName (self.containerName)
432 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
433
434 # Set up the FSR selection
436 # wpSelection needs the ',as_char' suffix so SysReadSelectionHandle knows the type
437 wpDecoration = alg.selectionDecoration
438 wpDecorationName = wpDecoration.split(',')[0]
439 # Insert FSR before the postfix (e.g., selectEM_loose -> selectEMFSR_loose)
440 underscorePos = wpDecorationName.find('_')
441 if underscorePos < 0:
442 underscorePos = len(wpDecorationName)
443 outputDecorationName = wpDecorationName[:underscorePos] + 'FSR' + wpDecorationName[underscorePos:]
444
445 alg = config.createAlgorithm( 'CP::EgammaFSRForMuonsCollectorAlg', 'EgammaFSRForMuonsCollectorAlg')
446 alg.wpSelection = wpDecoration # Input: read the WP selection (with type suffix)
447 alg.selectionDecoration = outputDecorationName # Output: combined WP||FSR (name only for SysWriteDecorHandle)
448 alg.ElectronOrPhotonContKey = config.readName (self.containerName)
449 if self.muonsForFSRSelection is not None:
450 alg.MuonContKey = config.readName (self.muonsForFSRSelection)
451
452 # Register the FSR COMBINED selection
453 config.addSelection (self.containerName, self.selectionName,
454 alg.selectionDecoration + ',as_char',
455 preselection=self.addSelectionToPreselection)
456 else:
457 # No FSR - register the WP selection directly
458 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
459 preselection=self.addSelectionToPreselection)
460
461 # Set up the isolation selection algorithm:
462 if self.isolationWP != 'NonIso' :
463 alg = config.createAlgorithm( 'CP::EgammaIsolationSelectionAlg',
464 'PhotonIsolationSelectionAlg' )
465 alg.selectionDecoration = 'isolated' + postfix + ',as_char'
466 config.addPrivateTool( 'selectionTool', 'CP::IsolationSelectionTool' )
467 alg.selectionTool.PhotonWP = self.isolationWP
469 alg.selectionTool.IsoDecSuffix = "CloseByCorr"
470 alg.isPhoton = True
471 alg.egammas = config.readName (self.containerName)
472 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
473 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
474 preselection=self.addSelectionToPreselection)
475
476
478 """the ConfigBlock for the photon working point efficiency computation"""
479
480 def __init__ (self) :
481 super (PhotonWorkingPointEfficiencyConfig, self).__init__ ()
482 self.setBlockName('PhotonWorkingPointEfficiency')
483 self.addDependency('PhotonWorkingPointSelection', required=True)
484 self.addDependency('EventSelection', required=False)
485 self.addDependency('EventSelectionMerger', required=False)
486 self.addOption ('containerName', '', type=str,
487 noneAction='error',
488 info="the name of the input container.",
489 meta={'role':'containerRef'})
490 self.addOption ('selectionName', '', type=str,
491 noneAction='error',
492 info="the name of the photon selection to define (e.g. `tight` or "
493 "`loose`).",
494 meta={'role':'selection'})
495 self.addOption ('postfix', None, type=str,
496 info="a postfix to apply to decorations and algorithm names. "
497 "Typically not needed here as `selectionName` is used internally.")
498 self.addOption ('qualityWP', None, type=str,
499 info="the ID WP to use. Supported ID WPs: `Tight`, `Medium`, `Loose`.",
500 meta={'choices':(['Tight','Medium','Loose'],1)})
501 self.addOption ('isolationWP', None, type=str,
502 info="the isolation WP to use. Supported isolation WPs: "
503 "`FixedCutLoose`, `FixedCutTight`, `TightCaloOnly`, `NonIso`.",
504 meta={'choices':(['FixedCutLoose','FixedCutTight','TightCaloOnly','NonIso'],1)})
505 self.addOption ('noEffSFForID', False, type=bool,
506 info="disables the calculation of ID efficiencies and scale factors. "
507 "Experimental! only useful to test a new WP for which scale "
508 "factors are not available.",
509 expertMode=True)
510 self.addOption ('noEffSFForIso', False, type=bool,
511 info="disables the calculation of isolation efficiencies and scale factors. "
512 "Experimental! only useful to test a new WP for which scale "
513 "factors are not available.",
514 expertMode=True)
515 self.addOption ('saveDetailedSF', True, type=bool,
516 info="save all the independent detailed object scale factors.")
517 self.addOption ('saveCombinedSF', False, type=bool,
518 info="save the combined object scale factor.")
519 self.addOption ('forceFullSimConfigForID', False, type=bool,
520 info="whether to force the ID tool to use the configuration meant "
521 "for full simulation samples. Only for testing purposes.")
522 self.addOption ('forceFullSimConfigForIso', False, type=bool,
523 info="whether to force the isolation tool to use the configuration meant "
524 "for full simulation samples. Only for testing purposes.")
525
526 def instanceName (self) :
527 """Return the instance name for this block"""
528 if self.postfix is not None :
529 return self.containerName + '_' + self.selectionName + self.postfix
530 return self.containerName + '_' + self.selectionName
531
532 def makeAlgs (self, config) :
533
534 # The setup below is inappropriate for Run 1
535 if config.geometry() is LHCPeriod.Run1:
536 raise ValueError ("Can't set up the PhotonWorkingPointConfig with %s, there must be something wrong!" % config.geometry().value)
537
539 warnings.warn_explicit(
540 "You are running PhotonWorkingPointConfig forcing"
541 " full sim config for ID."
542 " This is only intended to be used for testing purposes.",
543 TestingOnlyWarning, filename='', lineno=0)
544
546 warnings.warn_explicit(
547 "You are running PhotonWorkingPointConfig forcing"
548 " full sim config for Iso."
549 " This is only intended to be used for testing purposes.",
550 TestingOnlyWarning, filename='', lineno=0)
551
552 postfix = self.postfix
553 if postfix is None :
554 postfix = self.selectionName
555 if postfix != '' and postfix[0] != '_' :
556 postfix = '_' + postfix
557
558 sfList = []
559 # Set up the ID/reco photon efficiency correction algorithm:
560 if config.dataType() is not DataType.Data and not self.noEffSFForID:
561 alg = config.createAlgorithm( 'CP::PhotonEfficiencyCorrectionAlg',
562 'PhotonEfficiencyCorrectionAlgID' )
563 config.addPrivateTool( 'efficiencyCorrectionTool',
564 'AsgPhotonEfficiencyCorrectionTool' )
565 alg.scaleFactorDecoration = 'ph_id_effSF' + postfix + '_%SYS%'
566 if config.dataType() is DataType.FastSim:
567 alg.efficiencyCorrectionTool.ForceDataType = (
568 PATCore.ParticleDataType.Full if self.forceFullSimConfigForID else
569 PATCore.ParticleDataType.Fast)
570 elif config.dataType() is DataType.FullSim:
571 alg.efficiencyCorrectionTool.ForceDataType = \
572 PATCore.ParticleDataType.Full
573 alg.efficiencyCorrectionTool.MapFilePath = 'PhotonEfficiencyCorrection/2015_2025/rel22.2/2026_Run3Consolidated_Recommendation_v1/map0.txt'
574 alg.outOfValidity = 2 #silent
575 alg.outOfValidityDeco = 'ph_id_bad_eff' + postfix
576 alg.photons = config.readName (self.containerName)
577 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
579 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
580 'id_effSF' + postfix)
581 sfList += [alg.scaleFactorDecoration]
582
583 # Set up the ISO photon efficiency correction algorithm:
584 if config.dataType() is not DataType.Data and self.isolationWP != 'NonIso' and not self.noEffSFForIso:
585 alg = config.createAlgorithm( 'CP::PhotonEfficiencyCorrectionAlg',
586 'PhotonEfficiencyCorrectionAlgIsol' )
587 config.addPrivateTool( 'efficiencyCorrectionTool',
588 'AsgPhotonEfficiencyCorrectionTool' )
589 alg.scaleFactorDecoration = 'ph_isol_effSF' + postfix + '_%SYS%'
590 if config.dataType() is DataType.FastSim:
591 alg.efficiencyCorrectionTool.ForceDataType = (
592 PATCore.ParticleDataType.Full if self.forceFullSimConfigForIso else
593 PATCore.ParticleDataType.Fast)
594 elif config.dataType() is DataType.FullSim:
595 alg.efficiencyCorrectionTool.ForceDataType = \
596 PATCore.ParticleDataType.Full
597 alg.efficiencyCorrectionTool.IsoKey = self.isolationWP.replace("FixedCut","")
598 alg.efficiencyCorrectionTool.MapFilePath = 'PhotonEfficiencyCorrection/2015_2025/rel22.2/2022_Summer_Prerecom_v1/map1.txt'
599 alg.outOfValidity = 2 #silent
600 alg.outOfValidityDeco = 'ph_isol_bad_eff' + postfix
601 alg.photons = config.readName (self.containerName)
602 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
603 if self.saveDetailedSF:
604 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
605 'isol_effSF' + postfix)
606 sfList += [alg.scaleFactorDecoration]
607
608 doCombEffSF = not self.noEffSFForID or not self.noEffSFForIso
609 if config.dataType() is not DataType.Data and doCombEffSF and self.saveCombinedSF:
610 alg = config.createAlgorithm( 'CP::AsgObjectScaleFactorAlg',
611 'PhotonCombinedEfficiencyScaleFactorAlg' )
612 alg.particles = config.readName (self.containerName)
613 alg.inScaleFactors = sfList
614 alg.outScaleFactor = 'effSF' + postfix + '_%SYS%'
615 config.addOutputVar (self.containerName, alg.outScaleFactor, 'effSF' + postfix)
616
617
618@groupBlocks
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:312