ATLAS Offline Software
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
21  , m_globalPosition{}
22 //
23 {
24 }
25 
26 // copy constructor
29  : Trk::CompetingRIOsOnTrack(compROT)
30  , m_globalPosition{}
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))
47  , m_globalPosition{}
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
63  m_containedChildRots.clear();
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
85  clearChildRotVector();
86  m_containedChildRots = std::move(compROT.m_containedChildRots);
87  m_globalPosition = std::move(compROT.m_globalPosition);
88  }
89  return (*this);
90 }
91 
92 
94 {
96 }
97 
98 void
100 {
102  delete rot;
103 }
104 
105 MsgStream&
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 
123 std::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?
142 bool
144 {
145  return true;
146 }
147 
148 void
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) {
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 =
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);
231  m_localParams = Trk::LocalParameters(Par1, Par2);
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 }
Trk::LocalParameters
Definition: LocalParameters.h:98
Amg::VectorX
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Definition: EventPrimitives.h:32
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:29
InDet::CompetingSCT_ClustersOnTrack::m_containedChildRots
std::vector< const InDet::SCT_ClusterOnTrack * > m_containedChildRots
The vector of contained InDet::SCT_ClusterOnTrack objects.
Definition: CompetingSCT_ClustersOnTrack.h:109
Trk::CompetingRIOsOnTrack::dump
virtual MsgStream & dump(MsgStream &out) const override
returns the some information about the base class members (avoid code duplication)
Definition: CompetingRIOsOnTrack.cxx:115
Trk::locX
@ locX
Definition: ParamDefs.h:43
Trk::locY
@ locY
local cartesian
Definition: ParamDefs.h:44
Surface.h
Trk::LocalParameters::parameterKey
int parameterKey() const
Identifier key for matrix expansion/reduction.
InDet::CompetingSCT_ClustersOnTrack::dump
MsgStream & dump(MsgStream &out) const
returns some information about this MeasurementBase/CompetingSCT_ClustersOnTrack.
Definition: CompetingSCT_ClustersOnTrack.cxx:106
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
InDet::CompetingSCT_ClustersOnTrack::clearChildRotVector
void clearChildRotVector()
private method to clear the Trk::RIO_OnTrack vector
Definition: CompetingSCT_ClustersOnTrack.cxx:99
Trk::loc2
@ loc2
generic first and second local coordinate
Definition: ParamDefs.h:41
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
InDet::CompetingSCT_ClustersOnTrack::CompetingSCT_ClustersOnTrack
CompetingSCT_ClustersOnTrack()
Default Constructor for POOL.
Definition: CompetingSCT_ClustersOnTrack.cxx:19
InDet::CompetingSCT_ClustersOnTrack::m_globalPosition
CxxUtils::CachedUniquePtr< const Amg::Vector3D > m_globalPosition
The global position.
Definition: CompetingSCT_ClustersOnTrack.h:106
InDet::CompetingSCT_ClustersOnTrack::operator=
CompetingSCT_ClustersOnTrack & operator=(const CompetingSCT_ClustersOnTrack &compROT)
Assignment operator.
Definition: CompetingSCT_ClustersOnTrack.cxx:55
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
Trk::DefinedParameter
std::pair< double, ParamDefs > DefinedParameter
Definition: DefinedParameter.h:27
InDet::CompetingSCT_ClustersOnTrack::setLocalParametersAndErrorMatrix
virtual void setLocalParametersAndErrorMatrix()
recalculate the LocalParameters and ErrorMatrix
Definition: CompetingSCT_ClustersOnTrack.cxx:149
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
CompetingSCT_ClustersOnTrack.h
Trk::CompetingRIOsOnTrack::operator=
CompetingRIOsOnTrack & operator=(const CompetingRIOsOnTrack &compROT)=default
Assignment operator.
lumiFormat.i
int i
Definition: lumiFormat.py:92
Trk::MeasurementBaseType::CompetingRIOsOnTrack
@ CompetingRIOsOnTrack
Definition: MeasurementBase.h:50
InDet::SCT_ClusterOnTrack::clone
virtual SCT_ClusterOnTrack * clone() const override final
Pseudo-constructor.
Definition: SCT_ClusterOnTrack.h:140
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
WritePulseShapeToCool.det
det
Definition: WritePulseShapeToCool.py:204
Trk::MeasurementBase::m_localParams
LocalParameters m_localParams
Definition: MeasurementBase.h:111
Trk::MeasurementBase::localCovariance
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
Definition: MeasurementBase.h:138
InDet::CompetingSCT_ClustersOnTrack::ROTsHaveCommonSurface
bool ROTsHaveCommonSurface(const bool withNonVanishingAssignProb=true) const
Have all the contained ROTs a common associated surface? If withNonVanishingAssignProb==true just the...
Definition: CompetingSCT_ClustersOnTrack.cxx:143
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
InDet::CompetingSCT_ClustersOnTrack::numberOfContainedROTs
unsigned int numberOfContainedROTs() const
Number of RIO_OnTracks to be contained by this CompetingRIOsOnTrack.
Definition: CompetingSCT_ClustersOnTrack.h:155
InDet::CompetingSCT_ClustersOnTrack
Definition: CompetingSCT_ClustersOnTrack.h:45
Trk::MeasurementBase::localParameters
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
Definition: MeasurementBase.h:132
Trk::MeasurementBase::m_localCovariance
Amg::MatrixX m_localCovariance
Definition: MeasurementBase.h:112
InDet::CompetingSCT_ClustersOnTrack::rioOnTrack
const InDet::SCT_ClusterOnTrack & rioOnTrack(unsigned int) const
returns the RIO_OnTrack (also known as ROT) objects depending on the integer
Definition: CompetingSCT_ClustersOnTrack.h:139
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
InDet::CompetingSCT_ClustersOnTrack::~CompetingSCT_ClustersOnTrack
virtual ~CompetingSCT_ClustersOnTrack()
Destructor.
Definition: CompetingSCT_ClustersOnTrack.cxx:93
Trk::CompetingRIOsOnTrack::indexOfMaxAssignProb
unsigned int indexOfMaxAssignProb() const
Index of the ROT with the highest assignment probability.
Definition: CompetingRIOsOnTrack.cxx:101
Trk::loc1
@ loc1
Definition: ParamDefs.h:40
Trk::CompetingRIOsOnTrack::assignmentProbability
AssignmentProb assignmentProbability(unsigned int indx) const
returns the AssignmentProbability depending on the integer.
Definition: CompetingRIOsOnTrack.h:139
InDet::SCT_ClusterOnTrack
Definition: SCT_ClusterOnTrack.h:44