ATLAS Offline Software
Loading...
Searching...
No Matches
CompetingRIOsOnTrack.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// CompetingRIOsOnTrack.cxx, (c) ATLAS Detector software
8
10
13#include "GaudiKernel/MsgStream.h"
14#include <boost/io/ios_state.hpp>
15#include <iostream>
16
17// default constructor
23// constructor with parameters
24Trk::CompetingRIOsOnTrack::CompetingRIOsOnTrack(std::vector<AssignmentProb>&& assgnProb)
26 , m_assignProb(std::move(assgnProb))
27{
28}
29
30// return the effective LocalParameters according to the weights (assignment probabilities)
31//@f$ \~m = (\sum_i p_i G_i)^{-1} \sum_i p_i G_i m_i @f$
32void
34{
35
37 // std::cout << "CompROT - weight matrices: " << std::endl;
38 // std::cout << "CompROT - [1] " << rioOnTrack(0).localCovariance() << std::endl;
39 Amg::MatrixX meanWeightMatrix =
40 assignmentProbability(0) * rioOnTrack(0).localCovariance().inverse();
41 for (unsigned int i = 1; i < numberOfContainedROTs(); i++) {
42 meanWeightMatrix += assignmentProbability(i) * rioOnTrack(i).localCovariance().inverse();
43 // std::cout << "CompROT - ["<< i << "] " << rioOnTrack(i).localCovariance() <<
44 // std::endl;
45 }
46 // limit weight values against values too close to 0, otherwise inversion will fail!
47 if (meanWeightMatrix.trace() <= 1.0e-15) {
48 meanWeightMatrix = Amg::MatrixX(rioOnTrack(0).localCovariance().rows(),
49 rioOnTrack(0).localCovariance().cols());
50 meanWeightMatrix.setZero();
51 for (int i = 0; i < meanWeightMatrix.cols(); ++i) {
52 meanWeightMatrix(i, i) = 1.0e-10;
53 }
54 }
55 // std::cout << "CompROT - mean weight: " << meanWeightMatrix << std::endl;
56 m_localCovariance = meanWeightMatrix.inverse();
57 // std::cout << "CompROT - mean covariance: " << localCovariance() << std::endl;
58
59 if (numberOfContainedROTs() == 1) {
60 m_localParams = rioOnTrack(0).localParameters();
61 } else {
62 Amg::MatrixX weight = rioOnTrack(0).localCovariance().inverse();
63 Amg::VectorX meanParams =
64 assignmentProbability(0) * weight * rioOnTrack(0).localParameters();
65 for (unsigned int i = 1; i < numberOfContainedROTs(); i++) {
66 weight = rioOnTrack(i).localCovariance().inverse();
67 meanParams =
68 meanParams + assignmentProbability(i) * weight * rioOnTrack(i).localParameters();
69 }
70 // std::cout << "CompROT - sum params: " << meanParams << std::endl;
71 meanParams = localCovariance() * meanParams;
72 // std::cout << "CompROT - mean params: " << meanParams << std::endl;
73 int paramKey = rioOnTrack(0).localParameters().parameterKey();
74 if (paramKey == 1) {
75 Trk::DefinedParameter Par1(meanParams[Trk::loc1], Trk::loc1);
77 } else if (paramKey == 3) {
78 Trk::DefinedParameter Par1(meanParams[Trk::loc1], Trk::loc1);
79 Trk::DefinedParameter Par2(meanParams[Trk::loc2], Trk::loc2);
81 } else {
82 std::cout << "Trk::CompetingRIOsOnTrack: can not handle parameter key " << paramKey
83 << std::endl;
84 }
85 }
86 } else {
87 // --------------------------------------------------
88 // Warning: effective localParams cannot be calculated when ROTs don't lie on the
89 // associated surface without detector specific knowledge.
90 // --------------------------------------------------
91 // return 0;
92 std::cout
93 << "Trk::CompetingRIOsOnTrack: can not handle ROTs in different surfaces without "
94 "detector specific knowledge "
95 << std::endl;
96 }
97}
98
99unsigned int
101{
102 unsigned int index = 0;
103 double maxAssgnProb = 0;
104 for (unsigned int i = 0; i < numberOfContainedROTs(); i++) {
105 if (m_assignProb[i] >= maxAssgnProb) {
106 index = i;
107 maxAssgnProb = m_assignProb[i];
108 }
109 }
110 return index;
111}
112
113MsgStream&
115{
116
117 boost::io::ios_all_saver ias(out.stream());
118 out << " - effective pars locX : ";
119 if (m_localParams.contains(Trk::locX)) {
120 out << (m_localParams)[Trk::locX];
121 if (m_localParams.contains(Trk::locY)) {
122 out << " and " << (m_localParams)[Trk::locY];
123 }
124 } else {
125 out << "ill-defined! They are " << m_localParams;
126 }
128 if (m_localParams.contains(Trk::locY)) {
130 out << std::endl // << std::setiosflags(ios::right)<<std::setiosflags(ios::adjustfield)
131 << std::setiosflags(std::ios::fixed) << std::resetiosflags(std::ios::scientific)
132 << std::setprecision(6);
133 }
134 unsigned int indexOfMaxProb = indexOfMaxAssignProb();
135 out << " - Contains: |ROT# identifier locX dLocX locY dlocY "
136 "ass.Prob |";
137 for (unsigned int i = 0; i < this->numberOfContainedROTs(); ++i) {
138 out << std::endl
139 << " | " << i << " " << this->rioOnTrack(i).identify() << " ";
141 out << std::setw(10) << this->rioOnTrack(i).localParameters()[Trk::locX] << " "
142 << 1 / this->rioOnTrack(i).localCovariance()(Trk::locX, Trk::locX);
143 } else {
144 out << " ";
145 }
147 out << " " << std::setw(10) << this->rioOnTrack(i).localParameters()[Trk::locY] << " "
148 << 1 / this->rioOnTrack(i).localCovariance()(Trk::locY, Trk::locY) << " ";
149 } else {
150 out << " ";
151 }
152 out << " " << m_assignProb.at(i) << (indexOfMaxProb == i ? " **|" : " |");
153 }
154 ias.restore();
155 return out;
156}
157
158std::ostream&
159Trk::CompetingRIOsOnTrack::dump(std::ostream& out) const
160{
161 boost::io::ios_all_saver ias(out);
162 out << " - effective pars locX : ";
163 if (m_localParams.contains(Trk::locX)) {
164 out << (m_localParams)[Trk::locX];
165 if (m_localParams.contains(Trk::locY)) {
166 out << " and " << (m_localParams)[Trk::locY];
167 }
168 } else {
169 out << "ill-defined! They are " << m_localParams;
170 }
172 if (m_localParams.contains(Trk::locY)) {
174 out << std::endl // << std::setiosflags(ios::right)<<std::setiosflags(ios::adjustfield)
175 << std::setiosflags(std::ios::fixed) << std::resetiosflags(std::ios::scientific)
176 << std::setprecision(6);
177 }
178
179 unsigned int indexOfMaxProb = indexOfMaxAssignProb();
180 out << " - Contains: |ROT# identifier locX dLocX locY dlocY "
181 "ass.Prob |";
182 for (unsigned int i = 0; i < this->numberOfContainedROTs(); ++i) {
183 out << std::endl
184 << " | " << i << " " << this->rioOnTrack(i).identify() << " ";
186 out << std::setw(10) << this->rioOnTrack(i).localParameters()[Trk::locX] << " "
187 << 1 / this->rioOnTrack(i).localCovariance()(Trk::locX, Trk::locX);
188 } else {
189 out << " ";
190 }
192 out << " " << std::setw(10) << this->rioOnTrack(i).localParameters()[Trk::locY] << " "
193 << 1 / this->rioOnTrack(i).localCovariance()(Trk::locY, Trk::locY) << " ";
194 } else {
195 out << " ";
196 }
197 out << " " << m_assignProb.at(i) << (indexOfMaxProb == i ? " **|" : " |");
198 }
199 ias.restore();
200 return out;
201}
virtual bool ROTsHaveCommonSurface(const bool withNonVanishingAssignProb=true) const =0
query if all the contained ROTs have a common associated surface.
virtual void setLocalParametersAndErrorMatrix()
recalculate the LocalParameters and ErrorMatrix
std::vector< AssignmentProb > m_assignProb
assignment probabilities of the ROTs
AssignmentProb assignmentProbability(unsigned int indx) const
returns the AssignmentProbability depending on the integer.
virtual unsigned int numberOfContainedROTs() const =0
Number of RIO_OnTracks to be contained by this CompetingRIOsOnTrack.
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.
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
CompetingRIOsOnTrack()
Default Constructor for POOL.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
MeasurementBase()=default
Default constructor - needed for POOL/SEAL.
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
LocalParameters m_localParams
Amg::MatrixX m_localCovariance
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
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...
Definition index.py:1
STL namespace.