ATLAS Offline Software
InDetTrackSelectionAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 //
10 // includes
11 //
12 
14 
17 
18 //
19 // method implementations
20 //
21 
22 namespace CP
23 {
24 
26  initialize ()
27  {
28  if (!m_selectionTool.empty())
29  ANA_CHECK (m_selectionTool.retrieve());
30  if (!m_filterTool.empty())
31  {
32  if (m_selectionTool.empty())
33  {
34  ATH_MSG_ERROR( "The TruthFilterTool was requested without initializing the SelectionTool. "
35  "This is not supported. Please check that the SelectionTool is used." );
36  return StatusCode::FAILURE;
37  }
38 
39  CP::SystematicSet recommendedSystematics;
40  if ( m_filterWP=="TIGHT" )
41  {
42  ATH_MSG_INFO( "The TruthFilterTool is set up with the TIGHT selection "
43  "working point. Will run the appropriate systematics" );
44  recommendedSystematics =
45  {
52  };
53  }
54  else if ( m_filterWP=="LOOSE" )
55  {
56  ATH_MSG_INFO( "The TruthFilterTool is set up with the LOOSE selection "
57  "working point. Will run the appropriate systematics" );
58  recommendedSystematics =
59  {
66  };
67  }
68  else
69  {
70  ATH_MSG_ERROR( "The TruthFilterTool was requested with the unsupported selection working "
71  "point "+ m_filterWP + ". Please use the cut levels 'Loose' or 'TightPrimary'." );
72  return StatusCode::FAILURE;
73  }
74 
75  ANA_CHECK (m_filterTool.retrieve());
76 
77  const SystematicSet affectingSystematics = m_filterTool->affectingSystematics();
78  for (auto& sys : recommendedSystematics)
79  {
80  if (affectingSystematics.find(sys.name()) == affectingSystematics.end())
81  {
82  ATH_MSG_ERROR( "Systematic " + sys.name() + " was expected for the FilterTool "
83  "based on the working point " + m_filterWP + " but not found "
84  "in affectingSystematics.");
85  return StatusCode::FAILURE;
86  }
87  }
88  //TODO: The second argument is meant to be 'affecting'. However, this leads
89  // to the registration of both 'Loose' and 'Tight' systematics in each
90  // WP. This may require changes to the underlying methods of the filterTool.
91  ANA_CHECK (m_systematicsList.addSystematics (recommendedSystematics, recommendedSystematics));
92  }
93 
98 
99  if (!m_selectionTool.empty())
100  {
101  m_acceptInfo = m_selectionTool->getAcceptInfo();
102  if (!m_filterTool.empty())
103  {
104  if (m_acceptInfo.addCut( "truthFilter", "Selection of tracks according to the InDetTrackTruthFilterTool" ) < 0)
105  {
106  ATH_MSG_ERROR( "Failed to add cut 'truthFilter' because the TAccept object is full." );
107  return StatusCode::FAILURE;
108  }
109  }
110  asg::AcceptData blankAccept (&m_acceptInfo);
111  // Just in case this isn't initially set up as a failure clear it this one
112  // time. This only calls reset on the bitset
113  blankAccept.clear();
114  m_setOnFail = selectionFromAccept(blankAccept);
115 
116  ANA_CHECK (m_nameSvc.retrieve());
117  ANA_CHECK (m_nameSvc->addAcceptInfo (m_tracksHandle.getNamePattern(),
119  }
120 
121  return StatusCode::SUCCESS;
122  }
123 
124 
125 
127  execute ()
128  {
129  for (const auto& sys : m_systematicsList.systematicsVector())
130  {
131  if (!m_filterTool.empty())
132  ANA_CHECK (m_filterTool->applySystematicVariation (sys));
133 
134  const xAOD::TrackParticleContainer *tracks = nullptr;
135  ANA_CHECK (m_tracksHandle.retrieve (tracks, sys));
136  for (const xAOD::TrackParticle *track : *tracks)
137  {
139  {
140  if (!m_selectionTool.empty())
141  {
142  asg::AcceptData fullAccept (&m_acceptInfo);
143  asg::AcceptData selectAccept = m_selectionTool->accept(track);
144  for (unsigned int i = 0; i < selectAccept.getNCuts(); i++)
145  {
146  fullAccept.setCutResult (selectAccept.getCutName(i), selectAccept.getCutResult(i));
147  }
148 
149  if (!m_filterTool.empty())
150  {
151  fullAccept.setCutResult ("truthFilter", m_filterTool->accept (track));
152  }
153 
155  (*track, selectionFromAccept (fullAccept), sys);
156  }
157  else
158  {
160  }
161  }
162  else
163  {
164  if (!m_selectionTool.empty())
165  {
167  }
168  else
169  {
170  m_selectionHandle.setBool (*track, false, sys);
171  }
172  }
173  }
174  }
175 
176  return StatusCode::SUCCESS;
177  }
178 }
InDet::TRK_FAKE_RATE_TIGHT
@ TRK_FAKE_RATE_TIGHT
Definition: InDetTrackSystematics.h:24
CP::SysWriteSelectionHandle::setBits
void setBits(const SG::AuxElement &element, SelectionType selection, const CP::SystematicSet &sys) const
set the selection decoration
InDet::TRK_EFF_TIGHT_PP0
@ TRK_EFF_TIGHT_PP0
Definition: InDetTrackSystematics.h:33
asg::AcceptData::getNCuts
unsigned int getNCuts() const
Get the number of cuts defined.
Definition: AcceptData.h:64
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CP::InDetTrackSelectionAlg::m_filterWP
Gaudi::Property< std::string > m_filterWP
Definition: InDetTrackSelectionAlg.h:76
CP::InDetTrackSelectionAlg::execute
StatusCode execute() override
Definition: InDetTrackSelectionAlg.cxx:127
InDet::TRK_EFF_LOOSE_COMBINED
@ TRK_EFF_LOOSE_COMBINED
Definition: InDetTrackSystematics.h:43
CP::selectionFromAccept
SelectionType selectionFromAccept(const asg::AcceptData &accept)
the selection decoration made from the given AcceptData object
Definition: SelectionHelpers.cxx:32
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
CP::InDetTrackSelectionAlg::m_setOnFail
SelectionType m_setOnFail
the bits to set for an object failing the preselection
Definition: InDetTrackSelectionAlg.h:70
CP::SysListHandle::addSystematics
StatusCode addSystematics(const CP::SystematicSet &recommended, const CP::SystematicSet &affecting)
register a set of affecting variables for the current algorithm (usually obtained from an CP::ISystem...
Definition: SysListHandle.cxx:48
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
CP::SysListHandle::systematicsVector
const std::vector< CP::SystematicSet > & systematicsVector() const
the list of systematics to loop over
Definition: SysListHandle.cxx:96
CP::InDetTrackSelectionAlg::initialize
StatusCode initialize() override
Definition: InDetTrackSelectionAlg.cxx:26
InDet::TRK_EFF_LOOSE_PP0
@ TRK_EFF_LOOSE_PP0
Definition: InDetTrackSystematics.h:29
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
CP::SysWriteSelectionHandle::setBool
void setBool(const SG::AuxElement &element, bool selection, const CP::SystematicSet &sys) const
set the selection decoration
ISystematicsTool.h
CP::SysWriteSelectionHandle::getLabel
std::string getLabel() const
get the name/label of the decoration
Definition: SysWriteSelectionHandle.cxx:76
InDetTrackSelectionAlg.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CP::SysListHandle::initialize
::StatusCode initialize()
intialize this property
Definition: SysListHandle.cxx:69
CP::SysReadSelectionHandle::getBool
bool getBool(const SG::AuxElement &element, const CP::SystematicSet &sys) const
get the selection as a bool
CP::InDetTrackSelectionAlg::m_selectionTool
ToolHandle< InDet::IInDetTrackSelectionTool > m_selectionTool
the smearing tool
Definition: InDetTrackSelectionAlg.h:39
lumiFormat.i
int i
Definition: lumiFormat.py:85
InDet::TrackSystematicMap
static const std::unordered_map< InDet::TrackSystematic, CP::SystematicVariation, std::hash< int > > TrackSystematicMap
Definition: InDetTrackSystematics.h:50
InDet::TRK_EFF_LOOSE_PHYSMODEL
@ TRK_EFF_LOOSE_PHYSMODEL
Definition: InDetTrackSystematics.h:30
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
InDet::TRK_EFF_TIGHT_COMBINED
@ TRK_EFF_TIGHT_COMBINED
Definition: InDetTrackSystematics.h:44
CP::SystematicSet::end
const_iterator end() const
description: const iterator to the end of the set
Definition: SystematicSet.h:59
InDet::TRK_EFF_TIGHT_GLOBAL
@ TRK_EFF_TIGHT_GLOBAL
Definition: InDetTrackSystematics.h:31
CP::InDetTrackSelectionAlg::m_filterTool
ToolHandle< InDet::IInDetTrackTruthFilterTool > m_filterTool
the filter tool
Definition: InDetTrackSelectionAlg.h:43
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
InDet::TRK_EFF_TIGHT_IBL
@ TRK_EFF_TIGHT_IBL
Definition: InDetTrackSystematics.h:32
asg::AcceptData::getCutName
const std::string & getCutName(unsigned int cutPosition) const
Get the name of a cut, based on the cut position (slow, avoid usage)
Definition: AcceptData.h:78
CP::InDetTrackSelectionAlg::m_tracksHandle
SysReadHandle< xAOD::TrackParticleContainer > m_tracksHandle
the track collection we run on
Definition: InDetTrackSelectionAlg.h:51
InDet::TRK_EFF_LOOSE_IBL
@ TRK_EFF_LOOSE_IBL
Definition: InDetTrackSystematics.h:28
CP::InDetTrackSelectionAlg::m_nameSvc
ServiceHandle< ISelectionNameSvc > m_nameSvc
the ISelectionNameSvc
Definition: InDetTrackSelectionAlg.h:66
CP::InDetTrackSelectionAlg::m_preselection
SysReadSelectionHandle m_preselection
the preselection we apply to our input
Definition: InDetTrackSelectionAlg.h:56
InDet::TRK_EFF_TIGHT_PHYSMODEL
@ TRK_EFF_TIGHT_PHYSMODEL
Definition: InDetTrackSystematics.h:34
CP::SystematicSet::find
iterator find(const SystematicVariation &sys) const
description: find an element in the set
Definition: SystematicSet.h:63
InDetTrackSystematics.h
InDet::TRK_FAKE_RATE_LOOSE
@ TRK_FAKE_RATE_LOOSE
Definition: InDetTrackSystematics.h:23
asg::AcceptData::setCutResult
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:134
asg::AcceptData::clear
void clear()
Clear all bits.
Definition: AcceptData.h:54
asg::AcceptData::getCutResult
bool getCutResult(const std::string &cutName) const
Get the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:98
CP::InDetTrackSelectionAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: InDetTrackSelectionAlg.h:47
CP::SysReadSelectionHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle, const ISysHandleBase &objectHandle)
initialize the accessor
Definition: SysReadSelectionHandle.cxx:34
CP::InDetTrackSelectionAlg::m_selectionHandle
SysWriteSelectionHandle m_selectionHandle
the decoration for the asg selection
Definition: InDetTrackSelectionAlg.h:61
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
CP::InDetTrackSelectionAlg::m_acceptInfo
asg::AcceptInfo m_acceptInfo
Definition: InDetTrackSelectionAlg.h:73
asg::AcceptData
Definition: AcceptData.h:30
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
InDet::TRK_EFF_LOOSE_GLOBAL
@ TRK_EFF_LOOSE_GLOBAL
Definition: InDetTrackSystematics.h:27
CP::SysWriteSelectionHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle, const ISysHandleBase &objectHandle)
initialize the accessor
Definition: SysWriteSelectionHandle.cxx:34
asg::AcceptInfo::addCut
int addCut(const std::string &cutName, const std::string &cutDescription)
Add a cut; returning the cut position.
Definition: AcceptInfo.h:53