ATLAS Offline Software
Loading...
Searching...
No Matches
EGAM12.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2# ====================================================================
3# EGAM12.py
4# This defines DAOD_EGAM12, a skimmed DAOD format for Run 3.
5# Keep events passing OR of electron triggers, or inclusive
6# electron selection, to retain fake electron candidates
7# Adaptation of EGAM7 format for heavy ion runs (no triggers, no pflow
8# jets, extra containers)
9# It requires the flag EGAM12 in Derivation_tf.py
10# ====================================================================
11
12from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
13from AthenaConfiguration.ComponentFactory import CompFactory
14from AthenaConfiguration.Enums import MetadataCategory
15
16from DerivationFrameworkEGamma.PhotonsCPDetailedContent import (
17 PhotonsCPDetailedContent,
18)
19
20
21# some info missing to calculate extra decorations
22addCaloDecorations = False
23
24
26 """Configure the EGAM12 skimming tool"""
27 # off-line based selection
28 expression = "count(Electrons.pt > 4.5*GeV) >= 1"
29 print("EGAM12 offline skimming expression: ", expression)
30 from DerivationFrameworkTools.DerivationFrameworkToolsConfig import (
31 xAODStringSkimmingToolCfg)
32 return xAODStringSkimmingToolCfg(flags, name="EGAM12_OfflineSkimmingTool",
33 expression=expression, TrigDecisionTool=None)
34
35
36def EGAM12KernelCfg(flags, name="EGAM12Kernel", **kwargs):
37 """Configure the derivation framework driving algorithm (kernel)
38 for EGAM12"""
39 acc = ComponentAccumulator()
40
41 # Schedule extra jets collections
42 from JetRecConfig.StandardSmallRJets import (
43 AntiKt4EMTopo,
44 AntiKt4PV0Track,
45 AntiKt4Truth,
46 )
47 from JetRecConfig.JetRecConfig import JetRecCfg
48
49 jetList = [AntiKt4EMTopo, AntiKt4PV0Track, AntiKt4Truth]
50 for jd in jetList:
51 acc.merge(JetRecCfg(flags, jd))
52 JetKey = "AntiKt4EMTopoJets"
53
54 # Common augmentations
55 # cannot use PhysCommon sequence because
56 # - no triggers
57 # - no TauJets
58 # so we have to use a modified version here
59 from DerivationFrameworkInDet.InDetCommonConfig import InDetCommonCfg
60 from DerivationFrameworkMuons.MuonsCommonConfig import MuonsCommonCfg
61 from DerivationFrameworkEGamma.EGammaCommonConfig import EGammaCommonCfg
62
63 TrackingFlags = flags.Tracking
64
65 acc.merge(
66 InDetCommonCfg(
67 flags,
68 DoVertexFinding=TrackingFlags.doVertexFinding,
69 AddPseudoTracks=TrackingFlags.doPseudoTracking,
70 DecoLRTTTVA=False,
71 DoR3LargeD0=TrackingFlags.doLargeD0,
72 StoreSeparateLargeD0Container=TrackingFlags.storeSeparateLargeD0Container,
73 MergeLRT=False,
74 )
75 )
76 acc.merge(MuonsCommonCfg(flags))
77 acc.merge(EGammaCommonCfg(flags))
78 # jet cleaning
79 # standard way in PhysCommon is
80 # - calculate tau ID (needed for default jet OR)
81 # - decorate jets with overlap removal
82 # - do event cleaning
83 # but taus are missing in HI derivations so need to do differently
84
85 # Decorate if jet passed JVT criteria
86 from JetJvtEfficiency.JetJvtEfficiencyToolConfig import getJvtSelToolCfg
87
88 algName = "DFJet_EventCleaning_passJvtAlg"
89 passJvtTool = acc.popToolsAndMerge(getJvtSelToolCfg(flags, "AntiKt4EMTopoJets"))
90 passJvtTool.PassFlagName = "DFCommonJets_passJvt"
91 acc.addEventAlgo(
92 CompFactory.JetDecorationAlg(
93 algName, JetContainer="AntiKt4EMTopoJets", Decorators=[passJvtTool]
94 )
95 )
96
97 # Decorate if jet passes OR and save decoration DFCommonJets_passOR
98 # Use modified OR that does not check overlaps with tauls
99 from AssociationUtils.AssociationUtilsConfig import OverlapRemovalToolCfg
100
101 outputLabel = "DFCommonJets_passOR_EMTopo"
102 bJetLabel = "" # default
103 tauLabel = "" # workaround for missing taus
104 tauKey = "" # workaround for missing taus
105 orTool = acc.popToolsAndMerge(
106 OverlapRemovalToolCfg(
107 flags, outputLabel=outputLabel, bJetLabel=bJetLabel, doTaus=False
108 )
109 )
110 algOR = CompFactory.OverlapRemovalGenUseAlg(
111 "OverlapRemovalGenUseAlg",
112 OverlapLabel=outputLabel,
113 OverlapRemovalTool=orTool,
114 TauKey=tauKey,
115 TauLabel=tauLabel,
116 BJetLabel=bJetLabel,
117 )
118 acc.addEventAlgo(algOR)
119
120 # Do the cleaning
121 from JetSelectorTools.JetSelectorToolsConfig import (
122 EventCleaningToolCfg,
123 JetCleaningToolCfg,
124 )
125
126 workingPoints = ["Loose"]
127 prefix = "DFCommonJets_"
128
129 for wp in workingPoints:
130 cleaningLevel = wp + "Bad"
131 # LLP WPs have a slightly different name format
132 if "LLP" in wp:
133 cleaningLevel = wp.replace("LLP", "BadLLP")
134
135 jetCleaningTool = acc.popToolsAndMerge(
136 JetCleaningToolCfg(
137 flags,
138 "JetCleaningTool_" + cleaningLevel,
139 "AntiKt4EMTopoJets",
140 cleaningLevel,
141 False,
142 )
143 )
144 acc.addPublicTool(jetCleaningTool)
145
146 ecTool = acc.popToolsAndMerge(
147 EventCleaningToolCfg(flags, "EventCleaningTool_" + wp, cleaningLevel)
148 )
149 ecTool.JetCleanPrefix = prefix
150 ecTool.OrDecorator = "passOR_EMTopo"
151 ecTool.JetContainer = "AntiKt4EMTopoJets"
152 ecTool.JetCleaningTool = jetCleaningTool
153 acc.addPublicTool(ecTool)
154
155 # Alg to calculate event-level and jet-level cleaning variables
156 # Only store event-level flags for Loose* WPs
157 eventCleanAlg = CompFactory.EventCleaningTestAlg(
158 "EventCleaningTestAlg_" + wp,
159 EventCleaningTool=ecTool,
160 JetCollectionName="AntiKt4EMTopoJets",
161 EventCleanPrefix=prefix,
162 CleaningLevel=cleaningLevel,
163 doEvent=("Loose" in wp),
164 )
165 acc.addEventAlgo(eventCleanAlg)
166
167 # EGAM12 augmentations
168 augmentationTools = []
169
170 # ====================================================================
171 # Common calo decoration tools
172 # ====================================================================
173 if addCaloDecorations:
174 from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
175 CaloDecoratorKernelCfg)
176 acc.merge(CaloDecoratorKernelCfg(flags))
177
178 # thinning tools
179 thinningTools = []
180 streamName = kwargs["StreamName"]
181
182 # Track thinning
183 if flags.Derivation.Egamma.doTrackThinning:
184 from DerivationFrameworkInDet.InDetToolsConfig import (
185 TrackParticleThinningCfg,
186 MuonTrackParticleThinningCfg,
187 TauTrackParticleThinningCfg,
188 )
189
190 TrackThinningKeepElectronTracks = True
191 TrackThinningKeepPhotonTracks = True
192 TrackThinningKeepAllElectronTracks = False
193 TrackThinningKeepJetTracks = False
194 TrackThinningKeepMuonTracks = False
195 TrackThinningKeepTauTracks = False
196 TrackThinningKeepPVTracks = False
197
198 # Tracks associated with Electrons
199 if TrackThinningKeepElectronTracks:
200 EGAM12ElectronTPThinningTool = (
201 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
202 name="EGAM12ElectronTPThinningTool",
203 StreamName=streamName,
204 SGKey="Electrons",
205 GSFTrackParticlesKey="GSFTrackParticles",
206 InDetTrackParticlesKey="InDetTrackParticles",
207 SelectionString="Electrons.pt > 0*GeV",
208 BestMatchOnly=True,
209 ConeSize=0.3,
210 )
211 )
212 acc.addPublicTool(EGAM12ElectronTPThinningTool)
213 thinningTools.append(EGAM12ElectronTPThinningTool)
214
215 # Tracks associated with Electrons (all tracks, large cone, for track
216 # isolation studies of the selected electrons)
217 if TrackThinningKeepAllElectronTracks:
218 EGAM12ElectronTPThinningTool2 = (
219 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
220 name="EGAM12ElectronTPThinningTool2",
221 StreamName=streamName,
222 SGKey="Electrons",
223 GSFTrackParticlesKey="GSFTrackParticles",
224 InDetTrackParticlesKey="InDetTrackParticles",
225 SelectionString="Electrons.pt > 4*GeV",
226 BestMatchOnly=False,
227 ConeSize=0.6,
228 )
229 )
230 acc.addPublicTool(EGAM12ElectronTPThinningTool2)
231 thinningTools.append(EGAM12ElectronTPThinningTool2)
232
233 # Tracks associated with Photons
234 if TrackThinningKeepPhotonTracks:
235 EGAM12PhotonTPThinningTool = (
236 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
237 name="EGAM12PhotonTPThinningTool",
238 StreamName=streamName,
239 SGKey="Photons",
240 GSFTrackParticlesKey="GSFTrackParticles",
241 InDetTrackParticlesKey="InDetTrackParticles",
242 GSFConversionVerticesKey="GSFConversionVertices",
243 SelectionString="Photons.pt > 0*GeV",
244 BestMatchOnly=True,
245 ConeSize=0.3,
246 )
247 )
248 acc.addPublicTool(EGAM12PhotonTPThinningTool)
249 thinningTools.append(EGAM12PhotonTPThinningTool)
250
251 # Tracks associated with Jets
252 if TrackThinningKeepJetTracks:
253 EGAM12JetTPThinningTool = (
254 CompFactory.DerivationFramework.JetTrackParticleThinning(
255 name="EGAM12JetTPThinningTool",
256 StreamName=streamName,
257 JetKey=JetKey,
258 InDetTrackParticlesKey="InDetTrackParticles",
259 )
260 )
261 acc.addPublicTool(EGAM12JetTPThinningTool)
262 thinningTools.append(EGAM12JetTPThinningTool)
263
264 # Tracks associated with Muons
265 if TrackThinningKeepMuonTracks:
266 EGAM12MuonTPThinningTool = acc.getPrimaryAndMerge(
267 MuonTrackParticleThinningCfg(
268 flags,
269 name="EGAM12MuonTPThinningTool",
270 StreamName=streamName,
271 MuonKey="Muons",
272 InDetTrackParticlesKey="InDetTrackParticles",
273 )
274 )
275 thinningTools.append(EGAM12MuonTPThinningTool)
276
277 # Tracks associated with Taus
278 if TrackThinningKeepTauTracks:
279 EGAM12TauTPThinningTool = acc.getPrimaryAndMerge(
280 TauTrackParticleThinningCfg(
281 flags,
282 name="EGAM12TauTPThinningTool",
283 StreamName=streamName,
284 TauKey="TauJets",
285 ConeSize=0.6,
286 InDetTrackParticlesKey="InDetTrackParticles",
287 DoTauTracksThinning=True,
288 TauTracksKey="TauTracks",
289 )
290 )
291 thinningTools.append(EGAM12TauTPThinningTool)
292
293 # Tracks from primary vertex
294 thinning_expression = " && ".join(
295 [
296 "(InDetTrackParticles.DFCommonTightPrimary)",
297 "(abs(InDetTrackParticles.DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)",
298 "(InDetTrackParticles.pt>10*GeV)",
299 ]
300 )
301 if TrackThinningKeepPVTracks:
302 EGAM12TPThinningTool = acc.getPrimaryAndMerge(
303 TrackParticleThinningCfg(
304 flags,
305 name="EGAM12TPThinningTool",
306 StreamName=streamName,
307 SelectionString=thinning_expression,
308 InDetTrackParticlesKey="InDetTrackParticles",
309 )
310 )
311 thinningTools.append(EGAM12TPThinningTool)
312
313 # truth thinning
314 if flags.Input.isMC:
315 # W, Z and Higgs
316 truth_cond_WZH = "(TruthParticles.isW || TruthParticles.isZ || TruthParticles.isHiggs)"
317 # Leptons
318 truth_cond_lep = "(TruthParticles.isLepton)"
319 # Top quark
320 truth_cond_top = "(TruthParticles.isTop)"
321 # Photon
322 truth_cond_gam = " && ".join(
323 ["(TruthParticles.isPhoton)", "(TruthParticles.pt > 1*GeV)"]
324 )
325 # stable particles
326 truth_cond_finalState = "(TruthParticles.isGenStable)"
327 truth_expression = (
328 "( "
329 + truth_cond_WZH
330 + " ) || "
331 + "( "
332 + truth_cond_lep
333 + " ) || "
334 + "( "
335 + truth_cond_top
336 + " ) || "
337 + "( "
338 + truth_cond_gam
339 + " ) || "
340 + "( "
341 + truth_cond_finalState
342 + " )"
343 )
344 print("EGAM12 truth thinning expression: ", truth_expression)
345
346 EGAM12TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning(
347 name="EGAM12TruthThinningTool",
348 StreamName=streamName,
349 ParticleSelectionString=truth_expression,
350 PreserveDescendants=False,
351 PreserveGeneratorDescendants=True,
352 PreserveAncestors=True,
353 )
354 acc.addPublicTool(EGAM12TruthThinningTool)
355 thinningTools.append(EGAM12TruthThinningTool)
356
357 # skimming
358 skimmingTool = acc.getPrimaryAndMerge(EGAM12SkimmingToolCfg(flags))
359
360 # setup the kernel
361 acc.addEventAlgo(
362 CompFactory.DerivationFramework.DerivationKernel(
363 name,
364 SkimmingTools=[skimmingTool],
365 AugmentationTools=augmentationTools,
366 ThinningTools=thinningTools,
367 )
368 )
369
370 return acc
371
372
373def EGAM12Cfg(flags):
374 acc = ComponentAccumulator()
375
376 JetKey = "AntiKt4EMTopoJets"
377 EGAM12TriggerListsHelper = None
378
379 # configure skimming/thinning/augmentation tools
380 acc.merge(
382 flags,
383 name="EGAM12Kernel",
384 StreamName="StreamDAOD_EGAM12",
385 TriggerListsHelper=EGAM12TriggerListsHelper,
386 )
387 )
388
389 # configure slimming
390 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
391 from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg
392 from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper
393
394 EGAM12SlimmingHelper = SlimmingHelper(
395 "EGAM12SlimmingHelper",
396 NamesAndTypes=flags.Input.TypedCollections,
397 flags=flags,
398 )
399
400 # ------------------------------------------
401 # containers for which we save all variables
402 # -------------------------------------------
403
404 # baseline
405 EGAM12SlimmingHelper.AllVariables = [
406 "Electrons",
407 "GSFTrackParticles",
408 "egammaClusters",
409 ]
410
411 # on MC we also add:
412 if flags.Input.isMC:
413 EGAM12SlimmingHelper.AllVariables += [
414 "TruthEvents",
415 "TruthParticles",
416 "TruthVertices",
417 "egammaTruthParticles",
418 ]
419
420 # -------------------------------------------
421 # containers that we slim
422 # -------------------------------------------
423
424 # first add variables from smart-slimming
425 # adding only also those for which we add all variables since
426 # the XXXCPContent.py files also bring in some extra variables
427 # for other collections
428 # muons, tau, MET, b-tagging could be switched off if not needed
429 # and use too much space
430 EGAM12SlimmingHelper.SmartCollections = [
431 "Electrons",
432 "Photons",
433 "Muons",
434 "TauJets",
435 "InDetTrackParticles",
436 "PrimaryVertices",
437 JetKey,
438 ]
439
440 if flags.Input.isMC:
441 EGAM12SlimmingHelper.SmartCollections += [
442 "AntiKt4TruthJets",
443 "AntiKt4TruthDressedWZJets",
444 ]
445
446 # then add extra variables:
447
448 # muons
449 EGAM12SlimmingHelper.ExtraVariables += [
450 "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40"
451 ]
452
453 # conversion vertices
454 EGAM12SlimmingHelper.ExtraVariables += [
455 "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo",
456 "GSFConversionVertices.trackParticleLinks",
457 ]
458
459 # primary vertices
460 EGAM12SlimmingHelper.ExtraVariables += ["PrimaryVertices.x.y.sumPt2"]
461
462 # track jets
463 EGAM12SlimmingHelper.ExtraVariables += [
464 "AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks"
465 ]
466
467 # photons: detailed shower shape variables
468 EGAM12SlimmingHelper.ExtraVariables += PhotonsCPDetailedContent
469
470 # photons: gain and cluster energy per layer
471 if addCaloDecorations:
472 from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
473 getGainDecorations,
474 getClusterEnergyPerLayerDecorations,
475 )
476
477 gainDecorations = getGainDecorations(acc, flags, "EGAM12Kernel")
478 print("EGAM12 gain decorations: ", gainDecorations)
479 EGAM12SlimmingHelper.ExtraVariables.extend(gainDecorations)
480 clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(
481 acc, "EGAM12Kernel"
482 )
483 print("EGAM12 cluster energy decorations: ", clusterEnergyDecorations)
484 EGAM12SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations)
485
486 # energy density
487 EGAM12SlimmingHelper.ExtraVariables += [
488 "TopoClusterIsoCentralEventShape.Density",
489 "TopoClusterIsoForwardEventShape.Density",
490 ]
491
492 # truth
493 if flags.Input.isMC:
494 EGAM12SlimmingHelper.ExtraVariables += [
495 "MuonTruthParticles.e.px.py.pz.status.pdgId.truthClassification.truthOrigin.truthType"
496 ]
497
498 EGAM12SlimmingHelper.ExtraVariables += [
499 "Photons.truthClassification.truthOrigin.truthType.truthParticleLink"
500 ]
501
502 # Add event info
503 if flags.Derivation.Egamma.doEventInfoSlimming:
504 EGAM12SlimmingHelper.SmartCollections.append("EventInfo")
505 else:
506 EGAM12SlimmingHelper.AllVariables += ["EventInfo"]
507
508 # Add HIEventShape and CaloSums variables for heavy ions
509 EGAM12SlimmingHelper.AllVariables += ["HIEventShape"]
510 EGAM12SlimmingHelper.AllVariables += ["CaloSums"]
511
512 EGAM12ItemList = EGAM12SlimmingHelper.GetItemList()
513 acc.merge(
514 OutputStreamCfg(
515 flags,
516 "DAOD_EGAM12",
517 ItemList=EGAM12ItemList,
518 AcceptAlgs=["EGAM12Kernel"],
519 )
520 )
521 acc.merge(
522 SetupMetaDataForStreamCfg(
523 flags,
524 "DAOD_EGAM12",
525 AcceptAlgs=["EGAM12Kernel"],
526 createMetadata=[
527 MetadataCategory.CutFlowMetaData,
528 MetadataCategory.TruthMetaData,
529 ],
530 )
531 )
532
533 return acc
void print(char *figname, TCanvas *c1)
EGAM12Cfg(flags)
Definition EGAM12.py:373
EGAM12SkimmingToolCfg(flags)
Definition EGAM12.py:25
EGAM12KernelCfg(flags, name="EGAM12Kernel", **kwargs)
Definition EGAM12.py:36