ATLAS Offline Software
EGAM10.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 # ====================================================================
3 # EGAM10.py
4 # This defines DAOD_EGAM10, a skimmed DAOD format for Run 3.
5 # Inclusive photon reduction - for e/gamma photon studies
6 # (migrated from r21 STDM2)
7 # It requires the flag EGAM10 in Derivation_tf.py
8 # ====================================================================
9 
10 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
11 from AthenaConfiguration.ComponentFactory import CompFactory
12 from AthenaConfiguration.Enums import MetadataCategory
13 
14 from DerivationFrameworkEGamma.PhotonsCPDetailedContent import (
15  PhotonsCPDetailedContent,
16 )
17 
18 from DerivationFrameworkEGamma.TriggerContent import (
19  singlePhotonTriggers,
20  diPhotonTriggers,
21  triPhotonTriggers,
22  noalgTriggers,
23 )
24 
25 electronRequirements = " && ".join(
26  [
27  "(Electrons.pt > 15*GeV)",
28  "(abs(Electrons.eta) < 2.5)",
29  "(Electrons.DFCommonElectronsLHLoose)",
30  ]
31 )
32 photonRequirements = " && ".join(
33  ["(DFCommonPhotons_et >= 15*GeV)", "(abs(DFCommonPhotons_eta) < 2.5)"]
34 )
35 
36 decorateCells = True
37 
39  """Configure the EGAM10 skimming tool"""
40  acc = ComponentAccumulator()
41 
42  # off-line based selection
43  photonSelection = "(count(" + photonRequirements + ") >= 1)"
44  print("EGAM10 offline skimming expression: ", photonSelection)
45  EGAM10_OfflineSkimmingTool = CompFactory.DerivationFramework.xAODStringSkimmingTool(
46  name="EGAM10_OfflineSkimmingTool", expression=photonSelection
47  )
48 
49  # trigger-based selection
50  MenuType = None
51  if flags.Trigger.EDMVersion == 2:
52  MenuType = "Run2"
53  elif flags.Trigger.EDMVersion == 3:
54  MenuType = "Run3"
55  else:
56  MenuType = ""
57  allTriggers = (
58  singlePhotonTriggers[MenuType]
59  + diPhotonTriggers[MenuType]
60  + triPhotonTriggers[MenuType]
61  + noalgTriggers[MenuType]
62  )
63  # remove duplicates
64  allTriggers = list(set(allTriggers))
65 
66  print("EGAM10 trigger skimming list (OR): ", allTriggers)
67  EGAM10_TriggerSkimmingTool = CompFactory.DerivationFramework.TriggerSkimmingTool(
68  name="EGAM10_TriggerSkimmingTool", TriggerListOR=allTriggers
69  )
70 
71  # do the AND of trigger-based and offline-based selection
72  print("EGAM10 skimming is logical AND of previous selections")
73  EGAM10_SkimmingTool = CompFactory.DerivationFramework.FilterCombinationAND(
74  name="EGAM10_SkimmingTool",
75  FilterList=[EGAM10_OfflineSkimmingTool, EGAM10_TriggerSkimmingTool],
76  )
77 
78  acc.addPublicTool(EGAM10_OfflineSkimmingTool)
79  acc.addPublicTool(EGAM10_TriggerSkimmingTool)
80  acc.addPublicTool(EGAM10_SkimmingTool, primary=True)
81 
82  return acc
83 
84 
85 def EGAM10KernelCfg(flags, name="EGAM10Kernel", **kwargs):
86  """Configure the derivation framework driving algorithm (kernel)
87  for EGAM10"""
88  acc = ComponentAccumulator()
89 
90  # Common augmentations
91  from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg
92 
93  acc.merge(
95  flags, TriggerListsHelper=kwargs["TriggerListsHelper"]
96  )
97  )
98 
99  # EGAM10 augmentations
100  augmentationTools = []
101 
102  # ====================================================================
103  # PhotonVertexSelectionWrapper decoration tool - needs PhotonPointing tool
104  # ====================================================================
105  from DerivationFrameworkEGamma.EGammaToolsConfig import (
106  PhotonVertexSelectionWrapperKernelCfg)
107  acc.merge(PhotonVertexSelectionWrapperKernelCfg(flags))
108 
109  # ====================================================================
110  # Common calo decoration tools
111  # ====================================================================
112  from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
113  CaloDecoratorKernelCfg, CaloCellDecoratorKernelCfg)
114  acc.merge(CaloDecoratorKernelCfg(flags))
115  acc.merge(CaloCellDecoratorKernelCfg(flags))
116 
117  # thinning tools
118  thinningTools = []
119  streamName = kwargs["StreamName"]
120 
121  # Track thinning
122  if flags.Derivation.Egamma.doTrackThinning:
123  TrackThinningKeepElectronTracks = True
124  TrackThinningKeepPhotonTracks = True
125  TrackThinningKeepAllElectronTracks = True
126 
127  # Tracks associated with high-pT Electrons (deltaR=0.6)
128  if TrackThinningKeepElectronTracks:
129  EGAM10ElectronTPThinningTool = (
130  CompFactory.DerivationFramework.EgammaTrackParticleThinning(
131  name="EGAM10ElectronTPThinningTool",
132  StreamName=streamName,
133  SGKey="Electrons",
134  GSFTrackParticlesKey="GSFTrackParticles",
135  InDetTrackParticlesKey="InDetTrackParticles",
136  SelectionString=electronRequirements,
137  BestMatchOnly=True,
138  ConeSize=0.6,
139  )
140  )
141  acc.addPublicTool(EGAM10ElectronTPThinningTool)
142  thinningTools.append(EGAM10ElectronTPThinningTool)
143 
144  # Tracks associated with Photons
145  if TrackThinningKeepPhotonTracks:
146  EGAM10PhotonTPThinningTool = (
147  CompFactory.DerivationFramework.EgammaTrackParticleThinning(
148  name="EGAM10PhotonTPThinningTool",
149  StreamName=streamName,
150  SGKey="Photons",
151  GSFTrackParticlesKey="GSFTrackParticles",
152  InDetTrackParticlesKey="InDetTrackParticles",
153  GSFConversionVerticesKey="GSFConversionVertices",
154  SelectionString=photonRequirements,
155  BestMatchOnly=False,
156  ConeSize=0.6,
157  )
158  )
159  acc.addPublicTool(EGAM10PhotonTPThinningTool)
160  thinningTools.append(EGAM10PhotonTPThinningTool)
161 
162  # Tracks associated with all Electrons (for ambiguity resolver tool)
163  if TrackThinningKeepAllElectronTracks:
164  EGAM10ElectronTPThinningToolAR = (
165  CompFactory.DerivationFramework.EgammaTrackParticleThinning(
166  name="EGAM10ElectronTPThinningToolAR",
167  StreamName=streamName,
168  SGKey="Electrons",
169  GSFTrackParticlesKey="GSFTrackParticles",
170  InDetTrackParticlesKey="InDetTrackParticles",
171  SelectionString=electronRequirements,
172  BestMatchOnly=True,
173  )
174  )
175  acc.addPublicTool(EGAM10ElectronTPThinningToolAR)
176  thinningTools.append(EGAM10ElectronTPThinningToolAR)
177 
178  # skimming
179  skimmingTool = acc.getPrimaryAndMerge(EGAM10SkimmingToolCfg(flags))
180 
181  # setup the kernel
182  acc.addEventAlgo(
183  CompFactory.DerivationFramework.DerivationKernel(
184  name,
185  SkimmingTools=[skimmingTool],
186  AugmentationTools=augmentationTools,
187  ThinningTools=thinningTools,
188  )
189  )
190 
191  return acc
192 
193 
194 def EGAM10Cfg(flags):
195  acc = ComponentAccumulator()
196 
197  # Get the lists of triggers needed for trigger matching.
198  # This is needed at this scope (for the slimming) and further down
199  # in the config chain for actually configuring the matching, so we create
200  # it here and pass it down
201  # TODO: this should ideally be called higher up to avoid it being run
202  # multiple times in a train.
203  # TODO: restrict it to relevant triggers
204  from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper
205 
206  EGAM10TriggerListsHelper = TriggerListsHelper(flags)
207 
208  # configure skimming/thinning/augmentation tools
209  acc.merge(
211  flags,
212  name="EGAM10Kernel",
213  StreamName="StreamDAOD_EGAM10",
214  TriggerListsHelper=EGAM10TriggerListsHelper,
215  )
216  )
217 
218  # configure slimming
219  from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
220  from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg
221  from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper
222 
223  EGAM10SlimmingHelper = SlimmingHelper(
224  "EGAM10SlimmingHelper",
225  NamesAndTypes=flags.Input.TypedCollections,
226  flags=flags,
227  )
228 
229  # ------------------------------------------
230  # containers for which we save all variables
231  # -------------------------------------------
232 
233  # baseline
234  EGAM10SlimmingHelper.AllVariables = [
235  "CaloCalTopoClusters"
236  ]
237 
238  # and on MC we also add:
239  if flags.Input.isMC:
240  EGAM10SlimmingHelper.AppendToDictionary.update(
241  {
242  "TruthIsoCentralEventShape": "xAOD::EventShape",
243  "TruthIsoCentralEventShapeAux": "xAOD::EventShapeAuxInfo",
244  "TruthIsoForwardEventShape": "xAOD::EventShape",
245  "TruthIsoForwardEventShapeAux": "xAOD::EventShapeAuxInfo",
246  }
247  )
248  EGAM10SlimmingHelper.AllVariables += [
249  "TruthEvents",
250  "TruthParticles",
251  "TruthVertices",
252  "TruthMuons",
253  "TruthElectrons",
254  "TruthPhotons",
255  "TruthNeutrinos",
256  "TruthTaus",
257  "AntiKt4TruthJets",
258  "AntiKt4TruthDressedWZJets",
259  "egammaTruthParticles",
260  "TruthIsoCentralEventShape",
261  "TruthIsoForwardEventShape",
262  ]
263 
264  # -------------------------------------------
265  # containers that we slim
266  # -------------------------------------------
267 
268  # first add variables from smart-slimming
269  # adding only also those for which we add all variables since
270  # the XXXCPContent.py files also bring in some extra variables
271  # for other collections
272  # muons, tau, MET, b-tagging could be switched off if not needed
273  # and use too much space
274  EGAM10SlimmingHelper.SmartCollections = [
275  "Electrons",
276  "Photons",
277  "InDetTrackParticles",
278  "PrimaryVertices",
279  "AntiKt4EMPFlowJets",
280  ]
281 
282  if flags.Input.isMC:
283  EGAM10SlimmingHelper.SmartCollections += [
284  "AntiKt4TruthJets",
285  "AntiKt4TruthDressedWZJets",
286  ]
287 
288  # then add extra variables:
289 
290  # egamma clusters
291  EGAM10SlimmingHelper.ExtraVariables += [
292  "egammaClusters.PHI2CALOFRAME.ETA2CALOFRAME.phi_sampl",
293  ]
294 
295  # photons
296  EGAM10SlimmingHelper.ExtraVariables += [
297  "Photons.ptcone30.ptcone40.f3.f3core",
298  "Photons.maxEcell_time.maxEcell_energy.maxEcell_gain.maxEcell_onlId",
299  "Photons.maxEcell_x.maxEcell_y.maxEcell_z",
300  "Photons.ptcone40_Nonprompt_All_MaxWeightTTVA_pt1000",
301  "Photons.ptcone40_Nonprompt_All_MaxWeightTTVA_pt500",
302  "Photons.ptcone20_Nonprompt_All_MaxWeightTTVA_pt500",
303  "Photons.ptvarcone30_Nonprompt_All_MaxWeightTTVA_pt1000",
304  "Photons.ptvarcone30_Nonprompt_All_MaxWeightTTVA_pt500",
305  ]
306 
307  # electrons
308  EGAM10SlimmingHelper.ExtraVariables += [
309  "Electrons.topoetcone30.topoetcone40.ptcone20.ptcone30",
310  "Electrons.ptcone40.maxEcell_time.maxEcell_energy.maxEcell_gain",
311  "Electrons.maxEcell_onlId.maxEcell_x.maxEcell_y.maxEcell_z",
312  ]
313 
314  # primary vertices
315  EGAM10SlimmingHelper.ExtraVariables += [
316  "PrimaryVertices.covariance.trackWeights.sumPt2.sumPt",
317  "PrimaryVertices.pt.eta.phi",
318  ]
319 
320  # tracks
321  EGAM10SlimmingHelper.ExtraVariables += [
322  "InDetTrackParticles.TTVA_AMVFVertices.TTVA_AMVFWeights"
323  ]
324 
325  # photons and electrons: detailed shower shape variables and track variables
326  EGAM10SlimmingHelper.ExtraVariables += PhotonsCPDetailedContent
327 
328  # photons: gain and cluster energy per layer
329  from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
330  getGainDecorations,
331  getClusterEnergyPerLayerDecorations,
332  )
333 
334  gainDecorations = getGainDecorations(acc, flags, "EGAM10Kernel")
335  print("EGAM10 gain decorations: ", gainDecorations)
336  EGAM10SlimmingHelper.ExtraVariables.extend(gainDecorations)
337  clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM10Kernel")
338  print("EGAM10 cluster energy decorations: ", clusterEnergyDecorations)
339  EGAM10SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations)
340 
341  # photons: cell decorations
342  if decorateCells:
343  EGAM10SlimmingHelper.ExtraVariables += [
344  "Photons.cells_E.cells_time.cells_onlId",
345  "Photons.cells_eta.cells_phi.cells_layer",
346  "Photons.cells_x.cells_y.cells_z",
347  "Photons.cells_gain",
348  "Photons.cells_quality",
349  "Photons.ncells",
350  ]
351 
352  # energy density
353  EGAM10SlimmingHelper.ExtraVariables += [
354  "TopoClusterIsoCentralEventShape.Density",
355  "TopoClusterIsoForwardEventShape.Density",
356  ]
357 
358  from DerivationFrameworkEGamma import EGammaIsoConfig
359 
360  (
361  pflowIsoVar,
362  densityList,
363  densityDict,
364  acc1,
365  ) = EGammaIsoConfig.makeEGammaCommonIsoCfg(flags)
366  acc.merge(acc1)
367  EGAM10SlimmingHelper.AppendToDictionary.update(densityDict)
368  EGAM10SlimmingHelper.ExtraVariables += densityList + [f"Photons{pflowIsoVar}"]
369 
370  # To have ptcone40, needed for efficiency measurement with MM
371  from IsolationAlgs.DerivationTrackIsoConfig import DerivationTrackIsoCfg
372 
373  acc.merge(
375  flags, object_types=("Photons",), ptCuts=(500, 1000), postfix="Extra"
376  )
377  )
378 
379  # truth
380  if flags.Input.isMC:
381  EGAM10SlimmingHelper.ExtraVariables += [
382  "Electrons.truthOrigin.truthType.truthParticleLink.truthPdgId",
383  "Electrons.lastEgMotherTruthType.lastEgMotherTruthOrigin",
384  "Electrons.lastEgMotherTruthParticleLink.lastEgMotherPdgId",
385  "Electrons.firstEgMotherTruthType.firstEgMotherTruthOrigin",
386  "Electrons.firstEgMotherTruthParticleLink.firstEgMotherPdgId",
387  ]
388 
389  EGAM10SlimmingHelper.ExtraVariables += [
390  "Photons.truthOrigin.truthType.truthParticleLink"
391  ]
392 
393  EGAM10SlimmingHelper.ExtraVariables += [
394  "TruthIsoCentralEventShape.DensitySigma.Density.DensityArea",
395  "TruthIsoForwardEventShape.DensitySigma.Density.DensityArea",
396  ]
397 
398  # Add event info
399  if flags.Derivation.Egamma.doEventInfoSlimming:
400  EGAM10SlimmingHelper.SmartCollections.append("EventInfo")
401  else:
402  EGAM10SlimmingHelper.AllVariables += ["EventInfo"]
403 
404  # Add egamma trigger objects
405  EGAM10SlimmingHelper.IncludeEGammaTriggerContent = True
406 
407  # Trigger matching
408  # Run 2
409  if flags.Trigger.EDMVersion == 2:
410  from DerivationFrameworkPhys.TriggerMatchingCommonConfig import AddRun2TriggerMatchingToSlimmingHelper
411  AddRun2TriggerMatchingToSlimmingHelper(SlimmingHelper = EGAM10SlimmingHelper,
412  OutputContainerPrefix = "TrigMatch_",
413  TriggerList = EGAM10TriggerListsHelper.Run2TriggerNamesNoTau)
414  # Run 3, or Run 2 with navigation conversion
415  if flags.Trigger.EDMVersion == 3 or (flags.Trigger.EDMVersion == 2 and flags.Trigger.doEDMVersionConversion):
416  from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import AddRun3TrigNavSlimmingCollectionsToSlimmingHelper
418 
419  EGAM10ItemList = EGAM10SlimmingHelper.GetItemList()
420  acc.merge(
422  flags,
423  "DAOD_EGAM10",
424  ItemList=EGAM10ItemList,
425  AcceptAlgs=["EGAM10Kernel"],
426  )
427  )
428  acc.merge(
430  flags,
431  "DAOD_EGAM10",
432  AcceptAlgs=["EGAM10Kernel"],
433  createMetadata=[
434  MetadataCategory.CutFlowMetaData,
435  MetadataCategory.TruthMetaData,
436  ],
437  )
438  )
439 
440  return acc
python.EGAM10.EGAM10KernelCfg
def EGAM10KernelCfg(flags, name="EGAM10Kernel", **kwargs)
Definition: EGAM10.py:85
TrigNavSlimmingMTConfig.AddRun3TrigNavSlimmingCollectionsToSlimmingHelper
def AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(slimmingHelper)
Definition: TrigNavSlimmingMTConfig.py:98
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, keepProvenanceTagsRegEx=None, AcceptAlgs=[], HelperTools=[])
Definition: OutputStreamConfig.py:16
python.TriggerMatchingCommonConfig.AddRun2TriggerMatchingToSlimmingHelper
def AddRun2TriggerMatchingToSlimmingHelper(**kwargs)
Definition: TriggerMatchingCommonConfig.py:49
DerivationFrameworkCaloConfig.CaloCellDecoratorKernelCfg
def CaloCellDecoratorKernelCfg(flags, name="CaloCellDecoratorKernel", **kwargs)
Definition: DerivationFrameworkCaloConfig.py:79
python.EGAM10.EGAM10Cfg
def EGAM10Cfg(flags)
Definition: EGAM10.py:194
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
python.EGAM10.EGAM10SkimmingToolCfg
def EGAM10SkimmingToolCfg(flags)
Definition: EGAM10.py:38
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
DerivationFrameworkCaloConfig.CaloDecoratorKernelCfg
def CaloDecoratorKernelCfg(flags, name="CaloDecoratorKernel", **kwargs)
Definition: DerivationFrameworkCaloConfig.py:105
DerivationFrameworkCaloConfig.getClusterEnergyPerLayerDecorations
def getClusterEnergyPerLayerDecorations(acc, kernel)
Definition: DerivationFrameworkCaloConfig.py:184
DerivationFrameworkCaloConfig.getGainDecorations
def getGainDecorations(acc, flags, kernel, collections=None, info=["E", "nCells"])
Definition: DerivationFrameworkCaloConfig.py:155
python.PhysCommonConfig.PhysCommonAugmentationsCfg
def PhysCommonAugmentationsCfg(flags, **kwargs)
Definition: PhysCommonConfig.py:13
DerivationTrackIsoConfig.DerivationTrackIsoCfg
def DerivationTrackIsoCfg(flags, **jwarg)
Definition: DerivationTrackIsoConfig.py:10
InfileMetaDataConfig.SetupMetaDataForStreamCfg
def SetupMetaDataForStreamCfg(flags, streamName="", AcceptAlgs=None, createMetadata=None, propagateMetadataFromInput=True, *args, **kwargs)
Definition: InfileMetaDataConfig.py:222
SlimmingHelper
Definition: SlimmingHelper.py:1
python.EGammaToolsConfig.PhotonVertexSelectionWrapperKernelCfg
def PhotonVertexSelectionWrapperKernelCfg(flags, name="PhotonVertexSelectionWrapperKernel", **kwargs)
Definition: EGammaToolsConfig.py:95