Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:06

0001 /** \file AlignableBeamSpot
0002  *
0003  *  Original author: Andreas Mussgiller, August 2010
0004  *
0005  *  $Date: 2010/10/26 19:53:53 $
0006  *  $Revision: 1.2 $
0007  *  (last update by $Author: flucke $)
0008  */
0009 
0010 #include "Alignment/CommonAlignment/interface/AlignableDetUnit.h"
0011 #include "CondFormats/Alignment/interface/Alignments.h"
0012 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0013 #include "CLHEP/Vector/RotationInterfaces.h"
0014 #include "DataFormats/GeometryCommonDetAlgo/interface/AlignmentPositionError.h"
0015 #include "Alignment/CommonAlignment/interface/AlignableBeamSpot.h"
0016 
0017 #include "FWCore/Utilities/interface/Exception.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 
0020 //__________________________________________________________________________________________________
0021 AlignableBeamSpot::AlignableBeamSpot()
0022     : Alignable(AlignableBeamSpot::detId().rawId(), AlignableSurface()),
0023       theAlignmentPositionError(nullptr),
0024       theInitializedFlag(false) {}
0025 
0026 //__________________________________________________________________________________________________
0027 AlignableBeamSpot::~AlignableBeamSpot() { delete theAlignmentPositionError; }
0028 
0029 //__________________________________________________________________________________________________
0030 void AlignableBeamSpot::move(const GlobalVector& displacement) {
0031   theSurface.move(displacement);
0032   this->addDisplacement(displacement);
0033 }
0034 
0035 //__________________________________________________________________________________________________
0036 void AlignableBeamSpot::rotateInGlobalFrame(const RotationType& rotation) {
0037   theSurface.rotate(rotation);
0038   this->addRotation(rotation);
0039 }
0040 
0041 //__________________________________________________________________________________________________
0042 void AlignableBeamSpot::setAlignmentPositionError(const AlignmentPositionError& ape, bool propagateDown) {
0043   if (!theAlignmentPositionError)
0044     theAlignmentPositionError = new AlignmentPositionError(ape);
0045   else
0046     *theAlignmentPositionError = ape;
0047 }
0048 
0049 //__________________________________________________________________________________________________
0050 void AlignableBeamSpot::addAlignmentPositionError(const AlignmentPositionError& ape, bool propagateDown) {
0051   if (!theAlignmentPositionError) {
0052     theAlignmentPositionError = new AlignmentPositionError(ape);
0053   } else {
0054     *theAlignmentPositionError += ape;
0055   }
0056 }
0057 
0058 //__________________________________________________________________________________________________
0059 void AlignableBeamSpot::addAlignmentPositionErrorFromRotation(const RotationType& rot, bool propagateDown) {}
0060 
0061 //__________________________________________________________________________________________________
0062 /// Adds the AlignmentPositionError (in x,y,z coordinates) that would result
0063 /// on the various components from a possible Rotation of a composite the
0064 /// rotation matrix is in interpreted in LOCAL  coordinates of the composite
0065 void AlignableBeamSpot::addAlignmentPositionErrorFromLocalRotation(const RotationType& rot, bool propagateDown) {}
0066 
0067 //__________________________________________________________________________________________________
0068 void AlignableBeamSpot::setSurfaceDeformation(const SurfaceDeformation*, bool) {
0069   edm::LogInfo("Alignment") << "@SUB=AlignableBeamSpot::setSurfaceDeformation"
0070                             << "Useless method for beam spot, do nothing.";
0071 }
0072 
0073 //__________________________________________________________________________________________________
0074 void AlignableBeamSpot::addSurfaceDeformation(const SurfaceDeformation*, bool) {
0075   edm::LogInfo("Alignment") << "@SUB=AlignableBeamSpot::addSurfaceDeformation"
0076                             << "Useless method for beam spot, do nothing.";
0077 }
0078 
0079 //__________________________________________________________________________________________________
0080 void AlignableBeamSpot::dump(void) const {
0081   // Dump this
0082 
0083   LocalVector lv(0.0, 0.0, 1.0);
0084   GlobalVector gv = theSurface.toGlobal(lv);
0085 
0086   edm::LogInfo("AlignableDump") << " Alignable of type " << this->alignableObjectId() << " has 0 components"
0087                                 << std::endl
0088                                 << " position = " << this->globalPosition() << ", orientation:" << std::endl
0089                                 << std::flush << this->globalRotation() << std::endl
0090                                 << std::flush << " dxdz = " << gv.x() / gv.z() << " dydz = " << gv.y() / gv.z()
0091                                 << std::endl;
0092 }
0093 
0094 //__________________________________________________________________________________________________
0095 Alignments* AlignableBeamSpot::alignments() const {
0096   Alignments* m_alignments = new Alignments();
0097   RotationType rot(this->globalRotation());
0098 
0099   // Get position, rotation, detId
0100   CLHEP::Hep3Vector clhepVector(globalPosition().x(), globalPosition().y(), globalPosition().z());
0101   CLHEP::HepRotation clhepRotation(
0102       CLHEP::HepRep3x3(rot.xx(), rot.xy(), rot.xz(), rot.yx(), rot.yy(), rot.yz(), rot.zx(), rot.zy(), rot.zz()));
0103   uint32_t detId = theId;
0104 
0105   AlignTransform transform(clhepVector, clhepRotation, detId);
0106 
0107   // Add to alignments container
0108   m_alignments->m_align.push_back(transform);
0109 
0110   return m_alignments;
0111 }
0112 
0113 //__________________________________________________________________________________________________
0114 AlignmentErrorsExtended* AlignableBeamSpot::alignmentErrors(void) const {
0115   AlignmentErrorsExtended* m_alignmentErrors = new AlignmentErrorsExtended();
0116 
0117   // Add associated alignment position error
0118   uint32_t detId = theId;
0119   CLHEP::HepSymMatrix clhepSymMatrix(6, 0);
0120   if (theAlignmentPositionError)  // Might not be set
0121     clhepSymMatrix = asHepMatrix(theAlignmentPositionError->globalError().matrix());
0122   AlignTransformErrorExtended transformError(clhepSymMatrix, detId);
0123   m_alignmentErrors->m_alignError.push_back(transformError);
0124 
0125   return m_alignmentErrors;
0126 }
0127 
0128 //______________________________________________________________________________
0129 void AlignableBeamSpot::initialize(double x, double y, double z, double dxdz, double dydz) {
0130   if (theInitializedFlag)
0131     return;
0132 
0133   GlobalVector gv(x, y, z);
0134   theSurface.move(gv);
0135 
0136   double angleY = std::atan(dxdz);
0137   double angleX = -std::atan(dydz);
0138 
0139   align::RotationType rotY(std::cos(angleY), 0., -std::sin(angleY), 0., 1., 0., std::sin(angleY), 0., std::cos(angleY));
0140 
0141   align::RotationType rotX(1., 0., 0., 0., std::cos(angleX), std::sin(angleX), 0., -std::sin(angleX), std::cos(angleX));
0142 
0143   theSurface.rotate(rotY * rotX);
0144 
0145   this->dump();
0146 
0147   theInitializedFlag = true;
0148 }
0149 
0150 //______________________________________________________________________________
0151 void AlignableBeamSpot::reset() {
0152   Alignable::update(this->id(), AlignableSurface());
0153   delete theAlignmentPositionError;
0154   theAlignmentPositionError = nullptr;
0155   theInitializedFlag = false;
0156 }
0157 
0158 //______________________________________________________________________________
0159 const align::Alignables AlignableBeamSpot::emptyComponents_{};