Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:22

0001 #ifndef GUARD_surveypxbimagelocalfit_h
0002 #define GUARD_surveypxbimagelocalfit_h
0003 
0004 #include <sstream>
0005 #include <vector>
0006 #include <utility>
0007 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0008 #include "Alignment/SurveyAnalysis/interface/SurveyPxbImage.h"
0009 #include "Math/SMatrix.h"
0010 #include "Math/SVector.h"
0011 #include <iostream>
0012 
0013 //! Class to hold one picture of the BPix survey and the local fit
0014 class SurveyPxbImageLocalFit : public SurveyPxbImage {
0015 public:
0016   typedef std::vector<value_t> localpars_t;
0017   typedef std::vector<coord_t> fidpoint_t;
0018   typedef unsigned int count_t;
0019   static const count_t nGlD = 3;        // no of global derivs
0020   static const count_t nLcD = 4;        // no of local derivs
0021   static const count_t nMsrmts = 8;     // no of measurements per image
0022   static const count_t nLcPars = 4;     // no of local parameters
0023   static const count_t nFidpoints = 4;  // no of fiducial points
0024   // Typedefs for pede
0025   typedef int pede_label_t;
0026   typedef float pede_deriv_t;
0027 
0028   // Constructors
0029   SurveyPxbImageLocalFit()
0030       : SurveyPxbImage(), a_(nLcPars, 0), fidpoints_(nFidpoints), fitValidFlag_(false), derivsValidFlag_(false) {
0031     initFidPoints();
0032   };
0033 
0034   //! Constructor from istringstream
0035   SurveyPxbImageLocalFit(std::istringstream& iss)
0036       : SurveyPxbImage(iss), a_(nLcPars, 0), fidpoints_(nFidpoints), fitValidFlag_(false), derivsValidFlag_(false) {
0037     initFidPoints();
0038   };
0039 
0040   //! Invoke the fit
0041   void doFit(const fidpoint_t& fidpointvec);
0042   void doFit(const fidpoint_t& fidpointvec, const pede_label_t& label1, const pede_label_t& label2);
0043   void doFit(value_t x1, value_t y1, value_t g1, value_t x2, value_t y2, value_t g2);
0044 
0045   //! returns validity flag
0046   bool isFitValid() { return fitValidFlag_; };
0047 
0048   //! returns local parameters after fit
0049   localpars_t getLocalParameters();
0050 
0051   //! returns the chi^2 of the fit
0052   value_t getChi2();
0053 
0054   pede_label_t getLocalDerivsSize() { return nLcD; };
0055   pede_label_t getGlobalDerivsSize() { return nGlD; };
0056   const pede_deriv_t* getLocalDerivsPtr(count_t i) { return localDerivsMatrix_.Array() + i * nLcD; };
0057   const pede_deriv_t* getGlobalDerivsPtr(count_t i) { return globalDerivsMatrix_.Array() + i * nGlD; };
0058   const pede_label_t* getGlobalDerivsLabelPtr(count_t i) { return i < 4 ? &labelVec1_[0] : &labelVec2_[0]; };
0059   pede_deriv_t getResiduum(count_t i) { return (pede_deriv_t)r(i); };
0060   pede_deriv_t getSigma(count_t i) { return i % 2 ? sigma_x_ : sigma_y_; };
0061 
0062   void setLocalDerivsToZero(count_t i);
0063   void setGlobalDerivsToZero(count_t i);
0064 
0065 private:
0066   //! Local parameters
0067   localpars_t a_;
0068 
0069   //! Vector of residuals
0070   ROOT::Math::SVector<value_t, nMsrmts> r;
0071 
0072   //! Matrix with global derivs
0073   //std::vector<localDerivs_t> globalDerivsVec_;
0074   ROOT::Math::SMatrix<pede_deriv_t, nMsrmts, nGlD> globalDerivsMatrix_;
0075 
0076   //! Matrix with local derivs
0077   //std::vector<globalDerivs_t> localDerivsVec_;
0078   ROOT::Math::SMatrix<pede_deriv_t, nMsrmts, nLcD> localDerivsMatrix_;
0079 
0080   //! Vector with labels to global derivs
0081   std::vector<pede_label_t> labelVec1_, labelVec2_;
0082 
0083   //! True position of the fiducial points on a sensor wrt. local frame (u,v)
0084   std::vector<coord_t> fidpoints_;
0085 
0086   //! chi2 of the local fit
0087   value_t chi2_;
0088 
0089   //! Validity Flag
0090   bool fitValidFlag_;
0091 
0092   //!
0093   bool derivsValidFlag_;
0094 
0095   //! Initialise the fiducial points
0096   void initFidPoints() {
0097     fidpoints_[0] = coord_t(-0.91, -3.30);
0098     fidpoints_[1] = coord_t(+0.91, -3.30);
0099     fidpoints_[2] = coord_t(-0.91, +3.30);
0100     fidpoints_[3] = coord_t(+0.91, +3.30);
0101   }
0102 
0103   //! Distance
0104   value_t dist(const coord_t& p1, const coord_t& p2) {
0105     value_t dx = p1.x() - p2.x();
0106     value_t dy = p1.y() - p2.y();
0107     return sqrt(dx * dx + dy * dy);
0108   }
0109 };
0110 
0111 #endif