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 @@
#define MUONSEGMENT_MUONSEGMENT_H
// Trk
#include "TrkSegment/Segment.h"
#include "TrkEventPrimitives/LocalDirection.h"
#include "TrkEventPrimitives/SurfaceHolderImpl.h"
#include "TrkRIO_OnTrack/RIO_OnTrack.h"
#include "TrkSegment/Segment.h"
#include "TrkSpaceTimePoint/SpaceTimePointBase.h"
#include "TrkSurfaces/PlaneSurface.h"
#include "TrkRIO_OnTrack/RIO_OnTrack.h"
namespace Muon {
/** @class MuonSegment
/** @class MuonSegment
This is the common class for 3D segments used in the muon spectrometer.
......@@ -34,11 +35,15 @@ namespace Muon {
@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:
@author Niels.van.Eldik@cern.ch, Edward.Moyse@cern.ch,
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;
......@@ -48,48 +53,57 @@ namespace Muon {
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.
/** 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 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
@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,
Trk::PlaneSurface* psf,
DataVector<const Trk::MeasurementBase>* cmeas,
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 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
@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 Amg::MatrixX& segLocalErr, //
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
Segment::Author author=AuthorUnknown);
Segment::Author author = AuthorUnknown);
/** Destructor */
virtual ~MuonSegment();
/** needed to avoid excessive RTTI*/
virtual MuonSegment* clone() const;
virtual MuonSegment* clone() const override final;
/** global position */
const Amg::Vector3D& globalPosition() const;
virtual const Amg::Vector3D& globalPosition() const override final;
/** global direction */
const Amg::Vector3D& globalDirection() const;
......@@ -99,12 +113,13 @@ namespace Muon {
/** returns the surface for the local to global transformation
- interface from MeasurementBase */
const Trk::PlaneSurface& associatedSurface() const;
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*/
/** 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 */
......@@ -116,8 +131,9 @@ namespace Muon {
/** recalculate the cache */
void recalculateCache();
private:
/** The global position the surface can be associated to. Cached (not persistified)*/
private:
/** The global position the surface can be associated to. Cached (not
* persistified)*/
Amg::Vector3D m_globalPosition;
/** cache global direction, not persistified */
......@@ -126,65 +142,78 @@ namespace Muon {
/** 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:
protected:
/**returns some information about this RIO_OnTrack/TrackSegment.
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.
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;
}
}
inline const Amg::Vector3D& MuonSegment::globalDirection() const
{
inline const Amg::Vector3D&
MuonSegment::globalDirection() const
{
return m_globalDirection;
}
}
inline const Trk::LocalDirection& MuonSegment::localDirection() const
{
inline const Trk::LocalDirection&
MuonSegment::localDirection() const
{
return m_localDirection;
}
}
inline const Trk::PlaneSurface& MuonSegment::associatedSurface() const
{ return (*m_associatedSurface); }
inline const Trk::PlaneSurface&
MuonSegment::associatedSurface() const
{
return (*m_associatedSurface);
}
inline MuonSegment* MuonSegment::clone() const
{
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::RIO_OnTrack* rot=dynamic_cast<const Trk::RIO_OnTrack*>(containedMeasurements()[indx]);
return rot;
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);
}
else return 0;
}
return nullptr;
}
inline unsigned int MuonSegment::numberOfContainedROTs() const {
inline unsigned int
MuonSegment::numberOfContainedROTs() const
{
return containedMeasurements().size();
}
}
inline void MuonSegment::setT0Error(float t0, float t0Error){
m_time=t0; m_errorTime=t0Error;
}
inline void
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;
}
}
}
......
/*
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"
// TrkEvent
#include "CxxUtils/sincos.h"
#include "EventPrimitives/EventPrimitivesToStringConverter.h"
#include "GeoPrimitives/GeoPrimitivesToStringConverter.h"
#include "TrkEventPrimitives/DefinedParameter.h"
#include "TrkEventPrimitives/FitQuality.h"
#include "TrkEventPrimitives/LocalParameters.h"
#include "TrkEventPrimitives/DefinedParameter.h"
#include "TrkEventPrimitives/ParamDefs.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>
namespace Muon {
const float MuonSegment::kNoValue = FLT_MAX;
MuonSegment::MuonSegment()
:
Segment(),
SpaceTimePointBase(kNoValue,kNoValue,1.),
m_globalPosition( ),
m_globalDirection( ),
m_localDirection( ),
m_associatedSurface( 0 )
: Segment()
, SpaceTimePointBase(kNoValue, kNoValue, 1.)
, Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(nullptr)
, m_globalPosition()
, m_globalDirection()
, m_localDirection()
{}
MuonSegment::MuonSegment(const MuonSegment& seg)
:
Segment(seg),
SpaceTimePointBase(seg),
m_globalPosition( seg.m_globalPosition ),
m_globalDirection( seg.m_globalDirection ),
m_localDirection ( seg.m_localDirection ),
m_associatedSurface( 0 )
: Segment(seg)
, SpaceTimePointBase(seg)
, Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(nullptr)
, m_globalPosition(seg.m_globalPosition)
, m_globalDirection(seg.m_globalDirection)
, m_localDirection(seg.m_localDirection)
{
m_associatedSurface = (seg.m_associatedSurface->associatedDetectorElement()) ?
seg.m_associatedSurface : seg.m_associatedSurface->clone();
m_associatedSurface = (seg.m_associatedSurface->associatedDetectorElement())
? 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::SpaceTimePointBase::operator=(seg);
Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>::operator=(seg);
m_globalPosition = seg.m_globalPosition;
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;
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,
Trk::PlaneSurface* psf,
DataVector<const Trk::MeasurementBase>* cmeas,
Trk::FitQuality* fqual,
Segment::Author author)
:
Segment( locpars, locerr, cmeas, fqual,author ),
SpaceTimePointBase(kNoValue,kNoValue,1.),
m_globalPosition(),
m_globalDirection(),
m_localDirection(),
m_associatedSurface( psf )
: Segment(locpars, locerr, cmeas, fqual, author)
, SpaceTimePointBase(kNoValue, kNoValue, 1.)
, Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(psf)
, m_globalPosition()
, m_globalDirection()
, m_localDirection()
{
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 Amg::MatrixX& locErr,
Trk::PlaneSurface* psf,
DataVector<const Trk::MeasurementBase>* cmeas,
Trk::FitQuality* fqual,
Segment::Author author)
:
Segment( Trk::LocalParameters(), locErr, cmeas, fqual,author ),
SpaceTimePointBase(kNoValue,kNoValue,1.),
m_globalPosition( ),
m_globalDirection(),
m_localDirection(locSegDir),
m_associatedSurface( psf )
: Segment(Trk::LocalParameters(), locErr, cmeas, fqual, author)
, SpaceTimePointBase(kNoValue, kNoValue, 1.)
, Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(psf)
, m_globalPosition()
, m_globalDirection()
, m_localDirection(locSegDir)
{
psf->localToGlobalDirection(locSegDir,m_globalDirection);
psf->localToGlobalDirection(locSegDir, m_globalDirection);
Amg::Vector2D lpos(locSegPos[Trk::locX], locSegPos[Trk::locY]);
m_associatedSurface->localToGlobal(lpos, m_globalDirection, m_globalPosition);
double phi = m_globalDirection.phi();
double theta = m_globalDirection.theta();
std::vector<Trk::DefinedParameter > pars;
pars.push_back( Trk::DefinedParameter( locSegPos[Trk::locX], Trk::locX) );
pars.push_back( Trk::DefinedParameter( locSegPos[Trk::locY], Trk::locY) );
pars.push_back( Trk::DefinedParameter( phi, Trk::phi) );
pars.push_back( Trk::DefinedParameter( theta, Trk::theta) );
m_localParams = Trk::LocalParameters( pars );
std::vector<Trk::DefinedParameter> pars;
pars.emplace_back(locSegPos[Trk::locX], Trk::locX);
pars.emplace_back(locSegPos[Trk::locY], Trk::locY);
pars.emplace_back(phi, Trk::phi);
pars.emplace_back(theta, Trk::theta);
m_localParams = Trk::LocalParameters(pars);
}
MuonSegment::~MuonSegment()
{
if ( 0!=m_associatedSurface && !m_associatedSurface->associatedDetectorElement()) delete m_associatedSurface;
}
MuonSegment::~MuonSegment() = default;
void MuonSegment::recalculateCache(){
void
MuonSegment::recalculateCache()
{
CxxUtils::sincos scphi(m_localParams[Trk::phi]);
CxxUtils::sincos sctheta(m_localParams[Trk::theta]);
......@@ -122,58 +114,71 @@ void MuonSegment::recalculateCache(){
double costheta = sctheta.cs;
double sinphi = scphi.sn;
double cosphi = scphi.cs;
m_globalDirection = Amg::Vector3D( cosphi*sintheta,
sinphi*sintheta,
costheta );
m_globalDirection =
Amg::Vector3D(cosphi * sintheta, sinphi * sintheta, costheta);
Amg::Vector2D lpos(m_localParams[Trk::locX], m_localParams[Trk::locY]);
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 << " - global position : " << std::endl<<Amg::toString(globalPosition())<<std::endl;
out << std::endl<<localDirection()<<std::endl;
out << " - local parameters : " << std::endl<<localParameters()<<std::endl;
out << " - local Err Matrix : " ;
out << std::endl<<Amg::toString(localCovariance())<<std::endl;
if (0!=m_fitQuality)
out << " - fit Quality : " << std::endl<<(*fitQuality())<<std::endl;
out << " - global position : " << std::endl
<< Amg::toString(globalPosition()) << std::endl;
out << std::endl << localDirection() << std::endl;
out << " - local parameters : " << std::endl
<< localParameters() << std::endl;
out << " - local Err Matrix : ";
out << std::endl << Amg::toString(localCovariance()) << std::endl;
if (nullptr != m_fitQuality)
out << " - fit Quality : " << std::endl
<< (*fitQuality()) << std::endl;
else
out << " - fit Quality : NO " <<std::endl;
out << " - associated Surface : " << std::endl<<associatedSurface()<<std::endl;
out << " - t0 (error) : "<<time()<<"("<<errorTime()<<")"<<std::endl;
out << " - it contains : " << numberOfContainedROTs() << " RIO_OnTrack object" << std::endl;
unsigned int numRoT=1;
out << " - fit Quality : NO " << std::endl;
out << " - associated Surface : " << std::endl
<< associatedSurface() << std::endl;
out << " - t0 (error) : " << time() << "(" << errorTime() << ")"
<< std::endl;
out << " - it contains : " << numberOfContainedROTs()
<< " RIO_OnTrack object" << std::endl;
unsigned int numRoT = 1;
for (const Trk::MeasurementBase* m : containedMeasurements()) {
const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(m);
if (rot) {
out << "RoT "<<numRoT++<<std::endl<<*rot<<std::endl;
out << "RoT " << numRoT++ << std::endl << *rot << std::endl;
}
}
return out;
}
std::ostream& MuonSegment::dump( std::ostream& out ) const
std::ostream&
MuonSegment::dump(std::ostream& out) const
{
out << "Muon::MuonSegment " << std::endl;
out << " - global position : " << std::endl<<Amg::toString(globalPosition())<<std::endl;
out << std::endl<<localDirection()<<std::endl;
out << " - local parameters : " << std::endl<<localParameters()<<std::endl;
out << " - local Err Matrix : " ;
out << std::endl<<Amg::toString(localCovariance())<<std::endl;
if (0!=m_fitQuality)
out << " - fit Quality : " << std::endl<<(*fitQuality())<<std::endl;
out << " - global position : " << std::endl
<< Amg::toString(globalPosition()) << std::endl;
out << std::endl << localDirection() << std::endl;
out << " - local parameters : " << std::endl
<< localParameters() << std::endl;
out << " - local Err Matrix : ";
out << std::endl << Amg::toString(localCovariance()) << std::endl;
if (nullptr != m_fitQuality)
out << " - fit Quality : " << std::endl
<< (*fitQuality()) << std::endl;
else
out << " - fit Quality : NO " <<std::endl;
out << " - associated Surface : " << std::endl<<associatedSurface()<<std::endl;
out << " - t0 (error) : "<<time()<<"("<<errorTime()<<")"<<std::endl;
out << " - it contains : " << numberOfContainedROTs() << " RIO_OnTrack object" << std::endl;
unsigned int numRoT=1;
out << " - fit Quality : NO " << std::endl;
out << " - associated Surface : " << std::endl
<< associatedSurface() << std::endl;
out << " - t0 (error) : " << time() << "(" << errorTime() << ")"
<< std::endl;
out << " - it contains : " << numberOfContainedROTs()
<< " RIO_OnTrack object" << std::endl;
unsigned int numRoT = 1;
for (const Trk::MeasurementBase* m : containedMeasurements()) {
const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(m);
if (rot) {
out << "RoT "<<numRoT++<<std::endl<<*rot<<std::endl;
out << "RoT " << numRoT++ << std::endl << *rot << std::endl;
}
}
return out;
......@@ -181,4 +186,3 @@ std::ostream& MuonSegment::dump( std::ostream& out ) const
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment