Commit 77d7b1e9 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'MuonSegment_surface_holder_simplify' into 'master'

MuonSegment use ptr holder. Default a few operation avoid a dynamic cast. Tidy up code

See merge request !44515
parents b76640a0 b5f4640e
/* /*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/ */
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
...@@ -10,15 +10,16 @@ ...@@ -10,15 +10,16 @@
#define MUONSEGMENT_MUONSEGMENT_H #define MUONSEGMENT_MUONSEGMENT_H
// Trk // Trk
#include "TrkSegment/Segment.h"
#include "TrkEventPrimitives/LocalDirection.h" #include "TrkEventPrimitives/LocalDirection.h"
#include "TrkEventPrimitives/SurfaceHolderImpl.h"
#include "TrkRIO_OnTrack/RIO_OnTrack.h"
#include "TrkSegment/Segment.h"
#include "TrkSpaceTimePoint/SpaceTimePointBase.h" #include "TrkSpaceTimePoint/SpaceTimePointBase.h"
#include "TrkSurfaces/PlaneSurface.h" #include "TrkSurfaces/PlaneSurface.h"
#include "TrkRIO_OnTrack/RIO_OnTrack.h"
namespace Muon { namespace Muon {
/** @class MuonSegment /** @class MuonSegment
This is the common class for 3D segments used in the muon spectrometer. This is the common class for 3D segments used in the muon spectrometer.
...@@ -34,11 +35,15 @@ namespace Muon { ...@@ -34,11 +35,15 @@ namespace Muon {
@image html segment_example.gif @image html segment_example.gif
@image html MuonSegment.gif @image html MuonSegment.gif
@author Niels.van.Eldik@cern.ch, Edward.Moyse@cern.ch, Andreas.Salzburger@cern.ch @author Niels.van.Eldik@cern.ch, Edward.Moyse@cern.ch,
*/ Andreas.Salzburger@cern.ch
class MuonSegment : public Trk::Segment, public Trk::SpaceTimePointBase { */
public: class MuonSegment final
: public Trk::Segment
, public Trk::SpaceTimePointBase
, public Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>
{
public:
/** define invalid value, used when the segment has no fitted t0 */ /** define invalid value, used when the segment has no fitted t0 */
static const float kNoValue; static const float kNoValue;
...@@ -48,48 +53,57 @@ namespace Muon { ...@@ -48,48 +53,57 @@ namespace Muon {
MuonSegment(const MuonSegment& seg); MuonSegment(const MuonSegment& seg);
/** Assignment operator */ /** Assignment operator */
MuonSegment& operator=(const MuonSegment& seg); MuonSegment& operator=(const MuonSegment& seg);
/** Move Constructor */
MuonSegment(MuonSegment&& seg) noexcept = default;
/** Move Assignment operator */
MuonSegment& operator=(MuonSegment&& seg) noexcept = default;
/** Constructor within standard track parameters frame taking a vector of MeasurementBase. /** Constructor within standard track parameters frame taking a vector of
MeasurementBase.
@param locpars 4 dim or 5 dim standard track parameters representation @param locpars 4 dim or 5 dim standard track parameters representation
@param locerr 4 x 4 error or 5 x 5 error on standard track parameters repr. @param locerr 4 x 4 error or 5 x 5 error on standard track parameters
repr.
@param psf plane surface @param psf plane surface
@param cmeas vector of contained measurements on track @param cmeas vector of contained measurements on track
@param fqual fit quality object @param fqual fit quality object
@param author enum to indicate author, see Segment.h for the possible authors @param author enum to indicate author, see Segment.h for the possible
authors
*/ */
MuonSegment( const Trk::LocalParameters& locpars, MuonSegment(const Trk::LocalParameters& locpars,
const Amg::MatrixX& locerr, const Amg::MatrixX& locerr,
Trk::PlaneSurface* psf, Trk::PlaneSurface* psf,
DataVector<const Trk::MeasurementBase>* cmeas, DataVector<const Trk::MeasurementBase>* cmeas,
Trk::FitQuality* fqual, Trk::FitQuality* fqual,
Segment::Author author=AuthorUnknown Segment::Author author = AuthorUnknown);
);
/** Constructor within local parameters of the Segment taking a vector of MeasurementBase /** Constructor within local parameters of the Segment taking a vector of
MeasurementBase
@param segLocPos 2 local position coordinates @param segLocPos 2 local position coordinates
@param segLocalErr 2 local direction coordinates @param segLocalErr 2 local direction coordinates
@param segLocalErr 4 x 4 full local error @param segLocalErr 4 x 4 full local error
@param psf plane surface @param psf plane surface
@param cmeas vector of contained measurements on track @param cmeas vector of contained measurements on track
@param fqual fit quality object @param fqual fit quality object
@param author enum to indicate author, see Segment.h for the possible authors @param author enum to indicate author, see Segment.h for the possible
authors
*/ */
MuonSegment( const Amg::Vector2D& segLocPos, // 2 local position coordinates MuonSegment(const Amg::Vector2D& segLocPos, // 2 local position coordinates
const Trk::LocalDirection& segLocDir, // const Trk::LocalDirection& segLocDir, //
const Amg::MatrixX& segLocalErr, // const Amg::MatrixX& segLocalErr, //
Trk::PlaneSurface* psf, // plane surface to define frame Trk::PlaneSurface* psf, // plane surface to define frame
DataVector<const Trk::MeasurementBase>* cmeas, // vector of contained measurements on track DataVector<const Trk::MeasurementBase>*
cmeas, // vector of contained measurements on track
Trk::FitQuality* fqual, // fit quality object Trk::FitQuality* fqual, // fit quality object
Segment::Author author=AuthorUnknown); Segment::Author author = AuthorUnknown);
/** Destructor */ /** Destructor */
virtual ~MuonSegment(); virtual ~MuonSegment();
/** needed to avoid excessive RTTI*/ /** needed to avoid excessive RTTI*/
virtual MuonSegment* clone() const; virtual MuonSegment* clone() const override final;
/** global position */ /** global position */
const Amg::Vector3D& globalPosition() const; virtual const Amg::Vector3D& globalPosition() const override final;
/** global direction */ /** global direction */
const Amg::Vector3D& globalDirection() const; const Amg::Vector3D& globalDirection() const;
...@@ -99,12 +113,13 @@ namespace Muon { ...@@ -99,12 +113,13 @@ namespace Muon {
/** returns the surface for the local to global transformation /** returns the surface for the local to global transformation
- interface from MeasurementBase */ - interface from MeasurementBase */
const Trk::PlaneSurface& associatedSurface() const; virtual const Trk::PlaneSurface& associatedSurface() const override final;
/** number of RIO_OnTracks */ /** number of RIO_OnTracks */
unsigned int numberOfContainedROTs() const; unsigned int numberOfContainedROTs() const;
/** returns the RIO_OnTrack (also known as ROT) objects depending on the integer*/ /** returns the RIO_OnTrack (also known as ROT) objects depending on the
* integer*/
const Trk::RIO_OnTrack* rioOnTrack(unsigned int) const; const Trk::RIO_OnTrack* rioOnTrack(unsigned int) const;
/** set the fitted time and error on the time */ /** set the fitted time and error on the time */
...@@ -116,8 +131,9 @@ namespace Muon { ...@@ -116,8 +131,9 @@ namespace Muon {
/** recalculate the cache */ /** recalculate the cache */
void recalculateCache(); void recalculateCache();
private: private:
/** The global position the surface can be associated to. Cached (not persistified)*/ /** The global position the surface can be associated to. Cached (not
* persistified)*/
Amg::Vector3D m_globalPosition; Amg::Vector3D m_globalPosition;
/** cache global direction, not persistified */ /** cache global direction, not persistified */
...@@ -126,65 +142,78 @@ namespace Muon { ...@@ -126,65 +142,78 @@ namespace Muon {
/** LocalDirection */ /** LocalDirection */
Trk::LocalDirection m_localDirection; Trk::LocalDirection m_localDirection;
/** The plane surface to which the segment parameters are expressed to */
const Trk::PlaneSurface* m_associatedSurface;
/** private method to clear the Trk::MeasurementBase vector */ /** private method to clear the Trk::MeasurementBase vector */
void clearMeasVector(); void clearMeasVector();
protected: protected:
/**returns some information about this RIO_OnTrack/TrackSegment. /**returns some information about this RIO_OnTrack/TrackSegment.
It should be overloaded by any child classes*/ It should be overloaded by any child classes*/
MsgStream& dump( MsgStream& out ) const; virtual MsgStream& dump(MsgStream& out) const override final;
/**returns some information about this RIO_OnTrack/TrackSegment. /**returns some information about this RIO_OnTrack/TrackSegment.
It should be overloaded by any child classes*/ It should be overloaded by any child classes*/
std::ostream& dump( std::ostream& out ) const; virtual std::ostream& dump(std::ostream& out) const override final;
};
};
inline const Amg::Vector3D& MuonSegment::globalPosition() const inline const Amg::Vector3D&
{ MuonSegment::globalPosition() const
{
return m_globalPosition; return m_globalPosition;
} }
inline const Amg::Vector3D& MuonSegment::globalDirection() const inline const Amg::Vector3D&
{ MuonSegment::globalDirection() const
{
return m_globalDirection; return m_globalDirection;
} }
inline const Trk::LocalDirection& MuonSegment::localDirection() const inline const Trk::LocalDirection&
{ MuonSegment::localDirection() const
{
return m_localDirection; return m_localDirection;
} }
inline const Trk::PlaneSurface& MuonSegment::associatedSurface() const inline const Trk::PlaneSurface&
{ return (*m_associatedSurface); } MuonSegment::associatedSurface() const
{
return (*m_associatedSurface);
}
inline MuonSegment* MuonSegment::clone() const inline MuonSegment*
{ MuonSegment::clone() const
{
return new MuonSegment(*this); return new MuonSegment(*this);
} }
inline const Trk::RIO_OnTrack* MuonSegment::rioOnTrack(unsigned int indx) const inline const Trk::RIO_OnTrack*
{ MuonSegment::rioOnTrack(unsigned int indx) const
if (indx<containedMeasurements().size()){ {
const Trk::RIO_OnTrack* rot=dynamic_cast<const Trk::RIO_OnTrack*>(containedMeasurements()[indx]); if (indx < containedMeasurements().size()) {
return rot; const Trk::MeasurementBase* meas = containedMeasurements()[indx];
if (meas->type(Trk::MeasurementBaseType::RIO_OnTrack)) {
return static_cast<const Trk::RIO_OnTrack*>(meas);
} }
else return 0;
} }
return nullptr;
}
inline unsigned int MuonSegment::numberOfContainedROTs() const { inline unsigned int
MuonSegment::numberOfContainedROTs() const
{
return containedMeasurements().size(); return containedMeasurements().size();
} }
inline void MuonSegment::setT0Error(float t0, float t0Error){ inline void
m_time=t0; m_errorTime=t0Error; MuonSegment::setT0Error(float t0, float t0Error)
} {
m_time = t0;
m_errorTime = t0Error;
}
inline bool MuonSegment::hasFittedT0() const { inline bool
MuonSegment::hasFittedT0() const
{
return m_time != MuonSegment::kNoValue; return m_time != MuonSegment::kNoValue;
} }
} }
......
/* /*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/ */
#include "MuonSegment/MuonSegment.h" #include "MuonSegment/MuonSegment.h"
// TrkEvent // TrkEvent
#include "CxxUtils/sincos.h"
#include "EventPrimitives/EventPrimitivesToStringConverter.h"
#include "GeoPrimitives/GeoPrimitivesToStringConverter.h"
#include "TrkEventPrimitives/DefinedParameter.h"
#include "TrkEventPrimitives/FitQuality.h" #include "TrkEventPrimitives/FitQuality.h"
#include "TrkEventPrimitives/LocalParameters.h" #include "TrkEventPrimitives/LocalParameters.h"
#include "TrkEventPrimitives/DefinedParameter.h"
#include "TrkEventPrimitives/ParamDefs.h" #include "TrkEventPrimitives/ParamDefs.h"
#include "TrkRIO_OnTrack/RIO_OnTrack.h" #include "TrkRIO_OnTrack/RIO_OnTrack.h"
#include "CxxUtils/sincos.h"
#include "EventPrimitives/EventPrimitivesToStringConverter.h"
#include "GeoPrimitives/GeoPrimitivesToStringConverter.h"
#include <float.h> #include <cfloat>
#include <iostream> #include <iostream>
namespace Muon { namespace Muon {
const float MuonSegment::kNoValue = FLT_MAX; const float MuonSegment::kNoValue = FLT_MAX;
MuonSegment::MuonSegment() MuonSegment::MuonSegment()
: : Segment()
Segment(), , SpaceTimePointBase(kNoValue, kNoValue, 1.)
SpaceTimePointBase(kNoValue,kNoValue,1.), , Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(nullptr)
m_globalPosition( ), , m_globalPosition()
m_globalDirection( ), , m_globalDirection()
m_localDirection( ), , m_localDirection()
m_associatedSurface( 0 )
{} {}
MuonSegment::MuonSegment(const MuonSegment& seg) MuonSegment::MuonSegment(const MuonSegment& seg)
: : Segment(seg)
Segment(seg), , SpaceTimePointBase(seg)
SpaceTimePointBase(seg), , Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(nullptr)
m_globalPosition( seg.m_globalPosition ), , m_globalPosition(seg.m_globalPosition)
m_globalDirection( seg.m_globalDirection ), , m_globalDirection(seg.m_globalDirection)
m_localDirection ( seg.m_localDirection ), , m_localDirection(seg.m_localDirection)
m_associatedSurface( 0 )
{ {
m_associatedSurface = (seg.m_associatedSurface->associatedDetectorElement()) ? m_associatedSurface = (seg.m_associatedSurface->associatedDetectorElement())
seg.m_associatedSurface : seg.m_associatedSurface->clone(); ? seg.m_associatedSurface
: seg.m_associatedSurface->clone();
} }
MuonSegment& MuonSegment::operator=(const MuonSegment& seg) MuonSegment&
MuonSegment::operator=(const MuonSegment& seg)
{ {
if (this!=&seg){ if (this != &seg) {
Trk::Segment::operator=(seg); Trk::Segment::operator=(seg);
Trk::SpaceTimePointBase::operator=(seg); Trk::SpaceTimePointBase::operator=(seg);
Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>::operator=(seg);
m_globalPosition = seg.m_globalPosition; m_globalPosition = seg.m_globalPosition;
m_globalDirection = seg.m_globalDirection; m_globalDirection = seg.m_globalDirection;
m_localDirection = seg.m_localDirection; m_localDirection = seg.m_localDirection;
// delete & clone the surface only if there's no associated DetectorElement
if (0!=m_associatedSurface && 0==m_associatedSurface->associatedDetectorElement()) delete m_associatedSurface;
m_associatedSurface = (seg.m_associatedSurface->associatedDetectorElement()) ?
seg.m_associatedSurface : seg.m_associatedSurface->clone();
} }
return (*this); return (*this);
} }
MuonSegment::MuonSegment( const Trk::LocalParameters& locpars, MuonSegment::MuonSegment(const Trk::LocalParameters& locpars,
const Amg::MatrixX& locerr, const Amg::MatrixX& locerr,
Trk::PlaneSurface* psf, Trk::PlaneSurface* psf,
DataVector<const Trk::MeasurementBase>* cmeas, DataVector<const Trk::MeasurementBase>* cmeas,
Trk::FitQuality* fqual, Trk::FitQuality* fqual,
Segment::Author author) Segment::Author author)
: : Segment(locpars, locerr, cmeas, fqual, author)
Segment( locpars, locerr, cmeas, fqual,author ), , SpaceTimePointBase(kNoValue, kNoValue, 1.)
SpaceTimePointBase(kNoValue,kNoValue,1.), , Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(psf)
m_globalPosition(), , m_globalPosition()
m_globalDirection(), , m_globalDirection()
m_localDirection(), , m_localDirection()
m_associatedSurface( psf )
{ {
recalculateCache(); recalculateCache();
psf->globalToLocalDirection(m_globalDirection,m_localDirection); psf->globalToLocalDirection(m_globalDirection, m_localDirection);
} }
MuonSegment::MuonSegment(const Amg::Vector2D& locSegPos,
MuonSegment::MuonSegment( const Amg::Vector2D& locSegPos,
const Trk::LocalDirection& locSegDir, const Trk::LocalDirection& locSegDir,
const Amg::MatrixX& locErr, const Amg::MatrixX& locErr,
Trk::PlaneSurface* psf, Trk::PlaneSurface* psf,
DataVector<const Trk::MeasurementBase>* cmeas, DataVector<const Trk::MeasurementBase>* cmeas,
Trk::FitQuality* fqual, Trk::FitQuality* fqual,
Segment::Author author) Segment::Author author)
: : Segment(Trk::LocalParameters(), locErr, cmeas, fqual, author)
Segment( Trk::LocalParameters(), locErr, cmeas, fqual,author ), , SpaceTimePointBase(kNoValue, kNoValue, 1.)
SpaceTimePointBase(kNoValue,kNoValue,1.), , Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(psf)
m_globalPosition( ), , m_globalPosition()
m_globalDirection(), , m_globalDirection()
m_localDirection(locSegDir), , m_localDirection(locSegDir)
m_associatedSurface( psf )
{ {
psf->localToGlobalDirection(locSegDir,m_globalDirection); psf->localToGlobalDirection(locSegDir, m_globalDirection);
Amg::Vector2D lpos(locSegPos[Trk::locX], locSegPos[Trk::locY]); Amg::Vector2D lpos(locSegPos[Trk::locX], locSegPos[Trk::locY]);
m_associatedSurface->localToGlobal(lpos, m_globalDirection, m_globalPosition); m_associatedSurface->localToGlobal(lpos, m_globalDirection, m_globalPosition);
double phi = m_globalDirection.phi(); double phi = m_globalDirection.phi();
double theta = m_globalDirection.theta(); double theta = m_globalDirection.theta();
std::vector<Trk::DefinedParameter > pars; std::vector<Trk::DefinedParameter> pars;
pars.push_back( Trk::DefinedParameter( locSegPos[Trk::locX], Trk::locX) ); pars.emplace_back(locSegPos[Trk::locX], Trk::locX);
pars.push_back( Trk::DefinedParameter( locSegPos[Trk::locY], Trk::locY) ); pars.emplace_back(locSegPos[Trk::locY], Trk::locY);
pars.push_back( Trk::DefinedParameter( phi, Trk::phi) ); pars.emplace_back(phi, Trk::phi);
pars.push_back( Trk::DefinedParameter( theta, Trk::theta) ); pars.emplace_back(theta, Trk::theta);
m_localParams = Trk::LocalParameters( pars ); m_localParams = Trk::LocalParameters(pars);
} }
MuonSegment::~MuonSegment() MuonSegment::~MuonSegment() = default;
{
if ( 0!=m_associatedSurface && !m_associatedSurface->associatedDetectorElement()) delete m_associatedSurface;
}
void MuonSegment::recalculateCache(){ void
MuonSegment::recalculateCache()
{
CxxUtils::sincos scphi(m_localParams[Trk::phi]); CxxUtils::sincos scphi(m_localParams[Trk::phi]);
CxxUtils::sincos sctheta(m_localParams[Trk::theta]); CxxUtils::sincos sctheta(m_localParams[Trk::theta]);
...@@ -122,58 +114,71 @@ void MuonSegment::recalculateCache(){ ...@@ -122,58 +114,71 @@ void MuonSegment::recalculateCache(){
double costheta = sctheta.cs; double costheta = sctheta.cs;
double sinphi = scphi.sn; double sinphi = scphi.sn;
double cosphi = scphi.cs; double cosphi = scphi.cs;
m_globalDirection = Amg::Vector3D( cosphi*sintheta, m_globalDirection =
sinphi*sintheta, Amg::Vector3D(cosphi * sintheta, sinphi * sintheta, costheta);
costheta );
Amg::Vector2D lpos(m_localParams[Trk::locX], m_localParams[Trk::locY]); Amg::Vector2D lpos(m_localParams[Trk::locX], m_localParams[Trk::locY]);
m_associatedSurface->localToGlobal(lpos, m_globalPosition, m_globalPosition); m_associatedSurface->localToGlobal(lpos, m_globalPosition, m_globalPosition);
} }
MsgStream& MuonSegment::dump( MsgStream& out ) const MsgStream&
MuonSegment::dump(MsgStream& out) const
{ {
out << "Muon::MuonSegment " << std::endl; out << "Muon::MuonSegment " << std::endl;
out << " - global position : " << std::endl<<Amg::toString(globalPosition())<<std::endl; out << " - global position : " << std::endl
out << std::endl<<localDirection()<<std::endl; << Amg::toString(globalPosition()) << std::endl;
out << " - local parameters : " << std::endl<<localParameters()<<std::endl; out << std::endl << localDirection() << std::endl;
out << " - local Err Matrix : " ; out << " - local parameters : " << std::endl