CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/Alignment/CommonAlignment/src/AlignableBeamSpot.cc

Go to the documentation of this file.
00001 
00010 #include "Alignment/CommonAlignment/interface/AlignableDetUnit.h"
00011 #include "CondFormats/Alignment/interface/Alignments.h"
00012 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00013 #include "CLHEP/Vector/RotationInterfaces.h" 
00014 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
00015 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00016 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00017 
00018 #include "Alignment/CommonAlignment/interface/AlignableBeamSpot.h"
00019 
00020 #include "FWCore/Utilities/interface/Exception.h"
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 
00023 //__________________________________________________________________________________________________
00024 AlignableBeamSpot::AlignableBeamSpot() : 
00025   Alignable( AlignableBeamSpot::detId().rawId(), AlignableSurface() ), 
00026   theAlignmentPositionError(0),
00027   theInitializedFlag(false)
00028 {
00029 
00030 }
00031 
00032 //__________________________________________________________________________________________________
00033 AlignableBeamSpot::~AlignableBeamSpot()
00034 {
00035   delete theAlignmentPositionError;
00036 }
00037 
00038 //__________________________________________________________________________________________________
00039 void AlignableBeamSpot::move( const GlobalVector& displacement) 
00040 {
00041   theSurface.move( displacement );
00042   this->addDisplacement( displacement );
00043 }
00044 
00045 //__________________________________________________________________________________________________
00046 void AlignableBeamSpot::rotateInGlobalFrame( const RotationType& rotation) 
00047 {
00048   theSurface.rotate( rotation );
00049   this->addRotation( rotation );
00050 }
00051 
00052 //__________________________________________________________________________________________________
00053 void AlignableBeamSpot::setAlignmentPositionError(const AlignmentPositionError& ape, bool propagateDown)
00054 {
00055   if ( !theAlignmentPositionError )
00056     theAlignmentPositionError = new AlignmentPositionError( ape );
00057   else 
00058     *theAlignmentPositionError = ape;
00059 }
00060 
00061 //__________________________________________________________________________________________________
00062 void AlignableBeamSpot::addAlignmentPositionError(const AlignmentPositionError& ape, bool propagateDown)
00063 {
00064   if ( !theAlignmentPositionError ) {
00065     theAlignmentPositionError = new AlignmentPositionError( ape );
00066   } else {
00067     *theAlignmentPositionError += ape;
00068   }
00069 }
00070 
00071 //__________________________________________________________________________________________________
00072 void AlignableBeamSpot::addAlignmentPositionErrorFromRotation(const RotationType& rot,
00073                                                               bool propagateDown)
00074 {
00075 
00076 }
00077 
00078 //__________________________________________________________________________________________________
00082 void AlignableBeamSpot::addAlignmentPositionErrorFromLocalRotation(const RotationType& rot,
00083                                                                    bool propagateDown )
00084 {
00085 
00086 }
00087 
00088 //__________________________________________________________________________________________________
00089 void AlignableBeamSpot::setSurfaceDeformation(const SurfaceDeformation*, bool)
00090 {
00091   edm::LogInfo("Alignment") << "@SUB=AlignableBeamSpot::setSurfaceDeformation"
00092                             << "Useless method for beam spot, do nothing.";
00093 }
00094 
00095 //__________________________________________________________________________________________________
00096 void AlignableBeamSpot::addSurfaceDeformation(const SurfaceDeformation*, bool)
00097 {
00098   edm::LogInfo("Alignment") << "@SUB=AlignableBeamSpot::addSurfaceDeformation"
00099                             << "Useless method for beam spot, do nothing.";
00100 }
00101 
00102 //__________________________________________________________________________________________________
00103 void AlignableBeamSpot::dump( void ) const
00104 {
00105   // Dump this
00106 
00107   LocalVector lv(0.0, 0.0, 1.0);
00108   GlobalVector gv = theSurface.toGlobal(lv);
00109 
00110   edm::LogInfo("AlignableDump") 
00111     << " Alignable of type " << this->alignableObjectId() 
00112     << " has 0 components" << std::endl
00113     << " position = " << this->globalPosition() << ", orientation:" << std::endl << std::flush
00114     << this->globalRotation() << std::endl << std::flush
00115     << " dxdz = " << gv.x()/gv.z() << " dydz = " << gv.y()/gv.z() << std::endl;
00116 }
00117 
00118 //__________________________________________________________________________________________________
00119 Alignments* AlignableBeamSpot::alignments() const
00120 {
00121   Alignments* m_alignments = new Alignments();
00122   RotationType rot( this->globalRotation() );
00123 
00124   // Get position, rotation, detId
00125   CLHEP::Hep3Vector clhepVector( globalPosition().x(), globalPosition().y(), globalPosition().z() );
00126   CLHEP::HepRotation clhepRotation( CLHEP::HepRep3x3( rot.xx(), rot.xy(), rot.xz(),
00127                                                       rot.yx(), rot.yy(), rot.yz(),
00128                                                       rot.zx(), rot.zy(), rot.zz() ) );
00129   uint32_t detId = theId;
00130   
00131   AlignTransform transform( clhepVector, clhepRotation, detId );
00132   
00133   // Add to alignments container
00134   m_alignments->m_align.push_back( transform );
00135 
00136   return m_alignments;
00137 }
00138 
00139 //__________________________________________________________________________________________________
00140 AlignmentErrors* AlignableBeamSpot::alignmentErrors( void ) const
00141 {
00142   AlignmentErrors* m_alignmentErrors = new AlignmentErrors();
00143 
00144   // Add associated alignment position error
00145   uint32_t detId = theId;
00146   CLHEP::HepSymMatrix clhepSymMatrix(3,0);
00147   if ( theAlignmentPositionError ) // Might not be set
00148     clhepSymMatrix = asHepMatrix(theAlignmentPositionError->globalError().matrix());
00149   AlignTransformError transformError( clhepSymMatrix, detId );
00150   m_alignmentErrors->m_alignError.push_back( transformError );
00151   
00152   return m_alignmentErrors;
00153 }
00154 
00155 void AlignableBeamSpot::initialize(double x, double y, double z,
00156                                    double dxdz, double dydz)
00157 {
00158   if (theInitializedFlag) return;
00159 
00160   GlobalVector gv(x, y, z);
00161   theSurface.move(gv);
00162 
00163   double angleY = std::atan(dxdz);
00164   double angleX = -std::atan(dydz);
00165 
00166   align::RotationType rotY( std::cos(angleY),  0., -std::sin(angleY), 
00167                             0.,                1.,  0.,
00168                             std::sin(angleY),  0.,  std::cos(angleY) );
00169 
00170   align::RotationType rotX( 1.,  0.,                0.,
00171                             0.,  std::cos(angleX),  std::sin(angleX),
00172                             0., -std::sin(angleX),  std::cos(angleX) );  
00173 
00174   theSurface.rotate(rotY * rotX);
00175 
00176   this->dump();
00177   
00178   theInitializedFlag = true;
00179 }