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