ATLAS Offline Software
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 
8 namespace 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)
22  , m_type(Unknown)
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)))
38  , m_originalPosition(new Amg::Vector3D( *(rhs.m_originalPosition )))
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)))
44  , m_constrained(rhs.m_constrained)
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)
76  , m_original(vertex)
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)
84  , m_type(Unknown)
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  {
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 
215  m_type = Refitted;
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
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Trk::AlignVertex::m_constrained
bool m_constrained
Definition: AlignVertex.h:144
Trk::Vertex
Definition: Tracking/TrkEvent/VxVertex/VxVertex/Vertex.h:26
Trk::AlignVertex
Definition: AlignVertex.h:39
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition: Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
Trk::AlignVertex::m_position
Amg::Vector3D * m_position
Definition: AlignVertex.h:137
Trk::AlignVertex::m_original
const xAOD::Vertex * m_original
Definition: AlignVertex.h:132
Trk::AlignVertex::AmgSymMatrix
const AmgSymMatrix(3) *covariance() const
Definition: AlignVertex.h:90
Trk::AlignVertex::Unknown
@ Unknown
default type
Definition: AlignVertex.h:44
Trk::AlignVertex::m_type
AlignVertexType m_type
Definition: AlignVertex.h:147
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
Trk::AlignVertex::m_derivatives
std::vector< AlignModuleVertexDerivatives > * m_derivatives
Definition: AlignVertex.h:140
Trk::AlignVertex::m_vVector
Amg::Vector3D * m_vVector
Definition: AlignVertex.h:143
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
Trk::AlignVertex::dump
void dump(MsgStream &msg)
dump align vertex information
Definition: AlignVertex.cxx:218
Trk::AlignVertex::Ntracks
int Ntracks() const
get the number of contributing tracks
Definition: AlignVertex.h:112
Trk::AlignVertex::fitVertex
void fitVertex()
fit the vertex internally
Definition: AlignVertex.cxx:144
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
m_type
TokenType m_type
the type
Definition: TProperty.cxx:44
AlignVertex.h
Trk::AlignVertex::setConstraint
void setConstraint(AmgSymMatrix(3) *, Amg::Vector3D *)
set and get the constraint on VTX position
Definition: AlignVertex.cxx:114
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Trk::AlignVertex::m_vector
Amg::Vector3D * m_vector
Definition: AlignVertex.h:130
Trk::AlignVertex::m_originalPosition
Amg::Vector3D * m_originalPosition
Definition: AlignVertex.h:133
Trk::Unknown
@ Unknown
Definition: TargetSurfaces.h:48
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Amg
Definition of ATLAS Math & Geometry primitives (Amg)
Definition: AmgStringHelpers.h:19
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
Trk::AlignVertex::~AlignVertex
~AlignVertex()
destructor
Definition: AlignVertex.cxx:98
Trk::AlignVertex::addDerivatives
void addDerivatives(std::vector< AlignModuleVertexDerivatives > *vec)
Definition: AlignVertex.cxx:132
Trk::AlignVertex::AlignVertex
AlignVertex()
default constructor
Definition: AlignVertex.cxx:11
Trk::AlignVertex::Refitted
@ Refitted
normally refitted, without adding any pseudo-measurement
Definition: AlignVertex.h:46
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Trk::AlignVertex::m_nTracks
int m_nTracks
Definition: AlignVertex.h:127
Trk::AlignVertex::operator=
AlignVertex & operator=(const AlignVertex &rhs)
assignment
Definition: AlignVertex.cxx:51