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,181 +10,210 @@ ...@@ -10,181 +10,210 @@
#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.
The Surface type for MuonSegments is restricted to be a PlaneSurface.
The parameters of the MuonSegment are:
- the Trk::LocalPosition of the segment in the surface reference frame
- the Trk::LocalDirection of the segment which consistes of the angles
@f$ \theta_{xz} @f$ and @f$\theta_{yz}@f$.
The MuonSegment stores a list of Trk::MeasurementBase objects allowing it to
contain measurements from all detector types in the muon spectrometer.
@image html segment_example.gif
@image html MuonSegment.gif
@author Niels.van.Eldik@cern.ch, Edward.Moyse@cern.ch, Andreas.Salzburger@cern.ch
*/
class MuonSegment : public Trk::Segment, public Trk::SpaceTimePointBase {
public:
/** define invalid value, used when the segment has no fitted t0 */
static const float kNoValue;
/** Default Constructor for POOL */
MuonSegment();
/** Copy Constructor */
MuonSegment(const MuonSegment& seg);
/** Assignment operator */
MuonSegment& operator=(const MuonSegment& seg);
/** Constructor within standard track parameters frame taking a vector of MeasurementBase.
@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 psf plane surface
@param cmeas vector of contained measurements on track
@param fqual fit quality object
@param author enum to indicate author, see Segment.h for the possible authors
*/
MuonSegment( const Trk::LocalParameters& locpars,
const Amg::MatrixX& locerr,
Trk::PlaneSurface* psf,
DataVector<const Trk::MeasurementBase>* cmeas,
Trk::FitQuality* fqual,
Segment::Author author=AuthorUnknown
);
/** Constructor within local parameters of the Segment taking a vector of MeasurementBase
@param segLocPos 2 local position coordinates
@param segLocalErr 2 local direction coordinates
@param segLocalErr 4 x 4 full local error
@param psf plane surface
@param cmeas vector of contained measurements on track
@param fqual fit quality object
@param author enum to indicate author, see Segment.h for the possible authors
*/
MuonSegment( const Amg::Vector2D& segLocPos, // 2 local position coordinates
const Trk::LocalDirection& segLocDir, //
const Amg::MatrixX& segLocalErr, //
Trk::PlaneSurface* psf, // plane surface to define frame
DataVector<const Trk::MeasurementBase>* cmeas, // vector of contained measurements on track
Trk::FitQuality* fqual, // fit quality object
Segment::Author author=AuthorUnknown);
/** Destructor */
virtual ~MuonSegment();
/** needed to avoid excessive RTTI*/
virtual MuonSegment* clone() const;
/** global position */
const Amg::Vector3D& globalPosition() const;
/** global direction */
const Amg::Vector3D& globalDirection() const;
/** local direction */
const Trk::LocalDirection& localDirection() const;
/** returns the surface for the local to global transformation
- interface from MeasurementBase */
const Trk::PlaneSurface& associatedSurface() const;
/** number of RIO_OnTracks */
unsigned int numberOfContainedROTs() const;
/** returns the RIO_OnTrack (also known as ROT) objects depending on the integer*/
const Trk::RIO_OnTrack* rioOnTrack(unsigned int) const;
/** set the fitted time and error on the time */
void setT0Error(float t0, float t0Error);
/** returns whether the segment has a fitted t0 */
bool hasFittedT0() const;
/** recalculate the cache */
void recalculateCache();
private:
/** The global position the surface can be associated to. Cached (not persistified)*/
Amg::Vector3D m_globalPosition;
/** cache global direction, not persistified */
Amg::Vector3D m_globalDirection;
/** 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 */
void clearMeasVector();
protected:
/**returns some information about this RIO_OnTrack/TrackSegment.
It should be overloaded by any child classes*/
MsgStream& dump( MsgStream& out ) const;
/**returns some information about this RIO_OnTrack/TrackSegment.
It should be overloaded by any child classes*/
std::ostream& dump( std::ostream& out ) const;
};
inline const Amg::Vector3D& MuonSegment::globalPosition() const
{
return m_globalPosition;
}
inline const Amg::Vector3D& MuonSegment::globalDirection() const This is the common class for 3D segments used in the muon spectrometer.
{
return m_globalDirection;
}
inline const Trk::LocalDirection& MuonSegment::localDirection() const The Surface type for MuonSegments is restricted to be a PlaneSurface.
{ The parameters of the MuonSegment are:
return m_localDirection; - the Trk::LocalPosition of the segment in the surface reference frame
} - the Trk::LocalDirection of the segment which consistes of the angles
@f$ \theta_{xz} @f$ and @f$\theta_{yz}@f$.
inline const Trk::PlaneSurface& MuonSegment::associatedSurface() const The MuonSegment stores a list of Trk::MeasurementBase objects allowing it to
{ return (*m_associatedSurface); } contain measurements from all detector types in the muon spectrometer.
inline MuonSegment* MuonSegment::clone() const @image html segment_example.gif
{ @image html MuonSegment.gif
return new MuonSegment(*this);
}
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]);
return rot;
}
else return 0;
}
inline unsigned int MuonSegment::numberOfContainedROTs() const {
return containedMeasurements().size();
}
inline void MuonSegment::setT0Error(float t0, float t0Error){ @author Niels.van.Eldik@cern.ch, Edward.Moyse@cern.ch,
m_time=t0; m_errorTime=t0Error; Andreas.Salzburger@cern.ch
} */
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 */
static const float kNoValue;
/** Default Constructor for POOL */
MuonSegment();
/** Copy Constructor */
MuonSegment(const MuonSegment& seg);
/** Assignment operator */
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.
@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 psf plane surface
@param cmeas vector of contained measurements on track
@param fqual fit quality object
@param author enum to indicate author, see Segment.h for the possible
authors
*/
MuonSegment(const Trk::LocalParameters& locpars,
const Amg::MatrixX& locerr,
Trk::PlaneSurface* psf,
DataVector<const Trk::MeasurementBase>* cmeas,
Trk::FitQuality* fqual,
Segment::Author author = AuthorUnknown);
/** Constructor within local parameters of the Segment taking a vector of
MeasurementBase
@param segLocPos 2 local position coordinates
@param segLocalErr 2 local direction coordinates
@param segLocalErr 4 x 4 full local error
@param psf plane surface
@param cmeas vector of contained measurements on track
@param fqual fit quality object
@param author enum to indicate author, see Segment.h for the possible
authors
*/
MuonSegment(const Amg::Vector2D& segLocPos, // 2 local position coordinates
const Trk::LocalDirection& segLocDir, //
const Amg::MatrixX& segLocalErr, //
Trk::PlaneSurface* psf, // plane surface to define frame
DataVector<const Trk::MeasurementBase>*
cmeas, // vector of contained measurements on track
Trk::FitQuality* fqual, // fit quality object
Segment::Author author = AuthorUnknown);
/** Destructor */
virtual ~MuonSegment();
/** needed to avoid excessive RTTI*/
virtual MuonSegment* clone() const override final;
/** global position */
virtual const Amg::Vector3D& globalPosition() const override final;
/** global direction */
const Amg::Vector3D& globalDirection() const;
/** local direction */
const Trk::LocalDirection& localDirection() const;
/** returns the surface for the local to global transformation
- interface from MeasurementBase */
virtual const Trk::PlaneSurface& associatedSurface() const override final;
/** number of RIO_OnTracks */
unsigned int numberOfContainedROTs() const;
/** returns the RIO_OnTrack (also known as ROT) objects depending on the
* integer*/
const Trk::RIO_OnTrack* rioOnTrack(unsigned int) const;
/** set the fitted time and error on the time */
void setT0Error(float t0, float t0Error);
/** returns whether the segment has a fitted t0 */
bool hasFittedT0() const;
/** recalculate the cache */
void recalculateCache();
private:
/** The global position the surface can be associated to. Cached (not
* persistified)*/
Amg::Vector3D m_globalPosition;
/** cache global direction, not persistified */
Amg::Vector3D m_globalDirection;
/** LocalDirection */
Trk::LocalDirection m_localDirection;
/** private method to clear the Trk::MeasurementBase vector */
void clearMeasVector();
protected:
/**returns some information about this RIO_OnTrack/TrackSegment.
It should be overloaded by any child classes*/
virtual MsgStream& dump(MsgStream& out) const override final;
/**returns some information about this RIO_OnTrack/TrackSegment.
It should be overloaded by any child classes*/
virtual std::ostream& dump(std::ostream& out) const override final;
};
inline const Amg::Vector3D&
MuonSegment::globalPosition() const
{
return m_globalPosition;
}
inline const Amg::Vector3D&
MuonSegment::globalDirection() const
{
return m_globalDirection;
}
inline bool MuonSegment::hasFittedT0() const { inline const Trk::LocalDirection&
return m_time != MuonSegment::kNoValue; MuonSegment::localDirection() const
{
return m_localDirection;
}
inline const Trk::PlaneSurface&
MuonSegment::associatedSurface() const
{
return (*m_associatedSurface);
}
inline MuonSegment*
MuonSegment::clone() const
{
return new MuonSegment(*this);
}
inline const Trk::RIO_OnTrack*
MuonSegment::rioOnTrack(unsigned int indx) const
{
if (indx < containedMeasurements().size()) {
const Trk::MeasurementBase* meas = containedMeasurements()[indx];
if (meas->type(Trk::MeasurementBaseType::RIO_OnTrack)) {
return static_cast<const Trk::RIO_OnTrack*>(meas);
}
} }
return nullptr;
}
inline unsigned int
MuonSegment::numberOfContainedROTs() const
{
return containedMeasurements().size();
}
inline void
MuonSegment::setT0Error(float t0, float t0Error)
{
m_time = t0;
m_errorTime = t0Error;
}
inline bool
MuonSegment::hasFittedT0() const
{
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);
m_globalPosition = seg.m_globalPosition; Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>::operator=(seg);
m_globalDirection = seg.m_globalDirection; m_globalPosition = seg.m_globalPosition;
m_localDirection = seg.m_localDirection; m_globalDirection = seg.m_globalDirection;
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; return (*this);
m_associatedSurface = (seg.m_associatedSurface->associatedDetectorElement()) ?
seg.m_associatedSurface : seg.m_associatedSurface->clone();
}
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)
: , SpaceTimePointBase(kNoValue, kNoValue, 1.)
Segment( Trk::LocalParameters(), locErr, cmeas, fqual,author ), , Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(psf)
SpaceTimePointBase(kNoValue,kNoValue,1.), , 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);