CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Alignment/CommonAlignment/src/AlignableDet.cc

Go to the documentation of this file.
00001 #include "Alignment/CommonAlignment/interface/AlignableDetUnit.h"
00002 #include "CondFormats/Alignment/interface/Alignments.h"
00003 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00004 #include "CLHEP/Vector/RotationInterfaces.h" 
00005 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
00006 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00007 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00008 
00009 #include "Alignment/CommonAlignment/interface/AlignableDet.h"
00010 
00011 #include "FWCore/Utilities/interface/Exception.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 
00014 
00015 //__________________________________________________________________________________________________
00016 AlignableDet::AlignableDet( const GeomDet* geomDet, bool addComponents ) : 
00017   AlignableComposite( geomDet ), 
00018   theAlignmentPositionError(0)
00019 {
00020   if (geomDet->alignmentPositionError()) {
00021     // false: do not propagate APE to (anyway not yet existing) daughters
00022     this->setAlignmentPositionError(*(geomDet->alignmentPositionError()), false); 
00023   }
00024 
00025   if (addComponents) {
00026     if ( geomDet->components().size() == 0 ) { // Is a DetUnit
00027       throw cms::Exception("BadHierarchy") << "[AlignableDet] GeomDet with DetId " 
00028                                            << geomDet->geographicalId().rawId() 
00029                                            << " has no components, use AlignableDetUnit.\n";
00030     } else { // Push back all components
00031       const std::vector<const GeomDet*>& geomDets = geomDet->components();
00032       for (std::vector<const GeomDet*>::const_iterator idet = geomDets.begin(); 
00033             idet != geomDets.end(); ++idet) {
00034         const GeomDetUnit *unit = dynamic_cast<const GeomDetUnit*>(*idet);
00035         if (!unit) {
00036           throw cms::Exception("BadHierarchy") 
00037             << "[AlignableDet] component not GeomDetUnit, call with addComponents==false" 
00038             << " and build hierarchy yourself.\n";  // e.g. AlignableDTChamber
00039         }
00040         this->addComponent(new AlignableDetUnit(unit));
00041       }
00042     }
00043     // Ensure that the surface is not screwed up by addComponent, it must stay the GeomDet's one:
00044     theSurface = AlignableSurface(geomDet->surface());
00045   } // end addComponents  
00046 }
00047 
00048 
00049 //__________________________________________________________________________________________________
00050 AlignableDet::~AlignableDet()
00051 {
00052 
00053   delete theAlignmentPositionError;
00054 
00055 }
00056 
00057 
00058 //__________________________________________________________________________________________________
00059 void AlignableDet::setAlignmentPositionError(const AlignmentPositionError& ape, bool propagateDown)
00060 {
00061 
00062   if ( !theAlignmentPositionError )
00063         theAlignmentPositionError = new AlignmentPositionError( ape );
00064   else 
00065         *theAlignmentPositionError = ape;
00066 
00067   this->AlignableComposite::setAlignmentPositionError( ape, propagateDown );
00068 
00069 }
00070 
00071 
00072 //__________________________________________________________________________________________________
00073 void AlignableDet::addAlignmentPositionError(const AlignmentPositionError& ape, bool propagateDown)
00074 {
00075 
00076   if ( !theAlignmentPositionError ) {
00077     theAlignmentPositionError = new AlignmentPositionError( ape );
00078   } else {
00079     *theAlignmentPositionError += ape;
00080   }
00081 
00082   this->AlignableComposite::addAlignmentPositionError( ape, propagateDown );
00083 
00084 }
00085 
00086 //__________________________________________________________________________________________________
00087 void AlignableDet::addAlignmentPositionErrorFromRotation(const RotationType& rot,
00088                                                          bool propagateDown)
00089 {
00090 
00091   // average error calculated by movement of a local point at
00092   // (xWidth/2,yLength/2,0) caused by the rotation rot
00093   GlobalVector localPositionVector = surface().toGlobal( LocalVector(.5 * surface().width(), .5 * surface().length(), 0.) );
00094 
00095   LocalVector::BasicVectorType lpvgf = localPositionVector.basicVector();
00096   GlobalVector gv( rot.multiplyInverse(lpvgf) - lpvgf );
00097 
00098   AlignmentPositionError  ape( gv.x(),gv.y(),gv.z() );
00099   this->addAlignmentPositionError( ape, propagateDown );
00100 
00101   this->AlignableComposite::addAlignmentPositionErrorFromRotation( rot, propagateDown );
00102 
00103 }
00104 
00105 //__________________________________________________________________________________________________
00106 Alignments* AlignableDet::alignments() const
00107 {
00108 
00109   Alignments* m_alignments = new Alignments();
00110   RotationType rot( this->globalRotation() );
00111 
00112   // Get position, rotation, detId
00113   CLHEP::Hep3Vector clhepVector( globalPosition().x(), globalPosition().y(), globalPosition().z() );
00114   CLHEP::HepRotation clhepRotation( CLHEP::HepRep3x3( rot.xx(), rot.xy(), rot.xz(),
00115                                         rot.yx(), rot.yy(), rot.yz(),
00116                                         rot.zx(), rot.zy(), rot.zz() ) );
00117   uint32_t detId = this->geomDetId().rawId();
00118   
00119   AlignTransform transform( clhepVector, clhepRotation, detId );
00120   
00121   // Add to alignments container
00122   m_alignments->m_align.push_back( transform );
00123 
00124   // Add those from components
00125   Alignments *compAlignments = this->AlignableComposite::alignments();
00126   std::copy(compAlignments->m_align.begin(), compAlignments->m_align.end(), 
00127             std::back_inserter(m_alignments->m_align));
00128   delete compAlignments;
00129 
00130 
00131   return m_alignments;
00132 }
00133 
00134 //__________________________________________________________________________________________________
00135 AlignmentErrors* AlignableDet::alignmentErrors( void ) const
00136 {
00137 
00138   AlignmentErrors* m_alignmentErrors = new AlignmentErrors();
00139 
00140   // Add associated alignment position error
00141   uint32_t detId = this->geomDetId().rawId();
00142   CLHEP::HepSymMatrix clhepSymMatrix(3,0);
00143   if ( theAlignmentPositionError ) // Might not be set
00144     clhepSymMatrix= asHepMatrix(theAlignmentPositionError->globalError().matrix());
00145   AlignTransformError transformError( clhepSymMatrix, detId );
00146   m_alignmentErrors->m_alignError.push_back( transformError );
00147 
00148   // Add those from components
00149   AlignmentErrors *compAlignmentErrs = this->AlignableComposite::alignmentErrors();
00150   std::copy(compAlignmentErrs->m_alignError.begin(), compAlignmentErrs->m_alignError.end(),
00151             std::back_inserter(m_alignmentErrors->m_alignError));
00152   delete compAlignmentErrs;
00153   
00154 
00155   return m_alignmentErrors;
00156 }