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