CMS 3D CMS Logo

AlignmentParameterStore.cc
Go to the documentation of this file.
1 
9 // This class's header should be first
11 
15 
19 
24 
27 
28 //__________________________________________________________________________________________________
30  : theAlignables(alis) {
31  if (config.getUntrackedParameter<bool>("UseExtendedCorrelations")) {
33  new AlignmentExtendedCorrelationsStore(config.getParameter<edm::ParameterSet>("ExtendedCorrelationsConfig"));
34  } else {
36  }
37 
38  edm::LogInfo("Alignment") << "@SUB=AlignmentParameterStore"
39  << "Created with " << theAlignables.size() << " alignables.";
40 
41  // set hierarchy vs averaging constraints
43  const std::string cfgStrTypeOfConstraints(config.getParameter<std::string>("TypeOfConstraints"));
44  if (cfgStrTypeOfConstraints == "hierarchy") {
46  } else if (cfgStrTypeOfConstraints == "approximate_averaging") {
48  edm::LogWarning("Alignment")
49  << "@SUB=AlignmentParameterStore"
50  << "\n\n\n******* WARNING ******************************************\n"
51  << "Using approximate implementation of averaging constraints."
52  << "This is not recommended."
53  << "Consider to use 'hierarchy' constraints:"
54  << " AlignmentProducer.ParameterStore.TypeOfConstraints = cms.string('hierarchy')\n\n\n";
55  } else {
56  edm::LogError("BadArgument") << "@SUB=AlignmentParameterStore"
57  << "Unknown type of hierarchy constraints '" << cfgStrTypeOfConstraints << "'";
58  }
59 }
60 
61 //__________________________________________________________________________________________________
63 
64 //__________________________________________________________________________________________________
66  const std::vector<AlignableDet*>& alignabledets) const {
67  std::vector<AlignableDetOrUnitPtr> detOrUnits;
68  detOrUnits.reserve(alignabledets.size());
69 
70  std::vector<AlignableDet*>::const_iterator it, iEnd;
71  for (it = alignabledets.begin(), iEnd = alignabledets.end(); it != iEnd; ++it)
72  detOrUnits.push_back(AlignableDetOrUnitPtr(*it));
73 
74  return this->selectParameters(detOrUnits);
75 }
76 
77 //__________________________________________________________________________________________________
79  const std::vector<AlignableDetOrUnitPtr>& alignabledets) const {
81  std::map<AlignableDetOrUnitPtr, Alignable*> alidettoalimap;
82  std::map<Alignable*, int> aliposmap;
83  std::map<Alignable*, int> alilenmap;
84  int nparam = 0;
85 
86  // iterate over AlignableDet's
87  for (std::vector<AlignableDetOrUnitPtr>::const_iterator iad = alignabledets.begin(); iad != alignabledets.end();
88  ++iad) {
90  if (ali) {
91  alidettoalimap[*iad] = ali; // Add to map
92  // Check if Alignable already there, insert into vector if not
93  if (find(alignables.begin(), alignables.end(), ali) == alignables.end()) {
94  alignables.push_back(ali);
96  nparam += ap->numSelected();
97  }
98  }
99  }
100 
101  AlgebraicVector* selpar = new AlgebraicVector(nparam, 0);
102  AlgebraicSymMatrix* selcov = new AlgebraicSymMatrix(nparam, 0);
103 
104  // Fill in parameters and corresponding covariance matricess
105  int ipos = 1; // NOTE: .sub indices start from 1
106  align::Alignables::const_iterator it1;
107  for (it1 = alignables.begin(); it1 != alignables.end(); ++it1) {
108  AlignmentParameters* ap = (*it1)->alignmentParameters();
109  selpar->sub(ipos, ap->selectedParameters());
110  selcov->sub(ipos, ap->selectedCovariance());
111  int npar = ap->numSelected();
112  aliposmap[*it1] = ipos;
113  alilenmap[*it1] = npar;
114  ipos += npar;
115  }
116 
117  // Fill in the correlations. Has to be an extra loop, because the
118  // AlignmentExtendedCorrelationsStore (if used) needs the
119  // alignables' covariance matrices already present.
120  ipos = 1;
121  for (it1 = alignables.begin(); it1 != alignables.end(); ++it1) {
122  int jpos = 1;
123 
124  // Look for correlations between alignables
125  align::Alignables::const_iterator it2;
126  for (it2 = alignables.begin(); it2 != it1; ++it2) {
127  theCorrelationsStore->correlations(*it1, *it2, *selcov, ipos - 1, jpos - 1);
128  jpos += (*it2)->alignmentParameters()->numSelected();
129  }
130 
131  ipos += (*it1)->alignmentParameters()->numSelected();
132  }
133 
135  CompositeAlignmentParameters aap(data, alignables, alidettoalimap, aliposmap, alilenmap);
136 
137  return aap;
138 }
139 
140 //__________________________________________________________________________________________________
142  align::Alignables selectedAlignables;
143  std::map<AlignableDetOrUnitPtr, Alignable*> alidettoalimap; // This map won't be filled!!!
144  std::map<Alignable*, int> aliposmap;
145  std::map<Alignable*, int> alilenmap;
146  int nparam = 0;
147 
148  // iterate over Alignable's
149  align::Alignables::const_iterator ita;
150  for (ita = alignables.begin(); ita != alignables.end(); ++ita) {
151  // Check if Alignable already there, insert into vector if not
152  if (find(selectedAlignables.begin(), selectedAlignables.end(), *ita) == selectedAlignables.end()) {
153  selectedAlignables.push_back(*ita);
154  AlignmentParameters* ap = (*ita)->alignmentParameters();
155  nparam += ap->numSelected();
156  }
157  }
158 
159  AlgebraicVector* selpar = new AlgebraicVector(nparam, 0);
160  AlgebraicSymMatrix* selcov = new AlgebraicSymMatrix(nparam, 0);
161 
162  // Fill in parameters and corresponding covariance matrices
163  int ipos = 1; // NOTE: .sub indices start from 1
164  align::Alignables::const_iterator it1;
165  for (it1 = selectedAlignables.begin(); it1 != selectedAlignables.end(); ++it1) {
166  AlignmentParameters* ap = (*it1)->alignmentParameters();
167  selpar->sub(ipos, ap->selectedParameters());
168  selcov->sub(ipos, ap->selectedCovariance());
169  int npar = ap->numSelected();
170  aliposmap[*it1] = ipos;
171  alilenmap[*it1] = npar;
172  ipos += npar;
173  }
174 
175  // Fill in the correlations. Has to be an extra loop, because the
176  // AlignmentExtendedCorrelationsStore (if used) needs the
177  // alignables' covariance matrices already present.
178  ipos = 1;
179  for (it1 = selectedAlignables.begin(); it1 != selectedAlignables.end(); ++it1) {
180  int jpos = 1;
181 
182  // Look for correlations between alignables
183  align::Alignables::const_iterator it2;
184  for (it2 = selectedAlignables.begin(); it2 != it1; ++it2) {
185  theCorrelationsStore->correlations(*it1, *it2, *selcov, ipos - 1, jpos - 1);
186  jpos += (*it2)->alignmentParameters()->numSelected();
187  }
188 
189  ipos += (*it1)->alignmentParameters()->numSelected();
190  }
191 
193  CompositeAlignmentParameters aap(data, selectedAlignables, alidettoalimap, aliposmap, alilenmap);
194 
195  return aap;
196 }
197 
198 //__________________________________________________________________________________________________
201  const AlgebraicVector& parameters = aap.parameters();
202  const AlgebraicSymMatrix& covariance = aap.covariance();
203 
204  int ipos = 1; // NOTE: .sub indices start from 1
205 
206  // Loop over alignables
207  for (align::Alignables::const_iterator it = alignables.begin(); it != alignables.end(); ++it) {
208  // Update parameters and local covariance
209  AlignmentParameters* ap = (*it)->alignmentParameters();
210  int nsel = ap->numSelected();
211  AlgebraicVector subvec = parameters.sub(ipos, ipos + nsel - 1);
212  AlgebraicSymMatrix subcov = covariance.sub(ipos, ipos + nsel - 1);
213  AlignmentParameters* apnew = ap->cloneFromSelected(subvec, subcov);
214  (*it)->setAlignmentParameters(apnew);
215 
216  // Now update correlations between detectors
217  if (updateCorrelations) {
218  int jpos = 1;
219  for (align::Alignables::const_iterator it2 = alignables.begin(); it2 != it; ++it2) {
220  theCorrelationsStore->setCorrelations(*it, *it2, covariance, ipos - 1, jpos - 1);
221  jpos += (*it2)->alignmentParameters()->numSelected();
222  }
223  }
224 
225  ipos += nsel;
226  }
227 }
228 
229 //__________________________________________________________________________________________________
232  for (align::Alignables::const_iterator iali = theAlignables.begin(); iali != theAlignables.end(); ++iali)
233  if ((*iali)->alignmentParameters()->isValid())
234  result.push_back(*iali);
235 
236  LogDebug("Alignment") << "@SUB=AlignmentParameterStore::validAlignables"
237  << "Valid alignables: " << result.size() << "out of " << theAlignables.size();
238  return result;
239 }
240 
241 //__________________________________________________________________________________________________
243  AlignableDetOrUnitPtr alignableDet = _alignableDet;
244  Alignable* mother = alignableDet;
245  while (mother) {
246  if (mother->alignmentParameters())
247  return mother;
248  mother = mother->mother();
249  }
250 
251  return nullptr;
252 }
253 
254 //__________________________________________________________________________________________________
256  align::Alignables::const_iterator iali;
257  for (iali = theAlignables.begin(); iali != theAlignables.end(); ++iali)
258  applyParameters(*iali);
259 }
260 
261 //__________________________________________________________________________________________________
263  AlignmentParameters* pars = (alignable ? alignable->alignmentParameters() : nullptr);
264  if (!pars) {
265  throw cms::Exception("BadAlignable") << "applyParameters: provided alignable does not have alignment parameters";
266  }
267  pars->apply();
268 }
269 
270 //__________________________________________________________________________________________________
272  // Erase contents of correlation map
274 
275  // Iterate over alignables in the store and reset parameters
276  align::Alignables::const_iterator iali;
277  for (iali = theAlignables.begin(); iali != theAlignables.end(); ++iali)
278  resetParameters(*iali);
279 }
280 
281 //__________________________________________________________________________________________________
283  if (ali) {
284  // Get alignment parameters for this alignable
286  if (ap) {
287  int npar = ap->numSelected();
288 
289  AlgebraicVector par(npar, 0);
290  AlgebraicSymMatrix cov(npar, 0);
291  AlignmentParameters* apnew = ap->cloneFromSelected(par, cov);
292  ali->setAlignmentParameters(apnew);
293  apnew->setValid(false);
294  } else
295  edm::LogError("BadArgument") << "@SUB=AlignmentParameterStore::resetParameters"
296  << "alignable has no alignment parameter";
297  } else
298  edm::LogError("BadArgument") << "@SUB=AlignmentParameterStore::resetParameters"
299  << "argument is NULL";
300 }
301 
302 //__________________________________________________________________________________________________
304  align::Alignables::const_iterator iali;
305  for (iali = theAlignables.begin(); iali != theAlignables.end(); ++iali)
306  (*iali)->cacheTransformation();
307 }
308 
309 //__________________________________________________________________________________________________
311  for (const auto& iali : theAlignables)
312  iali->cacheTransformation(run);
313 }
314 
315 //__________________________________________________________________________________________________
317  align::Alignables::const_iterator iali;
318  for (iali = theAlignables.begin(); iali != theAlignables.end(); ++iali)
319  (*iali)->restoreCachedTransformation();
320 }
321 
322 //__________________________________________________________________________________________________
324  for (const auto& iali : theAlignables)
325  iali->restoreCachedTransformation(run);
326 }
327 
328 //__________________________________________________________________________________________________
330  unsigned int nAlignables = theAlignables.size();
331 
332  for (unsigned int i = 0; i < nAlignables; ++i) {
333  Alignable* ali = theAlignables[i];
334 
335  RigidBodyAlignmentParameters* ap = dynamic_cast<RigidBodyAlignmentParameters*>(ali->alignmentParameters());
336 
337  if (!ap)
338  throw cms::Exception("BadAlignable") << "acquireRelativeParameters: "
339  << "provided alignable does not have rigid body alignment parameters";
340 
341  AlgebraicVector par(ap->size(), 0);
342  AlgebraicSymMatrix cov(ap->size(), 0);
343 
344  // Get displacement and transform global->local
345  align::LocalVector dloc = ali->surface().toLocal(ali->displacement());
346  par[0] = dloc.x();
347  par[1] = dloc.y();
348  par[2] = dloc.z();
349 
350  // Transform to local euler angles
352  par[3] = euloc(1);
353  par[4] = euloc(2);
354  par[5] = euloc(3);
355 
356  // Clone parameters
357  RigidBodyAlignmentParameters* apnew = ap->clone(par, cov);
358 
359  ali->setAlignmentParameters(apnew);
360  }
361 }
362 
363 //__________________________________________________________________________________________________
364 // Get type/layer from Alignable
365 // type: -6 -5 -4 -3 -2 -1 1 2 3 4 5 6
366 // TEC- TOB- TID- TIB- PxEC- PxBR- PxBr+ PxEC+ TIB+ TID+ TOB+ TEC+
367 // Layers start from zero
368 std::pair<int, int> AlignmentParameterStore::typeAndLayer(const Alignable* ali, const TrackerTopology* tTopo) const {
369  return TrackerAlignableId().typeAndLayerFromDetId(ali->id(), tTopo);
370 }
371 
372 //__________________________________________________________________________________________________
374  const AlignablePositions& newpos,
375  int& ierr) {
376  unsigned int nappl = 0;
377  ierr = 0;
378 
379  // Iterate over list of alignables
380  for (align::Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali) {
381  Alignable* ali = *iali;
382  align::ID id = ali->id();
383  align::StructureType typeId = ali->alignableObjectId();
384 
385  // Find corresponding entry in AlignablePositions
386  bool found = false;
387  for (AlignablePositions::const_iterator ipos = newpos.begin(); ipos != newpos.end(); ++ipos) {
388  if (id == ipos->id() && typeId == ipos->objId()) {
389  if (found) {
390  edm::LogError("DuplicatePosition") << "New positions for alignable found more than once!";
391  } else {
392  // New position/rotation
393  const align::PositionType& pnew = ipos->pos();
394  const align::RotationType& rnew = ipos->rot();
395  const std::vector<double>& dnew = ipos->deformationParameters();
396  // Current position / rotation
397  const align::PositionType& pold = ali->globalPosition();
398  const align::RotationType& rold = ali->globalRotation();
399  // Current surf. deformation
400  std::vector<std::pair<int, SurfaceDeformation*> > dold_id_pairs;
401  SurfaceDeformation* dold_obj = nullptr;
403  std::vector<double> dold;
404  if (1 == ali->surfaceDeformationIdPairs(dold_id_pairs)) { // might not have any...
405  dold_obj = dold_id_pairs[0].second;
406  dold = dold_obj->parameters();
408  }
409 
410  // shift needed to move from current to new position
411  align::GlobalVector posDiff = pnew - pold;
412  align::RotationType rotDiff = rold.multiplyInverse(rnew);
413  align::rectify(rotDiff); // correct for rounding errors
414  ali->move(posDiff);
415  ali->rotateInGlobalFrame(rotDiff);
416  LogDebug("NewPosition") << "moving by:" << posDiff;
417  LogDebug("NewRotation") << "rotating by:\n" << rotDiff;
418 
419  // add the surface deformations
420  // If an old surface deformation record exists, ensure that the added deformation has the same type and size.
421  if (!dold.empty() && dtype != SurfaceDeformationFactory::kNoDeformations && dnew.size() == dold.size()) {
422  std::vector<double> defDiff;
423  defDiff.reserve(dold.size());
424  for (unsigned int i = 0; i < dold.size(); i++)
425  defDiff.push_back(dnew[i] - dold[i]);
426  auto deform = SurfaceDeformationFactory::create(dtype, defDiff);
427  edm::LogInfo("Alignment") << "@SUB=AlignmentParameterStore::applyAlignableAbsolutePositions"
428  << "Adding surface deformation of type "
430  (SurfaceDeformationFactory::Type)deform->type())
431  << ", size " << defDiff.size() << " and first element " << defDiff.at(0)
432  << " to alignable with id / type: " << id << " / " << typeId;
433  ali->addSurfaceDeformation(deform, true);
434  delete deform;
435  }
436  // In case no old surface deformation record exists, only ensure that the new surface deformation record has size>0. Size check is done elsewhere.
437  else if (!dnew.empty()) {
438  auto deform = SurfaceDeformationFactory::create(dnew);
439  edm::LogInfo("Alignment") << "@SUB=AlignmentParameterStore::applyAlignableAbsolutePositions"
440  << "Setting surface deformation of type "
442  (SurfaceDeformationFactory::Type)deform->type())
443  << ", size " << dnew.size() << " and first element " << dnew.at(0)
444  << " to alignable with id / type: " << id << " / " << typeId;
445  ali->addSurfaceDeformation(deform, true); // Equivalent to setSurfaceDeformation in this case
446  delete deform;
447  }
448  // If there is no new surface deformation record, do nothing.
449 
450  // add position error
451  // AlignmentPositionError ape(shift.x(),shift.y(),shift.z());
452  // (*iali)->addAlignmentPositionError(ape);
453  // (*iali)->addAlignmentPositionErrorFromRotation(rot);
454 
455  found = true;
456  ++nappl;
457  }
458  }
459  }
460  }
461 
462  if (nappl < newpos.size())
463  edm::LogError("Mismatch") << "Applied only " << nappl << " new positions"
464  << " out of " << newpos.size();
465 
466  LogDebug("NewPositions") << "Applied new positions for " << nappl << " out of " << alivec.size() << " alignables.";
467 }
468 
469 //__________________________________________________________________________________________________
471  const AlignableShifts& shifts,
472  int& ierr) {
473  ierr = 0;
474  unsigned int nappl = 0;
475  unsigned int nAlignables = alivec.size();
476 
477  for (unsigned int i = 0; i < nAlignables; ++i) {
478  Alignable* ali = alivec[i];
479 
480  align::ID id = ali->id();
481  align::StructureType typeId = ali->alignableObjectId();
482 
483  // Find corresponding entry in AlignableShifts
484  bool found = false;
485  for (AlignableShifts::const_iterator ipos = shifts.begin(); ipos != shifts.end(); ++ipos) {
486  if (id == ipos->id() && typeId == ipos->objId()) {
487  if (found) {
488  edm::LogError("DuplicatePosition") << "New positions for alignable found more than once!";
489  } else {
490  // Current surf. deformation
491  std::vector<std::pair<int, SurfaceDeformation*> > dold_id_pairs;
492  SurfaceDeformation* dold_obj = nullptr;
494  std::vector<double> dold;
495  if (1 == ali->surfaceDeformationIdPairs(dold_id_pairs)) { // might not have any...
496  dold_obj = dold_id_pairs[0].second;
497  dold = dold_obj->parameters();
499  }
500 
501  ali->move(ipos->pos());
502  ali->rotateInGlobalFrame(ipos->rot());
503 
504  const std::vector<double>& defDiff = ipos->deformationParameters();
505  // If an old surface deformation record exists, ensure that the added deformation has the same type and size.
506  if (!dold.empty() && dtype != SurfaceDeformationFactory::kNoDeformations && defDiff.size() == dold.size()) {
507  auto deform = SurfaceDeformationFactory::create(dtype, defDiff);
508  edm::LogInfo("Alignment") << "@SUB=AlignmentParameterStore::applyAlignableRelativePositions"
509  << "Adding surface deformation of type "
511  (SurfaceDeformationFactory::Type)deform->type())
512  << ", size " << defDiff.size() << " and first element " << defDiff.at(0)
513  << " to alignable with id / type: " << id << " / " << typeId;
514  ali->addSurfaceDeformation(deform, true);
515  delete deform;
516  }
517  // In case no old surface deformation record exists, only ensure that the new surface deformation record has size>0. Size check is done elsewhere.
518  else if (!defDiff.empty()) {
519  auto deform = SurfaceDeformationFactory::create(defDiff);
520  edm::LogInfo("Alignment") << "@SUB=AlignmentParameterStore::applyAlignableRelativePositions"
521  << "Setting surface deformation of type "
523  (SurfaceDeformationFactory::Type)deform->type())
524  << ", size " << defDiff.size() << " and first element " << defDiff.at(0)
525  << " to alignable with id / type: " << id << " / " << typeId;
526  ali->addSurfaceDeformation(deform, true); // Equivalent to setSurfaceDeformation in this case
527  delete deform;
528  }
529  // If there is no new surface deformation record, do nothing.
530 
531  // Add position error
532  //AlignmentPositionError ape(pnew.x(),pnew.y(),pnew.z());
533  //ali->addAlignmentPositionError(ape);
534  //ali->addAlignmentPositionErrorFromRotation(rnew);
535 
536  found = true;
537  ++nappl;
538  }
539  }
540  }
541  }
542 
543  if (nappl < shifts.size())
544  edm::LogError("Mismatch") << "Applied only " << nappl << " new positions"
545  << " out of " << shifts.size();
546 
547  LogDebug("NewPositions") << "Applied new positions for " << nappl << " alignables.";
548 }
549 
550 //__________________________________________________________________________________________________
553 }
554 
555 //__________________________________________________________________________________________________
557  const Parameters& parvec,
558  int& ierr) {
559  int ipass = 0;
560  int ifail = 0;
561  ierr = 0;
562 
563  // Iterate over alignables
564  for (align::Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali) {
565  // Iterate over Parameters
566  bool found = false;
567  for (Parameters::const_iterator ipar = parvec.begin(); ipar != parvec.end(); ++ipar) {
568  // Get new alignment parameters
569  AlignmentParameters* ap = *ipar;
570 
571  // Check if parameters belong to alignable
572  if (ap->alignable() == (*iali)) {
573  if (!found) {
574  (*iali)->setAlignmentParameters(ap);
575  ++ipass;
576  found = true;
577  } else
578  edm::LogError("Alignment") << "@SUB=AlignmentParameterStore::attachAlignmentParameters"
579  << "More than one parameters for Alignable.";
580  }
581  }
582  if (!found)
583  ++ifail;
584  }
585  if (ifail > 0)
586  ierr = -1;
587 
588  LogDebug("attachAlignmentParameters") << " Parameters, Alignables: " << parvec.size() << "," << alivec.size()
589  << "\n pass,fail: " << ipass << "," << ifail;
590 }
591 
592 //__________________________________________________________________________________________________
593 void AlignmentParameterStore::attachCorrelations(const Correlations& cormap, bool overwrite, int& ierr) {
594  attachCorrelations(theAlignables, cormap, overwrite, ierr);
595 }
596 
597 //__________________________________________________________________________________________________
599  const Correlations& cormap,
600  bool overwrite,
601  int& ierr) {
602  ierr = 0;
603  int icount = 0;
604 
605  // Iterate over correlations
606  for (Correlations::const_iterator icor = cormap.begin(); icor != cormap.end(); ++icor) {
607  AlgebraicMatrix mat = (*icor).second;
608  Alignable* ali1 = (*icor).first.first;
609  Alignable* ali2 = (*icor).first.second;
610 
611  // Check if alignables exist
612  if (find(alivec.begin(), alivec.end(), ali1) != alivec.end() &&
613  find(alivec.begin(), alivec.end(), ali2) != alivec.end()) {
614  // Check if correlations already existing between these alignables
615  if (!theCorrelationsStore->correlationsAvailable(ali1, ali2) || (overwrite)) {
616  theCorrelationsStore->setCorrelations(ali1, ali2, mat);
617  ++icount;
618  } else
619  edm::LogInfo("AlreadyExists") << "Correlation existing and not overwritten";
620  } else
621  edm::LogInfo("IgnoreCorrelation") << "Ignoring correlation with no alignables!";
622  }
623 
624  LogDebug("attachCorrelations") << " Alignables,Correlations: " << alivec.size() << "," << cormap.size()
625  << "\n applied: " << icount;
626 }
627 
628 //__________________________________________________________________________________________________
630  const std::vector<AlignmentUserVariables*>& uvarvec,
631  int& ierr) {
632  ierr = 0;
633 
634  LogDebug("DumpArguments") << "size of alivec: " << alivec.size() << "\nsize of uvarvec: " << uvarvec.size();
635 
636  std::vector<AlignmentUserVariables*>::const_iterator iuvar = uvarvec.begin();
637 
638  for (align::Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali, ++iuvar) {
639  AlignmentParameters* ap = (*iali)->alignmentParameters();
640  AlignmentUserVariables* uvarnew = (*iuvar);
641  ap->setUserVariables(uvarnew);
642  }
643 }
644 
645 //__________________________________________________________________________________________________
647  double valshift,
648  double valrot) {
649  unsigned int nAlignables = alivec.size();
650 
651  for (unsigned int i = 0; i < nAlignables; ++i) {
652  Alignable* ali = alivec[i];
653 
654  // First reset APE
655  AlignmentPositionError nulApe(0, 0, 0);
656  ali->setAlignmentPositionError(nulApe, true);
657 
658  // Set APE from displacement
659  AlignmentPositionError ape(valshift, valshift, valshift);
660  if (valshift > 0.)
661  ali->addAlignmentPositionError(ape, true);
662  else
663  ali->setAlignmentPositionError(ape, true);
664  // GF: Resetting and setting as above does not really make sense to me,
665  // and adding to zero or setting is the same! I'd just do
666  //ali->setAlignmentPositionError(AlignmentPositionError ape(valshift,valshift,valshift),true);
667 
668  // Set APE from rotation
670  r(1) = valrot;
671  r(2) = valrot;
672  r(3) = valrot;
674  }
675 
676  LogDebug("StoreAPE") << "Store APE from shift: " << valshift << "\nStore APE from rotation: " << valrot;
677 }
678 
679 //__________________________________________________________________________________________________
681  const align::Alignables& aliComps,
682  std::vector<std::vector<ParameterId> >& paramIdsVecOut,
683  std::vector<std::vector<double> >& factorsVecOut,
684  bool all,
685  double epsilon) const {
686  // Weak point if all = false:
687  // Ignores constraints between non-subsequent levels in case the parameter is not considered in
688  // the intermediate level, e.g. global z for dets and layers is aligned, but not for rods!
689  if (!ali || !ali->alignmentParameters())
690  return false;
691 
692  const std::vector<bool>& aliSel = ali->alignmentParameters()->selector();
693  paramIdsVecOut.clear();
694  factorsVecOut.clear();
695 
696  bool firstComp = true;
697  for (align::Alignables::const_iterator iComp = aliComps.begin(), iCompE = aliComps.end(); iComp != iCompE; ++iComp) {
698  const ParametersToParametersDerivatives p2pDerivs(**iComp, *ali);
699  if (!p2pDerivs.isOK()) {
700  // std::cerr << (*iComp)->alignmentParameters()->type() << " "
701  // << ali->alignmentParameters()->type() << std::endl;
702  throw cms::Exception("BadConfig") << "AlignmentParameterStore::hierarchyConstraints"
703  << " Bad match of types of AlignmentParameters classes.\n";
704  return false;
705  }
706  const std::vector<bool>& aliCompSel = (*iComp)->alignmentParameters()->selector();
707  for (unsigned int iParMast = 0, iParMastUsed = 0; iParMast < aliSel.size(); ++iParMast) {
708  if (!all && !aliSel[iParMast])
709  continue; // no higher level parameter & constraint deselected
710  if (firstComp) { // fill output with empty arrays
711  paramIdsVecOut.push_back(std::vector<ParameterId>());
712  factorsVecOut.push_back(std::vector<double>());
713  }
714  for (unsigned int iParComp = 0; iParComp < aliCompSel.size(); ++iParComp) {
715  if (aliCompSel[iParComp]) {
716  double factor = 0.;
718  // hierachy constraints
719  factor = p2pDerivs(iParMast, iParComp);
721  // CHK poor mans averaging constraints
722  factor = p2pDerivs(iParMast, iParComp);
723  if (iParMast < 3 && (iParComp % 9) >= 3)
724  factor = 0.;
725  }
726  if (fabs(factor) > epsilon) {
727  paramIdsVecOut[iParMastUsed].push_back(ParameterId(*iComp, iParComp));
728  factorsVecOut[iParMastUsed].push_back(factor);
729  }
730  }
731  }
732  ++iParMastUsed;
733  }
734  firstComp = false;
735  } // end loop on components
736 
737  return true;
738 }
Vector3DBase
Definition: Vector3DBase.h:8
align::toAngles
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
Definition: Utilities.cc:8
TkRotation< Scalar >
AlignmentParameterStore::hierarchyConstraints
bool hierarchyConstraints(const Alignable *aliMaster, const align::Alignables &aliComps, std::vector< std::vector< ParameterId > > &paramIdsVecOut, std::vector< std::vector< double > > &factorsVecOut, bool all, double epsilon) const
Definition: AlignmentParameterStore.cc:680
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
Alignable::setAlignmentParameters
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:123
AlignmentUserVariables
(Abstract) Base class for alignment algorithm user variables
Definition: AlignmentUserVariables.h:6
AlignmentParameterStore::alignables
const align::Alignables & alignables(void) const
get all alignables
Definition: AlignmentParameterStore.h:47
AlignmentParameterStore::resetParameters
void resetParameters(void)
reset parameters, correlations, user variables
Definition: AlignmentParameterStore.cc:271
AlignmentParameterStore::selectParameters
CompositeAlignmentParameters selectParameters(const std::vector< AlignableDet * > &alignabledets) const
Definition: AlignmentParameterStore.cc:65
Alignable::setAlignmentPositionError
virtual void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown)=0
Set the alignment position error - if (!propagateDown) do not affect daughters.
Alignable::rotateInGlobalFrame
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
TrackerTopology
Definition: TrackerTopology.h:16
align::RunNumber
cond::RealTimeType< cond::runnumber >::type RunNumber
Definition: Utilities.h:37
Alignable
Definition: Alignable.h:27
AlignmentParameterStore::updateParameters
void updateParameters(const CompositeAlignmentParameters &aap, bool updateCorrelations=true)
update parameters
Definition: AlignmentParameterStore.cc:199
CompositeAlignmentParameters
Definition: CompositeAlignmentParameters.h:27
AlignmentParameterStore::attachUserVariables
void attachUserVariables(const align::Alignables &alivec, const std::vector< AlignmentUserVariables * > &uvarvec, int &ierr)
Attach User Variables to given alignables.
Definition: AlignmentParameterStore.cc:629
edm::LogInfo
Definition: MessageLogger.h:254
Alignable::surfaceDeformationIdPairs
virtual int surfaceDeformationIdPairs(std::vector< std::pair< int, SurfaceDeformation * > > &) const =0
AlignmentParameterStore::restoreCachedTransformations
void restoreCachedTransformations(void)
restore the previously cached position, rotation and other parameters
Definition: AlignmentParameterStore.cc:316
RigidBodyAlignmentParameters::clone
RigidBodyAlignmentParameters * clone(const AlgebraicVector &parameters, const AlgebraicSymMatrix &covMatrix) const override
Clone all parameters (for update of parameters)
Definition: RigidBodyAlignmentParameters.cc:48
AlignmentParameterStore::setAlignmentPositionError
void setAlignmentPositionError(const align::Alignables &alivec, double valshift, double valrot)
Set Alignment position error.
Definition: AlignmentParameterStore.cc:646
ReferenceCountingPointer
Definition: ReferenceCounted.h:60
AlignmentParameterStore::attachCorrelations
void attachCorrelations(const align::Alignables &alivec, const Correlations &cormap, bool overwrite, int &ierr)
Attach correlations to given alignables.
Definition: AlignmentParameterStore.cc:598
AlignmentParameters::apply
virtual void apply()=0
apply parameters to alignable
TkRotation::multiplyInverse
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
Definition: extTkRotation.h:178
AlignableSurface::toLocal
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
Definition: AlignableSurface.cc:35
CompositeAlignmentParameters::components
Components components() const
Get vector of alignable components.
Definition: CompositeAlignmentParameters.cc:71
AlignmentParameterStore::applyAlignableAbsolutePositions
void applyAlignableAbsolutePositions(const align::Alignables &alis, const AlignablePositions &newpos, int &ierr)
apply absolute positions to alignables
Definition: AlignmentParameterStore.cc:373
SurfaceDeformation::type
virtual int type() const =0
specific type, i.e. SurfaceDeformationFactory::Type
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
AlignmentCorrelationsStore::setCorrelations
virtual void setCorrelations(Alignable *ap1, Alignable *ap2, const AlgebraicSymMatrix &cov, int row, int col)
Definition: AlignmentCorrelationsStore.cc:51
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
AlignableDetOrUnitPtr
Definition: AlignableDetOrUnitPtr.h:30
ParametersToParametersDerivatives.h
AlignableShifts
std::vector< AlignableRelData > AlignableShifts
Definition: AlignableData.h:48
SurfaceDeformation
Definition: SurfaceDeformation.h:18
RigidBodyAlignmentParameters.h
python.cmstools.all
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:26
AlignmentParameters
Definition: AlignmentParameters.h:35
AlignmentParameterStore::ParameterId
std::pair< Alignable *, unsigned int > ParameterId
a single alignable parameter of an Alignable
Definition: AlignmentParameterStore.h:128
geometryDiff.epsilon
int epsilon
Definition: geometryDiff.py:26
AlignmentParameterStore::~AlignmentParameterStore
virtual ~AlignmentParameterStore()
destructor
Definition: AlignmentParameterStore.cc:62
parameters
parameters
Definition: BeamSpot_PayloadInspector.cc:14
AlignmentParameterStore::applyAlignableRelativePositions
void applyAlignableRelativePositions(const align::Alignables &alivec, const AlignableShifts &shifts, int &ierr)
apply relative shifts to alignables
Definition: AlignmentParameterStore.cc:470
config
Definition: config.py:1
AlignmentParameterStore::validAlignables
align::Alignables validAlignables(void) const
get all alignables with valid parameters
Definition: AlignmentParameterStore.cc:230
ParametersToParametersDerivatives::isOK
bool isOK() const
Indicate whether able to provide the derivatives.
Definition: ParametersToParametersDerivatives.h:48
AlignmentExtendedCorrelationsStore
Definition: AlignmentExtendedCorrelationsStore.h:19
Basic3DVector::y
T y() const
Cartesian y coordinate.
Definition: extBasic3DVector.h:97
AlgebraicVector
CLHEP::HepVector AlgebraicVector
Definition: AlgebraicObjects.h:13
SurfaceDeformation::parameters
virtual std::vector< double > parameters() const =0
parameters - interpretation left to the concrete implementation
AlignmentParameterStore::applyParameters
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
Definition: AlignmentParameterStore.cc:255
Alignable::alignableObjectId
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
AlignmentParameterStore::typeAndLayer
std::pair< int, int > typeAndLayer(const Alignable *ali, const TrackerTopology *tTopo) const
Obtain type and layer from Alignable.
Definition: AlignmentParameterStore.cc:368
Alignable::addAlignmentPositionError
virtual void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown)=0
DQMScaleToClient_cfi.factor
factor
Definition: DQMScaleToClient_cfi.py:8
align::rectify
void rectify(RotationType &)
Correct a rotation matrix for rounding errors.
Definition: Utilities.cc:185
AlignmentParameters::selectedCovariance
AlgebraicSymMatrix selectedCovariance(void) const
Get covariance matrix of selected parameters.
Definition: AlignmentParameters.cc:59
Alignable::surface
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
AlignmentCorrelationsStore::correlations
virtual void correlations(Alignable *ap1, Alignable *ap2, AlgebraicSymMatrix &cov, int row, int col) const
Definition: AlignmentCorrelationsStore.cc:12
Point3DBase< Scalar, GlobalTag >
Alignable::displacement
const GlobalVector & displacement() const
Return change of the global position since the creation of the object.
Definition: Alignable.h:141
AlignmentParameterStore.h
TrackerAlignableId::typeAndLayerFromDetId
std::pair< int, int > typeAndLayerFromDetId(const DetId &detId, const TrackerTopology *tTopo) const
Definition: TrackerAlignableId.cc:17
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
align::StructureType
StructureType
Definition: StructureType.h:16
Alignable::addAlignmentPositionErrorFromRotation
virtual void addAlignmentPositionErrorFromRotation(const RotationType &rotation, bool propagateDown)=0
SurfaceDeformation.h
edm::LogWarning
Definition: MessageLogger.h:141
ParametersToParametersDerivatives
Definition: ParametersToParametersDerivatives.h:43
AlignmentParameterStore::APPROX_AVERAGING_CONSTRAINTS
Definition: AlignmentParameterStore.h:156
AlignmentParameterStore::Correlations
std::map< std::pair< Alignable *, Alignable * >, AlgebraicMatrix > Correlations
Definition: AlignmentParameterStore.h:26
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
Alignable::rotation
const RotationType & rotation() const
Return change of orientation since the creation of the object.
Definition: Alignable.h:144
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
align::ID
uint32_t ID
Definition: Definitions.h:24
AlignableDetOrUnitPtr.h
AlignmentCorrelationsStore
Definition: AlignmentCorrelationsStore.h:16
SurfaceDeformationFactory::Type
Type
Definition: SurfaceDeformationFactory.h:17
RigidBodyAlignmentParameters
Definition: RigidBodyAlignmentParameters.h:21
AlignmentParameterStore::Parameters
std::vector< AlignmentParameters * > Parameters
Definition: AlignmentParameterStore.h:25
Alignable::id
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
Definition: Alignable.h:180
AlignmentCorrelationsStore::correlationsAvailable
virtual bool correlationsAvailable(Alignable *ap1, Alignable *ap2) const
Check whether correlations are stored for a given pair of alignables.
Definition: AlignmentCorrelationsStore.cc:100
runTauDisplay.dtype
dtype
Definition: runTauDisplay.py:121
AlignmentParameterStore::AlignmentParameterStore
AlignmentParameterStore(const align::Alignables &alis, const edm::ParameterSet &config)
constructor
Definition: AlignmentParameterStore.cc:29
AlignmentParameterStore::acquireRelativeParameters
void acquireRelativeParameters(void)
Definition: AlignmentParameterStore.cc:329
AlignmentParameterStore::HIERARCHY_CONSTRAINTS
Definition: AlignmentParameterStore.h:156
AlgebraicSymMatrix
CLHEP::HepSymMatrix AlgebraicSymMatrix
Definition: AlgebraicObjects.h:15
AlignmentParameterStore::theAlignables
align::Alignables theAlignables
alignables
Definition: AlignmentParameterStore.h:161
AlignmentParameterStore::cacheTransformations
void cacheTransformations(void)
cache the current position, rotation and other parameters
Definition: AlignmentParameterStore.cc:303
AlignmentParameterStore::alignableFromAlignableDet
Alignable * alignableFromAlignableDet(const AlignableDetOrUnitPtr &alignableDet) const
Obsolete: Use AlignableNavigator::alignableDetFromGeomDet and alignableFromAlignableDet.
Definition: AlignmentParameterStore.cc:242
AlignmentParameters::selectedParameters
AlgebraicVector selectedParameters(void) const
Get selected parameters.
Definition: AlignmentParameters.cc:54
align::EulerAngles
AlgebraicVector EulerAngles
Definition: Definitions.h:34
SurfaceDeformationFactory::surfaceDeformationTypeName
std::string surfaceDeformationTypeName(const Type &type)
Definition: SurfaceDeformationFactory.cc:26
Alignable::move
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
alignCSCRings.r
r
Definition: alignCSCRings.py:93
AlignmentParametersData
Definition: AlignmentParametersData.h:7
SurfaceDeformationFactory.h
align::Alignables
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
TrackerAlignableId
Definition: TrackerAlignableId.h:22
AlgebraicMatrix
CLHEP::HepMatrix AlgebraicMatrix
Definition: AlgebraicObjects.h:14
writedatasetfile.run
run
Definition: writedatasetfile.py:27
AlignmentParameterStore::theTypeOfConstraints
TypeOfConstraints theTypeOfConstraints
type of constraints
Definition: AlignmentParameterStore.h:164
AlignmentParameters::setValid
void setValid(bool v)
Set validity flag.
Definition: AlignmentParameters.cc:137
AlignmentParameterStore::NONE
Definition: AlignmentParameterStore.h:156
AlignmentParameters::cloneFromSelected
virtual AlignmentParameters * cloneFromSelected(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const =0
Exception
Definition: hltDiff.cc:246
CompositeAlignmentParameters::parameters
const AlgebraicVector & parameters() const
Get alignment parameters.
Definition: CompositeAlignmentParameters.h:59
AlignmentParameters::numSelected
int numSelected(void) const
Get number of selected parameters.
Definition: AlignmentParameters.cc:51
AlignmentPositionError.h
Alignable.h
AlignmentParameters::size
int size(void) const
Get number of parameters.
Definition: AlignmentParameters.cc:131
AlignmentParameterStore::theCorrelationsStore
AlignmentCorrelationsStore * theCorrelationsStore
Definition: AlignmentParameterStore.h:153
Exception.h
align::toMatrix
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
Definition: Utilities.cc:34
AlignmentParameters::alignable
Alignable * alignable(void) const
Get pointer to corresponding alignable.
Definition: AlignmentParameters.cc:104
AlignmentParameters::selector
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
Definition: AlignmentParameters.cc:48
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
SurfaceDeformationFactory::kNoDeformations
Definition: SurfaceDeformationFactory.h:21
TkRotation::x
Basic3DVector< T > x() const
Definition: extTkRotation.h:247
mps_fire.result
result
Definition: mps_fire.py:303
ParameterSet.h
TkRotation::rot
Rot3< T > rot
Definition: extTkRotation.h:263
Alignable::globalPosition
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
AlignablePositions
std::vector< AlignableAbsData > AlignablePositions
Definition: AlignableData.h:47
AlignmentPositionError
Definition: AlignmentPositionError.h:10
Alignable::alignmentParameters
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
CompositeAlignmentParameters::covariance
const AlgebraicSymMatrix & covariance() const
Get parameter covariance matrix.
Definition: CompositeAlignmentParameters.h:62
Alignable::addSurfaceDeformation
virtual void addSurfaceDeformation(const SurfaceDeformation *deformation, bool propagateDown)=0
AlignmentParameterStore::attachAlignmentParameters
void attachAlignmentParameters(const align::Alignables &alivec, const Parameters &parvec, int &ierr)
Attach alignment parameters to given alignables.
Definition: AlignmentParameterStore.cc:556
Alignable::globalRotation
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138
AlignmentCorrelationsStore::resetCorrelations
virtual void resetCorrelations(void)
Reset correlations.
Definition: AlignmentCorrelationsStore.cc:114
AlignmentParameters::setUserVariables
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
Definition: AlignmentParameters.cc:94
SurfaceDeformationFactory::create
SurfaceDeformation * create(int type, const std::vector< double > &params)
Definition: SurfaceDeformationFactory.cc:40
AlignmentExtendedCorrelationsStore.h
Alignable::mother
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:91
TrackerAlignableId.h