BeamSpot

BeamType

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
#ifndef BeamSpot_BeamSpot_h
#define BeamSpot_BeamSpot_h
/** \class reco::BeamSpot
 *  
 * Reconstructed beam spot object which provides position, error, and
 * width of the beam position.
 *
 * \author Francisco Yumiceva, Fermilab (yumiceva@fnal.gov)
 *
 *
 */

#include <Rtypes.h>
#include "DataFormats/Math/interface/Error.h"
#include "DataFormats/Math/interface/Point3D.h"
#include <string>
#include <sstream>

namespace reco {

  class BeamSpot {
  public:
    /// beam spot flags
    enum BeamType { Unknown = -1, Fake = 0, LHC = 1, Tracker = 2 };

    /// point in the space
    typedef math::XYZPoint Point;
    enum { dimension = 7 };
    typedef math::Error<dimension>::type CovarianceMatrix;
    enum { dim3 = 3 };
    typedef math::Error<dim3>::type Covariance3DMatrix;
    enum { resdim = 2 };
    typedef math::Error<resdim>::type ResCovMatrix;

    /// default constructor
    BeamSpot();

    /// constructor from values
    BeamSpot(const Point& point,
             double sigmaZ,
             double dxdz,
             double dydz,
             double BeamWidthX,
             const CovarianceMatrix& error,
             BeamType type = Unknown) {
      position_ = point;
      sigmaZ_ = sigmaZ;
      dxdz_ = dxdz;
      dydz_ = dydz;
      BeamWidthX_ = BeamWidthX;
      BeamWidthY_ = BeamWidthX;
      error_ = error;
      type_ = type;
      emittanceX_ = emittanceY_ = 0;
      betaStar_ = 0;
    };

    /// position
    const Point& position() const { return position_; }
    /// x coordinate
    double x0() const { return position_.X(); }
    /// y coordinate
    double y0() const { return position_.Y(); }
    /// z coordinate
    double z0() const { return position_.Z(); }

    /// x coordinate of the beeam spot position at a given z value (it takes into account the dxdz slope)
    double x(const double z) const { return x0() + dxdz() * (z - z0()); }
    /// y coordinate of the beeam spot position at a given z value (it takes into account the dydz slope)
    double y(const double z) const { return y0() + dydz() * (z - z0()); }
    /// position of the beam spot at a given z value (it takes into account the dxdz and dydz slopes)
    const Point position(const double z) const;
    //    const Point position(const double z) const {Point pos(x(z),y(z),z);    return pos;}

    /// sigma z
    double sigmaZ() const { return sigmaZ_; }
    /// dxdz slope
    double dxdz() const { return dxdz_; }
    /// dydz slope
    double dydz() const { return dydz_; }
    /// beam width X
    double BeamWidthX() const { return BeamWidthX_; }
    /// beam width Y
    double BeamWidthY() const { return BeamWidthY_; }
    /// error on x
    double x0Error() const { return sqrt(error_(0, 0)); }
    /// error on y
    double y0Error() const { return sqrt(error_(1, 1)); }
    /// error on z
    double z0Error() const { return sqrt(error_(2, 2)); }
    /// error on sigma z
    double sigmaZ0Error() const { return sqrt(error_(3, 3)); }
    /// error on dxdz
    double dxdzError() const { return sqrt(error_(4, 4)); }
    /// error on dydz
    double dydzError() const { return sqrt(error_(5, 5)); }

    /// error on beam width X, assume error in X = Y
    double BeamWidthXError() const { return sqrt(error_(6, 6)); }
    /// error on beam width Y, assume error in X = Y
    double BeamWidthYError() const { return sqrt(error_(6, 6)); }

    ///
    void setBeamWidthX(double v) { BeamWidthX_ = v; }
    void setBeamWidthY(double v) { BeamWidthY_ = v; }

    /// (i,j)-th element of error matrix
    double covariance(int i, int j) const { return error_(i, j); }
    /// return full covariance matrix of dim 7
    CovarianceMatrix covariance() const { return error_; }
    /// return only 3D position covariance matrix
    Covariance3DMatrix covariance3D() const {
      Covariance3DMatrix matrix;
      for (int j = 0; j < 3; j++) {
        for (int k = j; k < 3; k++) {
          matrix(j, k) = error_(j, k);
        }
      }
      return matrix;
    };
    /// return beam type
    BeamType type() const { return type_; }
    /// set beam type
    void setType(BeamType type) { type_ = type; }
    ///
    Covariance3DMatrix rotatedCovariance3D() const;

    /// additional information
    double emittanceX() const { return emittanceX_; }
    double emittanceY() const { return emittanceY_; }
    double betaStar() const { return betaStar_; }
    double beamWidthFromBeta(double z, double e) const {
      return sqrt(e * betaStar_ * (1 + pow((z - position_.Z()) / betaStar_, 2)));
    }
    ///
    void setEmittanceX(double v) { emittanceX_ = v; }
    void setEmittanceY(double v) { emittanceY_ = v; }
    void setbetaStar(double v) { betaStar_ = v; }

    /// print information
    void print(std::stringstream& ss) const;

  private:
    /// position
    Point position_;
    /// errors
    CovarianceMatrix error_;

    Double32_t sigmaZ_;
    Double32_t BeamWidthX_;
    Double32_t BeamWidthY_;
    Double32_t dxdz_;
    Double32_t dydz_;
    Double32_t emittanceX_;
    Double32_t emittanceY_;
    Double32_t betaStar_;

    BeamType type_;
  };
  ///
  std::ostream& operator<<(std::ostream&, BeamSpot beam);

}  // namespace reco

#endif