diff --git a/Event/xAOD/xAODTracking/Root/Vertex_v1.cxx b/Event/xAOD/xAODTracking/Root/Vertex_v1.cxx index 3ea2499b42014607cadc9315b55d647b548889f0..60c7cf33078923ae5453470a50f1754c67f5a4e6 100644 --- a/Event/xAOD/xAODTracking/Root/Vertex_v1.cxx +++ b/Event/xAOD/xAODTracking/Root/Vertex_v1.cxx @@ -19,18 +19,15 @@ namespace xAOD { Vertex_v1::Vertex_v1() : SG::AuxElement(), - m_position(), m_positionCached( false ), - m_covariance(), m_covarianceCached( false ) { + m_position(), + m_covariance() { } Vertex_v1::Vertex_v1( const Vertex_v1& other ) : SG::AuxElement(), m_position( other.m_position ), - m_positionCached( other.m_positionCached ), - m_covariance( other.m_covariance ), - m_covarianceCached( other.m_covarianceCached ) { - + m_covariance( other.m_covariance ){ //copy aux store content (only the stuffs already loaded in memory!) this->makePrivateStore( other ); } @@ -84,15 +81,16 @@ namespace xAOD { const Amg::Vector3D& Vertex_v1::position() const { // Cache the position if necessary: - if( ! m_positionCached ) { - m_position( 0 ) = x(); - m_position( 1 ) = y(); - m_position( 2 ) = z(); - m_positionCached = true; + if( ! m_position.isValid() ) { + Amg::Vector3D tmpPosition; + tmpPosition( 0 ) = x(); + tmpPosition( 1 ) = y(); + tmpPosition( 2 ) = z(); + m_position.set(tmpPosition); } // Return the object: - return m_position; + return *(m_position.ptr()); } void Vertex_v1::setPosition( const Amg::Vector3D& position ) { @@ -101,25 +99,22 @@ namespace xAOD { setX( position( 0 ) ); setY( position( 1 ) ); setZ( position( 2 ) ); - - // Update the cache: - m_position = position; - m_positionCached = true; - + // Reset the cache + m_position.reset(); return; } const AmgSymMatrix(3)& Vertex_v1::covariancePosition() const { // Cache the covariance matrix if necessary: - if( ! m_covarianceCached ) { + if( ! m_covariance.isValid() ) { // The matrix is now cached: - Amg::expand(covariance().begin(),covariance().end(),m_covariance); - m_covarianceCached = true; + AmgSymMatrix(3) tmpCovariance; + Amg::expand(covariance().begin(),covariance().end(),tmpCovariance); + m_covariance.set(tmpCovariance); } - // Return the cached object: - return m_covariance; + return *(m_covariance.ptr()); } void Vertex_v1::setCovariancePosition( const AmgSymMatrix(3)& cov ) { @@ -130,11 +125,7 @@ namespace xAOD { // Set the persistent variable: setCovariance( vec ); - - // Cache the variable: - m_covariance = cov; - m_covarianceCached = true; - + m_covariance.reset(); return; } @@ -344,17 +335,12 @@ namespace xAOD { return; } - // - ///////////////////////////////////////////////////////////////////////////// - - /// This function is used by ROOT to reset the object after a new object - /// was read into an existing memory location. - /// + /* + * Reset the cache + */ void Vertex_v1::resetCache() { - - m_positionCached = false; - m_covarianceCached = false; - + m_position.reset(); + m_covariance.reset(); return; } diff --git a/Event/xAOD/xAODTracking/xAODTracking/selection.xml b/Event/xAOD/xAODTracking/xAODTracking/selection.xml index c4515742823ebc694d88ca1a247a7f34a7ba6183..71da7653240461ecef267d53c3c91e4df05acc10 100644 --- a/Event/xAOD/xAODTracking/xAODTracking/selection.xml +++ b/Event/xAOD/xAODTracking/xAODTracking/selection.xml @@ -4,9 +4,7 @@ <!-- Vertex_v1 dictionaries: --> <class name="xAOD::Vertex_v1" > <field name="m_position" transient="true" /> - <field name="m_positionCached" transient="true" /> <field name="m_covariance" transient="true" /> - <field name="m_covarianceCached" transient="true" /> </class> <read sourceClass="xAOD::Vertex_v1" version="[1-]" targetClass="xAOD::Vertex_v1" source="" target="" > diff --git a/Event/xAOD/xAODTracking/xAODTracking/versions/Vertex_v1.h b/Event/xAOD/xAODTracking/xAODTracking/versions/Vertex_v1.h index 07d6e57721e20e342c5b318c08342e94117a2517..d2886bf6975fe87e062cffb6dab00e82b7f518e6 100644 --- a/Event/xAOD/xAODTracking/xAODTracking/versions/Vertex_v1.h +++ b/Event/xAOD/xAODTracking/xAODTracking/versions/Vertex_v1.h @@ -1,197 +1,196 @@ -// Dear emacs, this is -*- c++ -*- +// Dear emacs, this is -*- c++ -*- /* Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ -// $Id: Vertex_v1.h 575751 2013-12-16 16:45:36Z krasznaa $ -#ifndef XAODTRACKING_VERSIONS_VERTEX_V1_H -#define XAODTRACKING_VERSIONS_VERTEX_V1_H - -// System include(s): -#include <vector> - -// Core include(s): -#include "AthContainers/AuxElement.h" -#include "AthLinks/ElementLink.h" - -// EDM include(s): -#include "EventPrimitives/EventPrimitives.h" -#include "GeoPrimitives/GeoPrimitives.h" -#ifndef XAOD_STANDALONE -#ifndef XAOD_MANACORE -# include "VxVertex/VxTrackAtVertex.h" -#endif // not XAOD_MANACORE -#endif // not XAOD_STANDALONE - -// xAOD include(s): -#include "xAODTracking/TrackingPrimitives.h" -#include "xAODTracking/TrackParticleContainerFwd.h" -#include "xAODTracking/NeutralParticleContainer.h" -#include "xAODBase/ObjectType.h" - -// Local include(s): -#include "xAODTracking/TrackingPrimitives.h" - -namespace xAOD { - - /// Class describing a Vertex. - /// - /// @author Kirill Prokofiev <Kirill.Prokofev@cern.ch> - /// @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch> - /// @author Ruslan Mashinistov <Ruslan.Mashinistov@cern.ch> - /// @nosubgrouping - /// - class Vertex_v1 : public SG::AuxElement { - - public: - /// Default constructor - Vertex_v1(); - - /// Copy constructor - Vertex_v1(const Vertex_v1& other); - - /// Assignment operator. This can involve creating and copying an Auxilary store, and so should be used sparingly. - Vertex_v1& operator=(const Vertex_v1& tp ); - - /// A little helper function for identifying the type in template code - Type::ObjectType type() const; - - /// Returns the x position - float x() const; - /// Sets the x position - void setX( float value ); - /// Returns the y position - float y() const; - /// Sets the y position - void setY( float value ); - /// Returns the z position - float z() const; - /// Sets the z position - void setZ( float value ); - - /// Returns the covariance matrix as a simple vector of values - const std::vector< float >& covariance() const; - /// Sets the covariance matrix as a simple vector of values - void setCovariance( const std::vector< float >& value ); - - /// Returns the 3-pos - const Amg::Vector3D& position() const; - /// Sets the 3-position - void setPosition( const Amg::Vector3D& position ); - - /// Returns the vertex covariance matrix - const AmgSymMatrix(3)& covariancePosition() const; - /// Sets the vertex covariance matrix - void setCovariancePosition( const AmgSymMatrix(3)& covariancePosition ); - - /// @name Fit quality functions - /// @{ - - /// Returns the @f$ \chi^2 @f$ of the vertex fit as float. - float chiSquared() const; - /// Returns the number of degrees of freedom of the vertex fit as float. - float numberDoF() const; - /// Set the 'Fit Quality' information. - void setFitQuality( float chiSquared, float numberDoF ); - - /// @} - - /// The type of the vertex - VxType::VertexType vertexType() const; - /// Set the type of the vertex - void setVertexType( VxType::VertexType vType ); - -#if ( ! defined(XAOD_STANDALONE) ) && ( ! defined(XAOD_MANACORE) ) - /// Non-const access to the VxTrackAtVertex vector - std::vector< Trk::VxTrackAtVertex >& vxTrackAtVertex(); - /// Const access to the vector of tracks fitted to the vertex (may not exist!) - const std::vector< Trk::VxTrackAtVertex >& vxTrackAtVertex() const; - /// Check if VxTrackAtVertices are attached to the object - bool vxTrackAtVertexAvailable() const; -#endif // not XAOD_STANDALONE and not XAOD_MANACORE - - /// @name Track particle contents operations - /// @{ - - /// Type for the associated track particles - typedef std::vector< ElementLink< xAOD::TrackParticleContainer > > - TrackParticleLinks_t; - /// Get all the particles associated with the vertex - const TrackParticleLinks_t& trackParticleLinks() const; - /// Set all track particle links at once - void setTrackParticleLinks( const TrackParticleLinks_t& trackParticles ); - - /// Get all the track weights - const std::vector< float >& trackWeights() const; - /// Set all the track weights - void setTrackWeights( const std::vector< float >& weights ); - - - /// Type for the associated neutral particles - typedef std::vector< ElementLink< xAOD::NeutralParticleContainer > > NeutralParticleLinks_t; - /// Get all the particles associated with the vertex - const NeutralParticleLinks_t& neutralParticleLinks() const; - /// Set all neutral particle links at once - void setNeutralParticleLinks( const NeutralParticleLinks_t& neutralParticles ); - - /// Get all the neutral weights - const std::vector< float >& neutralWeights() const; - /// Set all the neutral weights - void setNeutralWeights( const std::vector< float >& weights ); - - - /// Get the pointer to a given track that was used in vertex reco. - const TrackParticle* trackParticle( size_t i ) const; - /// Get the weight of a given track in the vertex reconstruction - float trackWeight( size_t i ) const; - /// Get the number of tracks associated with this vertex - size_t nTrackParticles() const; - - - /// Get the pointer to a given neutral that was used in vertex reco. - const NeutralParticle* neutralParticle( size_t i ) const; - /// Get the weight of a given neutral in the vertex reconstruction - float neutralWeight( size_t i ) const; - /// Get the number of neutrals associated with this vertex - size_t nNeutralParticles() const; - - - /// Add a new track to the vertex - void addTrackAtVertex( const ElementLink< TrackParticleContainer >& tr, - float weight = 1.0 ); - - /// Add a new neutral to the vertex - void addNeutralAtVertex( const ElementLink< NeutralParticleContainer >& tr, - float weight = 1.0 ); - - /// Remove all tracks from the vertex - void clearTracks(); - - /// Remove all neutrals from the vertex - void clearNeutrals(); - - - /// @} - - /// Reset the internal cache of the object - void resetCache(); - - private: - /// Cached position of the vertex - mutable Amg::Vector3D m_position; - /// Cache status of the position object - mutable bool m_positionCached; - /// Cached covariance of the vertex - mutable AmgSymMatrix(3) m_covariance; - /// Cache status of the covariance object - mutable bool m_covarianceCached; - - }; // end of the Vertex_v1 class definitions - -} // end of the xAOD namespace - -#include "xAODCore/BaseInfo.h" -SG_BASE (xAOD::Vertex_v1, SG::AuxElement); - -#endif // XAODTRACKING_VERSIONS_VERTEX_V1_H +// $Id: Vertex_v1.h 575751 2013-12-16 16:45:36Z krasznaa $ +#ifndef XAODTRACKING_VERSIONS_VERTEX_V1_H +#define XAODTRACKING_VERSIONS_VERTEX_V1_H + +// System include(s): +#include <vector> + +// Core include(s): +#include "AthContainers/AuxElement.h" +#include "AthLinks/ElementLink.h" + +// EDM include(s): +#include "EventPrimitives/EventPrimitives.h" +#include "GeoPrimitives/GeoPrimitives.h" +#ifndef XAOD_STANDALONE +#ifndef XAOD_MANACORE +# include "VxVertex/VxTrackAtVertex.h" +#endif // not XAOD_MANACORE +#endif // not XAOD_STANDALONE + +// xAOD include(s): +#include "xAODTracking/TrackingPrimitives.h" +#include "xAODTracking/TrackParticleContainerFwd.h" +#include "xAODTracking/NeutralParticleContainer.h" +#include "xAODBase/ObjectType.h" + +// Local include(s): +#include "xAODTracking/TrackingPrimitives.h" + +//MT CachedValue +#include "CxxUtils/CachedValue.h" + +namespace xAOD { + + /// Class describing a Vertex. + /// + /// @author Kirill Prokofiev <Kirill.Prokofev@cern.ch> + /// @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch> + /// @author Ruslan Mashinistov <Ruslan.Mashinistov@cern.ch> + /// @nosubgrouping + /// + class Vertex_v1 : public SG::AuxElement { + + public: + /// Default constructor + Vertex_v1(); + + /// Copy constructor + Vertex_v1(const Vertex_v1& other); + + /// Assignment operator. This can involve creating and copying an Auxilary store, and so should be used sparingly. + Vertex_v1& operator=(const Vertex_v1& tp ); + + /// A little helper function for identifying the type in template code + Type::ObjectType type() const; + + /// Returns the x position + float x() const; + /// Sets the x position + void setX( float value ); + /// Returns the y position + float y() const; + /// Sets the y position + void setY( float value ); + /// Returns the z position + float z() const; + /// Sets the z position + void setZ( float value ); + + /// Returns the covariance matrix as a simple vector of values + const std::vector< float >& covariance() const; + /// Sets the covariance matrix as a simple vector of values + void setCovariance( const std::vector< float >& value ); + + /// Returns the 3-pos + const Amg::Vector3D& position() const; + /// Sets the 3-position + void setPosition( const Amg::Vector3D& position ); + + /// Returns the vertex covariance matrix + const AmgSymMatrix(3)& covariancePosition() const; + /// Sets the vertex covariance matrix + void setCovariancePosition( const AmgSymMatrix(3)& covariancePosition ); + + /// @name Fit quality functions + /// @{ + + /// Returns the @f$ \chi^2 @f$ of the vertex fit as float. + float chiSquared() const; + /// Returns the number of degrees of freedom of the vertex fit as float. + float numberDoF() const; + /// Set the 'Fit Quality' information. + void setFitQuality( float chiSquared, float numberDoF ); + + /// @} + + /// The type of the vertex + VxType::VertexType vertexType() const; + /// Set the type of the vertex + void setVertexType( VxType::VertexType vType ); + +#if ( ! defined(XAOD_STANDALONE) ) && ( ! defined(XAOD_MANACORE) ) + /// Non-const access to the VxTrackAtVertex vector + std::vector< Trk::VxTrackAtVertex >& vxTrackAtVertex(); + /// Const access to the vector of tracks fitted to the vertex (may not exist!) + const std::vector< Trk::VxTrackAtVertex >& vxTrackAtVertex() const; + /// Check if VxTrackAtVertices are attached to the object + bool vxTrackAtVertexAvailable() const; +#endif // not XAOD_STANDALONE and not XAOD_MANACORE + + /// @name Track particle contents operations + /// @{ + + /// Type for the associated track particles + typedef std::vector< ElementLink< xAOD::TrackParticleContainer > > + TrackParticleLinks_t; + /// Get all the particles associated with the vertex + const TrackParticleLinks_t& trackParticleLinks() const; + /// Set all track particle links at once + void setTrackParticleLinks( const TrackParticleLinks_t& trackParticles ); + + /// Get all the track weights + const std::vector< float >& trackWeights() const; + /// Set all the track weights + void setTrackWeights( const std::vector< float >& weights ); + + + /// Type for the associated neutral particles + typedef std::vector< ElementLink< xAOD::NeutralParticleContainer > > NeutralParticleLinks_t; + /// Get all the particles associated with the vertex + const NeutralParticleLinks_t& neutralParticleLinks() const; + /// Set all neutral particle links at once + void setNeutralParticleLinks( const NeutralParticleLinks_t& neutralParticles ); + + /// Get all the neutral weights + const std::vector< float >& neutralWeights() const; + /// Set all the neutral weights + void setNeutralWeights( const std::vector< float >& weights ); + + + /// Get the pointer to a given track that was used in vertex reco. + const TrackParticle* trackParticle( size_t i ) const; + /// Get the weight of a given track in the vertex reconstruction + float trackWeight( size_t i ) const; + /// Get the number of tracks associated with this vertex + size_t nTrackParticles() const; + + + /// Get the pointer to a given neutral that was used in vertex reco. + const NeutralParticle* neutralParticle( size_t i ) const; + /// Get the weight of a given neutral in the vertex reconstruction + float neutralWeight( size_t i ) const; + /// Get the number of neutrals associated with this vertex + size_t nNeutralParticles() const; + + + /// Add a new track to the vertex + void addTrackAtVertex( const ElementLink< TrackParticleContainer >& tr, + float weight = 1.0 ); + + /// Add a new neutral to the vertex + void addNeutralAtVertex( const ElementLink< NeutralParticleContainer >& tr, + float weight = 1.0 ); + + /// Remove all tracks from the vertex + void clearTracks(); + + /// Remove all neutrals from the vertex + void clearNeutrals(); + + + /// @} + + /// Reset the internal cache of the object + void resetCache(); + + private: + /// Cached position of the vertex + CxxUtils::CachedValue<Amg::Vector3D> m_position; + /// Cached covariance of the vertex + CxxUtils::CachedValue<AmgSymMatrix(3)> m_covariance; + + }; // end of the Vertex_v1 class definitions + +} // end of the xAOD namespace + +#include "xAODCore/BaseInfo.h" +SG_BASE (xAOD::Vertex_v1, SG::AuxElement); + +#endif // XAODTRACKING_VERSIONS_VERTEX_V1_H