Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:12

0001 /*
0002  *
0003 * This is a part of CTPPS offline software.
0004 * Author:
0005 *   Fabrizio Ferro (ferro@ge.infn.it)
0006 *   Enrico Robutti (robutti@ge.infn.it)
0007 *   Fabio Ravera   (fabio.ravera@cern.ch)
0008 *
0009 */
0010 
0011 #ifndef DataFormats_CTPPSReco_CTPPSPixelLocalTrack_H
0012 #define DataFormats_CTPPSReco_CTPPSPixelLocalTrack_H
0013 
0014 #include "DataFormats/Common/interface/DetSetVector.h"
0015 #include "DataFormats/CTPPSReco/interface/CTPPSPixelRecHit.h"
0016 #include "DataFormats/CTPPSDetId/interface/CTPPSPixelDetId.h"
0017 
0018 #include "DataFormats/Math/interface/Vector.h"
0019 #include "DataFormats/Math/interface/Error.h"
0020 #include "DataFormats/Math/interface/Matrix.h"
0021 #include "DataFormats/Math/interface/AlgebraicROOTObjects.h"
0022 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0023 
0024 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0025 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0026 
0027 #include "DataFormats/CTPPSReco/interface/CTPPSPixelLocalTrackRecoInfo.h"
0028 //----------------------------------------------------------------------------------------------------
0029 
0030 class CTPPSPixelFittedRecHit : public CTPPSPixelRecHit {
0031 public:
0032   CTPPSPixelFittedRecHit(const CTPPSPixelRecHit& hit,
0033                          const GlobalPoint& space_point_on_det,
0034                          const LocalPoint& residual,
0035                          const LocalPoint& pull)
0036       : CTPPSPixelRecHit(hit),
0037         space_point_on_det_(space_point_on_det),
0038         residual_(residual),
0039         pull_(pull),
0040         isUsedForFit_(false),
0041         isRealHit_(false) {}
0042 
0043   CTPPSPixelFittedRecHit()
0044       : CTPPSPixelRecHit(),
0045         residual_(LocalPoint(0, 0)),
0046         pull_(LocalPoint(0, 0)),
0047         isUsedForFit_(false),
0048         isRealHit_(false) {}
0049 
0050   virtual ~CTPPSPixelFittedRecHit() {}
0051 
0052   inline const GlobalPoint& globalCoordinates() const { return space_point_on_det_; }
0053   inline float xResidual() const { return residual_.x(); }
0054   inline float yResidual() const { return residual_.y(); }
0055 
0056   inline float xPull() const { return pull_.x(); }
0057   inline float yPull() const { return pull_.y(); }
0058 
0059   inline float xPullNormalization() const { return residual_.x() / pull_.x(); }
0060   inline float yPullNormalization() const { return residual_.y() / pull_.y(); }
0061 
0062   inline void setIsUsedForFit(bool usedForFit) {
0063     if (usedForFit)
0064       isRealHit_ = true;
0065     isUsedForFit_ = usedForFit;
0066   }
0067   inline bool isUsedForFit() const { return isUsedForFit_; }
0068 
0069   inline void setIsRealHit(bool realHit) {
0070     if (!realHit)
0071       isUsedForFit_ = false;
0072     isRealHit_ = realHit;
0073   }
0074   inline bool isRealHit() const { return isRealHit_; }
0075 
0076 private:
0077   GlobalPoint space_point_on_det_;  ///< mm
0078   LocalPoint residual_;             ///< mm
0079   LocalPoint pull_;                 ///< normalised residual
0080   bool isUsedForFit_;
0081   bool isRealHit_;
0082 };
0083 
0084 class CTPPSPixelLocalTrack {
0085 public:
0086   enum class TrackPar { x0 = 0, y0 = 1, tx = 2, ty = 3 };
0087 
0088   ///< parameter vector size
0089   static constexpr int dimension = 4;
0090   typedef math::Error<dimension>::type CovarianceMatrix;
0091   typedef math::Vector<dimension>::type ParameterVector;
0092 
0093   ///< covariance matrix size
0094   static constexpr int covarianceSize = dimension * dimension;
0095 
0096   CTPPSPixelLocalTrack()
0097       : z0_(0),
0098         chiSquared_(0),
0099         valid_(false),
0100         numberOfPointsUsedForFit_(0),
0101         recoInfo_(CTPPSpixelLocalTrackReconstructionInfo::invalid) {}
0102 
0103   CTPPSPixelLocalTrack(float z0,
0104                        const ParameterVector& track_params_vector,
0105                        const CovarianceMatrix& par_covariance_matrix,
0106                        float chiSquared);
0107 
0108   ~CTPPSPixelLocalTrack() {}
0109 
0110   inline const edm::DetSetVector<CTPPSPixelFittedRecHit>& hits() const { return track_hits_vector_; }
0111   inline void addHit(unsigned int detId, const CTPPSPixelFittedRecHit& hit) {
0112     track_hits_vector_.find_or_insert(detId).push_back(hit);
0113     if (hit.isUsedForFit())
0114       ++numberOfPointsUsedForFit_;
0115   }
0116 
0117   inline float x0() const { return track_params_vector_[(unsigned int)TrackPar::x0]; }
0118   inline float x0Sigma() const {
0119     return sqrt(par_covariance_matrix_[(unsigned int)TrackPar::x0][(unsigned int)TrackPar::x0]);
0120   }
0121   inline float x0Variance() const {
0122     return par_covariance_matrix_[(unsigned int)TrackPar::x0][(unsigned int)TrackPar::x0];
0123   }
0124 
0125   inline float y0() const { return track_params_vector_[(unsigned int)TrackPar::y0]; }
0126   inline float y0Sigma() const {
0127     return sqrt(par_covariance_matrix_[(unsigned int)TrackPar::y0][(unsigned int)TrackPar::y0]);
0128   }
0129   inline float y0Variance() const {
0130     return par_covariance_matrix_[(unsigned int)TrackPar::y0][(unsigned int)TrackPar::y0];
0131   }
0132 
0133   inline float z0() const { return z0_; }
0134   inline void setZ0(float z0) { z0_ = z0; }
0135 
0136   inline float tx() const { return track_params_vector_[(unsigned int)TrackPar::tx]; }
0137   inline float txSigma() const {
0138     return sqrt(par_covariance_matrix_[(unsigned int)TrackPar::tx][(unsigned int)TrackPar::tx]);
0139   }
0140 
0141   inline float ty() const { return track_params_vector_[(unsigned int)TrackPar::ty]; }
0142   inline float tySigma() const {
0143     return sqrt(par_covariance_matrix_[(unsigned int)TrackPar::ty][(unsigned int)TrackPar::ty]);
0144   }
0145 
0146   inline GlobalVector directionVector() const {
0147     GlobalVector vect(tx(), ty(), 1);
0148     return vect.unit();
0149   }
0150 
0151   inline const ParameterVector& parameterVector() const { return track_params_vector_; }
0152 
0153   inline const CovarianceMatrix& covarianceMatrix() const { return par_covariance_matrix_; }
0154 
0155   inline float chiSquared() const { return chiSquared_; }
0156 
0157   inline float chiSquaredOverNDF() const {
0158     if (numberOfPointsUsedForFit_ <= dimension / 2)
0159       return -999.;
0160     else
0161       return chiSquared_ / (2 * numberOfPointsUsedForFit_ - dimension);
0162   }
0163 
0164   inline int ndf() const { return (2 * numberOfPointsUsedForFit_ - dimension); }
0165 
0166   /// returns the point from which the track is passing by at the selected z
0167   inline GlobalPoint trackPoint(float z) const {
0168     float delta_z = z - z0_;
0169     return GlobalPoint(
0170         track_params_vector_[(unsigned int)TrackPar::x0] + track_params_vector_[(unsigned int)TrackPar::tx] * delta_z,
0171         track_params_vector_[(unsigned int)TrackPar::y0] + track_params_vector_[(unsigned int)TrackPar::ty] * delta_z,
0172         z);
0173   }
0174 
0175   inline GlobalPoint trackCentrePoint() {
0176     return GlobalPoint(
0177         track_params_vector_[(unsigned int)TrackPar::x0], track_params_vector_[(unsigned int)TrackPar::y0], z0_);
0178   }
0179 
0180   AlgebraicSymMatrix22 trackPointInterpolationCovariance(float z) const;
0181 
0182   inline bool isValid() const { return valid_; }
0183 
0184   inline void setValid(bool valid) { valid_ = valid; }
0185 
0186   bool operator<(const CTPPSPixelLocalTrack& r);
0187 
0188   inline CTPPSpixelLocalTrackReconstructionInfo recoInfo() const { return recoInfo_; }
0189   inline void setRecoInfo(CTPPSpixelLocalTrackReconstructionInfo recoInfo) { recoInfo_ = recoInfo; }
0190 
0191   inline unsigned short numberOfPointsUsedForFit() const { return numberOfPointsUsedForFit_; }
0192 
0193 private:
0194   edm::DetSetVector<CTPPSPixelFittedRecHit> track_hits_vector_;
0195 
0196   /// track parameters: (x0, y0, tx, ty); x = x0 + tx*(z-z0) ...
0197   ParameterVector track_params_vector_;
0198 
0199   /// z where x0 and y0 are evaluated.
0200   /// filled from TotemRPGeometry::GetRPGlobalTranslation
0201   float z0_;
0202 
0203   CovarianceMatrix par_covariance_matrix_;
0204 
0205   /// fit chi^2
0206   float chiSquared_;
0207 
0208   /// fit valid?
0209   bool valid_;
0210 
0211   /// number of points used for the track fit
0212   int numberOfPointsUsedForFit_;
0213 
0214   CTPPSpixelLocalTrackReconstructionInfo recoInfo_;
0215 };
0216 
0217 #endif