CMS 3D CMS Logo

AlignmentParameters.cc
Go to the documentation of this file.
3 
5 
7 
8 //__________________________________________________________________________________________________
9 AlignmentParameters::AlignmentParameters() : theAlignable(nullptr), theUserVariables(nullptr), bValid(true) {}
10 
11 //__________________________________________________________________________________________________
13  : theAlignable(object),
14  theData(DataContainer(new AlignmentParametersData(par, cov))),
15  theUserVariables(nullptr),
16  bValid(true) {
17  // is the data consistent?
18  theData->checkConsistency();
19 }
20 
21 //__________________________________________________________________________________________________
23  const AlgebraicVector& par,
24  const AlgebraicSymMatrix& cov,
25  const std::vector<bool>& sel)
26  : theAlignable(object),
27  theData(DataContainer(new AlignmentParametersData(par, cov, sel))),
28  theUserVariables(nullptr),
29  bValid(true) {
30  // is the data consistent?
31  theData->checkConsistency();
32 }
33 
34 //__________________________________________________________________________________________________
36  : theAlignable(object), theData(data), theUserVariables(nullptr), bValid(true) {
37  // is the data consistent?
38  theData->checkConsistency();
39 }
40 
41 //__________________________________________________________________________________________________
43  if (theUserVariables)
44  delete theUserVariables;
45 }
46 
47 //__________________________________________________________________________________________________
48 const std::vector<bool>& AlignmentParameters::selector(void) const { return theData->selector(); }
49 
50 //__________________________________________________________________________________________________
51 int AlignmentParameters::numSelected(void) const { return theData->numSelected(); }
52 
53 //__________________________________________________________________________________________________
55  return collapseVector(theData->parameters(), theData->selector());
56 }
57 
58 //__________________________________________________________________________________________________
60  return collapseSymMatrix(theData->covariance(), theData->selector());
61 }
62 
63 //__________________________________________________________________________________________________
64 const AlgebraicVector& AlignmentParameters::parameters(void) const { return theData->parameters(); }
65 
66 //__________________________________________________________________________________________________
67 const AlgebraicSymMatrix& AlignmentParameters::covariance(void) const { return theData->covariance(); }
68 
69 //__________________________________________________________________________________________________
71  const AlignableDetOrUnitPtr& alignableDet) const {
72  const AlgebraicMatrix dev(this->derivatives(tsos, alignableDet));
73 
74  const int ncols = dev.num_col();
75  const int nrows = dev.num_row();
76  const int nsel = numSelected();
77 
78  AlgebraicMatrix seldev(nsel, ncols);
79 
80  int ir2 = 0;
81  for (int irow = 0; irow < nrows; ++irow) {
82  if (this->selector()[irow]) {
83  for (int icol = 0; icol < ncols; ++icol) {
84  seldev[ir2][icol] = dev[irow][icol];
85  }
86  ++ir2;
87  }
88  }
89 
90  return seldev;
91 }
92 
93 //__________________________________________________________________________________________________
95  if (theUserVariables)
96  delete theUserVariables;
97  theUserVariables = auv;
98 }
99 
100 //__________________________________________________________________________________________________
102 
103 //__________________________________________________________________________________________________
105 
106 //__________________________________________________________________________________________________
108  if (!theAlignable) {
109  edm::LogError("Alignment") << "@SUB=AlignmentParameters::hierarchyLevel"
110  << "Called for AlignmentParameters without pointer to Alignable";
111  return 0;
112  }
113 
114  align::Alignables comps;
116  if (comps.empty())
117  return 0;
118 
119  unsigned int maxLevelOfComp = 0;
120  for (const auto& iAli : comps) { // firstCompsWithParams guaranties that alignmentParameters() != 0:
121  const unsigned int compResult = iAli->alignmentParameters()->hierarchyLevel();
122  // levels might be different for components, get largest:
123  if (maxLevelOfComp < compResult)
124  maxLevelOfComp = compResult;
125  }
126 
127  return maxLevelOfComp + 1;
128 }
129 
130 //__________________________________________________________________________________________________
131 int AlignmentParameters::size(void) const { return theData->parameters().num_row(); }
132 
133 //__________________________________________________________________________________________________
134 bool AlignmentParameters::isValid(void) const { return bValid; }
135 
136 //__________________________________________________________________________________________________
138 
139 //__________________________________________________________________________________________________
141  const std::vector<bool>& sel) const {
142  int nRows = m.num_row();
143  int size = sel.size();
144 
145  // Check size matching
146  if (nRows != size)
147  throw cms::Exception("LogicError") << "Size mismatch in parameters"
148  << " (input symmatrix = " << nRows << ", selection: " << size << ")";
149 
150  // If OK, continue
151  std::vector<int> rowvec;
152  for (int i = 0; i < nRows; i++)
153  if (sel[i])
154  rowvec.push_back(i);
155 
156  int nSelectedRows = rowvec.size();
157  AlgebraicSymMatrix result(nSelectedRows, 0);
158  for (int i = 0; i < nSelectedRows; i++)
159  for (int j = 0; j < nSelectedRows; j++)
160  result[i][j] = m[rowvec[i]][rowvec[j]];
161 
162  return result;
163 }
164 
165 //__________________________________________________________________________________________________
167  int nRows = m.num_row();
168  int size = sel.size();
169 
170  // Check size matching
171  if (nRows != size)
172  throw cms::Exception("LogicError") << "Size mismatch in parameters"
173  << " (input vector = " << nRows << ", selection: " << size << ")";
174 
175  // If OK, continue
176  std::vector<int> rowvec;
177  for (int i = 0; i < nRows; i++)
178  if (sel[i])
179  rowvec.push_back(i);
180 
181  int nSelectedRows = rowvec.size();
182  AlgebraicVector result(nSelectedRows, 0);
183  for (int i = 0; i < nSelectedRows; i++)
184  result[i] = m[(int)rowvec[i]];
185 
186  return result;
187 }
188 
189 //__________________________________________________________________________________________________
191  const std::vector<bool>& sel) const {
192  int nRows = m.num_row();
193  int size = sel.size();
194 
195  std::vector<int> rowvec;
196  for (int i = 0; i < size; i++)
197  if (sel[i])
198  rowvec.push_back(i);
199 
200  // Check size matching
201  if (nRows != static_cast<int>(rowvec.size()))
202  throw cms::Exception("LogicError") << "Size mismatch in parameters"
203  << " (input symmatrix = " << nRows << ", selection: " << size << ")";
204 
205  // If OK, continue
207  for (int i = 0; i < nRows; i++)
208  for (int j = 0; j < nRows; j++)
209  result[rowvec[i]][rowvec[j]] = m[i][j];
210 
211  return result;
212 }
213 
214 //__________________________________________________________________________________________________
215 AlgebraicVector AlignmentParameters::expandVector(const AlgebraicVector& m, const std::vector<bool>& sel) const {
216  int nRows = m.num_row();
217  int size = sel.size();
218 
219  std::vector<int> rowvec;
220  for (int i = 0; i < size; i++)
221  if (sel[i] == true)
222  rowvec.push_back(i);
223 
224  // Check size matching
225  if (nRows != static_cast<int>(rowvec.size()))
226  throw cms::Exception("LogicError") << "Size mismatch in parameters"
227  << " (input vector = " << nRows << ", selection: " << size << ")";
228 
229  // If OK, continue
231  for (int i = 0; i < nRows; i++)
232  result[rowvec[i]] = m[i];
233  return result;
234 }
const AlgebraicSymMatrix & covariance(void) const
Get parameter covariance matrix.
Alignable * alignable(void) const
Get pointer to corresponding alignable.
const AlgebraicVector & parameters(void) const
Get alignment parameters.
Log< level::Error, false > LogError
int numSelected(void) const
Get number of selected parameters.
AlgebraicVector expandVector(const AlgebraicVector &m, const std::vector< bool > &sel) const
AlgebraicVector selectedParameters(void) const
Get selected parameters.
AlgebraicSymMatrix expandSymMatrix(const AlgebraicSymMatrix &m, const std::vector< bool > &sel) const
bool firstCompsWithParams(Alignables &paramComps) const
Definition: Alignable.cc:62
virtual AlgebraicMatrix derivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const =0
Get derivatives of selected parameters.
CLHEP::HepMatrix AlgebraicMatrix
void setValid(bool v)
Set validity flag.
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
virtual AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
int size(void) const
Get number of parameters.
AlgebraicSymMatrix collapseSymMatrix(const AlgebraicSymMatrix &m, const std::vector< bool > &sel) const
(Abstract) Base class for alignment algorithm user variables
bool isValid(void) const
Get validity flag.
AlgebraicVector collapseVector(const AlgebraicVector &m, const std::vector< bool > &sel) const
CLHEP::HepVector AlgebraicVector
virtual unsigned int hierarchyLevel() const
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
virtual ~AlignmentParameters()
Destructor.
CLHEP::HepSymMatrix AlgebraicSymMatrix
AlignmentParameters()
Default constructor.
bool bValid
True if parameters are valid.
AlignmentUserVariables * theUserVariables
AlgebraicSymMatrix selectedCovariance(void) const
Get covariance matrix of selected parameters.