ATLAS Offline Software
EGAM5.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 # ====================================================================
3 # EGAM5.py
4 # This defines DAOD_EGAM5, a skimmed DAOD format for Run 3.
5 # W->enu derivation
6 # It requires the flag EGAM5 in Derivation_tf.py
7 # ====================================================================
8 
9 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
10 from AthenaConfiguration.ComponentFactory import CompFactory
11 from AthenaConfiguration.Enums import MetadataCategory
12 
13 from AthenaCommon.SystemOfUnits import MeV, GeV
14 
15 from DerivationFrameworkEGamma.PhotonsCPDetailedContent import (
16  PhotonsCPDetailedContent,
17 )
18 
19 from DerivationFrameworkEGamma.TriggerContent import (
20  WTnPTriggers,
21  ExtraContainersTrigger,
22  ExtraContainersElectronTrigger,
23  ExtraContainersTriggerDataOnly,
24 )
25 
26 
28  """Configure the EGAM5 skimming tool"""
29  acc = ComponentAccumulator()
30 
31  # 1st selection: trigger-based (WTP triggers)
32  MenuType = None
33  if flags.Trigger.EDMVersion == 2:
34  MenuType = "Run2"
35  elif flags.Trigger.EDMVersion == 3:
36  MenuType = "Run3"
37  else:
38  MenuType = ""
39  triggers = WTnPTriggers[MenuType]
40  print("EGAM5 trigger skimming list (OR): ", triggers)
41 
42  EGAM5_TriggerSkimmingTool = CompFactory.DerivationFramework.TriggerSkimmingTool(
43  name="EGAM5_TriggerSkimmingTool", TriggerListOR=triggers
44  )
45 
46  # 2nd selection: off-line, based on mT(enu)
47  expression2 = "count(EGAM5_ENuTransverseMass > 40*GeV)>=1"
48  print("EGAM5 offline skimming expression: ", expression2)
49  EGAM5_OfflineSkimmingTool = CompFactory.DerivationFramework.xAODStringSkimmingTool(
50  name="EGAM5_OfflineSkimmingTool", expression=expression2
51  )
52 
53  # 3rd selection: mix of off-line and on-line criteria
54  expression3a = " || ".join(
55  [
56  "HLT_e60_lhloose_xe60noL1",
57  "HLT_e120_lhloose",
58  "HLT_j80_xe80",
59  "HLT_xe70",
60  "HLT_xe80_tc_lcw_L1XE50",
61  "HLT_xe90_mht_L1XE50",
62  "HLT_xe90_tc_lcw_wEFMu_L1XE50",
63  "HLT_xe90_mht_wEFMu_L1XE50",
64  ]
65  )
66  expression3b = "count(Electrons.pt > 14.5*GeV) >= 1"
67  expression3 = "( " + expression3a + " ) && ( " + expression3b + " )"
68  print("EGAM5 mixed offline-online skimming expression: ", expression3)
69 
70  EGAM5_OnlineOfflineSkimmingTool = (
71  CompFactory.DerivationFramework.xAODStringSkimmingTool(
72  name="EGAM5_OnlineOfflineSkimmingTool", expression=expression3
73  )
74  )
75 
76  # do the OR of previous selections
77  print("EGAM5 skimming is logical OR of previous selections")
78  EGAM5_SkimmingTool = CompFactory.DerivationFramework.FilterCombinationOR(
79  name="EGAM5_SkimmingTool",
80  FilterList=[
81  EGAM5_OfflineSkimmingTool,
82  EGAM5_TriggerSkimmingTool,
83  EGAM5_OnlineOfflineSkimmingTool,
84  ],
85  )
86 
87  acc.addPublicTool(EGAM5_OfflineSkimmingTool)
88  acc.addPublicTool(EGAM5_TriggerSkimmingTool)
89  acc.addPublicTool(EGAM5_OnlineOfflineSkimmingTool)
90  acc.addPublicTool(EGAM5_SkimmingTool, primary=True)
91 
92  return acc
93 
94 
96  """Configure the EGAM5 enu transverse mass augmentation tool"""
97  acc = ComponentAccumulator()
98 
99  # ====================================================================
100  # enu transverse mass
101  #
102  # 1 tight electron with pT>25 GeV + MET > 25 GeV
103  # ====================================================================
104  electronPtRequirement = "(Electrons.pt > 24.5*GeV)"
105  electronQualityRequirement = "(Electrons.DFCommonElectronsLHTight)"
106  requirement_el = (
107  "(" + electronQualityRequirement + "&&" + electronPtRequirement + ")"
108  )
109 
110  acc.setPrivateTools(
111  CompFactory.DerivationFramework.EGTransverseMassTool(
112  name="EGAM5_enuTransverseMassTool",
113  ObjectRequirements=requirement_el,
114  METmin=25 * GeV,
115  StoreGateEntryName="EGAM5_ENuTransverseMass",
116  ObjectMassHypothesis=0.511 * MeV,
117  ObjectContainerName="Electrons",
118  METContainerName="MET_Core_AntiKt4EMPFlow",
119  )
120  )
121 
122  return acc
123 
124 
125 def EGAM5KernelCfg(flags, name="EGAM5Kernel", **kwargs):
126  """Configure the derivation framework driving algorithm (kernel)
127  for EGAM5"""
128  acc = ComponentAccumulator()
129 
130  # Common augmentations
131  from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg
132 
133  acc.merge(
135  flags, TriggerListsHelper=kwargs["TriggerListsHelper"]
136  )
137  )
138 
139  # EGAM5 augmentations
140  augmentationTools = []
141 
142  # ====================================================================
143  # enu transverse mass
144  # ====================================================================
145  EGAM5enuTransverseMassTool = acc.popToolsAndMerge(
147  )
148  acc.addPublicTool(EGAM5enuTransverseMassTool)
149  augmentationTools.append(EGAM5enuTransverseMassTool)
150 
151  # ====================================================================
152  # Common calo decoration tools
153  # ====================================================================
154  from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
155  CaloDecoratorKernelCfg)
156  acc.merge(CaloDecoratorKernelCfg(flags))
157 
158  # thinning tools
159  thinningTools = []
160  streamName = kwargs["StreamName"]
161 
162  # Track thinning
163  if flags.Derivation.Egamma.doTrackThinning:
164  from DerivationFrameworkInDet.InDetToolsConfig import (
165  TrackParticleThinningCfg,
166  MuonTrackParticleThinningCfg,
167  TauTrackParticleThinningCfg,
168  )
169 
170  TrackThinningKeepElectronTracks = True
171  TrackThinningKeepPhotonTracks = True
172  TrackThinningKeepAllElectronTracks = False
173  TrackThinningKeepJetTracks = False
174  TrackThinningKeepMuonTracks = False
175  TrackThinningKeepTauTracks = False
176  TrackThinningKeepPVTracks = True
177 
178  # Tracks associated with Electrons
179  if TrackThinningKeepElectronTracks:
180  EGAM5ElectronTPThinningTool = (
181  CompFactory.DerivationFramework.EgammaTrackParticleThinning(
182  name="EGAM5ElectronTPThinningTool",
183  StreamName=streamName,
184  SGKey="Electrons",
185  GSFTrackParticlesKey="GSFTrackParticles",
186  InDetTrackParticlesKey="InDetTrackParticles",
187  SelectionString="Electrons.pt > 0*GeV",
188  BestMatchOnly=True,
189  ConeSize=0.3,
190  )
191  )
192  acc.addPublicTool(EGAM5ElectronTPThinningTool)
193  thinningTools.append(EGAM5ElectronTPThinningTool)
194 
195  # Tracks associated with Electrons (all tracks, large cone, for track
196  # isolation studies of the selected electrons)
197  if TrackThinningKeepAllElectronTracks:
198  EGAM5ElectronTPThinningTool2 = (
199  CompFactory.DerivationFramework.EgammaTrackParticleThinning(
200  name="EGAM5ElectronTPThinningTool2",
201  StreamName=streamName,
202  SGKey="Electrons",
203  GSFTrackParticlesKey="GSFTrackParticles",
204  InDetTrackParticlesKey="InDetTrackParticles",
205  SelectionString="Electrons.pt > 4*GeV",
206  BestMatchOnly=False,
207  ConeSize=0.6,
208  )
209  )
210  acc.addPublicTool(EGAM5ElectronTPThinningTool2)
211  thinningTools.append(EGAM5ElectronTPThinningTool2)
212 
213  # Tracks associated with Photons
214  if TrackThinningKeepPhotonTracks:
215  EGAM5PhotonTPThinningTool = (
216  CompFactory.DerivationFramework.EgammaTrackParticleThinning(
217  name="EGAM5PhotonTPThinningTool",
218  StreamName=streamName,
219  SGKey="Photons",
220  GSFTrackParticlesKey="GSFTrackParticles",
221  InDetTrackParticlesKey="InDetTrackParticles",
222  GSFConversionVerticesKey="GSFConversionVertices",
223  SelectionString="Photons.pt > 0*GeV",
224  BestMatchOnly=True,
225  ConeSize=0.3,
226  )
227  )
228  acc.addPublicTool(EGAM5PhotonTPThinningTool)
229  thinningTools.append(EGAM5PhotonTPThinningTool)
230 
231  # Tracks associated with Jets
232  if TrackThinningKeepJetTracks:
233  EGAM5JetTPThinningTool = (
234  CompFactory.DerivationFramework.JetTrackParticleThinning(
235  name="EGAM5JetTPThinningTool",
236  StreamName=streamName,
237  JetKey="AntiKt4EMPFlowJets",
238  InDetTrackParticlesKey="InDetTrackParticles",
239  )
240  )
241  acc.addPublicTool(EGAM5JetTPThinningTool)
242  thinningTools.append(EGAM5JetTPThinningTool)
243 
244  # Tracks associated with Muons
245  if TrackThinningKeepMuonTracks:
246  EGAM5MuonTPThinningTool = acc.getPrimaryAndMerge(
248  flags,
249  name="EGAM5MuonTPThinningTool",
250  StreamName=streamName,
251  MuonKey="Muons",
252  InDetTrackParticlesKey="InDetTrackParticles",
253  )
254  )
255  thinningTools.append(EGAM5MuonTPThinningTool)
256 
257  # Tracks associated with Taus
258  if TrackThinningKeepTauTracks:
259  EGAM5TauTPThinningTool = acc.getPrimaryAndMerge(
261  flags,
262  name="EGAM5TauTPThinningTool",
263  StreamName=streamName,
264  TauKey="TauJets",
265  ConeSize=0.6,
266  InDetTrackParticlesKey="InDetTrackParticles",
267  DoTauTracksThinning=True,
268  TauTracksKey="TauTracks",
269  )
270  )
271  thinningTools.append(EGAM5TauTPThinningTool)
272 
273  # Tracks from primary vertex
274  thinning_expression = " && ".join(
275  [
276  "(InDetTrackParticles.DFCommonTightPrimary)",
277  "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)",
278  "(InDetTrackParticles.pt>10*GeV)",
279  ]
280  )
281  if TrackThinningKeepPVTracks:
282  EGAM5TPThinningTool = acc.getPrimaryAndMerge(
284  flags,
285  name="EGAM5TPThinningTool",
286  StreamName=streamName,
287  SelectionString=thinning_expression,
288  InDetTrackParticlesKey="InDetTrackParticles",
289  )
290  )
291  thinningTools.append(EGAM5TPThinningTool)
292 
293  # skimming
294  skimmingTool = acc.getPrimaryAndMerge(EGAM5SkimmingToolCfg(flags))
295 
296  # setup the kernel
297  acc.addEventAlgo(
298  CompFactory.DerivationFramework.DerivationKernel(
299  name,
300  SkimmingTools=[skimmingTool],
301  AugmentationTools=augmentationTools,
302  ThinningTools=thinningTools,
303  )
304  )
305 
306  return acc
307 
308 
309 def EGAM5Cfg(flags):
310  acc = ComponentAccumulator()
311 
312  # Get the lists of triggers needed for trigger matching.
313  # This is needed at this scope (for the slimming) and further down
314  # in the config chain for actually configuring the matching, so we create
315  # it here and pass it down
316  # TODO: this should ideally be called higher up to avoid it being run
317  # multiple times in a train.
318  # DODO: restrict it to relevant triggers
319  from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper
320 
321  EGAM5TriggerListsHelper = TriggerListsHelper(flags)
322 
323  # configure skimming/thinning/augmentation tools
324  acc.merge(
326  flags,
327  name="EGAM5Kernel",
328  StreamName="StreamDAOD_EGAM5",
329  TriggerListsHelper=EGAM5TriggerListsHelper,
330  )
331  )
332 
333  # configure slimming
334  from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
335  from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg
336  from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper
337 
338  EGAM5SlimmingHelper = SlimmingHelper(
339  "EGAM5SlimmingHelper",
340  NamesAndTypes=flags.Input.TypedCollections,
341  flags=flags,
342  )
343 
344  # ------------------------------------------
345  # containers for which we save all variables
346  # -------------------------------------------
347 
348  # baseline
349  EGAM5SlimmingHelper.AllVariables = [
350  "Electrons",
351  "GSFTrackParticles",
352  "egammaClusters",
353  ]
354 
355  # for trigger studies we also add:
356  MenuType = None
357  if flags.Trigger.EDMVersion == 2:
358  MenuType = "Run2"
359  elif flags.Trigger.EDMVersion == 3:
360  MenuType = "Run3"
361  else:
362  MenuType = ""
363  EGAM5SlimmingHelper.AllVariables += ExtraContainersTrigger[MenuType]
364  EGAM5SlimmingHelper.AllVariables += ExtraContainersElectronTrigger[MenuType]
365  if not flags.Input.isMC:
366  EGAM5SlimmingHelper.AllVariables += ExtraContainersTriggerDataOnly[MenuType]
367 
368  # and on MC we also add:
369  if flags.Input.isMC:
370  EGAM5SlimmingHelper.AllVariables += [
371  "TruthEvents",
372  "TruthParticles",
373  "TruthVertices",
374  "egammaTruthParticles",
375  ]
376 
377  # -------------------------------------------
378  # containers that we slim
379  # -------------------------------------------
380 
381  # first add variables from smart-slimming
382  # adding only also those for which we add all variables since
383  # the XXXCPContent.py files also bring in some extra variables
384  # for other collections
385  EGAM5SlimmingHelper.SmartCollections = [
386  "Electrons",
387  "Photons",
388  "Muons",
389  "TauJets",
390  "InDetTrackParticles",
391  "PrimaryVertices",
392  "AntiKt4EMPFlowJets",
393  "MET_Baseline_AntiKt4EMPFlow",
394  "BTagging_AntiKt4EMPFlow",
395  ]
396  # muons, tau, MET, b-tagging could be switched off if not needed
397  # and use too much space
398  if flags.Input.isMC:
399  EGAM5SlimmingHelper.SmartCollections += [
400  "AntiKt4TruthJets",
401  "AntiKt4TruthDressedWZJets",
402  ]
403 
404  # then add extra variables:
405 
406  # muons
407  EGAM5SlimmingHelper.ExtraVariables += [
408  "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40"
409  ]
410 
411  # conversion vertices
412  EGAM5SlimmingHelper.ExtraVariables += [
413  "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo",
414  "GSFConversionVertices.trackParticleLinks",
415  ]
416 
417  # primary vertices
418  EGAM5SlimmingHelper.ExtraVariables += ["PrimaryVertices.x.y.sumPt2"]
419 
420  # photons: detailed shower shape variables
421  EGAM5SlimmingHelper.ExtraVariables += PhotonsCPDetailedContent
422 
423  # photons and electrons: gain and cluster energy per layer
424  from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
425  getGainDecorations,
426  getClusterEnergyPerLayerDecorations,
427  )
428 
429  gainDecorations = getGainDecorations(acc, flags, "EGAM5Kernel")
430  print("EGAM5 gain decorations: ", gainDecorations)
431  EGAM5SlimmingHelper.ExtraVariables.extend(gainDecorations)
432  clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM5Kernel")
433  print("EGAM5 cluster energy decorations: ", clusterEnergyDecorations)
434  EGAM5SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations)
435 
436  # energy density
437  EGAM5SlimmingHelper.ExtraVariables += [
438  "TopoClusterIsoCentralEventShape.Density",
439  "TopoClusterIsoForwardEventShape.Density",
440  "NeutralParticleFlowIsoCentralEventShape.Density",
441  "NeutralParticleFlowIsoForwardEventShape.Density",
442  ]
443 
444  # truth
445  if flags.Input.isMC:
446  EGAM5SlimmingHelper.ExtraVariables += [
447  "MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType"
448  ]
449 
450  EGAM5SlimmingHelper.ExtraVariables += [
451  "Photons.truthOrigin.truthType.truthParticleLink"
452  ]
453 
454  # Add event info
455  if flags.Derivation.Egamma.doEventInfoSlimming:
456  EGAM5SlimmingHelper.SmartCollections.append("EventInfo")
457  else:
458  EGAM5SlimmingHelper.AllVariables += ["EventInfo"]
459 
460  # Add egamma trigger objects
461  EGAM5SlimmingHelper.IncludeEGammaTriggerContent = True
462 
463  # Trigger matching
464  # Run 2
465  if flags.Trigger.EDMVersion == 2:
466  from DerivationFrameworkPhys.TriggerMatchingCommonConfig import AddRun2TriggerMatchingToSlimmingHelper
467  AddRun2TriggerMatchingToSlimmingHelper(SlimmingHelper = EGAM5SlimmingHelper,
468  OutputContainerPrefix = "TrigMatch_",
469  TriggerList = EGAM5TriggerListsHelper.Run2TriggerNamesNoTau)
470  # Run 3, or Run 2 with navigation conversion
471  if flags.Trigger.EDMVersion == 3 or (flags.Trigger.EDMVersion == 2 and flags.Trigger.doEDMVersionConversion):
472  from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import AddRun3TrigNavSlimmingCollectionsToSlimmingHelper
474 
475  EGAM5ItemList = EGAM5SlimmingHelper.GetItemList()
476  acc.merge(
478  flags,
479  "DAOD_EGAM5",
480  ItemList=EGAM5ItemList,
481  AcceptAlgs=["EGAM5Kernel"],
482  )
483  )
484  acc.merge(
486  flags,
487  "DAOD_EGAM5",
488  AcceptAlgs=["EGAM5Kernel"],
489  createMetadata=[
490  MetadataCategory.CutFlowMetaData,
491  MetadataCategory.TruthMetaData,
492  ],
493  )
494  )
495 
496  return acc
TrigNavSlimmingMTConfig.AddRun3TrigNavSlimmingCollectionsToSlimmingHelper
def AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(slimmingHelper)
Definition: TrigNavSlimmingMTConfig.py:98
SystemOfUnits
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.OutputStreamConfig.OutputStreamCfg
def OutputStreamCfg(flags, streamName, ItemList=[], MetadataItemList=[], disableEventTag=False, trigNavThinningSvc=None, takeItemsFromInput=False, extendProvenanceRecord=True, AcceptAlgs=[], HelperTools=[])
Definition: OutputStreamConfig.py:12
python.InDetToolsConfig.TrackParticleThinningCfg
def TrackParticleThinningCfg(flags, name, **kwargs)
Definition: InDetToolsConfig.py:458
python.TriggerMatchingCommonConfig.AddRun2TriggerMatchingToSlimmingHelper
def AddRun2TriggerMatchingToSlimmingHelper(**kwargs)
Definition: TriggerMatchingCommonConfig.py:49
python.EGAM5.EGAM5enuTransverseMassToolCfg
def EGAM5enuTransverseMassToolCfg(flags)
Definition: EGAM5.py:95
python.EGAM5.EGAM5Cfg
def EGAM5Cfg(flags)
Definition: EGAM5.py:309
python.EGAM5.EGAM5KernelCfg
def EGAM5KernelCfg(flags, name="EGAM5Kernel", **kwargs)
Definition: EGAM5.py:125
python.InDetToolsConfig.MuonTrackParticleThinningCfg
def MuonTrackParticleThinningCfg(flags, name, **kwargs)
Definition: InDetToolsConfig.py:528
python.InDetToolsConfig.TauTrackParticleThinningCfg
def TauTrackParticleThinningCfg(flags, name, **kwargs)
Definition: InDetToolsConfig.py:539
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.EGAM5.EGAM5SkimmingToolCfg
def EGAM5SkimmingToolCfg(flags)
Definition: EGAM5.py:27
DerivationFrameworkCaloConfig.CaloDecoratorKernelCfg
def CaloDecoratorKernelCfg(flags, name="CaloDecoratorKernel", **kwargs)
Definition: DerivationFrameworkCaloConfig.py:77
DerivationFrameworkCaloConfig.getClusterEnergyPerLayerDecorations
def getClusterEnergyPerLayerDecorations(acc, kernel)
Definition: DerivationFrameworkCaloConfig.py:159
DerivationFrameworkCaloConfig.getGainDecorations
def getGainDecorations(acc, flags, kernel, collections=None, info=["E", "nCells"])
Definition: DerivationFrameworkCaloConfig.py:127
python.PhysCommonConfig.PhysCommonAugmentationsCfg
def PhysCommonAugmentationsCfg(flags, **kwargs)
Definition: PhysCommonConfig.py:14
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
InfileMetaDataConfig.SetupMetaDataForStreamCfg
def SetupMetaDataForStreamCfg(flags, streamName="", AcceptAlgs=None, createMetadata=None, propagateMetadataFromInput=True, *args, **kwargs)
Definition: InfileMetaDataConfig.py:219
SlimmingHelper
Definition: SlimmingHelper.py:1