Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:24:42

0001 #ifndef CSCSegment_CSCSegFit_h
0002 #define CSCSegment_CSCSegFit_h
0003 
0004 // CSCSegFit.h  - Segment fitting factored out of CSC segment builders - Tim Cox
0005 // Last mod: 03.02.2015
0006 
0007 /* This as an object which is initialized by a set of rechits (2 to 6) in a 
0008  * specific CSC and has the functionality to make a least squares fit to a 
0009  * straight line in 2-dim for those rechits.
0010  * The covariance matrix and chi2 of the fit are calculated.
0011  * The original code made use of CLHEP matrices but this version uses 
0012  * ROOT SMatrices because they are  multithreading compatible.
0013  * Because of this, the no. of rechits that can be handled is limited to
0014  * a maximum of 6, one per layer of a CSC. This means maximum dimensions
0015  * can be specified at compile time and hence satisfies SMatrix constraints.
0016  * For 2 hits of course there is no fit - just draw a straight line between them.
0017  * Details of the algorithm are in the .cc file
0018  *
0019  */
0020 
0021 #include <DataFormats/CSCRecHit/interface/CSCRecHit2D.h>
0022 #include <Geometry/CSCGeometry/interface/CSCChamber.h>
0023 
0024 #include <Math/Functions.h>
0025 #include <Math/SVector.h>
0026 #include <Math/SMatrix.h>
0027 
0028 #include <vector>
0029 
0030 class CSCSegFit {
0031 public:
0032   // TYPES
0033 
0034   typedef std::vector<const CSCRecHit2D*> CSCSetOfHits;
0035 
0036   // 12 x12 Symmetric
0037   typedef ROOT::Math::SMatrix<double, 12, 12, ROOT::Math::MatRepSym<double, 12> > SMatrixSym12;
0038 
0039   // 12 x 4
0040   typedef ROOT::Math::SMatrix<double, 12, 4> SMatrix12by4;
0041 
0042   // 4 x 4 General + Symmetric
0043   typedef ROOT::Math::SMatrix<double, 4> SMatrix4;
0044   typedef ROOT::Math::SMatrix<double, 4, 4, ROOT::Math::MatRepSym<double, 4> > SMatrixSym4;
0045 
0046   // 2 x 2 Symmetric
0047   typedef ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
0048 
0049   // 4-dim vector
0050   typedef ROOT::Math::SVector<double, 4> SVector4;
0051 
0052   // PUBLIC FUNCTIONS
0053 
0054   //@@ WANT OBJECT TO CACHE THE SET OF HITS SO CANNOT PASS BY REF
0055   CSCSegFit(const CSCChamber* csc, CSCSetOfHits hits)
0056       : chamber_(csc), hits_(hits), scaleXError_(1.0), fitdone_(false) {}
0057 
0058   virtual ~CSCSegFit() {}
0059 
0060   // Least-squares fit
0061   void fit(void);  // fill uslope_, vslope_, intercept_  @@ FKA fitSlopes()
0062   // Calculate covariance matrix of fitted parameters
0063   AlgebraicSymMatrix covarianceMatrix(void);
0064 
0065   // Change scale factor of rechit x error
0066   // - expert use only!
0067   void setScaleXError(double factor) { scaleXError_ = factor; }
0068 
0069   // Fit values
0070   float xfit(float z) const;
0071   float yfit(float z) const;
0072 
0073   // Deviations from fit for given input (local w.r.t. chamber)
0074   float xdev(float x, float z) const;
0075   float ydev(float y, float z) const;
0076   float Rdev(float x, float y, float z) const;
0077 
0078   // Other public functions are accessors
0079   CSCSetOfHits hits(void) const { return hits_; }
0080   double scaleXError(void) const { return scaleXError_; }
0081   size_t nhits(void) const { return hits_.size(); }
0082   double chi2(void) const { return chi2_; }
0083   int ndof(void) const { return ndof_; }
0084   LocalPoint intercept() const { return intercept_; }
0085   LocalVector localdir() const { return localdir_; }
0086   const CSCChamber* chamber() const { return chamber_; }
0087   bool fitdone() const { return fitdone_; }
0088 
0089 private:
0090   // PRIVATE FUNCTIONS
0091 
0092   void fit2(void);     // fit for 2 hits
0093   void fitlsq(void);   // least-squares fit for 3-6 hits
0094   void setChi2(void);  // fill chi2_ & ndof_ @@ FKA fillChiSquared()
0095 
0096 protected:
0097   // PROTECTED FUNCTIONS - derived class needs access
0098 
0099   // Set segment direction 'out' from IP
0100   void setOutFromIP(void);  // fill localdir_  @@ FKA fillLocalDirection()
0101 
0102   SMatrix12by4 derivativeMatrix(void);
0103   SMatrixSym12 weightMatrix(void);
0104   AlgebraicSymMatrix flipErrors(const SMatrixSym4&);
0105 
0106   // PROTECTED MEMBER VARIABLES - derived class needs access
0107 
0108   const CSCChamber* chamber_;
0109   CSCSetOfHits hits_;     //@@ FKA protoSegment
0110   float uslope_;          //@@ FKA protoSlope_u
0111   float vslope_;          //@@ FKA protoSlope_v
0112   LocalPoint intercept_;  //@@ FKA protoIntercept
0113   LocalVector localdir_;  //@@ FKA protoDirection
0114   double chi2_;           //@@ FKA protoChi2
0115   int ndof_;              //@@ FKA protoNDF, which was double!!
0116   double scaleXError_;
0117   bool fitdone_;
0118 };
0119 
0120 #endif