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:
65 from JetRecConfig.StandardSmallRJets
import AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged
66 from JetRecConfig.StandardLargeRJets
import AntiKt10TruthTrimmed,AntiKt10TruthSoftDrop
67 from JetRecConfig.JetRecConfig
import JetRecCfg
70 jetList = [AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged,
71 AntiKt10TruthTrimmed,AntiKt10TruthSoftDrop]
85 if (
"MissingETContainer#MET_Truth")
not in flags.Input.TypedCollections:
86 from METReconstruction.METTruth_Cfg
import METTruth_Cfg
95 augmentationToolsList = []
100 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import ( DFCommonTruthElectronDressingToolCfg,
101 DFCommonTruthMuonDressingToolCfg, DFCommonTruthClassificationToolCfg, DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
102 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
103 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthForwardProtonToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
104 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
105 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg )
108 for item
in [ DFCommonTruthClassificationToolCfg, DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
109 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
110 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
111 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
112 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg]:
113 augmentationToolsList.append(acc.getPrimaryAndMerge(
item(flags)))
116 if 'decorationDressing' in kwargs:
120 for i, tool
in enumerate(augmentationToolsList):
121 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(name =
"MCTruthCommonPreJetKernelNo{num}".
format(num = i+1), AugmentationTools = [tool]))
133 from DerivationFrameworkTau.TauTruthCommonConfig
import TauTruthToolsCfg
135 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthTauDressingToolCfg
139 from DerivationFrameworkMCTruth.GenFilterToolConfig
import GenFilterToolCfg
141 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthDressedWZQGLabelToolCfg
142 augmentationToolsList += [ acc.getPrimaryAndMerge(
GenFilterToolCfg(flags)) ,
146 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import IsSUSYSignalRun3
148 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import SUSYSignalTaggerCfg
149 augmentationToolsList += [ acc.getPrimaryAndMerge(
SUSYSignalTaggerCfg(flags,
'MCTruthCommon')) ]
151 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
152 for i, tool
in enumerate(augmentationToolsList):
153 acc.addEventAlgo(CommonAugmentation(name =
"MCTruthCommonPostJetKernelNo{num}".
format(num = i+1),
154 AugmentationTools = [tool]))
158 from DerivationFrameworkSUSY.SUSYWeightMetadataConfig
import AddSUSYWeightsCfg
165 decorationDressing='dressedPhoton',
166 includeTausInDressingPhotonRemoval=False,
176 if "McEventCollection#GEN_EVENT" in flags.Input.TypedCollections: isEVNT =
True
185 if includeTausInDressingPhotonRemoval:
186 acc.getPublicTool(
"DFCommonTruthTauDressingTool").decorationName=decorationDressing
187 acc.addEventAlgo(CompFactory.DerivationFramework.LockDecorations(name =
"AddStandardTruthContentsLockDecoration", Decorations = [
'TruthParticles.' + decorationDressing]))
190 acc.merge(
AddTruthCollectionNavigationDecorationsCfg(flags, [
"TruthElectrons",
"TruthMuons",
"TruthPhotons",
"TruthTaus",
"TruthNeutrinos",
"TruthBSM",
"TruthBottom",
"TruthTop",
"TruthBoson"], prefix=prefix))
207 collection_prefix=None,
208 rejectHadronChildren=False):
209 """Configure tools for adding immediate parents and descendants"""
211 collection_name=collection_prefix+
'WithDecay' if collection_prefix
is not None else 'Truth'+prefix+
'WithDecay'
214 name =
'DFCommon'+prefix+
'AndDecaysTool',
215 NewCollectionName = collection_name,
216 PDGIDsToKeep = parents,
217 Generations = generations,
218 RejectHadronChildren = rejectHadronChildren))
219 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
220 kernel_name =
'MCTruthCommon'+prefix+
'AndDecaysKernel'
221 acc.addEventAlgo(CommonAugmentation(kernel_name, AugmentationTools = [collection_maker] ))
244 rejectHadronChildren=False):
245 """Add bosons and downstream particles (not photons/gluons)"""
247 generations = generations,
248 parents = [23,24,25],
250 rejectHadronChildren = rejectHadronChildren)
255 rejectHadronChildren=False):
256 """Add top quarks and downstream particles"""
258 generations=generations,
261 rejectHadronChildren=rejectHadronChildren)
265 rejectHadronChildren=False):
266 """Add tau and downstream particles"""
268 generations=generations,
271 rejectHadronChildren=rejectHadronChildren)
293 """Add b/c-hadrons and their downstream particles"""
294 kwargs.setdefault(
"addB",
True)
295 kwargs.setdefault(
"addC",
True)
296 kwargs.setdefault(
"generations",-1)
297 kwargs.setdefault(
"prefix",
'')
300 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthDecayCollectionMakerCfg
303 name=kwargs[
'prefix']+
"DFCommonHFAndDecaysTool",
304 NewCollectionName=kwargs[
'prefix']+
"TruthHFWithDecay",
305 KeepBHadrons=kwargs[
'addB'],
306 KeepCHadrons=kwargs[
'addC'],
307 Generations=kwargs[
'generations']))
308 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
309 kwargs[
'prefix']+
"MCTruthCommonHFAndDecaysKernel",
310 AugmentationTools = [DFCommonHFAndDecaysTool] ))
316 """Add a one-vertex-per event "primary vertex" container"""
319 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthPVCollectionMakerCfg
322 name=
"DFCommonTruthPVCollTool",
323 NewCollectionName=
"TruthPrimaryVertices"))
324 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
325 "MCTruthCommonTruthPVCollKernel",
326 AugmentationTools = [DFCommonTruthPVCollTool] ))
332 """Tool to add navigation decorations on the truth collections"""
334 if len(TruthCollections)==0:
return
336 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthNavigationDecoratorCfg
338 name = prefix+
'DFCommonTruthNavigationDecorator',
339 InputCollections = TruthCollections))
340 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
341 acc.addEventAlgo(CommonAugmentation(prefix+
"MCTruthNavigationDecoratorKernel",
342 AugmentationTools = [DFCommonTruthNavigationDecorator] ))
347 """Add BSM particles and their downstream particles in a special collection"""
352 name =
"DFCommonBSMAndDecaysTool",
353 NewCollectionName =
"TruthBSMWithDecay",
355 Generations = generations))
356 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
357 acc.addEventAlgo(CommonAugmentation(name =
"MCTruthCommonBSMAndDecaysKernel",
358 AugmentationTools = [DFCommonBSMAndDecaysTool] ))
363 """Add born leptons as a mini collection"""
366 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthBornLeptonCollectionMakerCfg
368 name =
"DFCommonBornLeptonCollTool",
369 NewCollectionName =
"BornLeptons"))
370 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
371 acc.addEventAlgo(CommonAugmentation(
"MCTruthCommonBornLeptonsKernel", AugmentationTools = [DFCommonBornLeptonCollTool] ))
375 """Add large-R jet D2 variable"""
378 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthD2DecoratorCfg
380 name =
"TruthD2Decorator",
381 JetContainerKey =
"AntiKt10TruthSoftDropBeta100Zcut10Jets",
382 DecorationName =
"D2"))
383 TruthD2DecoratorKernel = CompFactory.DerivationFramework.CommonAugmentation
384 acc.addEventAlgo(TruthD2DecoratorKernel(
"TRUTHD2Kernel", AugmentationTools = [theTruthD2Decorator] ))
389 """Truth energy density tools"""
391 from EventShapeTools.EventDensityConfig
import configEventDensityTool
392 from JetRecConfig.StandardJetConstits
import stdConstitDic
as cst
393 EventDensityAthAlg = CompFactory.EventDensityAthAlg
398 AbsRapidityMax = 1.5,
399 OutputContainer =
"TruthIsoCentralEventShape",
401 acc.addPublicTool(DFCommonTruthCentralEDTool)
402 acc.addEventAlgo(
EventDensityAthAlg(
"DFCommonTruthCentralEDAlg", EventDensityTool = DFCommonTruthCentralEDTool ))
406 AbsRapidityMin = 1.5,
407 AbsRapidityMax = 3.0,
408 OutputContainer =
"TruthIsoForwardEventShape",
410 acc.addPublicTool(DFCommonTruthForwardEDTool)
411 acc.addEventAlgo(
EventDensityAthAlg(
"DFCommonTruthForwardEDAlg", EventDensityTool = DFCommonTruthForwardEDTool ))
414 DFCommonTruthEDDecorator = CompFactory.DerivationFramework.TruthEDDecorator(
"DFCommonTruthEDDecorator",
415 EventInfoName=
"EventInfo",
416 EnergyDensityKeys=[
"TruthIsoCentralEventShape",
"TruthIsoForwardEventShape"],
417 DecorationSuffix=
"_rho"
419 acc.addPublicTool(DFCommonTruthEDDecorator)
421 DFCommonTruthEDKernel = CompFactory.DerivationFramework.CommonAugmentation
422 acc.addEventAlgo(DFCommonTruthEDKernel(
"DFCommonTruthEDKernel", AugmentationTools = [DFCommonTruthEDDecorator] ))
428 """Tool to move pointers to new mini truth collections"""
430 kwargs.setdefault(
"doElectrons",
True)
431 kwargs.setdefault(
"doPhotons",
True)
432 kwargs.setdefault(
"doMuons",
True)
434 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthLinkRepointToolCfg
435 if kwargs[
'doElectrons']:
438 name=
"ElMiniCollectionTruthLinkTool",
439 RecoCollection=
"Electrons",
440 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
441 aug_tools += [ electron_relink ]
442 if kwargs[
'doPhotons']:
445 name=
"PhMiniCollectionTruthLinkTool",
446 RecoCollection=
"Photons",
447 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
448 aug_tools += [ photon_relink ]
449 if kwargs[
'doMuons']:
452 name=
"MuMiniCollectionTruthLinkTool",
453 RecoCollection=
"Muons",
454 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
455 aug_tools += [ muon_relink ]
456 for i, tool
in enumerate(aug_tools):
457 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
458 "MiniCollectionTruthLinkKernelNo{num}".
format(num=i+1),
459 AugmentationTools = [tool] ))
463 slimmer.AllVariables += [
474 "TruthForwardProtons",
476 "TruthBosonsWithDecayParticles",
477 "TruthBosonsWithDecayVertices",
478 "TruthBSMWithDecayParticles",
479 "TruthBSMWithDecayVertices",
481 slimmer.ExtraVariables += [
482 "AntiKt4TruthDressedWZJets.GhostCHadronsFinalCount.GhostBHadronsFinalCount.pt.HadronConeExclTruthLabelID.PartonTruthLabelID.TrueFlavor",
483 "AntiKt10TruthSoftDropBeta100Zcut10Jets.pt.Tau1_wta.Tau2_wta.Tau3_wta.D2",
484 "TruthEvents.Q.XF1.XF2.PDGID1.PDGID2.PDFID1.PDFID2.X1.X2.crossSection"]