ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/CMSSW/Alignment/CommonAlignmentAlgorithm/src/AlignmentParameterStore.cc
Revision: 1.12
Committed: Fri Mar 16 16:33:53 2007 UTC (18 years, 1 month ago) by flucke
Content type: text/plain
Branch: MAIN
CVS Tags: CMSSW_1_4_10, CMSSW_1_4_9, CMSSW_1_4_8, CMSSW_1_4_7, CMSSW_1_4_6, CMSSW_1_4_5, CMSSW_1_4_3g483, CMSSW_1_4_4, CMSSW_1_4_3, CMSSW_1_4_2, CMSSW_1_4_1, CMSSW_1_4_0_DAQ1, CMSSW_1_4_0, CMSSW_1_5_0_pre2, CMSSW_1_4_0_pre7, CMSSW_1_4_0_pre6, CMSSW_1_4_0_pre5, CMSSW_1_5_0_pre1, CMSSW_1_4_0_pre4, V01-06-00, V01-05-00, V01-04-01, CMSSW_1_4_0_pre3, V01-04-00, V01-03-01, V01-03-00
Changes since 1.11: +49 -2 lines
Log Message:
add first version of hierarchyConstraints() (temporary back port of old headers) in header file

File Contents

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