ATLAS Offline Software
AlignTrackDresser.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "GaudiKernel/MsgStream.h"
6 #include "CLHEP/Matrix/SymMatrix.h"
7 
12 
13 #include "TrkTrack/Track.h"
14 
20 
22 
23 namespace Trk {
24 
25  //________________________________________________________________________
26  AlignTrackDresser::AlignTrackDresser(const std::string & type, const std::string & name, const IInterface * parent)
28  , m_derivCalcTool("Trk::AnalyticalDerivCalcTool", this)
29  , m_numBadCovWMatrix(0)
30  {
31  declareInterface<IAlignTrackDresser>(this);
32 
33  declareProperty("DerivCalcTool", m_derivCalcTool, "tool for calculating derivatives");
34 
35  m_logStream = nullptr;
36  }
37 
38  //________________________________________________________________________
40  = default;
41 
42  //________________________________________________________________________
44  {
45  ATH_MSG_DEBUG("in AlignTrackDresser initialize()");
46 
47  // Get DerivCalcTool (will have to be moved to AlignTool)
48  if ( m_derivCalcTool.retrieve().isFailure() ) {
49  msg(MSG::FATAL)<< "Failed to retrieve tool " << m_derivCalcTool << endmsg;
50  return StatusCode::FAILURE;
51  }
52  ATH_MSG_INFO("Retrieved tool " << m_derivCalcTool);
53 
54  return StatusCode::SUCCESS;
55  }
56 
57  //________________________________________________________________________
58  void AlignTrackDresser::setLogStream(std::ostream * os)
59  {
60  m_logStream = os;
61  m_derivCalcTool->setLogStream(m_logStream);
62  }
63 
64  //________________________________________________________________________
66  {
67  if(m_numBadCovWMatrix>0)
68  ATH_MSG_INFO("Total of "<<m_numBadCovWMatrix<<" tracks had invalid weight matrix.");
69  return StatusCode::SUCCESS;
70  }
71 
72  //________________________________________________________________________
74  {
75  // set hit residuals
76  setResiduals(alignTrack);
77 
78  ATH_MSG_DEBUG("residuals set, getting partial derivatives from m_derivCalcTool="<<m_derivCalcTool);
79 
80  // set partial derivatives of hit residuals w.r.t. alignment parameters
81  if (!m_derivCalcTool->setDerivatives(alignTrack))
82  return false;
83 
84  // for global method we let the deriv.calc.tool calculate the weight matrix
85  // get W = V^{-1} R V^{-1} (simply V^{-1} for numerical derivatives)
86  bool Wisvalid = m_derivCalcTool->setResidualCovMatrix(alignTrack);
87 
88  if (!Wisvalid) {
89  ATH_MSG_INFO("something is wrong with the cov matrix for the residuals.");
91  }
92 
93  return Wisvalid;
94  }
95 
96  //________________________________________________________________________
98  {
99  if (alignTrack->residualVector())
100  ATH_MSG_ERROR("alignTrack already has residuals!");
101 
102  const int NMEAS = alignTrack->nAlignTSOSMeas();
103  Amg::VectorX * residuals = new Amg::VectorX(NMEAS);
104 
105  int imeas = 0;
106  AlignTSOSCollection::const_iterator atsosItr = alignTrack->firstAtsos();
107  for ( ; atsosItr != alignTrack->lastAtsos(); ++atsosItr) {
108 
109  if (!(*atsosItr)->isValid())
110  continue;
111 
112  std::vector<Residual>::const_iterator itRes = (**atsosItr).firstResidual();
113  for ( ; itRes != (**atsosItr).lastResidual() ; ++itRes, ++imeas) {
114  (*residuals)[imeas] = itRes->residual();
115  if (msgLvl(MSG::DEBUG)) {
116  double z=(**atsosItr).measurementOnTrack()->globalPosition().z();
117  ATH_MSG_DEBUG("pos.z: "<<z<<", res["<<imeas<<"]="<<itRes->residual()<<" res/sq["<<imeas<<"]="<<itRes->residualNorm());
118  }
119  }
120  }
121 
122  if (imeas!=NMEAS) {
123  msg(MSG::ERROR)<<"problem with nmeas. imeas="<<imeas<<", NMEAS="<<NMEAS<<endmsg;
124  throw std::runtime_error("Error in AlignTrackDresser::setResiduals");
125  }
126 
127  alignTrack->setResidualVector(residuals); // residuals owned by alignTrack
128  ATH_MSG_DEBUG("residuals set for AlignTrack");
129  }
130 
131 } // end namespace
132 
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Trk::AlignTrackDresser::AlignTrackDresser
AlignTrackDresser(const std::string &type, const std::string &name, const IInterface *parent)
Definition: AlignTrackDresser.cxx:26
Amg::VectorX
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Definition: EventPrimitives.h:30
Trk::z
@ z
global position (cartesian)
Definition: ParamDefs.h:57
MeasurementBase.h
Trk::AlignTrack::setResidualVector
void setResidualVector(Amg::VectorX *vec)
Definition: AlignTrack.h:151
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
Trk::AlignTrackDresser::initialize
virtual StatusCode initialize() override
Definition: AlignTrackDresser.cxx:43
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CompetingRIOsOnTrack.h
Trk::AlignTrackDresser::setResiduals
void setResiduals(AlignTrack *alignTrack) const
sets residuals for TSOS on alignTrack
Definition: AlignTrackDresser.cxx:97
IFillNtupleTool.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
AlignTSOS.h
Track.h
Trk::AlignTrackDresser::~AlignTrackDresser
virtual ~AlignTrackDresser()
AlignTrack.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::AlignTrack::firstAtsos
AlignTSOSCollection::const_iterator firstAtsos() const
retrieve iterator pointer to first element in collection
Definition: AlignTrack.h:279
Trk::AlignTrackDresser::m_derivCalcTool
ToolHandle< IDerivCalcTool > m_derivCalcTool
tool for calculating derivatives of residuals wrt.
Definition: AlignTrackDresser.h:54
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Trk::AlignTrack::residualVector
const Amg::VectorX * residualVector() const
Vector of residuals of the alignTSOS on the alignTrack, to be set by AlignTrackDresser.
Definition: AlignTrack.h:150
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
RIO_OnTrack.h
AlignModule.h
Trk::AlignTrackDresser::setLogStream
virtual void setLogStream(std::ostream *os) override
sets the output stream for the logfile
Definition: AlignTrackDresser.cxx:58
Trk::IAlignTrackDresser::m_logStream
std::ostream * m_logStream
logfile output stream
Definition: IAlignTrackDresser.h:42
Trk::AlignTrack::nAlignTSOSMeas
int nAlignTSOSMeas() const
number of alignTSOS (including scatterers if included on AlignTrack
Definition: AlignTrack.h:128
Trk::AlignTrack
Definition: AlignTrack.h:41
Trk::AlignTrackDresser::m_numBadCovWMatrix
unsigned int m_numBadCovWMatrix
number of tracks with invalid weight matrix from the deriv.calc.tool
Definition: AlignTrackDresser.h:56
AlignTrackDresser.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
Trk::AlignTrackDresser::finalize
virtual StatusCode finalize() override
Definition: AlignTrackDresser.cxx:65
AthAlgTool
Definition: AthAlgTool.h:26
IDerivCalcTool.h
TrackStateOnSurface.h
Trk::AlignTrackDresser::dressAlignTrack
virtual bool dressAlignTrack(AlignTrack *alignTrack) override
dresses alignTrack with derivatives and other information
Definition: AlignTrackDresser.cxx:73
Trk::AlignTrack::lastAtsos
AlignTSOSCollection::const_iterator lastAtsos() const
returns iterator pointer to last element in collection
Definition: AlignTrack.h:280