diff --git a/Tracking/TrkFitter/TrkFitterUtils/CMakeLists.txt b/Tracking/TrkFitter/TrkFitterUtils/CMakeLists.txt index a0cadba46d621f7855f526b67f538b82cf6ae443..86054f715e6ab77bc6c7d0c2ad3709d5aa530f46 100644 --- a/Tracking/TrkFitter/TrkFitterUtils/CMakeLists.txt +++ b/Tracking/TrkFitter/TrkFitterUtils/CMakeLists.txt @@ -17,6 +17,7 @@ atlas_depends_on_subdirs( PUBLIC Tracking/TrkEvent/TrkMeasurementBase Tracking/TrkEvent/TrkParameters Tracking/TrkExtrapolation/TrkExUtils + Control/CxxUtils PRIVATE DetectorDescription/AtlasDetDescr Tracking/TrkEvent/TrkMaterialOnTrack @@ -38,6 +39,7 @@ atlas_add_library( TrkFitterUtils PUBLIC_HEADERS TrkFitterUtils INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS} DEFINITIONS ${CLHEP_DEFINITIONS} - LINK_LIBRARIES ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} AthContainers GeoPrimitives Identifier GaudiKernel TrkSurfaces TrkEventPrimitives TrkEventUtils TrkMeasurementBase TrkParameters TrkExUtils - PRIVATE_LINK_LIBRARIES AtlasDetDescr TrkMaterialOnTrack TrkPseudoMeasurementOnTrack TrkRIO_OnTrack TrkSegment TrkTrack TrkVertexOnTrack TrkExInterfaces TrkToolInterfaces ) + LINK_LIBRARIES ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} AthContainers GeoPrimitives Identifier GaudiKernel TrkSurfaces TrkEventPrimitives TrkEventUtils + TrkMeasurementBase TrkParameters TrkExUtils CxxUtils + PRIVATE_LINK_LIBRARIES AtlasDetDescr TrkMaterialOnTrack TrkPseudoMeasurementOnTrack TrkRIO_OnTrack TrkSegment TrkTrack TrkVertexOnTrack TrkExInterfaces TrkToolInterfaces ) diff --git a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ATLAS_CHECK_THREAD_SAFETY b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ATLAS_CHECK_THREAD_SAFETY new file mode 100644 index 0000000000000000000000000000000000000000..9505ac12c3fb42b6633961fdb5ebf44e8225e56a --- /dev/null +++ b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ATLAS_CHECK_THREAD_SAFETY @@ -0,0 +1 @@ +Tracking/TrkFitter/TrkFitterUtils diff --git a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/DNA_MaterialEffects.h b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/DNA_MaterialEffects.h index d167f970862136eebc1372602cde67beb214a2e6..e0ad773c4d2a1bafeb515b267fd9e940ce9ac702 100755 --- a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/DNA_MaterialEffects.h +++ b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/DNA_MaterialEffects.h @@ -72,7 +72,7 @@ namespace Trk{ therefore the quantity is not part of the constructor. The quantities are mainly aimed at completing the information for the EDM class EstimatedBremOnTrack. */ - void setDeltaP(double deltaP, double sigmaDeltaP = 0.0) const; + void setDeltaP(double deltaP, double sigmaDeltaP = 0.0) ; double deltaP() const; double sigmaDeltaP() const; @@ -85,8 +85,8 @@ namespace Trk{ private: double m_xmin,m_dxmin,m_chi2min,m_thickness,m_sigmaDNA,m_addSigmaQoverP; bool m_foundByForwardFilter; - mutable double m_deltaP; - mutable double m_sigmaDeltaP; + double m_deltaP; + double m_sigmaDeltaP; const Surface* m_associatedSurface; }; @@ -108,7 +108,7 @@ namespace Trk{ inline double DNA_MaterialEffects::addSigmaQoverP() const { return m_addSigmaQoverP; } inline void DNA_MaterialEffects::setDeltaP(double deltaP, - double sigmaDeltaP) const + double sigmaDeltaP) { m_deltaP = deltaP; m_sigmaDeltaP = sigmaDeltaP; } inline double DNA_MaterialEffects::deltaP() const diff --git a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/KalmanMatEffectsController.h b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/KalmanMatEffectsController.h index d7c44220b37f4f107e7204b5e2cddaf24e6ee037..3273f598c91c78bac574fe94a116e0f380e02f6c 100644 --- a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/KalmanMatEffectsController.h +++ b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/KalmanMatEffectsController.h @@ -14,7 +14,7 @@ #include "TrkEventPrimitives/ParticleHypothesis.h" #include "TrkFitterUtils/TrackBreakpointType.h" - +#include "CxxUtils/checker_macros.h" namespace Trk{ /** @brief This class is a wrapper around the input particle hypothesis given @@ -57,57 +57,44 @@ namespace Trk{ ~KalmanMatEffectsController(); */ //! particleHypothesis as it was passed to the fitter - ParticleHypothesis originalParticleHypo() const; - //! particleHypothesis as it should be used for extrapolation calls - ParticleHypothesis particleType() const; - //! flag saying if dynamic noise adjustment should be called or not - bool doDNA() const; - //! flag saying if dynamic noise adjustment should maximise sensitivity to electron bremsstrahlung (aggressive tuning) or minimise effects on non-electron particles (generic tuning) - bool aggressiveDNA() const; - //! return breakpoint type resulting from DNA-based breakpoint search - TrackBreakpointType breakpointType() const; - //! sets breakpoint type after DNA & Separator provide such information - void updateBreakpoint(TrackBreakpointType) const; - - private: - const ParticleHypothesis m_inputHypothesis; - const bool m_haveDNA; - mutable TrackBreakpointType m_breakPointType; - }; - - /* - MsgStream& operator << ( MsgStream& sl, const KalmanMatEffectsController& dme); - std::ostream& operator << ( std::ostream& sl, const KalmanMatEffectsController& dme); - */ - - inline ParticleHypothesis KalmanMatEffectsController::originalParticleHypo() const - { + ParticleHypothesis originalParticleHypo() const { return m_inputHypothesis; } - - inline ParticleHypothesis KalmanMatEffectsController::particleType() const - { + //! particleHypothesis as it should be used for extrapolation calls + ParticleHypothesis particleType() const { if (m_haveDNA && m_inputHypothesis==Trk::electron) return Trk::pion; return m_inputHypothesis; } - - inline bool KalmanMatEffectsController::doDNA() const - { + //! flag saying if dynamic noise adjustment should be called or not + bool doDNA() const { return ( m_haveDNA && (m_breakPointType==Trk::BreakpointNotSpecified || m_breakPointType==Trk::DnaBremPointUseful) ); } - inline bool KalmanMatEffectsController::aggressiveDNA() const - { + //! flag saying if dynamic noise adjustment should maximise sensitivity to electron bremsstrahlung + //(aggressive tuning) or minimise effects on non-electron particles (generic tuning) + bool aggressiveDNA() const { return (this->doDNA() && m_inputHypothesis==electron); } + //! return breakpoint type resulting from DNA-based breakpoint search + TrackBreakpointType breakpointType() const{ + return m_breakPointType; + } + //! sets breakpoint type after DNA & Separator provide such information + void updateBreakpoint (TrackBreakpointType newBPT) { + m_breakPointType = newBPT; + } - inline TrackBreakpointType KalmanMatEffectsController::breakpointType() const - { return m_breakPointType; } + void updateBreakpoint ATLAS_NOT_THREAD_SAFE (TrackBreakpointType newBPT) const { + const_cast<TrackBreakpointType&> (m_breakPointType) = newBPT; + } - inline void KalmanMatEffectsController::updateBreakpoint(TrackBreakpointType newBPT) const - { m_breakPointType = newBPT; } + private: + const ParticleHypothesis m_inputHypothesis; + const bool m_haveDNA; + TrackBreakpointType m_breakPointType; + }; } // end namespace Trk #endif diff --git a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoMaterialEffects.h b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoMaterialEffects.h index b8b486dff812e52a1205004942b32776316ef261..beb0bbcb6ec8fc95afc60ba37914809cd85a6048 100644 --- a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoMaterialEffects.h +++ b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoMaterialEffects.h @@ -6,7 +6,7 @@ #define TRKPROTOMATERIALEFFECTS_H #include <vector> - +#include "CxxUtils/checker_macros.h" namespace Trk{ class MaterialEffectsOnTrack; @@ -58,7 +58,7 @@ namespace Trk{ bool isMeasuredEloss() const; const Surface *surface() const; void setSurface(const Surface*); - MaterialEffectsBase *makeMEOT() const; + MaterialEffectsBase *makeMEOT ATLAS_NOT_THREAD_SAFE() const; const MaterialProperties *materialProperties() const; void setMaterialProperties(const MaterialProperties *); //std::vector<double> &momentumJacobians(); @@ -79,7 +79,7 @@ namespace Trk{ const MaterialProperties *m_matprop; bool m_iskink; bool m_ismeasuredeloss; - mutable bool m_owneloss; + bool m_owneloss; //This the main MT issue in this package double m_measscatphi; // fudge to stabilize fit in muon system double m_sintheta; //std::vector<double> m_pjac; diff --git a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoTrackStateOnSurface.h b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoTrackStateOnSurface.h index 4f0509fecb42ba2f1195db7470038bd3b28819db..f6106b244dff4465936054851a33fa810e11832b 100755 --- a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoTrackStateOnSurface.h +++ b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoTrackStateOnSurface.h @@ -20,7 +20,7 @@ #include "TrkExUtils/TransportJacobian.h" #include "TrkFitterUtils/TrackCalibDefs.h" #include <vector> - +#include "CxxUtils/CachedUniquePtr.h" namespace Trk { class MeasurementBase; @@ -200,7 +200,7 @@ namespace Trk { TrackState::CalibrationType); //! create an EDM TrackStateOnSurface object from the internal information - const Trk::TrackStateOnSurface* createState(bool makeSlimOutlier=true); + const Trk::TrackStateOnSurface* createState ATLAS_NOT_THREAD_SAFE (bool makeSlimOutlier=true); //! get surface (either from measurement or from material effects) const Trk::Surface *surface() const; @@ -233,7 +233,7 @@ namespace Trk { bool m_iOwnParametersDifference; //!< flag to steer ownership on difference const AmgSymMatrix(5)* m_parametersCovariance; //!< covariance matrix of fitted parameters bool m_iOwnParametersCovariance; //!< flag for ownership of covarinace matrix of fitted parameters - mutable Amg::VectorX* m_measurementDifferenceVector; //!< cached difference between reference TrkParameters and measurement + CxxUtils::CachedUniquePtrT<Amg::VectorX> m_measurementDifferenceVector; //!< cached difference between reference TrkParameters and measurement }; /// general swap function for ProtoTrackStateOnSurface (to speed up sort, etc) diff --git a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoTrajectoryUtility.h b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoTrajectoryUtility.h index 8f6521e38d8054b390ac4d72b9895e51bc5ecda4..1d3b07e550fe80e5f485267f1eba554a970da772 100755 --- a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoTrajectoryUtility.h +++ b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/ProtoTrajectoryUtility.h @@ -12,6 +12,7 @@ //Trk #include "TrkParameters/TrackParameters.h" #include "TrkFitterUtils/ProtoTrackStateOnSurface.h" +#include "CxxUtils/checker_macros.h" class AtlasDetectorID; // to identify measurements namespace Trk { @@ -23,7 +24,7 @@ namespace Trk { @author Wolfgang Liebig <http://consult.cern.ch/xwho/people/54608> */ - class ProtoTrajectoryUtility { + class ATLAS_NOT_THREAD_SAFE ProtoTrajectoryUtility { public: //! Default constructor diff --git a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/SensorBoundsCheck.h b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/SensorBoundsCheck.h index 9f5daacf80eff7f940825d6ba91c5dc64453ec49..e451932b5d56ae63e8eaff2304cf3a6d38ec4c8e 100755 --- a/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/SensorBoundsCheck.h +++ b/Tracking/TrkFitter/TrkFitterUtils/TrkFitterUtils/SensorBoundsCheck.h @@ -47,7 +47,6 @@ namespace Trk { const double& = -1.0); private: - static Amg::Vector2D s_localTrack; }; } diff --git a/Tracking/TrkFitter/TrkFitterUtils/src/ProtoMaterialEffects.cxx b/Tracking/TrkFitter/TrkFitterUtils/src/ProtoMaterialEffects.cxx index b4954623edebccbd850abd62d358c5c7aaa873be..e09822c779190bc535b8a4b521bba00bf664d7d6 100644 --- a/Tracking/TrkFitter/TrkFitterUtils/src/ProtoMaterialEffects.cxx +++ b/Tracking/TrkFitter/TrkFitterUtils/src/ProtoMaterialEffects.cxx @@ -287,7 +287,7 @@ MaterialEffectsBase *ProtoMaterialEffects::makeMEOT() const { //std::cout << "deltae: " << neweloss->deltaE() << " sigde: " << neweloss->sigmaDeltaE() << " sigplus: " << neweloss->sigmaPlusDeltaE() << " sigminus: " << neweloss->sigmaMinusDeltaE() << std::endl; } MaterialEffectsOnTrack *meot=new MaterialEffectsOnTrack(m_x0,scatangles,neweloss,*m_surf,typePattern); - m_owneloss=false; + const_cast<bool&>(m_owneloss)=false; //Non MT safe function //m_eloss=0; return meot; } diff --git a/Tracking/TrkFitter/TrkFitterUtils/src/ProtoTrackStateOnSurface.cxx b/Tracking/TrkFitter/TrkFitterUtils/src/ProtoTrackStateOnSurface.cxx index 8c2430c705697850545737603f0cc2ab84430349..11d6ea9b93e61946f1c045b53d7201dafd3bef17 100755 --- a/Tracking/TrkFitter/TrkFitterUtils/src/ProtoTrackStateOnSurface.cxx +++ b/Tracking/TrkFitter/TrkFitterUtils/src/ProtoTrackStateOnSurface.cxx @@ -46,7 +46,7 @@ Trk::ProtoTrackStateOnSurface::ProtoTrackStateOnSurface() m_iOwnParametersDifference ( true ), m_parametersCovariance(0), m_iOwnParametersCovariance(true), - m_measurementDifferenceVector(0) + m_measurementDifferenceVector(nullptr) { m_identifier.clear(); } @@ -82,7 +82,7 @@ Trk::ProtoTrackStateOnSurface::ProtoTrackStateOnSurface m_parametersCovariance ( rhs.m_iOwnParametersCovariance? ( rhs.m_parametersCovariance? new AmgSymMatrix(5) ( *rhs.m_parametersCovariance ) : 0 ) : rhs.m_parametersCovariance), m_iOwnParametersCovariance ( rhs.m_iOwnParametersCovariance ), - m_measurementDifferenceVector(0) + m_measurementDifferenceVector(nullptr) { } @@ -120,7 +120,7 @@ Trk::ProtoTrackStateOnSurface::ProtoTrackStateOnSurface m_iOwnParametersDifference(true), m_parametersCovariance(0), m_iOwnParametersCovariance(true), - m_measurementDifferenceVector(0) + m_measurementDifferenceVector(nullptr) { m_identifier.clear(); } @@ -149,7 +149,6 @@ Trk::ProtoTrackStateOnSurface::~ProtoTrackStateOnSurface() if (m_iOwnParametersCovariance) { delete m_parametersCovariance; } - delete m_measurementDifferenceVector; } Trk::ProtoTrackStateOnSurface& Trk::ProtoTrackStateOnSurface::operator=(const Trk::ProtoTrackStateOnSurface& rhs) @@ -201,7 +200,7 @@ Trk::ProtoTrackStateOnSurface& Trk::ProtoTrackStateOnSurface::operator=(const Tr ? new AmgSymMatrix(5)(*rhs.m_parametersCovariance) : 0 ) : rhs.m_parametersCovariance; m_iOwnParametersCovariance= rhs.m_iOwnParametersCovariance; - m_measurementDifferenceVector = 0; + m_measurementDifferenceVector.store(nullptr); } return *this; } @@ -246,7 +245,7 @@ void Trk::ProtoTrackStateOnSurface::checkinMeasurement(const Trk::MeasurementBas m_measurement = meas; m_iOwnMeasurement = classShallOwnMbase; m_mType = Trk::TrackState::unidentified; - delete m_measurementDifferenceVector; m_measurementDifferenceVector = 0; + m_measurementDifferenceVector.store(nullptr); } void Trk::ProtoTrackStateOnSurface::replaceMeasurement(const Trk::MeasurementBase* meas, @@ -257,7 +256,7 @@ void Trk::ProtoTrackStateOnSurface::replaceMeasurement(const Trk::MeasurementBas m_measurement = meas; m_iOwnMeasurement = true; m_calib = ct; - delete m_measurementDifferenceVector; m_measurementDifferenceVector = 0; + m_measurementDifferenceVector.store(nullptr); // assume that replacements are done with the same detector type (recalibration) } } @@ -269,8 +268,8 @@ const Trk::MeasurementBase* Trk::ProtoTrackStateOnSurface::checkoutMeasurement() return 0; } const Trk::MeasurementBase* helper = m_measurement; - m_measurement = NULL; - delete m_measurementDifferenceVector; m_measurementDifferenceVector = 0; + m_measurement = nullptr; + m_measurementDifferenceVector.store(nullptr); if (!m_iOwnMeasurement) { return helper->clone(); } else { @@ -314,7 +313,7 @@ void Trk::ProtoTrackStateOnSurface::checkinReferenceParameters ( const Trk::Trac } m_referenceParameters = referenceParameters; m_iOwnRefPars = classShallOwnRefPars; - delete m_measurementDifferenceVector; m_measurementDifferenceVector = 0; + m_measurementDifferenceVector.store(nullptr); } const Trk::TrackParameters* Trk::ProtoTrackStateOnSurface::checkoutReferenceParameters() @@ -323,7 +322,7 @@ const Trk::TrackParameters* Trk::ProtoTrackStateOnSurface::checkoutReferencePara std::cout << "ProtoTrackStateOnSurface >>> WARNING possibly bad use of ::checkoutReferenceParameters!" << std::endl; return 0; } - delete m_measurementDifferenceVector; m_measurementDifferenceVector = 0; + m_measurementDifferenceVector.store(nullptr); const Trk::TrackParameters* helper = m_referenceParameters; m_referenceParameters = 0; if ( !m_iOwnRefPars ) return helper->clone(); @@ -546,7 +545,7 @@ const Trk::TrackStateOnSurface* Trk::ProtoTrackStateOnSurface::createState(bool else if (!m_measurement && m_protoMaterialEffects) typePattern.set(TrackStateOnSurface::Scatterer); else return 0; - const Trk::MaterialEffectsBase* mefot = 0; + const Trk::MaterialEffectsBase* mefot = nullptr; if (m_dnaMaterialEffects) { mefot = m_dnaMaterialEffects->makeMEFOT(); typePattern.set(TrackStateOnSurface::BremPoint); @@ -580,23 +579,17 @@ const Trk::Surface *Trk::ProtoTrackStateOnSurface::surface() const { const Amg::VectorX* Trk::ProtoTrackStateOnSurface::measurementDifference() const { if (!m_measurement || !m_referenceParameters) { - return 0; + return nullptr; } if (m_measurementDifferenceVector) { - return m_measurementDifferenceVector; + return m_measurementDifferenceVector.get(); } - const LocalParameters& locPar = m_measurement->localParameters(); - - m_measurementDifferenceVector = new Amg::VectorX(); - // TODO. check, how to simplify projection by using block -// if ( paramKey == 3 || paramKey == 7 || paramKey == 15 ) { -// projTrkPar = trkPar.block<DIM,1>(0,0); -// } -// else projTrkPar = H*trkPar; - *m_measurementDifferenceVector = - locPar - locPar.expansionMatrix()*m_referenceParameters->parameters(); - return m_measurementDifferenceVector; + const LocalParameters& locPar = m_measurement->localParameters(); + std::unique_ptr<Amg::VectorX> tmp_measurementDifferenceVector=std::make_unique<Amg::VectorX>(); + (*tmp_measurementDifferenceVector)=locPar - locPar.expansionMatrix()*m_referenceParameters->parameters(); + m_measurementDifferenceVector.set(std::move(tmp_measurementDifferenceVector)); + return m_measurementDifferenceVector.get(); } /// general swap function for ProtoTrackStateOnSurface (to speed up sort, etc) diff --git a/Tracking/TrkFitter/TrkFitterUtils/src/SensorBoundsCheck.cxx b/Tracking/TrkFitter/TrkFitterUtils/src/SensorBoundsCheck.cxx index b533126278191117a0af30e5e3398177df1b48f7..184d0c1d2841167e05133752047dd20403e3eb2e 100755 --- a/Tracking/TrkFitter/TrkFitterUtils/src/SensorBoundsCheck.cxx +++ b/Tracking/TrkFitter/TrkFitterUtils/src/SensorBoundsCheck.cxx @@ -11,7 +11,6 @@ #include "TrkSurfaces/Surface.h" #include "TrkSurfaces/TrapezoidBounds.h" -Amg::Vector2D Trk::SensorBoundsCheck::s_localTrack; bool Trk::SensorBoundsCheck::areParamsInside (const Trk::MeasurementBase& sensor, @@ -28,8 +27,7 @@ bool Trk::SensorBoundsCheck::areParamsInside double sig2 = (tolerance2>=0 ? err2 * tolerance2 : err2 * tolerance1); const Surface& surf = sensor.associatedSurface(); - s_localTrack = Amg::Vector2D(positionPars(Trk::loc1), - positionPars(Trk::loc2) ); - return surf.insideBounds(*const_cast<const Amg::Vector2D*>(&s_localTrack),sig1,sig2); + const Amg::Vector2D localTrack(positionPars(Trk::loc1),positionPars(Trk::loc2) ); + return surf.insideBounds(localTrack,sig1,sig2); }