diff --git a/Tracking/TrkEvent/TrkEventUtils/TrkEventUtils/PrepRawDataComparisonFunction.h b/Tracking/TrkEvent/TrkEventUtils/TrkEventUtils/PrepRawDataComparisonFunction.h index 6bc3fedf450f19a745e2aa95c4db967aefd92ac8..080aabdab6adfc81585cdb57f212b8392892e483 100755 --- a/Tracking/TrkEvent/TrkEventUtils/TrkEventUtils/PrepRawDataComparisonFunction.h +++ b/Tracking/TrkEvent/TrkEventUtils/TrkEventUtils/PrepRawDataComparisonFunction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ /////////////////////////////////////////////////////////////////// @@ -11,153 +11,143 @@ // Wolfgang.Liebig@cern.ch / Andreas.Salzburger@cern.ch /////////////////////////////////////////////////////////////////// - #ifndef TRKNIRVANA_PREPRAWDATACOMPARISONFUNCTION_H #define TRKNIRVANA_PREPRAWDATACOMPARISONFUNCTION_H -//Trk +// Trk +#include "GeoPrimitives/GeoPrimitives.h" #include "TrkPrepRawData/PrepRawData.h" +#include "TrkSurfaces/DiscSurface.h" #include "TrkSurfaces/PlaneSurface.h" #include "TrkSurfaces/StraightLineSurface.h" -#include "TrkSurfaces/DiscSurface.h" -#include "GeoPrimitives/GeoPrimitives.h" -//STL -#include <ext/algorithm> +// STL +#include <cmath> +#include <stdexcept> namespace Trk { - /** - * Class providing comparison function, or relational definition, for PrepRawData - */ - class PrepRawDataComparisonFunction +/** + * Class providing comparison function, or relational definition, for + * PrepRawData + */ +class PrepRawDataComparisonFunction +{ +public: + /** Full relation definition using a straight line propagation */ + PrepRawDataComparisonFunction(const Amg::Vector3D& sp, + const Amg::Vector3D& dir) + : m_point(sp) + , m_direction(dir.unit()) + {} + + PrepRawDataComparisonFunction() = delete; + PrepRawDataComparisonFunction(const PrepRawDataComparisonFunction& PCF) = + default; + PrepRawDataComparisonFunction(PrepRawDataComparisonFunction&& PCF) = default; + + PrepRawDataComparisonFunction& operator=( + const PrepRawDataComparisonFunction& PCF) = default; + + PrepRawDataComparisonFunction& operator=( + PrepRawDataComparisonFunction&& PCF) = default; + + ~PrepRawDataComparisonFunction() = default; + + /** The comparison function defining in what case a PRD is 'smaller' than + a second one */ + bool operator()(const Trk::PrepRawData* one, + const Trk::PrepRawData* two) const { - public: - - /** Default Constructor */ - PrepRawDataComparisonFunction() - : m_point(new Amg::Vector3D(0., 0., 0.)), - m_direction(0) - {} - - /** Simple relation definition using a 3d distance to the reference point */ - PrepRawDataComparisonFunction(const Amg::Vector3D& sp) - : m_point(new Amg::Vector3D(sp)), - m_direction(0) - {} - - /** Full relation definition using a straight line propagation */ - PrepRawDataComparisonFunction(const Amg::Vector3D& sp, - const Amg::Vector3D& dir) - : m_point(new Amg::Vector3D(sp)), - m_direction(new Amg::Vector3D(dir.unit())) - {} - - /** Copy Ctor */ - PrepRawDataComparisonFunction(const PrepRawDataComparisonFunction& PCF) - : m_point(PCF.m_point ? new Amg::Vector3D(*PCF.m_point) : 0), - m_direction(PCF.m_direction ? new Amg::Vector3D(*PCF.m_direction) : 0) - {} - - /** Destructor */ - virtual ~PrepRawDataComparisonFunction(){ - delete m_point; - delete m_direction; - } - - PrepRawDataComparisonFunction &operator=(const PrepRawDataComparisonFunction& PCF) { - if (this != &PCF) { - delete m_point; - m_point=(PCF.m_point ? new Amg::Vector3D(*PCF.m_point) : 0); - delete m_direction; - m_direction=(PCF.m_direction ? new Amg::Vector3D(*PCF.m_direction) : 0); + + // --- identify the surface type and get intersection path for surface 1 + // + double path1 = 0; + const Trk::Surface& sf1 = one->detectorElement()->surface(one->identify()); + const Trk::Surface::SurfaceType surfType1 = sf1.type(); + switch (surfType1) { + case Trk::Surface::Plane: { + const Trk::PlaneSurface& opsf = + static_cast<const Trk::PlaneSurface&>(sf1); + path1 = this->pathIntersectWithPlane(opsf); + } break; + case Trk::Surface::Line: { + const Trk::StraightLineSurface& ossf = + static_cast<const Trk::StraightLineSurface&>(sf1); + path1 = this->pathIntersectWithLine(ossf); + } break; + case Trk::Surface::Disc: { + const Trk::DiscSurface& odsf = + static_cast<const Trk::DiscSurface&>(sf1); + path1 = this->pathIntersectWithDisc(odsf); + } break; + default: { + throw std::runtime_error( + "PrepRawDataComparisonFunction: surface type error!"); } - return *this; - } - - /** The comparison function defining in what case a PRD is 'smaller' than - a second one */ - bool operator() (const Trk::PrepRawData* one, - const Trk::PrepRawData* two) const { - - if (!m_direction) { // simple case, just return surface distances - return ( (one->detectorElement()->surface( one->identify() ).center() - - *m_point).mag() - < (two->detectorElement()->surface( two->identify() ).center() - - *m_point).mag() - ); - } else { - // --- identify the surface type and get intersection path for surface 1 - // - double path1 = 0; - const Trk::Surface& sf1 = one->detectorElement()->surface( one->identify() ); - const Trk::PlaneSurface* opsf = dynamic_cast <const Trk::PlaneSurface*>(&sf1); - const Trk::StraightLineSurface* ossf = 0; // dyncast only when necessary - const Trk::DiscSurface* odsf = 0; - if (opsf) { - path1 = this->pathIntersectWithPlane(*opsf); - } else if ((ossf = dynamic_cast< const Trk::StraightLineSurface* >(&sf1)) && ossf) { - path1 = this->pathIntersectWithLine (*ossf); - } else if ((odsf = dynamic_cast <const Trk::DiscSurface*> (&sf1)) && odsf) { - path1 = this->pathIntersectWithDisc (*odsf); - } else { - std::cout << "PrepRawDataComparisonFunction: surface type error!" << std::endl; - } // --- no raw data on Cylinder. Ever. - - // --- identify the surface type and get intersection path for surface 1 - // - double path2 = 0; - const Trk::Surface& sf2 = two->detectorElement()->surface( two->identify() ); - const Trk::PlaneSurface* tpsf = dynamic_cast< const Trk::PlaneSurface* >(&sf2); - const Trk::StraightLineSurface* tssf = 0; // dyncast only when necessary - const Trk::DiscSurface* tdsf = 0; - if (tpsf) { - path2 = this->pathIntersectWithPlane(*tpsf); - } else if ((tssf = dynamic_cast< const Trk::StraightLineSurface* >(&sf2)) && tssf) { - path2 = this->pathIntersectWithLine (*tssf); - } else if ((tdsf = dynamic_cast< const Trk::DiscSurface* > (&sf2)) && tdsf) { - path2 = this->pathIntersectWithDisc (*tdsf); - } else { - std::cout << "PrepRawDataComparisonFunction: surface type error!" << std::endl; - } // --- no PRD on Cylinder. Ever. - - return path1 < path2; + } // --- no raw data on Cylinder. Ever. + + // --- identify the surface type and get intersection path for surface 1 + // + double path2 = 0; + const Trk::Surface& sf2 = two->detectorElement()->surface(two->identify()); + const Trk::Surface::SurfaceType surfType2 = sf2.type(); + switch (surfType2) { + case Trk::Surface::Plane: { + const Trk::PlaneSurface& opsf = + static_cast<const Trk::PlaneSurface&>(sf2); + path2 = this->pathIntersectWithPlane(opsf); + } break; + case Trk::Surface::Line: { + const Trk::StraightLineSurface& ossf = + static_cast<const Trk::StraightLineSurface&>(sf2); + path2 = this->pathIntersectWithLine(ossf); + } break; + case Trk::Surface::Disc: { + const Trk::DiscSurface& odsf = + static_cast<const Trk::DiscSurface&>(sf2); + path2 = this->pathIntersectWithDisc(odsf); + } break; + default: { + throw std::runtime_error( + "PrepRawDataComparisonFunction: surface type error!"); } + } // --- no raw data on Cylinder. Ever. - } - - private: - Amg::Vector3D* m_point; - Amg::Vector3D* m_direction; - - double pathIntersectWithPlane(const Trk::PlaneSurface& psf) const - { - double denom = m_direction->dot(psf.normal()); // c++ can be unreadable - return (denom) ? - psf.normal().dot(psf.center() - *m_point)/(denom) : - denom ; - } - - double pathIntersectWithLine(const Trk::StraightLineSurface& lsf) const - { - Amg::Vector3D dirWire(lsf.transform().rotation().col(2).unit()); - Amg::Vector3D trackToWire(lsf.center() - *m_point); - double parallelity = m_direction->dot(dirWire); - double denom = 1 - parallelity*parallelity; - return (fabs(denom)>10e-7) ? - (trackToWire.dot(*m_direction) - - trackToWire.dot(dirWire)*parallelity)/denom : - 0. ; - } - - double pathIntersectWithDisc(const Trk::DiscSurface& dsf) const - { - double denom = m_direction->dot(dsf.normal()); - return (denom) ? - dsf.normal().dot(dsf.center() - *m_point)/(denom) : - denom ; - } - }; + return path1 < path2; + } + +private: + Amg::Vector3D m_point; + Amg::Vector3D m_direction; + + double pathIntersectWithPlane(const Trk::PlaneSurface& psf) const + { + double denom = m_direction.dot(psf.normal()); + return (denom) ? psf.normal().dot(psf.center() - m_point) / (denom) + : denom; + } + + double pathIntersectWithLine(const Trk::StraightLineSurface& lsf) const + { + Amg::Vector3D dirWire(lsf.transform().rotation().col(2).unit()); + Amg::Vector3D trackToWire(lsf.center() - m_point); + double parallelity = m_direction.dot(dirWire); + double denom = 1 - parallelity * parallelity; + return (std::abs(denom) > 10e-7) + ? (trackToWire.dot(m_direction) - + trackToWire.dot(dirWire) * parallelity) / + denom + : 0.; + } + + double pathIntersectWithDisc(const Trk::DiscSurface& dsf) const + { + double denom = m_direction.dot(dsf.normal()); + return (denom) ? dsf.normal().dot(dsf.center() - m_point) / (denom) + : denom; + } +}; } // end of namespace -#endif //TRKNIRVANA_PREPRAWDATACOMPARISONFUNCTION_H +#endif // TRKNIRVANA_PREPRAWDATACOMPARISONFUNCTION_H