ATLAS Offline Software
JetTrackSelectionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
10  asg::AsgTool(name), m_hidselector("",this) {
11  declareProperty("Selector", m_hidselector);
12 
13  declareProperty("InputContainer",m_inCont_key);
14  declareProperty("OutputContainer",m_outCont_key);
15 }
16 
18  ATH_MSG_INFO("Initializing tool " << "...");
19  ATH_MSG_DEBUG("initializing version with data handles");
20 
21 
22  StatusCode sc = m_hidselector.retrieve();
23  if (sc.isFailure()) {ATH_MSG_ERROR("Can't retrieve ITrackSelectorTool "<< m_hidselector.name() ); return sc;}
24 
25  if(!(m_inCont_key.key().empty() && m_outCont_key.key().empty())) {
28  }
29 
30  return StatusCode::SUCCESS;
31 }
32 
34  ATH_MSG_DEBUG(" execute() ... ");
35 
36  auto handle_in = SG::makeHandle(m_inCont_key);
37  if (! handle_in.isValid()){
38  // ATH_MSG_ERROR("Can't retrieve input track container "<< m_inputContainer);
39  ATH_MSG_ERROR("Can't retrieve input track container "
40  << m_inCont_key.key());
41  return 1;
42  }
43 
44  const auto *inCont = handle_in.cptr();
45 
47  OutContType* pOutCont = new OutContType(SG::VIEW_ELEMENTS);
48 
49  selectTracks(*inCont, *pOutCont);
50 
51  auto handle_out = SG::makeHandle(m_outCont_key);
52 
53  if (!handle_out.record(std::unique_ptr<OutContType>(pOutCont))){
54  // ATH_MSG_ERROR("Can't record output track container "<< m_outputContainer);
55  ATH_MSG_ERROR("Can't record output track container "
56  << m_outCont_key.key());
57  return 1;
58  }
59 
60  return 0;
61 }
62 
64  return static_cast<bool>(m_hidselector->accept(trk, nullptr));
65 }
66 
67 template<class T>
69  for ( const xAOD::TrackParticle* ptrk : inCont ) {
70  if ( ptrk != nullptr && keep(*ptrk) ) outCont.push_back(ptrk);
71  }
72 }
73 
75  selectionLoop(inCont, outCont);
76 }
77 
78 void JetTrackSelectionTool::selectTracks(const xAOD::TrackParticleContainer& inCont, std::vector<const xAOD::TrackParticle*> outCont) const {
79  selectionLoop(inCont, outCont);
80 }
81 
WriteHandle.h
Handle class for recording to StoreGate.
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
JetTrackSelectionTool::keep
int keep(const xAOD::TrackParticle &trk) const
Method to select.
Definition: JetTrackSelectionTool.cxx:63
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
asg
Definition: DataHandleTestTool.h:28
JetTrackSelectionTool::m_inCont_key
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inCont_key
Definition: JetTrackSelectionTool.h:52
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
JetTrackSelectionTool::selectionLoop
void selectionLoop(const xAOD::TrackParticleContainer &inCont, T &outCont) const
Definition: JetTrackSelectionTool.cxx:68
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
JetTrackSelectionTool::JetTrackSelectionTool
JetTrackSelectionTool(const std::string &name)
Definition: JetTrackSelectionTool.cxx:9
JetTrackSelectionTool.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector< xAOD::TrackParticle_v1 >
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ReadHandle.h
Handle class for reading from StoreGate.
JetTrackSelectionTool::selectTracks
void selectTracks(const xAOD::TrackParticleContainer &inCont, ConstDataVector< xAOD::TrackParticleContainer > &outCont) const
Definition: JetTrackSelectionTool.cxx:74
JetTrackSelectionTool::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetTrackSelectionTool.cxx:17
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
JetTrackSelectionTool::execute
int execute() const
Method to be called for each event.
Definition: JetTrackSelectionTool.cxx:33
JetTrackSelectionTool::m_hidselector
ToolHandle< InDet::IInDetTrackSelectionTool > m_hidselector
Definition: JetTrackSelectionTool.h:50
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
JetTrackSelectionTool::m_outCont_key
SG::WriteHandleKey< ConstDataVector< xAOD::TrackParticleContainer > > m_outCont_key
Definition: JetTrackSelectionTool.h:54
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35