CMS 3D CMS Logo

CompositeAlignmentParameters.cc
Go to the documentation of this file.
1 
6 
8 
13 
15 
16 //__________________________________________________________________________________________________
18  const AlgebraicSymMatrix &cov,
19  const Components &comp)
20  : theData(DataContainer(new AlignmentParametersData(par, cov))), theComponents(comp) {}
21 
22 //__________________________________________________________________________________________________
24  const AlgebraicSymMatrix &cov,
25  const Components &comp,
26  const AlignableDetToAlignableMap &alimap,
27  const Aliposmap &aliposmap,
28  const Alilenmap &alilenmap)
29  : theData(DataContainer(new AlignmentParametersData(par, cov))),
30  theComponents(comp),
31  theAlignableDetToAlignableMap(alimap),
32  theAliposmap(aliposmap),
33  theAlilenmap(alilenmap) {}
34 
35 //__________________________________________________________________________________________________
37  const Components &comp,
38  const AlignableDetToAlignableMap &alimap,
39  const Aliposmap &aliposmap,
40  const Alilenmap &alilenmap)
41  : theData(data),
42  theComponents(comp),
43  theAlignableDetToAlignableMap(alimap),
44  theAliposmap(aliposmap),
45  theAlilenmap(alilenmap) {}
46 
47 //__________________________________________________________________________________________________
49 
50 //__________________________________________________________________________________________________
52  const AlgebraicSymMatrix &cov) const {
54 
55  return cap;
56 }
57 
58 //__________________________________________________________________________________________________
60  const AlgebraicSymMatrix &cov,
61  const AlignableDetToAlignableMap &alimap,
62  const Aliposmap &aliposmap,
63  const Alilenmap &alilenmap) const {
65  new CompositeAlignmentParameters(par, cov, components(), alimap, aliposmap, alilenmap);
66 
67  return cap;
68 }
69 
70 //__________________________________________________________________________________________________
72 
73 //__________________________________________________________________________________________________
74 // full derivatives for a composed object
75 AlgebraicMatrix CompositeAlignmentParameters::derivatives(const std::vector<TrajectoryStateOnSurface> &tsosvec,
76  const std::vector<AlignableDet *> &alidetvec) const {
77  std::vector<AlignableDetOrUnitPtr> detOrUnits;
78  this->convert(alidetvec, detOrUnits);
79 
80  return this->derivatives(tsosvec, detOrUnits);
81 }
82 
83 AlgebraicMatrix CompositeAlignmentParameters::derivatives(const std::vector<TrajectoryStateOnSurface> &tsosvec,
84  const std::vector<AlignableDetOrUnitPtr> &alidetvec) const {
85  align::Alignables alivec;
86  for (std::vector<AlignableDetOrUnitPtr>::const_iterator it = alidetvec.begin(); it != alidetvec.end(); ++it)
87  alivec.push_back(alignableFromAlignableDet(*it));
88 
89  CompositeAlignmentDerivativesExtractor extractor(alivec, alidetvec, tsosvec);
90  return extractor.derivatives();
91 }
92 
93 //__________________________________________________________________________________________________
94 AlgebraicVector CompositeAlignmentParameters::correctionTerm(const std::vector<TrajectoryStateOnSurface> &tsosvec,
95  const std::vector<AlignableDet *> &alidetvec) const {
96  std::vector<AlignableDetOrUnitPtr> detOrUnits;
97  this->convert(alidetvec, detOrUnits);
98 
99  return this->correctionTerm(tsosvec, detOrUnits);
100 }
101 
102 //__________________________________________________________________________________________________
104  const std::vector<TrajectoryStateOnSurface> &tsosvec, const std::vector<AlignableDetOrUnitPtr> &alidetvec) const {
105  align::Alignables alivec;
106  for (std::vector<AlignableDetOrUnitPtr>::const_iterator it = alidetvec.begin(); it != alidetvec.end(); ++it)
107  alivec.push_back(alignableFromAlignableDet(*it));
108 
109  CompositeAlignmentDerivativesExtractor extractor(alivec, alidetvec, tsosvec);
110  return extractor.correctionTerm();
111 }
112 
113 //__________________________________________________________________________________________________
114 // assume all are selected
115 AlgebraicMatrix CompositeAlignmentParameters::selectedDerivatives(const std::vector<TrajectoryStateOnSurface> &tsosvec,
116  const std::vector<AlignableDet *> &alidetvec) const {
117  return derivatives(tsosvec, alidetvec);
118 }
119 //__________________________________________________________________________________________________
120 // assume all are selected
122  const std::vector<TrajectoryStateOnSurface> &tsosvec, const std::vector<AlignableDetOrUnitPtr> &alidetvec) const {
123  return derivatives(tsosvec, alidetvec);
124 }
125 
126 //__________________________________________________________________________________________________
127 // only one (tsos,AlignableDet) as argument [for compatibility with base class]
129  const AlignableDetOrUnitPtr &alidet) const {
130  std::vector<TrajectoryStateOnSurface> tsosvec;
131  std::vector<AlignableDetOrUnitPtr> alidetvec;
132  tsosvec.push_back(tsos);
133  alidetvec.push_back(alidet);
134  return derivatives(tsosvec, alidetvec);
135 }
136 
137 //__________________________________________________________________________________________________
138 // assume all are selected
140  const AlignableDetOrUnitPtr &alidet) const {
141  return derivatives(tsos, alidet);
142 }
143 
144 // Derivatives ----------------------------------------------------------------
145 // legacy methods
146 // full derivatives for a composed object
147 AlgebraicMatrix CompositeAlignmentParameters::derivativesLegacy(const std::vector<TrajectoryStateOnSurface> &tsosvec,
148  const std::vector<AlignableDet *> &alidetvec) const {
149  // sanity check: length of parameter argument vectors must be equal
150  if (alidetvec.size() != tsosvec.size()) {
151  edm::LogError("BadArgument") << " Inconsistent length of argument vectors! ";
152  AlgebraicMatrix selderiv(1, 0);
153  return selderiv;
154  }
155 
156  std::vector<AlgebraicMatrix> vecderiv;
157  int nparam = 0;
158 
159  std::vector<TrajectoryStateOnSurface>::const_iterator itsos = tsosvec.begin();
160  for (std::vector<AlignableDet *>::const_iterator it = alidetvec.begin(); it != alidetvec.end(); ++it, ++itsos) {
161  AlignableDet *ad = (*it);
164  AlgebraicMatrix thisselderiv = ap->selectedDerivatives(*itsos, ad);
165  vecderiv.push_back(thisselderiv);
166  nparam += thisselderiv.num_row();
167  }
168 
169  int ipos = 1;
170  AlgebraicMatrix selderiv(nparam, 2);
171  for (std::vector<AlgebraicMatrix>::const_iterator imat = vecderiv.begin(); imat != vecderiv.end(); ++imat) {
172  const AlgebraicMatrix &thisselderiv = (*imat);
173  int npar = thisselderiv.num_row();
174  selderiv.sub(ipos, 1, thisselderiv);
175  ipos += npar;
176  }
177 
178  return selderiv;
179 }
180 
181 //__________________________________________________________________________________________________
182 // assume all are selected
184  const std::vector<TrajectoryStateOnSurface> &tsosvec, const std::vector<AlignableDet *> &alidetvec) const {
185  return derivativesLegacy(tsosvec, alidetvec);
186 }
187 
188 //__________________________________________________________________________________________________
189 // only one (tsos,AlignableDet) as argument [for compatibility with base class]
191  AlignableDet *alidet) const {
192  std::vector<TrajectoryStateOnSurface> tsosvec;
193  std::vector<AlignableDet *> alidetvec;
194  tsosvec.push_back(tsos);
195  alidetvec.push_back(alidet);
196  return derivativesLegacy(tsosvec, alidetvec);
197 }
198 
199 //__________________________________________________________________________________________________
200 // assume all are selected
202  AlignableDet *alidet) const {
203  return derivativesLegacy(tsos, alidet);
204 }
205 
206 //__________________________________________________________________________________________________
207 // finds Alignable corresponding to AlignableDet
209  AlignableDetToAlignableMap::const_iterator iali = theAlignableDetToAlignableMap.find(adet);
210  if (iali != theAlignableDetToAlignableMap.end())
211  return (*iali).second;
212  else
213  return nullptr;
214 }
215 
216 //__________________________________________________________________________________________________
218  const auto &sel = extractAlignables(vec);
219 
220  const unsigned int nali = sel.size();
221  int ndim = 0;
222 
223  std::vector<int> posvec;
224  std::vector<int> lenvec;
225 
226  posvec.reserve(nali);
227  lenvec.reserve(nali);
228 
229  // iterate over input vector of alignables to determine size of result vector
230  if (!extractPositionAndLength(sel, posvec, lenvec, ndim))
231  return AlgebraicVector();
232 
233  // OK, let's do the real work now
234  AlgebraicVector result(ndim);
235 
236  int resi = 0;
237  for (unsigned int iali = 0; iali < nali; ++iali) {
238  int posi = posvec[iali];
239  int leni = lenvec[iali];
240 
241  for (int ir = 0; ir < leni; ++ir)
242  result[resi + ir] = theData->parameters()[posi - 1 + ir];
243 
244  resi += leni;
245  }
246 
247  return result;
248 }
249 
250 //__________________________________________________________________________________________________
251 // extract covariance matrix for a subset of alignables
253  const auto &sel = extractAlignables(vec);
254 
255  const unsigned int nali = sel.size();
256  int ndim = 0;
257 
258  std::vector<int> posvec;
259  std::vector<int> lenvec;
260 
261  posvec.reserve(nali);
262  lenvec.reserve(nali);
263 
264  // iterate over input vectors of alignables
265  // to determine dimensions of result matrix
266  if (!extractPositionAndLength(sel, posvec, lenvec, ndim))
267  return AlgebraicSymMatrix();
268 
269  // OK, let's do the real work now
271 
272  int resi = 0;
273  for (unsigned int iali = 0; iali < nali; ++iali) {
274  int posi = posvec[iali];
275  int leni = lenvec[iali];
276 
277  int resj = 0;
278  for (unsigned int jali = 0; jali <= iali; ++jali) {
279  int posj = posvec[jali];
280  int lenj = lenvec[jali];
281 
282  for (int ir = 0; ir < leni; ++ir)
283  for (int ic = 0; ic < lenj; ++ic)
284  result[resi + ir][resj + ic] = theData->covariance()[posi - 1 + ir][posj - 1 + ic];
285 
286  resj += lenj;
287  }
288  resi += leni;
289  }
290 
291  return result;
292 }
293 
294 //__________________________________________________________________________________________________
295 // extract covariance matrix elements between two subsets of alignables
297  const align::Alignables &vecj) const {
298  const auto &seli = extractAlignables(veci);
299  const auto &selj = extractAlignables(vecj);
300 
301  int ndimi = 0;
302  int ndimj = 0;
303 
304  std::vector<int> posveci;
305  std::vector<int> lenveci;
306  std::vector<int> posvecj;
307  std::vector<int> lenvecj;
308 
309  posveci.reserve(seli.size());
310  lenveci.reserve(seli.size());
311  posvecj.reserve(selj.size());
312  lenvecj.reserve(selj.size());
313 
314  // iterate over input vectors of alignables
315  // to determine dimensions of result matrix
316  if (!extractPositionAndLength(seli, posveci, lenveci, ndimi))
317  return AlgebraicSymMatrix();
318  // vector vecj
319  if (!extractPositionAndLength(selj, posvecj, lenvecj, ndimj))
320  return AlgebraicSymMatrix();
321 
322  // OK, let's do the real work now
323  AlgebraicMatrix result(ndimi, ndimj);
324 
325  int resi = 0;
326  for (unsigned int iali = 0; iali < seli.size(); ++iali) {
327  int posi = posveci[iali];
328  int leni = lenveci[iali];
329 
330  int resj = 0;
331  for (unsigned int jali = 0; jali < selj.size(); ++jali) {
332  int posj = posvecj[jali];
333  int lenj = lenvecj[jali];
334 
335  for (int ir = 0; ir < leni; ++ir)
336  for (int ic = 0; ic < lenj; ++ic)
337  result[resi + ir][resj + ic] = theData->covariance()[posi - 1 + ir][posj - 1 + ic];
338 
339  resj += lenj;
340  }
341  resi += leni;
342  }
343 
344  return result;
345 }
346 
347 //__________________________________________________________________________________________________
348 // Extract position and length of parameters for a subset of Alignables.
350  std::vector<int> &posvec,
351  std::vector<int> &lenvec,
352  int &length) const {
353  length = 0;
354 
355  for (const auto &it : alignables) {
356  // check if in components
357  if (std::find(theComponents.begin(), theComponents.end(), it) == theComponents.end()) {
358  edm::LogError("NotFound") << "@SUB=CompositeAlignmentParameters::extractPositionAndLength"
359  << "Alignable not found in components!";
360  return false;
361  }
362 
363  // get pos/length
364  Aliposmap::const_iterator iposmap = theAliposmap.find(it);
365  Alilenmap::const_iterator ilenmap = theAlilenmap.find(it);
366  if (iposmap == theAliposmap.end() || ilenmap == theAlilenmap.end()) {
367  edm::LogError("NotFound") << "@SUB=CompositeAlignmentParameters::extractPositionAndLength"
368  << "position/length not found for Alignable in maps!";
369  return false;
370  }
371  posvec.push_back(iposmap->second);
372  lenvec.push_back(ilenmap->second);
373  length += ilenmap->second;
374  }
375 
376  return true;
377 }
378 
379 //__________________________________________________________________________________________________
382 
383  for (const auto &itA : alignables) {
384  if (std::find(result.begin(), result.end(), itA) == result.end())
385  result.push_back(itA);
386  }
387 
388  return result;
389 }
390 
391 //__________________________________________________________________________________________________
392 void CompositeAlignmentParameters::convert(const std::vector<AlignableDet *> &input,
393  std::vector<AlignableDetOrUnitPtr> &output) const {
394  output.clear();
395  output.reserve(input.size());
396 
397  std::vector<AlignableDet *>::const_iterator it, itEnd;
398  for (it = input.begin(), itEnd = input.end(); it != itEnd; ++it)
399  output.push_back(AlignableDetOrUnitPtr(*it));
400 }
CompositeAlignmentParameters * clone(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const
Clone parameters.
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
std::map< Alignable *, int > Aliposmap
align::Alignables Components
vector of alignable components
AlignableDetToAlignableMap theAlignableDetToAlignableMap
Relate Alignable&#39;s and AlignableDet&#39;s.
bool extractPositionAndLength(const align::Alignables &alignables, std::vector< int > &posvec, std::vector< int > &lenvec, int &length) const
Extract position and length of parameters for a subset of Alignables.
void convert(const std::vector< AlignableDet *> &input, std::vector< AlignableDetOrUnitPtr > &output) const
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
static std::string const input
Definition: EdmProvDump.cc:50
CLHEP::HepMatrix AlgebraicMatrix
AlgebraicVector correctionTerm(const std::vector< TrajectoryStateOnSurface > &tsosvec, const std::vector< AlignableDet *> &alidetvec) const
for backward compatibility, use std::vector<AlignableDetOrUnitPtr>
virtual AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
AlgebraicMatrix selectedDerivativesLegacy(const TrajectoryStateOnSurface &tsos, AlignableDet *alidet) const
AlgebraicMatrix derivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
Get derivatives.
AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
Get derivatives for selected alignables.
virtual ~CompositeAlignmentParameters()
destructor
AlgebraicVector parameterSubset(const align::Alignables &) const
Extract parameters for subset of alignables.
CLHEP::HepVector AlgebraicVector
AlgebraicMatrix derivativesLegacy(const TrajectoryStateOnSurface &tsos, AlignableDet *alidet) const
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
Aliposmap theAliposmap
Maps to find parameters/covariance elements for given alignable.
CompositeAlignmentParameters(const AlgebraicVector &par, const AlgebraicSymMatrix &cov, const Components &comp)
constructors
AlgebraicSymMatrix covarianceSubset(const align::Alignables &) const
Extract covariance matrix for subset of alignables.
std::map< Alignable *, int > Alilenmap
std::map< AlignableDetOrUnitPtr, Alignable * > AlignableDetToAlignableMap
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
CLHEP::HepSymMatrix AlgebraicSymMatrix
align::Alignables extractAlignables(const align::Alignables &) const
Return vector of alignables without multiple occurences.
Definition: output.py:1
Components theComponents
Vector of alignable components.
Alignable * alignableFromAlignableDet(const AlignableDetOrUnitPtr &adet) const
Get relevant Alignable from AlignableDet.
Components components() const
Get vector of alignable components.