ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/CMSSW/Alignment/CommonAlignmentAlgorithm/src/AlignmentParameterStore.cc
Revision: 1.31
Committed: Mon May 23 20:50:32 2011 UTC (13 years, 11 months ago) by mussgill
Content type: text/plain
Branch: MAIN
CVS Tags: CMSSW_5_3_11_patch3, CMSSW_6_1_2_SLHC6_patch1, CMSSW_5_3_11_patch2, CMSSW_5_3_11_patch1, CMSSW_6_1_2_SLHC6, CMSSW_6_1_2_SLHC5, CMSSW_5_3_11, CMSSW_4_4_5_patch3, V04-00-09-53X-calib-V01, br53-00-09, br53-00-08, CMSSW_5_3_10_patch2, br53-00-07, br53-00-06, br53-00-05, CMSSW_6_1_2_SLHC4_patch1, CMSSW_6_1_2_SLHC4, CMSSW_6_1_2_SLHC2_patch3, CMSSW_6_1_2_SLHC2_patch2, CMSSW_5_3_10_patch1, CMSSW_6_1_2_SLHC3, CMSSW_6_1_2_SLHC2_patch1, CMSSW_5_3_10, CMSSW_6_1_2_SLHC2, br53-00-04, br53-00-03, br53-00-02, CMSSW_5_3_9_patch3, CMSSW_6_1_2_SLHC1, CMSSW_6_1_X_2012-12-19-0200, CMSSW_6_0_X_2012-08-07-0200, CMSSW_5_2_X_2012-05-03-0200, CMSSW_5_2_X_2012-03-08-0200, CMSSW_5_0_X_2011-12-18-0200, CMSSW_4_4_X_2011-06-09-0400, CMSSW_5_3_9_patch2, CMSSW_6_1_2, CMSSW_5_3_9_patch1, CMSSW_6_1_1_SLHCphase2tk1, CMSSW_5_3_9, CMSSW_6_1_1_SLHCphase1tk1, CMSSW_5_2_9, br53-00-01, CMSSW_6_1_1, CMSSW_5_3_8_patch3, CMSSW_5_3_7_patch6, CMSSW_5_3_8_patch2, CMSSW_5_3_8_patch1, CMSSW_5_3_8, CMSSW_5_3_8_HI_patch2, CMSSW_5_3_7_patch5, CMSSW_5_3_8_HI_patch1, CMSSW_5_2_6_patch2, CMSSW_6_1_0, CMSSW_5_3_8_HI, CMSSW_5_3_7_patch4, CMSSW_5_3_7_patch3, CMSSW_6_0_1_PostLS1v2_patch4, CMSSW_6_1_0_pre8, CMSSW_5_3_7_25nspatch1, CMSSW_5_3_7_patch2, V04-00-10, CMSSW_6_1_0_pre7_TS127013, CMSSW_6_0_1_PostLS1v2_patch3, CMSSW_6_1_0_pre7, CMSSW_5_3_7_patch1, CMSSW_6_1_0_pre6_TS126203_TS126341_patch1, CMSSW_5_3_7_alcapatch1, CMSSW_6_1_0_pre6g496cand01, CMSSW_5_3_7, CMSSW_6_0_1_PostLS1v2_patch2, CMSSW_6_0_1_PostLS1v2_patch1, CMSSW_6_1_0_pre6_TS126203_TS126341, CMSSW_6_1_0_pre6, CMSSW_6_0_1_PostLS1v2, CMSSW_4_4_5_patch2, CMSSW_5_3_6_patch1, CMSSW_5_2_8, CMSSW_6_1_0_pre5, CMSSW_6_0_1_PostLS1v1, CMSSW_5_2_7_hltpatch2, CMSSW_5_3_4_TC125616patch1, V04-00-09, CMSSW_6_0_1, CMSSW_5_3_4_patch2, CMSSW_6_1_0_pre3_TS124729, CMSSW_6_1_0_pre4, CMSSW_5_3_5, CMSSW_5_3_3_patch3, CMSSW_5_3_4_patch1, CMSSW_6_1_0_pre3, CMSSW_4_4_5_patch1, CMSSW_5_2_7, CMSSW_5_3_4, V04-00-08, CMSSW_5_3_2_patch5, V04-00-07, CMSSW_6_1_0_pre2, CMSSW_5_3_4_cand2, CMSSW_5_3_4_cand1_patch1, CMSSW_6_0_0_patch1, V04-00-06, CMSSW_6_0_0_SLHCtkpre1, V04-00-05, V04-00-04, V04-00-03, V04-00-02, CMSSW_6_1_0_pre1, CMSSW_5_3_4_cand1, CMSSW_6_0_0_TS123272, CMSSW_5_2_6_patch1, CMSSW_6_0_0, V04-00-01, CMSSW_4_4_5, V04-00-00, CMSSW_5_3_3_patch2, CMSSW_5_3_3, CMSSW_5_3_3_patch1, CMSSW_6_0_0_pre11, CMSSW_6_0_0_pre10, CMSSW_6_0_0_pre9, CMSSW_5_3_2_patch4, CMSSW_6_0_0_pre8, CMSSW_5_3_3_cand1, CMSSW_5_3_2_patch2, CMSSW_5_3_2_metpatch1, CMSSW_5_2_6_hltpatch1, CMSSW_6_0_0_pre7py273, CMSSW_5_2_6, CMSSW_5_3_2_patch1, CMSSW_5_3_2, CMSSW_6_0_0_pre7, CMSSW_5_2_4_hltpatch4, CMSSW_6_0_0_pre6g495p01, CMSSW_5_2_5_patch3, CMSSW_5_2_5_patch2, CMSSW_6_0_0_pre6, CMSSW_5_3_1, CMSSW_5_2_5_ecalpatch1, CMSSW_6_0_0_pre5, CMSSW_5_3_0_patch1, CMSSW_5_2_5, CMSSW_5_2_5_patch1, CMSSW_sm120515b, CMSSW_sm120515a, CMSSW_5_3_0, CMSSW_6_0_0_pre4, CMSSW_5_2_4_hltpatch2, CMSSW_6_0_X, CMSSW_5_2_5_cand1, CMSSW_5_2_4_patch4, CMSSW_6_0_0_pre3, CMSSW_5_2_4_patch3, CMSSW_5_2_4_patch2, CMSSW_5_2_4_patch1, CMSSW_5_2_4, CMSSW_5_2_3_patch4, CMSSW_5_2_3_patch3, CMSSW_6_0_0_pre2, CMSSW_5_2_3_patch2, CMSSW_5_2_3_patch1, CMSSW_5_2_3, CMSSW_6_0_0_pre1, CMSSW_5_1_3, CMSSW_5_2_2, CMSSW_5_2_1, CMSSW_4_4_4, CMSSW_5_1_2_patch1, CMSSW_5_2_0, CMSSW_5_1_1_patch3, CMSSW_5_2_0_pre5_TS117504, CMSSW_5_1_2, CMSSW_5_2_0_pre6, CMSSW_5_1_1_patch2, CMSSW_4_4_3_patch1, CMSSW_5_1_1_patch1, CMSSW_5_2_0_pre5, CMSSW_5_1_1, CMSSW_5_0_1_patch3, CMSSW_5_0_1_patch2, CMSSW_5_2_0_pre4, CMSSW_5_0_1_patch1, CMSSW_5_2_0_pre3HLT, CMSSW_5_2_0_pre3, CMSSW_5_0_1, CMSSW_5_2_0_pre2_TS113282, CMSSW_4_4_3, CMSSW_5_0_0_patch1, CMSSW_5_2_0_pre2, CMSSW_5_2_0_pre1, CMSSW_5_1_0_pre2, CMSSW_5_1_0_pre1, CMSSW_4_4_2_patch10, CMSSW_5_0_0, CMSSW_4_4_2_patch9, CMSSW_4_4_2_patch8, CMSSW_5_0_0_pre7, CMSSW_5_0_0_pre6g494, CMSSW_4_4_2_patch7, CMSSW_5_0_0_pre6, CMSSW_4_4_2_patch6, CMSSW_5_0_0_pre5_root532rc1, CMSSW_4_4_2_patch5, CMSSW_4_4_2_patch4, CMSSW_4_4_2_patch3, CMSSW_4_4_2_patch2, CMSSW_5_0_0_pre5, CMSSW_4_4_2_patch1, CMSSW_4_4_2, CMSSW_5_0_0_pre4, CMSSW_4_4_0_patch4, CMSSW_5_0_0_pre3, CMSSW_4_4_1, CMSSW_5_0_0_pre2, CMSSW_4_4_0_patch3, CMSSW_4_4_0_patch2, CMSSW_4_4_0_patch1, CMSSW_5_0_0_pre1, CMSSW_4_4_0, CMSSW_4_4_0_pre10, CMSSW_4_4_0_pre9, CMSSW_4_4_0_pre8, CMSSW_4_4_0_pre7_g494p02, CMSSW_4_4_0_pre7, CMSSW_4_4_0_pre6, CMSSW_4_4_0_pre5, CMSSW_4_4_0_pre4, CMSSW_4_3_0_dqmpatch2, CMSSW_4_4_0_pre3, CMSSW_4_3_0_dqmpatch1, CMSSW_4_3_0, CMSSW_4_4_0_pre2, V03-03-05-01, CMSSW_4_4_0_pre1, CMSSW_4_3_0_pre6_dqmIO, CMSSW_4_3_0_pre7, CMSSW_4_3_0_pre6, V03-05-00
Branch point for: branch53X_calibration
Changes since 1.30: +19 -3 lines
Log Message:
added methods that lets all alignables either cache their current positions, rotations etc. or restore the cached values

File Contents

# User Rev Content
1 flucke 1.9 /**
2     * \file AlignmentParameterStore.cc
3     *
4 mussgill 1.31 * $Revision: 1.30 $
5     * $Date: 2010/12/09 19:47:16 $
6 flucke 1.26 * (last update by $Author: flucke $)
7 flucke 1.9 */
8    
9 flucke 1.23 // This class's header should be first
10     #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterStore.h"
11    
12 fronga 1.1 #include "FWCore/MessageLogger/interface/MessageLogger.h"
13 flucke 1.23 #include "FWCore/Utilities/interface/Exception.h"
14 cklae 1.19 #include "FWCore/ParameterSet/interface/ParameterSet.h"
15 fronga 1.1
16 cklae 1.16 #include "Alignment/CommonAlignment/interface/Alignable.h"
17 cklae 1.19 #include "Alignment/CommonAlignment/interface/AlignableDetOrUnitPtr.h"
18 flucke 1.9 #include "Alignment/TrackerAlignment/interface/TrackerAlignableId.h"
19    
20     #include "Alignment/CommonAlignmentParametrization/interface/RigidBodyAlignmentParameters.h"
21 flucke 1.30 #include "Alignment/CommonAlignmentParametrization/interface/ParametersToParametersDerivatives.h"
22 cklae 1.10 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentExtendedCorrelationsStore.h"
23 cklae 1.19 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
24 fronga 1.1
25     //__________________________________________________________________________________________________
26 cklae 1.19 AlignmentParameterStore::AlignmentParameterStore( const align::Alignables &alis,
27 ewidl 1.6 const edm::ParameterSet& config ) :
28 flucke 1.9 theAlignables(alis)
29 fronga 1.1 {
30 flucke 1.9 if (config.getUntrackedParameter<bool>("UseExtendedCorrelations")) {
31     theCorrelationsStore = new AlignmentExtendedCorrelationsStore
32     (config.getParameter<edm::ParameterSet>("ExtendedCorrelationsConfig"));
33     } else {
34 ewidl 1.6 theCorrelationsStore = new AlignmentCorrelationsStore();
35     }
36 fronga 1.1
37 flucke 1.9 edm::LogInfo("Alignment") << "@SUB=AlignmentParameterStore"
38     << "Created with " << theAlignables.size() << " alignables.";
39     }
40 fronga 1.1
41 flucke 1.9 //__________________________________________________________________________________________________
42     AlignmentParameterStore::~AlignmentParameterStore()
43     {
44     delete theCorrelationsStore;
45 fronga 1.1 }
46    
47     //__________________________________________________________________________________________________
48 ewidl 1.6 CompositeAlignmentParameters
49 fronga 1.1 AlignmentParameterStore::selectParameters( const std::vector<AlignableDet*>& alignabledets ) const
50     {
51 cklae 1.16 std::vector<AlignableDetOrUnitPtr> detOrUnits;
52     detOrUnits.reserve(alignabledets.size());
53 ewidl 1.17
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 cklae 1.16
58     return this->selectParameters(detOrUnits);
59     }
60    
61     //__________________________________________________________________________________________________
62     CompositeAlignmentParameters
63     AlignmentParameterStore::selectParameters( const std::vector<AlignableDetOrUnitPtr>& alignabledets ) const
64     {
65 fronga 1.1
66 cklae 1.19 align::Alignables alignables;
67 cklae 1.16 std::map <AlignableDetOrUnitPtr,Alignable*> alidettoalimap;
68 fronga 1.1 std::map <Alignable*,int> aliposmap;
69     std::map <Alignable*,int> alilenmap;
70     int nparam=0;
71    
72     // iterate over AlignableDet's
73 cklae 1.16 for( std::vector<AlignableDetOrUnitPtr>::const_iterator iad = alignabledets.begin();
74     iad != alignabledets.end(); ++iad )
75 ewidl 1.6 {
76 flucke 1.9 Alignable* ali = alignableFromAlignableDet( *iad );
77 ewidl 1.6 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 fronga 1.1
93 ewidl 1.6 // Fill in parameters and corresponding covariance matricess
94     int ipos = 1; // NOTE: .sub indices start from 1
95 cklae 1.19 align::Alignables::const_iterator it1;
96 ewidl 1.6 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 fronga 1.1
107 ewidl 1.6 // 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 cklae 1.19 align::Alignables::const_iterator it2;
117 ewidl 1.6 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 fronga 1.1
123 ewidl 1.6 ipos += (*it1)->alignmentParameters()->numSelected();
124 fronga 1.1 }
125    
126 ewidl 1.6 AlignmentParametersData::DataContainer data( new AlignmentParametersData( selpar, selcov ) );
127     CompositeAlignmentParameters aap( data, alignables, alidettoalimap, aliposmap, alilenmap );
128    
129 fronga 1.1 return aap;
130     }
131    
132    
133     //__________________________________________________________________________________________________
134 ewidl 1.17 CompositeAlignmentParameters
135 cklae 1.19 AlignmentParameterStore::selectParameters( const align::Alignables& alignables ) const
136 ewidl 1.17 {
137    
138 cklae 1.19 align::Alignables selectedAlignables;
139 ewidl 1.17 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 cklae 1.19 align::Alignables::const_iterator ita;
146 ewidl 1.17 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 cklae 1.19 align::Alignables::const_iterator it1;
163 ewidl 1.17 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 cklae 1.19 align::Alignables::const_iterator it2;
184 ewidl 1.17 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 ewidl 1.24 void AlignmentParameterStore::updateParameters( const CompositeAlignmentParameters& aap, bool updateCorrelations )
202 fronga 1.1 {
203    
204 cklae 1.19 align::Alignables alignables = aap.components();
205 ewidl 1.6 const AlgebraicVector& parameters = aap.parameters();
206     const AlgebraicSymMatrix& covariance = aap.covariance();
207 fronga 1.1
208 ewidl 1.6 int ipos = 1; // NOTE: .sub indices start from 1
209 fronga 1.1
210     // Loop over alignables
211 cklae 1.19 for( align::Alignables::const_iterator it=alignables.begin(); it != alignables.end(); ++it )
212 ewidl 1.6 {
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 fronga 1.1
221 ewidl 1.6 // Now update correlations between detectors
222 ewidl 1.24 if ( updateCorrelations )
223 ewidl 1.6 {
224 ewidl 1.24 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 ewidl 1.6 }
231    
232     ipos+=nsel;
233     }
234 fronga 1.1
235     }
236    
237    
238     //__________________________________________________________________________________________________
239 cklae 1.19 align::Alignables AlignmentParameterStore::validAlignables(void) const
240 fronga 1.1 {
241 cklae 1.19 align::Alignables result;
242     for (align::Alignables::const_iterator iali = theAlignables.begin();
243 ewidl 1.6 iali != theAlignables.end(); ++iali)
244     if ( (*iali)->alignmentParameters()->isValid() ) result.push_back(*iali);
245 fronga 1.1
246 flucke 1.4 LogDebug("Alignment") << "@SUB=AlignmentParameterStore::validAlignables"
247     << "Valid alignables: " << result.size()
248     << "out of " << theAlignables.size();
249 fronga 1.1 return result;
250     }
251    
252     //__________________________________________________________________________________________________
253 cklae 1.16 Alignable* AlignmentParameterStore::alignableFromAlignableDet( AlignableDetOrUnitPtr alignableDet ) const
254 fronga 1.1 {
255 flucke 1.9 Alignable *mother = alignableDet;
256     while (mother) {
257     if (mother->alignmentParameters()) return mother;
258     mother = mother->mother();
259     }
260 fronga 1.1
261 flucke 1.9 return 0;
262 fronga 1.1 }
263    
264     //__________________________________________________________________________________________________
265     void AlignmentParameterStore::applyParameters(void)
266     {
267 cklae 1.19 align::Alignables::const_iterator iali;
268 ewidl 1.6 for ( iali = theAlignables.begin(); iali != theAlignables.end(); ++iali)
269     applyParameters( *iali );
270 fronga 1.1 }
271    
272    
273     //__________________________________________________________________________________________________
274     void AlignmentParameterStore::applyParameters(Alignable* alignable)
275     {
276    
277 flucke 1.23 AlignmentParameters *pars = (alignable ? alignable->alignmentParameters() : 0);
278     if (!pars) {
279 ewidl 1.6 throw cms::Exception("BadAlignable")
280 flucke 1.23 << "applyParameters: provided alignable does not have alignment parameters";
281     }
282     pars->apply();
283 fronga 1.1 }
284    
285    
286     //__________________________________________________________________________________________________
287     void AlignmentParameterStore::resetParameters(void)
288     {
289     // Erase contents of correlation map
290 ewidl 1.6 theCorrelationsStore->resetCorrelations();
291 fronga 1.1
292     // Iterate over alignables in the store and reset parameters
293 cklae 1.19 align::Alignables::const_iterator iali;
294 ewidl 1.6 for ( iali = theAlignables.begin(); iali != theAlignables.end(); ++iali )
295     resetParameters( *iali );
296 fronga 1.1 }
297    
298    
299     //__________________________________________________________________________________________________
300     void AlignmentParameterStore::resetParameters( Alignable* ali )
301     {
302     if ( ali )
303 ewidl 1.6 {
304     // Get alignment parameters for this alignable
305     AlignmentParameters* ap = ali->alignmentParameters();
306     if ( ap )
307 flucke 1.4 {
308 ewidl 1.6 int npar=ap->numSelected();
309 flucke 1.4
310 ewidl 1.6 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 flucke 1.4 }
316 ewidl 1.6 else
317     edm::LogError("BadArgument") << "@SUB=AlignmentParameterStore::resetParameters"
318     << "alignable has no alignment parameter";
319     }
320 fronga 1.1 else
321 flucke 1.4 edm::LogError("BadArgument") << "@SUB=AlignmentParameterStore::resetParameters"
322     << "argument is NULL";
323 fronga 1.1 }
324    
325    
326     //__________________________________________________________________________________________________
327 mussgill 1.31 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 fronga 1.1 void AlignmentParameterStore::acquireRelativeParameters(void)
345     {
346    
347 cklae 1.10 unsigned int nAlignables = theAlignables.size();
348    
349     for (unsigned int i = 0; i < nAlignables; ++i)
350 ewidl 1.6 {
351 cklae 1.10 Alignable* ali = theAlignables[i];
352    
353 ewidl 1.6 RigidBodyAlignmentParameters* ap =
354 cklae 1.10 dynamic_cast<RigidBodyAlignmentParameters*>( ali->alignmentParameters() );
355 ewidl 1.6
356     if ( !ap )
357     throw cms::Exception("BadAlignable")
358     << "acquireRelativeParameters: "
359     << "provided alignable does not have rigid body alignment parameters";
360 fronga 1.1
361 ewidl 1.6 AlgebraicVector par( ap->size(),0 );
362     AlgebraicSymMatrix cov( ap->size(), 0 );
363 fronga 1.1
364 ewidl 1.6 // Get displacement and transform global->local
365 cklae 1.10 align::LocalVector dloc = ali->surface().toLocal( ali->displacement() );
366 ewidl 1.6 par[0]=dloc.x();
367     par[1]=dloc.y();
368     par[2]=dloc.z();
369    
370     // Transform to local euler angles
371 cklae 1.10 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 fronga 1.1
376 ewidl 1.6 // Clone parameters
377     RigidBodyAlignmentParameters* apnew = ap->clone(par,cov);
378 fronga 1.1
379 cklae 1.10 ali->setAlignmentParameters(apnew);
380 ewidl 1.6 }
381 fronga 1.1 }
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 flucke 1.9 std::pair<int,int> AlignmentParameterStore::typeAndLayer(const Alignable* ali) const
390 fronga 1.1 {
391 cklae 1.19 return TrackerAlignableId().typeAndLayerFromDetId( ali->id() );
392 fronga 1.1 }
393    
394    
395     //__________________________________________________________________________________________________
396     void AlignmentParameterStore::
397 cklae 1.19 applyAlignableAbsolutePositions( const align::Alignables& alivec,
398 ewidl 1.6 const AlignablePositions& newpos,
399     int& ierr )
400 fronga 1.1 {
401     unsigned int nappl=0;
402     ierr=0;
403    
404     // Iterate over list of alignables
405 flucke 1.26 for (align::Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali) {
406 ewidl 1.6 Alignable* ali = *iali;
407 cklae 1.19 align::ID id = ali->id();
408     align::StructureType typeId = ali->alignableObjectId();
409 ewidl 1.6
410     // Find corresponding entry in AlignablePositions
411     bool found=false;
412 flucke 1.26 for (AlignablePositions::const_iterator ipos = newpos.begin(); ipos != newpos.end(); ++ipos) {
413     if (id == ipos->id() && typeId == ipos->objId()) {
414     if (found) {
415 ewidl 1.6 edm::LogError("DuplicatePosition")
416     << "New positions for alignable found more than once!";
417 flucke 1.26 } else {
418 ewidl 1.6 // New position/rotation
419 cklae 1.10 const align::PositionType& pnew = ipos->pos();
420     const align::RotationType& rnew = ipos->rot();
421 ewidl 1.6 // Current position / rotation
422 cklae 1.10 const align::PositionType& pold = ali->globalPosition();
423     const align::RotationType& rold = ali->globalRotation();
424 fronga 1.1
425 ewidl 1.6 // shift needed to move from current to new position
426 cklae 1.10 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 ewidl 1.6 // add position error
435     // AlignmentPositionError ape(shift.x(),shift.y(),shift.z());
436     // (*iali)->addAlignmentPositionError(ape);
437     // (*iali)->addAlignmentPositionErrorFromRotation(rot);
438 fronga 1.1
439 ewidl 1.6 found=true;
440     ++nappl;
441 fronga 1.1 }
442 flucke 1.26 }
443     }
444 ewidl 1.6 }
445 fronga 1.1
446     if ( nappl< newpos.size() )
447 ewidl 1.6 edm::LogError("Mismatch") << "Applied only " << nappl << " new positions"
448     << " out of " << newpos.size();
449 fronga 1.1
450 flucke 1.4 LogDebug("NewPositions") << "Applied new positions for " << nappl
451     << " out of " << alivec.size() <<" alignables.";
452 fronga 1.1
453     }
454    
455    
456     //__________________________________________________________________________________________________
457     void AlignmentParameterStore::
458 cklae 1.19 applyAlignableRelativePositions( const align::Alignables& alivec, const AlignableShifts& shifts, int& ierr )
459 fronga 1.1 {
460    
461 cklae 1.10 ierr=0;
462 fronga 1.1 unsigned int nappl=0;
463 cklae 1.10 unsigned int nAlignables = alivec.size();
464 fronga 1.1
465 flucke 1.26 for (unsigned int i = 0; i < nAlignables; ++i) {
466 cklae 1.10 Alignable* ali = alivec[i];
467    
468 cklae 1.19 align::ID id = ali->id();
469     align::StructureType typeId = ali->alignableObjectId();
470 ewidl 1.6
471     // Find corresponding entry in AlignableShifts
472     bool found = false;
473 flucke 1.26 for (AlignableShifts::const_iterator ipos = shifts.begin(); ipos != shifts.end(); ++ipos) {
474     if (id == ipos->id() && typeId == ipos->objId()) {
475     if (found) {
476 ewidl 1.6 edm::LogError("DuplicatePosition")
477     << "New positions for alignable found more than once!";
478 flucke 1.26 } else {
479 cklae 1.10 ali->move( ipos->pos() );
480     ali->rotateInGlobalFrame( ipos->rot() );
481 flucke 1.26
482 ewidl 1.6 // Add position error
483     //AlignmentPositionError ape(pnew.x(),pnew.y(),pnew.z());
484 cklae 1.10 //ali->addAlignmentPositionError(ape);
485     //ali->addAlignmentPositionErrorFromRotation(rnew);
486 flucke 1.26
487 ewidl 1.6 found=true;
488     ++nappl;
489 fronga 1.1 }
490 flucke 1.26 }
491 ewidl 1.6 }
492     }
493 fronga 1.1
494     if ( nappl < shifts.size() )
495 ewidl 1.6 edm::LogError("Mismatch") << "Applied only " << nappl << " new positions"
496     << " out of " << shifts.size();
497 fronga 1.1
498 flucke 1.4 LogDebug("NewPositions") << "Applied new positions for " << nappl << " alignables.";
499 fronga 1.1 }
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 cklae 1.19 void AlignmentParameterStore::attachAlignmentParameters( const align::Alignables& alivec,
513 ewidl 1.6 const Parameters& parvec, int& ierr )
514 fronga 1.1 {
515     int ipass = 0;
516     int ifail = 0;
517     ierr = 0;
518    
519     // Iterate over alignables
520 cklae 1.19 for ( align::Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali )
521 ewidl 1.6 {
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 flucke 1.23 AlignmentParameters* ap = *ipar;
528 ewidl 1.6
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 flucke 1.23 else edm::LogError("Alignment") << "@SUB=AlignmentParameterStore::attachAlignmentParameters"
539     << "More than one parameters for Alignable.";
540 ewidl 1.6 }
541     }
542     if (!found) ++ifail;
543     }
544 fronga 1.1 if (ifail>0) ierr=-1;
545    
546 ewidl 1.6 LogDebug("attachAlignmentParameters") << " Parameters, Alignables: " << parvec.size() << ","
547     << alivec.size() << "\n pass,fail: " << ipass << ","<< ifail;
548 fronga 1.1 }
549    
550    
551     //__________________________________________________________________________________________________
552     void AlignmentParameterStore::attachCorrelations( const Correlations& cormap,
553 ewidl 1.6 bool overwrite, int& ierr )
554 fronga 1.1 {
555     attachCorrelations( theAlignables, cormap, overwrite, ierr );
556     }
557    
558    
559     //__________________________________________________________________________________________________
560 cklae 1.19 void AlignmentParameterStore::attachCorrelations( const align::Alignables& alivec,
561 ewidl 1.6 const Correlations& cormap,
562     bool overwrite, int& ierr )
563 fronga 1.1 {
564     ierr=0;
565     int icount=0;
566    
567     // Iterate over correlations
568 ewidl 1.6 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 fronga 1.1
589 ewidl 1.6 LogDebug( "attachCorrelations" ) << " Alignables,Correlations: " << alivec.size() <<","<< cormap.size()
590     << "\n applied: " << icount ;
591 fronga 1.1
592     }
593    
594    
595     //__________________________________________________________________________________________________
596     void AlignmentParameterStore::
597 cklae 1.19 attachUserVariables( const align::Alignables& alivec,
598 ewidl 1.6 const std::vector<AlignmentUserVariables*>& uvarvec, int& ierr )
599 fronga 1.1 {
600     ierr=0;
601    
602 flucke 1.4 LogDebug("DumpArguments") << "size of alivec: " << alivec.size()
603     << "\nsize of uvarvec: " << uvarvec.size();
604 fronga 1.1
605     std::vector<AlignmentUserVariables*>::const_iterator iuvar=uvarvec.begin();
606    
607 cklae 1.19 for ( align::Alignables::const_iterator iali=alivec.begin(); iali!=alivec.end(); ++iali, ++iuvar )
608 ewidl 1.6 {
609     AlignmentParameters* ap = (*iali)->alignmentParameters();
610     AlignmentUserVariables* uvarnew = (*iuvar);
611     ap->setUserVariables(uvarnew);
612     }
613 fronga 1.1 }
614    
615    
616     //__________________________________________________________________________________________________
617 cklae 1.19 void AlignmentParameterStore::setAlignmentPositionError( const align::Alignables& alivec,
618 cklae 1.11 double valshift, double valrot )
619 fronga 1.1 {
620 cklae 1.10 unsigned int nAlignables = alivec.size();
621    
622     for (unsigned int i = 0; i < nAlignables; ++i)
623 ewidl 1.6 {
624 cklae 1.10 Alignable* ali = alivec[i];
625 fronga 1.1
626 fronga 1.7 // First reset APE
627     AlignmentPositionError nulApe(0,0,0);
628 flucke 1.27 ali->setAlignmentPositionError(nulApe, true);
629 fronga 1.7
630     // Set APE from displacement
631     AlignmentPositionError ape(valshift,valshift,valshift);
632 flucke 1.27 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 fronga 1.7
638     // Set APE from rotation
639 cklae 1.10 align::EulerAngles r(3);
640     r(1)=valrot; r(2)=valrot; r(3)=valrot;
641 flucke 1.27 ali->addAlignmentPositionErrorFromRotation(align::toMatrix(r), true);
642 ewidl 1.6 }
643 cklae 1.11
644 flucke 1.18 LogDebug("StoreAPE") << "Store APE from shift: " << valshift
645     << "\nStore APE from rotation: " << valrot;
646 fronga 1.1 }
647 flucke 1.12
648     //__________________________________________________________________________________________________
649     bool AlignmentParameterStore
650 cklae 1.19 ::hierarchyConstraints(const Alignable *ali, const align::Alignables &aliComps,
651 flucke 1.12 std::vector<std::vector<ParameterId> > &paramIdsVecOut,
652 flucke 1.25 std::vector<std::vector<double> > &factorsVecOut,
653 flucke 1.30 bool all, double epsilon) const
654 flucke 1.12 {
655 flucke 1.30 // Weak point if all = false:
656 flucke 1.12 // 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 cklae 1.19 for (align::Alignables::const_iterator iComp = aliComps.begin(), iCompE = aliComps.end();
666 flucke 1.12 iComp != iCompE; ++iComp) {
667 flucke 1.30
668     const ParametersToParametersDerivatives p2pDerivs(**iComp, *ali);
669     if (!p2pDerivs.isOK()) {
670 flucke 1.23 throw cms::Exception("BadConfig")
671     << "AlignmentParameterStore::hierarchyConstraints"
672 flucke 1.30 << " Bad match of types of AlignmentParameters classes.\n";
673     return false;
674 flucke 1.23 }
675 flucke 1.12 const std::vector<bool> &aliCompSel = (*iComp)->alignmentParameters()->selector();
676     for (unsigned int iParMast = 0, iParMastUsed = 0; iParMast < aliSel.size(); ++iParMast) {
677 flucke 1.30 if (!all && !aliSel[iParMast]) continue;// no higher level parameter & constraint deselected
678 flucke 1.12 if (firstComp) { // fill output with empty arrays
679     paramIdsVecOut.push_back(std::vector<ParameterId>());
680 flucke 1.25 factorsVecOut.push_back(std::vector<double>());
681 flucke 1.12 }
682 flucke 1.30 for (unsigned int iParComp = 0; iParComp < aliCompSel.size(); ++iParComp) {
683 flucke 1.12 if (aliCompSel[iParComp]) {
684 flucke 1.30 const double factor = p2pDerivs(iParMast, iParComp);
685 flucke 1.12 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     }