CMS 3D CMS Logo

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