ATLAS Offline Software
CompetingRIOsOnTrack.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 // CompetingRIOsOnTrack.cxx, (c) ATLAS Detector software
8 
10 // CLHEP
11 //#include "CLHEP/Matrix/SymMatrix.h"
14 
15 #include <boost/io/ios_state.hpp>
16 #include <iostream>
17 
18 // default constructor
20  : Trk::MeasurementBase()
21  , m_assignProb()
22 {
23 }
24 // constructor with parameters
25 Trk::CompetingRIOsOnTrack::CompetingRIOsOnTrack(std::vector<AssignmentProb>&& assgnProb)
26  : Trk::MeasurementBase()
27  , m_assignProb(std::move(assgnProb))
28 {
29 }
30 
31 // return the effective LocalParameters according to the weights (assignment probabilities)
32 //@f$ \~m = (\sum_i p_i G_i)^{-1} \sum_i p_i G_i m_i @f$
33 void
35 {
36 
37  if (ROTsHaveCommonSurface()) {
38  // std::cout << "CompROT - weight matrices: " << std::endl;
39  // std::cout << "CompROT - [1] " << rioOnTrack(0).localCovariance() << std::endl;
40  Amg::MatrixX meanWeightMatrix =
41  assignmentProbability(0) * rioOnTrack(0).localCovariance().inverse();
42  for (unsigned int i = 1; i < numberOfContainedROTs(); i++) {
43  meanWeightMatrix += assignmentProbability(i) * rioOnTrack(i).localCovariance().inverse();
44  // std::cout << "CompROT - ["<< i << "] " << rioOnTrack(i).localCovariance() <<
45  // std::endl;
46  }
47  // limit weight values against values too close to 0, otherwise inversion will fail!
48  if (meanWeightMatrix.trace() <= 1.0e-15) {
49  meanWeightMatrix = Amg::MatrixX(rioOnTrack(0).localCovariance().rows(),
50  rioOnTrack(0).localCovariance().cols());
51  meanWeightMatrix.setZero();
52  for (int i = 0; i < meanWeightMatrix.cols(); ++i) {
53  meanWeightMatrix(i, i) = 1.0e-10;
54  }
55  }
56  // std::cout << "CompROT - mean weight: " << meanWeightMatrix << std::endl;
57  m_localCovariance = meanWeightMatrix.inverse();
58  // std::cout << "CompROT - mean covariance: " << localCovariance() << std::endl;
59 
60  if (numberOfContainedROTs() == 1) {
61  m_localParams = rioOnTrack(0).localParameters();
62  } else {
63  Amg::MatrixX weight = rioOnTrack(0).localCovariance().inverse();
64  Amg::VectorX meanParams =
65  assignmentProbability(0) * weight * rioOnTrack(0).localParameters();
66  for (unsigned int i = 1; i < numberOfContainedROTs(); i++) {
67  weight = rioOnTrack(i).localCovariance().inverse();
68  meanParams =
69  meanParams + assignmentProbability(i) * weight * rioOnTrack(i).localParameters();
70  }
71  // std::cout << "CompROT - sum params: " << meanParams << std::endl;
72  meanParams = localCovariance() * meanParams;
73  // std::cout << "CompROT - mean params: " << meanParams << std::endl;
74  int paramKey = rioOnTrack(0).localParameters().parameterKey();
75  if (paramKey == 1) {
76  Trk::DefinedParameter Par1(meanParams[Trk::loc1], Trk::loc1);
77  m_localParams = Trk::LocalParameters(Par1);
78  } else if (paramKey == 3) {
79  Trk::DefinedParameter Par1(meanParams[Trk::loc1], Trk::loc1);
80  Trk::DefinedParameter Par2(meanParams[Trk::loc2], Trk::loc2);
81  m_localParams = Trk::LocalParameters(Par1, Par2);
82  } else {
83  std::cout << "Trk::CompetingRIOsOnTrack: can not handle parameter key " << paramKey
84  << std::endl;
85  }
86  }
87  } else {
88  // --------------------------------------------------
89  // Warning: effective localParams cannot be calculated when ROTs don't lie on the
90  // associated surface without detector specific knowledge.
91  // --------------------------------------------------
92  // return 0;
93  std::cout
94  << "Trk::CompetingRIOsOnTrack: can not handle ROTs in different surfaces without "
95  "detector specific knowledge "
96  << std::endl;
97  }
98 }
99 
100 unsigned int
102 {
103  unsigned int index = 0;
104  double maxAssgnProb = 0;
105  for (unsigned int i = 0; i < numberOfContainedROTs(); i++) {
106  if (m_assignProb[i] >= maxAssgnProb) {
107  index = i;
108  maxAssgnProb = m_assignProb[i];
109  }
110  }
111  return index;
112 }
113 
114 MsgStream&
116 {
117 
118  boost::io::ios_all_saver ias(out.stream());
119  out << " - effective pars locX : ";
120  if (m_localParams.contains(Trk::locX)) {
121  out << (m_localParams)[Trk::locX];
122  if (m_localParams.contains(Trk::locY)) {
123  out << " and " << (m_localParams)[Trk::locY];
124  }
125  } else {
126  out << "ill-defined! They are " << m_localParams;
127  }
129  if (m_localParams.contains(Trk::locY)) {
131  out << std::endl // << std::setiosflags(ios::right)<<std::setiosflags(ios::adjustfield)
132  << std::setiosflags(std::ios::fixed) << std::resetiosflags(std::ios::scientific)
133  << std::setprecision(6);
134  }
135  unsigned int indexOfMaxProb = indexOfMaxAssignProb();
136  out << " - Contains: |ROT# identifier locX dLocX locY dlocY "
137  "ass.Prob |";
138  for (unsigned int i = 0; i < this->numberOfContainedROTs(); ++i) {
139  out << std::endl
140  << " | " << i << " " << this->rioOnTrack(i).identify() << " ";
141  if (this->rioOnTrack(i).localParameters().contains(Trk::locX)) {
142  out << std::setw(10) << this->rioOnTrack(i).localParameters()[Trk::locX] << " "
143  << 1 / this->rioOnTrack(i).localCovariance()(Trk::locX, Trk::locX);
144  } else {
145  out << " ";
146  }
147  if (this->rioOnTrack(i).localParameters().contains(Trk::locY)) {
148  out << " " << std::setw(10) << this->rioOnTrack(i).localParameters()[Trk::locY] << " "
149  << 1 / this->rioOnTrack(i).localCovariance()(Trk::locY, Trk::locY) << " ";
150  } else {
151  out << " ";
152  }
153  out << " " << m_assignProb.at(i) << (indexOfMaxProb == i ? " **|" : " |");
154  }
155  ias.restore();
156  return out;
157 }
158 
159 std::ostream&
161 {
162  boost::io::ios_all_saver ias(out);
163  out << " - effective pars locX : ";
164  if (m_localParams.contains(Trk::locX)) {
165  out << (m_localParams)[Trk::locX];
166  if (m_localParams.contains(Trk::locY)) {
167  out << " and " << (m_localParams)[Trk::locY];
168  }
169  } else {
170  out << "ill-defined! They are " << m_localParams;
171  }
173  if (m_localParams.contains(Trk::locY)) {
175  out << std::endl // << std::setiosflags(ios::right)<<std::setiosflags(ios::adjustfield)
176  << std::setiosflags(std::ios::fixed) << std::resetiosflags(std::ios::scientific)
177  << std::setprecision(6);
178  }
179 
180  unsigned int indexOfMaxProb = indexOfMaxAssignProb();
181  out << " - Contains: |ROT# identifier locX dLocX locY dlocY "
182  "ass.Prob |";
183  for (unsigned int i = 0; i < this->numberOfContainedROTs(); ++i) {
184  out << std::endl
185  << " | " << i << " " << this->rioOnTrack(i).identify() << " ";
186  if (this->rioOnTrack(i).localParameters().contains(Trk::locX)) {
187  out << std::setw(10) << this->rioOnTrack(i).localParameters()[Trk::locX] << " "
188  << 1 / this->rioOnTrack(i).localCovariance()(Trk::locX, Trk::locX);
189  } else {
190  out << " ";
191  }
192  if (this->rioOnTrack(i).localParameters().contains(Trk::locY)) {
193  out << " " << std::setw(10) << this->rioOnTrack(i).localParameters()[Trk::locY] << " "
194  << 1 / this->rioOnTrack(i).localCovariance()(Trk::locY, Trk::locY) << " ";
195  } else {
196  out << " ";
197  }
198  out << " " << m_assignProb.at(i) << (indexOfMaxProb == i ? " **|" : " |");
199  }
200  ias.restore();
201  return out;
202 }
Trk::LocalParameters
Definition: LocalParameters.h:98
Amg::VectorX
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Definition: EventPrimitives.h:30
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:27
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:37
CompetingRIOsOnTrack.h
Trk::locY
@ locY
local cartesian
Definition: ParamDefs.h:38
index
Definition: index.py:1
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
Trk::loc2
@ loc2
generic first and second local coordinate
Definition: ParamDefs.h:35
Trk::CompetingRIOsOnTrack::setLocalParametersAndErrorMatrix
virtual void setLocalParametersAndErrorMatrix()
recalculate the LocalParameters and ErrorMatrix
Definition: CompetingRIOsOnTrack.cxx:34
Trk::DefinedParameter
std::pair< double, ParamDefs > DefinedParameter
Definition: DefinedParameter.h:27
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
beamspotnt.cols
list cols
Definition: bin/beamspotnt.py:1114
lumiFormat.i
int i
Definition: lumiFormat.py:85
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
beamspotnt.rows
list rows
Definition: bin/beamspotnt.py:1112
Trk::MeasurementBase
Definition: MeasurementBase.h:58
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
RIO_OnTrack.h
LocalParameters.h
DeMoScan.index
string index
Definition: DeMoScan.py:364
Trk::CompetingRIOsOnTrack::CompetingRIOsOnTrack
CompetingRIOsOnTrack()
Default Constructor for POOL.
Definition: CompetingRIOsOnTrack.cxx:19
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:34