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