ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/CMSSW/Alignment/CommonAlignmentAlgorithm/src/AlignmentParameterStore.cc
Revision: 1.14
Committed: Fri May 11 14:28:02 2007 UTC (17 years, 11 months ago) by flucke
Content type: text/plain
Branch: MAIN
CVS Tags: V01-04-00-07, V01-04-00-06, V01-04-00-05, V01-04-00-03, V01-07-02, V01-07-01, V01-04-00-02
Branch point for: V01-04-00-04
Changes since 1.13: +3 -6 lines
Log Message:
remove cut that prevents application of small rotational corrections, as discussed https://hypernews.cern.ch/HyperNews/CMS/get/tk-alignment/41/1/1/1.html

File Contents

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