ATLAS Offline Software
TopGhostTrackCPTools.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
7 #include <map>
8 #include <string>
9 #include <utility>
10 
11 // Top includes
13 #include "TopEvent/EventTools.h"
14 
15 // PathResolver include(s):
17 
18 
19 namespace top {
21  asg::AsgTool(name) {
22  declareProperty("config", m_config);
23  }
24 
26  ATH_MSG_INFO("top::GhostTrackCPTools initialize...");
27 
28  if (m_config->isTruthDxAOD()) {
29  ATH_MSG_INFO("top::GhostTrackCPTools: no need to initialise anything on truth DxAOD");
30  return StatusCode::SUCCESS;
31  }
32 
33  if (!m_config->useJets() || !m_config->useJetGhostTrack()) {
35  "top::GhostTrackCPTools: no need to initialise anything since not using jets or tracks ghost-matched to jets");
36  return StatusCode::SUCCESS;
37  }
38 
39  if (!m_config->makeAllCPTools()) {
40  ATH_MSG_INFO("top::GhostTrackCPTools: no need to initialise for mini-xAOD");
41  return StatusCode::SUCCESS;
42  }
43 
44 
45  // This defines the run period (ranges) that are used by the
46  // InDet::InDetTrackBiasingTool. The following inputs are possible:
47  // - No / empty input: Use the maximum range, that is [0;
48  // UInt32_t::max) as allowed run number value range. Initialise
49  // the tool with run number 0 (which will use 2015 precriptions).
50  // - A single run number: Configure the tool with this run number
51  // and to not apply checks / selection on the random run number of
52  // the actual events.
53  // - At least two values: Use this to define adjacent ranges, each
54  // of which is processed using a unique instance of the tool which
55  // was initialised using the lower bound of the range. From an
56  // input of size n, n-1 ranges are formed. The i-th element is the
57  // lower bound (incl) of the i-th range; the (i+1)-th element is
58  // the upper bound (excl) of the i-th range.
59  m_runPeriods = {
60  276262, 297730, 300909, 311482, 334738, 341650, 364486
61  };
62 
63  m_config->runPeriodJetGhostTrack(m_runPeriods);
64 
65  top::check(setupSmearingTool(), "Failed to setup track smearing tools");
66  top::check(setupBiasingTools(), "Failed to setup track biasing tools");
67  top::check(setupTruthFilterTool(), "Failed to setup truth filter tools");
68  top::check(setupJetTrackFilterTool(), "Failed to setup track filter tools");
69  top::check(setupSelectionTool(), "Failed to setup track selection tools");
70 
71  return StatusCode::SUCCESS;
72  }
73 
75 
76  if (asg::ToolStore::contains<InDet::InDetTrackSelectionTool>(m_TrkSelName)) {
77  m_trackseltool = asg::ToolStore::get<InDet::InDetTrackSelectionTool>(m_TrkSelName);
78  } else {
79  auto selTool = std::make_unique<InDet::InDetTrackSelectionTool>( m_TrkSelName ,m_config->ghostTracksQuality());
80  top::check(selTool -> initialize(), "Failed to initialize InDetTrackSelectionTool for GA tracks");
81  m_trackseltool = selTool.release();
82  ATH_MSG_INFO("Creating selection tool " + m_TrkSelName);
83  }
84 
85  return StatusCode::SUCCESS;
86 
87  }
88 
90  if (asg::ToolStore::contains<InDet::InDetTrackSmearingTool>(m_smearingToolName)) {
91  m_smearingTool = asg::ToolStore::get<InDet::InDetTrackSmearingTool>(m_smearingToolName);
92  } else {
94  top::check(tool->initialize(), "Failure to initialize InDetTrackSmearingTool");
96  ATH_MSG_INFO(" Creating smearing tool " + m_smearingToolName);
97  }
98  return StatusCode::SUCCESS;
99  }
100 
102  top::check(not m_runPeriods.empty(), "Assertion failed");
103 
104  // Two cases are possible:
105  // - Either a single run number was specified to the runPeriods
106  // parameter in which case we'll use exactly that run number, or
107  // - at least two numbers have been specified, which then define
108  // (potentially multiple) run number ranges.
109 
110  if (m_runPeriods.size() == 1) {
111  m_runPeriods.resize(1);
112 
113  const std::string biasToolName {
115  };
116 
117  if (asg::ToolStore::contains<InDet::InDetTrackBiasingTool>(biasToolName)) {
118  m_biasingTool[0] = asg::ToolStore::get<InDet::InDetTrackBiasingTool>(biasToolName);
119  } else {
120  auto tool = new InDet::InDetTrackBiasingTool(biasToolName);
121  top::check(tool->setProperty("runNumber", m_runPeriods[0]),
122  "Failure to setProperty runNumber of InDetTrackBiasingTool " + biasToolName);
123  top::check(tool->initialize(),
124  "Failure to initialize InDetTrackBiasingTool " + biasToolName);
125  m_biasingTool[0] = tool;
126  }
127  ATH_MSG_INFO(" Creating biasing tool to calibrate for run#=" << m_runPeriods[0] << ": " + biasToolName);
128  } else {
129  m_biasingTool.resize(m_runPeriods.size() - 1);
130  for (std::size_t i = 0; i < m_runPeriods.size() - 1; ++i) {
131  const std::string biasToolName {
133  + "_" + std::to_string(m_runPeriods[i])
134  + "_" + std::to_string(m_runPeriods[i + 1])
135  };
136  ATH_MSG_INFO(
137  " Creating biasing tool to calibrate for period [" << m_runPeriods[i] << ", " << m_runPeriods[i + 1] << "): " <<
138  biasToolName);
139  if (asg::ToolStore::contains<InDet::InDetTrackBiasingTool>(biasToolName)) {
140  m_biasingTool[i] =
141  asg::ToolStore::get<InDet::InDetTrackBiasingTool>(biasToolName);
142  } else {
143  auto tool = new InDet::InDetTrackBiasingTool(biasToolName);
144  top::check(tool->setProperty("runNumber", m_runPeriods[i]),
145  "Failure to setProperty runNumber of InDetTrackBiasingTool " + biasToolName);
146  top::check(tool->initialize(),
147  "Failure to initialize InDetTrackBiasingTool " + biasToolName);
148  m_biasingTool[i] = tool;
149  }
150  }
151  }
152  return StatusCode::SUCCESS;
153  }
154 
156  if (asg::ToolStore::contains<InDet::InDetTrackTruthOriginTool>(m_truthOriginToolName)) {
157  m_truthOriginTool = asg::ToolStore::get<InDet::InDetTrackTruthOriginTool>(m_truthOriginToolName);
158  } else {
160  top::check(tool->initialize(),
161  "Failure to initialize InDetTrackTruthOriginTool " + m_truthOriginToolName);
163  ATH_MSG_INFO(" Creating truth origin tool " + m_truthOriginToolName);
164  }
165 
166  if (asg::ToolStore::contains<InDet::InDetTrackTruthFilterTool>(m_truthFilterToolName)) {
167  m_truthFilterTool = asg::ToolStore::get<InDet::InDetTrackTruthFilterTool>(m_truthFilterToolName);
168  } else {
170  top::check(tool->setProperty("trackOriginTool",
171  ToolHandle<InDet::IInDetTrackTruthOriginTool>{&(*m_truthOriginTool)}),
172  "Failed to setProperty trackOriginTool of InDetTrackTruthFilterTool " + m_truthFilterToolName);
173  top::check(tool->initialize(),
174  "Failure to initialize InDetTrackTruthFilterTool " + m_truthFilterToolName);
176  ATH_MSG_INFO(" Creating truth filter tool " + m_truthFilterToolName);
177  }
178  return StatusCode::SUCCESS;
179  }
180 
182  if (asg::ToolStore::contains<InDet::InDetTrackTruthOriginTool>(m_truthOriginToolName)) {
183  m_truthOriginTool = asg::ToolStore::get<InDet::InDetTrackTruthOriginTool>(m_truthOriginToolName);
184  } else {
186  top::check(tool->initialize(),
187  "Failure to initialize InDetTrackTruthOriginTool " + m_truthOriginToolName);
189  ATH_MSG_INFO(" Creating truth origin tool " + m_truthOriginToolName);
190  }
191 
192  if (asg::ToolStore::contains<InDet::JetTrackFilterTool>(m_jetTrackFilterToolName)) {
193  m_jetTrackFilterTool = asg::ToolStore::get<InDet::JetTrackFilterTool>(m_jetTrackFilterToolName);
194  } else {
196  top::check(tool->setProperty("trackOriginTool",
197  ToolHandle<InDet::IInDetTrackTruthOriginTool>{&(*m_truthOriginTool)}),
198  "Failed to setProperty trackOriginTool of InDetTrackTruthFilterTool " + m_truthFilterToolName);
199  top::check(tool->initialize(), "Failure to initialize JetTrackFilterTool");
201  ATH_MSG_INFO(" Creating jet track filter tool");
202  }
203  return StatusCode::SUCCESS;
204  }
205 } // namespace top
top::GhostTrackCPTools::m_biasingTool
std::vector< ToolHandle< InDet::InDetTrackBiasingTool > > m_biasingTool
Definition: TopGhostTrackCPTools.h:71
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
top::GhostTrackCPTools::m_trackseltool
ToolHandle< InDet::InDetTrackSelectionTool > m_trackseltool
Definition: TopGhostTrackCPTools.h:68
top::GhostTrackCPTools::m_truthOriginToolName
const std::string m_truthOriginToolName
Definition: TopGhostTrackCPTools.h:50
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
top::GhostTrackCPTools::m_jetTrackFilterTool
ToolHandle< InDet::JetTrackFilterTool > m_jetTrackFilterTool
Definition: TopGhostTrackCPTools.h:67
asg
Definition: DataHandleTestTool.h:28
InDet::InDetTrackTruthOriginTool
Definition: InDetTrackTruthOriginTool.h:24
InDet::InDetTrackSmearingTool
Definition: InDetTrackSmearingTool.h:32
top::GhostTrackCPTools::setupBiasingTools
StatusCode setupBiasingTools()
Definition: TopGhostTrackCPTools.cxx:101
top::GhostTrackCPTools::m_TrkSelName
const std::string m_TrkSelName
Definition: TopGhostTrackCPTools.h:60
top::GhostTrackCPTools::m_truthFilterToolName
const std::string m_truthFilterToolName
Definition: TopGhostTrackCPTools.h:53
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
TopGhostTrackCPTools.h
top::GhostTrackCPTools::m_truthFilterTool
ToolHandle< InDet::InDetTrackTruthFilterTool > m_truthFilterTool
Definition: TopGhostTrackCPTools.h:66
lumiFormat.i
int i
Definition: lumiFormat.py:92
top::GhostTrackCPTools::m_biasToolPrefix
const std::string m_biasToolPrefix
Definition: TopGhostTrackCPTools.h:47
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
top::GhostTrackCPTools::m_smearingToolName
const std::string m_smearingToolName
Definition: TopGhostTrackCPTools.h:44
InDet::InDetTrackBiasingTool
Definition: InDetTrackBiasingTool.h:36
top::GhostTrackCPTools::setupSelectionTool
StatusCode setupSelectionTool()
Definition: TopGhostTrackCPTools.cxx:74
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
top::GhostTrackCPTools::m_truthOriginTool
ToolHandle< InDet::InDetTrackTruthOriginTool > m_truthOriginTool
Definition: TopGhostTrackCPTools.h:65
top::GhostTrackCPTools::setupJetTrackFilterTool
StatusCode setupJetTrackFilterTool()
Definition: TopGhostTrackCPTools.cxx:181
InDet::JetTrackFilterTool
Definition: JetTrackFilterTool.h:37
top::GhostTrackCPTools::GhostTrackCPTools
GhostTrackCPTools(const std::string &name)
Definition: TopGhostTrackCPTools.cxx:20
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
top::GhostTrackCPTools::m_smearingTool
ToolHandle< InDet::InDetTrackSmearingTool > m_smearingTool
Definition: TopGhostTrackCPTools.h:64
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
InDet::InDetTrackTruthFilterTool
Definition: InDetTrackTruthFilterTool.h:36
TopConfig.h
top::GhostTrackCPTools::setupTruthFilterTool
StatusCode setupTruthFilterTool()
Definition: TopGhostTrackCPTools.cxx:155
top::GhostTrackCPTools::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: TopGhostTrackCPTools.cxx:25
top::GhostTrackCPTools::setupSmearingTool
StatusCode setupSmearingTool()
Definition: TopGhostTrackCPTools.cxx:89
top::GhostTrackCPTools::m_runPeriods
std::vector< std::uint32_t > m_runPeriods
Definition: TopGhostTrackCPTools.h:42
top::GhostTrackCPTools::m_config
std::shared_ptr< top::TopConfig > m_config
Definition: TopGhostTrackCPTools.h:40
top::GhostTrackCPTools::m_jetTrackFilterToolName
const std::string m_jetTrackFilterToolName
Definition: TopGhostTrackCPTools.h:56