7 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
8 from AthenaConfiguration.ComponentFactory
import CompFactory
9 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthDecayCollectionMakerCfg
13 theTruthMetaDataWriter = CompFactory.DerivationFramework.TruthMetaDataWriter(name)
14 acc.addPublicTool(theTruthMetaDataWriter)
15 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
16 acc.addEventAlgo(CommonAugmentation(f
"{name}Kernel", AugmentationTools = [theTruthMetaDataWriter]))
20 """Conversion of HepMC to xAOD truth"""
24 if flags.Input.isMC
is False:
25 raise RuntimeError(
"Common MC truth building requested for non-MC input")
32 if "EventInfo#McEventInfo" in flags.Input.TypedCollections
and "xAOD::EventInfo#EventInfo" not in flags.Input.TypedCollections:
33 from xAODEventInfoCnv.xAODEventInfoCnvConfig
import EventInfoCnvAlgCfg
34 acc.merge(
EventInfoCnvAlgCfg(flags, inputKey=
"McEventInfo", outputKey=
"EventInfo", disableBeamSpot=
True))
38 from xAODTruthCnv.xAODTruthCnvConfig
import GEN_EVNT2xAODCfg
39 if "McEventCollection#GEN_EVENT" in flags.Input.TypedCollections:
40 acc.merge(
GEN_EVNT2xAODCfg(flags,name=
"GEN_EVNT2xAOD",AODContainerName=
"GEN_EVENT"))
43 elif "McEventCollection#TruthEvent" in flags.Input.TypedCollections:
44 acc.merge(
GEN_EVNT2xAODCfg(flags,name=
"GEN_EVNT2xAOD",AODContainerName=
"TruthEvent"))
48 elif "xAOD::TruthEventContainer#TruthEvents" in flags.Input.TypedCollections:
51 raise RuntimeError(
"No recognised HepMC truth information found in the input")
54 if "TruthMetaDataContainer#TruthMetaData" not in flags.Input.TypedCollections
and not isEVNT:
66 from JetRecConfig.StandardSmallRJets
import AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged
67 from JetRecConfig.StandardLargeRJets
import AntiKt10TruthSoftDrop
68 from JetRecConfig.JetRecConfig
import JetRecCfg
70 inputCollections =
set(flags.Input.Collections)
71 jetList = [AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged,
72 AntiKt10TruthSoftDrop]
76 expectedName = jd.fullname().
encode(
"utf-8")
77 if expectedName
in inputCollections:
89 if (
"MissingETContainer#MET_Truth")
not in flags.Input.TypedCollections:
90 from METReconstruction.METTruth_Cfg
import METTruth_Cfg
99 augmentationToolsList = []
104 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import ( DFCommonTruthElectronDressingToolCfg,
105 DFCommonTruthMuonDressingToolCfg, DFCommonTruthClassificationToolCfg, DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
106 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
107 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthForwardProtonToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
108 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
109 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg )
112 for item
in [ DFCommonTruthClassificationToolCfg, DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
113 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
114 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
115 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
116 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg]:
117 augmentationToolsList.append(acc.getPrimaryAndMerge(
item(flags)))
120 if 'decorationDressing' in kwargs:
124 for i, tool
in enumerate(augmentationToolsList):
125 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(name =
"MCTruthCommonPreJetKernelNo{num}".
format(num = i+1), AugmentationTools = [tool]))
137 from DerivationFrameworkTau.TauTruthCommonConfig
import TauTruthToolsCfg
139 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthTauDressingToolCfg
143 from DerivationFrameworkMCTruth.GenFilterToolConfig
import GenFilterToolCfg
145 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthDressedWZQGLabelToolCfg
146 augmentationToolsList += [ acc.getPrimaryAndMerge(
GenFilterToolCfg(flags)) ,
150 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import IsSUSYSignalRun3
152 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import SUSYSignalTaggerCfg
153 augmentationToolsList += [ acc.getPrimaryAndMerge(
SUSYSignalTaggerCfg(flags,
'MCTruthCommon')) ]
155 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
156 for i, tool
in enumerate(augmentationToolsList):
157 acc.addEventAlgo(CommonAugmentation(name =
"MCTruthCommonPostJetKernelNo{num}".
format(num = i+1),
158 AugmentationTools = [tool]))
162 from DerivationFrameworkSUSY.SUSYWeightMetadataConfig
import AddSUSYWeightsCfg
169 decorationDressing='dressedPhoton',
170 includeTausInDressingPhotonRemoval=False,
180 if "McEventCollection#GEN_EVENT" in flags.Input.TypedCollections: isEVNT =
True
189 if includeTausInDressingPhotonRemoval:
190 acc.getPublicTool(
"DFCommonTruthTauDressingTool").decorationName=decorationDressing+
"_tau"
193 acc.merge(
AddTruthCollectionNavigationDecorationsCfg(flags, [
"TruthElectrons",
"TruthMuons",
"TruthPhotons",
"TruthTaus",
"TruthNeutrinos",
"TruthBSM",
"TruthBottom",
"TruthTop",
"TruthBoson"], prefix=prefix))
210 collection_prefix=None,
211 rejectHadronChildren=False):
212 """Configure tools for adding immediate parents and descendants"""
214 collection_name=collection_prefix+
'WithDecay' if collection_prefix
is not None else 'Truth'+prefix+
'WithDecay'
217 name =
'DFCommon'+prefix+
'AndDecaysTool',
218 NewCollectionName = collection_name,
219 PDGIDsToKeep = parents,
220 Generations = generations,
221 RejectHadronChildren = rejectHadronChildren))
222 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
223 kernel_name =
'MCTruthCommon'+prefix+
'AndDecaysKernel'
224 acc.addEventAlgo(CommonAugmentation(kernel_name, AugmentationTools = [collection_maker] ))
247 rejectHadronChildren=False):
248 """Add bosons and downstream particles (not photons/gluons)"""
250 generations = generations,
251 parents = [23,24,25],
253 rejectHadronChildren = rejectHadronChildren)
258 rejectHadronChildren=False):
259 """Add top quarks and downstream particles"""
261 generations=generations,
264 rejectHadronChildren=rejectHadronChildren)
268 rejectHadronChildren=False):
269 """Add tau and downstream particles"""
271 generations=generations,
274 rejectHadronChildren=rejectHadronChildren)
296 """Add b/c-hadrons and their downstream particles"""
297 kwargs.setdefault(
"addB",
True)
298 kwargs.setdefault(
"addC",
True)
299 kwargs.setdefault(
"generations",-1)
300 kwargs.setdefault(
"prefix",
'')
303 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthDecayCollectionMakerCfg
306 name=kwargs[
'prefix']+
"DFCommonHFAndDecaysTool",
307 NewCollectionName=kwargs[
'prefix']+
"TruthHFWithDecay",
308 KeepBHadrons=kwargs[
'addB'],
309 KeepCHadrons=kwargs[
'addC'],
310 Generations=kwargs[
'generations']))
311 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
312 kwargs[
'prefix']+
"MCTruthCommonHFAndDecaysKernel",
313 AugmentationTools = [DFCommonHFAndDecaysTool] ))
319 """Add a one-vertex-per event "primary vertex" container"""
322 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthPVCollectionMakerCfg
325 name=
"DFCommonTruthPVCollTool",
326 NewCollectionName=
"TruthPrimaryVertices"))
327 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
328 "MCTruthCommonTruthPVCollKernel",
329 AugmentationTools = [DFCommonTruthPVCollTool] ))
335 """Tool to add navigation decorations on the truth collections"""
337 if len(TruthCollections)==0:
return
339 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthNavigationDecoratorCfg
341 name = prefix+
'DFCommonTruthNavigationDecorator',
342 InputCollections = TruthCollections))
343 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
344 acc.addEventAlgo(CommonAugmentation(prefix+
"MCTruthNavigationDecoratorKernel",
345 AugmentationTools = [DFCommonTruthNavigationDecorator] ))
350 """Add BSM particles and their downstream particles in a special collection"""
355 name =
"DFCommonBSMAndDecaysTool",
356 NewCollectionName =
"TruthBSMWithDecay",
358 Generations = generations))
359 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
360 acc.addEventAlgo(CommonAugmentation(name =
"MCTruthCommonBSMAndDecaysKernel",
361 AugmentationTools = [DFCommonBSMAndDecaysTool] ))
366 """Add born leptons as a mini collection"""
369 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthBornLeptonCollectionMakerCfg
371 name =
"DFCommonBornLeptonCollTool",
372 NewCollectionName =
"BornLeptons"))
373 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
374 acc.addEventAlgo(CommonAugmentation(
"MCTruthCommonBornLeptonsKernel", AugmentationTools = [DFCommonBornLeptonCollTool] ))
378 """Add large-R jet D2 variable"""
381 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthD2DecoratorCfg
383 name =
"TruthD2Decorator",
384 JetContainerKey =
"AntiKt10TruthSoftDropBeta100Zcut10Jets",
385 DecorationName =
"D2"))
386 TruthD2DecoratorKernel = CompFactory.DerivationFramework.CommonAugmentation
387 acc.addEventAlgo(TruthD2DecoratorKernel(
"TRUTHD2Kernel", AugmentationTools = [theTruthD2Decorator] ))
392 """Truth energy density tools"""
394 from EventShapeTools.EventDensityConfig
import configEventDensityTool
395 from JetRecConfig.StandardJetConstits
import stdConstitDic
as cst
396 EventDensityAthAlg = CompFactory.EventDensityAthAlg
401 AbsRapidityMax = 1.5,
402 OutputContainer =
"TruthIsoCentralEventShape",
404 acc.addPublicTool(DFCommonTruthCentralEDTool)
405 acc.addEventAlgo(
EventDensityAthAlg(
"DFCommonTruthCentralEDAlg", EventDensityTool = DFCommonTruthCentralEDTool ))
409 AbsRapidityMin = 1.5,
410 AbsRapidityMax = 3.0,
411 OutputContainer =
"TruthIsoForwardEventShape",
413 acc.addPublicTool(DFCommonTruthForwardEDTool)
414 acc.addEventAlgo(
EventDensityAthAlg(
"DFCommonTruthForwardEDAlg", EventDensityTool = DFCommonTruthForwardEDTool ))
417 DFCommonTruthEDDecorator = CompFactory.DerivationFramework.TruthEDDecorator(
"DFCommonTruthEDDecorator",
418 EventInfoName=
"EventInfo",
419 EventShapeKeys=[
"TruthIsoCentralEventShape",
"TruthIsoForwardEventShape"],
420 DecorationSuffix=
"_rho"
422 acc.addPublicTool(DFCommonTruthEDDecorator)
424 DFCommonTruthEDKernel = CompFactory.DerivationFramework.CommonAugmentation
425 acc.addEventAlgo(DFCommonTruthEDKernel(
"DFCommonTruthEDKernel", AugmentationTools = [DFCommonTruthEDDecorator] ))
431 """Tool to move pointers to new mini truth collections"""
433 kwargs.setdefault(
"doElectrons",
True)
434 kwargs.setdefault(
"doPhotons",
True)
435 kwargs.setdefault(
"doMuons",
True)
437 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthLinkRepointToolCfg
438 if kwargs[
'doElectrons']:
441 name=
"ElMiniCollectionTruthLinkTool",
442 RecoCollection=
"Electrons",
443 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
444 aug_tools += [ electron_relink ]
445 if kwargs[
'doPhotons']:
448 name=
"PhMiniCollectionTruthLinkTool",
449 RecoCollection=
"Photons",
450 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
451 aug_tools += [ photon_relink ]
452 if kwargs[
'doMuons']:
455 name=
"MuMiniCollectionTruthLinkTool",
456 RecoCollection=
"Muons",
457 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
458 aug_tools += [ muon_relink ]
459 for i, tool
in enumerate(aug_tools):
460 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
461 "MiniCollectionTruthLinkKernelNo{num}".
format(num=i+1),
462 AugmentationTools = [tool] ))
466 slimmer.AllVariables += [
477 "TruthForwardProtons",
479 "TruthBosonsWithDecayParticles",
480 "TruthBosonsWithDecayVertices",
481 "TruthBSMWithDecayParticles",
482 "TruthBSMWithDecayVertices",
484 slimmer.ExtraVariables += [
485 "AntiKt4TruthDressedWZJets.GhostCHadronsFinalCount.GhostBHadronsFinalCount.pt.HadronConeExclTruthLabelID.PartonTruthLabelID.TrueFlavor",
486 "AntiKt10TruthSoftDropBeta100Zcut10Jets.pt.Tau1_wta.Tau2_wta.Tau3_wta.D2",
487 "TruthEvents.Q.XF1.XF2.PDGID1.PDGID2.PDFID1.PDFID2.X1.X2.crossSection"]