ATLAS Offline Software
Loading...
Searching...
No Matches
CompetingSCT_ClustersOnTrack.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6// CompetingSCT_ClustersOnTrack.cxx, (c) ATLAS Detector software
8
9// Trk
10#include "GaudiKernel/MsgStream.h"
11#include "TrkSurfaces/Surface.h"
12// InDet
14// std
15#include <cmath>
16#include <ostream>
17
18// default constructor
25
26// copy constructor
29 : Trk::CompetingRIOsOnTrack(compROT)
31{
32 for (const InDet::SCT_ClusterOnTrack* rot : compROT.m_containedChildRots) {
33 m_containedChildRots.push_back(rot->clone());
34 }
35 if (compROT.m_globalPosition) {
36 m_globalPosition.store(std::make_unique<const Amg::Vector3D>(*compROT.m_globalPosition));
37 }
38}
39
40// explicit constructor
42 std::vector<const InDet::SCT_ClusterOnTrack*>&& childrots,
43 std::vector<AssignmentProb>&& assgnProb
44
45 )
46 : Trk::CompetingRIOsOnTrack(std::move(assgnProb))
48 , m_containedChildRots(std::move(childrots))
49{
50 // initialize local position and error matrix
52}
53
57{
58 if (this != &compROT) {
59 // assingment operator of base class
61 // clear rots
64
65 for (const InDet::SCT_ClusterOnTrack* rot : compROT.m_containedChildRots) {
66 m_containedChildRots.push_back(rot->clone());
67 }
68 if (compROT.m_globalPosition) {
69 m_globalPosition.store(std::make_unique<const Amg::Vector3D>(*compROT.m_globalPosition));
70 } else if (m_globalPosition) {
71 m_globalPosition.release().reset();
72 }
73 }
74 return (*this);
75}
76
79 InDet::CompetingSCT_ClustersOnTrack&& compROT) noexcept
80{
81 if (this != &compROT) {
82 // move operator of base class
84 // clear rots
86 m_containedChildRots = std::move(compROT.m_containedChildRots);
87 m_globalPosition = std::move(compROT.m_globalPosition);
88 }
89 return (*this);
90}
91
92
97
98void
104
105MsgStream&
107{
108 using std::ios;
109 out << "Trk::CompetingSCT_ClustersOnTrack with [" << numberOfContainedROTs()
110 << "] competing RIO_OnTrack objects" << std::endl;
111 out << " - "
112 << (this->ROTsHaveCommonSurface(true) ? "on common surface" : "over different surfaces")
113 << " (given prob>cut)" << std::endl;
115 out << " - GlobalPosition : ";
116 if (not m_globalPosition)
117 out << "null pointer" << endmsg;
118 else
119 out << *m_globalPosition << endmsg;
120 return out;
121}
122
123std::ostream&
125{
126 using std::ios;
127 out << "Trk::CompetingSCT_ClustersOnTrack with [" << numberOfContainedROTs()
128 << "] competing RIO_OnTrack objects" << std::endl;
129 out << " - "
130 << (this->ROTsHaveCommonSurface(true) ? "on common surface" : "over different surfaces")
131 << " (given prob>cut)" << std::endl;
133 out << " - GlobalPosition : ";
134 if (not m_globalPosition)
135 out << "null pointer" << std::endl;
136 else
137 out << *m_globalPosition << std::endl;
138 return out;
139}
140
141// Have all the contained ROTs a common associated surface?
142bool
144{
145 return true;
146}
147
148void
150{
151
152 if (ROTsHaveCommonSurface()) {
153 int nNonVanishingROTs = ((assignmentProbability(0) > 1.e-10) ? 1 : 0);
154 for (unsigned int i = 1; i < numberOfContainedROTs(); i++) {
155 if (assignmentProbability(i) > 1.e-10) {
156 nNonVanishingROTs += 1;
157 }
158 }
159 const int& paramKey = rioOnTrack(0).localParameters().parameterKey();
160 Amg::MatrixX meanWeightMatrix;
161 meanWeightMatrix.setZero();
162 const unsigned int& maxProbIndex = indexOfMaxAssignProb();
163 if (nNonVanishingROTs > 1) {
164 // more than one non-vanishing ROT: do the more complicated calculation
165 if (paramKey == 1) {
166 Amg::MatrixX weight = rioOnTrack(0).localCovariance().inverse();
167 Amg::VectorX meanParams =
169 meanWeightMatrix = assignmentProbability(0) * weight;
170 for (unsigned int i = 1; i < numberOfContainedROTs(); i++) {
171 weight = rioOnTrack(i).localCovariance().inverse();
172 meanParams =
173 meanParams + assignmentProbability(i) * weight * rioOnTrack(i).localParameters();
174 meanWeightMatrix += assignmentProbability(i) * weight;
175 }
176
177 meanParams = meanWeightMatrix.inverse() * meanParams;
178 Trk::DefinedParameter Par1(meanParams[Trk::loc1], Trk::loc1);
180 } else if (paramKey == 3) {
181 double meanTheta = 0.;
182 double meanEigen1 = 0.;
183 double meanEigen2 = 0.;
184 double sumAssignProb = 0.;
185 double meanMeasX = 0.;
186 double meanMeasY = 0.;
187 for (unsigned int i = 0; i < numberOfContainedROTs(); i++) {
188 const Amg::MatrixX& covMat = rioOnTrack(i).localCovariance();
189 // rho[i] = covMat[0][1]/sqrt(covMat[0][0]*covMat[1][1]);
190 const double& assignProb = assignmentProbability(i);
191 sumAssignProb += assignProb;
192 const double trace = covMat(0, 0) + covMat(1, 1);
193 const double det = covMat(0, 0) * covMat(1, 1) - covMat(0, 1) * covMat(1, 0);
194 const double lambda1 = trace / 2. - sqrt(trace * trace / 4. - det);
195 const double lambda2 = trace / 2. + sqrt(trace * trace / 4. - det);
196 meanTheta +=
197 assignProb * 0.5 * atan(2. * covMat(0, 1) / (covMat(0, 0) - covMat(1, 1)));
198 meanEigen1 += assignProb / lambda1;
199 meanEigen2 += assignProb / lambda2;
200 // x coord has smaller uncert (use smaller eigenvalue):
201 meanMeasX += assignProb / lambda1 * rioOnTrack(i).localParameters()[Trk::locX];
202 meanMeasY += assignProb / lambda2 * rioOnTrack(i).localParameters()[Trk::locY];
203 }
204 meanTheta /= sumAssignProb;
205 meanMeasX /= meanEigen1;
206 meanMeasY /= meanEigen2;
207
208 const double cosTheta = cos(meanTheta);
209 const double sinTheta = sin(meanTheta);
210 meanWeightMatrix = Amg::MatrixX(2, 2);
211 meanWeightMatrix.setZero();
212 meanWeightMatrix(0, 0) =
213 cosTheta * cosTheta * meanEigen1 + sinTheta * sinTheta * meanEigen2;
214 meanWeightMatrix(1, 1) =
215 cosTheta * cosTheta * meanEigen2 + sinTheta * sinTheta * meanEigen1;
216 meanWeightMatrix(0, 1) =
217 cosTheta * sinTheta * meanEigen1 - cosTheta * sinTheta * meanEigen2;
218 meanWeightMatrix(1, 0) = meanWeightMatrix(0, 1);
219
220 Amg::MatrixX weightMatrix_maxIndex =
221 rioOnTrack(maxProbIndex).localCovariance().inverse();
222 int orderInput = (weightMatrix_maxIndex(0, 0) > weightMatrix_maxIndex(1, 1)) ? -1 : 1;
223 int orderOutput = (meanWeightMatrix(0, 0) > meanWeightMatrix(1, 1)) ? -1 : 1;
224 if (orderInput * orderOutput < 0) {
225 std::cout << "Trk::CompetingSCT_ClustersOnTrack: order of dimensions "
226 "does not match!!!";
227 }
228
229 Trk::DefinedParameter Par1(meanMeasX, Trk::loc1);
230 Trk::DefinedParameter Par2(meanMeasY, Trk::loc2);
232 } else {
233 std::cout << "Trk::CompetingSCT_ClustersOnTrack: can not handle parameter key "
234 << paramKey << std::endl;
235 }
236 } else {
237 // not more than one non-vanishing ROT: use the ROT with highest prob
238 meanWeightMatrix = assignmentProbability(maxProbIndex) *
239 rioOnTrack(maxProbIndex).localCovariance().inverse();
240 m_localParams = rioOnTrack(maxProbIndex).localParameters();
241 }
242 // limit weight values against values too close to 0, otherwise inversion
243 // will fail!
244 if (meanWeightMatrix.trace() <= 1.0e-15) {
245 for (int i = 0; i < meanWeightMatrix.cols(); ++i)
246 meanWeightMatrix(i, i) = 1.0e-10;
247 }
248 m_localCovariance = meanWeightMatrix.inverse();
249
250 } else {
251
252 std::cout << "Trk::CompetingRIOsOnTrack: can not handle ROTs in different "
253 "surfaces without detector specific knowledge "
254 << std::endl;
255 }
256}
#define endmsg
if(febId1==febId2)
Class for competing SCT_Clusters, it extends the Trk::CompetingRIOsOnTrack base class.
const InDet::SCT_ClusterOnTrack & rioOnTrack(unsigned int) const
returns the RIO_OnTrack (also known as ROT) objects depending on the integer
bool ROTsHaveCommonSurface(const bool withNonVanishingAssignProb=true) const
Have all the contained ROTs a common associated surface?
MsgStream & dump(MsgStream &out) const
returns some information about this MeasurementBase/CompetingSCT_ClustersOnTrack.
unsigned int numberOfContainedROTs() const
Number of RIO_OnTracks to be contained by this CompetingRIOsOnTrack.
virtual void setLocalParametersAndErrorMatrix()
recalculate the LocalParameters and ErrorMatrix
std::vector< const InDet::SCT_ClusterOnTrack * > m_containedChildRots
The vector of contained InDet::SCT_ClusterOnTrack objects.
CompetingSCT_ClustersOnTrack & operator=(const CompetingSCT_ClustersOnTrack &compROT)
Assignment operator.
CxxUtils::CachedUniquePtr< const Amg::Vector3D > m_globalPosition
The global position.
CompetingSCT_ClustersOnTrack()
Default Constructor for POOL.
void clearChildRotVector()
private method to clear the Trk::RIO_OnTrack vector
Specific class to represent the SCT measurements.
virtual SCT_ClusterOnTrack * clone() const override final
Pseudo-constructor.
AssignmentProb assignmentProbability(unsigned int indx) const
returns the AssignmentProbability depending on the integer.
CompetingRIOsOnTrack & operator=(const CompetingRIOsOnTrack &compROT)=default
Assignment operator.
virtual MsgStream & dump(MsgStream &out) const override
returns the some information about the base class members (avoid code duplication)
unsigned int indexOfMaxAssignProb() const
Index of the ROT with the highest assignment probability.
CompetingRIOsOnTrack()
Default Constructor for POOL.
int parameterKey() const
Identifier key for matrix expansion/reduction.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
LocalParameters m_localParams
Amg::MatrixX m_localCovariance
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Ensure that the ATLAS eigen extensions are properly loaded.
@ locY
local cartesian
Definition ParamDefs.h:38
@ locX
Definition ParamDefs.h:37
@ loc2
generic first and second local coordinate
Definition ParamDefs.h:35
@ loc1
Definition ParamDefs.h:34
std::pair< double, ParamDefs > DefinedParameter
Typedef to of a std::pair<double, ParamDefs> to identify a passed-through double as a specific type o...
STL namespace.