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"
43 const IInterface* parent)
78 declareInterface<IAlignTool>(
this);
115 return StatusCode::SUCCESS;
128 ATH_MSG_DEBUG(
"in GlobalGhi2AlignTool::firstEventInitialize()");
131 ATH_MSG_DEBUG(
"allocating matrix with "<<nDoF<<
" degrees of freedom");
134 msg(MSG::FATAL)<<
"Problem with allocateMatrix"<<
endmsg;
135 return StatusCode::FAILURE;
139 return StatusCode::SUCCESS;
152 m_tree=
new TTree(
"globalChi2Deriv",
"globalChi2Deriv");
183 bool fullVertex =
false;
187 const std::vector<AlignModuleVertexDerivatives> * ptrX =
nullptr;
191 ptrPosition = ptrVertex->
position();
192 ptrCovariance = ptrVertex->covariance();
194 vtxType = ptrVertex->
type();
198 msg(MSG::ERROR)<<
"something missing from alignVertex!"<<
endmsg;
199 if (!ptrPosition)
msg(MSG::ERROR)<<
"no fitted position!"<<
endmsg;
200 if (!ptrCovariance)
msg(MSG::ERROR)<<
"no covariance!"<<
endmsg;
201 if (!ptrX)
msg(MSG::ERROR)<<
"no link to the X object!"<<
endmsg;
217 const std::vector<AlignModuleDerivatives> * ptrDerivs = alignTrack->
derivatives();
220 if (!ptrWeights || !ptrWeightsFD || !ptrResiduals || !ptrDerivs) {
221 msg(MSG::ERROR)<<
"something missing from alignTrack!"<<
endmsg;
222 if (!ptrWeights)
msg(MSG::ERROR)<<
"no weights!"<<
endmsg;
223 if (!ptrWeightsFD)
msg(MSG::ERROR)<<
"no weights for first deriv!"<<
endmsg;
224 if (!ptrResiduals)
msg(MSG::ERROR)<<
"no residuals!"<<
endmsg;
225 if (!ptrDerivs)
msg(MSG::ERROR)<<
"no derivatives!"<<
endmsg;
237 std::vector<AlignModuleDerivatives> derivatives = *ptrDerivs;
238 const std::vector<AlignModuleDerivatives>* derivativeErr = alignTrack->
derivativeErr();
239 const std::vector<std::pair<AlignModule*,std::vector<double> > >* secDerivs = alignTrack->
actualSecondDerivatives();
243 std::vector<AlignPar*> allAlignPars;
244 std::vector<Amg::VectorX*> allDerivatives;
245 std::vector<const Amg::VectorX*> allDerivativeErr;
246 std::vector<double> allActualSecDeriv;
252 msg(MSG::DEBUG) <<
"accumulate: The derivative vector size is " << derivatives.size() <<
endmsg;
253 std::vector<AlignModuleDerivatives>::iterator derivIt = derivatives.begin();
254 std::vector<AlignModuleDerivatives>::iterator derivIt_end = derivatives.end();
256 std::vector<AlignModuleDerivatives>::const_iterator derivErrIt;
257 std::vector<std::pair<AlignModule*,std::vector<double> > >
::const_iterator secDerivIt;
258 if (derivativeErr) derivErrIt=derivativeErr->begin();
259 if (secDerivs) secDerivIt=secDerivs->begin();
260 for ( ; derivIt!=derivIt_end ; ++derivIt) {
267 ATH_MSG_DEBUG(
"add track to module "<<module->identify().get_identifier32().get_compact());
268 module->addNDoF(alignTrack->fitQuality()->numberDoF());
269 module->addTrackChi2(alignTrack->fitQuality()->chiSquared());
279 std::vector<Amg::VectorX>& deriv_vec = derivIt->second;
280 ATH_MSG_DEBUG(
"accumulate: The deriv_vec size is " << deriv_vec.size() );
282 int nModPars = alignPars->
size();
283 if (nModPars != (
int)deriv_vec.size() && (nModPars+3) != (
int)deriv_vec.size()) {
287 for (
int i=0;i<3;i++) {
288 for (
int j=0;j<WSize;j++) {
289 matrix_F(i,j) += deriv_vec[nModPars+i][j];
294 for (
int i=0;i<nModPars;i++) {
295 ATH_MSG_DEBUG(
"align par for module "<<(*alignPars)[i]->alignModule()->identify());
296 allAlignPars.push_back((*alignPars)[i]);
297 allDerivatives.push_back(&deriv_vec[i]);
299 allDerivativeErr.push_back(&(derivErrIt->second)[i]);
301 allActualSecDeriv.push_back((secDerivIt->second)[i]);
303 if (derivativeErr) ++derivErrIt;
304 if (secDerivs) ++secDerivIt;
310 for (; iatsos != iatsos_last; ++iatsos)
311 if ((*iatsos)->module())
312 (*iatsos)->module()->addHit();
315 int nAllPars = allAlignPars.size();
317 for (
int ipar=0;ipar<nAllPars;ipar++) {
320 Amg::MatrixX derivativesT = (*allDerivatives[ipar]).transpose();
321 ATH_MSG_DEBUG(
"derivativesT (size "<<derivativesT.cols()<<
"): "<<derivativesT);
327 int index1 = allAlignPars[ipar]->index();
331 if (firstderivM(0,0)==0.) {
332 ATH_MSG_DEBUG(
"firstderivM[0][0] is zero : "<<firstderivM(0,0));
343 ATH_MSG_DEBUG(
"alActualSecDeriv size: "<<allActualSecDeriv.size());
350 int imodule1 = allAlignPars[ipar]->alignModule()->identifyHash();
353 bool goodSecondDeriv =
true;
354 for (
int jpar=ipar;jpar<nAllPars;jpar++) {
357 int index2=allAlignPars[jpar]->index();
360 int imodule2 = allAlignPars[jpar]->alignModule()->identifyHash();
365 if (imodule1 != imodule2)
373 if (jpar==ipar && secondderivM(0,0)<0.) {
379 goodSecondDeriv =
false;
393 if (goodSecondDeriv) {
407 ATH_MSG_DEBUG(
"accumulate: Contribution from the fullVTX will be added " );
409 Amg::MatrixX RHM = (*ptrCovariance) * (matrix_F) * (weightsFirstDeriv * residuals);
411 std::vector<AlignPar*> vtxAlignPars;
412 std::vector<const Amg::VectorX*> vtxDerivatives;
415 msg(MSG::DEBUG) <<
"accumulate: The Vertex derivative vector size is " << ptrX->size() <<
endmsg;
416 std::vector<AlignModuleVertexDerivatives>::const_iterator XIt = ptrX->begin();
417 std::vector<AlignModuleVertexDerivatives>::const_iterator XIt_end = ptrX->end();
419 for ( ; XIt!=XIt_end ; ++XIt) {
425 const std::vector<Amg::VectorX>& X_vec = XIt->second;
426 msg(MSG::DEBUG) <<
"accumulate: The X_vec size is " << X_vec.size() <<
endmsg;
428 int nModPars = alignPars->
size();
429 if (nModPars != (
int)X_vec.size()) {
435 for (
int i=0;i<nModPars;i++) {
436 ATH_MSG_DEBUG(
"align par for module "<<(*alignPars)[i]->alignModule()->identify());
437 vtxAlignPars.push_back((*alignPars)[i]);
438 vtxDerivatives.push_back(&X_vec[i]);
453 ptrVertex->Qmatrix()->computeInverseAndDetWithCheck(Qinv,determinant,invertible);
456 std::cout <<
"accumulate: Q inversion failed. CLHEP status flag = "<<ierr<< std::endl;
466 int nvtxPars = vtxAlignPars.size();
467 for (
int ipar=0;ipar<nvtxPars;ipar++) {
470 Amg::MatrixX derivativesT = (*vtxDerivatives[ipar]).transpose();
475 firstderivM += 2.* derivativesT * ((*ptrCovariance) * Qinv) * vtemp;
479 int index1 = vtxAlignPars[ipar]->index();
485 ATH_MSG_DEBUG(
"accumulate: Filling second derivative for this vertex... ");
486 for (
int jpar=0;jpar<nvtxPars;jpar++) {
489 Amg::MatrixX secondderivM = -1.* derivativesT * (*ptrCovariance) * (*vtxDerivatives[jpar]);
492 if( ptrVertex->
Constrained() && ptrVertex->Qmatrix()->determinant() > 1.0e-24 ) {
493 secondderivM += 2.* derivativesT * ((*ptrCovariance) * Qinv * (*ptrCovariance)) * (*vtxDerivatives[jpar]);
497 int index2=vtxAlignPars[jpar]->index();
523 StatusCode
sc =
evtStore()->retrieve(currentEvent);
524 if (
sc==StatusCode::SUCCESS) {
602 *
m_logStream<<
"*************************************************************"<<std::endl;
603 *
m_logStream<<
"****** Global Chi2 alignment solving ******"<<std::endl;
618 ATH_MSG_INFO(
">>>> -----------------------------------------------");
620 ATH_MSG_INFO(
">>>> -----------------------------------------------");
624 return StatusCode::SUCCESS;
626 return StatusCode::FAILURE;
636 success =
m_tree->Write();
638 return success>0 ? StatusCode::SUCCESS : StatusCode::FAILURE;
645 return StatusCode::SUCCESS;
652 double materialOnTrack(0.);
665 for ( ; tsit!=tsit_end ; ++tsit ) {
666 const Trk:: MaterialEffectsBase* materialEffects = (*tsit)->materialEffectsOnTrack();
667 if (materialEffects) {
679 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)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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
constexpr int MAXNCHAMBERS
constexpr int MAXNINDICES
EventInfo_v1 EventInfo
Definition of the latest event info version.