CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CompositeAlignmentParameters.cc
Go to the documentation of this file.
1 
6 
8 
13 
15 
16 
17 //__________________________________________________________________________________________________
20  const Components& comp) :
21  theData(DataContainer(new AlignmentParametersData(par, cov))),
22  theComponents(comp)
23 {}
24 
25 
26 //__________________________________________________________________________________________________
29  const Components& comp, const AlignableDetToAlignableMap& alimap,
30  const Aliposmap& aliposmap, const Alilenmap& alilenmap) :
31  theData(DataContainer(new AlignmentParametersData(par, cov))),
32  theComponents(comp) ,
33  theAlignableDetToAlignableMap(alimap),
34  theAliposmap(aliposmap),
35  theAlilenmap(alilenmap)
36 {}
37 
38 
39 //__________________________________________________________________________________________________
42  const Components& comp, const AlignableDetToAlignableMap& alimap,
43  const Aliposmap& aliposmap, const Alilenmap& alilenmap) :
44  theData(data),
45  theComponents(comp) ,
46  theAlignableDetToAlignableMap(alimap),
47  theAliposmap(aliposmap),
48  theAlilenmap(alilenmap)
49 {}
50 
51 
52 //__________________________________________________________________________________________________
54 {}
55 
56 
57 //__________________________________________________________________________________________________
60  const AlgebraicSymMatrix& cov) const
61 {
64 
65  return cap;
66 }
67 
68 //__________________________________________________________________________________________________
71  const AlgebraicSymMatrix& cov,
72  const AlignableDetToAlignableMap& alimap,
73  const Aliposmap& aliposmap,
74  const Alilenmap& alilenmap ) const
75 {
77  new CompositeAlignmentParameters(par,cov,components(),alimap,aliposmap,alilenmap);
78 
79  return cap;
80 }
81 
82 //__________________________________________________________________________________________________
85 {
86  return theComponents;
87 }
88 
89 
90 //__________________________________________________________________________________________________
91 // full derivatives for a composed object
93 CompositeAlignmentParameters::derivatives( const std::vector<TrajectoryStateOnSurface>& tsosvec,
94  const std::vector<AlignableDet*>& alidetvec ) const
95 {
96  std::vector<AlignableDetOrUnitPtr> detOrUnits;
97  this->convert(alidetvec, detOrUnits);
98 
99  return this->derivatives(tsosvec, detOrUnits);
100 }
101 
103 CompositeAlignmentParameters::derivatives( const std::vector<TrajectoryStateOnSurface>& tsosvec,
104  const std::vector<AlignableDetOrUnitPtr>& alidetvec ) const
105 {
106  std::vector<Alignable*> alivec;
107  for (std::vector<AlignableDetOrUnitPtr>::const_iterator it=alidetvec.begin(); it!=alidetvec.end(); ++it)
108  alivec.push_back(alignableFromAlignableDet(*it));
109 
110  CompositeAlignmentDerivativesExtractor extractor(alivec,alidetvec,tsosvec);
111  return extractor.derivatives();
112 }
113 
114 //__________________________________________________________________________________________________
116 CompositeAlignmentParameters::correctionTerm( const std::vector<TrajectoryStateOnSurface>& tsosvec,
117  const std::vector<AlignableDet*>& alidetvec) const
118 {
119  std::vector<AlignableDetOrUnitPtr> detOrUnits;
120  this->convert(alidetvec, detOrUnits);
121 
122  return this->correctionTerm(tsosvec, detOrUnits);
123 }
124 
125 //__________________________________________________________________________________________________
127 CompositeAlignmentParameters::correctionTerm( const std::vector<TrajectoryStateOnSurface>& tsosvec,
128  const std::vector<AlignableDetOrUnitPtr>& alidetvec) const
129 {
130  std::vector<Alignable*> alivec;
131  for (std::vector<AlignableDetOrUnitPtr>::const_iterator it=alidetvec.begin(); it!=alidetvec.end(); ++it )
132  alivec.push_back(alignableFromAlignableDet(*it));
133 
134  CompositeAlignmentDerivativesExtractor extractor(alivec,alidetvec,tsosvec);
135  return extractor.correctionTerm();
136 }
137 
138 //__________________________________________________________________________________________________
139 // assume all are selected
141 CompositeAlignmentParameters::selectedDerivatives( const std::vector<TrajectoryStateOnSurface>& tsosvec,
142  const std::vector<AlignableDet*>& alidetvec) const
143 {
144  return derivatives(tsosvec,alidetvec);
145 }
146 //__________________________________________________________________________________________________
147 // assume all are selected
149 CompositeAlignmentParameters::selectedDerivatives( const std::vector<TrajectoryStateOnSurface>& tsosvec,
150  const std::vector<AlignableDetOrUnitPtr>& alidetvec) const
151 {
152  return derivatives(tsosvec,alidetvec);
153 }
154 
155 //__________________________________________________________________________________________________
156 // only one (tsos,AlignableDet) as argument [for compatibility with base class]
159  const AlignableDetOrUnitPtr &alidet) const
160 {
161  std::vector<TrajectoryStateOnSurface> tsosvec;
162  std::vector<AlignableDetOrUnitPtr> alidetvec;
163  tsosvec.push_back(tsos);
164  alidetvec.push_back(alidet);
165  return derivatives(tsosvec,alidetvec);
166 }
167 
168 //__________________________________________________________________________________________________
169 // assume all are selected
172  const AlignableDetOrUnitPtr &alidet ) const
173 {
174  return derivatives(tsos,alidet);
175 }
176 
177 
178 // Derivatives ----------------------------------------------------------------
179 // legacy methods
180 // full derivatives for a composed object
182 CompositeAlignmentParameters::derivativesLegacy( const std::vector<TrajectoryStateOnSurface> &tsosvec,
183  const std::vector<AlignableDet*>& alidetvec ) const
184 {
185  // sanity check: length of parameter argument vectors must be equal
186  if (alidetvec.size() != tsosvec.size())
187  {
188  edm::LogError("BadArgument") << " Inconsistent length of argument vectors! ";
189  AlgebraicMatrix selderiv(1,0);
190  return selderiv;
191  }
192 
193  std::vector<AlgebraicMatrix> vecderiv;
194  int nparam=0;
195 
196  std::vector<TrajectoryStateOnSurface>::const_iterator itsos=tsosvec.begin();
197  for( std::vector<AlignableDet*>::const_iterator it=alidetvec.begin();
198  it!=alidetvec.end(); ++it, ++itsos )
199  {
200  AlignableDet* ad = (*it);
203  AlgebraicMatrix thisselderiv = ap->selectedDerivatives(*itsos,ad);
204  vecderiv.push_back(thisselderiv);
205  nparam += thisselderiv.num_row();
206  }
207 
208  int ipos=1;
209  AlgebraicMatrix selderiv(nparam,2);
210  for ( std::vector<AlgebraicMatrix>::const_iterator imat=vecderiv.begin();
211  imat!=vecderiv.end(); ++imat )
212  {
213  AlgebraicMatrix thisselderiv=(*imat);
214  int npar=thisselderiv.num_row();
215  selderiv.sub(ipos,1,thisselderiv);
216  ipos += npar;
217  }
218 
219  return selderiv;
220 }
221 
222 
223 //__________________________________________________________________________________________________
224 // assume all are selected
226 CompositeAlignmentParameters::selectedDerivativesLegacy( const std::vector<TrajectoryStateOnSurface> &tsosvec,
227  const std::vector<AlignableDet*>& alidetvec ) const
228 {
229  return derivativesLegacy(tsosvec,alidetvec);
230 }
231 
232 
233 //__________________________________________________________________________________________________
234 // only one (tsos,AlignableDet) as argument [for compatibility with base class]
237  AlignableDet* alidet ) const
238 {
239  std::vector<TrajectoryStateOnSurface> tsosvec;
240  std::vector<AlignableDet*> alidetvec;
241  tsosvec.push_back(tsos);
242  alidetvec.push_back(alidet);
243  return derivativesLegacy(tsosvec,alidetvec);
244 
245 }
246 
247 
248 //__________________________________________________________________________________________________
249 // assume all are selected
252  AlignableDet* alidet ) const
253 {
254  return derivativesLegacy(tsos,alidet);
255 }
256 
257 
258 //__________________________________________________________________________________________________
259 // finds Alignable corresponding to AlignableDet
260 Alignable*
262 {
263 
264  AlignableDetToAlignableMap::const_iterator iali =
266  if ( iali!=theAlignableDetToAlignableMap.end() ) return (*iali).second;
267  else return 0;
268 
269 }
270 
271 
272 //__________________________________________________________________________________________________
274 CompositeAlignmentParameters::parameterSubset( const std::vector<Alignable*>& vec ) const
275 {
276  const std::vector< Alignable* > sel = extractAlignables( vec );
277 
278  const unsigned int nali = sel.size();
279  int ndim = 0;
280 
281  std::vector<int> posvec;
282  std::vector<int> lenvec;
283 
284  posvec.reserve( nali );
285  lenvec.reserve( nali );
286 
287  // iterate over input vector of alignables to determine size of result vector
288  if ( !extractPositionAndLength( sel, posvec, lenvec, ndim ) ) return AlgebraicVector();
289 
290  // OK, let's do the real work now
291  AlgebraicVector result( ndim );
292 
293  int resi = 0;
294  for ( unsigned int iali = 0; iali < nali; ++iali )
295  {
296  int posi = posvec[iali];
297  int leni = lenvec[iali];
298 
299  for ( int ir = 0; ir < leni; ++ir )
300  result[resi+ir] = theData->parameters()[posi-1+ir];
301 
302  resi += leni;
303  }
304 
305  return result;
306 }
307 
308 
309 //__________________________________________________________________________________________________
310 // extract covariance matrix for a subset of alignables
312 CompositeAlignmentParameters::covarianceSubset( const std::vector<Alignable*>& vec ) const
313 {
314  const std::vector< Alignable* > sel = extractAlignables( vec );
315 
316  const unsigned int nali = sel.size();
317  int ndim = 0;
318 
319  std::vector<int> posvec;
320  std::vector<int> lenvec;
321 
322  posvec.reserve( nali );
323  lenvec.reserve( nali );
324 
325  // iterate over input vectors of alignables
326  // to determine dimensions of result matrix
327  if ( !extractPositionAndLength( sel, posvec, lenvec, ndim ) ) return AlgebraicSymMatrix();
328 
329  // OK, let's do the real work now
330  AlgebraicSymMatrix result( ndim );
331 
332  int resi = 0;
333  for ( unsigned int iali = 0; iali < nali; ++iali )
334  {
335  int posi = posvec[iali];
336  int leni = lenvec[iali];
337 
338  int resj = 0;
339  for ( unsigned int jali = 0; jali <= iali; ++jali )
340  {
341  int posj = posvec[jali];
342  int lenj = lenvec[jali];
343 
344  for ( int ir = 0; ir < leni; ++ir )
345  for ( int ic = 0; ic < lenj; ++ic )
346  result[resi+ir][resj+ic] = theData->covariance()[posi-1+ir][posj-1+ic];
347 
348  resj += lenj;
349  }
350  resi += leni;
351  }
352 
353  return result;
354 }
355 
356 
357 //__________________________________________________________________________________________________
358 // extract covariance matrix elements between two subsets of alignables
360 CompositeAlignmentParameters::covarianceSubset( const std::vector<Alignable*>& veci,
361  const std::vector<Alignable*>& vecj ) const
362 {
363  const std::vector< Alignable* > seli = extractAlignables( veci );
364  const std::vector< Alignable* > selj = extractAlignables( vecj );
365 
366  int ndimi=0;
367  int ndimj=0;
368 
369  std::vector<int> posveci;
370  std::vector<int> lenveci;
371  std::vector<int> posvecj;
372  std::vector<int> lenvecj;
373 
374  posveci.reserve( seli.size() );
375  lenveci.reserve( seli.size() );
376  posvecj.reserve( selj.size() );
377  lenvecj.reserve( selj.size() );
378 
379  // iterate over input vectors of alignables
380  // to determine dimensions of result matrix
381  if ( !extractPositionAndLength( seli, posveci, lenveci, ndimi ) ) return AlgebraicSymMatrix();
382  // vector vecj
383  if ( !extractPositionAndLength( selj, posvecj, lenvecj, ndimj ) ) return AlgebraicSymMatrix();
384 
385  // OK, let's do the real work now
386  AlgebraicMatrix result( ndimi, ndimj );
387 
388  int resi = 0;
389  for ( unsigned int iali = 0; iali < seli.size(); ++iali )
390  {
391  int posi = posveci[iali];
392  int leni = lenveci[iali];
393 
394  int resj = 0;
395  for ( unsigned int jali = 0; jali < selj.size(); ++jali )
396  {
397  int posj = posvecj[jali];
398  int lenj = lenvecj[jali];
399 
400  for ( int ir = 0; ir < leni; ++ir )
401  for ( int ic = 0; ic < lenj; ++ic )
402  result[resi+ir][resj+ic] = theData->covariance()[posi-1+ir][posj-1+ic];
403 
404  resj += lenj;
405  }
406  resi += leni;
407  }
408 
409  return result;
410 }
411 
412 
413 //__________________________________________________________________________________________________
414 // Extract position and length of parameters for a subset of Alignables.
415 bool
416 CompositeAlignmentParameters::extractPositionAndLength( const std::vector<Alignable*>& alignables,
417  std::vector<int>& posvec,
418  std::vector<int>& lenvec,
419  int& length ) const
420 {
421  length = 0;
422 
423  for ( std::vector<Alignable*>::const_iterator it = alignables.begin(); it != alignables.end(); ++it )
424  {
425  // check if in components
426  if ( std::find( theComponents.begin(), theComponents.end(), *it ) == theComponents.end() )
427  {
428  edm::LogError( "NotFound" ) << "@SUB=CompositeAlignmentParameters::extractPositionAndLength"
429  << "Alignable not found in components!";
430  return false;
431  }
432 
433  // get pos/length
434  Aliposmap::const_iterator iposmap = theAliposmap.find( *it );
435  Alilenmap::const_iterator ilenmap = theAlilenmap.find( *it );
436  if ( iposmap == theAliposmap.end() || ilenmap == theAlilenmap.end() )
437  {
438  edm::LogError( "NotFound" ) << "@SUB=CompositeAlignmentParameters::extractPositionAndLength"
439  << "position/length not found for Alignable in maps!";
440  return false;
441  }
442  posvec.push_back( iposmap->second );
443  lenvec.push_back( ilenmap->second );
444  length += ilenmap->second;
445  }
446 
447  return true;
448 }
449 
450 
451 //__________________________________________________________________________________________________
452 std::vector< Alignable* >
453 CompositeAlignmentParameters::extractAlignables( const std::vector< Alignable* >& alignables ) const
454 {
455  std::vector< Alignable* > result;
456 
457  std::vector< Alignable* >::const_iterator itA, itEnd;
458  for ( itA = alignables.begin(), itEnd = alignables.end(); itA != itEnd; ++itA )
459  {
460  if ( std::find( result.begin(), result.end(), *itA ) == result.end() ) result.push_back( *itA );
461  }
462 
463  return result;
464 }
465 
466 
467 //__________________________________________________________________________________________________
468 void CompositeAlignmentParameters::convert(const std::vector<AlignableDet*> &input,
469  std::vector<AlignableDetOrUnitPtr> &output) const
470 {
471  output.clear();
472  output.reserve(input.size());
473 
474  std::vector<AlignableDet*>::const_iterator it, itEnd;
475  for (it = input.begin(), itEnd = input.end(); it != itEnd; ++it)
476  output.push_back(AlignableDetOrUnitPtr(*it));
477 }
bool extractPositionAndLength(const std::vector< Alignable * > &alignables, std::vector< int > &posvec, std::vector< int > &lenvec, int &length) const
Extract position and length of parameters for a subset of Alignables.
std::vector< Alignable * > extractAlignables(const std::vector< Alignable * > &alignables) const
Return vector of alignables without multiple occurences.
std::vector< Alignable * > Components
vector of alignable components
AlignableDetToAlignableMap theAlignableDetToAlignableMap
Relate Alignable&#39;s and AlignableDet&#39;s.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
Alignable * alignableFromAlignableDet(const AlignableDetOrUnitPtr &adet) const
Get relevant Alignable from AlignableDet.
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:57
static std::string const input
Definition: EdmProvDump.cc:43
AlgebraicMatrix selectedDerivativesLegacy(const TrajectoryStateOnSurface &tsos, AlignableDet *alidet) const
deprecated due to &#39;AlignableDet*&#39; interface (legacy code should not be needed anymore) ...
void convert(const std::vector< AlignableDet * > &input, std::vector< AlignableDetOrUnitPtr > &output) const
AlgebraicSymMatrix covarianceSubset(const std::vector< Alignable * > &vec) const
Extract covariance matrix for subset of alignables.
CLHEP::HepMatrix AlgebraicMatrix
Components components() const
Get vector of alignable components.
tuple result
Definition: query.py:137
std::map< Alignable *, int > Alilenmap
virtual ~CompositeAlignmentParameters()
destructor
AlgebraicVector correctionTerm(const std::vector< TrajectoryStateOnSurface > &tsosvec, const std::vector< AlignableDet * > &alidetvec) const
for backward compatibility, use std::vector&lt;AlignableDetOrUnitPtr&gt;
CLHEP::HepVector AlgebraicVector
std::map< AlignableDetOrUnitPtr, Alignable * > AlignableDetToAlignableMap
AlgebraicMatrix derivativesLegacy(const TrajectoryStateOnSurface &tsos, AlignableDet *alidet) const
deprecated due to &#39;AlignableDet*&#39; interface (legacy code should not be needed anymore) ...
AlgebraicVector parameterSubset(const std::vector< Alignable * > &vec) const
Extract parameters for subset of alignables.
AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
Get derivatives for selected alignables.
Aliposmap theAliposmap
Maps to find parameters/covariance elements for given alignable.
CompositeAlignmentParameters(const AlgebraicVector &par, const AlgebraicSymMatrix &cov, const Components &comp)
constructors
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::map< Alignable *, int > Aliposmap
Components theComponents
Vector of alignable components.
AlgebraicMatrix derivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
Get derivatives.
CompositeAlignmentParameters * clone(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const
Clone parameters.
virtual AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const