CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
AlignmentExtendedCorrelationsStore Class Reference

#include <AlignmentExtendedCorrelationsStore.h>

Inheritance diagram for AlignmentExtendedCorrelationsStore:
AlignmentCorrelationsStore

Public Types

typedef std::map< Alignable *, ExtendedCorrelationsTable * > ExtendedCorrelations
 
typedef AlignmentExtendedCorrelationsEntry ExtendedCorrelationsEntry
 
typedef std::map< Alignable *, ExtendedCorrelationsEntryExtendedCorrelationsTable
 
- Public Types inherited from AlignmentCorrelationsStore
typedef std::map< Alignable *, CorrelationsTable * > Correlations
 
typedef std::map< Alignable *, AlgebraicMatrixCorrelationsTable
 

Public Member Functions

 AlignmentExtendedCorrelationsStore (const edm::ParameterSet &config)
 
void correlations (Alignable *ap1, Alignable *ap2, AlgebraicSymMatrix &cov, int row, int col) const override
 
bool correlationsAvailable (Alignable *ap1, Alignable *ap2) const override
 Check whether correlations are stored for a given pair of alignables. More...
 
virtual void getCorrelations (Alignable *ap1, Alignable *ap2, AlgebraicMatrix &mat) const
 Get correlations. More...
 
void resetCorrelations (void) override
 Reset correlations. More...
 
void setCorrelations (Alignable *ap1, Alignable *ap2, const AlgebraicSymMatrix &cov, int row, int col) override
 
void setCorrelations (Alignable *ap1, Alignable *ap2, AlgebraicMatrix &mat) override
 
unsigned int size (void) const override
 Get number of stored correlations. More...
 
 ~AlignmentExtendedCorrelationsStore (void) override
 
- Public Member Functions inherited from AlignmentCorrelationsStore
 AlignmentCorrelationsStore (void)
 
virtual ~AlignmentCorrelationsStore (void)
 

Private Member Functions

void fillCorrelationsTable (Alignable *ap1, Alignable *ap2, ExtendedCorrelationsTable *table, const AlgebraicSymMatrix &cov, int row, int col, bool transpose)
 
void fillCovariance (Alignable *ap1, Alignable *ap2, const ExtendedCorrelationsEntry &entry, AlgebraicSymMatrix &cov, int row, int col) const
 
void fillCovarianceT (Alignable *ap1, Alignable *ap2, const ExtendedCorrelationsEntry &entry, AlgebraicSymMatrix &cov, int row, int col) const
 
void readFromCovariance (Alignable *ap1, Alignable *ap2, ExtendedCorrelationsEntry &entry, const AlgebraicSymMatrix &cov, int row, int col)
 
void readFromCovarianceT (Alignable *ap1, Alignable *ap2, ExtendedCorrelationsEntry &entry, const AlgebraicSymMatrix &cov, int row, int col)
 
void resizeCorruptCorrelations (ExtendedCorrelationsEntry &entry, double maxCorr)
 

Private Attributes

ExtendedCorrelations theCorrelations
 
double theCut
 
int theMaxUpdates
 
double theWeight
 

Detailed Description

Definition at line 19 of file AlignmentExtendedCorrelationsStore.h.

Member Typedef Documentation

Definition at line 23 of file AlignmentExtendedCorrelationsStore.h.

Definition at line 21 of file AlignmentExtendedCorrelationsStore.h.

Definition at line 22 of file AlignmentExtendedCorrelationsStore.h.

Constructor & Destructor Documentation

AlignmentExtendedCorrelationsStore::AlignmentExtendedCorrelationsStore ( const edm::ParameterSet config)

Definition at line 11 of file AlignmentExtendedCorrelationsStore.cc.

References edm::ParameterSet::getParameter(), theCut, theMaxUpdates, and theWeight.

11  {
12  theMaxUpdates = config.getParameter<int>("MaxUpdates");
13  theCut = config.getParameter<double>("CutValue");
14  theWeight = config.getParameter<double>("Weight");
15 
16  edm::LogInfo("Alignment") << "@SUB=AlignmentExtendedCorrelationsStore::AlignmentExtendedCorrelationsStore"
17  << "Created.";
18 }
T getParameter(std::string const &) const
AlignmentExtendedCorrelationsStore::~AlignmentExtendedCorrelationsStore ( void  )
inlineoverride

Member Function Documentation

void AlignmentExtendedCorrelationsStore::correlations ( Alignable ap1,
Alignable ap2,
AlgebraicSymMatrix cov,
int  row,
int  col 
) const
overridevirtual

Write correlations directly to the covariance matrix starting at the given position. Indices are assumed to start from 0.

Reimplemented from AlignmentCorrelationsStore.

Definition at line 20 of file AlignmentExtendedCorrelationsStore.cc.

References fillCovariance(), fillCovarianceT(), std::swap(), theCorrelations, and geometryDiff::transpose().

Referenced by resetCorrelations().

21  {
22  static Alignable* previousAlignable = nullptr;
23  static ExtendedCorrelationsTable* previousCorrelations;
24 
25  // Needed by 'resetCorrelations()' to reset the static pointer:
26  if (ap1 == nullptr) {
27  previousAlignable = nullptr;
28  return;
29  }
30 
31  bool transpose = (ap2 > ap1);
32  if (transpose)
33  std::swap(ap1, ap2);
34 
35  if (ap1 == previousAlignable) {
36  ExtendedCorrelationsTable::const_iterator itC2 = previousCorrelations->find(ap2);
37  if (itC2 != previousCorrelations->end()) {
38  transpose ? fillCovarianceT(ap1, ap2, (*itC2).second, cov, row, col)
39  : fillCovariance(ap1, ap2, (*itC2).second, cov, row, col);
40  }
41  } else {
42  ExtendedCorrelations::const_iterator itC1 = theCorrelations.find(ap1);
43  if (itC1 != theCorrelations.end()) {
44  previousAlignable = ap1;
45  previousCorrelations = (*itC1).second;
46 
47  ExtendedCorrelationsTable::const_iterator itC2 = (*itC1).second->find(ap2);
48  if (itC2 != (*itC1).second->end()) {
49  transpose ? fillCovarianceT(ap1, ap2, (*itC2).second, cov, row, col)
50  : fillCovariance(ap1, ap2, (*itC2).second, cov, row, col);
51  }
52  }
53  }
54 
55  // don't fill anything into the covariance if there's no entry
56  return;
57 }
def transpose(a)
Definition: geometryDiff.py:39
std::map< Alignable *, ExtendedCorrelationsEntry > ExtendedCorrelationsTable
void fillCovariance(Alignable *ap1, Alignable *ap2, const ExtendedCorrelationsEntry &entry, AlgebraicSymMatrix &cov, int row, int col) const
U second(std::pair< T, U > const &p)
void fillCovarianceT(Alignable *ap1, Alignable *ap2, const ExtendedCorrelationsEntry &entry, AlgebraicSymMatrix &cov, int row, int col) const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
col
Definition: cuy.py:1010
bool AlignmentExtendedCorrelationsStore::correlationsAvailable ( Alignable ap1,
Alignable ap2 
) const
overridevirtual

Check whether correlations are stored for a given pair of alignables.

Reimplemented from AlignmentCorrelationsStore.

Definition at line 132 of file AlignmentExtendedCorrelationsStore.cc.

References std::swap(), theCorrelations, and geometryDiff::transpose().

132  {
133  bool transpose = (ap2 > ap1);
134  if (transpose)
135  std::swap(ap1, ap2);
136 
137  ExtendedCorrelations::const_iterator itC1 = theCorrelations.find(ap1);
138  if (itC1 != theCorrelations.end()) {
139  ExtendedCorrelationsTable::const_iterator itC2 = itC1->second->find(ap2);
140  if (itC2 != itC1->second->end())
141  return true;
142  }
143  return false;
144 }
def transpose(a)
Definition: geometryDiff.py:39
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
void AlignmentExtendedCorrelationsStore::fillCorrelationsTable ( Alignable ap1,
Alignable ap2,
ExtendedCorrelationsTable table,
const AlgebraicSymMatrix cov,
int  row,
int  col,
bool  transpose 
)
private

Definition at line 167 of file AlignmentExtendedCorrelationsStore.cc.

References Alignable::alignmentParameters(), AlignmentParameters::numSelected(), readFromCovariance(), and readFromCovarianceT().

Referenced by setCorrelations().

173  {
174  ExtendedCorrelationsTable::iterator itC = table->find(ap2);
175 
176  if (itC != table->end()) {
177  //if ( itC->second.counter() > theMaxUpdates ) return;
178 
179  transpose ? readFromCovarianceT(ap1, ap2, itC->second, cov, row, col)
180  : readFromCovariance(ap1, ap2, itC->second, cov, row, col);
181 
182  //itC->second.incrementCounter();
183  } else {
184  int nRow = ap1->alignmentParameters()->numSelected();
185  int nCol = ap2->alignmentParameters()->numSelected();
186  ExtendedCorrelationsEntry newEntry(nRow, nCol);
187 
188  transpose ? readFromCovarianceT(ap1, ap2, newEntry, cov, row, col)
189  : readFromCovariance(ap1, ap2, newEntry, cov, row, col);
190 
191  (*table)[ap2] = newEntry;
192  }
193 }
def transpose(a)
Definition: geometryDiff.py:39
AlignmentExtendedCorrelationsEntry ExtendedCorrelationsEntry
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:61
U second(std::pair< T, U > const &p)
void readFromCovariance(Alignable *ap1, Alignable *ap2, ExtendedCorrelationsEntry &entry, const AlgebraicSymMatrix &cov, int row, int col)
int numSelected(void) const
Get number of selected parameters.
void readFromCovarianceT(Alignable *ap1, Alignable *ap2, ExtendedCorrelationsEntry &entry, const AlgebraicSymMatrix &cov, int row, int col)
col
Definition: cuy.py:1010
void AlignmentExtendedCorrelationsStore::fillCovariance ( Alignable ap1,
Alignable ap2,
const ExtendedCorrelationsEntry entry,
AlgebraicSymMatrix cov,
int  row,
int  col 
) const
private

Definition at line 195 of file AlignmentExtendedCorrelationsStore.cc.

References mps_splice::entry, Exception, edm::isNotFinite(), AlignmentExtendedCorrelationsEntry::numCol(), AlignmentExtendedCorrelationsEntry::numRow(), and mathSSE::sqrt().

Referenced by correlations().

200  {
201  int nRow = entry.numRow();
202  int nCol = entry.numCol();
203 
204  for (int iRow = 0; iRow < nRow; ++iRow) {
205  double factor = sqrt(cov[row + iRow][row + iRow]);
206  if (edm::isNotFinite(factor))
207  throw cms::Exception("LogicError") << "[AlignmentExtendedCorrelationsStore::fillCovariance] "
208  << "NaN-factor: sqrt(" << cov[row + iRow][row + iRow] << ")";
209 
210  for (int jCol = 0; jCol < nCol; ++jCol)
211  cov[row + iRow][col + jCol] = entry(iRow, jCol) * factor;
212  }
213 
214  for (int jCol = 0; jCol < nCol; ++jCol) {
215  double factor = sqrt(cov[col + jCol][col + jCol]);
216  if (edm::isNotFinite(factor))
217  throw cms::Exception("LogicError") << "[AlignmentExtendedCorrelationsStore::fillCovariance] "
218  << "NaN-factor: sqrt(" << cov[col + jCol][col + jCol] << ")";
219 
220  for (int iRow = 0; iRow < nRow; ++iRow)
221  cov[row + iRow][col + jCol] *= factor;
222  }
223 }
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
T sqrt(T t)
Definition: SSEVec.h:18
col
Definition: cuy.py:1010
void AlignmentExtendedCorrelationsStore::fillCovarianceT ( Alignable ap1,
Alignable ap2,
const ExtendedCorrelationsEntry entry,
AlgebraicSymMatrix cov,
int  row,
int  col 
) const
private

Definition at line 225 of file AlignmentExtendedCorrelationsStore.cc.

References mps_splice::entry, Exception, edm::isNotFinite(), AlignmentExtendedCorrelationsEntry::numCol(), AlignmentExtendedCorrelationsEntry::numRow(), and mathSSE::sqrt().

Referenced by correlations().

230  {
231  int nRow = entry.numRow();
232  int nCol = entry.numCol();
233 
234  for (int iRow = 0; iRow < nRow; ++iRow) {
235  double factor = sqrt(cov[col + iRow][col + iRow]);
236  if (edm::isNotFinite(factor))
237  throw cms::Exception("LogicError") << "[AlignmentExtendedCorrelationsStore::fillCovarianceT] "
238  << "NaN-factor: sqrt(" << cov[col + iRow][col + iRow] << ")";
239  for (int jCol = 0; jCol < nCol; ++jCol)
240  cov[row + jCol][col + iRow] = entry(iRow, jCol) * factor;
241  }
242 
243  for (int jCol = 0; jCol < nCol; ++jCol) {
244  double factor = sqrt(cov[row + jCol][row + jCol]);
245  if (edm::isNotFinite(factor))
246  throw cms::Exception("LogicError") << "[AlignmentExtendedCorrelationsStore::fillCovarianceT] "
247  << "NaN-factor: sqrt(" << cov[row + jCol][row + jCol] << ")";
248  for (int iRow = 0; iRow < nRow; ++iRow)
249  cov[row + jCol][col + iRow] *= factor;
250  }
251 }
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
T sqrt(T t)
Definition: SSEVec.h:18
col
Definition: cuy.py:1010
void AlignmentExtendedCorrelationsStore::getCorrelations ( Alignable ap1,
Alignable ap2,
AlgebraicMatrix mat 
) const
virtual

Get correlations.

Definition at line 115 of file AlignmentExtendedCorrelationsStore.cc.

References std::swap(), theCorrelations, and geometryDiff::transpose().

115  {
116  bool transpose = (ap2 > ap1);
117  if (transpose)
118  std::swap(ap1, ap2);
119 
120  ExtendedCorrelations::const_iterator itC1 = theCorrelations.find(ap1);
121  if (itC1 != theCorrelations.end()) {
122  ExtendedCorrelationsTable::const_iterator itC2 = itC1->second->find(ap2);
123  if (itC2 != itC1->second->end()) {
124  mat = transpose ? itC2->second.matrix().T() : itC2->second.matrix();
125  return;
126  }
127  }
128 
129  mat = AlgebraicMatrix();
130 }
def transpose(a)
Definition: geometryDiff.py:39
CLHEP::HepMatrix AlgebraicMatrix
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
void AlignmentExtendedCorrelationsStore::readFromCovariance ( Alignable ap1,
Alignable ap2,
ExtendedCorrelationsEntry entry,
const AlgebraicSymMatrix cov,
int  row,
int  col 
)
private

Definition at line 253 of file AlignmentExtendedCorrelationsStore.cc.

References mps_splice::entry, AlignmentExtendedCorrelationsEntry::numCol(), AlignmentExtendedCorrelationsEntry::numRow(), resizeCorruptCorrelations(), and mathSSE::sqrt().

Referenced by fillCorrelationsTable().

254  {
255  int nRow = entry.numRow();
256  int nCol = entry.numCol();
257 
258  for (int iRow = 0; iRow < nRow; ++iRow) {
259  double factor = sqrt(cov[row + iRow][row + iRow]);
260  for (int jCol = 0; jCol < nCol; ++jCol)
261  entry(iRow, jCol) = cov[row + iRow][col + jCol] / factor;
262  }
263 
264  double maxCorr = 0;
265 
266  for (int jCol = 0; jCol < nCol; ++jCol) {
267  double factor = sqrt(cov[col + jCol][col + jCol]);
268  for (int iRow = 0; iRow < nRow; ++iRow) {
269  entry(iRow, jCol) /= factor;
270  if (fabs(entry(iRow, jCol)) > maxCorr)
271  maxCorr = fabs(entry(iRow, jCol));
272  }
273  }
274 
276 }
T sqrt(T t)
Definition: SSEVec.h:18
void resizeCorruptCorrelations(ExtendedCorrelationsEntry &entry, double maxCorr)
col
Definition: cuy.py:1010
void AlignmentExtendedCorrelationsStore::readFromCovarianceT ( Alignable ap1,
Alignable ap2,
ExtendedCorrelationsEntry entry,
const AlgebraicSymMatrix cov,
int  row,
int  col 
)
private

Definition at line 278 of file AlignmentExtendedCorrelationsStore.cc.

References mps_splice::entry, AlignmentExtendedCorrelationsEntry::numCol(), AlignmentExtendedCorrelationsEntry::numRow(), resizeCorruptCorrelations(), and mathSSE::sqrt().

Referenced by fillCorrelationsTable().

279  {
280  int nRow = entry.numRow();
281  int nCol = entry.numCol();
282 
283  for (int iRow = 0; iRow < nRow; ++iRow) {
284  double factor = sqrt(cov[col + iRow][col + iRow]);
285  for (int jCol = 0; jCol < nCol; ++jCol)
286  entry(iRow, jCol) = cov[row + jCol][col + iRow] / factor;
287  }
288 
289  double maxCorr = 0;
290 
291  for (int jCol = 0; jCol < nCol; ++jCol) {
292  double factor = sqrt(cov[row + jCol][row + jCol]);
293  for (int iRow = 0; iRow < nRow; ++iRow) {
294  entry(iRow, jCol) /= factor;
295  if (fabs(entry(iRow, jCol)) > maxCorr)
296  maxCorr = fabs(entry(iRow, jCol));
297  }
298  }
299 
301 }
T sqrt(T t)
Definition: SSEVec.h:18
void resizeCorruptCorrelations(ExtendedCorrelationsEntry &entry, double maxCorr)
col
Definition: cuy.py:1010
void AlignmentExtendedCorrelationsStore::resetCorrelations ( void  )
overridevirtual

Reset correlations.

Reimplemented from AlignmentCorrelationsStore.

Definition at line 146 of file AlignmentExtendedCorrelationsStore.cc.

References correlations(), setCorrelations(), and theCorrelations.

146  {
147  ExtendedCorrelations::iterator itC;
148  for (itC = theCorrelations.begin(); itC != theCorrelations.end(); ++itC)
149  delete (*itC).second;
150  theCorrelations.erase(theCorrelations.begin(), theCorrelations.end());
151 
152  // Reset the static pointers to the 'previous alignables'
154  correlations(nullptr, nullptr, dummy, 0, 0);
155  setCorrelations(nullptr, nullptr, dummy, 0, 0);
156 }
void correlations(Alignable *ap1, Alignable *ap2, AlgebraicSymMatrix &cov, int row, int col) const override
CLHEP::HepSymMatrix AlgebraicSymMatrix
void setCorrelations(Alignable *ap1, Alignable *ap2, const AlgebraicSymMatrix &cov, int row, int col) override
void AlignmentExtendedCorrelationsStore::resizeCorruptCorrelations ( ExtendedCorrelationsEntry entry,
double  maxCorr 
)
private

Definition at line 303 of file AlignmentExtendedCorrelationsStore.cc.

References theCut, and theWeight.

Referenced by readFromCovariance(), and readFromCovarianceT().

303  {
304  if (maxCorr > 1.) {
305  entry *= theWeight / maxCorr;
306  } else if (maxCorr > theCut) {
307  entry *= 1. - (maxCorr - theCut) / (1. - theCut) * (1. - theWeight);
308  }
309 }
void AlignmentExtendedCorrelationsStore::setCorrelations ( Alignable ap1,
Alignable ap2,
const AlgebraicSymMatrix cov,
int  row,
int  col 
)
overridevirtual

Get correlations directly from the given position of the covariance matrix and store them. Indices are assumed to start from 0.

Reimplemented from AlignmentCorrelationsStore.

Definition at line 59 of file AlignmentExtendedCorrelationsStore.cc.

References fillCorrelationsTable(), std::swap(), theCorrelations, and geometryDiff::transpose().

Referenced by resetCorrelations().

60  {
61  static Alignable* previousAlignable = nullptr;
62  static ExtendedCorrelationsTable* previousCorrelations;
63 
64  // Needed by 'resetCorrelations()' to reset the static pointer:
65  if (ap1 == nullptr) {
66  previousAlignable = nullptr;
67  return;
68  }
69 
70  bool transpose = (ap2 > ap1);
71  if (transpose)
72  std::swap(ap1, ap2);
73 
74  if (ap1 == previousAlignable) {
75  fillCorrelationsTable(ap1, ap2, previousCorrelations, cov, row, col, transpose);
76  } else {
77  ExtendedCorrelations::iterator itC = theCorrelations.find(ap1);
78  if (itC != theCorrelations.end()) {
79  fillCorrelationsTable(ap1, ap2, itC->second, cov, row, col, transpose);
80  previousAlignable = ap1;
81  previousCorrelations = itC->second;
82  } else {
83  // make new entry
85  fillCorrelationsTable(ap1, ap2, newTable, cov, row, col, transpose);
86 
87  theCorrelations[ap1] = newTable;
88 
89  previousAlignable = ap1;
90  previousCorrelations = newTable;
91  }
92  }
93 }
def transpose(a)
Definition: geometryDiff.py:39
void fillCorrelationsTable(Alignable *ap1, Alignable *ap2, ExtendedCorrelationsTable *table, const AlgebraicSymMatrix &cov, int row, int col, bool transpose)
std::map< Alignable *, ExtendedCorrelationsEntry > ExtendedCorrelationsTable
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
col
Definition: cuy.py:1010
void AlignmentExtendedCorrelationsStore::setCorrelations ( Alignable ap1,
Alignable ap2,
AlgebraicMatrix mat 
)
overridevirtual

Set correlations without checking whether the maximum number of updates has already been reached.

Reimplemented from AlignmentCorrelationsStore.

Definition at line 95 of file AlignmentExtendedCorrelationsStore.cc.

References std::swap(), theCorrelations, and geometryDiff::transpose().

95  {
96  bool transpose = (ap2 > ap1);
97  if (transpose)
98  std::swap(ap1, ap2);
99 
100  ExtendedCorrelations::iterator itC1 = theCorrelations.find(ap1);
101  if (itC1 != theCorrelations.end()) {
102  ExtendedCorrelationsTable::iterator itC2 = itC1->second->find(ap1);
103  if (itC2 != itC1->second->end()) {
104  itC2->second = transpose ? ExtendedCorrelationsEntry(mat.T()) : ExtendedCorrelationsEntry(mat);
105  } else {
106  (*itC1->second)[ap2] = transpose ? ExtendedCorrelationsEntry(mat.T()) : ExtendedCorrelationsEntry(mat);
107  }
108  } else {
110  (*newTable)[ap2] = transpose ? ExtendedCorrelationsEntry(mat.T()) : ExtendedCorrelationsEntry(mat);
111  theCorrelations[ap1] = newTable;
112  }
113 }
def transpose(a)
Definition: geometryDiff.py:39
std::map< Alignable *, ExtendedCorrelationsEntry > ExtendedCorrelationsTable
AlignmentExtendedCorrelationsEntry ExtendedCorrelationsEntry
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
unsigned int AlignmentExtendedCorrelationsStore::size ( void  ) const
overridevirtual

Get number of stored correlations.

Reimplemented from AlignmentCorrelationsStore.

Definition at line 158 of file AlignmentExtendedCorrelationsStore.cc.

References theCorrelations.

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

158  {
159  unsigned int size = 0;
160  ExtendedCorrelations::const_iterator itC;
161  for (itC = theCorrelations.begin(); itC != theCorrelations.end(); ++itC)
162  size += itC->second->size();
163 
164  return size;
165 }
unsigned int size(void) const override
Get number of stored correlations.

Member Data Documentation

ExtendedCorrelations AlignmentExtendedCorrelationsStore::theCorrelations
private
double AlignmentExtendedCorrelationsStore::theCut
private
int AlignmentExtendedCorrelationsStore::theMaxUpdates
private
double AlignmentExtendedCorrelationsStore::theWeight
private