CMS 3D CMS Logo

CompositeAlignmentDerivativesExtractor.cc
Go to the documentation of this file.
2 
7 
9 
10 //--------------------------------------------------------------------------------------
12  const align::Alignables &alignables,
13  const std::vector<AlignableDet *> &alignableDets,
14  const std::vector<TrajectoryStateOnSurface> &tsos) {
15  std::vector<AlignableDetOrUnitPtr> detOrUnits;
16  detOrUnits.reserve(alignableDets.size());
17 
18  std::vector<AlignableDet *>::const_iterator it, itEnd;
19  for (it = alignableDets.begin(), itEnd = alignableDets.end(); it != itEnd; ++it)
20  detOrUnits.push_back(AlignableDetOrUnitPtr(*it));
21 
22  extractCurrentAlignment(alignables, detOrUnits, tsos);
23 }
24 
25 //--------------------------------------------------------------------------------------
27  const align::Alignables &alignables,
28  const std::vector<AlignableDetOrUnitPtr> &alignableDets,
29  const std::vector<TrajectoryStateOnSurface> &tsos) {
30  extractCurrentAlignment(alignables, alignableDets, tsos);
31 }
32 
33 //--------------------------------------------------------------------------------------
34 
36  const align::Alignables &alignables,
37  const std::vector<AlignableDetOrUnitPtr> &alignableDets,
38  const std::vector<TrajectoryStateOnSurface> &tsos) {
39  // sanity check
40  if (alignables.size() != alignableDets.size()) {
41  edm::LogError("CompositeAlignmentDerivativesExtractor")
42  << "Inconsistent length of arguments: alignables=" << alignables.size()
43  << ", alignableDets=" << alignableDets.size();
44  return;
45  }
46 
47  if (alignables.size() != tsos.size()) {
48  edm::LogError("CompositeAlignmentDerivativesExtractor")
49  << "Inconsistent length of arguments: alignables=" << alignables.size() << ", tsos=" << tsos.size();
50  return;
51  }
52 
53  align::Alignables::const_iterator itAlignable = alignables.begin();
54  std::vector<AlignableDetOrUnitPtr>::const_iterator itAlignableDet = alignableDets.begin();
55  std::vector<TrajectoryStateOnSurface>::const_iterator itTsos = tsos.begin();
56 
57  int nRow = 0;
58  int nCollumn = 0;
59  unsigned int nAlignables = 0;
60 
61  std::vector<AlgebraicMatrix> subDerivatives;
62  std::vector<AlgebraicVector> subCorrectionTerm;
63 
64  // get the individual derivatives and correction term and determine the
65  // dimension
66  while (itAlignable != alignables.end()) {
67  // Get the current estimate on the alignment parameters
68  AlgebraicVector subAlignmentParameters = (*itAlignable)->alignmentParameters()->selectedParameters();
69 
70  // Get the derivatives or the local coordinates w.r.t. the corresponding
71  // alignment parameters
72  AlgebraicMatrix subAlignmentDerivatives =
73  (*itAlignable)->alignmentParameters()->selectedDerivatives(*itTsos, *itAlignableDet);
74 
75  subDerivatives.push_back(subAlignmentDerivatives.T());
76  subCorrectionTerm.push_back(subAlignmentDerivatives.T() * subAlignmentParameters);
77 
78  nRow += 2;
79  // check if it is the first occurrence of this Alignable
80  if (count(alignables.begin(), itAlignable, *itAlignable) == 0) {
81  // matrix is transposed -> num_row() instead of num_col()
82  nCollumn += subAlignmentDerivatives.num_row();
83  nAlignables++;
84  }
85 
86  ++itAlignable;
87  ++itAlignableDet;
88  ++itTsos;
89  }
90 
91  // construct derivatives and correction term with the right dimension
92  theDerivatives = AlgebraicMatrix(nRow, nCollumn, 0);
94 
95  if (alignables.size() == nAlignables)
96  // One hit per alignable
97  extractWithoutMultipleHits(subCorrectionTerm, subDerivatives);
98  else
99  // At least one alignable has two hits
100  extractWithMultipleHits(subCorrectionTerm, subDerivatives, alignables);
101 
102  return;
103 }
104 
105 //--------------------------------------------------------------------------------------
106 
108  const std::vector<AlgebraicVector> &subCorrectionTerm, const std::vector<AlgebraicMatrix> &subDerivatives) {
109  std::vector<AlgebraicVector>::const_iterator itSubCorrectionTerm = subCorrectionTerm.begin();
110  std::vector<AlgebraicMatrix>::const_iterator itSubDerivatives = subDerivatives.begin();
111 
112  int iRow = 1;
113  int iCollumn = 1;
114 
115  // Fill in the individual terms
116  while (itSubCorrectionTerm != subCorrectionTerm.end()) {
117  theCorrectionTerm.sub(iRow, *itSubCorrectionTerm);
118  theDerivatives.sub(iRow, iCollumn, *itSubDerivatives);
119 
120  iRow += 2;
121  iCollumn += (*itSubDerivatives).num_col();
122 
123  ++itSubCorrectionTerm;
124  ++itSubDerivatives;
125  }
126 
127  return;
128 }
129 
130 //--------------------------------------------------------------------------------------
131 
133  const std::vector<AlgebraicVector> &subCorrectionTerm,
134  const std::vector<AlgebraicMatrix> &subDerivatives,
135  const align::Alignables &alignables) {
136  std::vector<AlgebraicVector>::const_iterator itSubCorrectionTerm = subCorrectionTerm.begin();
137  std::vector<AlgebraicMatrix>::const_iterator itSubDerivatives = subDerivatives.begin();
138  align::Alignables::const_iterator itAlignables = alignables.begin();
139  align::Alignables::const_iterator itPosition;
140  align::Alignables::const_iterator itLastPosition;
141 
142  int iRow = 1;
143 
144  // Fill in the individual terms
145  while (itAlignables != alignables.end()) {
146  theCorrectionTerm.sub(iRow, *itSubCorrectionTerm);
147 
148  int iCollumn = 1;
149  int iAlignable = 0;
150 
151  itLastPosition = find(alignables.begin(), itAlignables, *itAlignables);
152 
153  for (itPosition = alignables.begin(); itPosition != itLastPosition; ++itPosition) {
154  if (count(alignables.begin(), itPosition, *itPosition) == 0)
155  iCollumn += subDerivatives[iAlignable].num_col();
156  iAlignable++;
157  }
158 
159  theDerivatives.sub(iRow, iCollumn, *itSubDerivatives);
160 
161  iRow += 2;
162 
163  ++itAlignables;
164  ++itSubCorrectionTerm;
165  ++itSubDerivatives;
166  }
167 
168  return;
169 }
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void extractWithMultipleHits(const std::vector< AlgebraicVector > &subCorrectionTerm, const std::vector< AlgebraicMatrix > &subDerivatives, const align::Alignables &alignables)
CLHEP::HepMatrix AlgebraicMatrix
void extractWithoutMultipleHits(const std::vector< AlgebraicVector > &subCorrectionTerm, const std::vector< AlgebraicMatrix > &subDerivatives)
CLHEP::HepVector AlgebraicVector
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
CompositeAlignmentDerivativesExtractor(const align::Alignables &alignables, const std::vector< AlignableDet *> &alignableDets, const std::vector< TrajectoryStateOnSurface > &tsos)
void extractCurrentAlignment(const align::Alignables &alignables, const std::vector< AlignableDetOrUnitPtr > &alignableDets, const std::vector< TrajectoryStateOnSurface > &tsos)