ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/CMSSW/Alignment/CommonAlignmentAlgorithm/src/AlignmentParameterStore.cc
Revision: 1.32
Committed: Mon Jan 7 20:56:26 2013 UTC (12 years, 3 months ago) by wmtan
Content type: text/plain
Branch: MAIN
CVS Tags: CMSSW_6_2_0, CMSSW_6_2_0_pre7_TS133806, CMSSW_6_2_0_pre8, V04-00-14, V04-00-13, CMSSW_6_2_0_pre7_TS132947, CMSSW_6_2_0_pre7_g496p02, CMSSW_6_2_0_pre7, V04-00-12, CMSSW_6_2_0_pre6_patch1, CMSSW_6_2_0_pre6, CMSSW_6_2_0_pre5slc6, CMSSW_6_2_0_pre5, CMSSW_6_2_0_pre4, CMSSW_6_2_0_pre3, CMSSW_6_2_0_pre2, CMSSW_6_2_0_pre1, V04-00-11, HEAD
Changes since 1.31: +5 -5 lines
Log Message:
Get geometry from the EventSetup system, rather than having it hard coded in the data formats

File Contents

# Content
1 /**
2 * \file AlignmentParameterStore.cc
3 *
4 * $Revision: 1.31 $
5 * $Date: 2011/05/23 20:50:32 $
6 * (last update by $Author: mussgill $)
7 */
8
9 // This class's header should be first
10 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterStore.h"
11
12 #include "FWCore/MessageLogger/interface/MessageLogger.h"
13 #include "FWCore/Utilities/interface/Exception.h"
14 #include "FWCore/ParameterSet/interface/ParameterSet.h"
15
16 #include "Alignment/CommonAlignment/interface/Alignable.h"
17 #include "Alignment/CommonAlignment/interface/AlignableDetOrUnitPtr.h"
18 #include "Alignment/TrackerAlignment/interface/TrackerAlignableId.h"
19
20 #include "Alignment/CommonAlignmentParametrization/interface/RigidBodyAlignmentParameters.h"
21 #include "Alignment/CommonAlignmentParametrization/interface/ParametersToParametersDerivatives.h"
22 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentExtendedCorrelationsStore.h"
23 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
24
25 //__________________________________________________________________________________________________
26 AlignmentParameterStore::AlignmentParameterStore( const align::Alignables &alis,
27 const edm::ParameterSet& config ) :
28 theAlignables(alis)
29 {
30 if (config.getUntrackedParameter<bool>("UseExtendedCorrelations")) {
31 theCorrelationsStore = new AlignmentExtendedCorrelationsStore
32 (config.getParameter<edm::ParameterSet>("ExtendedCorrelationsConfig"));
33 } else {
34 theCorrelationsStore = new AlignmentCorrelationsStore();
35 }
36
37 edm::LogInfo("Alignment") << "@SUB=AlignmentParameterStore"
38 << "Created with " << theAlignables.size() << " alignables.";
39 }
40
41 //__________________________________________________________________________________________________
42 AlignmentParameterStore::~AlignmentParameterStore()
43 {
44 delete theCorrelationsStore;
45 }
46
47 //__________________________________________________________________________________________________
48 CompositeAlignmentParameters
49 AlignmentParameterStore::selectParameters( const std::vector<AlignableDet*>& alignabledets ) const
50 {
51 std::vector<AlignableDetOrUnitPtr> detOrUnits;
52 detOrUnits.reserve(alignabledets.size());
53
54 std::vector<AlignableDet*>::const_iterator it, iEnd;
55 for ( it = alignabledets.begin(), iEnd = alignabledets.end(); it != iEnd; ++it)
56 detOrUnits.push_back(AlignableDetOrUnitPtr(*it));
57
58 return this->selectParameters(detOrUnits);
59 }
60
61 //__________________________________________________________________________________________________
62 CompositeAlignmentParameters
63 AlignmentParameterStore::selectParameters( const std::vector<AlignableDetOrUnitPtr>& alignabledets ) const
64 {
65
66 align::Alignables alignables;
67 std::map <AlignableDetOrUnitPtr,Alignable*> alidettoalimap;
68 std::map <Alignable*,int> aliposmap;
69 std::map <Alignable*,int> alilenmap;
70 int nparam=0;
71
72 // iterate over AlignableDet's
73 for( std::vector<AlignableDetOrUnitPtr>::const_iterator iad = alignabledets.begin();
74 iad != alignabledets.end(); ++iad )
75 {
76 Alignable* ali = alignableFromAlignableDet( *iad );
77 if ( ali )
78 {
79 alidettoalimap[ *iad ] = ali; // Add to map
80 // Check if Alignable already there, insert into vector if not
81 if ( find(alignables.begin(),alignables.end(),ali) == alignables.end() )
82 {
83 alignables.push_back(ali);
84 AlignmentParameters* ap = ali->alignmentParameters();
85 nparam += ap->numSelected();
86 }
87 }
88 }
89
90 AlgebraicVector* selpar = new AlgebraicVector( nparam, 0 );
91 AlgebraicSymMatrix* selcov = new AlgebraicSymMatrix( nparam, 0 );
92
93 // Fill in parameters and corresponding covariance matricess
94 int ipos = 1; // NOTE: .sub indices start from 1
95 align::Alignables::const_iterator it1;
96 for( it1 = alignables.begin(); it1 != alignables.end(); ++it1 )
97 {
98 AlignmentParameters* ap = (*it1)->alignmentParameters();
99 selpar->sub( ipos, ap->selectedParameters() );
100 selcov->sub( ipos, ap->selectedCovariance() );
101 int npar = ap->numSelected();
102 aliposmap[*it1]=ipos;
103 alilenmap[*it1]=npar;
104 ipos +=npar;
105 }
106
107 // Fill in the correlations. Has to be an extra loop, because the
108 // AlignmentExtendedCorrelationsStore (if used) needs the
109 // alignables' covariance matrices already present.
110 ipos = 1;
111 for( it1 = alignables.begin(); it1 != alignables.end(); ++it1 )
112 {
113 int jpos=1;
114
115 // Look for correlations between alignables
116 align::Alignables::const_iterator it2;
117 for( it2 = alignables.begin(); it2 != it1; ++it2 )
118 {
119 theCorrelationsStore->correlations( *it1, *it2, *selcov, ipos-1, jpos-1 );
120 jpos += (*it2)->alignmentParameters()->numSelected();
121 }
122
123 ipos += (*it1)->alignmentParameters()->numSelected();
124 }
125
126 AlignmentParametersData::DataContainer data( new AlignmentParametersData( selpar, selcov ) );
127 CompositeAlignmentParameters aap( data, alignables, alidettoalimap, aliposmap, alilenmap );
128
129 return aap;
130 }
131
132
133 //__________________________________________________________________________________________________
134 CompositeAlignmentParameters
135 AlignmentParameterStore::selectParameters( const align::Alignables& alignables ) const
136 {
137
138 align::Alignables selectedAlignables;
139 std::map <AlignableDetOrUnitPtr,Alignable*> alidettoalimap; // This map won't be filled!!!
140 std::map <Alignable*,int> aliposmap;
141 std::map <Alignable*,int> alilenmap;
142 int nparam=0;
143
144 // iterate over Alignable's
145 align::Alignables::const_iterator ita;
146 for ( ita = alignables.begin(); ita != alignables.end(); ++ita )
147 {
148 // Check if Alignable already there, insert into vector if not
149 if ( find(selectedAlignables.begin(), selectedAlignables.end(), *ita) == selectedAlignables.end() )
150 {
151 selectedAlignables.push_back( *ita );
152 AlignmentParameters* ap = (*ita)->alignmentParameters();
153 nparam += ap->numSelected();
154 }
155 }
156
157 AlgebraicVector* selpar = new AlgebraicVector( nparam, 0 );
158 AlgebraicSymMatrix* selcov = new AlgebraicSymMatrix( nparam, 0 );
159
160 // Fill in parameters and corresponding covariance matrices
161 int ipos = 1; // NOTE: .sub indices start from 1
162 align::Alignables::const_iterator it1;
163 for( it1 = selectedAlignables.begin(); it1 != selectedAlignables.end(); ++it1 )
164 {
165 AlignmentParameters* ap = (*it1)->alignmentParameters();
166 selpar->sub( ipos, ap->selectedParameters() );
167 selcov->sub( ipos, ap->selectedCovariance() );
168 int npar = ap->numSelected();
169 aliposmap[*it1]=ipos;
170 alilenmap[*it1]=npar;
171 ipos +=npar;
172 }
173
174 // Fill in the correlations. Has to be an extra loop, because the
175 // AlignmentExtendedCorrelationsStore (if used) needs the
176 // alignables' covariance matrices already present.
177 ipos = 1;
178 for( it1 = selectedAlignables.begin(); it1 != selectedAlignables.end(); ++it1 )
179 {
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 {
186 theCorrelationsStore->correlations( *it1, *it2, *selcov, ipos-1, jpos-1 );
187 jpos += (*it2)->alignmentParameters()->numSelected();
188 }
189
190 ipos += (*it1)->alignmentParameters()->numSelected();
191 }
192
193 AlignmentParametersData::DataContainer data( new AlignmentParametersData( selpar, selcov ) );
194 CompositeAlignmentParameters aap( data, selectedAlignables, alidettoalimap, aliposmap, alilenmap );
195
196 return aap;
197 }
198
199
200 //__________________________________________________________________________________________________
201 void AlignmentParameterStore::updateParameters( const CompositeAlignmentParameters& aap, bool updateCorrelations )
202 {
203
204 align::Alignables alignables = aap.components();
205 const AlgebraicVector& parameters = aap.parameters();
206 const AlgebraicSymMatrix& covariance = aap.covariance();
207
208 int ipos = 1; // NOTE: .sub indices start from 1
209
210 // Loop over alignables
211 for( align::Alignables::const_iterator it=alignables.begin(); it != alignables.end(); ++it )
212 {
213 // Update parameters and local covariance
214 AlignmentParameters* ap = (*it)->alignmentParameters();
215 int nsel = ap->numSelected();
216 AlgebraicVector subvec = parameters.sub( ipos, ipos+nsel-1 );
217 AlgebraicSymMatrix subcov = covariance.sub( ipos, ipos+nsel-1 );
218 AlignmentParameters* apnew = ap->cloneFromSelected( subvec, subcov );
219 (*it)->setAlignmentParameters( apnew );
220
221 // Now update correlations between detectors
222 if ( updateCorrelations )
223 {
224 int jpos = 1;
225 for( align::Alignables::const_iterator it2 = alignables.begin(); it2 != it; ++it2 )
226 {
227 theCorrelationsStore->setCorrelations( *it, *it2, covariance, ipos-1, jpos-1 );
228 jpos += (*it2)->alignmentParameters()->numSelected();
229 }
230 }
231
232 ipos+=nsel;
233 }
234
235 }
236
237
238 //__________________________________________________________________________________________________
239 align::Alignables AlignmentParameterStore::validAlignables(void) const
240 {
241 align::Alignables result;
242 for (align::Alignables::const_iterator iali = theAlignables.begin();
243 iali != theAlignables.end(); ++iali)
244 if ( (*iali)->alignmentParameters()->isValid() ) result.push_back(*iali);
245
246 LogDebug("Alignment") << "@SUB=AlignmentParameterStore::validAlignables"
247 << "Valid alignables: " << result.size()
248 << "out of " << theAlignables.size();
249 return result;
250 }
251
252 //__________________________________________________________________________________________________
253 Alignable* AlignmentParameterStore::alignableFromAlignableDet( AlignableDetOrUnitPtr alignableDet ) const
254 {
255 Alignable *mother = alignableDet;
256 while (mother) {
257 if (mother->alignmentParameters()) return mother;
258 mother = mother->mother();
259 }
260
261 return 0;
262 }
263
264 //__________________________________________________________________________________________________
265 void AlignmentParameterStore::applyParameters(void)
266 {
267 align::Alignables::const_iterator iali;
268 for ( iali = theAlignables.begin(); iali != theAlignables.end(); ++iali)
269 applyParameters( *iali );
270 }
271
272
273 //__________________________________________________________________________________________________
274 void AlignmentParameterStore::applyParameters(Alignable* alignable)
275 {
276
277 AlignmentParameters *pars = (alignable ? alignable->alignmentParameters() : 0);
278 if (!pars) {
279 throw cms::Exception("BadAlignable")
280 << "applyParameters: provided alignable does not have alignment parameters";
281 }
282 pars->apply();
283 }
284
285
286 //__________________________________________________________________________________________________
287 void AlignmentParameterStore::resetParameters(void)
288 {
289 // Erase contents of correlation map
290 theCorrelationsStore->resetCorrelations();
291
292 // Iterate over alignables in the store and reset parameters
293 align::Alignables::const_iterator iali;
294 for ( iali = theAlignables.begin(); iali != theAlignables.end(); ++iali )
295 resetParameters( *iali );
296 }
297
298
299 //__________________________________________________________________________________________________
300 void AlignmentParameterStore::resetParameters( Alignable* ali )
301 {
302 if ( ali )
303 {
304 // Get alignment parameters for this alignable
305 AlignmentParameters* ap = ali->alignmentParameters();
306 if ( ap )
307 {
308 int npar=ap->numSelected();
309
310 AlgebraicVector par(npar,0);
311 AlgebraicSymMatrix cov(npar,0);
312 AlignmentParameters* apnew = ap->cloneFromSelected(par,cov);
313 ali->setAlignmentParameters(apnew);
314 apnew->setValid(false);
315 }
316 else
317 edm::LogError("BadArgument") << "@SUB=AlignmentParameterStore::resetParameters"
318 << "alignable has no alignment parameter";
319 }
320 else
321 edm::LogError("BadArgument") << "@SUB=AlignmentParameterStore::resetParameters"
322 << "argument is NULL";
323 }
324
325
326 //__________________________________________________________________________________________________
327 void AlignmentParameterStore::cacheTransformations(void)
328 {
329 align::Alignables::const_iterator iali;
330 for ( iali = theAlignables.begin(); iali != theAlignables.end(); ++iali)
331 (*iali)->cacheTransformation();
332 }
333
334
335 //__________________________________________________________________________________________________
336 void AlignmentParameterStore::restoreCachedTransformations(void)
337 {
338 align::Alignables::const_iterator iali;
339 for ( iali = theAlignables.begin(); iali != theAlignables.end(); ++iali)
340 (*iali)->restoreCachedTransformation();
341 }
342
343 //__________________________________________________________________________________________________
344 void AlignmentParameterStore::acquireRelativeParameters(void)
345 {
346
347 unsigned int nAlignables = theAlignables.size();
348
349 for (unsigned int i = 0; i < nAlignables; ++i)
350 {
351 Alignable* ali = theAlignables[i];
352
353 RigidBodyAlignmentParameters* ap =
354 dynamic_cast<RigidBodyAlignmentParameters*>( ali->alignmentParameters() );
355
356 if ( !ap )
357 throw cms::Exception("BadAlignable")
358 << "acquireRelativeParameters: "
359 << "provided alignable does not have rigid body alignment parameters";
360
361 AlgebraicVector par( ap->size(),0 );
362 AlgebraicSymMatrix cov( ap->size(), 0 );
363
364 // Get displacement and transform global->local
365 align::LocalVector dloc = ali->surface().toLocal( ali->displacement() );
366 par[0]=dloc.x();
367 par[1]=dloc.y();
368 par[2]=dloc.z();
369
370 // Transform to local euler angles
371 align::EulerAngles euloc = align::toAngles( ali->surface().toLocal( ali->rotation() ) );
372 par[3]=euloc(1);
373 par[4]=euloc(2);
374 par[5]=euloc(3);
375
376 // Clone parameters
377 RigidBodyAlignmentParameters* apnew = ap->clone(par,cov);
378
379 ali->setAlignmentParameters(apnew);
380 }
381 }
382
383
384 //__________________________________________________________________________________________________
385 // Get type/layer from Alignable
386 // type: -6 -5 -4 -3 -2 -1 1 2 3 4 5 6
387 // TEC- TOB- TID- TIB- PxEC- PxBR- PxBr+ PxEC+ TIB+ TID+ TOB+ TEC+
388 // Layers start from zero
389 std::pair<int,int> AlignmentParameterStore::typeAndLayer(const Alignable* ali, const TrackerTopology* tTopo) const
390 {
391 return TrackerAlignableId().typeAndLayerFromDetId( ali->id(), tTopo );
392 }
393
394
395 //__________________________________________________________________________________________________
396 void AlignmentParameterStore::
397 applyAlignableAbsolutePositions( const align::Alignables& alivec,
398 const AlignablePositions& newpos,
399 int& ierr )
400 {
401 unsigned int nappl=0;
402 ierr=0;
403
404 // Iterate over list of alignables
405 for (align::Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali) {
406 Alignable* ali = *iali;
407 align::ID id = ali->id();
408 align::StructureType typeId = ali->alignableObjectId();
409
410 // Find corresponding entry in AlignablePositions
411 bool found=false;
412 for (AlignablePositions::const_iterator ipos = newpos.begin(); ipos != newpos.end(); ++ipos) {
413 if (id == ipos->id() && typeId == ipos->objId()) {
414 if (found) {
415 edm::LogError("DuplicatePosition")
416 << "New positions for alignable found more than once!";
417 } else {
418 // New position/rotation
419 const align::PositionType& pnew = ipos->pos();
420 const align::RotationType& rnew = ipos->rot();
421 // Current position / rotation
422 const align::PositionType& pold = ali->globalPosition();
423 const align::RotationType& rold = ali->globalRotation();
424
425 // shift needed to move from current to new position
426 align::GlobalVector posDiff = pnew - pold;
427 align::RotationType rotDiff = rold.multiplyInverse(rnew);
428 align::rectify(rotDiff); // correct for rounding errors
429 ali->move( posDiff );
430 ali->rotateInGlobalFrame( rotDiff );
431 LogDebug("NewPosition") << "moving by:" << posDiff;
432 LogDebug("NewRotation") << "rotating by:\n" << rotDiff;
433
434 // add position error
435 // AlignmentPositionError ape(shift.x(),shift.y(),shift.z());
436 // (*iali)->addAlignmentPositionError(ape);
437 // (*iali)->addAlignmentPositionErrorFromRotation(rot);
438
439 found=true;
440 ++nappl;
441 }
442 }
443 }
444 }
445
446 if ( nappl< newpos.size() )
447 edm::LogError("Mismatch") << "Applied only " << nappl << " new positions"
448 << " out of " << newpos.size();
449
450 LogDebug("NewPositions") << "Applied new positions for " << nappl
451 << " out of " << alivec.size() <<" alignables.";
452
453 }
454
455
456 //__________________________________________________________________________________________________
457 void AlignmentParameterStore::
458 applyAlignableRelativePositions( const align::Alignables& alivec, const AlignableShifts& shifts, int& ierr )
459 {
460
461 ierr=0;
462 unsigned int nappl=0;
463 unsigned int nAlignables = alivec.size();
464
465 for (unsigned int i = 0; i < nAlignables; ++i) {
466 Alignable* ali = alivec[i];
467
468 align::ID id = ali->id();
469 align::StructureType typeId = ali->alignableObjectId();
470
471 // Find corresponding entry in AlignableShifts
472 bool found = false;
473 for (AlignableShifts::const_iterator ipos = shifts.begin(); ipos != shifts.end(); ++ipos) {
474 if (id == ipos->id() && typeId == ipos->objId()) {
475 if (found) {
476 edm::LogError("DuplicatePosition")
477 << "New positions for alignable found more than once!";
478 } else {
479 ali->move( ipos->pos() );
480 ali->rotateInGlobalFrame( ipos->rot() );
481
482 // Add position error
483 //AlignmentPositionError ape(pnew.x(),pnew.y(),pnew.z());
484 //ali->addAlignmentPositionError(ape);
485 //ali->addAlignmentPositionErrorFromRotation(rnew);
486
487 found=true;
488 ++nappl;
489 }
490 }
491 }
492 }
493
494 if ( nappl < shifts.size() )
495 edm::LogError("Mismatch") << "Applied only " << nappl << " new positions"
496 << " out of " << shifts.size();
497
498 LogDebug("NewPositions") << "Applied new positions for " << nappl << " alignables.";
499 }
500
501
502
503 //__________________________________________________________________________________________________
504 void AlignmentParameterStore::attachAlignmentParameters( const Parameters& parvec, int& ierr )
505 {
506 attachAlignmentParameters( theAlignables, parvec, ierr);
507 }
508
509
510
511 //__________________________________________________________________________________________________
512 void AlignmentParameterStore::attachAlignmentParameters( const align::Alignables& alivec,
513 const Parameters& parvec, int& ierr )
514 {
515 int ipass = 0;
516 int ifail = 0;
517 ierr = 0;
518
519 // Iterate over alignables
520 for ( align::Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali )
521 {
522 // Iterate over Parameters
523 bool found=false;
524 for ( Parameters::const_iterator ipar = parvec.begin(); ipar != parvec.end(); ++ipar)
525 {
526 // Get new alignment parameters
527 AlignmentParameters* ap = *ipar;
528
529 // Check if parameters belong to alignable
530 if ( ap->alignable() == (*iali) )
531 {
532 if (!found)
533 {
534 (*iali)->setAlignmentParameters(ap);
535 ++ipass;
536 found=true;
537 }
538 else edm::LogError("Alignment") << "@SUB=AlignmentParameterStore::attachAlignmentParameters"
539 << "More than one parameters for Alignable.";
540 }
541 }
542 if (!found) ++ifail;
543 }
544 if (ifail>0) ierr=-1;
545
546 LogDebug("attachAlignmentParameters") << " Parameters, Alignables: " << parvec.size() << ","
547 << alivec.size() << "\n pass,fail: " << ipass << ","<< ifail;
548 }
549
550
551 //__________________________________________________________________________________________________
552 void AlignmentParameterStore::attachCorrelations( const Correlations& cormap,
553 bool overwrite, int& ierr )
554 {
555 attachCorrelations( theAlignables, cormap, overwrite, ierr );
556 }
557
558
559 //__________________________________________________________________________________________________
560 void AlignmentParameterStore::attachCorrelations( const align::Alignables& alivec,
561 const Correlations& cormap,
562 bool overwrite, int& ierr )
563 {
564 ierr=0;
565 int icount=0;
566
567 // Iterate over correlations
568 for ( Correlations::const_iterator icor = cormap.begin(); icor!=cormap.end(); ++icor )
569 {
570 AlgebraicMatrix mat=(*icor).second;
571 Alignable* ali1 = (*icor).first.first;
572 Alignable* ali2 = (*icor).first.second;
573
574 // Check if alignables exist
575 if ( find( alivec.begin(), alivec.end(), ali1 ) != alivec.end() &&
576 find( alivec.begin(), alivec.end(), ali2 ) != alivec.end() )
577 {
578 // Check if correlations already existing between these alignables
579 if ( !theCorrelationsStore->correlationsAvailable(ali1,ali2) || (overwrite) )
580 {
581 theCorrelationsStore->setCorrelations(ali1,ali2,mat);
582 ++icount;
583 }
584 else edm::LogInfo("AlreadyExists") << "Correlation existing and not overwritten";
585 }
586 else edm::LogInfo("IgnoreCorrelation") << "Ignoring correlation with no alignables!";
587 }
588
589 LogDebug( "attachCorrelations" ) << " Alignables,Correlations: " << alivec.size() <<","<< cormap.size()
590 << "\n applied: " << icount ;
591
592 }
593
594
595 //__________________________________________________________________________________________________
596 void AlignmentParameterStore::
597 attachUserVariables( const align::Alignables& alivec,
598 const std::vector<AlignmentUserVariables*>& uvarvec, int& ierr )
599 {
600 ierr=0;
601
602 LogDebug("DumpArguments") << "size of alivec: " << alivec.size()
603 << "\nsize of uvarvec: " << uvarvec.size();
604
605 std::vector<AlignmentUserVariables*>::const_iterator iuvar=uvarvec.begin();
606
607 for ( align::Alignables::const_iterator iali=alivec.begin(); iali!=alivec.end(); ++iali, ++iuvar )
608 {
609 AlignmentParameters* ap = (*iali)->alignmentParameters();
610 AlignmentUserVariables* uvarnew = (*iuvar);
611 ap->setUserVariables(uvarnew);
612 }
613 }
614
615
616 //__________________________________________________________________________________________________
617 void AlignmentParameterStore::setAlignmentPositionError( const align::Alignables& alivec,
618 double valshift, double valrot )
619 {
620 unsigned int nAlignables = alivec.size();
621
622 for (unsigned int i = 0; i < nAlignables; ++i)
623 {
624 Alignable* ali = alivec[i];
625
626 // First reset APE
627 AlignmentPositionError nulApe(0,0,0);
628 ali->setAlignmentPositionError(nulApe, true);
629
630 // Set APE from displacement
631 AlignmentPositionError ape(valshift,valshift,valshift);
632 if ( valshift > 0. ) ali->addAlignmentPositionError(ape, true);
633 else ali->setAlignmentPositionError(ape, true);
634 // GF: Resetting and setting as above does not really make sense to me,
635 // and adding to zero or setting is the same! I'd just do
636 //ali->setAlignmentPositionError(AlignmentPositionError ape(valshift,valshift,valshift),true);
637
638 // Set APE from rotation
639 align::EulerAngles r(3);
640 r(1)=valrot; r(2)=valrot; r(3)=valrot;
641 ali->addAlignmentPositionErrorFromRotation(align::toMatrix(r), true);
642 }
643
644 LogDebug("StoreAPE") << "Store APE from shift: " << valshift
645 << "\nStore APE from rotation: " << valrot;
646 }
647
648 //__________________________________________________________________________________________________
649 bool AlignmentParameterStore
650 ::hierarchyConstraints(const Alignable *ali, const align::Alignables &aliComps,
651 std::vector<std::vector<ParameterId> > &paramIdsVecOut,
652 std::vector<std::vector<double> > &factorsVecOut,
653 bool all, double epsilon) const
654 {
655 // Weak point if all = false:
656 // Ignores constraints between non-subsequent levels in case the parameter is not considered in
657 // the intermediate level, e.g. global z for dets and layers is aligned, but not for rods!
658 if (!ali || !ali->alignmentParameters()) return false;
659
660 const std::vector<bool> &aliSel= ali->alignmentParameters()->selector();
661 paramIdsVecOut.clear();
662 factorsVecOut.clear();
663
664 bool firstComp = true;
665 for (align::Alignables::const_iterator iComp = aliComps.begin(), iCompE = aliComps.end();
666 iComp != iCompE; ++iComp) {
667
668 const ParametersToParametersDerivatives p2pDerivs(**iComp, *ali);
669 if (!p2pDerivs.isOK()) {
670 throw cms::Exception("BadConfig")
671 << "AlignmentParameterStore::hierarchyConstraints"
672 << " Bad match of types of AlignmentParameters classes.\n";
673 return false;
674 }
675 const std::vector<bool> &aliCompSel = (*iComp)->alignmentParameters()->selector();
676 for (unsigned int iParMast = 0, iParMastUsed = 0; iParMast < aliSel.size(); ++iParMast) {
677 if (!all && !aliSel[iParMast]) continue;// no higher level parameter & constraint deselected
678 if (firstComp) { // fill output with empty arrays
679 paramIdsVecOut.push_back(std::vector<ParameterId>());
680 factorsVecOut.push_back(std::vector<double>());
681 }
682 for (unsigned int iParComp = 0; iParComp < aliCompSel.size(); ++iParComp) {
683 if (aliCompSel[iParComp]) {
684 const double factor = p2pDerivs(iParMast, iParComp);
685 if (fabs(factor) > epsilon) {
686 paramIdsVecOut[iParMastUsed].push_back(ParameterId(*iComp, iParComp));
687 factorsVecOut[iParMastUsed].push_back(factor);
688 }
689 }
690 }
691 ++iParMastUsed;
692 }
693 firstComp = false;
694 } // end loop on components
695
696 return true;
697 }