Commit 2b5b7205 authored by Atlas-Software Librarian's avatar Atlas-Software Librarian Committed by Graeme Stewart
Browse files

'CMakeLists.txt' (MuonResidualPullCalculators-01-00-00)

parent 0b0f004a
################################################################################
# Package: MuonResidualPullCalculators
################################################################################
# Declare the package name:
atlas_subdir( MuonResidualPullCalculators )
# Declare the package's dependencies:
atlas_depends_on_subdirs( PRIVATE
Control/AthenaBaseComps
Event/EventPrimitives
GaudiKernel
MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry
MuonSpectrometer/MuonIdHelpers
MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonCompetingRIOsOnTrack
Tracking/TrkEvent/TrkEventPrimitives
Tracking/TrkEvent/TrkEventUtils
Tracking/TrkEvent/TrkParameters
Tracking/TrkEvent/TrkRIO_OnTrack
Tracking/TrkTools/TrkToolInterfaces )
# Component(s) in the package:
atlas_add_component( MuonResidualPullCalculators
src/*.cxx
src/components/*.cxx
LINK_LIBRARIES AthenaBaseComps EventPrimitives GaudiKernel MuonReadoutGeometry MuonIdHelpersLib MuonCompetingRIOsOnTrack TrkEventPrimitives TrkEventUtils TrkParameters TrkRIO_OnTrack TrkToolInterfaces )
# Install files from the package:
atlas_install_headers( MuonResidualPullCalculators )
package MuonResidualPullCalculators
author Wolfgang Liebig <Wolfgang.Liebig@cern.ch>
public
use AtlasPolicy AtlasPolicy-*
apply_pattern component_library
library MuonResidualPullCalculators *.cxx components/*.cxx
private
use GaudiInterface GaudiInterface-* External
use TrkEventUtils TrkEventUtils-* Tracking/TrkEvent
use MuonIdHelpers MuonIdHelpers-* MuonSpectrometer
use TrkRIO_OnTrack TrkRIO_OnTrack-* Tracking/TrkEvent
use MuonCompetingRIOsOnTrack MuonCompetingRIOsOnTrack-* MuonSpectrometer/MuonReconstruction/MuonRecEvent
use EventPrimitives EventPrimitives-* Event
use AthenaBaseComps AthenaBaseComps-* Control
use TrkEventPrimitives TrkEventPrimitives-* Tracking/TrkEvent
use TrkParameters TrkParameters-* Tracking/TrkEvent
use TrkToolInterfaces TrkToolInterfaces-* Tracking/TrkTools
use MuonReadoutGeometry MuonReadoutGeometry-* MuonSpectrometer/MuonDetDescr
#macro cppdebugflags '$(cppdebugflags_s)'
#macro_remove componentshr_linkopts "-Wl,-s"
#macro cppdebugflags '$(cppdebugflags_s)'
#macro_remove componentshr_linkopts "-Wl,-s"
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/**
@mainpage MuonResidualPullCalculators Package
This package extends the residual calculation tools from
the Tracking realm towards MuonSpectrometer-specific
functionality, i.e. it allows to recognise different
eta/phi chamber orientation and stereo angles between strips
in order to calculate the residual correctly.
@author Wolfgang Liebig <http://consult.cern.ch/xwho/people/54608>
@section MuonResidualPullCalculatorsUsage Usage
To have hit residuals and pull calculated for any kind
of hits on (Muon) tracks, please use from the Tracking
realm:
<pre>
ToolHandle<Trk::IResidualPullCalculator>
</pre>
configured as
<pre>
from TrkValTools.TrkValToolsConf import Trk__ResidualPullCalculator
MuonResPullCalculator = Trk__ResidualPullCalculator(
name = 'MuonResPullCalculator',
ResidualPullCalculatorForSCT = None,
ResidualPullCalculatorForRPC = 'Muon::RPC_ResidualPullCalculator/RPC_ResidualPullCalculator',
ResidualPullCalculatorForTGC = 'Muon::TGC_ResidualPullCalculator/TGC_ResidualPullCalculator')
ToolSvc += MuonResPullCalculator
</pre>
@section ExtrasMuonResidualPullCalculators Extra Pages
- @ref UsedMuonResidualPullCalculators
- @ref RequirementsMuonResidualPullCalculators
*/
/**
@page UsedMuonResidualPullCalculators Used Packages
@htmlinclude used_packages.html
*/
/**
@page RequirementsMuonResidualPullCalculators Requirements
@include requirements
*/
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// RPC_ResidualPullCalculator.cxx, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////
#include "RPC_ResidualPullCalculator.h"
#include "TrkEventUtils/IdentifierExtractor.h"
#include "TrkEventPrimitives/LocalParameters.h"
#include "MuonIdHelpers/MuonIdHelperTool.h"
#include "MuonIdHelpers/RpcIdHelper.h"
//================ Constructor =================================================
Muon::RPC_ResidualPullCalculator::RPC_ResidualPullCalculator(const std::string& t,
const std::string& n,
const IInterface* p )
:
AthAlgTool(t,n,p),
m_idHelper("Muon::MuonIdHelperTool/MuonIdHelperTool")
{
declareInterface<IResidualPullCalculator>(this);
}
//================ Destructor =================================================
Muon::RPC_ResidualPullCalculator::~RPC_ResidualPullCalculator()
{}
//================ Initialisation =================================================
StatusCode Muon::RPC_ResidualPullCalculator::initialize()
{
StatusCode sc = AlgTool::initialize();
if (sc.isFailure()) return sc;
sc = m_idHelper.retrieve();
if (sc.isFailure()) {
ATH_MSG_ERROR (" Cannot retrieve " << m_idHelper);
return StatusCode::FAILURE;
}
ATH_MSG_DEBUG ("initialize() successful in " << name());
return StatusCode::SUCCESS;
}
//================ Finalisation =================================================
StatusCode Muon::RPC_ResidualPullCalculator::finalize()
{
StatusCode sc = AlgTool::finalize();
return sc;
}
//================ calculate residuals for RPC ==================================
void Muon::RPC_ResidualPullCalculator::residuals(
std::vector<double> &residuals,
const Trk::MeasurementBase* measurement,
const Trk::TrackParameters* trkPar,
const Trk::ResidualPull::ResidualType /*resType*/,
const Trk::TrackState::MeasurementType) const {
if (!trkPar || !measurement) return;
if (residuals.size()<1) residuals.resize(1);
Identifier ID = Trk::IdentifierExtractor::extract(measurement);
if( ID.is_valid() && m_idHelper->isRpc(ID) ) {
if (measurement->localParameters().parameterKey() == 1) {
// convention to be interpreted by TrkValTools: 2nd coordinate codes orientation of RPC
residuals[Trk::loc1] = measurement->localParameters()[Trk::loc1]
- trkPar->parameters()[Trk::loc1];
} else {
ATH_MSG_WARNING ( "RPC ClusterOnTrack does not carry the expected "
<< "LocalParameters structure!" );
return;
}
} else {
ATH_MSG_DEBUG ( "Input problem measurement is not RPC." );
return;
}
}
//================ calculate residuals and pulls for RPC ==================================
const Trk::ResidualPull* Muon::RPC_ResidualPullCalculator::residualPull(
const Trk::MeasurementBase* measurement,
const Trk::TrackParameters* trkPar,
const Trk::ResidualPull::ResidualType resType,
const Trk::TrackState::MeasurementType) const {
if (!trkPar || !measurement) return 0;
Identifier ID = Trk::IdentifierExtractor::extract(measurement);
if( ID.is_valid() && m_idHelper->isRpc(ID) ) {
// if no covariance for the track parameters is given the pull calculation is not valid
const AmgSymMatrix(5)* trkCov = trkPar->covariance();
bool pullIsValid = (trkCov);
// calculate residual
std::vector<double> residual(1);
std::vector<double> pull(1);
if (measurement->localParameters().parameterKey() == 1) {
// convention to be interpreted by TrkValTools: 2nd coordinate codes orientation of RPC
residual[Trk::loc1] = measurement->localParameters()[Trk::loc1]
- trkPar->parameters()[Trk::loc1];
} else {
ATH_MSG_WARNING ( "RPC ClusterOnTrack does not carry the expected "
<< "LocalParameters structure!" );
return 0;
}
// calculate pull
if (pullIsValid)
pull[Trk::loc1] = calcPull(residual[Trk::loc1],
measurement->localCovariance()(Trk::loc1,Trk::loc1),
(*trkCov)(Trk::loc1,Trk::loc1),
resType);
else
pull[Trk::loc1] = calcPull(residual[Trk::loc1],
measurement->localCovariance()(Trk::loc1,Trk::loc1),
0,
resType);
// create the Trk::ResidualPull.
ATH_MSG_DEBUG ( "Calculating Pull for channel " << m_idHelper->toString(ID) << " residual " << residual[Trk::loc1] << " pull " << pull[Trk::loc1] );
return new Trk::ResidualPull(residual, pull, pullIsValid, resType, 1);
} else {
ATH_MSG_DEBUG ( "Input problem measurement is not RPC." );
return 0;
}
}
/////////////////////////////////////////////////////////////////////////////
/// calc pull in 1 dimension
/////////////////////////////////////////////////////////////////////////////
double Muon::RPC_ResidualPullCalculator::calcPull(
const double residual,
const double locMesCov,
const double locTrkCov,
const Trk::ResidualPull::ResidualType& resType ) const {
double ErrorSum(0.0);
if (resType == Trk::ResidualPull::Unbiased) {
if( locMesCov + locTrkCov > 0 ) ErrorSum = sqrt(locMesCov + locTrkCov);
} else if (resType == Trk::ResidualPull::Biased) {
if ((locMesCov - locTrkCov) < 0.) {
return 0;
}
ErrorSum = sqrt(locMesCov - locTrkCov);
} else ErrorSum = sqrt(locMesCov);
if (ErrorSum != 0) return residual/ErrorSum;
return 0;
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// RPC_ResidualPullCalculator.h, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////
// W. Liebig <http://consult.cern.ch/xwho/people/54608>
// muon version adapted from S. Fleischmann's SCT tool
///////////////////////////////////////////////////////////////////
#ifndef MUONRPC_RESIDUALPULLCALCULATOR_H
#define MUONRPC_RESIDUALPULLCALCULATOR_H
// interfaces
#include "AthenaBaseComps/AthAlgTool.h"
#include "GaudiKernel/ToolHandle.h"
#include "TrkToolInterfaces/IResidualPullCalculator.h"
// edm
#include "TrkParameters/TrackParameters.h"
#include "TrkEventPrimitives/ResidualPull.h"
namespace Muon { class MuonIdHelperTool;}
namespace Muon
{
/** @brief RPC-specific tool to calculate hit residual and pull from a RIO_OnTrack/TrackParameter pair
Uses Muon-specific info to code the strip type (measuring phi/eta)
in the 2nd coordinate of the residual.
@author Wolfgang Liebig <http://consult.cern.ch/xwho/people/54608>
*/
class RPC_ResidualPullCalculator : virtual public Trk::IResidualPullCalculator, public AthAlgTool
{
public:
//! standard AlgTool constructor
RPC_ResidualPullCalculator(const std::string&,const std::string&,const IInterface*);
//! default destructor
virtual ~RPC_ResidualPullCalculator ();
//! standard Athena-Algorithm method
virtual StatusCode initialize();
//! standard Athena-Algorithm method
virtual StatusCode finalize ();
/**
@brief This function returns (creates!) a Trk::ResidualPull object, which contains the values
of residual and pull for the given measurement and track state.
The track state can be an unbiased one (which can be retrieved by the Trk::IUpdator),
a biased one (which contains the measurement), or a truth state.
The enum ResidualType must be set according to this, otherwise the pulls will be wrong.
Residuals differ in all three cases; please be aware of this!
*/
virtual const Trk::ResidualPull* residualPull(
const Trk::MeasurementBase* measurement,
const Trk::TrackParameters* trkPar,
const Trk::ResidualPull::ResidualType,
const Trk::TrackState::MeasurementType) const;
/** This function is a light-weight version of the function above, designed for track fitters
* where speed is critical. The user has to provide a std::vector of size 5, which gets
* filled with the residuals.
*/
virtual void residuals(
std::vector<double>& residuals,
const Trk::MeasurementBase* measurement,
const Trk::TrackParameters* trkPar,
const Trk::ResidualPull::ResidualType,
const Trk::TrackState::MeasurementType) const;
private:
//! MuonIdHelper
ToolHandle<Muon::MuonIdHelperTool> m_idHelper;
//! internal structuring: common method to calculate the hit pull.
double calcPull(const double residual,
const double locMesCov,
const double locTrkCov,
const Trk::ResidualPull::ResidualType& ) const;
};
} // end of namespace
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// TGC_ResidualPullCalculator.cxx, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////
#include "TGC_ResidualPullCalculator.h"
#include "TrkRIO_OnTrack/RIO_OnTrack.h"
// muon-specific actions
#include "MuonReadoutGeometry/TgcReadoutElement.h"
#include "MuonCompetingRIOsOnTrack/CompetingMuonClustersOnTrack.h"
#include "MuonIdHelpers/MuonIdHelperTool.h"
#include "MuonIdHelpers/TgcIdHelper.h"
// matrix stuff for matrix transformation of tgc errors
#include "EventPrimitives/EventPrimitives.h"
//================ Constructor =================================================
Muon::TGC_ResidualPullCalculator::TGC_ResidualPullCalculator(const std::string& t,
const std::string& n,
const IInterface* p )
:
AthAlgTool(t,n,p),
m_idHelper("Muon::MuonIdHelperTool/MuonIdHelperTool")
{
declareInterface<IResidualPullCalculator>(this);
}
//================ Destructor =================================================
Muon::TGC_ResidualPullCalculator::~TGC_ResidualPullCalculator()
{}
//================ Initialisation =================================================
StatusCode Muon::TGC_ResidualPullCalculator::initialize()
{
StatusCode sc = AthAlgTool::initialize();
if (sc.isFailure()) return sc;
sc = m_idHelper.retrieve();
if (sc.isFailure()) {
ATH_MSG_ERROR (" Cannot retrieve " << m_idHelper);
return StatusCode::FAILURE;
}
ATH_MSG_DEBUG ("initialize() successful in " << name());
return StatusCode::SUCCESS;
}
//================ Finalisation =================================================
StatusCode Muon::TGC_ResidualPullCalculator::finalize()
{
StatusCode sc = AthAlgTool::finalize();
return sc;
}
//================ calculate residuals for TGC ==================================
void Muon::TGC_ResidualPullCalculator::residuals(
std::vector<double>& residuals,
const Trk::MeasurementBase* measurement,
const Trk::TrackParameters* trkPar,
const Trk::ResidualPull::ResidualType /*resType*/,
const Trk::TrackState::MeasurementType) const {
if (residuals.size()<1) residuals.resize(1);
const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(measurement);
if (!rot) {
const Muon::CompetingMuonClustersOnTrack* muonCompClusters =
dynamic_cast<const Muon::CompetingMuonClustersOnTrack*>(measurement);
if (muonCompClusters) rot = muonCompClusters->containedROTs().empty() ? 0 :
muonCompClusters->containedROTs().front();
}
if (!trkPar || !rot) {
if( !trkPar ) ATH_MSG_WARNING ("No TrackParameters, cannot calculate residual/pull ");
if( !rot ) ATH_MSG_WARNING ("No ROT, cannot calculate residual/pull ");
return;
}
Identifier ID = rot->identify();
if( m_idHelper->isTgc(ID) ) {
double sinAlpha = 0.0;
bool isStrip = m_idHelper->tgcIdHelper().isStrip(ID);
// calculate residual
if (isStrip) {
// consistency check that Muon EDM is as expected
if (measurement->localParameters().parameterKey() !=3) {
ATH_MSG_WARNING ( "TGC ClusterOnTrack does not carry the expected "
<< "LocalParameters structure!");
return;
}
// get orientation angle of strip to rotate back from local frame to strip
const Amg::MatrixX &covmat=measurement->localCovariance();
double v0=0.5*(covmat(0,0)+covmat(1,1)-sqrt((covmat(0,0)+covmat(1,1))*(covmat(0,0)+covmat(1,1))-
4*(covmat(0,0)*covmat(1,1)-covmat(0,1)*covmat(0,1))));
double v1=0.5*(covmat(0,0)+covmat(1,1)+sqrt((covmat(0,0)+covmat(1,1))*(covmat(0,0)+covmat(1,1))-
4*(covmat(0,0)*covmat(1,1)-covmat(0,1)*covmat(0,1))));
sinAlpha=sin(0.5*asin(2*covmat(0,1)/(v0-v1)));
double cosAlpha = sqrt(1 - sinAlpha*sinAlpha);
// Calculate Residual for hit: res = (vec(x_hit) - vec(x_track)) * vec(n_perpendicular)
residuals[Trk::loc1] =
(measurement->localParameters()[Trk::locX] - trkPar->parameters()[Trk::locX]) * cosAlpha
+ (measurement->localParameters()[Trk::locY] - trkPar->parameters()[Trk::locY]) * sinAlpha;
} else {
if (measurement->localParameters().parameterKey() != 1) {
ATH_MSG_WARNING ("TGC ClusterOnTrack does not carry the expected "
<< "LocalParameters structure!" );
return;
} else {
// convention to be interpreted by TrkValTools: 2nd coordinate codes orientation of TGC
residuals[Trk::loc1] = measurement->localParameters()[Trk::loc1]
- trkPar->parameters()[Trk::loc1];
}
}
} else {
ATH_MSG_DEBUG ( "Input problem measurement is not TGC." );
return;
}
}
//================ calculate residuals and pulls for TGC ==================================
const Trk::ResidualPull* Muon::TGC_ResidualPullCalculator::residualPull(
const Trk::MeasurementBase* measurement,
const Trk::TrackParameters* trkPar,
const Trk::ResidualPull::ResidualType resType,
const Trk::TrackState::MeasurementType) const {
const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(measurement);
if (!rot) {
const Muon::CompetingMuonClustersOnTrack* muonCompClusters =
dynamic_cast<const Muon::CompetingMuonClustersOnTrack*>(measurement);
if (muonCompClusters) rot = muonCompClusters->containedROTs().empty() ? 0 :
muonCompClusters->containedROTs().front();
}
if (!trkPar || !rot) {
if( !trkPar ) ATH_MSG_WARNING ("No TrackParameters, cannot calculate residual/pull ");
if( !rot ) ATH_MSG_WARNING ("No ROT, cannot calculate residual/pull ");
return 0;
}
Identifier ID = rot->identify();
if( m_idHelper->isTgc(ID) ) {
// try to cast the track parameters to measured ones
const AmgSymMatrix(5)* trkCov = trkPar->covariance();
bool pullIsValid = (trkCov);
double sinAlpha = 0.0;
bool isStrip = m_idHelper->tgcIdHelper().isStrip(ID);
// calculate residual
std::vector<double> residual(1);
std::vector<double> pull(1);
if (isStrip) {
// consistency check that Muon EDM is as expected
if (measurement->localParameters().parameterKey() !=3) {
ATH_MSG_WARNING ( "TGC ClusterOnTrack does not carry the expected "
<< "LocalParameters structure!");
return 0;
}
// get orientation angle of strip to rotate back from local frame to strip
const Amg::MatrixX &covmat=measurement->localCovariance();
double v0=0.5*(covmat(0,0)+covmat(1,1)-sqrt((covmat(0,0)+covmat(1,1))*(covmat(0,0)+covmat(1,1))-
4*(covmat(0,0)*covmat(1,1)-covmat(0,1)*covmat(0,1))));
double v1=0.5*(covmat(0,0)+covmat(1,1)+sqrt((covmat(0,0)+covmat(1,1))*(covmat(0,0)+covmat(1,1))-
4*(covmat(0,0)*covmat(1,1)-covmat(0,1)*covmat(0,1))));
sinAlpha=sin(0.5*asin(2*covmat(0,1)/(v0-v1)));
const MuonGM::TgcReadoutElement *ele =
dynamic_cast<const MuonGM::TgcReadoutElement*>(rot->detectorElement());
if (ele == 0) {
ATH_MSG_WARNING ("Could not obtain TGC detEl from TGC ROT, this is a bug!" );
return 0;
}