30 : theAlignables(alis) {
31 if (
config.getUntrackedParameter<
bool>(
"UseExtendedCorrelations")) {
38 edm::LogInfo(
"Alignment") <<
"@SUB=AlignmentParameterStore" 44 if (cfgStrTypeOfConstraints ==
"hierarchy") {
46 }
else if (cfgStrTypeOfConstraints ==
"approximate_averaging") {
49 <<
"@SUB=AlignmentParameterStore" 50 <<
"\n\n\n******* WARNING ******************************************\n" 51 <<
"Using approximate implementation of averaging constraints." 52 <<
"This is not recommended." 53 <<
"Consider to use 'hierarchy' constraints:" 54 <<
" AlignmentProducer.ParameterStore.TypeOfConstraints = cms.string('hierarchy')\n\n\n";
56 edm::LogError(
"BadArgument") <<
"@SUB=AlignmentParameterStore" 57 <<
"Unknown type of hierarchy constraints '" << cfgStrTypeOfConstraints <<
"'";
66 const std::vector<AlignableDet*>& alignabledets)
const {
67 std::vector<AlignableDetOrUnitPtr> detOrUnits;
68 detOrUnits.reserve(alignabledets.size());
70 std::vector<AlignableDet*>::const_iterator
it, iEnd;
71 for (
it = alignabledets.begin(), iEnd = alignabledets.end();
it != iEnd; ++
it)
79 const std::vector<AlignableDetOrUnitPtr>& alignabledets)
const {
81 std::map<AlignableDetOrUnitPtr, Alignable*> alidettoalimap;
82 std::map<Alignable*, int> aliposmap;
83 std::map<Alignable*, int> alilenmap;
87 for (std::vector<AlignableDetOrUnitPtr>::const_iterator iad = alignabledets.begin(); iad != alignabledets.end();
91 alidettoalimap[*iad] = ali;
106 align::Alignables::const_iterator it1;
112 aliposmap[*it1] = ipos;
113 alilenmap[*it1] = npar;
125 align::Alignables::const_iterator it2;
126 for (it2 =
alignables.begin(); it2 != it1; ++it2) {
128 jpos += (*it2)->alignmentParameters()->numSelected();
131 ipos += (*it1)->alignmentParameters()->numSelected();
143 std::map<AlignableDetOrUnitPtr, Alignable*> alidettoalimap;
144 std::map<Alignable*, int> aliposmap;
145 std::map<Alignable*, int> alilenmap;
149 align::Alignables::const_iterator ita;
152 if (
find(selectedAlignables.begin(), selectedAlignables.end(), *ita) == selectedAlignables.end()) {
153 selectedAlignables.push_back(*ita);
164 align::Alignables::const_iterator it1;
165 for (it1 = selectedAlignables.begin(); it1 != selectedAlignables.end(); ++it1) {
170 aliposmap[*it1] = ipos;
171 alilenmap[*it1] = npar;
179 for (it1 = selectedAlignables.begin(); it1 != selectedAlignables.end(); ++it1) {
183 align::Alignables::const_iterator it2;
184 for (it2 = selectedAlignables.begin(); it2 != it1; ++it2) {
186 jpos += (*it2)->alignmentParameters()->numSelected();
189 ipos += (*it1)->alignmentParameters()->numSelected();
214 (*it)->setAlignmentParameters(apnew);
217 if (updateCorrelations) {
219 for (align::Alignables::const_iterator it2 =
alignables.begin(); it2 !=
it; ++it2) {
221 jpos += (*it2)->alignmentParameters()->numSelected();
233 if ((*iali)->alignmentParameters()->isValid())
236 LogDebug(
"Alignment") <<
"@SUB=AlignmentParameterStore::validAlignables" 248 mother = mother->
mother();
256 align::Alignables::const_iterator iali;
265 throw cms::Exception(
"BadAlignable") <<
"applyParameters: provided alignable does not have alignment parameters";
276 align::Alignables::const_iterator iali;
295 edm::LogError(
"BadArgument") <<
"@SUB=AlignmentParameterStore::resetParameters" 296 <<
"alignable has no alignment parameter";
298 edm::LogError(
"BadArgument") <<
"@SUB=AlignmentParameterStore::resetParameters" 299 <<
"argument is NULL";
304 align::Alignables::const_iterator iali;
306 (*iali)->cacheTransformation();
312 iali->cacheTransformation(
run);
317 align::Alignables::const_iterator iali;
319 (*iali)->restoreCachedTransformation();
325 iali->restoreCachedTransformation(
run);
332 for (
unsigned int i = 0;
i < nAlignables; ++
i) {
338 throw cms::Exception(
"BadAlignable") <<
"acquireRelativeParameters: " 339 <<
"provided alignable does not have rigid body alignment parameters";
376 unsigned int nappl = 0;
380 for (align::Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali) {
387 for (AlignablePositions::const_iterator ipos = newpos.begin(); ipos != newpos.end(); ++ipos) {
388 if (
id == ipos->id() && typeId == ipos->objId()) {
390 edm::LogError(
"DuplicatePosition") <<
"New positions for alignable found more than once!";
395 const std::vector<double>& dnew = ipos->deformationParameters();
400 std::vector<std::pair<int, SurfaceDeformation*> > dold_id_pairs;
403 std::vector<double> dold;
405 dold_obj = dold_id_pairs[0].second;
416 LogDebug(
"NewPosition") <<
"moving by:" << posDiff;
417 LogDebug(
"NewRotation") <<
"rotating by:\n" << rotDiff;
422 std::vector<double> defDiff;
423 defDiff.reserve(dold.size());
424 for (
unsigned int i = 0;
i < dold.size();
i++)
425 defDiff.push_back(dnew[
i] - dold[
i]);
427 edm::LogInfo(
"Alignment") <<
"@SUB=AlignmentParameterStore::applyAlignableAbsolutePositions" 428 <<
"Adding surface deformation of type " 431 <<
", size " << defDiff.size() <<
" and first element " << defDiff.at(0)
432 <<
" to alignable with id / type: " <<
id <<
" / " << typeId;
437 else if (!dnew.empty()) {
439 edm::LogInfo(
"Alignment") <<
"@SUB=AlignmentParameterStore::applyAlignableAbsolutePositions" 440 <<
"Setting surface deformation of type " 443 <<
", size " << dnew.size() <<
" and first element " << dnew.at(0)
444 <<
" to alignable with id / type: " <<
id <<
" / " << typeId;
462 if (nappl < newpos.size())
463 edm::LogError(
"Mismatch") <<
"Applied only " << nappl <<
" new positions" 464 <<
" out of " << newpos.size();
466 LogDebug(
"NewPositions") <<
"Applied new positions for " << nappl <<
" out of " << alivec.size() <<
" alignables.";
474 unsigned int nappl = 0;
475 unsigned int nAlignables = alivec.size();
477 for (
unsigned int i = 0;
i < nAlignables; ++
i) {
485 for (AlignableShifts::const_iterator ipos = shifts.begin(); ipos != shifts.end(); ++ipos) {
486 if (
id == ipos->id() && typeId == ipos->objId()) {
488 edm::LogError(
"DuplicatePosition") <<
"New positions for alignable found more than once!";
491 std::vector<std::pair<int, SurfaceDeformation*> > dold_id_pairs;
494 std::vector<double> dold;
496 dold_obj = dold_id_pairs[0].second;
501 ali->
move(ipos->pos());
504 const std::vector<double>& defDiff = ipos->deformationParameters();
508 edm::LogInfo(
"Alignment") <<
"@SUB=AlignmentParameterStore::applyAlignableRelativePositions" 509 <<
"Adding surface deformation of type " 512 <<
", size " << defDiff.size() <<
" and first element " << defDiff.at(0)
513 <<
" to alignable with id / type: " <<
id <<
" / " << typeId;
518 else if (!defDiff.empty()) {
520 edm::LogInfo(
"Alignment") <<
"@SUB=AlignmentParameterStore::applyAlignableRelativePositions" 521 <<
"Setting surface deformation of type " 524 <<
", size " << defDiff.size() <<
" and first element " << defDiff.at(0)
525 <<
" to alignable with id / type: " <<
id <<
" / " << typeId;
543 if (nappl < shifts.size())
544 edm::LogError(
"Mismatch") <<
"Applied only " << nappl <<
" new positions" 545 <<
" out of " << shifts.size();
547 LogDebug(
"NewPositions") <<
"Applied new positions for " << nappl <<
" alignables.";
564 for (align::Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali) {
567 for (Parameters::const_iterator ipar = parvec.begin(); ipar != parvec.end(); ++ipar) {
574 (*iali)->setAlignmentParameters(ap);
578 edm::LogError(
"Alignment") <<
"@SUB=AlignmentParameterStore::attachAlignmentParameters" 579 <<
"More than one parameters for Alignable.";
588 LogDebug(
"attachAlignmentParameters") <<
" Parameters, Alignables: " << parvec.size() <<
"," << alivec.size()
589 <<
"\n pass,fail: " << ipass <<
"," << ifail;
606 for (Correlations::const_iterator icor = cormap.begin(); icor != cormap.end(); ++icor) {
612 if (
find(alivec.begin(), alivec.end(), ali1) != alivec.end() &&
613 find(alivec.begin(), alivec.end(), ali2) != alivec.end()) {
619 edm::LogInfo(
"AlreadyExists") <<
"Correlation existing and not overwritten";
621 edm::LogInfo(
"IgnoreCorrelation") <<
"Ignoring correlation with no alignables!";
624 LogDebug(
"attachCorrelations") <<
" Alignables,Correlations: " << alivec.size() <<
"," << cormap.size()
625 <<
"\n applied: " << icount;
630 const std::vector<AlignmentUserVariables*>& uvarvec,
634 LogDebug(
"DumpArguments") <<
"size of alivec: " << alivec.size() <<
"\nsize of uvarvec: " << uvarvec.size();
636 std::vector<AlignmentUserVariables*>::const_iterator iuvar = uvarvec.begin();
638 for (align::Alignables::const_iterator iali = alivec.begin(); iali != alivec.end(); ++iali, ++iuvar) {
649 unsigned int nAlignables = alivec.size();
651 for (
unsigned int i = 0;
i < nAlignables; ++
i) {
676 LogDebug(
"StoreAPE") <<
"Store APE from shift: " << valshift <<
"\nStore APE from rotation: " << valrot;
682 std::vector<std::vector<ParameterId> >& paramIdsVecOut,
693 paramIdsVecOut.clear();
694 factorsVecOut.clear();
696 bool firstComp =
true;
697 for (align::Alignables::const_iterator iComp = aliComps.begin(), iCompE = aliComps.end(); iComp != iCompE; ++iComp) {
699 if (!p2pDerivs.
isOK()) {
702 throw cms::Exception(
"BadConfig") <<
"AlignmentParameterStore::hierarchyConstraints" 703 <<
" Bad match of types of AlignmentParameters classes.\n";
706 const std::vector<bool>& aliCompSel = (*iComp)->alignmentParameters()->selector();
707 for (
unsigned int iParMast = 0, iParMastUsed = 0; iParMast < aliSel.size(); ++iParMast) {
708 if (!
all && !aliSel[iParMast])
711 paramIdsVecOut.push_back(std::vector<ParameterId>());
712 factorsVecOut.push_back(std::vector<double>());
714 for (
unsigned int iParComp = 0; iParComp < aliCompSel.size(); ++iParComp) {
715 if (aliCompSel[iParComp]) {
719 factor = p2pDerivs(iParMast, iParComp);
722 factor = p2pDerivs(iParMast, iParComp);
723 if (iParMast < 3 && (iParComp % 9) >= 3)
727 paramIdsVecOut[iParMastUsed].push_back(
ParameterId(*iComp, iParComp));
728 factorsVecOut[iParMastUsed].push_back(
factor);
void resetParameters(void)
reset parameters, correlations, user variables
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Alignable * mother() const
Return pointer to container alignable (if any)
const AlgebraicVector & parameters() const
Get alignment parameters.
bool hierarchyConstraints(const Alignable *aliMaster, const align::Alignables &aliComps, std::vector< std::vector< ParameterId > > ¶mIdsVecOut, std::vector< std::vector< double > > &factorsVecOut, bool all, double epsilon) const
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
std::pair< Alignable *, unsigned int > ParameterId
a single alignable parameter of an Alignable
Alignable * alignable(void) const
Get pointer to corresponding alignable.
virtual void addAlignmentPositionErrorFromRotation(const RotationType &rotation, bool propagateDown)=0
void setAlignmentPositionError(const align::Alignables &alivec, double valshift, double valrot)
Set Alignment position error.
void attachCorrelations(const align::Alignables &alivec, const Correlations &cormap, bool overwrite, int &ierr)
Attach correlations to given alignables.
void restoreCachedTransformations(void)
restore the previously cached position, rotation and other parameters
virtual ~AlignmentParameterStore()
destructor
const align::Alignables & alignables(void) const
get all alignables
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
std::pair< int, int > typeAndLayer(const Alignable *ali, const TrackerTopology *tTopo) const
Obtain type and layer from Alignable.
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void attachUserVariables(const align::Alignables &alivec, const std::vector< AlignmentUserVariables *> &uvarvec, int &ierr)
Attach User Variables to given alignables.
T y() const
Cartesian y coordinate.
virtual void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown)=0
void applyAlignableAbsolutePositions(const align::Alignables &alis, const AlignablePositions &newpos, int &ierr)
apply absolute positions to alignables
int numSelected(void) const
Get number of selected parameters.
bool isOK() const
Indicate whether able to provide the derivatives.
const AlgebraicSymMatrix & covariance() const
Get parameter covariance matrix.
void updateParameters(const CompositeAlignmentParameters &aap, bool updateCorrelations=true)
update parameters
std::vector< AlignableRelData > AlignableShifts
AlgebraicVector selectedParameters(void) const
Get selected parameters.
virtual void correlations(Alignable *ap1, Alignable *ap2, AlgebraicSymMatrix &cov, int row, int col) const
align::Alignables validAlignables(void) const
get all alignables with valid parameters
Basic3DVector< T > x() const
const PositionType & globalPosition() const
Return the global position of the object.
virtual void setCorrelations(Alignable *ap1, Alignable *ap2, const AlgebraicSymMatrix &cov, int row, int col)
std::vector< AlignmentParameters * > Parameters
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
CLHEP::HepMatrix AlgebraicMatrix
void rectify(RotationType &)
Correct a rotation matrix for rounding errors.
void setValid(bool v)
Set validity flag.
virtual void addSurfaceDeformation(const SurfaceDeformation *deformation, bool propagateDown)=0
AlignmentParameterStore(const align::Alignables &alis, const edm::ParameterSet &config)
constructor
CompositeAlignmentParameters selectParameters(const std::vector< AlignableDet *> &alignabledets) const
void applyAlignableRelativePositions(const align::Alignables &alivec, const AlignableShifts &shifts, int &ierr)
apply relative shifts to alignables
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
virtual void resetCorrelations(void)
Reset correlations.
int size(void) const
Get number of parameters.
(Abstract) Base class for alignment algorithm user variables
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
virtual void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown)=0
Set the alignment position error - if (!propagateDown) do not affect daughters.
TypeOfConstraints theTypeOfConstraints
type of constraints
Alignable * alignableFromAlignableDet(const AlignableDetOrUnitPtr &alignableDet) const
Obsolete: Use AlignableNavigator::alignableDetFromGeomDet and alignableFromAlignableDet.
Log< level::Info, false > LogInfo
void acquireRelativeParameters(void)
CLHEP::HepVector AlgebraicVector
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
AlgebraicVector EulerAngles
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
std::map< std::pair< Alignable *, Alignable * >, AlgebraicMatrix > Correlations
align::Alignables theAlignables
alignables
const GlobalVector & displacement() const
Return change of the global position since the creation of the object.
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
std::vector< Alignable * > Alignables
AlignmentCorrelationsStore * theCorrelationsStore
char data[epos_bytes_allocation]
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
void cacheTransformations(void)
cache the current position, rotation and other parameters
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::pair< int, int > typeAndLayerFromDetId(const DetId &detId, const TrackerTopology *tTopo) const
virtual int surfaceDeformationIdPairs(std::vector< std::pair< int, SurfaceDeformation *> > &) const =0
const RotationType & globalRotation() const
Return the global orientation of the object.
std::vector< AlignableAbsData > AlignablePositions
RigidBodyAlignmentParameters * clone(const AlgebraicVector ¶meters, const AlgebraicSymMatrix &covMatrix) const override
Clone all parameters (for update of parameters)
Log< level::Warning, false > LogWarning
virtual bool correlationsAvailable(Alignable *ap1, Alignable *ap2) const
Check whether correlations are stored for a given pair of alignables.
void attachAlignmentParameters(const align::Alignables &alivec, const Parameters &parvec, int &ierr)
Attach alignment parameters to given alignables.
virtual AlignmentParameters * cloneFromSelected(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const =0
virtual void apply()=0
apply parameters to alignable
AlgebraicSymMatrix selectedCovariance(void) const
Get covariance matrix of selected parameters.
cond::RealTimeType< cond::runnumber >::type RunNumber
Components components() const
Get vector of alignable components.
const RotationType & rotation() const
Return change of orientation since the creation of the object.