ATLAS Offline Software
TrkVertexFitter/TrkVertexWeightCalculators/python/TrkVertexWeightCalculatorsConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 
6 
7 def DecorateVertexScoreAlgCfg(flags, name="DecorateVertexScoreAlg", **kwargs):
8  """
9  This algorithm decorates all the vertices with the score computed by a tool.
10  """
11  acc = ComponentAccumulator()
12  if not kwargs.get("VertexWeightCalculator", None):
13  from TrkConfig.TrkVertexWeightCalculatorsConfig import BDTVertexWeightCalculatorSeqCfg
14  toolBDTAcc = BDTVertexWeightCalculatorSeqCfg(flags)
15  tool = toolBDTAcc.popPrivateTools()
16  acc.merge(toolBDTAcc)
17  kwargs["VertexWeightCalculator"] = tool
18 
19  kwargs.setdefault("VertexScoreDecor", "score")
20  alg = CompFactory.DecorateVertexScoreAlg(name, **kwargs)
21  acc.addEventAlgo(alg)
22  return acc
23 
24 
25 def TrkVertexWeightCalculatorDebugCfg(flags, **kwargs):
26  """
27  This is a test configuration for the TrkVertexWeightCalculator. It is not meant to be run in production.
28  It produces a ROOT file with a tree containing relevant information to check the performance of the tool.
29  """
30  from AthenaCommon.Constants import DEBUG
31  from AthenaCommon.Logging import logging
32 
33  mlog = logging.getLogger("TrkVertexWeightCalculatorBDTDebugCfg")
34  mlog.warning(
35  "This is a test algorithm, it is not meant to be run in production."
36  )
37 
38  acc = ComponentAccumulator()
39  acc.merge(DecorateVertexScoreAlgCfg(flags, **kwargs))
40  mlog.info(
41  "Setting the output level of BuildVertexPointingAlg, DecorateVertexScoreAlg, DecorateVertexScoreAlg/VertexSelectionTool to DEBUG"
42  )
43  acc.getEventAlgo("BuildVertexPointingAlg").OutputLevel = DEBUG
44  acc.getEventAlgo("DecorateVertexScoreAlg").OutputLevel = DEBUG
45  acc.getEventAlgo(
46  "DecorateVertexScoreAlg"
47  ).VertexWeightCalculator.OutputLevel = DEBUG
48 
49  from TrkConfig.TrkVertexWeightCalculatorsConfig import (
50  SumPt2VertexWeightCalculatorCfg,
51  )
52 
53  tool_pt2 = acc.popToolsAndMerge(SumPt2VertexWeightCalculatorCfg(flags))
54  acc.merge(
56  flags,
57  "DecorateVertexScoreAlgSumPt2",
58  VertexWeightCalculator=tool_pt2,
59  VertexScoreDecor="score_sumpt2",
60  )
61  )
62  acc.getEventAlgo("DecorateVertexScoreAlgSumPt2").OutputLevel = DEBUG
63 
64  tool = CompFactory.Trk.TrueVertexDistanceWeightCalculator()
65  acc.merge(
67  flags,
68  "DecorateVertexScoreAlgTrueVertexDistance",
69  VertexWeightCalculator=tool,
70  VertexScoreDecor="score_true_vertex_distance",
71  )
72  )
73  acc.getEventAlgo("DecorateVertexScoreAlgTrueVertexDistance").OutputLevel = DEBUG
74 
75  sysService = CompFactory.CP.SystematicsSvc("SystematicsSvc", sigmaRecommended=0)
76  acc.addService(sysService)
77 
78  histoSvc = CompFactory.THistSvc(
79  Output=[
80  f"ANALYSIS DATAFILE='{flags.Output.HISTFileName}' TYPE='ROOT' OPT='RECREATE'"
81  ]
82  )
83  acc.addService(histoSvc)
84  acc.setAppProperty("HistogramPersistency", "ROOT")
85 
86  acc.addEventAlgo(
87  CompFactory.CP.TreeMakerAlg("TreeMaker", TreeName=flags.Output.TreeName)
88  )
89  branches = [
90  "EventInfo.runNumber -> runNumber",
91  "EventInfo.eventNumber -> eventNumber",
92  "EventInfo.actualInteractionsPerCrossing -> actualInteractionsPerCrossing",
93  "EventInfo.averageInteractionsPerCrossing -> averageInteractionsPerCrossing",
94  "PrimaryVertices.x -> vtx_x",
95  "PrimaryVertices.y -> vtx_y",
96  "PrimaryVertices.z -> vtx_z",
97  "PrimaryVertices.score -> vtx_score",
98  "PhotonPointingVertices.z -> z_common",
99  "PhotonPointingVertices.nphotons_good -> nphotons_good",
100  "PrimaryVertices.score_sumpt2 -> vtx_score_sumpt2",
101  "PrimaryVertices.score_true_vertex_distance -> vtx_score_true_vertex_distance",
102  ]
103  acc.addEventAlgo(
104  CompFactory.CP.AsgxAODNTupleMakerAlg(
105  "NTupleMaker", TreeName=flags.Output.TreeName, Branches=branches
106  )
107  )
108  acc.addEventAlgo(
109  CompFactory.CP.TreeFillerAlg("TreeFiller", TreeName=flags.Output.TreeName)
110  )
111 
112  return acc
113 
114 
116  from AthenaConfiguration.AllConfigFlags import initConfigFlags
117 
118  flags = initConfigFlags()
119  flags.Exec.MaxEvents = 100
120  from AthenaConfiguration.TestDefaults import defaultTestFiles
121 
122  flags.Input.Files = defaultTestFiles.AOD_RUN3_MC
123  flags.Output.HISTFileName = "test_tree.root"
124  flags.addFlag("Output.TreeName", "tree")
125 
126  flags.fillFromArgs()
127  flags.lock()
128  flags.dump()
129 
130  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
131 
132  acc = MainServicesCfg(flags)
133 
134  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
135 
136  acc.merge(PoolReadCfg(flags))
137 
138  acc.merge(TrkVertexWeightCalculatorDebugCfg(flags))
139  acc.printConfig(withDetails=True, summariseProps=True)
140  acc.store(open("TrkVertexWeightCalculatorBDTConfig.pkl", "wb"))
141  return acc
142 
143 
144 if __name__ == "__main__":
146  status = acc.run()
147 
148  import sys
149 
150  sys.exit(not status.isSuccess())
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.TrkVertexWeightCalculatorsConfig.SumPt2VertexWeightCalculatorCfg
def SumPt2VertexWeightCalculatorCfg(flags, name="SumPt2VertexWeightCalculator", **kwargs)
Definition: TrkConfig/python/TrkVertexWeightCalculatorsConfig.py:7
python.TrkVertexWeightCalculatorsConfig.DecorateVertexScoreAlgCfg
def DecorateVertexScoreAlgCfg(flags, name="DecorateVertexScoreAlg", **kwargs)
Definition: TrkVertexFitter/TrkVertexWeightCalculators/python/TrkVertexWeightCalculatorsConfig.py:7
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:256
Constants
some useful constants -------------------------------------------------—
Trk::open
@ open
Definition: BinningType.h:40
python.TrkVertexWeightCalculatorsConfig.BDTVertexWeightCalculatorSeqCfg
def BDTVertexWeightCalculatorSeqCfg(flags, container='Photons', **kwargs)
Definition: TrkConfig/python/TrkVertexWeightCalculatorsConfig.py:44
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
python.TrkVertexWeightCalculatorsConfig.TrkVertexWeightCalculatorBDTDebugRunCfg
def TrkVertexWeightCalculatorBDTDebugRunCfg()
Definition: TrkVertexFitter/TrkVertexWeightCalculators/python/TrkVertexWeightCalculatorsConfig.py:115
python.TrkVertexWeightCalculatorsConfig.TrkVertexWeightCalculatorDebugCfg
def TrkVertexWeightCalculatorDebugCfg(flags, **kwargs)
Definition: TrkVertexFitter/TrkVertexWeightCalculators/python/TrkVertexWeightCalculatorsConfig.py:25