ATLAS Offline Software
Loading...
Searching...
No Matches
Vertex_v1.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6// System include(s):
7#include <cmath>
8
9// EDM include(s):
12
13// Local include(s):
16
17namespace xAOD {
18
20 : SG::AuxElement(),
21 m_position(),
22 m_covariance() {
23
24 }
25
27 : SG::AuxElement(other),
30 //copy aux store content (only the stuffs already loaded in memory!)
31 this->makePrivateStore( other );
32 }
33
35
36 // Check if anything needs to be done:
37 if( this == &tp ) {
38 return *this;
39 }
40
41 // If the object doesn't have an auxiliary store yet, make a private
42 // one for it:
43 if( ( ! hasStore() ) && ( ! container() ) ) {
44 makePrivateStore();
45 }
46
47 // copy the cache
50
51 // Now let the base class copy the auxiliary contents:
52 SG::AuxElement::operator=( tp );
53
54 // Return the object:
55 return *this;
56 }
57
58 Type::ObjectType Vertex_v1::type() const {
59
60 return Type::Vertex;
61 }
62
64 //
65 // Implementation of the primitive accessors
66
70 AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( Vertex_v1, uint8_t, hasValidTime, setHasValidTime )
71
73 covariance, setCovariance )
74
75 float Vertex_v1::time() const {
76 static const SG::AuxElement::Accessor< uint8_t > acc("hasValidTime");
77 if( !acc.isAvailable( *this) || !static_cast<bool>(hasValidTime()) ) throw std::runtime_error( "Unavailable Vertex time requested" );
78 static const SG::AuxElement::Accessor< float > accTime("time");
79 return accTime( *this );
80 }
81
82 float Vertex_v1::timeResolution() const {
83 static const SG::AuxElement::Accessor< uint8_t > acc("hasValidTime");
84 if( !acc.isAvailable( *this) || !static_cast<bool>(hasValidTime()) ) throw std::runtime_error( "Unavailable Vertex timeResolution requested" );
85 static const SG::AuxElement::Accessor< float > accTimeRes("timeResolution");
86 return accTimeRes( *this );
87 }
88
89 void Vertex_v1::setTime(float time) {
90 static const SG::AuxElement::Accessor< float > acc("time");
91 acc( *this ) = time;
92 }
93
94 void Vertex_v1::setTimeResolution(float timeRes) {
95 static const SG::AuxElement::Accessor< float > acc("timeResolution");
96 acc( *this ) = timeRes;
97 }
98
99 //
101
103 // Implementation of the Eigen functions
104 //
105
107
108 // Cache the position if necessary:
109 if( ! m_position.isValid() ) {
110 Amg::Vector3D tmpPosition;
111 tmpPosition( 0 ) = x();
112 tmpPosition( 1 ) = y();
113 tmpPosition( 2 ) = z();
114 m_position.set(tmpPosition);
115 }
116
117 // Return the object:
118 return *(m_position.ptr());
119 }
120
122
123 // Set the primitive variables using the simple functions:
124 setX( position( 0 ) );
125 setY( position( 1 ) );
126 setZ( position( 2 ) );
127 // Reset the cache
128 // This will enforce float precision level on the values of
129 // m_position. The effect of this float conversion has been
130 // discussed in ATLASRECTS-7671
131 m_position.reset();
132 }
133
134 const AmgSymMatrix(3)& Vertex_v1::covariancePosition() const {
135
136 // Cache the covariance matrix if necessary:
137 if( ! m_covariance.isValid() ) {
138 // The matrix is now cached:
139 AmgSymMatrix(3) tmpCovariance;
140 Amg::expand(covariance().begin(),covariance().end(),tmpCovariance);
141 m_covariance.set(tmpCovariance);
142 }
143 // Return the cached object:
144 return *(m_covariance.ptr());
145 }
146
147 void Vertex_v1::setCovariancePosition( const AmgSymMatrix(3)& cov ) {
148
149 // The to-be persistent variable:
150 std::vector< float > vec;
151 Amg::compress(cov,vec);
152
153 // Set the persistent variable:
155 // This will enforce float precision level on the values of
156 // m_covariance. The effect of this float conversion has been
157 // discussed in ATLASRECTS-7671
159 }
160
161 //
163
165 //
166 // Implementation of the fit quality functions
167 //
168
169 AUXSTORE_PRIMITIVE_GETTER( Vertex_v1, float, chiSquared )
170 AUXSTORE_PRIMITIVE_GETTER( Vertex_v1, float, numberDoF )
171
173
174 static const Accessor< float > acc1( "chiSquared" );
175 static const Accessor< float > acc2( "numberDoF" );
176 acc1( *this ) = chiSquared;
177 acc2( *this ) = numberDoF;
178
179 return;
180 }
181
182 //
184
186 vertexType )
188 vertexType, setVertexType )
189
190#ifndef XAOD_ANALYSIS
192 static const SG::AuxElement::Accessor< std::vector< Trk::VxTrackAtVertex > >
193 vxVertAcc( "vxTrackAtVertex" );
194
203 std::vector< Trk::VxTrackAtVertex >& Vertex_v1::vxTrackAtVertex() {
204
205 return vxVertAcc( *this );
206 }
207
219 const std::vector< Trk::VxTrackAtVertex >&
221
222 return vxVertAcc( *this );
223 }
224
232
233 return vxVertAcc.isAvailable( *this );
234 }
235#endif // not XAOD_ANALYSIS
236
238 //
239 // Implementation of the track particle handling functions
240 //
241
243 static const SG::AuxElement::Accessor< Vertex_v1::TrackParticleLinks_t >
244 trackAcc( "trackParticleLinks" );
246 static const SG::AuxElement::Accessor< std::vector< float > >
247 weightTrackAcc( "trackWeights" );
248
250 static const SG::AuxElement::Accessor< Vertex_v1::NeutralParticleLinks_t >
251 neutralAcc( "neutralParticleLinks" );
253 static const SG::AuxElement::Accessor< std::vector< float > >
254 weightNeutralAcc( "neutralWeights" );
255
258 trackParticleLinks,
259 setTrackParticleLinks )
260 AUXSTORE_OBJECT_SETTER_AND_GETTER( Vertex_v1, std::vector< float >,
261 trackWeights, setTrackWeights )
262
264 Vertex_v1::NeutralParticleLinks_t,
265 neutralParticleLinks,
266 setNeutralParticleLinks )
268 neutralWeights, setNeutralWeights )
269
270
272
273 if( ! trackAcc.isAvailable( *this ) ) {
274 return nullptr;
275 }
276 if( ( trackAcc( *this ).size() <= i ) ||
277 ( ! trackAcc( *this )[ i ].isValid() ) ) {
278 return nullptr;
279 }
280
281 return ( *( trackAcc( *this )[ i ] ) );
282 }
283
284 float Vertex_v1::trackWeight( size_t i ) const {
285
286 if( weightTrackAcc( *this ).size() <= i ) {
287 return -1.0;
288 }
289 return weightTrackAcc( *this )[ i ];
290 }
291
293
294 if( ! trackAcc.isAvailable( *this ) ) {
295 return 0;
296 }
297
298 return trackAcc( *this ).size();
299 }
300
301
303
304 if( ! neutralAcc.isAvailable( *this ) ) {
305 return nullptr;
306 }
307 if( ( neutralAcc( *this ).size() <= i ) ||
308 ( ! neutralAcc( *this )[ i ].isValid() ) ) {
309 return nullptr;
310 }
311
312 return ( *( neutralAcc( *this )[ i ] ) );
313 }
314
315 float Vertex_v1::neutralWeight( size_t i ) const {
316
317 if( weightNeutralAcc( *this ).size() <= i ) {
318 return -1.0;
319 }
320 return weightNeutralAcc( *this )[ i ];
321 }
322
324
325 if( ! neutralAcc.isAvailable( *this ) ) {
326 return 0;
327 }
328
329 return neutralAcc( *this ).size();
330 }
331
332
333
334
335 void
337 float weight ) {
338
339 trackAcc( *this ).push_back( tr );
340 weightTrackAcc( *this ).push_back( weight );
341 return;
342 }
343
344 void
346 float weight ) {
347
348 neutralAcc( *this ).push_back( tr );
349 weightNeutralAcc( *this ).push_back( weight );
350 return;
351 }
352
354
355 trackAcc( *this ).clear();
356 weightTrackAcc( *this ).clear();
357 return;
358 }
359
361
362 neutralAcc( *this ).clear();
363 weightNeutralAcc( *this ).clear();
364 return;
365 }
366
367 /*
368 * Reset the cache
369 */
371 m_position.reset();
372 m_covariance.reset();
373 return;
374 }
375
376} // namespace xAOD
#define AUXSTORE_PRIMITIVE_GETTER_WITH_CAST(CL, PERSTYPE, TRANSTYPE, NAME)
Macro creating a getter function with a type conversion.
#define AUXSTORE_PRIMITIVE_GETTER(CL, TYPE, NAME)
Macro creating the reader function for a primitive auxiliary property.
#define AUXSTORE_PRIMITIVE_SETTER_AND_GETTER(CL, TYPE, NAME, SETTER)
Macro creating the accessors of primitive auxiliary properties.
#define AUXSTORE_OBJECT_SETTER_AND_GETTER(CL, TYPE, NAME, SETTER)
Macro creating the accessors of complex auxiliary properties.
std::vector< size_t > vec
#define AmgSymMatrix(dim)
#define y
#define x
#define z
void reset()
Reset the value to invalid.
const T * ptr() const
Return a pointer to the cached value.
void set(const T &val) const
Set the value, assuming it is currently invalid.
bool isValid() const
Test to see if the value is valid.
Class describing a Vertex.
Definition Vertex_v1.h:42
void clearNeutrals()
Remove all neutrals from the vertex.
float z() const
Returns the z position.
size_t nNeutralParticles() const
Get the number of neutrals associated with this vertex.
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
void clearTracks()
Remove all tracks from the vertex.
const NeutralParticle * neutralParticle(size_t i) const
Get the pointer to a given neutral that was used in vertex reco.
CxxUtils::CachedValue< Amg::Vector3D > m_position
Cached position of the vertex.
Definition Vertex_v1.h:191
void setCovariancePosition(const AmgSymMatrix(3)&covariancePosition)
Sets the vertex covariance matrix.
Vertex_v1()
Default constructor.
Definition Vertex_v1.cxx:19
Vertex_v1 & operator=(const Vertex_v1 &tp)
Assignment operator. This can involve creating and copying an Auxilary store, and so should be used s...
Definition Vertex_v1.cxx:34
float time() const
Returns the time.
void addTrackAtVertex(const ElementLink< TrackParticleContainer > &tr, float weight=1.0)
Add a new track to the vertex.
CxxUtils::CachedValue< AmgSymMatrix(3)> m_covariance
Cached covariance of the vertex.
Definition Vertex_v1.h:193
void setZ(float value)
Sets the z position.
void addNeutralAtVertex(const ElementLink< NeutralParticleContainer > &tr, float weight=1.0)
Add a new neutral to the vertex.
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
std::vector< ElementLink< xAOD::TrackParticleContainer > > TrackParticleLinks_t
Type for the associated track particles.
Definition Vertex_v1.h:128
void resetCache()
Reset the internal cache of the object.
void setX(float value)
Sets the x position.
float neutralWeight(size_t i) const
Get the weight of a given neutral in the vertex reconstruction.
void setY(float value)
Sets the y position.
Type::ObjectType type() const
A little helper function for identifying the type in template code.
Definition Vertex_v1.cxx:58
float y() const
Returns the y position.
void setCovariance(const std::vector< float > &value)
Sets the covariance matrix as a simple vector of values.
float numberDoF() const
Returns the number of degrees of freedom of the vertex fit as float.
void setTimeResolution(float value)
Sets the time resolution.
Definition Vertex_v1.cxx:94
void setPosition(const Amg::Vector3D &position)
Sets the 3-position.
bool vxTrackAtVertexAvailable() const
Check if VxTrackAtVertices are attached to the object.
float chiSquared() const
Returns the of the vertex fit as float.
std::vector< Trk::VxTrackAtVertex > & vxTrackAtVertex()
Non-const access to the VxTrackAtVertex vector.
void setTime(float value)
Sets the time.
float timeResolution() const
Returns the time resolution.
void setFitQuality(float chiSquared, float numberDoF)
Set the 'Fit Quality' information.
const Amg::Vector3D & position() const
Returns the 3-pos.
uint8_t hasValidTime() const
Returns whether or not the vertex has a valid time.
float x() const
Returns the x position.
const std::vector< float > & covariance() const
Returns the covariance matrix as a simple vector of values.
float trackWeight(size_t i) const
Get the weight of a given track in the vertex reconstruction.
void compress(const AmgSymMatrix(N) &covMatrix, std::vector< float > &vec)
void expand(std::vector< float >::const_iterator it, std::vector< float >::const_iterator, AmgSymMatrix(N) &covMatrix)
Eigen::Matrix< double, 3, 1 > Vector3D
Forward declaration.
STL namespace.
A convenience namespace to make the client code easier to understand.
VertexType
Vertex types.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
setStrategy setMatchFlag ElementLink< TrackParticleContainer >
AUXSTORE_PRIMITIVE_SETTER_WITH_CAST(CompositeParticle_v1, float, double, px, setPx) AUXSTORE_PRIMITIVE_SETTER_WITH_CAST(CompositeParticle_v1
setTrackWeights neutralWeights
NeutralParticle_v1 NeutralParticle
Reference the current persistent version:
static const SG::AuxElement::Accessor< std::vector< float > > weightNeutralAcc("neutralWeights")
Accessor for the neutral weights.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
static const SG::AuxElement::Accessor< Vertex_v1::TrackParticleLinks_t > trackAcc("trackParticleLinks")
Accessor for the track links.
static const SG::AuxElement::Accessor< std::vector< float > > weightTrackAcc("trackWeights")
Accessor for the track weights.
static const SG::AuxElement::Accessor< Vertex_v1::NeutralParticleLinks_t > neutralAcc("neutralParticleLinks")
Accessor for the neutral links.
AUXSTORE_OBJECT_SETTER_AND_GETTER(CaloRings_v1, RingSetLinks, ringSetLinks, setRingSetLinks) unsigned CaloRings_v1
static setVertexType const SG::AuxElement::Accessor< std::vector< Trk::VxTrackAtVertex > > vxVertAcc("vxTrackAtVertex")
Helper object for implementing the vxTrackAtVertex functions.
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.