ATLAS Offline Software
Loading...
Searching...
No Matches
JetFitterTrackSelectorTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5#include <cassert>
6
7using namespace InDet;
8
9 JetFitterTrackSelectorTool::JetFitterTrackSelectorTool(const std::string &t, const std::string &n, const IInterface *p)
10 : AthAlgTool(t, n, p)
11 {
12 declareInterface< JetFitterTrackSelectorTool >(this);
13 }
14
16
18
19 if ( m_trkFilter.retrieve().isFailure() ) {
20 msg(MSG::ERROR) << " Unable to retrieve InDet::InDetDetailedTrackSelectorTool" << endmsg;
21 return StatusCode::FAILURE;
22 }
23
24 if ( m_jetFitterUtils.retrieve().isFailure() ) {
25 msg(MSG::ERROR) << " Unable to retrieve InDet::InDetJetFitterUtils/InDetJetFitterUtils" << endmsg;
26 return StatusCode::FAILURE;
27 }
28
29 if ( m_extrapolator.retrieve().isFailure() ) {
30 msg(MSG::ERROR) << " Unable to retrieve Trk::Extrapolator/InDetExtrapolator" << endmsg;
31 return StatusCode::FAILURE;
32 }
33
34 return StatusCode::SUCCESS;
35 }
36
37
39 const TLorentzVector &jetMomentum,
40 const std::vector<const xAOD::IParticle *> &inputTracks) const {
41 // perform the track selection
42 // step 1, apply a track filter like "InDet::InDetDetailedTrackSelectorTool"
43 // step 2, calculate the compatibility of filtered tracks with primary vertex
44 // use this to deduce primaryTracks and secondaryTracks
45
46 ATH_MSG_DEBUG( "Doing track selection on " << inputTracks.size() << " tracks ... " );
47
48 // We need to use normal pointers instead of smart pointers since the code breaks.
49 // We have to fix this issue in the future
50 // if ( m_selectedTracks != nullptr ) delete m_selectedTracks; // May this break the code?
52
53 // Vectors of Trk::ITrackLink to be given to m_selectedTracks once we understand if they are primary of secondary tracks
54 std::vector< const Trk::ITrackLink* > primaryTrackLinks;
55 std::vector< const Trk::ITrackLink* > secondaryTrackLinks;
56
57 // Running on input tracks
58 std::vector<const xAOD::IParticle *>::const_iterator trk_iter = inputTracks.begin();
59 std::vector<const xAOD::IParticle*>::const_iterator trk_end = inputTracks.end();
60
61 int counter = 0;
62 for ( ; trk_iter != trk_end; ++trk_iter ) {
63 // Convert xAOD::IParticle to xAOD::TrackParticle
64 const xAOD::TrackParticle * tmp = dynamic_cast< const xAOD::TrackParticle* > ( *trk_iter );
65 assert( tmp != nullptr ); // in principle should really check that inputTracks only contains TrackParticle objects
66
67 // Compute compatibility and understand track type
68 // -1: track filter failed
69 // 0: extrapolation of MeasuredPerigee failed
70 // 1: primary
71 // 2: secondary
72 //'tmp' is checked in dbg builds, should be enough; _could_ probably use static_cast there
73 //coverity[FORWARD_NULL]
74 int type = computeTrackCompatibility( primaryVertex,jetMomentum,*tmp );
75
76 // Create Trk::ITrackLink collections to be given to selected tracks
77 if (type==1 || type==2) {
79 linkTP.setElement( tmp );
81
82 if ( type == 1) primaryTrackLinks.push_back( link );
83 else if ( type == 2 ) secondaryTrackLinks.push_back( link );
84 }
85 else {
86 continue;
87 }
88
89 // How many tracks we are selecting
90 counter++;
91 }
92
93 ATH_MSG_DEBUG( " Total of selected tracks: "<< counter );
94
95 selectedTracks->setPrimaryTrackLinks( primaryTrackLinks );
96 selectedTracks->setSecondaryTrackLinks( secondaryTrackLinks );
97 return selectedTracks;
98 }
99
100
103 {
104 std::vector<std::string> out;
105 std::string toolname = this->name();
106 std::string delimiter = "_";
107 std::string::size_type firstDelimiter = toolname.find(delimiter);
108 std::string sub = toolname.substr(0, firstDelimiter);
110 sub += "FLIP_SIGN";
111 }
112 return std::string("JetFitter_TrackCompatibility_") + sub;
113 }
114
118 std::vector<std::string>
120 {
121 return std::vector<std::string> { decorationName() };
122 }
123
125 const TLorentzVector &jetMomentum,
126 const xAOD::TrackParticle &track ) const {
127
128 // Decorators for tracks
129 SG::AuxElement::Decorator< float > compatibilityDecorator(decorationName());
130
131 // Apply track filter
132 if ( !m_trkFilter->decision( track, &primaryVertex ) ) {
133 compatibilityDecorator ( track ) = 0.;
134 return -1;
135 }
136
137 // Recomputing Perigee w.r.t PV
138 Trk::PerigeeSurface mySurface( primaryVertex.position() );
139 std::unique_ptr<const Trk::TrackParameters> myMeasuredPerigee(m_extrapolator->extrapolate(
140 Gaudi::Hive::currentContext(),track.perigeeParameters(),mySurface ));
141
142 if ( !myMeasuredPerigee) {
143 ATH_MSG_DEBUG( " Extrapolation to primary vertex failed. Skipping track " );
144 compatibilityDecorator ( track ) = 0.;
145 return 0;
146 }
147
148
149 // Prepare for using jetFitterUtils (for the computation of the compatibility)
150 // Is this conrvertion really necessary?
151 Trk::RecVertex primaryVertexRecVertex( primaryVertex.position(),
152 primaryVertex.covariancePosition(),
153 primaryVertex.numberDoF(),
154 primaryVertex.chiSquared());
155
156 Amg::Vector3D jetMomSpatial( jetMomentum.X(),jetMomentum.Y(),jetMomentum.Z() );
157 double compatibilityValue = m_jetFitterUtils->compatibility( *myMeasuredPerigee,primaryVertexRecVertex ).first;
158 compatibilityValue = fabs( compatibilityValue ) * InDet::InDetJetFitterUtils::get3DLifetimeSignOfTrack( *myMeasuredPerigee,
159 jetMomSpatial,
160 primaryVertexRecVertex );
161
162 // Decorate
163 ATH_MSG_DEBUG( "compatibilityValue = " << compatibilityValue );
164 compatibilityDecorator ( track ) = compatibilityValue;
165
166 // Understand if primary or secondary track particle
167 double cutCompatibilityPVforPosTracks = m_cutCompatibilityPrimaryVertexForPositiveLifetimeTracks;
168 double cutCompatibilityPVforNegTracks = m_cutCompatibilityPrimaryVertexForNegativeLifetimeTracks;
169
171 cutCompatibilityPVforNegTracks = m_cutCompatibilityPrimaryVertexForPositiveLifetimeTracks;
172 cutCompatibilityPVforPosTracks = m_cutCompatibilityPrimaryVertexForNegativeLifetimeTracks;
173 }
174
175 if ( ( compatibilityValue < 0 &&
176 TMath::Prob( fabs( compatibilityValue ),2 ) < cutCompatibilityPVforNegTracks) ||
177 ( compatibilityValue >= 0 &&
178 TMath::Prob( fabs( compatibilityValue ),2 ) < cutCompatibilityPVforPosTracks ) )
179 return 2;
180 else return 1;
181
182 }
183
184
185
#define endmsg
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
MsgStream & msg() const
static double get3DLifetimeSignOfTrack(const Trk::TrackParameters &track, const Amg::Vector3D &jetMomentum, const Trk::RecVertex &primaryVertex)
Gaudi::Property< double > m_cutCompatibilityPrimaryVertexForPositiveLifetimeTracks
std::vector< std::string > trackDecorationNames() const
Return a list of the names of track decorations created by this tool, in order to allow them to be lo...
JetFitterTrackSelectorTool(const std::string &t, const std::string &n, const IInterface *p)
std::string decorationName() const
Return the name of the decoration we produce.
ToolHandle< Trk::ITrackSelectorTool > m_trkFilter
Gaudi::Property< bool > m_revertFromPositiveToNegativeTags
Gaudi::Property< double > m_cutCompatibilityPrimaryVertexForNegativeLifetimeTracks
int computeTrackCompatibility(const xAOD::Vertex &primaryVertex, const TLorentzVector &jetMomentum, const xAOD::TrackParticle &trk_iter) const
const Trk::SelectedTracksInJet * doTrackSelection(const xAOD::Vertex &primaryVertex, const TLorentzVector &jetMomentum, const std::vector< const xAOD::IParticle * > &inputTracks) const
ToolHandle< InDet::InDetJetFitterUtils > m_jetFitterUtils
ToolHandle< Trk::IExtrapolator > m_extrapolator
Element link to XAOD TrackParticle.
Class describing the Line to which the Perigee refers to.
Trk::RecVertex inherits from Trk::Vertex.
Definition RecVertex.h:44
void setPrimaryTrackLinks(std::vector< const ITrackLink * > &primaryTrackLinks)
Set the primary tracks (takes ownership of pointers).
void setSecondaryTrackLinks(std::vector< const ITrackLink * > &secondaryTracLinks)
Set the secondary tracks (takes ownership of pointers).
float numberDoF() const
Returns the number of degrees of freedom of the vertex fit as float.
float chiSquared() const
Returns the of the vertex fit as float.
const Amg::Vector3D & position() const
Returns the 3-pos.
static const std::string delimiter("/")
Eigen::Matrix< double, 3, 1 > Vector3D
Primary Vertex Finder.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.