ATLAS Offline Software
Loading...
Searching...
No Matches
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
9
10using std::string;
11
12HI::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
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
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
virtual asg::AcceptData accept(const xAOD::IParticle *) const override
The main accept method: the actual cuts are applied here.
virtual const asg::AcceptInfo & getAcceptInfo() const override
Declare the interface ID for this pure-virtual interface class to the Athena framework.
virtual StatusCode initialize() override
double m_maxAbsZ
maximum |z| position of the vertex
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool
track selection tool which can be optionally used for N_trk and sum pt cuts
ASG_TOOL_CLASS2(HIVertexSelectionTool, IAsgSelectionTool, HI::IHIVertexSelectionTool) public ~HIVertexSelectionTool()
virtual StatusCode finalize() override
bool m_requirePrimary
require the vertex to be of type PriVtx
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition AcceptData.h:134
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition AsgTool.h:133
Class providing the definition of the 4-vector interface.
float z() const
Returns the z position.
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
VxType::VertexType vertexType() const
The type of the vertex.
@ PriVtx
Primary vertex.
Vertex_v1 Vertex
Define the latest version of the vertex class.