Go to the documentation of this file.00001 #include "Alignment/CommonAlignment/interface/AlignableDetUnit.h"
00002
00003 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00004
00005 #include "CondFormats/Alignment/interface/Alignments.h"
00006 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00007 #include "CLHEP/Vector/RotationInterfaces.h"
00008 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
00009 #include "Geometry/CommonTopologies/interface/SurfaceDeformation.h"
00010
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "FWCore/Utilities/interface/Exception.h"
00013
00014
00015 AlignableDetUnit::AlignableDetUnit(const GeomDetUnit *geomDetUnit) :
00016 Alignable(geomDetUnit->geographicalId().rawId(), geomDetUnit->surface()),
00017 theAlignmentPositionError(0),
00018 theSurfaceDeformation(0),
00019 theCachedSurfaceDeformation(0)
00020 {
00021 if (geomDetUnit->alignmentPositionError()) {
00022
00023 this->setAlignmentPositionError(*(geomDetUnit->alignmentPositionError()), false);
00024 }
00025
00026 if (geomDetUnit->surfaceDeformation()) {
00027
00028 this->setSurfaceDeformation(geomDetUnit->surfaceDeformation(), false);
00029 }
00030
00031 theDeepComponents.push_back(this);
00032
00033 }
00034
00035
00036 AlignableDetUnit::~AlignableDetUnit()
00037 {
00038 delete theAlignmentPositionError;
00039 delete theSurfaceDeformation;
00040 delete theCachedSurfaceDeformation;
00041 }
00042
00043
00044 void AlignableDetUnit::addComponent( Alignable* )
00045 {
00046 throw cms::Exception("LogicError")
00047 << "AlignableDetUnit cannot have components, but try to add one!";
00048 }
00049
00050
00051 void AlignableDetUnit::move( const GlobalVector& displacement)
00052 {
00053
00054 theSurface.move( displacement );
00055 this->addDisplacement( displacement );
00056
00057 }
00058
00059
00060
00061 void AlignableDetUnit::rotateInGlobalFrame( const RotationType& rotation)
00062 {
00063
00064 theSurface.rotate( rotation );
00065 this->addRotation( rotation );
00066
00067 }
00068
00069
00070
00071 void AlignableDetUnit::setAlignmentPositionError(const AlignmentPositionError& ape,
00072 bool )
00073 {
00074
00075 if ( !theAlignmentPositionError )
00076 theAlignmentPositionError = new AlignmentPositionError( ape );
00077 else
00078 *theAlignmentPositionError = ape;
00079
00080 }
00081
00082
00083
00084 void AlignableDetUnit::addAlignmentPositionError(const AlignmentPositionError& ape,
00085 bool propagateDown )
00086 {
00087
00088 if ( !theAlignmentPositionError )
00089 this->setAlignmentPositionError( ape, propagateDown );
00090 else
00091 *theAlignmentPositionError += ape;
00092 }
00093
00094
00095
00096 void AlignableDetUnit::addAlignmentPositionErrorFromRotation(const RotationType& rot,
00097 bool propagateDown )
00098 {
00099
00100
00101
00102 GlobalVector localPositionVector = surface().toGlobal( LocalVector(.5 * surface().width(),
00103 .5 * surface().length(),
00104 0.) );
00105
00106 LocalVector::BasicVectorType lpvgf = localPositionVector.basicVector();
00107 GlobalVector gv( rot.multiplyInverse(lpvgf) - lpvgf );
00108
00109 AlignmentPositionError ape( gv.x(),gv.y(),gv.z() );
00110 this->addAlignmentPositionError( ape, propagateDown );
00111
00112 }
00113
00114
00115
00116 void AlignableDetUnit::addAlignmentPositionErrorFromLocalRotation(const RotationType& rot,
00117 bool propagateDown )
00118 {
00119
00120 RotationType globalRot = globalRotation().multiplyInverse(rot*globalRotation());
00121 this->addAlignmentPositionErrorFromRotation(globalRot, propagateDown);
00122
00123 }
00124
00125
00126 void AlignableDetUnit::setSurfaceDeformation(const SurfaceDeformation *deformation,
00127 bool )
00128 {
00129 delete theSurfaceDeformation;
00130 if (deformation) {
00131 theSurfaceDeformation = deformation->clone();
00132 } else {
00133 theSurfaceDeformation = 0;
00134 }
00135 }
00136
00137
00138 void AlignableDetUnit::addSurfaceDeformation(const SurfaceDeformation *deformation,
00139 bool propagateDown)
00140 {
00141 if (!deformation) {
00142
00143 } else if (!theSurfaceDeformation) {
00144 this->setSurfaceDeformation(deformation, propagateDown);
00145 } else if (!theSurfaceDeformation->add(*deformation)) {
00146 edm::LogError("Alignment") << "@SUB=AlignableDetUnit::addSurfaceDeformation"
00147 << "Cannot add deformation type " << deformation->type()
00148 << " to type " << theSurfaceDeformation->type()
00149 << ", so erase deformation information.";
00150 delete theSurfaceDeformation;
00151 theSurfaceDeformation = 0;
00152 }
00153 }
00154
00155
00156 void AlignableDetUnit::dump() const
00157 {
00158
00159 edm::LogInfo("AlignableDump")
00160 << " AlignableDetUnit has position = " << this->globalPosition()
00161 << ", orientation:" << std::endl << this->globalRotation() << std::endl
00162 << " total displacement and rotation: " << this->displacement() << std::endl
00163 << this->rotation();
00164
00165 }
00166
00167
00168
00169 Alignments* AlignableDetUnit::alignments() const
00170 {
00171 Alignments* m_alignments = new Alignments();
00172 RotationType rot( this->globalRotation() );
00173
00174
00175 CLHEP::Hep3Vector clhepVector( globalPosition().x(), globalPosition().y(), globalPosition().z() );
00176 CLHEP::HepRotation clhepRotation( CLHEP::HepRep3x3( rot.xx(), rot.xy(), rot.xz(),
00177 rot.yx(), rot.yy(), rot.yz(),
00178 rot.zx(), rot.zy(), rot.zz() ) );
00179 uint32_t detId = this->geomDetId().rawId();
00180
00181 AlignTransform transform( clhepVector, clhepRotation, detId );
00182
00183
00184 m_alignments->m_align.push_back( transform );
00185
00186 return m_alignments;
00187
00188 }
00189
00190
00191
00192 AlignmentErrors* AlignableDetUnit::alignmentErrors() const
00193 {
00194
00195 AlignmentErrors* m_alignmentErrors = new AlignmentErrors();
00196
00197 uint32_t detId = this->geomDetId().rawId();
00198
00199 CLHEP::HepSymMatrix clhepSymMatrix(3,0);
00200 if ( theAlignmentPositionError )
00201 clhepSymMatrix = asHepMatrix(theAlignmentPositionError->globalError().matrix());
00202
00203 AlignTransformError transformError( clhepSymMatrix, detId );
00204
00205 m_alignmentErrors->m_alignError.push_back( transformError );
00206
00207 return m_alignmentErrors;
00208
00209 }
00210
00211
00212
00213 int AlignableDetUnit::surfaceDeformationIdPairs(std::vector<std::pair<int,SurfaceDeformation*> > & result) const
00214 {
00215 if ( theSurfaceDeformation ) {
00216 result.push_back( std::pair<int,SurfaceDeformation*>(this->geomDetId().rawId(),theSurfaceDeformation) );
00217 return 1;
00218 }
00219
00220 return 0;
00221 }
00222
00223
00224 void AlignableDetUnit::cacheTransformation()
00225 {
00226 theCachedSurface = theSurface;
00227 theCachedDisplacement = theDisplacement;
00228 theCachedRotation = theRotation;
00229
00230 if (theCachedSurfaceDeformation) {
00231 delete theCachedSurfaceDeformation;
00232 theCachedSurfaceDeformation = 0;
00233 }
00234
00235 if (theSurfaceDeformation)
00236 theCachedSurfaceDeformation = theSurfaceDeformation->clone();
00237 }
00238
00239
00240 void AlignableDetUnit::restoreCachedTransformation()
00241 {
00242 theSurface = theCachedSurface;
00243 theDisplacement = theCachedDisplacement;
00244 theRotation = theCachedRotation;
00245
00246 if (theSurfaceDeformation) {
00247 delete theSurfaceDeformation;
00248 theSurfaceDeformation = 0;
00249 }
00250
00251 if (theCachedSurfaceDeformation) {
00252 this->setSurfaceDeformation(theCachedSurfaceDeformation, false);
00253 }
00254 }