diff --git a/InnerDetector/InDetRecTools/InDetConversionFinderTools/src/TrackPairsSelector.cxx b/InnerDetector/InDetRecTools/InDetConversionFinderTools/src/TrackPairsSelector.cxx index 53ed185e2378209421177c35c442f1d9dd92d624..00ff0a4c31f48d84d4b1d838b078533788b36837 100644 --- a/InnerDetector/InDetRecTools/InDetConversionFinderTools/src/TrackPairsSelector.cxx +++ b/InnerDetector/InDetRecTools/InDetConversionFinderTools/src/TrackPairsSelector.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ /*************************************************************************** @@ -14,10 +14,25 @@ #include "InDetConversionFinderTools/ConversionFinderUtils.h" #include "TrkVertexSeedFinderUtils/ITrkDistanceFinder.h" #include "TrkMeasurementBase/MeasurementBase.h" +#include "GeoPrimitives/GeoPrimitivesHelpers.h" #include "xAODTracking/TrackParticle.h" +// Would be nice to use something like Amg::distance instead. +// But that rounds slightly differently. +// Do it like this so that results are identical with the pre-MT version. +namespace { + inline double square(const double tosquare) { + return std::pow(tosquare,2); + } + double dist(const std::pair<Amg::Vector3D,Amg::Vector3D>& pairofpos) { + Amg::Vector3D diff(pairofpos.first-pairofpos.second); + return std::sqrt(square(diff.x())+square(diff.y())+square(diff.z())); + } +} + + namespace InDet { // ------------------------------------------------------------- @@ -201,10 +216,13 @@ namespace InDet { maxDist = m_maxDist[2]; } - bool gotDistance = false; m_distance = 1000000.; - gotDistance = m_distanceTool->CalculateMinimumDistance(trkPneg->perigeeParameters(),trkPpos->perigeeParameters() ); - if (gotDistance) m_distance = m_distanceTool->GetDistance(); - if (!gotDistance || (m_distance>maxDist)) return false; + m_distance = 1000000.; + std::optional<Trk::ITrkDistanceFinder::TwoPoints> result + = m_distanceTool->CalculateMinimumDistance(trkPneg->perigeeParameters(), + trkPpos->perigeeParameters() ); + if (!result) return false; + m_distance = dist (result.value()); + if (m_distance>maxDist) return false; //3D angle cut in the case of V0s, not used in the case of conversions double d_beta = (perPos->momentum().dot(perNeg->momentum()))/(perPos->momentum().mag()*perNeg->momentum().mag()); @@ -268,10 +286,17 @@ namespace InDet { } else if(sCase == 2) { maxDist = m_maxDist[2]; } - bool gotDistance = false; double newDistance = 1000000.; - gotDistance = m_distanceTool->CalculateMinimumDistance(*trkpos,*trkneg); - if (gotDistance) newDistance = m_distanceTool->GetDistance(); - if (!gotDistance || (newDistance>maxDist)) pass = false; + + double newDistance = 1000000.; + std::optional<Trk::ITrkDistanceFinder::TwoPoints> result + = m_distanceTool->CalculateMinimumDistance(*trkpos, *trkneg); + if (!result) { + pass = false; + } + else { + newDistance = dist (result.value()); + if (newDistance>maxDist) pass = false; + } //3D angle cut in the case of V0s, not used in the case of conversions double d_beta = (perPos->momentum().dot(perNeg->momentum()))/(perPos->momentum().mag()*perNeg->momentum().mag()); diff --git a/Tracking/TrkVertexFitter/TrkVertexSeedFinderTools/src/CrossDistancesSeedFinder.cxx b/Tracking/TrkVertexFitter/TrkVertexSeedFinderTools/src/CrossDistancesSeedFinder.cxx index 937bd287358030145c9a9ff1bc844a5f3203cef4..01a505f4bf9c0536e1c0be6049d4921400239984 100755 --- a/Tracking/TrkVertexFitter/TrkVertexSeedFinderTools/src/CrossDistancesSeedFinder.cxx +++ b/Tracking/TrkVertexFitter/TrkVertexSeedFinderTools/src/CrossDistancesSeedFinder.cxx @@ -17,6 +17,7 @@ #include "TrkTrack/Track.h" #include "GeoPrimitives/GeoPrimitives.h" +#include "GeoPrimitives/GeoPrimitivesHelpers.h" #include "EventPrimitives/EventPrimitives.h" #include "TrkParameters/TrackParameters.h" @@ -24,6 +25,20 @@ #include <math.h> +// Would be nice to use something like Amg::distance instead. +// But that rounds slightly differently. +// Do it like this so that results are identical with the pre-MT version. +namespace { + inline double square(const double tosquare) { + return std::pow(tosquare,2); + } + double dist(const std::pair<Amg::Vector3D,Amg::Vector3D>& pairofpos) { + Amg::Vector3D diff(pairofpos.first-pairofpos.second); + return std::sqrt(square(diff.x())+square(diff.y())+square(diff.z())); + } +} + + namespace Trk { @@ -112,8 +127,6 @@ namespace Trk //now implement the code you already had in the standalone code... - //Variable to temporary store the points at minimum distance between the two tracks - std::pair<Amg::Vector3D,Amg::Vector3D> PointsAtMinDistance; //Calculate and cache the covariance matrix for the constraint AmgSymMatrix(3) weightMatrixPositionConstraint; @@ -153,32 +166,33 @@ namespace Trk #endif try { - - bool result=m_distancefinder->CalculateMinimumDistance(*MyI,*MyJ); + + std::optional<ITrkDistanceFinder::TwoPoints> result + = m_distancefinder->CalculateMinimumDistance(*MyI,*MyJ); if (!result) { if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG)<< "Problem with distance finder: THIS POINT WILL BE SKIPPED!" << endmsg; } else { //Get the points which connect the minimum distance between the two tracks - PointsAtMinDistance=m_distancefinder->GetPoints(); + double distance = dist (result.value()); #ifdef CROSSDISTANCESSEEDFINDER_DEBUG - if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG)<< "Point 1 x: " << PointsAtMinDistance.first.x() << - " y: " << PointsAtMinDistance.first.y() << - " z: " << PointsAtMinDistance.first.z() << endmsg; - if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG)<< "Point 2 x: " << PointsAtMinDistance.second.x() << - " y: " << PointsAtMinDistance.second.y() << - " z: " << PointsAtMinDistance.second.z() << endmsg; - if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG)<< "distance is: " << m_distancefinder->GetDistance() << endmsg; + if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG)<< "Point 1 x: " << result->first.x() << + " y: " << result->first.y() << + " z: " << result->first.z() << endmsg; + if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG)<< "Point 2 x: " << result->second.x() << + " y: " << result->second.y() << + " z: " << result->second.z() << endmsg; + if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG)<< "distance is: " << distance << endmsg; #endif - Amg::Vector3D thepoint((PointsAtMinDistance.first+PointsAtMinDistance.second)/2.); + Amg::Vector3D thepoint((result->first+result->second)/2.); if (m_useweights) { PositionAndWeight thispoint(thepoint, - 1./pow(m_trackdistcutoff+m_distancefinder->GetDistance(),m_trackdistexppower)); + 1./pow(m_trackdistcutoff+distance,m_trackdistexppower)); - if(msgLvl(MSG::VERBOSE)) msg(MSG::DEBUG) << "distance weight: " << 1./pow(m_trackdistcutoff+m_distancefinder->GetDistance(),m_trackdistexppower) << endmsg; + if(msgLvl(MSG::VERBOSE)) msg(MSG::DEBUG) << "distance weight: " << 1./pow(m_trackdistcutoff+distance,m_trackdistexppower) << endmsg; if (constraint!=0) { @@ -198,7 +212,7 @@ namespace Trk thispoint.second=thispoint.second*1./(1.+exp((chi2-m_constraintcutoff)/m_constrainttemp)); } - if ((useCutOnDistance==false || m_distancefinder->GetDistance()<m_maximumDistanceCut) && thispoint.second > 1e-10) + if ((useCutOnDistance==false || distance<m_maximumDistanceCut) && thispoint.second > 1e-10) { CrossingPointsAndWeights.push_back(thispoint); } @@ -206,7 +220,7 @@ namespace Trk else { Amg::Vector3D thispoint(thepoint); - if (useCutOnDistance==false || m_distancefinder->GetDistance()<m_maximumDistanceCut) + if (useCutOnDistance==false || distance<m_maximumDistanceCut) { CrossingPoints.push_back(thispoint); } diff --git a/Tracking/TrkVertexFitter/TrkVertexSeedFinderTools/src/IndexedCrossDistancesSeedFinder.cxx b/Tracking/TrkVertexFitter/TrkVertexSeedFinderTools/src/IndexedCrossDistancesSeedFinder.cxx index 953a0e028ba78d99f0e9f6b8bb1a21a008a19e16..4f6dcf14e2d1079c4221a1fce3821f4fd695db6f 100755 --- a/Tracking/TrkVertexFitter/TrkVertexSeedFinderTools/src/IndexedCrossDistancesSeedFinder.cxx +++ b/Tracking/TrkVertexFitter/TrkVertexSeedFinderTools/src/IndexedCrossDistancesSeedFinder.cxx @@ -16,6 +16,7 @@ #include "TrkTrack/Track.h" #include "GeoPrimitives/GeoPrimitives.h" +#include "GeoPrimitives/GeoPrimitivesHelpers.h" #include "EventPrimitives/EventPrimitives.h" #include "TrkParameters/TrackParameters.h" @@ -119,9 +120,6 @@ namespace Trk //now implement the code you already had in the standalone code... - //Variable to temporary store the points at minimum distance between the two tracks - std::pair<Amg::Vector3D,Amg::Vector3D> PointsAtMinDistance; - //Calculate and cache the covariance matrix for the constraint AmgSymMatrix(3) weightMatrixPositionConstraint; weightMatrixPositionConstraint.setIdentity(); //very arbitrary @@ -165,31 +163,32 @@ namespace Trk try { - bool result=m_distancefinder->CalculateMinimumDistance(*MyI,*MyJ); + std::optional<ITrkDistanceFinder::TwoPoints> result + = m_distancefinder->CalculateMinimumDistance(*MyI,*MyJ); if (!result) {ATH_MSG_DEBUG("Problem with distance finder: THIS POINT WILL BE SKIPPED!"); } else { //Get the points which connect the minimum distance between the two tracks - PointsAtMinDistance=m_distancefinder->GetPoints(); + double distance = Amg::distance (result->first, result->second); #ifdef CROSSDISTANCESSEEDFINDER_DEBUG - ATH_MSG_DEBUG("Point 1 x: " << PointsAtMinDistance.first.x() << - " y: " << PointsAtMinDistance.first.y() << - " z: " << PointsAtMinDistance.first.z() ); - ATH_MSG_DEBUG("Point 2 x: " << PointsAtMinDistance.second.x() << - " y: " << PointsAtMinDistance.second.y() << - " z: " << PointsAtMinDistance.second.z() ); - ATH_MSG_DEBUG("distance is: " << m_distancefinder->GetDistance() ); + ATH_MSG_DEBUG("Point 1 x: " << result->first.x() << + " y: " << result->first.y() << + " z: " << result->first.z() ); + ATH_MSG_DEBUG("Point 2 x: " << result->second.x() << + " y: " << result->second.y() << + " z: " << result->second.z() ); + ATH_MSG_DEBUG("distance is: " << distance ); #endif - Amg::Vector3D thepoint((PointsAtMinDistance.first+PointsAtMinDistance.second)/2.); + Amg::Vector3D thepoint((result->first+result->second)/2.); if (m_useweights) { PositionAndWeight thispoint(thepoint, - 1./pow(m_trackdistcutoff+m_distancefinder->GetDistance(),m_trackdistexppower)); + 1./pow(m_trackdistcutoff+distance,m_trackdistexppower)); - ATH_MSG_VERBOSE("distance weight: " << 1./pow(m_trackdistcutoff+m_distancefinder->GetDistance(),m_trackdistexppower) ); + ATH_MSG_VERBOSE("distance weight: " << 1./pow(m_trackdistcutoff+distance,m_trackdistexppower) ); if (constraint!=0) { @@ -210,7 +209,7 @@ namespace Trk } - if ((useCutOnDistance==false || m_distancefinder->GetDistance()<m_maximumDistanceCut) && thispoint.second > 1e-10) + if ((useCutOnDistance==false || distance<m_maximumDistanceCut) && thispoint.second > 1e-10) { CrossingPointsAndWeights.push_back( thispoint ); @@ -225,7 +224,7 @@ namespace Trk else { Amg::Vector3D thispoint(thepoint); - if ( useCutOnDistance==false || m_distancefinder->GetDistance()<m_maximumDistanceCut ) + if ( useCutOnDistance==false || distance<m_maximumDistanceCut ) { CrossingPoints.push_back( thispoint ); } diff --git a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/ITrkDistanceFinder.h b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/ITrkDistanceFinder.h index 8e074721c73fd8cc73c37adf0022b7ada37564b7..f6c88f7bbf79d33db113cf3691571abd0656e804 100644 --- a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/ITrkDistanceFinder.h +++ b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/ITrkDistanceFinder.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ /////////////////////////////////////////////////////////////////// @@ -11,6 +11,7 @@ #include "GaudiKernel/IAlgTool.h" #include "TrkParameters/TrackParameters.h" +#include <optional> //Amg #include "GeoPrimitives/GeoPrimitives.h" @@ -21,8 +22,6 @@ namespace Trk class Track; class TrackParticleBase; - static const InterfaceID IID_ITRKDISTANCEFINDER("ITrkDistanceFinder", 1, 1); - /** @class ITrkDistanceFinder @@ -37,21 +36,25 @@ namespace Trk class ITrkDistanceFinder : virtual public IAlgTool { public: + typedef std::pair<Amg::Vector3D,Amg::Vector3D> TwoPoints; + + DeclareInterfaceID( ITrkDistanceFinder, 1, 0 ); + /** Virtual destructor */ virtual ~ITrkDistanceFinder(){}; - /** AlgTool interface methods */ - static const InterfaceID& interfaceID() { return IID_ITRKDISTANCEFINDER; }; - /** method to do the calculation starting from two MeasuredPerigees*/ - /** return value is true if calculation is successfull */ - virtual bool CalculateMinimumDistance(const Trk::Perigee &, const Trk::Perigee &) = 0; + /** If successful, returns the points on the two tracks at minimum distance. */ + virtual std::optional<TwoPoints> + CalculateMinimumDistance(const Trk::Perigee &, const Trk::Perigee &) = 0; /** method to do the calculation starting from two tracks */ - virtual bool CalculateMinimumDistance(const Trk::Track &, const Trk::Track &) = 0; + virtual std::optional<TwoPoints> + CalculateMinimumDistance(const Trk::Track &, const Trk::Track &) = 0; /** method to do the calculation starting from two track particles */ - virtual bool CalculateMinimumDistance(const Trk::TrackParticleBase &, const Trk::TrackParticleBase &) = 0; + virtual std::optional<TwoPoints> + CalculateMinimumDistance(const Trk::TrackParticleBase &, const Trk::TrackParticleBase &) = 0; /**method to obtain the distance (call CalculateMinimumDistance before) **/ virtual double GetDistance() const =0; diff --git a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/SeedNewtonTrkDistanceFinder.h b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/SeedNewtonTrkDistanceFinder.h index 679467341f70faeffbcd6e3ccabe809a0729f30c..a34ed9821bfbe62447b8923fbdf2b75dd19e747c 100644 --- a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/SeedNewtonTrkDistanceFinder.h +++ b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/SeedNewtonTrkDistanceFinder.h @@ -40,11 +40,11 @@ namespace Trk - class SeedNewtonTrkDistanceFinder : public AthAlgTool, virtual public ITrkDistanceFinder + class SeedNewtonTrkDistanceFinder : public extends<AthAlgTool, ITrkDistanceFinder> { public: - StatusCode initialize(); - StatusCode finalize(); + virtual StatusCode initialize() override; + virtual StatusCode finalize() override; //default constructor due to Athena interface SeedNewtonTrkDistanceFinder(const std::string& t, const std::string& n, const IInterface* p); @@ -53,30 +53,31 @@ namespace Trk virtual ~SeedNewtonTrkDistanceFinder(); /** method to do the calculation starting from two Perigees*/ - /** return value is true if calculation is successfull */ - virtual bool CalculateMinimumDistance(const Trk::Perigee &, const Trk::Perigee &); + /** If successful, returns the points on the two tracks at minimum distance. */ + virtual std::optional<TwoPoints> + CalculateMinimumDistance(const Trk::Perigee &, const Trk::Perigee &) override; /** method to do the calculation starting from two tracks */ - virtual bool CalculateMinimumDistance(const Trk::Track &, const Trk::Track &); + virtual std::optional<TwoPoints> + CalculateMinimumDistance(const Trk::Track &, const Trk::Track &) override; /** method to do the calculation starting from two track particles */ - virtual bool CalculateMinimumDistance(const Trk::TrackParticleBase &, const Trk::TrackParticleBase &); + virtual std::optional<TwoPoints> + CalculateMinimumDistance(const Trk::TrackParticleBase &, const Trk::TrackParticleBase &) override; /**method to obtain the distance (call CalculateMinimumDistance before) **/ - virtual double GetDistance() const; + virtual double GetDistance() const override; /** method to obtain the points on the two tracks at minimum distance **/ - virtual const std::pair<Amg::Vector3D,Amg::Vector3D> GetPoints() const; + virtual const std::pair<Amg::Vector3D,Amg::Vector3D> GetPoints() const override; private: - ToolHandle<Trk2dDistanceSeeder> m_2ddistanceseeder; ToolHandle<NewtonTrkDistanceFinder> m_distancefinder; TwoPoints m_points; int m_numberOfMinimizationFailures; - }; } #endif diff --git a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/Trk2DDistanceFinder.h b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/Trk2DDistanceFinder.h index e55b69f6a1402f79253ce8c109c27bb94f915d67..48efea059f3c62a731c275704e12dbd81834a9bf 100644 --- a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/Trk2DDistanceFinder.h +++ b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/TrkVertexSeedFinderUtils/Trk2DDistanceFinder.h @@ -34,42 +34,43 @@ namespace Trk - class Trk2DDistanceFinder : public AthAlgTool, virtual public ITrkDistanceFinder + class Trk2DDistanceFinder : public extends<AthAlgTool, ITrkDistanceFinder> { public: - StatusCode initialize(); - StatusCode finalize(); - //default constructor due to Athena interface Trk2DDistanceFinder(const std::string& t, const std::string& n, const IInterface* p); //destructor virtual ~Trk2DDistanceFinder(); + virtual StatusCode initialize() override; + virtual StatusCode finalize() override; + /** method to do the calculation starting from two MeasuredPerigees*/ - /** return value is true if calculation is successfull */ - virtual bool CalculateMinimumDistance(const Trk::Perigee &, const Trk::Perigee &); + /** If successful, returns the points on the two tracks at minimum distance. */ + virtual std::optional<TwoPoints> + CalculateMinimumDistance(const Trk::Perigee &, const Trk::Perigee &) override; /** method to do the calculation starting from two tracks */ - virtual bool CalculateMinimumDistance(const Trk::Track &, const Trk::Track &); + virtual std::optional<TwoPoints> + CalculateMinimumDistance(const Trk::Track &, const Trk::Track &) override; /** method to do the calculation starting from two track particles */ - virtual bool CalculateMinimumDistance(const Trk::TrackParticleBase &, const Trk::TrackParticleBase &); + virtual std::optional<TwoPoints> + CalculateMinimumDistance(const Trk::TrackParticleBase &, + const Trk::TrackParticleBase &) override; /**method to obtain the distance (call CalculateMinimumDistance before) **/ - virtual double GetDistance() const; + virtual double GetDistance() const override; /** method to obtain the points on the two tracks at minimum distance **/ - virtual const std::pair<Amg::Vector3D,Amg::Vector3D> GetPoints() const; + virtual const std::pair<Amg::Vector3D,Amg::Vector3D> GetPoints() const override; - private: - ToolHandle<Trk2dDistanceSeeder> m_2ddistanceseeder; int m_numberOfMinimizationFailures; Trk::TwoPoints m_points; - }; } #endif diff --git a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/share/SeedNewtonTrkDistanceFinder_test.ref b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/share/SeedNewtonTrkDistanceFinder_test.ref index 00a6176aeb46c2a7440b81bb23dc519606bb25cd..90c8888f67bba6014d3a6593a57236e30ecfd147 100644 --- a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/share/SeedNewtonTrkDistanceFinder_test.ref +++ b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/share/SeedNewtonTrkDistanceFinder_test.ref @@ -10,7 +10,7 @@ JobOptionsSvc INFO Job options successfully read in from /home/sss/atlas/ ApplicationMgr SUCCESS ==================================================================================================================================== Welcome to ApplicationMgr (GaudiCoreSvc v27r1p99) - running on karma on Sun Jun 16 00:44:19 2019 + running on karma on Sun Jun 16 15:50:32 2019 ==================================================================================================================================== ApplicationMgr INFO Application Manager Configured successfully AtlasFieldSvc INFO initialize() ... @@ -30,5 +30,4 @@ AtlasFieldSvc INFO Initialized the field map from /home/sss/nobackup/atla AtlasFieldSvc INFO Currents imported and map initialized AtlasFieldSvc INFO BeginRun incident handled AtlasFieldSvc INFO incidents handled successfully -ToolSvc.Trk::Se... INFO Initialize successful test1 diff --git a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/share/Trk2DDistanceFinder_test.ref b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/share/Trk2DDistanceFinder_test.ref index 69ff6f027e99aa7d42b34b1778c3f73f084d3712..74bcd71bdf907bf6044ef4ac4346a4654cf53332 100644 --- a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/share/Trk2DDistanceFinder_test.ref +++ b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/share/Trk2DDistanceFinder_test.ref @@ -10,7 +10,7 @@ JobOptionsSvc INFO Job options successfully read in from /home/sss/atlas/ ApplicationMgr SUCCESS ==================================================================================================================================== Welcome to ApplicationMgr (GaudiCoreSvc v27r1p99) - running on karma on Sun Jun 16 00:44:22 2019 + running on karma on Sun Jun 16 15:50:34 2019 ==================================================================================================================================== ApplicationMgr INFO Application Manager Configured successfully AtlasFieldSvc INFO initialize() ... @@ -30,5 +30,4 @@ AtlasFieldSvc INFO Initialized the field map from /home/sss/nobackup/atla AtlasFieldSvc INFO Currents imported and map initialized AtlasFieldSvc INFO BeginRun incident handled AtlasFieldSvc INFO incidents handled successfully -ToolSvc.Trk::Tr... INFO Initialize successful test1 diff --git a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/src/SeedNewtonTrkDistanceFinder.cxx b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/src/SeedNewtonTrkDistanceFinder.cxx index be84e9f5d6e5d72982f397f58ee2c4c13e074112..c231e3f2ce4ddcca6daf8a0c95efb481f13863d1 100644 --- a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/src/SeedNewtonTrkDistanceFinder.cxx +++ b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/src/SeedNewtonTrkDistanceFinder.cxx @@ -21,19 +21,9 @@ namespace { -#if 0 - inline const Amg::Vector3D operator + ( const Amg::Vector3D & first, const Amg::Vector3D & second) { - return Amg::Vector3D( first.x()+second.x(),first.y()+second.y(),first.z()+second.z()); - } -#endif inline const Amg::Vector3D operator - ( const Amg::Vector3D & first, const Amg::Vector3D & second) { return Amg::Vector3D( first.x()-second.x(),first.y()-second.y(),first.z()-second.z()); } -#if 0 - inline const Amg::Vector3D operator / ( const Amg::Vector3D & first, const double second) { - return Amg::Vector3D( first.x()/second,first.y()/second,first.z()/second); - } -#endif inline double square(const double tosquare) { return std::pow(tosquare,2); } @@ -50,14 +40,13 @@ namespace Trk SeedNewtonTrkDistanceFinder::SeedNewtonTrkDistanceFinder(const std::string& t, const std::string& n, const IInterface* p) : - AthAlgTool(t,n,p), + base_class(t,n,p), m_2ddistanceseeder("Trk::Trk2dDistanceSeeder"), m_distancefinder("Trk::NewtonTrkDistanceFinder"), m_numberOfMinimizationFailures(0) { declareProperty("Trk2dDistanceSeeder", m_2ddistanceseeder); declareProperty("TrkDistanceFinderImplementation", m_distancefinder); - declareInterface<ITrkDistanceFinder>(this); } SeedNewtonTrkDistanceFinder::~SeedNewtonTrkDistanceFinder() {} @@ -68,82 +57,62 @@ namespace Trk //initialize number of failures to 0 m_numberOfMinimizationFailures=0; - StatusCode s = AlgTool::initialize(); - if (s.isFailure() ) - { - msg(MSG::FATAL) << "AlgTool::initialize() initialize failed!" << endmsg; - return StatusCode::FAILURE; - } - - s = m_2ddistanceseeder.retrieve(); - if (s.isFailure()) - { - msg(MSG::FATAL)<<"Could not find 2d distance seeder tool." << endmsg; - return StatusCode::FAILURE; - } - s = m_distancefinder.retrieve(); - if (s.isFailure()) - { - msg(MSG::FATAL)<<"Could not find newton distance finder implementation tool." << endmsg; - return StatusCode::FAILURE; - } - msg(MSG::INFO) << "Initialize successful" << endmsg; + ATH_CHECK( AlgTool::initialize() ); + ATH_CHECK( m_2ddistanceseeder.retrieve() ); + ATH_CHECK( m_distancefinder.retrieve() ); + ATH_MSG_DEBUG( "Initialize successful" ); return StatusCode::SUCCESS; } StatusCode SeedNewtonTrkDistanceFinder::finalize() { - msg(MSG::INFO) << "Finalize successful. Number of failed minimizations: " << m_numberOfMinimizationFailures << ". Few per events is OK!" << endmsg; + ATH_MSG_DEBUG( "Finalize successful. Number of failed minimizations: " << m_numberOfMinimizationFailures << ". Few per events is OK!" ); return StatusCode::SUCCESS; } /** method to do the calculation starting from two MeasuredPerigees*/ /** return value is true if calculation is successfull */ - bool SeedNewtonTrkDistanceFinder::CalculateMinimumDistance(const Trk::Perigee & a, const Trk::Perigee & b) + std::optional<ITrkDistanceFinder::TwoPoints> + SeedNewtonTrkDistanceFinder::CalculateMinimumDistance(const Trk::Perigee & a, + const Trk::Perigee & b) { - -//defragmenting the meory: local variable instead of private data member - std::pair<PointOnTrack,PointOnTrack> minpoints; + //defragmenting the meory: local variable instead of private data member + std::pair<PointOnTrack,PointOnTrack> minpoints; //try first to get the minimum directly with the Newton method try { -// m_minpoints=m_distancefinder->GetClosestPoints(a,b); - m_points = m_distancefinder->GetClosestPoints(a,b); - } catch (Error::NewtonProblem e) { + m_points = m_distancefinder->GetClosestPoints(a,b); + return m_points; + } + catch (Error::NewtonProblem e) { if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Problem with Newton finder: " << e.p << endmsg; try { -// m_minpoints=m_2ddistanceseeder->GetSeed(TwoTracks(a,b)); -// m_minpoints=m_distancefinder->GetClosestPoints(m_minpoints); minpoints=m_2ddistanceseeder->GetSeed(TwoTracks(a,b)); m_points = m_distancefinder->GetClosestPoints(minpoints); - - } catch (Error::NewtonProblem e) { - if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Problem with Newton finder, even after 2d seeder: no minimum between tracks found" << e.p << endmsg; + return m_points; + } + catch (Error::NewtonProblem e) { + ATH_MSG_DEBUG( "Problem with Newton finder, even after 2d seeder: no minimum between tracks found" << e.p); m_numberOfMinimizationFailures+=1; - return false; } catch (...) { m_numberOfMinimizationFailures+=1; - return false; } } - -#ifdef SEEDNEWTONTRKDISTANCEFINDER_DEBUG - ATH_MSG_DEBUG( "Returned a_phi " << minpoints.first.getPhiPoint() ); - ATH_MSG_DEBUG( "Returned b_phi " << minpoints.second.getPhiPoint() ); -#endif - return true; + return std::nullopt; } /** method to do the calculation starting from two tracks */ - bool SeedNewtonTrkDistanceFinder::CalculateMinimumDistance(const Trk::Track & a, const Trk::Track & b) { - + std::optional<ITrkDistanceFinder::TwoPoints> + SeedNewtonTrkDistanceFinder::CalculateMinimumDistance(const Trk::Track & a, + const Trk::Track & b) + { if (std::isnan(a.perigeeParameters()->parameters()[Trk::d0])||std::isnan(b.perigeeParameters()->parameters()[Trk::d0])) { - msg(MSG::ERROR) << "Nan parameters in tracks. Cannot use them" << endmsg; - return false; + ATH_MSG_ERROR( "Nan parameters in tracks. Cannot use them" ); + return std::nullopt; } return CalculateMinimumDistance(*(a.perigeeParameters()),*(b.perigeeParameters())); @@ -151,8 +120,10 @@ namespace Trk } /** method to do the calculation starting from two track particles */ - bool SeedNewtonTrkDistanceFinder::CalculateMinimumDistance(const Trk::TrackParticleBase & a, const Trk::TrackParticleBase & b) { - + std::optional<ITrkDistanceFinder::TwoPoints> + SeedNewtonTrkDistanceFinder::CalculateMinimumDistance(const Trk::TrackParticleBase & a, + const Trk::TrackParticleBase & b) + { const Trk::TrackParameters& para=a.definingParameters(); const Trk::TrackParameters& parb=b.definingParameters(); @@ -160,13 +131,13 @@ namespace Trk const Trk::Perigee* parperb=dynamic_cast<const Trk::Perigee*>(&parb); if (parpera==0||parperb==0) { - msg(MSG::WARNING) << "Cannot cast to perigee. Neutral will be supported soon" << endmsg; - return false; + ATH_MSG_WARNING( "Cannot cast to perigee. Neutral will be supported soon" ); + return std::nullopt; } if (std::isnan(parpera->parameters()[Trk::d0])||std::isnan(parperb->parameters()[Trk::d0])) { - msg(MSG::ERROR) << "Nan parameters in tracks. Cannot use them" << endmsg; - return false; + ATH_MSG_ERROR( "Nan parameters in tracks. Cannot use them" ); + return std::nullopt; } return CalculateMinimumDistance(*(parpera),*(parperb)); diff --git a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/src/Trk2DDistanceFinder.cxx b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/src/Trk2DDistanceFinder.cxx index d60687020822c5aa0c6b02cac56f6ff6909209c3..333d0e8a60084f0acc98240221a8e92e8c778978 100644 --- a/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/src/Trk2DDistanceFinder.cxx +++ b/Tracking/TrkVertexFitter/TrkVertexSeedFinderUtils/src/Trk2DDistanceFinder.cxx @@ -38,12 +38,11 @@ namespace Trk Trk2DDistanceFinder::Trk2DDistanceFinder(const std::string& t, const std::string& n, const IInterface* p) : - AthAlgTool(t,n,p), + base_class(t,n,p), m_2ddistanceseeder("Trk::Trk2dDistanceSeeder"), m_numberOfMinimizationFailures(0) { declareProperty("Trk2dDistanceSeeder", m_2ddistanceseeder); - declareInterface<ITrkDistanceFinder>(this); } Trk2DDistanceFinder::~Trk2DDistanceFinder() {} @@ -54,74 +53,64 @@ namespace Trk //initialize number of failures to 0 m_numberOfMinimizationFailures=0; - StatusCode s = AlgTool::initialize(); - if (s.isFailure() ) - { - msg(MSG::FATAL) << "AlgTool::initialize() initialize failed!" << endmsg; - return StatusCode::FAILURE; - } - - s = m_2ddistanceseeder.retrieve(); - if (s.isFailure()) - { - msg(MSG::FATAL)<<"Could not find 2d distance seeder tool." << endmsg; - return StatusCode::FAILURE; - } - msg(MSG::INFO) << "Initialize successful" << endmsg; + ATH_CHECK( AlgTool::initialize() ); + ATH_CHECK( m_2ddistanceseeder.retrieve() ); + ATH_MSG_DEBUG( "Initialize successful" ); return StatusCode::SUCCESS; } StatusCode Trk2DDistanceFinder::finalize() { - - msg(MSG::INFO) << "Finalize successful. Number of failed minimizations: " << m_numberOfMinimizationFailures << ". Few per events is OK!" << endmsg; + ATH_MSG_DEBUG( "Finalize successful. Number of failed minimizations: " << m_numberOfMinimizationFailures << ". Few per events is OK!" ); return StatusCode::SUCCESS; } /** method to do the calculation starting from two MeasuredPerigees*/ /** return value is true if calculation is successfull */ - bool Trk2DDistanceFinder::CalculateMinimumDistance(const Trk::Perigee & a, const Trk::Perigee & b) + std::optional<ITrkDistanceFinder::TwoPoints> + Trk2DDistanceFinder::CalculateMinimumDistance(const Trk::Perigee & a, + const Trk::Perigee & b) { - - std::pair<PointOnTrack,PointOnTrack> minpoints; + std::pair<PointOnTrack,PointOnTrack> minpoints; try { minpoints=m_2ddistanceseeder->GetSeed(TwoTracks(a,b), &m_points); } catch (...) { - if(msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Problem with 2d analytic minimum distance finder" << endmsg; + ATH_MSG_WARNING( "Problem with 2d analytic minimum distance finder" ); m_numberOfMinimizationFailures+=1; - return false; + return std::nullopt; } #ifdef SEEDNEWTONTRKDISTANCEFINDER_DEBUG -// m_log(MSG::DEBUG) << "Returned a_phi " << minpoints.first.getPhiPoint() << endmsg; -// m_log(MSG::DEBUG) << "Returned b_phi " << minpoints.second.getPhiPoint() << endmsg; - - if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Returned a_phi " << minpoints.first.getPhiPoint() << endmsg; - if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Returned b_phi " << minpoints.second.getPhiPoint() << endmsg; + ATH_MSG_DEBUG( "Returned a_phi " << minpoints.first.getPhiPoint() ); + ATH_MSG_DEBUG( "Returned b_phi " << minpoints.second.getPhiPoint() ); #endif - return true; + return m_points;; } /** method to do the calculation starting from two tracks */ - bool Trk2DDistanceFinder::CalculateMinimumDistance(const Trk::Track & a, const Trk::Track & b) { - + std::optional<ITrkDistanceFinder::TwoPoints> + Trk2DDistanceFinder::CalculateMinimumDistance(const Trk::Track & a, + const Trk::Track & b) + { if (std::isnan(a.perigeeParameters()->parameters()[Trk::d0])||std::isnan(b.perigeeParameters()->parameters()[Trk::d0])) { - msg(MSG::ERROR) << "Nan parameters in tracks. Cannot use them" << endmsg; - return false; + ATH_MSG_ERROR( "Nan parameters in tracks. Cannot use them" ); + return std::nullopt; } return CalculateMinimumDistance(*(a.perigeeParameters()),*(b.perigeeParameters())); - } - /** method to do the calculation starting from two track particles */ - bool Trk2DDistanceFinder::CalculateMinimumDistance(const Trk::TrackParticleBase & a, const Trk::TrackParticleBase & b) { + /** method to do the calculation starting from two track particles */ + std::optional<ITrkDistanceFinder::TwoPoints> + Trk2DDistanceFinder::CalculateMinimumDistance(const Trk::TrackParticleBase & a, + const Trk::TrackParticleBase & b) + { const Trk::TrackParameters& para=a.definingParameters(); const Trk::TrackParameters& parb=b.definingParameters(); @@ -129,13 +118,13 @@ namespace Trk const Trk::Perigee* parperb=dynamic_cast<const Trk::Perigee*>(&parb); if (parpera==0||parperb==0) { - msg(MSG::WARNING) << "Cannot cast to perigee. Neutral will be supported soon" << endmsg; - return false; + ATH_MSG_WARNING("Cannot cast to perigee. Neutral will be supported soon" ); + return std::nullopt; } if (std::isnan(parpera->parameters()[Trk::d0])||std::isnan(parperb->parameters()[Trk::d0])) { - msg(MSG::ERROR) << "Nan parameters in tracks. Cannot use them" << endmsg; - return false; + ATH_MSG_ERROR( "Nan parameters in tracks. Cannot use them" ); + return std::nullopt; } return CalculateMinimumDistance(*(parpera),*(parperb));