1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
#include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentCorrelationsStore.h"
#include "Alignment/CommonAlignment/interface/Alignable.h"
#include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
AlignmentCorrelationsStore::AlignmentCorrelationsStore(void) {
edm::LogInfo("Alignment") << "@SUB=AlignmentCorrelationsStore::AlignmentCorrelationsStore "
<< "\nCreated.";
}
void AlignmentCorrelationsStore::correlations(
Alignable* ap1, Alignable* ap2, AlgebraicSymMatrix& cov, int row, int col) const {
static Alignable* previousAlignable = nullptr;
static CorrelationsTable* previousCorrelations;
// Needed by 'resetCorrelations()' to reset the static pointer:
if (ap1 == nullptr) {
previousAlignable = nullptr;
return;
}
bool transpose = (ap2 > ap1);
if (transpose)
std::swap(ap1, ap2);
if (ap1 == previousAlignable) {
CorrelationsTable::const_iterator itC2 = previousCorrelations->find(ap2);
if (itC2 != previousCorrelations->end()) {
transpose ? fillCovarianceT(ap1, ap2, (*itC2).second, cov, row, col)
: fillCovariance(ap1, ap2, (*itC2).second, cov, row, col);
}
} else {
Correlations::const_iterator itC1 = theCorrelations.find(ap1);
if (itC1 != theCorrelations.end()) {
previousAlignable = ap1;
previousCorrelations = (*itC1).second;
CorrelationsTable::const_iterator itC2 = (*itC1).second->find(ap2);
if (itC2 != (*itC1).second->end()) {
transpose ? fillCovarianceT(ap1, ap2, (*itC2).second, cov, row, col)
: fillCovariance(ap1, ap2, (*itC2).second, cov, row, col);
}
}
}
// don't fill anything into the covariance if there's no entry
return;
}
void AlignmentCorrelationsStore::setCorrelations(
Alignable* ap1, Alignable* ap2, const AlgebraicSymMatrix& cov, int row, int col) {
static Alignable* previousAlignable = nullptr;
static CorrelationsTable* previousCorrelations;
// Needed by 'resetCorrelations()' to reset the static pointer:
if (ap1 == nullptr) {
previousAlignable = nullptr;
return;
}
bool transpose = (ap2 > ap1);
if (transpose)
std::swap(ap1, ap2);
if (ap1 == previousAlignable) {
fillCorrelationsTable(ap1, ap2, previousCorrelations, cov, row, col, transpose);
} else {
Correlations::iterator itC = theCorrelations.find(ap1);
if (itC != theCorrelations.end()) {
fillCorrelationsTable(ap1, ap2, itC->second, cov, row, col, transpose);
previousAlignable = ap1;
previousCorrelations = itC->second;
} else {
CorrelationsTable* newTable = new CorrelationsTable;
fillCorrelationsTable(ap1, ap2, newTable, cov, row, col, transpose);
theCorrelations[ap1] = newTable;
previousAlignable = ap1;
previousCorrelations = newTable;
}
}
}
void AlignmentCorrelationsStore::setCorrelations(Alignable* ap1, Alignable* ap2, AlgebraicMatrix& mat) {
bool transpose = (ap2 > ap1);
if (transpose)
std::swap(ap1, ap2);
Correlations::iterator itC1 = theCorrelations.find(ap1);
if (itC1 != theCorrelations.end()) {
(*itC1->second)[ap2] = transpose ? mat.T() : mat;
} else {
CorrelationsTable* newTable = new CorrelationsTable;
(*newTable)[ap2] = transpose ? mat.T() : mat;
theCorrelations[ap1] = newTable;
}
}
bool AlignmentCorrelationsStore::correlationsAvailable(Alignable* ap1, Alignable* ap2) const {
bool transpose = (ap2 > ap1);
if (transpose)
std::swap(ap1, ap2);
Correlations::const_iterator itC1 = theCorrelations.find(ap1);
if (itC1 != theCorrelations.end()) {
CorrelationsTable::const_iterator itC2 = itC1->second->find(ap2);
if (itC2 != itC1->second->end())
return true;
}
return false;
}
void AlignmentCorrelationsStore::resetCorrelations(void) {
Correlations::iterator itC;
for (itC = theCorrelations.begin(); itC != theCorrelations.end(); ++itC)
delete (*itC).second;
theCorrelations.erase(theCorrelations.begin(), theCorrelations.end());
// Reset the static pointers to the 'previous alignables'
AlgebraicSymMatrix dummy;
correlations(nullptr, nullptr, dummy, 0, 0);
setCorrelations(nullptr, nullptr, dummy, 0, 0);
}
unsigned int AlignmentCorrelationsStore::size(void) const {
unsigned int size = 0;
Correlations::const_iterator itC;
for (itC = theCorrelations.begin(); itC != theCorrelations.end(); ++itC)
size += itC->second->size();
return size;
}
void AlignmentCorrelationsStore::fillCorrelationsTable(Alignable* ap1,
Alignable* ap2,
CorrelationsTable* table,
const AlgebraicSymMatrix& cov,
int row,
int col,
bool transpose) {
CorrelationsTable::iterator itC = table->find(ap2);
if (itC != table->end()) {
transpose ? readFromCovarianceT(ap1, ap2, itC->second, cov, row, col)
: readFromCovariance(ap1, ap2, itC->second, cov, row, col);
} else {
int nRow = ap1->alignmentParameters()->numSelected();
int nCol = ap2->alignmentParameters()->numSelected();
AlgebraicMatrix newEntry(nRow, nCol);
transpose ? readFromCovarianceT(ap1, ap2, newEntry, cov, row, col)
: readFromCovariance(ap1, ap2, newEntry, cov, row, col);
(*table)[ap2] = newEntry;
}
}
void AlignmentCorrelationsStore::fillCovariance(
Alignable* ap1, Alignable* ap2, const AlgebraicMatrix& entry, AlgebraicSymMatrix& cov, int row, int col) const {
int nRow = entry.num_row();
int nCol = entry.num_col();
for (int iRow = 0; iRow < nRow; ++iRow)
for (int jCol = 0; jCol < nCol; ++jCol)
cov[row + iRow][col + jCol] = entry[iRow][jCol];
}
void AlignmentCorrelationsStore::fillCovarianceT(
Alignable* ap1, Alignable* ap2, const AlgebraicMatrix& entry, AlgebraicSymMatrix& cov, int row, int col) const {
int nRow = entry.num_row();
int nCol = entry.num_col();
for (int iRow = 0; iRow < nRow; ++iRow)
for (int jCol = 0; jCol < nCol; ++jCol)
cov[row + jCol][col + iRow] = entry[iRow][jCol];
}
void AlignmentCorrelationsStore::readFromCovariance(
Alignable* ap1, Alignable* ap2, AlgebraicMatrix& entry, const AlgebraicSymMatrix& cov, int row, int col) {
int nRow = entry.num_row();
int nCol = entry.num_col();
for (int iRow = 0; iRow < nRow; ++iRow)
for (int jCol = 0; jCol < nCol; ++jCol)
entry[iRow][jCol] = cov[row + iRow][col + jCol];
}
void AlignmentCorrelationsStore::readFromCovarianceT(
Alignable* ap1, Alignable* ap2, AlgebraicMatrix& entry, const AlgebraicSymMatrix& cov, int row, int col) {
int nRow = entry.num_row();
int nCol = entry.num_col();
for (int iRow = 0; iRow < nRow; ++iRow)
for (int jCol = 0; jCol < nCol; ++jCol)
entry[iRow][jCol] = cov[row + jCol][col + iRow];
}
|