ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/CMSSW/Alignment/CommonAlignmentAlgorithm/src/AlignmentParameterStore.cc
Revision: 1.6
Committed: Sat Dec 23 16:00:00 2006 UTC (18 years, 4 months ago) by ewidl
Content type: text/plain
Branch: MAIN
CVS Tags: CMSSW_1_3_0_pre3, CMSSW_1_3_0_SLC4_pre2, CMSSW_1_3_0_pre2, V01-01-01, V01-01-00, CMSSW_1_3_0_SLC4_pre1, CMSSW_1_3_0_pre1, V01-00-00
Changes since 1.5: +334 -411 lines
Log Message:
Changes due to modified internal correlations management; constructor takes now a ParameterSet for configuration.

File Contents

# User Rev Content
1 fronga 1.1 #include "FWCore/MessageLogger/interface/MessageLogger.h"
2     #include "FWCore/Utilities/interface/Exception.h"
3    
4     #include "Alignment/CommonAlignment/interface/AlignableDet.h"
5     #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
6     #include "Alignment/CommonAlignmentParametrization/interface/KarimakiAlignmentDerivatives.h"
7     #include "Alignment/CommonAlignmentParametrization/interface/AlignmentTransformations.h"
8    
9     #include <string>
10    
11     // This class's header
12     #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterStore.h"
13    
14    
15     //__________________________________________________________________________________________________
16 ewidl 1.6 AlignmentParameterStore::AlignmentParameterStore( std::vector<Alignable*> alivec,
17     const edm::ParameterSet& config ) :
18 fronga 1.1 theAlignables(alivec)
19     {
20 ewidl 1.6 bool useExtendedCorrelations =
21     config.getUntrackedParameter<bool>( "UseExtendedCorrelations", false );
22 fronga 1.1
23 ewidl 1.6 if ( !useExtendedCorrelations )
24     {
25     theCorrelationsStore = new AlignmentCorrelationsStore();
26     }
27     else
28     {
29     const edm::ParameterSet& extCorrConfig =
30     config.getParameter<edm::ParameterSet>( "ExtendedCorrelationsConfig" );
31     theCorrelationsStore = new AlignmentExtendedCorrelationsStore( extCorrConfig );
32     }
33 fronga 1.1
34     theTrackerAlignableId = new TrackerAlignableId;
35    
36     // Fill detId <-> Alignable map
37 ewidl 1.6 std::vector<Alignable*>::iterator it;
38     for ( it = alivec.begin(); it != alivec.end(); ++it )
39     {
40     DetIds tmpDetIds = findDetIds(*it);
41     for ( DetIds::iterator iDetId = tmpDetIds.begin(); iDetId != tmpDetIds.end(); ++iDetId )
42     theActiveAlignablesByDetId[ *iDetId ] = *it;
43     }
44 fronga 1.1
45 flucke 1.4 edm::LogInfo("Alignment") << "@SUB=AlignmentParameterStore::AlignmentParameterStore"
46     << "Created.";
47 fronga 1.1 }
48    
49     //__________________________________________________________________________________________________
50 ewidl 1.6 CompositeAlignmentParameters
51 fronga 1.1 AlignmentParameterStore::selectParameters( const std::vector<AlignableDet*>& alignabledets ) const
52     {
53    
54     std::vector<Alignable*> alignables;
55     std::map <AlignableDet*,Alignable*> alidettoalimap;
56     std::map <Alignable*,int> aliposmap;
57     std::map <Alignable*,int> alilenmap;
58     int nparam=0;
59    
60     // iterate over AlignableDet's
61 ewidl 1.6 std::vector<AlignableDet*>::const_iterator iad;
62     for( iad = alignabledets.begin(); iad != alignabledets.end(); ++iad )
63     {
64     unsigned int detId = (*iad)->geomDetId().rawId();
65     Alignable* ali = alignableFromDetId( detId );
66     if ( ali )
67     {
68     alidettoalimap[ *iad ] = ali; // Add to map
69     // Check if Alignable already there, insert into vector if not
70     if ( find(alignables.begin(),alignables.end(),ali) == alignables.end() )
71     {
72     alignables.push_back(ali);
73     AlignmentParameters* ap = ali->alignmentParameters();
74     nparam += ap->numSelected();
75     }
76     }
77     }
78    
79     AlgebraicVector* selpar = new AlgebraicVector( nparam, 0 );
80     AlgebraicSymMatrix* selcov = new AlgebraicSymMatrix( nparam, 0 );
81 fronga 1.1
82 ewidl 1.6 // Fill in parameters and corresponding covariance matricess
83     int ipos = 1; // NOTE: .sub indices start from 1
84     std::vector<Alignable*>::const_iterator it1;
85     for( it1 = alignables.begin(); it1 != alignables.end(); ++it1 )
86     {
87     AlignmentParameters* ap = (*it1)->alignmentParameters();
88     selpar->sub( ipos, ap->selectedParameters() );
89     selcov->sub( ipos, ap->selectedCovariance() );
90     int npar = ap->numSelected();
91     aliposmap[*it1]=ipos;
92     alilenmap[*it1]=npar;
93     ipos +=npar;
94     }
95 fronga 1.1
96 ewidl 1.6 // Fill in the correlations. Has to be an extra loop, because the
97     // AlignmentExtendedCorrelationsStore (if used) needs the
98     // alignables' covariance matrices already present.
99     ipos = 1;
100     for( it1 = alignables.begin(); it1 != alignables.end(); ++it1 )
101     {
102     int jpos=1;
103    
104     // Look for correlations between alignables
105     std::vector<Alignable*>::const_iterator it2;
106     for( it2 = alignables.begin(); it2 != it1; ++it2 )
107     {
108     theCorrelationsStore->correlations( *it1, *it2, *selcov, ipos-1, jpos-1 );
109     jpos += (*it2)->alignmentParameters()->numSelected();
110     }
111 fronga 1.1
112 ewidl 1.6 ipos += (*it1)->alignmentParameters()->numSelected();
113 fronga 1.1 }
114    
115 ewidl 1.6 AlignmentParametersData::DataContainer data( new AlignmentParametersData( selpar, selcov ) );
116     CompositeAlignmentParameters aap( data, alignables, alidettoalimap, aliposmap, alilenmap );
117    
118 fronga 1.1 return aap;
119     }
120    
121    
122     //__________________________________________________________________________________________________
123     void AlignmentParameterStore::updateParameters( const CompositeAlignmentParameters& aap )
124     {
125    
126     std::vector<Alignable*> alignables = aap.components();
127 ewidl 1.6 const AlgebraicVector& parameters = aap.parameters();
128     const AlgebraicSymMatrix& covariance = aap.covariance();
129 fronga 1.1
130 ewidl 1.6 int ipos = 1; // NOTE: .sub indices start from 1
131 fronga 1.1
132     // Loop over alignables
133 ewidl 1.6 for( std::vector<Alignable*>::const_iterator it=alignables.begin(); it != alignables.end(); ++it )
134     {
135     // Update parameters and local covariance
136     AlignmentParameters* ap = (*it)->alignmentParameters();
137     int nsel = ap->numSelected();
138     AlgebraicVector subvec = parameters.sub( ipos, ipos+nsel-1 );
139     AlgebraicSymMatrix subcov = covariance.sub( ipos, ipos+nsel-1 );
140     AlignmentParameters* apnew = ap->cloneFromSelected( subvec, subcov );
141     (*it)->setAlignmentParameters( apnew );
142 fronga 1.1
143 ewidl 1.6 // Now update correlations between detectors
144     int jpos = 1;
145     for( std::vector<Alignable*>::const_iterator it2 = alignables.begin(); it2 != it; ++it2 )
146     {
147     theCorrelationsStore->setCorrelations( *it, *it2, covariance, ipos-1, jpos-1 );
148     jpos += (*it2)->alignmentParameters()->numSelected();
149     }
150    
151     ipos+=nsel;
152     }
153 fronga 1.1
154     }
155    
156    
157     //__________________________________________________________________________________________________
158     std::vector<Alignable*> AlignmentParameterStore::validAlignables(void) const
159     {
160     std::vector<Alignable*> result;
161     for (std::vector<Alignable*>::const_iterator iali = theAlignables.begin();
162 ewidl 1.6 iali != theAlignables.end(); ++iali)
163     if ( (*iali)->alignmentParameters()->isValid() ) result.push_back(*iali);
164 fronga 1.1
165 flucke 1.4 LogDebug("Alignment") << "@SUB=AlignmentParameterStore::validAlignables"
166     << "Valid alignables: " << result.size()
167     << "out of " << theAlignables.size();
168 fronga 1.1 return result;
169     }
170    
171    
172     //__________________________________________________________________________________________________
173 fronga 1.2 Alignable*
174     AlignmentParameterStore::alignableFromGeomDet( const GeomDet* geomDet ) const
175 fronga 1.1 {
176 fronga 1.2 return alignableFromDetId( geomDet->geographicalId().rawId() );
177     }
178 fronga 1.1
179    
180 fronga 1.2 //__________________________________________________________________________________________________
181     Alignable*
182     AlignmentParameterStore::alignableFromAlignableDet( const AlignableDet* alignableDet ) const
183     {
184     return alignableFromDetId( alignableDet->geomDetId().rawId() );
185 fronga 1.1 }
186    
187    
188     //__________________________________________________________________________________________________
189     Alignable*
190 fronga 1.2 AlignmentParameterStore::alignableFromDetId( const unsigned int& detId ) const
191 fronga 1.1 {
192 fronga 1.2
193 fronga 1.1 ActiveAlignablesByDetIdMap::const_iterator iali = theActiveAlignablesByDetId.find( detId );
194     if ( iali != theActiveAlignablesByDetId.end() )
195 ewidl 1.6 return (*iali).second;
196 fronga 1.1 else return 0;
197 fronga 1.2
198 fronga 1.1 }
199    
200    
201     //__________________________________________________________________________________________________
202 fronga 1.2 AlignmentParameterStore::DetIds
203     AlignmentParameterStore::findDetIds(Alignable* alignable)
204 fronga 1.1 {
205 fronga 1.2
206     DetIds result;
207     AlignableDet* alidet = dynamic_cast<AlignableDet*>( alignable );
208     if (alidet !=0) result.push_back( alignable->geomDetId().rawId() );
209     std::vector<Alignable*> comp = alignable->components();
210     if ( comp.size() > 1 )
211 ewidl 1.6 for ( std::vector<Alignable*>::const_iterator ib = comp.begin(); ib != comp.end(); ++ib )
212     {
213     DetIds tmpDetIds = findDetIds(*ib);
214     std::copy( tmpDetIds.begin(), tmpDetIds.end(), std::back_inserter( result ) );
215     }
216 fronga 1.1 return result;
217     }
218    
219    
220    
221     //__________________________________________________________________________________________________
222     void AlignmentParameterStore::applyParameters(void)
223     {
224 ewidl 1.6 std::vector<Alignable*>::const_iterator iali;
225     for ( iali = theAlignables.begin(); iali != theAlignables.end(); ++iali)
226     applyParameters( *iali );
227 fronga 1.1 }
228    
229    
230     //__________________________________________________________________________________________________
231     void AlignmentParameterStore::applyParameters(Alignable* alignable)
232     {
233    
234     // Get alignment parameters
235     RigidBodyAlignmentParameters* ap =
236 ewidl 1.6 dynamic_cast<RigidBodyAlignmentParameters*>( alignable->alignmentParameters() );
237 fronga 1.1
238     if ( !ap )
239 ewidl 1.6 throw cms::Exception("BadAlignable")
240     << "applyParameters: provided alignable does not have rigid body alignment parameters";
241 fronga 1.1
242     // Translation in local frame
243     AlgebraicVector shift = ap->translation();
244    
245     // Translation local->global
246     LocalPoint l0 = Local3DPoint( 0.0, 0.0, 0.0);
247     LocalPoint l1 = Local3DPoint(shift[0], shift[1], shift[2]);
248     GlobalPoint g0 = alignable->surface().toGlobal( l0 );
249     GlobalPoint g1 = alignable->surface().toGlobal( l1 );
250     GlobalVector dg = g1-g0;
251     alignable->move(dg);
252    
253     // Rotation in local frame
254     AlgebraicVector rota = ap->rotation();
255     if ( fabs(rota[0]) > 1e-5 || fabs(rota[1]) > 1e-5 || fabs(rota[2]) > 1e-5 )
256 ewidl 1.6 {
257     AlignmentTransformations alignTransform;
258     Surface::RotationType rot = alignTransform.rotationType( alignTransform.rotMatrix3(rota) );
259     Surface::RotationType rot2 =
260     alignTransform.localToGlobalMatrix( rot, alignable->globalRotation() );
261     alignable->rotateInGlobalFrame(rot2);
262     }
263 fronga 1.1 }
264    
265    
266     //__________________________________________________________________________________________________
267     void AlignmentParameterStore::resetParameters(void)
268     {
269     // Erase contents of correlation map
270 ewidl 1.6 theCorrelationsStore->resetCorrelations();
271 fronga 1.1
272     // Iterate over alignables in the store and reset parameters
273 ewidl 1.6 std::vector<Alignable*>::const_iterator iali;
274     for ( iali = theAlignables.begin(); iali != theAlignables.end(); ++iali )
275     resetParameters( *iali );
276 fronga 1.1 }
277    
278    
279     //__________________________________________________________________________________________________
280     void AlignmentParameterStore::resetParameters( Alignable* ali )
281     {
282     if ( ali )
283 ewidl 1.6 {
284     // Get alignment parameters for this alignable
285     AlignmentParameters* ap = ali->alignmentParameters();
286     if ( ap )
287 flucke 1.4 {
288 ewidl 1.6 int npar=ap->numSelected();
289 flucke 1.4
290 ewidl 1.6 AlgebraicVector par(npar,0);
291     AlgebraicSymMatrix cov(npar,0);
292     AlignmentParameters* apnew = ap->cloneFromSelected(par,cov);
293     ali->setAlignmentParameters(apnew);
294     apnew->setValid(false);
295 flucke 1.4 }
296 ewidl 1.6 else
297     edm::LogError("BadArgument") << "@SUB=AlignmentParameterStore::resetParameters"
298     << "alignable has no alignment parameter";
299     }
300 fronga 1.1 else
301 flucke 1.4 edm::LogError("BadArgument") << "@SUB=AlignmentParameterStore::resetParameters"
302     << "argument is NULL";
303 fronga 1.1 }
304    
305    
306     //__________________________________________________________________________________________________
307     void AlignmentParameterStore::acquireRelativeParameters(void)
308     {
309    
310     AlignmentTransformations alignTransform;
311 ewidl 1.6 std::vector<Alignable*>::const_iterator iali;
312     for ( iali = theAlignables.begin(); iali != theAlignables.end(); ++iali )
313     {
314     RigidBodyAlignmentParameters* ap =
315     dynamic_cast<RigidBodyAlignmentParameters*>( (*iali)->alignmentParameters() );
316    
317     if ( !ap )
318     throw cms::Exception("BadAlignable")
319     << "acquireRelativeParameters: "
320     << "provided alignable does not have rigid body alignment parameters";
321 fronga 1.1
322 ewidl 1.6 AlgebraicVector par( ap->size(),0 );
323     AlgebraicSymMatrix cov( ap->size(), 0 );
324 fronga 1.1
325 ewidl 1.6 // Get displacement and transform global->local
326     LocalVector dloc = (*iali)->surface().toLocal( (*iali)->displacement() );
327     par[0]=dloc.x();
328     par[1]=dloc.y();
329     par[2]=dloc.z();
330 fronga 1.1
331 ewidl 1.6 // Global rel rotation
332     Surface::RotationType rot = (*iali)->rotation();
333     // Global abs rotation
334     Surface::RotationType detrot = (*iali)->surface().rotation();
335    
336     // Global euler angles
337     AlgebraicVector euglob = alignTransform.eulerAngles( rot,0 );
338    
339     // Transform to local euler angles
340     AlgebraicVector euloc = alignTransform.globalToLocalEulerAngles( euglob, detrot );
341     par[3]=euloc[0];
342     par[4]=euloc[1];
343     par[5]=euloc[2];
344 fronga 1.1
345 ewidl 1.6 // Clone parameters
346     RigidBodyAlignmentParameters* apnew = ap->clone(par,cov);
347 fronga 1.1
348 ewidl 1.6 (*iali)->setAlignmentParameters(apnew);
349     }
350 fronga 1.1 }
351    
352    
353     //__________________________________________________________________________________________________
354     // Get type/layer from Alignable
355     // type: -6 -5 -4 -3 -2 -1 1 2 3 4 5 6
356     // TEC- TOB- TID- TIB- PxEC- PxBR- PxBr+ PxEC+ TIB+ TID+ TOB+ TEC+
357     // Layers start from zero
358     std::pair<int,int> AlignmentParameterStore::typeAndLayer(Alignable* ali)
359     {
360     return theTrackerAlignableId->typeAndLayerFromAlignable( ali );
361     }
362    
363    
364     //__________________________________________________________________________________________________
365     void AlignmentParameterStore::
366     applyAlignableAbsolutePositions( const Alignables& alivec,
367 ewidl 1.6 const AlignablePositions& newpos,
368     int& ierr )
369 fronga 1.1 {
370     unsigned int nappl=0;
371     ierr=0;
372    
373     // Iterate over list of alignables
374 ewidl 1.6 for ( Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali )
375     {
376     Alignable* ali = *iali;
377     unsigned int detId = theTrackerAlignableId->alignableId(ali);
378     int typeId = theTrackerAlignableId->alignableTypeId(ali);
379    
380     // Find corresponding entry in AlignablePositions
381     bool found=false;
382     for ( AlignablePositions::const_iterator ipos = newpos.begin(); ipos != newpos.end(); ++ipos )
383     if ( detId == ipos->id() && typeId == ipos->objId() )
384     if ( found )
385     edm::LogError("DuplicatePosition")
386     << "New positions for alignable found more than once!";
387     else
388     {
389     // New position/rotation
390     GlobalPoint pnew = ipos->pos();
391     Surface::RotationType rnew = ipos->rot();
392     // Current position / rotation
393     GlobalPoint pold = ali->surface().position();
394     Surface::RotationType rold = ali->surface().rotation();
395 fronga 1.1
396 ewidl 1.6 // shift needed to move from current to new position
397     GlobalVector shift = pnew - pold;
398     ali->move( shift );
399     LogDebug("NewPosition") << "moving by" << shift;
400 fronga 1.1
401 ewidl 1.6 // Delta-rotation needed to rotate from current to new rotation
402     int ierr;
403     AlignmentTransformations alignTransform;
404     Surface::RotationType rot =
405     alignTransform.rotationType(alignTransform.algebraicMatrix(rold).inverse(ierr)) * rnew;
406     if ( ierr )
407     edm::LogError("InversionError") << "Matrix inversion failed: not rotating";
408     else
409     {
410     // 'Repair' matrix for rounding errors
411     Surface::RotationType rotfixed = alignTransform.rectify(rot);
412     ali->rotateInGlobalFrame(rotfixed);
413     AlgebraicMatrix mrot = alignTransform.algebraicMatrix( rotfixed );
414     LogDebug("NewRotation") << "rotating by: " << mrot;
415     }
416 fronga 1.1
417 ewidl 1.6 // add position error
418     // AlignmentPositionError ape(shift.x(),shift.y(),shift.z());
419     // (*iali)->addAlignmentPositionError(ape);
420     // (*iali)->addAlignmentPositionErrorFromRotation(rot);
421 fronga 1.1
422 ewidl 1.6 found=true;
423     ++nappl;
424 fronga 1.1 }
425 ewidl 1.6 }
426 fronga 1.1
427     if ( nappl< newpos.size() )
428 ewidl 1.6 edm::LogError("Mismatch") << "Applied only " << nappl << " new positions"
429     << " out of " << newpos.size();
430 fronga 1.1
431 flucke 1.4 LogDebug("NewPositions") << "Applied new positions for " << nappl
432     << " out of " << alivec.size() <<" alignables.";
433 fronga 1.1
434     }
435    
436    
437     //__________________________________________________________________________________________________
438     void AlignmentParameterStore::
439 ewidl 1.6 applyAlignableRelativePositions( const Alignables& alivec, const AlignableShifts& shifts, int& ierr )
440 fronga 1.1 {
441    
442     unsigned int nappl=0;
443     ierr=0;
444    
445     // Iterate over list of alignables
446 ewidl 1.6 for ( Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali)
447     {
448     unsigned int detId = theTrackerAlignableId->alignableId( *iali );
449     int typeId=theTrackerAlignableId->alignableTypeId( *iali );
450    
451     // Find corresponding entry in AlignableShifts
452     bool found = false;
453     for ( AlignableShifts::const_iterator ipos = shifts.begin(); ipos != shifts.end(); ++ipos )
454     {
455     if ( detId == ipos->id() && typeId == ipos->objId() )
456     if ( found )
457     edm::LogError("DuplicatePosition")
458     << "New positions for alignable found more than once!";
459     else
460     {
461     // New position/rotation shift
462     GlobalVector pnew = ipos->pos();
463     Surface::RotationType rnew = ipos->rot();
464 fronga 1.1
465 ewidl 1.6 (*iali)->move(pnew);
466     (*iali)->rotateInGlobalFrame(rnew);
467    
468     // Add position error
469     //AlignmentPositionError ape(pnew.x(),pnew.y(),pnew.z());
470     //(*iali)->addAlignmentPositionError(ape);
471     //(*iali)->addAlignmentPositionErrorFromRotation(rnew);
472 fronga 1.1
473 ewidl 1.6 found=true;
474     ++nappl;
475 fronga 1.1 }
476 ewidl 1.6 }
477     }
478 fronga 1.1
479     if ( nappl < shifts.size() )
480 ewidl 1.6 edm::LogError("Mismatch") << "Applied only " << nappl << " new positions"
481     << " out of " << shifts.size();
482 fronga 1.1
483 flucke 1.4 LogDebug("NewPositions") << "Applied new positions for " << nappl << " alignables.";
484 fronga 1.1 }
485    
486    
487    
488     //__________________________________________________________________________________________________
489     void AlignmentParameterStore::attachAlignmentParameters( const Parameters& parvec, int& ierr )
490     {
491     attachAlignmentParameters( theAlignables, parvec, ierr);
492     }
493    
494    
495    
496     //__________________________________________________________________________________________________
497     void AlignmentParameterStore::attachAlignmentParameters( const Alignables& alivec,
498 ewidl 1.6 const Parameters& parvec, int& ierr )
499 fronga 1.1 {
500     int ipass = 0;
501     int ifail = 0;
502     ierr = 0;
503    
504     // Iterate over alignables
505 ewidl 1.6 for ( Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali )
506     {
507     // Iterate over Parameters
508     bool found=false;
509     for ( Parameters::const_iterator ipar = parvec.begin(); ipar != parvec.end(); ++ipar)
510     {
511     // Get new alignment parameters
512     RigidBodyAlignmentParameters* ap = dynamic_cast<RigidBodyAlignmentParameters*>(*ipar);
513    
514     // Check if parameters belong to alignable
515     if ( ap->alignable() == (*iali) )
516     {
517     if (!found)
518     {
519     (*iali)->setAlignmentParameters(ap);
520     ++ipass;
521     found=true;
522     }
523     else edm::LogError("DuplicateParameters") << "More than one parameters for Alignable";
524     }
525     }
526     if (!found) ++ifail;
527     }
528 fronga 1.1 if (ifail>0) ierr=-1;
529    
530 ewidl 1.6 LogDebug("attachAlignmentParameters") << " Parameters, Alignables: " << parvec.size() << ","
531     << alivec.size() << "\n pass,fail: " << ipass << ","<< ifail;
532 fronga 1.1 }
533    
534    
535     //__________________________________________________________________________________________________
536     void AlignmentParameterStore::attachCorrelations( const Correlations& cormap,
537 ewidl 1.6 bool overwrite, int& ierr )
538 fronga 1.1 {
539     attachCorrelations( theAlignables, cormap, overwrite, ierr );
540     }
541    
542    
543     //__________________________________________________________________________________________________
544     void AlignmentParameterStore::attachCorrelations( const Alignables& alivec,
545 ewidl 1.6 const Correlations& cormap,
546     bool overwrite, int& ierr )
547 fronga 1.1 {
548     ierr=0;
549     int icount=0;
550    
551     // Iterate over correlations
552 ewidl 1.6 for ( Correlations::const_iterator icor = cormap.begin(); icor!=cormap.end(); ++icor )
553     {
554     AlgebraicMatrix mat=(*icor).second;
555     Alignable* ali1 = (*icor).first.first;
556     Alignable* ali2 = (*icor).first.second;
557    
558     // Check if alignables exist
559     if ( find( alivec.begin(), alivec.end(), ali1 ) != alivec.end() &&
560     find( alivec.begin(), alivec.end(), ali2 ) != alivec.end() )
561     {
562     // Check if correlations already existing between these alignables
563     if ( !theCorrelationsStore->correlationsAvailable(ali1,ali2) || (overwrite) )
564     {
565     theCorrelationsStore->setCorrelations(ali1,ali2,mat);
566     ++icount;
567     }
568     else edm::LogInfo("AlreadyExists") << "Correlation existing and not overwritten";
569     }
570     else edm::LogInfo("IgnoreCorrelation") << "Ignoring correlation with no alignables!";
571     }
572 fronga 1.1
573 ewidl 1.6 LogDebug( "attachCorrelations" ) << " Alignables,Correlations: " << alivec.size() <<","<< cormap.size()
574     << "\n applied: " << icount ;
575 fronga 1.1
576     }
577    
578    
579     //__________________________________________________________________________________________________
580     void AlignmentParameterStore::
581     attachUserVariables( const Alignables& alivec,
582 ewidl 1.6 const std::vector<AlignmentUserVariables*>& uvarvec, int& ierr )
583 fronga 1.1 {
584     ierr=0;
585    
586 flucke 1.4 LogDebug("DumpArguments") << "size of alivec: " << alivec.size()
587     << "\nsize of uvarvec: " << uvarvec.size();
588 fronga 1.1
589     std::vector<AlignmentUserVariables*>::const_iterator iuvar=uvarvec.begin();
590    
591 ewidl 1.6 for ( Alignables::const_iterator iali=alivec.begin(); iali!=alivec.end(); ++iali, ++iuvar )
592     {
593     AlignmentParameters* ap = (*iali)->alignmentParameters();
594     AlignmentUserVariables* uvarnew = (*iuvar);
595     ap->setUserVariables(uvarnew);
596     }
597 fronga 1.1 }
598    
599    
600     //__________________________________________________________________________________________________
601     void AlignmentParameterStore::setAlignmentPositionError( const Alignables& alivec,
602 ewidl 1.6 double valshift, double valrot )
603 fronga 1.1 {
604 ewidl 1.6 bool first=true;
605     for ( Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali )
606     {
607     if (valshift>0)
608     {
609     AlignmentPositionError ape(valshift,valshift,valshift);
610     (*iali)->addAlignmentPositionError(ape);
611     if (first)
612     LogDebug("StoreAPE") << "Store APE from shift: " << valshift;
613     }
614 fronga 1.1
615 ewidl 1.6 if (valrot>0)
616     {
617     AlignmentTransformations alignTransform;
618     AlgebraicVector r(3);
619     r[0]=valrot; r[1]=valrot; r[2]=valrot;
620     Surface::RotationType aperot
621     = alignTransform.rotationType( alignTransform.rotMatrix3(r) );
622     (*iali)->addAlignmentPositionErrorFromRotation(aperot);
623     if (first)
624     LogDebug("StoreAPE") << "Store APE from rotation: " << valrot;
625     }
626     first=false;
627     }
628 fronga 1.1 }