Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:50

0001 #ifndef BeamSpot_BeamSpot_h
0002 #define BeamSpot_BeamSpot_h
0003 /** \class reco::BeamSpot
0004  *  
0005  * Reconstructed beam spot object which provides position, error, and
0006  * width of the beam position.
0007  *
0008  * \author Francisco Yumiceva, Fermilab (yumiceva@fnal.gov)
0009  *
0010  *
0011  */
0012 
0013 #include <Rtypes.h>
0014 #include "DataFormats/Math/interface/Error.h"
0015 #include "DataFormats/Math/interface/Point3D.h"
0016 #include <string>
0017 #include <sstream>
0018 
0019 namespace reco {
0020 
0021   class BeamSpot {
0022   public:
0023     /// beam spot flags
0024     enum BeamType { Unknown = -1, Fake = 0, LHC = 1, Tracker = 2 };
0025 
0026     /// point in the space
0027     typedef math::XYZPoint Point;
0028     enum { dimension = 7 };
0029     typedef math::Error<dimension>::type CovarianceMatrix;
0030     enum { dim3 = 3 };
0031     typedef math::Error<dim3>::type Covariance3DMatrix;
0032     enum { resdim = 2 };
0033     typedef math::Error<resdim>::type ResCovMatrix;
0034 
0035     /// default constructor
0036     BeamSpot();
0037 
0038     /// constructor from values
0039     BeamSpot(const Point& point,
0040              double sigmaZ,
0041              double dxdz,
0042              double dydz,
0043              double BeamWidthX,
0044              const CovarianceMatrix& error,
0045              BeamType type = Unknown) {
0046       position_ = point;
0047       sigmaZ_ = sigmaZ;
0048       dxdz_ = dxdz;
0049       dydz_ = dydz;
0050       BeamWidthX_ = BeamWidthX;
0051       BeamWidthY_ = BeamWidthX;
0052       error_ = error;
0053       type_ = type;
0054       emittanceX_ = emittanceY_ = 0;
0055       betaStar_ = 0;
0056     };
0057 
0058     /// position
0059     const Point& position() const { return position_; }
0060     /// x coordinate
0061     double x0() const { return position_.X(); }
0062     /// y coordinate
0063     double y0() const { return position_.Y(); }
0064     /// z coordinate
0065     double z0() const { return position_.Z(); }
0066 
0067     /// x coordinate of the beeam spot position at a given z value (it takes into account the dxdz slope)
0068     double x(const double z) const { return x0() + dxdz() * (z - z0()); }
0069     /// y coordinate of the beeam spot position at a given z value (it takes into account the dydz slope)
0070     double y(const double z) const { return y0() + dydz() * (z - z0()); }
0071     /// position of the beam spot at a given z value (it takes into account the dxdz and dydz slopes)
0072     const Point position(const double z) const;
0073     //    const Point position(const double z) const {Point pos(x(z),y(z),z);    return pos;}
0074 
0075     /// sigma z
0076     double sigmaZ() const { return sigmaZ_; }
0077     /// dxdz slope
0078     double dxdz() const { return dxdz_; }
0079     /// dydz slope
0080     double dydz() const { return dydz_; }
0081     /// beam width X
0082     double BeamWidthX() const { return BeamWidthX_; }
0083     /// beam width Y
0084     double BeamWidthY() const { return BeamWidthY_; }
0085     /// error on x
0086     double x0Error() const { return sqrt(error_(0, 0)); }
0087     /// error on y
0088     double y0Error() const { return sqrt(error_(1, 1)); }
0089     /// error on z
0090     double z0Error() const { return sqrt(error_(2, 2)); }
0091     /// error on sigma z
0092     double sigmaZ0Error() const { return sqrt(error_(3, 3)); }
0093     /// error on dxdz
0094     double dxdzError() const { return sqrt(error_(4, 4)); }
0095     /// error on dydz
0096     double dydzError() const { return sqrt(error_(5, 5)); }
0097 
0098     /// error on beam width X, assume error in X = Y
0099     double BeamWidthXError() const { return sqrt(error_(6, 6)); }
0100     /// error on beam width Y, assume error in X = Y
0101     double BeamWidthYError() const { return sqrt(error_(6, 6)); }
0102 
0103     ///
0104     void setBeamWidthX(double v) { BeamWidthX_ = v; }
0105     void setBeamWidthY(double v) { BeamWidthY_ = v; }
0106 
0107     /// (i,j)-th element of error matrix
0108     double covariance(int i, int j) const { return error_(i, j); }
0109     /// return full covariance matrix of dim 7
0110     CovarianceMatrix covariance() const { return error_; }
0111     /// return only 3D position covariance matrix
0112     Covariance3DMatrix covariance3D() const {
0113       Covariance3DMatrix matrix;
0114       for (int j = 0; j < 3; j++) {
0115         for (int k = j; k < 3; k++) {
0116           matrix(j, k) = error_(j, k);
0117         }
0118       }
0119       return matrix;
0120     };
0121     /// return beam type
0122     BeamType type() const { return type_; }
0123     /// set beam type
0124     void setType(BeamType type) { type_ = type; }
0125     ///
0126     Covariance3DMatrix rotatedCovariance3D() const;
0127 
0128     /// additional information
0129     double emittanceX() const { return emittanceX_; }
0130     double emittanceY() const { return emittanceY_; }
0131     double betaStar() const { return betaStar_; }
0132     double beamWidthFromBeta(double z, double e) const {
0133       return sqrt(e * betaStar_ * (1 + pow((z - position_.Z()) / betaStar_, 2)));
0134     }
0135     ///
0136     void setEmittanceX(double v) { emittanceX_ = v; }
0137     void setEmittanceY(double v) { emittanceY_ = v; }
0138     void setbetaStar(double v) { betaStar_ = v; }
0139 
0140     /// print information
0141     void print(std::stringstream& ss) const;
0142 
0143   private:
0144     /// position
0145     Point position_;
0146     /// errors
0147     CovarianceMatrix error_;
0148 
0149     Double32_t sigmaZ_;
0150     Double32_t BeamWidthX_;
0151     Double32_t BeamWidthY_;
0152     Double32_t dxdz_;
0153     Double32_t dydz_;
0154     Double32_t emittanceX_;
0155     Double32_t emittanceY_;
0156     Double32_t betaStar_;
0157 
0158     BeamType type_;
0159   };
0160   ///
0161   std::ostream& operator<<(std::ostream&, BeamSpot beam);
0162 
0163 }  // namespace reco
0164 
0165 #endif