ATLAS Offline Software
HIVertexSelectionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
8 #include "AsgMessaging/Check.h"
9 
10 using std::string;
11 
12 HI::HIVertexSelectionTool::HIVertexSelectionTool( const string& name )
13  : asg::AsgTool( name )
14  , m_accept( "HIVertexSelection" )
15 #ifndef XAOD_STANDALONE
16  // we don't want to give the tool a name in rootcore
17  , m_trkSelTool( "InDet::InDetTrackSelectionTool", this )
18 #endif // XAOD_STANDALONE
19 {
20  declareProperty( "RequirePrimary", m_requirePrimary, "Require the vertex to have type PriVtx");
21  declareProperty( "MaxAbsZ", m_maxAbsZ, "Maximum absolute value of the vertex z position");
22  declareProperty( "TrackSelectionTool", m_trkSelTool, "Track selection tool" );
23  declareProperty( "MinNTrk", m_minNtrk, "Minimum number of associated tracks passing selection" );
24  declareProperty( "MinRmsPt", m_minRmsPt, "Minimum RMS pt [MeV] of associated tracks passing selection" );
25 }
26 
27 HI::HIVertexSelectionTool::~HIVertexSelectionTool() = default;
28 
30 {
31  ATH_MSG_INFO( "Initializing vertex selection tool." );
33 
34 
35  if (m_requirePrimary) {
36  ATH_MSG_INFO( "Requiring vertex to be a primary vertex" );
37  m_accept.addCut( "type", "Whether the vertex satisfies the requirement to be a primary vertex" );
38  }
39  else {
40  ATH_MSG_INFO( "NOT requiring vertex to be a primary vertex" );
41  }
42 
43  if (m_maxAbsZ > 0.) {
44  ATH_MSG_INFO( "Maximum |z| = " << m_maxAbsZ << " mm" );
45  m_accept.addCut( "z", "Whether the vertex's |z| is in an allowed range" );
46  }
47 
48  if (m_minNtrk >= 0) {
49  m_checkTracks = true;
50  ATH_MSG_INFO( "Minimum Ntrk = " << m_minNtrk );
51  m_accept.addCut( "ntrk", "Whether the vertex has the minimum number of tracks" );
52  }
53  if (m_minRmsPt >= 0.) {
54  m_checkTracks = true;
55  ATH_MSG_INFO( "Minimum RMS track pt = " << m_minRmsPt << " MeV" );
56  m_accept.addCut( "pt", "Whether the vertex's tracks RMS pt is sufficient" );
57  }
58 
59 
60  return StatusCode::SUCCESS;
61 }
62 
64 {
65  ATH_MSG_INFO( "Finalizing vertex selection tool." );
66  return StatusCode::SUCCESS;
67 }
68 
69 //R.Longo 13-10-2019 - Replacing PATCore/TAccept (inherited from 21.0 HI-equalization)
71 {
72  // return the current TAccept object by reference. This allows users to avoid copying it.
73  return m_accept;
74 }
75 
77 {
78  asg::AcceptData acceptData (&m_accept);
79  ATH_MSG_ERROR( "Vertex selection tool should not be passed an IParticle." );
80  throw std::invalid_argument( "Vertex selection tool given an IParticle." );
81  return acceptData;
82 }
83 
85 {
86  asg::AcceptData acceptData (&m_accept);
87 
88  if (!m_requirePrimary || vtx.vertexType() == xAOD::VxType::PriVtx) {
89  acceptData.setCutResult( "type", true );
90  }
91  if (m_maxAbsZ < 0. || std::fabs( vtx.z() ) < m_maxAbsZ) {
92  acceptData.setCutResult( "z", true );
93  }
94  if (m_checkTracks) {
95  bool countTracks = m_minNtrk >= 0;
96  bool countPt = m_minRmsPt >= 0.;
97  int nPassed = 0; // cumulative total number of tracks passed
98  double sumPtSq = 0.; // cumulative total of pt^2 of tracks passed
99  for ( const auto& track : vtx.trackParticleLinks() ) {
100  if ( !track.isValid() ) continue;
101  if ( !m_trkSelTool->accept( **track, &vtx ) ) continue;
102 
103  if (countTracks) {
104  nPassed++;
105  if (nPassed >= m_minNtrk) {
106  acceptData.setCutResult( "ntrk", true );
107  countTracks = false; // stop bothering to count
108  }
109  }
110  if (countPt) {
111  auto pt = (*track)->pt();
112  sumPtSq += pt*pt;
113  if (sumPtSq >= m_minRmsPt*m_minRmsPt) {
114  acceptData.setCutResult( "pt", true);
115  countPt = false; // stop evaluating pt
116  }
117  }
118 
119  if (!countTracks && !countPt) break; // don't run through tracks we don't need to check
120  } // end loop over tracks
121  }
122 
123  return acceptData;
124 }
Check.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
HI::HIVertexSelectionTool::m_maxAbsZ
double m_maxAbsZ
maximum |z| position of the vertex
Definition: HIVertexSelectionTool.h:42
xAOD::Vertex_v1::trackParticleLinks
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
HIVertexSelectionTool.h
HI::HIVertexSelectionTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *) const override
The main accept method: the actual cuts are applied here.
Definition: HIVertexSelectionTool.cxx:76
asg
Definition: DataHandleTestTool.h:28
test_pyathena.pt
pt
Definition: test_pyathena.py:11
HI::HIVertexSelectionTool::getAcceptInfo
virtual const asg::AcceptInfo & getAcceptInfo() const override
Declare the interface ID for this pure-virtual interface class to the Athena framework.
Definition: HIVertexSelectionTool.cxx:70
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::Vertex_v1::vertexType
VxType::VertexType vertexType() const
The type of the vertex.
HI::HIVertexSelectionTool::m_accept
asg::AcceptInfo m_accept
Definition: HIVertexSelectionTool.h:38
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
asg::AcceptInfo
Definition: AcceptInfo.h:28
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
HI::HIVertexSelectionTool::m_minNtrk
int m_minNtrk
Definition: HIVertexSelectionTool.h:45
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::Vertex_v1::z
float z() const
Returns the z position.
HI::HIVertexSelectionTool::m_checkTracks
bool m_checkTracks
Definition: HIVertexSelectionTool.h:47
HI::HIVertexSelectionTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: HIVertexSelectionTool.cxx:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
HI::HIVertexSelectionTool::m_requirePrimary
bool m_requirePrimary
require the vertex to be of type PriVtx
Definition: HIVertexSelectionTool.h:41
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
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
HI::HIVertexSelectionTool::finalize
virtual StatusCode finalize() override
Definition: HIVertexSelectionTool.cxx:63
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
asg::AcceptData
Definition: AcceptData.h:30
asg::AsgTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: AsgTool.h:133
TrackParticleContainer.h
asg::AcceptInfo::addCut
int addCut(const std::string &cutName, const std::string &cutDescription)
Add a cut; returning the cut position.
Definition: AcceptInfo.h:53
HI::HIVertexSelectionTool::m_minRmsPt
double m_minRmsPt
Definition: HIVertexSelectionTool.h:46