CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/CommonAlignment/src/AlignableDetUnit.cc

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) : // rely on non-NULL pointer!
00016   Alignable(geomDetUnit->geographicalId().rawId(), geomDetUnit->surface()),
00017   theAlignmentPositionError(0),
00018   theSurfaceDeformation(0)
00019 {
00020   if (geomDetUnit->alignmentPositionError()) { // take over APE from geometry
00021     // 2nd argument w/o effect:
00022     this->setAlignmentPositionError(*(geomDetUnit->alignmentPositionError()), false);
00023   }
00024 
00025   if (geomDetUnit->surfaceDeformation()) { // take over surface modification
00026     // 2nd argument w/o effect:
00027     this->setSurfaceDeformation(geomDetUnit->surfaceDeformation(), false);
00028   }
00029   
00030   theDeepComponents.push_back(this);
00031 
00032 }
00033 
00034 //__________________________________________________________________________________________________
00035 AlignableDetUnit::~AlignableDetUnit()
00036 {
00037   delete theAlignmentPositionError;
00038   delete theSurfaceDeformation;
00039 }
00040 
00041 //__________________________________________________________________________________________________
00042 void AlignableDetUnit::addComponent( Alignable* /*unused*/)
00043 {
00044   throw cms::Exception("LogicError") 
00045     << "AlignableDetUnit cannot have components, but try to add one!";
00046 }
00047 
00048 //__________________________________________________________________________________________________
00049 void AlignableDetUnit::move( const GlobalVector& displacement) 
00050 {
00051   
00052   theSurface.move( displacement );
00053   this->addDisplacement( displacement );
00054 
00055 }
00056 
00057 
00058 //__________________________________________________________________________________________________
00059 void AlignableDetUnit::rotateInGlobalFrame( const RotationType& rotation) 
00060 {
00061   
00062   theSurface.rotate( rotation );
00063   this->addRotation( rotation );
00064   
00065 }
00066 
00067 
00068 //__________________________________________________________________________________________________
00069 void AlignableDetUnit::setAlignmentPositionError(const AlignmentPositionError& ape,
00070                                                  bool /*propagateDown*/)
00071 {
00072 
00073   if ( !theAlignmentPositionError ) 
00074     theAlignmentPositionError = new AlignmentPositionError( ape );
00075   else
00076     *theAlignmentPositionError = ape;
00077 
00078 }
00079 
00080 
00081 //__________________________________________________________________________________________________
00082 void AlignableDetUnit::addAlignmentPositionError(const AlignmentPositionError& ape,
00083                                                  bool propagateDown )
00084 {
00085 
00086   if ( !theAlignmentPositionError )
00087     this->setAlignmentPositionError( ape, propagateDown ); // 2nd argument w/o effect
00088   else 
00089     *theAlignmentPositionError += ape;
00090 }
00091 
00092 
00093 //__________________________________________________________________________________________________
00094 void AlignableDetUnit::addAlignmentPositionErrorFromRotation(const RotationType& rot,
00095                                                              bool propagateDown ) 
00096 {
00097 
00098   // average error calculated by movement of a local point at
00099   // (xWidth/2,yLength/2,0) caused by the rotation rot
00100   GlobalVector localPositionVector = surface().toGlobal( LocalVector(.5 * surface().width(),
00101                                                                      .5 * surface().length(),
00102                                                                      0.) );
00103 
00104   LocalVector::BasicVectorType lpvgf = localPositionVector.basicVector();
00105   GlobalVector gv( rot.multiplyInverse(lpvgf) - lpvgf );
00106 
00107   AlignmentPositionError  ape( gv.x(),gv.y(),gv.z() );
00108   this->addAlignmentPositionError( ape, propagateDown ); // 2nd argument w/o effect
00109 
00110 }
00111 
00112 
00113 //__________________________________________________________________________________________________
00114 void AlignableDetUnit::addAlignmentPositionErrorFromLocalRotation(const RotationType& rot,
00115                                                                   bool propagateDown )
00116 {
00117 
00118   RotationType globalRot = globalRotation().multiplyInverse(rot*globalRotation());
00119   this->addAlignmentPositionErrorFromRotation(globalRot, propagateDown); // 2nd argument w/o effect
00120 
00121 }
00122 
00123 //__________________________________________________________________________________________________
00124 void AlignableDetUnit::setSurfaceDeformation(const SurfaceDeformation *deformation,
00125                                               bool /* propagateDown */ )
00126 {
00127   delete theSurfaceDeformation; // OK for zero pointers
00128   if (deformation) {
00129     theSurfaceDeformation = deformation->clone();
00130   } else {
00131     theSurfaceDeformation = 0;
00132   }
00133 }
00134 
00135 //__________________________________________________________________________________________________
00136 void AlignableDetUnit::addSurfaceDeformation(const SurfaceDeformation *deformation,
00137                                              bool propagateDown)
00138 {
00139   if (!deformation) {
00140     // nothing to do
00141   } else if (!theSurfaceDeformation) {
00142     this->setSurfaceDeformation(deformation, propagateDown); // fine since no components
00143   } else if (!theSurfaceDeformation->add(*deformation)) {
00144     edm::LogError("Alignment") << "@SUB=AlignableDetUnit::addSurfaceDeformation"
00145                                << "Cannot add deformation type " << deformation->type()
00146                                << " to type " << theSurfaceDeformation->type()
00147                                << ", so erase deformation information.";
00148     delete theSurfaceDeformation;
00149     theSurfaceDeformation = 0;
00150   }
00151 }
00152 
00153 //__________________________________________________________________________________________________
00154 void AlignableDetUnit::dump() const
00155 {
00156 
00157   edm::LogInfo("AlignableDump") 
00158     << " AlignableDetUnit has position = " << this->globalPosition() 
00159     << ", orientation:" << std::endl << this->globalRotation() << std::endl
00160     << " total displacement and rotation: " << this->displacement() << std::endl
00161     << this->rotation();
00162 
00163 }
00164 
00165 
00166 //__________________________________________________________________________________________________
00167 Alignments* AlignableDetUnit::alignments() const
00168 {
00169 
00170   Alignments* m_alignments = new Alignments();
00171   RotationType rot( this->globalRotation() );
00172   
00173   // Get alignments (position, rotation, detId)
00174   CLHEP::Hep3Vector clhepVector( globalPosition().x(), globalPosition().y(), globalPosition().z() );
00175   CLHEP::HepRotation clhepRotation( CLHEP::HepRep3x3( rot.xx(), rot.xy(), rot.xz(),
00176                                                                                 rot.yx(), rot.yy(), rot.yz(),
00177                                                                                 rot.zx(), rot.zy(), rot.zz() ) );
00178   uint32_t detId = this->geomDetId().rawId();
00179   
00180   AlignTransform transform( clhepVector, clhepRotation, detId );
00181 
00182   // Add to alignments container
00183   m_alignments->m_align.push_back( transform );
00184 
00185   return m_alignments;
00186 
00187 }
00188 
00189 
00190 //__________________________________________________________________________________________________
00191 AlignmentErrors* AlignableDetUnit::alignmentErrors() const
00192 {
00193   
00194   AlignmentErrors* m_alignmentErrors = new AlignmentErrors();
00195   
00196   uint32_t detId = this->geomDetId().rawId();
00197  
00198   CLHEP::HepSymMatrix clhepSymMatrix(3,0);
00199   if ( theAlignmentPositionError ) // Might not be set
00200     clhepSymMatrix = theAlignmentPositionError->globalError().matrix();
00201   
00202   AlignTransformError transformError( clhepSymMatrix, detId );
00203   
00204   m_alignmentErrors->m_alignError.push_back( transformError );
00205   
00206   return m_alignmentErrors;
00207 
00208 }
00209 
00210 
00211 //__________________________________________________________________________________________________
00212 int AlignableDetUnit::surfaceDeformationIdPairs(std::vector<std::pair<int,SurfaceDeformation*> > & result) const
00213 {
00214   if ( theSurfaceDeformation ) {
00215     result.push_back( std::pair<int,SurfaceDeformation*>(this->geomDetId().rawId(),theSurfaceDeformation) );
00216     return 1;
00217   }
00218   
00219   return 0;
00220 }