ATLAS Offline Software
BTagTrackAugmenterAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 
9 
10 namespace Analysis {
11 
12  BTagTrackAugmenterAlg::BTagTrackAugmenterAlg( const std::string& name, ISvcLocator* loc )
13  : AthReentrantAlgorithm(name, loc) {}
14 
16  ATH_MSG_INFO( "Inizializing " << name() << "... " );
17 
18  if ( m_track_to_vx.retrieve().isFailure() ) {
19  ATH_MSG_FATAL("Failed to retrieve tool " << m_track_to_vx);
20  return StatusCode::FAILURE;
21  }
22 
23  if ( m_extrapolator.retrieve().isFailure() ) {
24  ATH_MSG_FATAL("Failed to retrieve tool " << m_extrapolator);
25  return StatusCode::FAILURE;
26  }
27 
28  // Initialize Container keys
29  ATH_MSG_DEBUG( "Inizializing containers:" );
32 
34  ATH_CHECK( m_VertexContainerKey.initialize() );
35 
36  // Prepare decorators
37  m_dec_d0 = m_TrackContainerKey.key() + "." + m_prefix.value() + m_dec_d0.key();
38  m_dec_z0 = m_TrackContainerKey.key() + "." + m_prefix.value() + m_dec_z0.key();
41 
44 
46 
47  // Initialize decorators
48  ATH_MSG_DEBUG( "Inizializing decorators:" );
49  ATH_MSG_DEBUG( " ** " << m_dec_d0 );
50  ATH_MSG_DEBUG( " ** " << m_dec_z0 );
51  ATH_MSG_DEBUG( " ** " << m_dec_d0_sigma );
52  ATH_MSG_DEBUG( " ** " << m_dec_z0_sigma );
53  ATH_MSG_DEBUG( " ** " << m_dec_track_pos );
54  ATH_MSG_DEBUG( " ** " << m_dec_track_mom );
55  ATH_MSG_DEBUG( " ** " << m_dec_invalid );
56 
64 
65  return StatusCode::SUCCESS;
66  }
67 
68  StatusCode BTagTrackAugmenterAlg::execute(const EventContext& ctx) const {
69  ATH_MSG_DEBUG( "Executing " << name() << "... " );
70 
71  // ==========================================================================================================================
72  // ** Retrieve Ingredients
73  // ==========================================================================================================================
74 
75  SG::ReadHandle< xAOD::VertexContainer > vertexContainerHandle = SG::makeHandle< xAOD::VertexContainer >( m_VertexContainerKey,ctx );
76  CHECK( vertexContainerHandle.isValid() );
77  const xAOD::VertexContainer *verteces = vertexContainerHandle.get();
78 
79  const xAOD::Vertex* primary = getPrimaryVertex( *verteces );
80  if ( primary == nullptr ) {
81  ATH_MSG_FATAL("No primary vertex found");
82  return StatusCode::FAILURE;
83  }
84 
85  SG::ReadHandle< xAOD::TrackParticleContainer > trackContainerHandle = SG::makeHandle< xAOD::TrackParticleContainer >( m_TrackContainerKey,ctx);
86  CHECK( trackContainerHandle.isValid() );
87  const xAOD::TrackParticleContainer* tracks = trackContainerHandle.get();
88  ATH_MSG_DEBUG( "Retrieved " << tracks->size() << " input tracks..." );
89 
90 
91  // ==========================================================================================================================
92  // ** Make Decorators (these are outputs)
93  // ==========================================================================================================================
94 
99 
102 
104  m_dec_invalid, ctx);
105 
106  // ==========================================================================================================================
107  // ** Computation
108  // ==========================================================================================================================
109 
110  Trk::PerigeeSurface primary_surface( primary->position() );
111 
112  // now decorate the tracks
113  for (const xAOD::TrackParticle *track: *tracks) {
114  std::unique_ptr< const Trk::ImpactParametersAndSigma > ip( m_track_to_vx->estimate( track, primary ) );
115  if ( ip ) {
116  decor_d0(*track) = ip->IPd0;
117  decor_z0(*track) = ip->IPz0SinTheta;
118  decor_d0_sigma(*track) = ip->sigmad0;
119  decor_z0_sigma(*track) = ip->sigmaz0SinTheta;
120  ATH_MSG_DEBUG( " d0= " << ip->IPd0 <<
121  " z0SinTheta= " << ip->IPz0SinTheta <<
122  " sigmad0= " << ip->sigmad0 <<
123  " sigmaz0SinTheta= " << ip->sigmaz0SinTheta );
124  } else {
125  ATH_MSG_WARNING( "failed to estimate track impact parameter, using dummy values" );
126  decor_d0(*track) = NAN;
127  decor_z0(*track) = NAN;
128  decor_d0_sigma(*track) = NAN;
129  decor_z0_sigma(*track) = NAN;
130  }
131 
132  // some other parameters we have go get directly from the
133  // extrapolator. This is more or less copied from:
134  // https://goo.gl/iWLv5T
135  std::unique_ptr< const Trk::TrackParameters > extrap_pars( m_extrapolator->extrapolate(ctx,
136  track->perigeeParameters(),
137  primary_surface ) );
138  if ( extrap_pars ) {
139  const Amg::Vector3D& track_pos = extrap_pars->position();
140  const Amg::Vector3D& vertex_pos = primary->position();
141 
142  const Amg::Vector3D position = track_pos - vertex_pos;
143  const Amg::Vector3D momentum = extrap_pars->momentum();
144 
145  //Test output for cross checking output with stored values
146  ATH_MSG_DEBUG( "vertex_pos (x,y,z)= (" << vertex_pos.x() << ", " << vertex_pos.y() << ", " << vertex_pos.z() << ")");
147  ATH_MSG_DEBUG( "track_pos (x,y,z)= (" << track_pos.x() << ", " << track_pos.y() << ", " << track_pos.z() << ")");
148  ATH_MSG_DEBUG( "track_displacement (x,y,z)= (" << position.x() << ", " << position.y() << ", " << position.z() << ")");
149  ATH_MSG_DEBUG( "track_momentum (x,y,z)= (" << momentum.x() << ", " << momentum.y() << ", " << momentum.z() << ")");
150 
151  std::vector< float > out_vec_pos( position.data(), position.data() + position.size() );
152  std::vector< float > out_vec_mom( momentum.data(), momentum.data() + momentum.size() );
153 
154  decor_track_pos (*track) = out_vec_pos;
155  decor_track_mom (*track) = out_vec_mom;
156  } else {
157  ATH_MSG_WARNING( "failed to extrapolate track coordinates at primary vertex, using dummy values");
158 
159  std::vector< float > out_vec_pos = {NAN,NAN,NAN};
160  std::vector< float > out_vec_mom = {NAN,NAN,NAN};
161 
162  decor_track_pos (*track) = out_vec_pos;
163  decor_track_mom (*track) = out_vec_mom;
164  }
165  bool invalid = !(ip && extrap_pars);
166  decor_invalid(*track) = invalid ? 1 : 0;
167  }
168 
169  return StatusCode::SUCCESS;
170  }
171 
173  if ( vertexCollection.empty() ) {
174  ATH_MSG_DEBUG( "Input vertex collection has size 0!" );
175  return nullptr;
176  }
177 
178  for ( const xAOD::Vertex *vertex : vertexCollection ) {
179  if ( vertex->vertexType() == xAOD::VxType::PriVtx ) {
180  return vertex;
181  }
182  }
183 
184  // this is taken from BTagTool, should be the beam spot if nothing
185  // else exists.
186  return vertexCollection.front();
187  }
188 
189 }
190 
191 
Analysis::BTagTrackAugmenterAlg::m_dec_invalid
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_invalid
Definition: BTagTrackAugmenterAlg.h:51
Analysis::BTagTrackAugmenterAlg::execute
StatusCode execute(const EventContext &ctx) const override final
Definition: BTagTrackAugmenterAlg.cxx:68
Analysis::BTagTrackAugmenterAlg::m_dec_z0
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_z0
Definition: BTagTrackAugmenterAlg.h:44
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PerigeeSurface.h
Analysis::BTagTrackAugmenterAlg::m_prefix
Gaudi::Property< std::string > m_prefix
Definition: BTagTrackAugmenterAlg.h:41
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
Trk::ParametersBase::position
const Amg::Vector3D & position() const
Access method for the position.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Analysis::BTagTrackAugmenterAlg::m_VertexContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_VertexContainerKey
Definition: BTagTrackAugmenterAlg.h:36
Analysis::BTagTrackAugmenterAlg::m_TrackContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackContainerKey
Definition: BTagTrackAugmenterAlg.h:35
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
Analysis::BTagTrackAugmenterAlg::BTagTrackAugmenterAlg
BTagTrackAugmenterAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: BTagTrackAugmenterAlg.cxx:12
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
Analysis::BTagTrackAugmenterAlg::m_dec_track_pos
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_track_pos
Definition: BTagTrackAugmenterAlg.h:48
StateLessPT_NewConfig.primary
primary
Definition: StateLessPT_NewConfig.py:228
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Analysis::BTagTrackAugmenterAlg::m_dec_track_mom
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_track_mom
Definition: BTagTrackAugmenterAlg.h:49
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
Analysis::BTagTrackAugmenterAlg::m_dec_d0
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_d0
Definition: BTagTrackAugmenterAlg.h:43
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
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Analysis::BTagTrackAugmenterAlg::m_dec_d0_sigma
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_d0_sigma
Definition: BTagTrackAugmenterAlg.h:45
Analysis
The namespace of all packages in PhysicsAnalysis/JetTagging.
Definition: BTaggingCnvAlg.h:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
BTagTrackAugmenterAlg.h
Analysis::BTagTrackAugmenterAlg::m_track_to_vx
ToolHandle< Trk::ITrackToVertexIPEstimator > m_track_to_vx
Definition: BTagTrackAugmenterAlg.h:31
Trk::ParametersBase::momentum
const Amg::Vector3D & momentum() const
Access method for the momentum.
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Analysis::BTagTrackAugmenterAlg::getPrimaryVertex
const xAOD::Vertex * getPrimaryVertex(const xAOD::VertexContainer &) const
Definition: BTagTrackAugmenterAlg.cxx:172
Analysis::BTagTrackAugmenterAlg::m_extrapolator
ToolHandle< Trk::IExtrapolator > m_extrapolator
Definition: BTagTrackAugmenterAlg.h:32
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
Analysis::BTagTrackAugmenterAlg::initialize
StatusCode initialize() override final
Definition: BTagTrackAugmenterAlg.cxx:15
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Analysis::BTagTrackAugmenterAlg::m_dec_z0_sigma
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_dec_z0_sigma
Definition: BTagTrackAugmenterAlg.h:46
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.