ATLAS Offline Software
Loading...
Searching...
No Matches
AlignVertex.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <iostream>
7
8namespace Trk {
9
10 //________________________________________________________________________
12 : m_matrix(nullptr)
13 , m_vector(nullptr)
14 , m_original(nullptr)
15 , m_originalPosition(nullptr)
16 , m_position(nullptr)
17 , m_covariance(nullptr)
18 , m_derivatives(nullptr)
19 , m_qMatrix(nullptr)
20 , m_vVector(nullptr)
21 , m_constrained(false)
23 {
24 m_vector=new Amg::Vector3D(0.,0.,0.);
25 m_matrix=new AmgSymMatrix(3);
26 m_derivatives=new std::vector<AlignModuleVertexDerivatives >(0);
27 m_qMatrix= new AmgSymMatrix(3);
28 m_vVector=new Amg::Vector3D(0.,0.,0.);
29 m_nTracks=0;
30 }
31
32 //copy constructor
34 : m_nTracks(rhs.m_nTracks)
35 , m_matrix(new AmgSymMatrix(3)(*(rhs.m_matrix)))
36 , m_vector(new Amg::Vector3D(*(rhs.m_vector)))
37 , m_original(new xAOD::Vertex(*(rhs.m_original)))
39 , m_position(new Amg::Vector3D(*(rhs.m_position)))
40 , m_covariance(new AmgSymMatrix(3) (*(rhs.m_covariance)) )
41 , m_derivatives(new auto(*(rhs.m_derivatives)))
42 , m_qMatrix(new AmgSymMatrix(3) (*(rhs.m_qMatrix)) )
43 , m_vVector(new Amg::Vector3D(*(rhs.m_vVector)))
45 , m_type(rhs.m_type)
46 {
47
48 }
49
50 //assignment
52 if (&rhs!=this){
53 m_nTracks = rhs.m_nTracks;
54 delete m_matrix; m_matrix = new AmgSymMatrix(3)(*(rhs.m_matrix));
55 delete m_vector; m_vector = new Amg::Vector3D(*(rhs.m_vector));
56 delete m_original; m_original = new xAOD::Vertex(*(rhs.m_original));
58 delete m_position; m_position = new Amg::Vector3D(*(rhs.m_position));
59 delete m_covariance; m_covariance = new AmgSymMatrix(3) (*(rhs.m_covariance));
60 delete m_derivatives; m_derivatives = new auto(*(rhs.m_derivatives));
61 delete m_qMatrix; m_qMatrix = new AmgSymMatrix(3) (*(rhs.m_qMatrix));
62 delete m_vVector; m_vVector = new Amg::Vector3D(*(rhs.m_vVector));
64 m_type = rhs.m_type;
65 }
66 return *this;
67 }
68
69
70
71
72 //________________________________________________________________________
74 : m_matrix(nullptr)
75 , m_vector(nullptr)
77 , m_originalPosition(nullptr)
78 , m_position(nullptr)
79 , m_covariance(nullptr)
80 , m_derivatives(nullptr)
81 , m_qMatrix(nullptr)
82 , m_vVector(nullptr)
83 , m_constrained(false)
85 {
86 m_vector=new Amg::Vector3D(0.,0.,0.);
87 m_matrix=new AmgSymMatrix(3);
89 m_originalPosition = new Amg::Vector3D( vertex->position() );
90 m_derivatives=new std::vector<AlignModuleVertexDerivatives >(0);
91 m_qMatrix=new AmgSymMatrix(3);
92 m_vVector=new Amg::Vector3D(0.,0.,0.);
93 m_nTracks=0;
94 }
95
96
97 //________________________________________________________________________
99 {
100 if( m_matrix ) delete m_matrix;
101 if( m_vector ) delete m_vector;
102
104
105 if( m_position ) delete m_position;
106 if( m_covariance ) delete m_covariance;
107 if( m_derivatives ) delete m_derivatives;
108
109 if( m_qMatrix ) delete m_qMatrix;
110 if( m_vVector ) delete m_vVector;
111 }
112
113 //________________________________________________________________________
115 {
116 if( Q->rows()!=3 || V->rows()!=3 ) {
117 std::cout <<"Unexpected size of the constraint:"<< std::endl;
118 std::cout <<" Q size = "<< Q->rows() << ", V size = "<< V->rows() << std::endl;
119 return;
120 }
121 if( Q->determinant() < 1.0e-24 ) {
122 std::cout <<" Suspicious Q determinant: detQ = "<< Q->determinant() << std::endl;
123 return;
124 }
125 (*m_qMatrix) = (*Q);
126 (*m_vVector) = (*V);
127 m_constrained = true;
128 }
129
130
131 //________________________________________________________________________
132 void AlignVertex::addDerivatives(std::vector<AlignModuleVertexDerivatives>* vec)
133 {
134 std::vector<AlignModuleVertexDerivatives>::iterator derivIt = vec->begin();
135 std::vector<AlignModuleVertexDerivatives>::iterator derivIt_end = vec->end();
136
137 for ( ; derivIt!=derivIt_end ; ++derivIt) {
138 m_derivatives->push_back(*derivIt);
139 }
140
141 }
142
143 //________________________________________________________________________
145 {
146
147 m_type = Unknown;
148
149 if( Ntracks() < 2 ) return; // this is not a good vertex!
150
151
152 if( !m_matrix ) {
153 std::cout <<"NULL pointer to the matrix! Bailing out..."<< std::endl;
154 return;
155 }
156
157 Amg::Vector3D vec = (*m_vector);
158 AmgSymMatrix(3) cov = (*m_matrix);
159 AmgSymMatrix(3) covcons = (*m_matrix);
160
161 AmgSymMatrix(3) Qinv;
162 if( m_constrained && m_qMatrix->determinant() > 1.0e-24 ) { // just my guess sigma>0.1 micron ???
163
164 bool invertible;
165 m_qMatrix->computeInverseWithCheck(Qinv,invertible);
166
167 if(!invertible) {
168 std::cout <<"fitVertex: Q inversion failed. " << std::endl;
169 return;
170 }
171
172
173 Amg::Vector3D vtemp(3, 0);
174
175 vtemp = *m_originalPosition;
176 vtemp -= *m_vVector;
177
178 covcons += 2.0*Qinv;
179 vec += 2.0*Qinv*vtemp;
180 }
181
182 // invert the constrained covariance:
183 AmgSymMatrix(3) invcovcons;
184
185 bool invertible;
186 covcons.computeInverseWithCheck(invcovcons,invertible);
187
188 if(!invertible) {
189 std::cout <<"fitVertex: covcons inversion failed. " << std::endl;
190 return;
191 }
192
193 // invert the covariance matrix:
194 AmgSymMatrix(3) invcov;
195 cov.computeInverseWithCheck(invcov,invertible);
196
197 if(!invertible) {
198 std::cout <<"fitVertex: cov inversion failed. " << std::endl;
199 return;
200 }
201
202
203
204 // calculate corrections (mind the sign!)
205 Amg::Vector3D delta(invcovcons * vec);
206
207 if ( !m_position ) m_position=new Amg::Vector3D(0.,0.,0.);
209 *m_position -= delta;
210
211
212 if ( !m_covariance ) m_covariance= new AmgSymMatrix(3);
213 (*m_covariance)=invcov; // this one is unconstrained!
214
216 }
217 //________________________________________________________________________
218 void AlignVertex::dump(MsgStream& msg)
219 {
220 msg<<"dumping AlignVertex: "<<endmsg;
221
222 msg<<" vertex Position: "<< (*m_position) << endmsg;
223 msg<<" vertex Covariance: "<< (*m_covariance) << endmsg;
224 msg<< endmsg;
225
226 }
227
228
229
230} // end namespace
#define endmsg
std::vector< size_t > vec
#define AmgSymMatrix(dim)
Eigen::Matrix< double, 3, 1 > Vector3D
AlignVertex & operator=(const AlignVertex &rhs)
assignment
AlignVertexType m_type
@ Unknown
default type
Definition AlignVertex.h:44
@ Refitted
normally refitted, without adding any pseudo-measurement
Definition AlignVertex.h:46
Amg::Vector3D * m_originalPosition
~AlignVertex()
destructor
Amg::Vector3D * m_vVector
void dump(MsgStream &msg)
dump align vertex information
AlignVertex()
default constructor
int Ntracks() const
get the number of contributing tracks
std::vector< AlignModuleVertexDerivatives > * m_derivatives
void fitVertex()
fit the vertex internally
void addDerivatives(std::vector< AlignModuleVertexDerivatives > *vec)
void setConstraint(AmgSymMatrix(3) *, Amg::Vector3D *)
set and get the constraint on VTX position
Amg::Vector3D * m_position
const xAOD::Vertex * m_original
const AmgSymMatrix(3) *covariance() const
Definition AlignVertex.h:90
Amg::Vector3D * m_vector
This class is a simplest representation of a vertex candidate.
Definition of ATLAS Math & Geometry primitives (Amg)
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Vertex_v1 Vertex
Define the latest version of the vertex class.
MsgStream & msg
Definition testRead.cxx:32