diff --git a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/InDetRIO_OnTrack/TRT_DriftCircleOnTrack.h b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/InDetRIO_OnTrack/TRT_DriftCircleOnTrack.h index d3912e4bd63c4548646405e86308b69c2643eef0..e84917187f49cd7cd4b3e6dd359708ebc9cedb82 100755 --- a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/InDetRIO_OnTrack/TRT_DriftCircleOnTrack.h +++ b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/InDetRIO_OnTrack/TRT_DriftCircleOnTrack.h @@ -76,9 +76,13 @@ namespace InDet{ const Amg::Vector3D& predictedTrackDirection, const Trk::DriftCircleStatus status); + + /** + * Constructor used by the TP converters + */ TRT_DriftCircleOnTrack( const ElementLinkToIDCTRT_DriftCircleContainer& RIO, const Trk::LocalParameters& driftRadius, - const Amg::MatrixX& errDriftRadius, + const Amg::MatrixX& errDriftRadius, IdentifierHash idDE, const Identifier& id, double predictedLocZ, @@ -86,7 +90,7 @@ namespace InDet{ const Trk::DriftCircleStatus status, bool highLevel, double timeOverThreshold); - + /**Destructor */ virtual ~TRT_DriftCircleOnTrack(); @@ -154,17 +158,19 @@ namespace InDet{ float localAngle() const; float positionAlongWire() const; + private: /** ONLY for use in custom convertor Allows the custom convertor to reset values when persistying/reading back RoTs*/ virtual void setValues(const Trk::TrkDetElementBase* detEl, const Trk::PrepRawData* prd) override; - /** @brief Uses the passed loc3Dframe to calculate and set the global coord of this hit. - The detector element surface is used*/ - void setGlobalPosition(Amg::Vector3D& loc3Dframe) const; + /** @calculate and set the global coord of this hit. + The detector element surface is used. Can be used from the convertor + after setValues if the element is constructed without a detEl*/ + void setGlobalPositionHelper(); /** global position to be cached */ - CxxUtils::CachedUniquePtr<const Amg::Vector3D> m_globalPosition; + Amg::Vector3D m_globalPosition; /**local angle to be written out */ float m_localAngle; @@ -192,17 +198,22 @@ namespace InDet{ }; - inline TRT_DriftCircleOnTrack* TRT_DriftCircleOnTrack::clone() const + inline TRT_DriftCircleOnTrack* + TRT_DriftCircleOnTrack::clone() const { return new TRT_DriftCircleOnTrack(*this); } - - inline const TRT_DriftCircle* TRT_DriftCircleOnTrack::prepRawData() const + + inline const TRT_DriftCircle* + TRT_DriftCircleOnTrack::prepRawData() const { - // somehow one has to ask first if it is valid ... otherwise it always returns 0 ... - if (m_rio.isValid()) return m_rio.cachedElement(); - else return 0; - } + // ask first if it is valid ... + // otherwise it always returns nullptr ... + if (m_rio.isValid()) { + return m_rio.cachedElement(); + } + return nullptr; + } inline const ElementLinkToIDCTRT_DriftCircleContainer& diff --git a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/TRT_DriftCircleOnTrack.cxx b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/TRT_DriftCircleOnTrack.cxx index 1c1cb9b16892d96ced0c303ab6e584f376da420f..52548493e8a2ac56229a33591982eb86f831f1ee 100755 --- a/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/TRT_DriftCircleOnTrack.cxx +++ b/InnerDetector/InDetRecEvent/InDetRIO_OnTrack/src/TRT_DriftCircleOnTrack.cxx @@ -23,38 +23,71 @@ #include <utility> // Constructor with parameters: -InDet::TRT_DriftCircleOnTrack::TRT_DriftCircleOnTrack( - const InDet::TRT_DriftCircle* RIO, - const Trk::LocalParameters& driftRadius, - const Amg::MatrixX& errDriftRadius, - const IdentifierHash& idDE, - double predictedLocZ, - const Amg::Vector3D& predictedTrackDirection, - const Trk::DriftCircleStatus status) - : - Trk::RIO_OnTrack(driftRadius, errDriftRadius, RIO->identify()), //call base class constructor - m_globalPosition{}, - m_positionAlongWire(predictedLocZ), - m_idDE(idDE), - m_status(status), - m_highLevel(RIO->highLevel()), - m_timeOverThreshold(RIO->timeOverThreshold()), - m_detEl( RIO->detectorElement() ) +InDet::TRT_DriftCircleOnTrack::TRT_DriftCircleOnTrack( + const InDet::TRT_DriftCircle* RIO, + const Trk::LocalParameters& driftRadius, + const Amg::MatrixX& errDriftRadius, + const IdentifierHash& idDE, + double predictedLocZ, + const Amg::Vector3D& predictedTrackDirection, + const Trk::DriftCircleStatus status) + // call base class constructor + : Trk::RIO_OnTrack(driftRadius, errDriftRadius, RIO->identify()) + , m_globalPosition{} + , m_positionAlongWire(predictedLocZ) + , m_idDE(idDE) + , m_status(status) + , m_highLevel(RIO->highLevel()) + , m_timeOverThreshold(RIO->timeOverThreshold()) + , m_detEl(RIO->detectorElement()) { + m_rio.setElement(RIO); - if (m_detEl->surface(RIO->identify()).type()==Trk::Surface::Line){ - const Trk::StraightLineSurface& slsf =static_cast<const Trk::StraightLineSurface&>((m_detEl->surface(RIO->identify()))); - m_globalPosition.store(std::unique_ptr<const Amg::Vector3D>(slsf.localToGlobal(driftRadius, predictedTrackDirection, predictedLocZ))); - } + + const Trk::Surface& detElSurf= m_detEl->surface(RIO->identify()); + if (detElSurf.type() == Trk::Surface::Line) { + + const Trk::StraightLineSurface& slsf = + static_cast<const Trk::StraightLineSurface&>(detElSurf); + + m_globalPosition = + slsf.localToGlobalPos(driftRadius, predictedTrackDirection, predictedLocZ); + } Amg::Vector3D loc_gDirection = predictedTrackDirection; const double dr = driftRadius[Trk::driftRadius]; + //scaling the direction with drift radius - if(dr !=0.){ - m_localAngle = atan2(loc_gDirection.y(),loc_gDirection.x()); - } else m_localAngle = 0.; - + if(dr !=0.){ + m_localAngle = std::atan2(loc_gDirection.y(), loc_gDirection.x()); + } else { + m_localAngle = 0.; + } } +//Constructor used by the converter +InDet::TRT_DriftCircleOnTrack::TRT_DriftCircleOnTrack( + const ElementLinkToIDCTRT_DriftCircleContainer& RIO, + const Trk::LocalParameters& driftRadius, + const Amg::MatrixX& errDriftRadius, + IdentifierHash idDE, + const Identifier& id, + double predictedLocZ, + float localAngle, + const Trk::DriftCircleStatus status, + bool highLevel, + double timeOverThreshold) + : Trk::RIO_OnTrack(driftRadius, errDriftRadius, id) + , m_globalPosition{} + , m_localAngle(localAngle) + , m_positionAlongWire(predictedLocZ) + , m_rio(RIO) + , m_idDE(idDE) + , m_status(status) + , m_highLevel(highLevel) + , m_timeOverThreshold(timeOverThreshold) + , m_detEl(nullptr) +{} + // Destructor: InDet::TRT_DriftCircleOnTrack::~TRT_DriftCircleOnTrack() {} @@ -71,37 +104,13 @@ InDet::TRT_DriftCircleOnTrack::TRT_DriftCircleOnTrack() m_status(Trk::UNDECIDED), m_highLevel(false), m_timeOverThreshold(0.), - m_detEl(0) + m_detEl(nullptr) {} -InDet::TRT_DriftCircleOnTrack::TRT_DriftCircleOnTrack - ( const ElementLinkToIDCTRT_DriftCircleContainer& RIO, - const Trk::LocalParameters& driftRadius, - const Amg::MatrixX& errDriftRadius, - IdentifierHash idDE, - const Identifier& id, - double predictedLocZ, - float localAngle, - const Trk::DriftCircleStatus status, - bool highLevel, - double timeOverThreshold) - : Trk::RIO_OnTrack (driftRadius, errDriftRadius, id), - m_globalPosition{}, - m_localAngle(localAngle), - m_positionAlongWire(predictedLocZ), - m_rio(RIO), - m_idDE(idDE), - m_status(status), - m_highLevel(highLevel), - m_timeOverThreshold(timeOverThreshold), - m_detEl( nullptr) -{ -} - //copy constructor: InDet::TRT_DriftCircleOnTrack::TRT_DriftCircleOnTrack( const InDet::TRT_DriftCircleOnTrack& rot): Trk::RIO_OnTrack(rot), - m_globalPosition{}, + m_globalPosition(rot.m_globalPosition), m_localAngle(rot.m_localAngle), m_positionAlongWire(rot.m_positionAlongWire), m_rio(rot.m_rio), @@ -111,9 +120,6 @@ InDet::TRT_DriftCircleOnTrack::TRT_DriftCircleOnTrack( const InDet::TRT_DriftCir m_timeOverThreshold(rot.m_timeOverThreshold), m_detEl(rot.m_detEl) { - if (rot.m_globalPosition) { - m_globalPosition.store(std::make_unique<const Amg::Vector3D>(*(rot.m_globalPosition))); - } } //assignment operator: @@ -121,11 +127,7 @@ InDet::TRT_DriftCircleOnTrack& InDet::TRT_DriftCircleOnTrack::operator=( const I { if ( &rot != this) { Trk::RIO_OnTrack::operator= (rot); - if (rot.m_globalPosition) { - m_globalPosition.store(std::make_unique<const Amg::Vector3D>(*(rot.m_globalPosition))); - } else if (m_globalPosition) { - m_globalPosition.release().reset(); - } + m_globalPosition = rot.m_globalPosition; m_rio = rot.m_rio; m_localAngle = rot.m_localAngle; m_positionAlongWire = rot.m_positionAlongWire; @@ -168,59 +170,57 @@ const Trk::Surface& InDet::TRT_DriftCircleOnTrack::associatedSurface() const assert(0!=m_detEl); return (m_detEl->surface(identify())); } - -void InDet::TRT_DriftCircleOnTrack::setGlobalPosition(Amg::Vector3D& loc3Dframe) const{ - const Trk::StraightLineSurface* slsf = dynamic_cast<const Trk::StraightLineSurface*>( &(associatedSurface()) ); - if(slsf) { - m_globalPosition.set(std::make_unique<Amg::Vector3D>(slsf->transform() * loc3Dframe)); - }else{ - throw GaudiException("Dynamic_cast to StraightLineSurface failed!", - "TRT_DriftCircleOnTrack::setGlobalPosition()", - StatusCode::FAILURE); - } -} - -void InDet::TRT_DriftCircleOnTrack::setValues(const Trk::TrkDetElementBase* detEl, const Trk::PrepRawData*) -{ - m_detEl = dynamic_cast<const InDetDD::TRT_BaseElement* >(detEl); -} const Amg::Vector3D& InDet::TRT_DriftCircleOnTrack::globalPosition() const { - if (not m_globalPosition) - { - - if (side()==Trk::NONE) - { - //local position - Amg::Vector3D loc3Dframe(0., 0., m_positionAlongWire); + return m_globalPosition; +} - //transfrom to global - setGlobalPosition(loc3Dframe); - }else{ - - // get global position where track and drift radius intersect. - double Sf,Cf; sincos(m_localAngle,&Sf,&Cf); - double x = localParameters()[Trk::driftRadius]*Sf; - double y = localParameters()[Trk::driftRadius]*Cf; - /* - double x = localParameters()[Trk::driftRadius]*std::sin(m_localAngle); - double y = localParameters()[Trk::driftRadius]*std::cos(m_localAngle); - */ - //get local position - Amg::Vector3D loc3Dframe(x, y, m_positionAlongWire); - //transform to global - setGlobalPosition(loc3Dframe); - }//end of checking the side information availability - - }//end of checking whether the global position is there +//Global Position Helper for the converter +void +InDet::TRT_DriftCircleOnTrack::setGlobalPositionHelper() +{ - //returning the result (now stored in private datamember) - return (*m_globalPosition); - } + //default + Amg::Vector3D loc3Dframe(0., 0., m_positionAlongWire); + if (side() != Trk::NONE) { + // get global position where track and drift radius intersect. + double Sf, Cf; + sincos(m_localAngle, &Sf, &Cf); + double x = localParameters()[Trk::driftRadius] * Sf; + double y = localParameters()[Trk::driftRadius] * Cf; + /* + double x = localParameters()[Trk::driftRadius]*std::sin(m_localAngle); + double y = localParameters()[Trk::driftRadius]*std::cos(m_localAngle); + */ + // get local position + loc3Dframe = Amg::Vector3D(x, y, m_positionAlongWire); + } + //We need a surface for the global position + const Trk::StraightLineSurface* slsf = + dynamic_cast<const Trk::StraightLineSurface*>(&(associatedSurface())); + if (slsf) { + m_globalPosition = Amg::Vector3D(slsf->transform() * loc3Dframe); + } else { + throw GaudiException("Dynamic_cast to StraightLineSurface failed!", + "TRT_DriftCircleOnTrack::setGlobalPosition()", + StatusCode::FAILURE); + } +} +//set Values to be used by the converter +void +InDet::TRT_DriftCircleOnTrack::setValues(const Trk::TrkDetElementBase* detEl, + const Trk::PrepRawData*) +{ + m_detEl = dynamic_cast<const InDetDD::TRT_BaseElement* >(detEl); + // If we have a m_detEL we can set the global position + if (m_detEl) { + setGlobalPositionHelper(); + } +} MsgStream& InDet::TRT_DriftCircleOnTrack::dump( MsgStream& sl ) const { @@ -244,14 +244,9 @@ std::ostream& InDet::TRT_DriftCircleOnTrack::dump( std::ostream& sl ) const sl << "Global position (x,y,z) = ("; this->globalPosition(); - if (m_globalPosition) - { - sl <<this->globalPosition().x()<<", " - <<this->globalPosition().y()<<", " - <<this->globalPosition().z()<<")"<<std::endl; - } else { - sl<<"NULL!), "<<std::endl; - } + sl <<this->globalPosition().x()<<", " + <<this->globalPosition().y()<<", " + <<this->globalPosition().z()<<")"<<std::endl; sl << "\t time-over-threshold = " << timeOverThreshold() << (highLevel() ? " with TR flag ON":" with TR flag OFF")<<std::endl; @@ -259,7 +254,3 @@ std::ostream& InDet::TRT_DriftCircleOnTrack::dump( std::ostream& sl ) const return sl; } - - - - diff --git a/Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/StraightLineSurface.h b/Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/StraightLineSurface.h index 260ac1ef98ae970a9ae9dbb8f08fcf9940e962bb..db57e565fbc56c1a0c0823308dc7d0a572160e5d 100644 --- a/Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/StraightLineSurface.h +++ b/Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/StraightLineSurface.h @@ -178,11 +178,16 @@ public: Amg::Vector2D& loc) const override final; /** Special method for StraightLineSurface - providing a different z estimate + Performs memory allocation the caller owns the ptr */ - const Amg::Vector3D* localToGlobal( - const Trk::LocalParameters& locpars, - const Amg::Vector3D& glomom, - double locZ) const; + Amg::Vector3D* localToGlobal(const Trk::LocalParameters& locpars, + const Amg::Vector3D& glomom, + double locZ) const; + /** Special method for StraightLineSurface - providing a different z estimate + */ + Amg::Vector3D localToGlobalPos(const Trk::LocalParameters& locpars, + const Amg::Vector3D& glomom, + double locZ) const; /** Special method for StraightLineSurface - provides the Line direction from * cache: speedup */ diff --git a/Tracking/TrkDetDescr/TrkSurfaces/src/StraightLineSurface.cxx b/Tracking/TrkDetDescr/TrkSurfaces/src/StraightLineSurface.cxx index eb867589508c33d4828da700b5a8a371944ba6ca..c4197ffd073e7b5667e4ab342f8ba7aa9056757c 100644 --- a/Tracking/TrkDetDescr/TrkSurfaces/src/StraightLineSurface.cxx +++ b/Tracking/TrkDetDescr/TrkSurfaces/src/StraightLineSurface.cxx @@ -110,7 +110,7 @@ Trk::StraightLineSurface::localToGlobal(const Amg::Vector2D& locpos, } // specialized version for providing different Z - local to global method - from LocalParameters/ -const Amg::Vector3D* +Amg::Vector3D* Trk::StraightLineSurface::localToGlobal(const Trk::LocalParameters& locpars, const Amg::Vector3D& glomom, double locZ) const @@ -120,6 +120,17 @@ Trk::StraightLineSurface::localToGlobal(const Trk::LocalParameters& locpars, return Surface::localToGlobal(locPos, glomom); } +Amg::Vector3D +Trk::StraightLineSurface::localToGlobalPos(const Trk::LocalParameters& locpars, + const Amg::Vector3D& glomom, + double locZ) const +{ + // create a local Position + Amg::Vector2D locPos(locpars[Trk::driftRadius], locZ); + return Surface::localToGlobalPos(locPos, glomom); +} + + // true global to local method - fully defined bool Trk::StraightLineSurface::globalToLocal(const Amg::Vector3D& glopos,