CMS 3D CMS Logo

GeometryAligner.h

Go to the documentation of this file.
00001 #ifndef Geometry_TrackingGeometryAligner_GeometryAligner_h
00002 #define Geometry_TrackingGeometryAligner_GeometryAligner_h
00003 
00004 #include <vector>
00005 #include <algorithm>
00006 #include <iterator>
00007 
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 #include "Geometry/CommonDetUnit/interface/DetPositioner.h"
00012 
00013 #include "CondFormats/Alignment/interface/Alignments.h"
00014 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00015 #include "CondFormats/Alignment/interface/AlignTransform.h"
00016 #include "CondFormats/Alignment/interface/AlignTransformError.h"
00017 
00018 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00019 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
00020 #include "DataFormats/GeometryCommonDetAlgo/interface/GlobalError.h"
00021 #include "DataFormats/GeometrySurface/interface/Surface.h"
00022 
00023 class Alignments;
00024 
00025 
00027 
00028 class GeometryAligner : public DetPositioner {
00029 
00030 public:
00031   template<class C> 
00032   void applyAlignments( C* geometry,
00033                         const Alignments* alignments,
00034                         const AlignmentErrors* alignmentErrors,
00035                         const AlignTransform& globalCoordinates );
00036 
00037 };
00038 
00039 
00040 template<class C>
00041 void GeometryAligner::applyAlignments( C* geometry,
00042                                        const Alignments* alignments,
00043                                        const AlignmentErrors* alignmentErrors,
00044                                        const AlignTransform& globalCoordinates )
00045 {
00046 
00047   edm::LogInfo("Starting") << "Starting to apply alignments";
00048 
00049   // Preliminary checks (or we can't loop!)
00050   if ( alignments->m_align.size() != geometry->theMap.size() )
00051         throw cms::Exception("GeometryMismatch") 
00052           << "Size mismatch between geometry (size=" << geometry->theMap.size() 
00053           << ") and alignments (size=" << alignments->m_align.size() << ")";
00054   if ( alignments->m_align.size() != alignmentErrors->m_alignError.size() )
00055         throw cms::Exception("GeometryMismatch") 
00056           << "Size mismatch between geometry (size=" << geometry->theMap.size() 
00057           << ") and alignment errors (size=" << alignmentErrors->m_alignError.size() << ")";
00058 
00059   const AlignTransform::Translation &globalShift = globalCoordinates.translation();
00060   const AlignTransform::Rotation globalRotation = globalCoordinates.rotation(); // by value!
00061 
00062   // Parallel loop on alignments, alignment errors and geomdets
00063   std::vector<AlignTransform>::const_iterator iAlign = alignments->m_align.begin();
00064   std::vector<AlignTransformError>::const_iterator 
00065         iAlignError = alignmentErrors->m_alignError.begin();
00066   //copy  geometry->theMap to a real map to order it....
00067   std::map<unsigned int, GeomDet*> theMap;
00068   std::copy(geometry->theMap.begin(), geometry->theMap.end(), std::inserter(theMap,theMap.begin()));
00069   for ( std::map<unsigned int, GeomDet*>::const_iterator iPair = theMap.begin(); 
00070                 iPair != theMap.end(); ++iPair, ++iAlign, ++iAlignError )
00071         {
00072           // Check DetIds
00073           if ( (*iPair).first != (*iAlign).rawId() )
00074             throw cms::Exception("GeometryMismatch") 
00075               << "DetId mismatch between geometry (rawId=" << (*iPair).first
00076               << ") and alignments (rawId=" << (*iAlign).rawId();
00077           
00078           if ( (*iPair).first != (*iAlignError).rawId() )
00079             throw cms::Exception("GeometryMismatch") 
00080               << "DetId mismatch between geometry (rawId=" << (*iPair).first
00081               << ") and alignment errors (rawId=" << (*iAlignError).rawId();
00082 
00083           // Apply global correction
00084           CLHEP::Hep3Vector positionHep = globalRotation * CLHEP::Hep3Vector( (*iAlign).translation() ) + globalShift;
00085           CLHEP::HepRotation rotationHep = globalRotation * CLHEP::HepRotation( (*iAlign).rotation() );
00086 
00087           // Define new quantities
00088           Surface::PositionType position( positionHep.x(), positionHep.y(), positionHep.z() );
00089           Surface::RotationType rotation( rotationHep.xx(), rotationHep.xy(), rotationHep.xz(), 
00090                                           rotationHep.yx(), rotationHep.yy(), rotationHep.yz(), 
00091                                           rotationHep.zx(), rotationHep.zy(), rotationHep.zz() );
00092 
00093           // Alignment Position Error
00094           GlobalError error( (*iAlignError).matrix() );
00095           AlignmentPositionError ape( error );
00096 
00097           // Apply new quantities
00098           GeomDet* iGeomDet = (*iPair).second;
00099           DetPositioner::setGeomDetPosition( *iGeomDet, position, rotation );
00100           DetPositioner::setAlignmentPositionError( *iGeomDet, ape );
00101         }
00102 
00103   edm::LogInfo("Done") << "Finished to apply alignments";
00104 }
00105 
00106 
00107 
00108 #endif

Generated on Tue Jun 9 17:37:34 2009 for CMSSW by  doxygen 1.5.4