ATLAS Offline Software
JetFitterTrackSelectorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
5 #include <cassert>
6 
7 using 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?
51  Trk::SelectedTracksInJet *selectedTracks = new Trk::SelectedTracksInJet();
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  int type = computeTrackCompatibility( primaryVertex,jetMomentum,*tmp );
73 
74  // Create Trk::ITrackLink collections to be given to selected tracks
75  if (type==1 || type==2) {
77  linkTP.setElement( tmp );
79 
80  if ( type == 1) primaryTrackLinks.push_back( link );
81  else if ( type == 2 ) secondaryTrackLinks.push_back( link );
82  }
83  else {
84  continue;
85  }
86 
87  // How many tracks we are selecting
88  counter++;
89  }
90 
91  ATH_MSG_DEBUG( " Total of selected tracks: "<< counter );
92 
93  selectedTracks->setPrimaryTrackLinks( primaryTrackLinks );
94  selectedTracks->setSecondaryTrackLinks( secondaryTrackLinks );
95  return selectedTracks;
96  }
97 
99  const TLorentzVector &jetMomentum,
100  const xAOD::TrackParticle &track ) const {
101 
102  // Decorators for tracks
103  std::string toolname = this->name();
104  std::string delimiter = "_";
105  std::string::size_type firstDelimiter = toolname.find(delimiter);
106  std::string sub = toolname.substr(0, firstDelimiter);
107  std::string decoratorName = std::string("JetFitter_TrackCompatibility_") + sub;
108  SG::AuxElement::Decorator< float > compatibilityDecorator(decoratorName.c_str());
109 
110  // Apply track filter
111  if ( !m_trkFilter->decision( track, &primaryVertex ) ) {
112  compatibilityDecorator ( track ) = 0.;
113  return -1;
114  }
115 
116  // Recomputing Perigee w.r.t PV
117  Trk::PerigeeSurface mySurface( primaryVertex.position() );
118  std::unique_ptr<const Trk::TrackParameters> myMeasuredPerigee(m_extrapolator->extrapolate(
119  Gaudi::Hive::currentContext(),track.perigeeParameters(),mySurface ));
120 
121  if ( !myMeasuredPerigee) {
122  ATH_MSG_DEBUG( " Extrapolation to primary vertex failed. Skipping track " );
123  compatibilityDecorator ( track ) = 0.;
124  return 0;
125  }
126 
127 
128  // Prepare for using jetFitterUtils (for the computation of the compatibility)
129  // Is this conrvertion really necessary?
130  Trk::RecVertex primaryVertexRecVertex( primaryVertex.position(),
131  primaryVertex.covariancePosition(),
132  primaryVertex.numberDoF(),
133  primaryVertex.chiSquared());
134 
135  Amg::Vector3D jetMomSpatial( jetMomentum.X(),jetMomentum.Y(),jetMomentum.Z() );
136  double compatibilityValue = m_jetFitterUtils->compatibility( *myMeasuredPerigee,primaryVertexRecVertex ).first;
137  compatibilityValue = fabs( compatibilityValue ) * m_jetFitterUtils->get3DLifetimeSignOfTrack( *myMeasuredPerigee,
138  jetMomSpatial,
139  primaryVertexRecVertex );
140 
141  // Decorate
142  ATH_MSG_DEBUG( "compatibilityValue = " << compatibilityValue );
143  compatibilityDecorator ( track ) = compatibilityValue;
144 
145  // Understand if primary or secondary track particle
146  double cutCompatibilityPVforPosTracks = m_cutCompatibilityPrimaryVertexForPositiveLifetimeTracks;
147  double cutCompatibilityPVforNegTracks = m_cutCompatibilityPrimaryVertexForNegativeLifetimeTracks;
148 
150  cutCompatibilityPVforNegTracks = m_cutCompatibilityPrimaryVertexForPositiveLifetimeTracks;
151  cutCompatibilityPVforPosTracks = m_cutCompatibilityPrimaryVertexForNegativeLifetimeTracks;
152  }
153 
154  if ( ( compatibilityValue < 0 &&
155  TMath::Prob( fabs( compatibilityValue ),2 ) < cutCompatibilityPVforNegTracks) ||
156  ( compatibilityValue >= 0 &&
157  TMath::Prob( fabs( compatibilityValue ),2 ) < cutCompatibilityPVforPosTracks ) )
158  return 2;
159  else return 1;
160 
161  }
162 
163 
164 
Trk::SelectedTracksInJet
Definition: SelectedTracksInJet.h:62
InDet::JetFitterTrackSelectorTool::computeTrackCompatibility
int computeTrackCompatibility(const xAOD::Vertex &primaryVertex, const TLorentzVector &jetMomentum, const xAOD::TrackParticle &trk_iter) const
Definition: JetFitterTrackSelectorTool.cxx:98
InDet::JetFitterTrackSelectorTool::m_trkFilter
ToolHandle< Trk::ITrackSelectorTool > m_trkFilter
Definition: JetFitterTrackSelectorTool.h:62
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
Trk::SelectedTracksInJet::setPrimaryTrackLinks
void setPrimaryTrackLinks(std::vector< const ITrackLink * > &primaryTrackLinks)
Set the primary tracks (takes ownership of pointers)
Definition: SelectedTracksInJet.cxx:135
InDet
DUMMY Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
InDet::JetFitterTrackSelectorTool::m_cutCompatibilityPrimaryVertexForPositiveLifetimeTracks
Gaudi::Property< double > m_cutCompatibilityPrimaryVertexForPositiveLifetimeTracks
Definition: JetFitterTrackSelectorTool.h:66
InDet::JetFitterTrackSelectorTool::m_cutCompatibilityPrimaryVertexForNegativeLifetimeTracks
Gaudi::Property< double > m_cutCompatibilityPrimaryVertexForNegativeLifetimeTracks
Definition: JetFitterTrackSelectorTool.h:67
Trk::RecVertex
Trk::RecVertex inherits from Trk::Vertex.
Definition: RecVertex.h:44
python.AthDsoLogger.delimiter
delimiter
Definition: AthDsoLogger.py:71
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
python.TrigInDetConfig.inputTracks
inputTracks
Definition: TrigInDetConfig.py:168
beamspotman.n
n
Definition: beamspotman.py:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
Trk::SelectedTracksInJet::setSecondaryTrackLinks
void setSecondaryTrackLinks(std::vector< const ITrackLink * > &secondaryTracLinks)
Set the secondary tracks (takes ownership of pointers)
Definition: SelectedTracksInJet.cxx:151
Trk::LinkToXAODTrackParticle
Element link to XAOD TrackParticle.
Definition: LinkToXAODTrackParticle.h:33
InDet::JetFitterTrackSelectorTool::m_jetFitterUtils
ToolHandle< InDet::InDetJetFitterUtils > m_jetFitterUtils
Definition: JetFitterTrackSelectorTool.h:61
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
InDet::JetFitterTrackSelectorTool::~JetFitterTrackSelectorTool
~JetFitterTrackSelectorTool()
InDet::JetFitterTrackSelectorTool::initialize
virtual StatusCode initialize() override
Definition: JetFitterTrackSelectorTool.cxx:17
InDet::JetFitterTrackSelectorTool::m_extrapolator
ToolHandle< Trk::IExtrapolator > m_extrapolator
Definition: JetFitterTrackSelectorTool.h:60
python.hypoToolDisplay.toolname
def toolname(tool)
Definition: hypoToolDisplay.py:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
InDet::JetFitterTrackSelectorTool::doTrackSelection
const Trk::SelectedTracksInJet * doTrackSelection(const xAOD::Vertex &primaryVertex, const TLorentzVector &jetMomentum, const std::vector< const xAOD::IParticle * > &inputTracks) const
Definition: JetFitterTrackSelectorTool.cxx:38
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
xAOD::Vertex_v1::numberDoF
float numberDoF() const
Returns the number of degrees of freedom of the vertex fit as float.
JetFitterTrackSelectorTool.h
xAOD::Vertex_v1::chiSquared
float chiSquared() const
Returns the of the vertex fit as float.
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
AthAlgTool
Definition: AthAlgTool.h:26
InDet::JetFitterTrackSelectorTool::JetFitterTrackSelectorTool
JetFitterTrackSelectorTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: JetFitterTrackSelectorTool.cxx:9
test_pyathena.counter
counter
Definition: test_pyathena.py:15
InDet::JetFitterTrackSelectorTool::m_revertFromPositiveToNegativeTags
Gaudi::Property< bool > m_revertFromPositiveToNegativeTags
Definition: JetFitterTrackSelectorTool.h:65