6#include "CLHEP/Matrix/Matrix.h"
7#include "CLHEP/Matrix/SymMatrix.h"
8#include "CLHEP/Matrix/DiagMatrix.h"
10#include "GaudiKernel/StatusCode.h"
11#include "GaudiKernel/MsgStream.h"
12#include "GaudiKernel/AlgTool.h"
38 const IInterface* parent)
41 declareInterface<IAlignTool>(
this);
67 return StatusCode::SUCCESS;
80 ATH_MSG_DEBUG(
"in GlobalGhi2AlignTool::firstEventInitialize()");
83 ATH_MSG_DEBUG(
"allocating matrix with "<<nDoF<<
" degrees of freedom");
86 msg(MSG::FATAL)<<
"Problem with allocateMatrix"<<
endmsg;
87 return StatusCode::FAILURE;
91 return StatusCode::SUCCESS;
104 m_tree=
new TTree(
"globalChi2Deriv",
"globalChi2Deriv");
135 bool fullVertex =
false;
139 const std::vector<AlignModuleVertexDerivatives> * ptrX =
nullptr;
143 ptrPosition = ptrVertex->
position();
144 ptrCovariance = ptrVertex->covariance();
146 vtxType = ptrVertex->
type();
150 msg(MSG::ERROR)<<
"something missing from alignVertex!"<<
endmsg;
151 if (!ptrPosition)
msg(MSG::ERROR)<<
"no fitted position!"<<
endmsg;
152 if (!ptrCovariance)
msg(MSG::ERROR)<<
"no covariance!"<<
endmsg;
153 if (!ptrX)
msg(MSG::ERROR)<<
"no link to the X object!"<<
endmsg;
169 const std::vector<AlignModuleDerivatives> * ptrDerivs = alignTrack->
derivatives();
172 if (!ptrWeights || !ptrWeightsFD || !ptrResiduals || !ptrDerivs) {
173 msg(MSG::ERROR)<<
"something missing from alignTrack!"<<
endmsg;
174 if (!ptrWeights)
msg(MSG::ERROR)<<
"no weights!"<<
endmsg;
175 if (!ptrWeightsFD)
msg(MSG::ERROR)<<
"no weights for first deriv!"<<
endmsg;
176 if (!ptrResiduals)
msg(MSG::ERROR)<<
"no residuals!"<<
endmsg;
177 if (!ptrDerivs)
msg(MSG::ERROR)<<
"no derivatives!"<<
endmsg;
189 std::vector<AlignModuleDerivatives> derivatives = *ptrDerivs;
190 const std::vector<AlignModuleDerivatives>* derivativeErr = alignTrack->
derivativeErr();
191 const std::vector<std::pair<AlignModule*,std::vector<double> > >* secDerivs = alignTrack->
actualSecondDerivatives();
195 std::vector<AlignPar*> allAlignPars;
196 std::vector<Amg::VectorX*> allDerivatives;
197 std::vector<const Amg::VectorX*> allDerivativeErr;
198 std::vector<double> allActualSecDeriv;
204 msg(MSG::DEBUG) <<
"accumulate: The derivative vector size is " << derivatives.size() <<
endmsg;
205 std::vector<AlignModuleDerivatives>::iterator derivIt = derivatives.begin();
206 std::vector<AlignModuleDerivatives>::iterator derivIt_end = derivatives.end();
208 std::vector<AlignModuleDerivatives>::const_iterator derivErrIt;
209 std::vector<std::pair<AlignModule*,std::vector<double> > >
::const_iterator secDerivIt;
210 if (derivativeErr) derivErrIt=derivativeErr->begin();
211 if (secDerivs) secDerivIt=secDerivs->begin();
212 for ( ; derivIt!=derivIt_end ; ++derivIt) {
219 ATH_MSG_DEBUG(
"add track to module "<<module->identify().get_identifier32().get_compact());
220 module->addNDoF(alignTrack->fitQuality()->numberDoF());
221 module->addTrackChi2(alignTrack->fitQuality()->chiSquared());
231 std::vector<Amg::VectorX>& deriv_vec = derivIt->second;
232 ATH_MSG_DEBUG(
"accumulate: The deriv_vec size is " << deriv_vec.size() );
234 int nModPars = alignPars->
size();
235 if (nModPars != (
int)deriv_vec.size() && (nModPars+3) != (
int)deriv_vec.size()) {
239 for (
int i=0;i<3;i++) {
240 for (
int j=0;j<WSize;j++) {
241 matrix_F(i,j) += deriv_vec[nModPars+i][j];
246 for (
int i=0;i<nModPars;i++) {
247 ATH_MSG_DEBUG(
"align par for module "<<(*alignPars)[i]->alignModule()->identify());
248 allAlignPars.push_back((*alignPars)[i]);
249 allDerivatives.push_back(&deriv_vec[i]);
251 allDerivativeErr.push_back(&(derivErrIt->second)[i]);
253 allActualSecDeriv.push_back((secDerivIt->second)[i]);
255 if (derivativeErr) ++derivErrIt;
256 if (secDerivs) ++secDerivIt;
262 for (; iatsos != iatsos_last; ++iatsos)
263 if ((*iatsos)->module())
264 (*iatsos)->module()->addHit();
267 int nAllPars = allAlignPars.size();
269 for (
int ipar=0;ipar<nAllPars;ipar++) {
272 Amg::MatrixX derivativesT = (*allDerivatives[ipar]).transpose();
273 ATH_MSG_DEBUG(
"derivativesT (size "<<derivativesT.cols()<<
"): "<<derivativesT);
279 int index1 = allAlignPars[ipar]->index();
283 if (firstderivM(0,0)==0.) {
284 ATH_MSG_DEBUG(
"firstderivM[0][0] is zero : "<<firstderivM(0,0));
295 ATH_MSG_DEBUG(
"alActualSecDeriv size: "<<allActualSecDeriv.size());
302 int imodule1 = allAlignPars[ipar]->alignModule()->identifyHash();
305 bool goodSecondDeriv =
true;
306 for (
int jpar=ipar;jpar<nAllPars;jpar++) {
309 int index2=allAlignPars[jpar]->index();
312 int imodule2 = allAlignPars[jpar]->alignModule()->identifyHash();
317 if (imodule1 != imodule2)
325 if (jpar==ipar && secondderivM(0,0)<0.) {
331 goodSecondDeriv =
false;
345 if (goodSecondDeriv) {
359 ATH_MSG_DEBUG(
"accumulate: Contribution from the fullVTX will be added " );
361 Amg::MatrixX RHM = (*ptrCovariance) * (matrix_F) * (weightsFirstDeriv * residuals);
363 std::vector<AlignPar*> vtxAlignPars;
364 std::vector<const Amg::VectorX*> vtxDerivatives;
367 msg(MSG::DEBUG) <<
"accumulate: The Vertex derivative vector size is " << ptrX->size() <<
endmsg;
368 std::vector<AlignModuleVertexDerivatives>::const_iterator XIt = ptrX->begin();
369 std::vector<AlignModuleVertexDerivatives>::const_iterator XIt_end = ptrX->end();
371 for ( ; XIt!=XIt_end ; ++XIt) {
377 const std::vector<Amg::VectorX>& X_vec = XIt->second;
378 msg(MSG::DEBUG) <<
"accumulate: The X_vec size is " << X_vec.size() <<
endmsg;
380 int nModPars = alignPars->
size();
381 if (nModPars != (
int)X_vec.size()) {
387 for (
int i=0;i<nModPars;i++) {
388 ATH_MSG_DEBUG(
"align par for module "<<(*alignPars)[i]->alignModule()->identify());
389 vtxAlignPars.push_back((*alignPars)[i]);
390 vtxDerivatives.push_back(&X_vec[i]);
405 ptrVertex->Qmatrix()->computeInverseAndDetWithCheck(Qinv,determinant,invertible);
408 std::cout <<
"accumulate: Q inversion failed. CLHEP status flag = "<<ierr<< std::endl;
418 int nvtxPars = vtxAlignPars.size();
419 for (
int ipar=0;ipar<nvtxPars;ipar++) {
422 Amg::MatrixX derivativesT = (*vtxDerivatives[ipar]).transpose();
427 firstderivM += 2.* derivativesT * ((*ptrCovariance) * Qinv) * vtemp;
431 int index1 = vtxAlignPars[ipar]->index();
437 ATH_MSG_DEBUG(
"accumulate: Filling second derivative for this vertex... ");
438 for (
int jpar=0;jpar<nvtxPars;jpar++) {
441 Amg::MatrixX secondderivM = -1.* derivativesT * (*ptrCovariance) * (*vtxDerivatives[jpar]);
444 if( ptrVertex->
Constrained() && ptrVertex->Qmatrix()->determinant() > 1.0e-24 ) {
445 secondderivM += 2.* derivativesT * ((*ptrCovariance) * Qinv * (*ptrCovariance)) * (*vtxDerivatives[jpar]);
449 int index2=vtxAlignPars[jpar]->index();
475 StatusCode
sc =
evtStore()->retrieve(currentEvent);
476 if (
sc==StatusCode::SUCCESS) {
554 *
m_logStream<<
"*************************************************************"<<std::endl;
555 *
m_logStream<<
"****** Global Chi2 alignment solving ******"<<std::endl;
570 ATH_MSG_INFO(
">>>> -----------------------------------------------");
572 ATH_MSG_INFO(
">>>> -----------------------------------------------");
576 return StatusCode::SUCCESS;
578 return StatusCode::FAILURE;
588 success =
m_tree->Write();
590 return success>0 ? StatusCode::SUCCESS : StatusCode::FAILURE;
597 return StatusCode::SUCCESS;
604 double materialOnTrack(0.);
617 for ( ; tsit!=tsit_end ; ++tsit ) {
618 const Trk:: MaterialEffectsBase* materialEffects = (*tsit)->materialEffectsOnTrack();
619 if (materialEffects) {
631 return materialOnTrack;
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define AmgSymMatrix(dim)
ServiceHandle< StoreGateSvc > & evtStore()
DataModel_detail::const_iterator< DataVector > const_iterator
DataModel_detail::iterator< DataVector > iterator
size_type size() const noexcept
Returns the number of elements in the collection.
AlignTSOSCollection::const_iterator lastAtsos() const
returns iterator pointer to last element in collection
int nAlignTSOSMeas() const
number of alignTSOS (including scatterers if included on AlignTrack
const std::vector< AlignModuleDerivatives > * derivatives() const
The Amg::VectorX is a vector of first-derivatives of the alignTSOS on the alignTrack w....
const Track * originalTrack() const
retrieve pointer to original track
const Amg::VectorX * residualVector() const
Vector of residuals of the alignTSOS on the alignTrack, to be set by AlignTrackDresser.
const std::vector< std::pair< AlignModule *, std::vector< double > > > * actualSecondDerivatives() const
The Amg::VectorX is a vector of first-derivatives of the alignTSOS on the alignTrack w....
const std::vector< AlignModuleDerivatives > * derivativeErr() const
The Amg::VectorX is a vector of errors in first-derivatives of the alignTSOS on the alignTrack w....
AlignTSOSCollection::const_iterator firstAtsos() const
retrieve iterator pointer to first element in collection
const AlignTSOSCollection * alignTSOSCollection() const
returns collection of alignTSOS
const Amg::SymMatrixX * weightMatrixFirstDeriv() const
First deriv weight matrix can be either W from Si alignment (see Eqn.
const AlignVertex * getVtx() const
set and get pointer to the associated vertex
const Amg::SymMatrixX * weightMatrix() const
Weight matrix is W from Si alignment (see Eqn.
const Amg::Vector3D * originalPosition() const
@ Refitted
normally refitted, without adding any pseudo-measurement
@ Accumulated
accumulated by the GX algorithm.
const Amg::Vector3D * Vvector() const
AlignVertexType type() const
get and set the refit type
const Amg::Vector3D * position() const
get the vertex position and covariance
void setType(AlignVertexType type)
const std::vector< AlignModuleVertexDerivatives > * derivatives() const
The Amg::VectorX is a vector of first-derivatives of the alignTSOS on the alignTrack w....
int numberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as integer
double chiSquared() const
returns the of the overall track fit
double thicknessInX0() const
returns the actually traversed material .
represents the full description of deflection and e-loss of a track in material.
double eta() const
Access method for pseudorapidity - from momentum.
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
double pT() const
Access method for transverse momentum.
Contains information about the 'fitter' of this track.
@ BremFit
A brem fit was performed on this track.
@ StraightTrack
A straight track.
@ HardScatterOrKink
A track with a kink or a hard scatter.
@ LowPtTrack
A LowPt track.
@ BremFitSuccessful
A brem fit was performed on this track and this fit was successful.
@ SlimmedTrack
A slimmed track.
const TrackInfo & info() const
Returns a const ref to info of a const tracks.
const Perigee * perigeeParameters() const
return Perigee.
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > SymMatrixX
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Ensure that the ATLAS eigen extensions are properly loaded.
DataVector< const Trk::TrackStateOnSurface > TrackStates
EventInfo_v1 EventInfo
Definition of the latest event info version.