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