CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/DataFormats/BeamSpot/src/BeamSpot.cc

Go to the documentation of this file.
00001 
00014 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00015 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
00016 #include "DataFormats/GeometrySurface/interface/TkRotation.h"
00017 
00018 #include <iostream>
00019 
00020 
00021 namespace reco {
00022 
00023   using namespace math;
00024 
00025   BeamSpot::BeamSpot() {
00026           // initialize
00027           position_ = Point(0.,0.,0.);
00028           sigmaZ_ = 0.;
00029           dxdz_ = 0.;
00030           dydz_ = 0.;
00031           BeamWidthX_ = 0.; BeamWidthY_ = 0;
00032           for (int j=0; j<7; j++) {
00033                         for (int k=j; k<7; k++) {
00034                                 error_(j,k) = 0.;
00035                         }
00036           }
00037           type_ = Unknown;
00038           emittanceX_ = 0;
00039           emittanceY_ = 0;
00040           betaStar_ = 0;
00041   }
00042         
00043   const BeamSpot::Point BeamSpot::position(const double z) const {
00044 
00045     Point pos(x(z),y(z),z);
00046     return pos;
00047 
00048   }
00049 
00050 
00051   void BeamSpot::print(std::stringstream& ss) const {
00052 
00053     ss << "-----------------------------------------------------\n"
00054        << "              Beam Spot Data\n\n"
00055            << " Beam type    = " << type() << "\n"
00056        << "       X0     = " << x0() << " +/- " << x0Error() << " [cm]\n"
00057        << "       Y0     = " << y0() << " +/- " << y0Error() << " [cm]\n"
00058        << "       Z0     = " << z0() << " +/- " << z0Error() << " [cm]\n"
00059        << " Sigma Z0     = " << sigmaZ() << " +/- " << sigmaZ0Error() << " [cm]\n"
00060        << " dxdz         = " << dxdz() << " +/- " << dxdzError() << " [radians]\n"
00061        << " dydz         = " << dydz() << " +/- " << dydzError() << " [radians]\n"
00062        << " Beam width X = " << BeamWidthX() << " +/- " << BeamWidthXError() << " [cm]\n"
00063            << " Beam width Y = " << BeamWidthY() << " +/- " << BeamWidthYError() << " [cm]\n"
00064            << " EmittanceX   = " << emittanceX() << " [cm]\n"
00065            << " EmittanceY   = " << emittanceY() << " [cm]\n"
00066            << " beta-star    = " << betaStar() << " [cm]\n"
00067        << "-----------------------------------------------------\n\n";
00068         
00069   }
00070 
00071   //
00072   std::ostream& operator<< ( std::ostream& os, BeamSpot beam ) {
00073     std::stringstream ss;
00074     beam.print(ss);
00075     os << ss.str();
00076     return os;
00077   }
00078 
00079   BeamSpot::Covariance3DMatrix BeamSpot::rotatedCovariance3D() const
00080   {
00081       AlgebraicVector3 newZ(dxdz(), dydz(), 1.);
00082       AlgebraicVector3 globalZ(0.,0.,1.);
00083       AlgebraicVector3 rotationAxis = ROOT::Math::Cross(globalZ.Unit(), newZ.Unit());
00084       float rotationAngle = -acos( ROOT::Math::Dot(globalZ.Unit(),newZ.Unit()));
00085       Basic3DVector<float> aa(rotationAxis[0],rotationAxis[1],rotationAxis[2]);
00086       TkRotation<float> rotation(aa ,rotationAngle);
00087       AlgebraicMatrix33 rotationMatrix;
00088       rotationMatrix(0,0) = rotation.xx();
00089       rotationMatrix(0,1) = rotation.xy();
00090       rotationMatrix(0,2) = rotation.xz();
00091       rotationMatrix(1,0) = rotation.yx();
00092       rotationMatrix(1,1) = rotation.yy();
00093       rotationMatrix(1,2) = rotation.yz();
00094       rotationMatrix(2,0) = rotation.zx();
00095       rotationMatrix(2,1) = rotation.zy();
00096       rotationMatrix(2,2) = rotation.zz();
00097 
00098       AlgebraicSymMatrix33 diagError ;
00099       diagError(0,0) = pow(BeamWidthX(),2);
00100       diagError(1,1) = pow(BeamWidthY(),2);
00101       diagError(2,2) = pow(sigmaZ(),2);
00102 
00103       Covariance3DMatrix matrix;
00104       matrix = ROOT::Math::Similarity(rotationMatrix, diagError) + covariance3D();
00105       return matrix;
00106   }
00107 
00108 }