CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlignmentCorrelationsStore.cc
Go to the documentation of this file.
2 
6 
7 
9 {
10  edm::LogInfo("Alignment") << "@SUB=AlignmentCorrelationsStore::AlignmentCorrelationsStore "
11  << "\nCreated.";
12 }
13 
14 
16  AlgebraicSymMatrix& cov, int row, int col ) const
17 {
18  static Alignable* previousAlignable = 0;
19  static CorrelationsTable* previousCorrelations;
20 
21  // Needed by 'resetCorrelations()' to reset the static pointer:
22  if ( ap1 == 0 ) { previousAlignable = 0; return; }
23 
24  bool transpose = ( ap2 > ap1 );
25  if ( transpose ) std::swap( ap1, ap2 );
26 
27  if ( ap1 == previousAlignable )
28  {
29  CorrelationsTable::const_iterator itC2 = previousCorrelations->find( ap2 );
30  if ( itC2 != previousCorrelations->end() )
31  {
32  transpose ?
33  fillCovarianceT( ap1, ap2, (*itC2).second, cov, row, col ) :
34  fillCovariance( ap1, ap2, (*itC2).second, cov, row, col );
35  }
36  }
37  else
38  {
39  Correlations::const_iterator itC1 = theCorrelations.find( ap1 );
40  if ( itC1 != theCorrelations.end() )
41  {
42  previousAlignable = ap1;
43  previousCorrelations = (*itC1).second;
44 
45  CorrelationsTable::const_iterator itC2 = (*itC1).second->find( ap2 );
46  if ( itC2 != (*itC1).second->end() )
47  {
48  transpose ?
49  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 }
58 
59 
61  const AlgebraicSymMatrix& cov, int row, int col )
62 {
63  static Alignable* previousAlignable = 0;
64  static CorrelationsTable* previousCorrelations;
65 
66  // Needed by 'resetCorrelations()' to reset the static pointer:
67  if ( ap1 == 0 ) { previousAlignable = 0; return; }
68 
69  bool transpose = ( ap2 > ap1 );
70  if ( transpose ) std::swap( ap1, ap2 );
71 
72  if ( ap1 == previousAlignable )
73  {
74  fillCorrelationsTable( ap1, ap2, previousCorrelations, cov, row, col, transpose );
75  }
76  else
77  {
78  Correlations::iterator itC = theCorrelations.find( ap1 );
79  if ( itC != theCorrelations.end() )
80  {
81  fillCorrelationsTable( ap1, ap2, itC->second, cov, row, col, transpose );
82  previousAlignable = ap1;
83  previousCorrelations = itC->second;
84  }
85  else
86  {
87  CorrelationsTable* newTable = new CorrelationsTable;
88  fillCorrelationsTable( ap1, ap2, newTable, cov, row, col, transpose );
89 
90  theCorrelations[ap1] = newTable;
91  previousAlignable = ap1;
92  previousCorrelations = newTable;
93  }
94  }
95 }
96 
97 
99 {
100  bool transpose = ( ap2 > ap1 );
101  if ( transpose ) std::swap( ap1, ap2 );
102 
103  Correlations::iterator itC1 = theCorrelations.find( ap1 );
104  if ( itC1 != theCorrelations.end() )
105  {
106  (*itC1->second)[ap2] = transpose ? mat.T() : mat;
107  }
108  else
109  {
110  CorrelationsTable* newTable = new CorrelationsTable;
111  (*newTable)[ap2] = transpose ? mat.T() : mat;
112  theCorrelations[ap1] = newTable;
113  }
114 }
115 
116 
118 {
119  bool transpose = ( ap2 > ap1 );
120  if ( transpose ) std::swap( ap1, ap2 );
121 
122  Correlations::const_iterator itC1 = theCorrelations.find( ap1 );
123  if ( itC1 != theCorrelations.end() )
124  {
125  CorrelationsTable::const_iterator itC2 = itC1->second->find( ap2 );
126  if ( itC2 != itC1->second->end() ) return true;
127  }
128  return false;
129 }
130 
131 
133 {
134  Correlations::iterator itC;
135  for ( itC = theCorrelations.begin(); itC != theCorrelations.end(); ++itC ) delete (*itC).second;
136  theCorrelations.erase( theCorrelations.begin(), theCorrelations.end() );
137 
138  // Reset the static pointers to the 'previous alignables'
139  AlgebraicSymMatrix dummy;
140  correlations( 0, 0, dummy, 0, 0 );
141  setCorrelations( 0, 0, dummy, 0, 0 );
142 }
143 
144 
145 unsigned int AlignmentCorrelationsStore::size( void ) const
146 {
147  unsigned int size = 0;
148  Correlations::const_iterator itC;
149  for ( itC = theCorrelations.begin(); itC != theCorrelations.end(); ++itC )
150  size += itC->second->size();
151 
152  return size;
153 }
154 
155 
156 void
158  const AlgebraicSymMatrix& cov, int row, int col, bool transpose )
159 {
160  CorrelationsTable::iterator itC = table->find( ap2 );
161 
162  if ( itC != table->end() )
163  {
164  transpose ?
165  readFromCovarianceT( ap1, ap2, itC->second, cov, row, col ) :
166  readFromCovariance( ap1, ap2, itC->second, cov, row, col );
167  }
168  else
169  {
170  int nRow = ap1->alignmentParameters()->numSelected();
171  int nCol = ap2->alignmentParameters()->numSelected();
172  AlgebraicMatrix newEntry( nRow, nCol );
173 
174  transpose ?
175  readFromCovarianceT( ap1, ap2, newEntry, cov, row, col ) :
176  readFromCovariance( ap1, ap2, newEntry, cov, row, col );
177 
178  (*table)[ap2] = newEntry;
179  }
180 }
181 
182 
183 void
185  AlgebraicSymMatrix& cov, int row, int col ) const
186 {
187  int nRow = entry.num_row();
188  int nCol = entry.num_col();
189 
190  for ( int iRow = 0; iRow < nRow; ++iRow )
191  for ( int jCol = 0; jCol < nCol; ++jCol )
192  cov[row+iRow][col+jCol] = entry[iRow][jCol];
193 }
194 
195 
196 void
198  AlgebraicSymMatrix& cov, int row, int col ) const
199 {
200  int nRow = entry.num_row();
201  int nCol = entry.num_col();
202 
203  for ( int iRow = 0; iRow < nRow; ++iRow )
204  for ( int jCol = 0; jCol < nCol; ++jCol )
205  cov[row+jCol][col+iRow] = entry[iRow][jCol];
206 }
207 
208 
209 void
211  const AlgebraicSymMatrix& cov, int row, int col )
212 {
213  int nRow = entry.num_row();
214  int nCol = entry.num_col();
215 
216  for ( int iRow = 0; iRow < nRow; ++iRow )
217  for ( int jCol = 0; jCol < nCol; ++jCol )
218  entry[iRow][jCol] = cov[row+iRow][col+jCol];
219 }
220 
221 
222 void
224  const AlgebraicSymMatrix& cov, int row, int col )
225 {
226  int nRow = entry.num_row();
227  int nCol = entry.num_col();
228 
229  for ( int iRow = 0; iRow < nRow; ++iRow )
230  for ( int jCol = 0; jCol < nCol; ++jCol )
231  entry[iRow][jCol] = cov[row+jCol][col+iRow];
232 }
std::map< Alignable *, AlgebraicMatrix > CorrelationsTable
virtual void fillCovariance(Alignable *ap1, Alignable *ap2, const AlgebraicMatrix &entry, AlgebraicSymMatrix &cov, int row, int col) const
virtual void fillCorrelationsTable(Alignable *ap1, Alignable *ap2, CorrelationsTable *table, const AlgebraicSymMatrix &cov, int row, int col, bool transpose)
virtual 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:57
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)
CLHEP::HepMatrix AlgebraicMatrix
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual 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.
#define table(NAME)
Definition: DbCore.h:49
virtual void correlations(Alignable *ap1, Alignable *ap2, AlgebraicSymMatrix &cov, int row, int col) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
int col
Definition: cuy.py:1008
virtual void readFromCovariance(Alignable *ap1, Alignable *ap2, AlgebraicMatrix &entry, const AlgebraicSymMatrix &cov, int row, int col)