ATLAS Offline Software
Loading...
Searching...
No Matches
EGAM7.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration # ====================================================================
2# EGAM7.py
3# This defines DAOD_EGAM7, a skimmed DAOD format for Run 3.
4# Keep events passing OR of electron triggers, or inclusive
5# electron selection, to retain fake electron candidates
6# Cell collection is saved but thinned (keep only cells associated with
7# egammaClusters)
8# It requires the flag EGAM7 in Derivation_tf.py
9# ====================================================================
10
11from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
12from AthenaConfiguration.ComponentFactory import CompFactory
13from AthenaConfiguration.Enums import MetadataCategory
14
15from DerivationFrameworkEGamma.PhotonsCPDetailedContent import (
16 PhotonsCPDetailedContent,
17)
18
19from DerivationFrameworkEGamma.TriggerContent import (
20 BkgElectronTriggers,
21 ExtraContainersTrigger,
22 ExtraContainersElectronTrigger,
23 ExtraContainersTriggerDataOnly,
24)
25
26
27thinCells = True
28
29
31 """Configure the EGAM7 skimming tool"""
32 acc = ComponentAccumulator()
33 skimmingTools = []
34
35 # off-line based selection
36 expression = "count(Electrons.pt > 4.5*GeV) >= 1"
37 print("EGAM7 offline skimming expression: ", expression)
38 from DerivationFrameworkTools.DerivationFrameworkToolsConfig import (
39 xAODStringSkimmingToolCfg)
40 EGAM7_OfflineSkimmingTool = acc.getPrimaryAndMerge(xAODStringSkimmingToolCfg(
41 flags, name = "EGAM7_OfflineSkimmingTool", expression = expression))
42 skimmingTools += [EGAM7_OfflineSkimmingTool]
43
44 # trigger-based selection
45 MenuType = ""
46 if flags.Trigger.EDMVersion == 2:
47 MenuType = "Run2"
48 elif flags.Trigger.EDMVersion == 3:
49 MenuType = "Run3"
50
51 if MenuType:
52 triggers = BkgElectronTriggers[MenuType]
53 print("EGAM7 trigger skimming list (OR): ", triggers)
54
55 EGAM7_TriggerSkimmingTool = CompFactory.DerivationFramework.TriggerSkimmingTool(
56 name="EGAM7_TriggerSkimmingTool", TriggerListOR=triggers
57 )
58
59 acc.addPublicTool(EGAM7_TriggerSkimmingTool)
60 skimmingTools += [EGAM7_TriggerSkimmingTool]
61
62 # do the AND of trigger-based and offline-based selection
63 print("EGAM7 skimming is logical AND of previous selections")
64 EGAM7_SkimmingTool = CompFactory.DerivationFramework.FilterCombinationAND(
65 name="EGAM7_SkimmingTool",
66 FilterList=skimmingTools
67 )
68
69 acc.addPublicTool(EGAM7_SkimmingTool, primary=True)
70
71 return acc
72
73
74def EGAM7KernelCfg(flags, name="EGAM7Kernel", **kwargs):
75 """Configure the derivation framework driving algorithm (kernel)
76 for EGAM7"""
77 acc = ComponentAccumulator()
78
79 # Schedule extra jets collections
80 from JetRecConfig.StandardSmallRJets import AntiKt4PV0Track
81 from JetRecConfig.JetRecConfig import JetRecCfg
82
83 jetList = [AntiKt4PV0Track]
84 for jd in jetList:
85 acc.merge(JetRecCfg(flags, jd))
86
87 # Common augmentations
88 from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg
89
90 acc.merge(
91 PhysCommonAugmentationsCfg(
92 flags, TriggerListsHelper=kwargs["TriggerListsHelper"]
93 )
94 )
95
96 # EGAM7 augmentations
97 augmentationTools = []
98
99 # ====================================================================
100 # Common calo decoration tools
101 # ====================================================================
102 from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
103 CaloDecoratorKernelCfg)
104 acc.merge(CaloDecoratorKernelCfg(flags))
105
106 # thinning tools
107 thinningTools = []
108
109 streamName = kwargs["StreamName"]
110
111 # Track thinning
112 if flags.Derivation.Egamma.doTrackThinning:
113 from DerivationFrameworkInDet.InDetToolsConfig import (
114 TrackParticleThinningCfg,
115 MuonTrackParticleThinningCfg,
116 TauTrackParticleThinningCfg,
117 )
118
119 TrackThinningKeepElectronTracks = True
120 TrackThinningKeepPhotonTracks = True
121 TrackThinningKeepAllElectronTracks = False
122 TrackThinningKeepJetTracks = False
123 TrackThinningKeepMuonTracks = False
124 TrackThinningKeepTauTracks = False
125 TrackThinningKeepPVTracks = False
126
127 # Tracks associated with Electrons
128 if TrackThinningKeepElectronTracks:
129 EGAM7ElectronTPThinningTool = (
130 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
131 name="EGAM7ElectronTPThinningTool",
132 StreamName=streamName,
133 SGKey="Electrons",
134 GSFTrackParticlesKey="GSFTrackParticles",
135 InDetTrackParticlesKey="InDetTrackParticles",
136 SelectionString="Electrons.pt > 0*GeV",
137 BestMatchOnly=True,
138 ConeSize=0.3,
139 )
140 )
141 acc.addPublicTool(EGAM7ElectronTPThinningTool)
142 thinningTools.append(EGAM7ElectronTPThinningTool)
143
144 # Tracks associated with Electrons (all tracks, large cone, for track
145 # isolation studies of the selected electrons)
146 if TrackThinningKeepAllElectronTracks:
147 EGAM7ElectronTPThinningTool2 = (
148 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
149 name="EGAM7ElectronTPThinningTool2",
150 StreamName=streamName,
151 SGKey="Electrons",
152 GSFTrackParticlesKey="GSFTrackParticles",
153 InDetTrackParticlesKey="InDetTrackParticles",
154 SelectionString="Electrons.pt > 4*GeV",
155 BestMatchOnly=False,
156 ConeSize=0.6,
157 )
158 )
159 acc.addPublicTool(EGAM7ElectronTPThinningTool2)
160 thinningTools.append(EGAM7ElectronTPThinningTool2)
161
162 # Tracks associated with Photons
163 if TrackThinningKeepPhotonTracks:
164 EGAM7PhotonTPThinningTool = (
165 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
166 name="EGAM7PhotonTPThinningTool",
167 StreamName=streamName,
168 SGKey="Photons",
169 GSFTrackParticlesKey="GSFTrackParticles",
170 InDetTrackParticlesKey="InDetTrackParticles",
171 GSFConversionVerticesKey="GSFConversionVertices",
172 SelectionString="Photons.pt > 0*GeV",
173 BestMatchOnly=True,
174 ConeSize=0.3,
175 )
176 )
177 acc.addPublicTool(EGAM7PhotonTPThinningTool)
178 thinningTools.append(EGAM7PhotonTPThinningTool)
179
180 # Tracks associated with Jets
181 if TrackThinningKeepJetTracks:
182 EGAM7JetTPThinningTool = (
183 CompFactory.DerivationFramework.JetTrackParticleThinning(
184 name="EGAM7JetTPThinningTool",
185 StreamName=streamName,
186 JetKey="AntiKt4EMPFlowJets",
187 InDetTrackParticlesKey="InDetTrackParticles",
188 )
189 )
190 acc.addPublicTool(EGAM7JetTPThinningTool)
191 thinningTools.append(EGAM7JetTPThinningTool)
192
193 # Tracks associated with Muons
194 if TrackThinningKeepMuonTracks:
195 EGAM7MuonTPThinningTool = acc.getPrimaryAndMerge(
196 MuonTrackParticleThinningCfg(
197 flags,
198 name="EGAM7MuonTPThinningTool",
199 StreamName=streamName,
200 MuonKey="Muons",
201 InDetTrackParticlesKey="InDetTrackParticles",
202 )
203 )
204 thinningTools.append(EGAM7MuonTPThinningTool)
205
206 # Tracks associated with Taus
207 if TrackThinningKeepTauTracks:
208 EGAM7TauTPThinningTool = acc.getPrimaryAndMerge(
209 TauTrackParticleThinningCfg(
210 flags,
211 name="EGAM7TauTPThinningTool",
212 StreamName=streamName,
213 TauKey="TauJets",
214 ConeSize=0.6,
215 InDetTrackParticlesKey="InDetTrackParticles",
216 DoTauTracksThinning=True,
217 TauTracksKey="TauTracks",
218 )
219 )
220 thinningTools.append(EGAM7TauTPThinningTool)
221
222 # Tracks from primary vertex
223 thinning_expression = " && ".join(
224 [
225 "(InDetTrackParticles.DFCommonTightPrimary)",
226 "(abs(InDetTrackParticles.DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)",
227 "(InDetTrackParticles.pt>10*GeV)",
228 ]
229 )
230 if TrackThinningKeepPVTracks:
231 EGAM7TPThinningTool = acc.getPrimaryAndMerge(
232 TrackParticleThinningCfg(
233 flags,
234 name="EGAM7TPThinningTool",
235 StreamName=streamName,
236 SelectionString=thinning_expression,
237 InDetTrackParticlesKey="InDetTrackParticles",
238 )
239 )
240 thinningTools.append(EGAM7TPThinningTool)
241
242 # truth thinning
243 if flags.Input.isMC:
244 # W, Z and Higgs
245 truth_cond_WZH = "(TruthParticles.isW || TruthParticles.isZ || TruthParticles.isHiggs)"
246 # Leptons
247 truth_cond_lep = "(TruthParticles.isLepton)"
248 # Top quark
249 truth_cond_top = "(TruthParticles.isTop)"
250 # Photon
251 truth_cond_gam = " && ".join(
252 ["(TruthParticles.isPhoton)", "(TruthParticles.pt > 1*GeV)"]
253 )
254 # stable particles
255 truth_cond_finalState = "(TruthParticles.isGenStable)"
256 truth_expression = (
257 "( "
258 + truth_cond_WZH
259 + " ) || "
260 + "( "
261 + truth_cond_lep
262 + " ) || "
263 + "( "
264 + truth_cond_top
265 + " ) || "
266 + "( "
267 + truth_cond_gam
268 + " ) || "
269 + "( "
270 + truth_cond_finalState
271 + " )"
272 )
273 print("EGAM7 truth thinning expression: ", truth_expression)
274
275 EGAM7TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning(
276 name="EGAM7TruthThinningTool",
277 StreamName=streamName,
278 ParticleSelectionString=truth_expression,
279 PreserveDescendants=False,
280 PreserveGeneratorDescendants=True,
281 PreserveAncestors=True,
282 )
283 acc.addPublicTool(EGAM7TruthThinningTool)
284 thinningTools.append(EGAM7TruthThinningTool)
285
286 # Keep only calo cells associated with the egammaClusters collection
287 if thinCells:
288 from DerivationFrameworkCalo.CaloCellDFGetterConfig import thinCaloCellsForDFCfg
289
290 acc.merge(
291 thinCaloCellsForDFCfg(
292 flags,
293 inputClusterKeys=["egammaClusters"],
294 streamName="StreamDAOD_EGAM7",
295 inputCellKey="AllCalo",
296 outputCellKey="DFEGAMCellContainer",
297 )
298 )
299
300 # skimming
301 skimmingTool = acc.getPrimaryAndMerge(EGAM7SkimmingToolCfg(flags))
302
303 # setup the kernel
304 acc.addEventAlgo(
305 CompFactory.DerivationFramework.DerivationKernel(
306 name,
307 SkimmingTools=[skimmingTool],
308 AugmentationTools=augmentationTools,
309 ThinningTools=thinningTools,
310 )
311 )
312
313 return acc
314
315
316def EGAM7Cfg(flags):
317 acc = ComponentAccumulator()
318
319 # Get the lists of triggers needed for trigger matching.
320 # This is needed at this scope (for the slimming) and further down
321 # in the config chain for actually configuring the matching, so we create
322 # it here and pass it down
323 # TODO: this should ideally be called higher up to avoid it being run
324 # multiple times in a train.
325 # DODO: restrict it to relevant triggers
326 from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper
327
328 EGAM7TriggerListsHelper = TriggerListsHelper(flags)
329
330 # configure skimming/thinning/augmentation tools
331 acc.merge(
333 flags,
334 name="EGAM7Kernel",
335 StreamName="StreamDAOD_EGAM7",
336 TriggerListsHelper=EGAM7TriggerListsHelper,
337 )
338 )
339
340 # configure slimming
341 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
342 from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg
343 from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper
344
345 EGAM7SlimmingHelper = SlimmingHelper(
346 "EGAM7SlimmingHelper",
347 NamesAndTypes=flags.Input.TypedCollections,
348 flags=flags,
349 )
350
351 # ------------------------------------------
352 # containers for which we save all variables
353 # -------------------------------------------
354
355 # baseline
356 EGAM7SlimmingHelper.AllVariables = [
357 "Electrons",
358 "GSFTrackParticles",
359 "egammaClusters",
360 ]
361
362 # for trigger studies we also add:
363 MenuType = ""
364 if flags.Trigger.EDMVersion == 2:
365 MenuType = "Run2"
366 elif flags.Trigger.EDMVersion == 3:
367 MenuType = "Run3"
368
369 if MenuType:
370 EGAM7SlimmingHelper.AllVariables += ExtraContainersTrigger[MenuType]
371 EGAM7SlimmingHelper.AllVariables += ExtraContainersElectronTrigger[MenuType]
372 if not flags.Input.isMC:
373 EGAM7SlimmingHelper.AllVariables += ExtraContainersTriggerDataOnly[MenuType]
374
375 # and on MC we also add:
376 if flags.Input.isMC:
377 EGAM7SlimmingHelper.AllVariables += [
378 "TruthEvents",
379 "TruthParticles",
380 "TruthVertices",
381 "egammaTruthParticles",
382 ]
383
384 # -------------------------------------------
385 # containers that we slim
386 # -------------------------------------------
387
388 # first add variables from smart-slimming
389 # adding only also those for which we add all variables since
390 # the XXXCPContent.py files also bring in some extra variables
391 # for other collections
392 # muons, tau, MET, b-tagging could be switched off if not needed
393 # and use too much space
394 EGAM7SlimmingHelper.SmartCollections = [
395 "Electrons",
396 "Photons",
397 "Muons",
398 "TauJets",
399 "InDetTrackParticles",
400 "PrimaryVertices",
401 "AntiKt4EMPFlowJets",
402 "MET_Baseline_AntiKt4EMPFlow",
403
404 ]
405 if flags.Input.isMC:
406 EGAM7SlimmingHelper.SmartCollections += [
407 "AntiKt4TruthJets",
408 "AntiKt4TruthDressedWZJets",
409 ]
410
411 # then add extra variables:
412
413 # muons
414 EGAM7SlimmingHelper.ExtraVariables += [
415 "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40"
416 ]
417
418 # conversion vertices
419 EGAM7SlimmingHelper.ExtraVariables += [
420 "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo",
421 "GSFConversionVertices.trackParticleLinks",
422 ]
423
424 # primary vertices
425 EGAM7SlimmingHelper.ExtraVariables += ["PrimaryVertices.x.y.sumPt2"]
426
427 # track jets
428 EGAM7SlimmingHelper.ExtraVariables += [
429 "AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks"
430 ]
431
432 # photons: detailed shower shape variables
433 EGAM7SlimmingHelper.ExtraVariables += PhotonsCPDetailedContent
434
435 # photons: gain and cluster energy per layer
436 from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
437 getGainDecorations,
438 getClusterEnergyPerLayerDecorations,
439 )
440
441 gainDecorations = getGainDecorations(acc, flags, "EGAM7Kernel")
442 print("EGAM7 gain decorations: ", gainDecorations)
443 EGAM7SlimmingHelper.ExtraVariables.extend(gainDecorations)
444 clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM7Kernel")
445 print("EGAM7 cluster energy decorations: ", clusterEnergyDecorations)
446 EGAM7SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations)
447
448 # energy density
449 EGAM7SlimmingHelper.ExtraVariables += [
450 "TopoClusterIsoCentralEventShape.Density",
451 "TopoClusterIsoForwardEventShape.Density",
452 "NeutralParticleFlowIsoCentralEventShape.Density",
453 "NeutralParticleFlowIsoForwardEventShape.Density",
454 ]
455
456 # truth
457 if flags.Input.isMC:
458 EGAM7SlimmingHelper.ExtraVariables += [
459 "MuonTruthParticles.e.px.py.pz.status.pdgId.truthClassification.truthOrigin.truthType"
460 ]
461
462 EGAM7SlimmingHelper.ExtraVariables += [
463 "Photons.truthClassification.truthOrigin.truthType.truthParticleLink"
464 ]
465
466 # Add event info
467 if flags.Derivation.Egamma.doEventInfoSlimming:
468 EGAM7SlimmingHelper.SmartCollections.append("EventInfo")
469 else:
470 EGAM7SlimmingHelper.AllVariables += ["EventInfo"]
471
472 # Add egamma trigger objects
473 EGAM7SlimmingHelper.IncludeEGammaTriggerContent = True
474
475 # Trigger matching
476 # Run 2
477 if flags.Trigger.EDMVersion == 2:
478 from DerivationFrameworkPhys.TriggerMatchingCommonConfig import AddRun2TriggerMatchingToSlimmingHelper
479 AddRun2TriggerMatchingToSlimmingHelper(SlimmingHelper = EGAM7SlimmingHelper,
480 OutputContainerPrefix = "TrigMatch_",
481 TriggerList = EGAM7TriggerListsHelper.Run2TriggerNamesNoTau)
482 # Run 3, or Run 2 with navigation conversion
483 if flags.Trigger.EDMVersion == 3 or (flags.Trigger.EDMVersion == 2 and flags.Trigger.doEDMVersionConversion):
484 from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import AddRun3TrigNavSlimmingCollectionsToSlimmingHelper
485 AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(EGAM7SlimmingHelper)
486
487 # Add CellContainer and cluster->cell links
488 if thinCells:
489 EGAM7SlimmingHelper.StaticContent = [
490 "CaloCellContainer#DFEGAMCellContainer",
491 "CaloClusterCellLinkContainer#egammaClusters_links",
492 ]
493 else:
494 EGAM7SlimmingHelper.StaticContent = [
495 "CaloCellContainer#AllCalo",
496 "CaloClusterCellLinkContainer#egammaClusters_links",
497 ]
498
499 # PLIT variables
500 if flags.Derivation.Egamma.addPLITInputs:
501 from LeptonTaggers.LeptonTaggersConfig import DecorateImprovedPromptLeptonAlgsCfg, GetExtraImprovedPromptVariablesForDxAOD
502 acc.merge(DecorateImprovedPromptLeptonAlgsCfg(flags))
503 EGAM7SlimmingHelper.ExtraVariables += [ item for item in GetExtraImprovedPromptVariablesForDxAOD() if item.startswith("Electrons")]
504 if flags.Derivation.Egamma.addPLITOutputs:
505 from LeptonTaggers.LeptonTaggersConfig import DecoratePLITAlgsCfg, GetExtraPLITVariablesForDxAOD
506 acc.merge(DecoratePLITAlgsCfg(flags))
507 EGAM7SlimmingHelper.ExtraVariables += [ item for item in GetExtraPLITVariablesForDxAOD() if item.startswith("Electrons")]
508
509 EGAM7ItemList = EGAM7SlimmingHelper.GetItemList()
510 acc.merge(
511 OutputStreamCfg(
512 flags,
513 "DAOD_EGAM7",
514 ItemList=EGAM7ItemList,
515 AcceptAlgs=["EGAM7Kernel"],
516 )
517 )
518 acc.merge(
519 SetupMetaDataForStreamCfg(
520 flags,
521 "DAOD_EGAM7",
522 AcceptAlgs=["EGAM7Kernel"],
523 createMetadata=[
524 MetadataCategory.CutFlowMetaData,
525 MetadataCategory.TruthMetaData,
526 ],
527 )
528 )
529
530 return acc
void print(char *figname, TCanvas *c1)
EGAM7Cfg(flags)
Definition EGAM7.py:316
EGAM7KernelCfg(flags, name="EGAM7Kernel", **kwargs)
Definition EGAM7.py:74
EGAM7SkimmingToolCfg(flags)
Definition EGAM7.py:30