CMS 3D CMS Logo

CSCSegFit.h
Go to the documentation of this file.
1 #ifndef CSCSegment_CSCSegFit_h
2 #define CSCSegment_CSCSegFit_h
3 
4 // CSCSegFit.h - Segment fitting factored out of CSC segment builders - Tim Cox
5 // Last mod: 03.02.2015
6 
7 /* This as an object which is initialized by a set of rechits (2 to 6) in a
8  * specific CSC and has the functionality to make a least squares fit to a
9  * straight line in 2-dim for those rechits.
10  * The covariance matrix and chi2 of the fit are calculated.
11  * The original code made use of CLHEP matrices but this version uses
12  * ROOT SMatrices because they are multithreading compatible.
13  * Because of this, the no. of rechits that can be handled is limited to
14  * a maximum of 6, one per layer of a CSC. This means maximum dimensions
15  * can be specified at compile time and hence satisfies SMatrix constraints.
16  * For 2 hits of course there is no fit - just draw a straight line between them.
17  * Details of the algorithm are in the .cc file
18  *
19  */
20 
23 
24 #include <Math/Functions.h>
25 #include <Math/SVector.h>
26 #include <Math/SMatrix.h>
27 
28 #include <vector>
29 
30 class CSCSegFit {
31 
32 public:
33 
34 // TYPES
35 
36  typedef std::vector<const CSCRecHit2D*> CSCSetOfHits;
37 
38  // 12 x12 Symmetric
39  typedef ROOT::Math::SMatrix<double,12,12,ROOT::Math::MatRepSym<double,12> > SMatrixSym12;
40 
41  // 12 x 4
42  typedef ROOT::Math::SMatrix<double,12,4 > SMatrix12by4;
43 
44  // 4 x 4 General + Symmetric
45  typedef ROOT::Math::SMatrix<double, 4 > SMatrix4;
46  typedef ROOT::Math::SMatrix<double,4,4,ROOT::Math::MatRepSym<double,4> > SMatrixSym4;
47 
48  // 2 x 2 Symmetric
49  typedef ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2> > SMatrixSym2;
50 
51  // 4-dim vector
52  typedef ROOT::Math::SVector<double,4> SVector4;
53 
54 
55  // PUBLIC FUNCTIONS
56 
57  //@@ WANT OBJECT TO CACHE THE SET OF HITS SO CANNOT PASS BY REF
58  CSCSegFit( const CSCChamber* csc, CSCSetOfHits hits) :
59  chamber_( csc ), hits_( hits ), scaleXError_( 1.0 ), fitdone_( false ) {}
60 
61  virtual ~CSCSegFit() {}
62 
63  // Least-squares fit
64  void fit( void ); // fill uslope_, vslope_, intercept_ @@ FKA fitSlopes()
65  // Calculate covariance matrix of fitted parameters
67 
68  // Change scale factor of rechit x error
69  // - expert use only!
70  void setScaleXError ( double factor ) { scaleXError_ = factor; }
71 
72  // Fit values
73  float xfit( float z ) const;
74  float yfit( float z ) const;
75 
76  // Deviations from fit for given input (local w.r.t. chamber)
77  float xdev( float x, float z ) const;
78  float ydev ( float y, float z ) const;
79  float Rdev( float x, float y, float z ) const;
80 
81  // Other public functions are accessors
82  CSCSetOfHits hits(void) const { return hits_; }
83  double scaleXError(void) const { return scaleXError_; }
84  size_t nhits(void) const { return hits_.size(); }
85  double chi2(void) const { return chi2_; }
86  int ndof(void) const { return ndof_; }
87  LocalPoint intercept() const { return intercept_;}
88  LocalVector localdir() const { return localdir_;}
89  const CSCChamber* chamber() const { return chamber_; }
90  bool fitdone() const { return fitdone_; }
91 
92  private:
93 
94  // PRIVATE FUNCTIONS
95 
96  void fit2(void); // fit for 2 hits
97  void fitlsq(void); // least-squares fit for 3-6 hits
98  void setChi2(void); // fill chi2_ & ndof_ @@ FKA fillChiSquared()
99 
100 
101  protected:
102 
103  // PROTECTED FUNCTIONS - derived class needs access
104 
105  // Set segment direction 'out' from IP
106  void setOutFromIP(void); // fill localdir_ @@ FKA fillLocalDirection()
107 
108  SMatrix12by4 derivativeMatrix(void);
109  SMatrixSym12 weightMatrix(void);
110  AlgebraicSymMatrix flipErrors(const SMatrixSym4&);
111 
112  // PROTECTED MEMBER VARIABLES - derived class needs access
113 
115  CSCSetOfHits hits_; //@@ FKA protoSegment
116  float uslope_; //@@ FKA protoSlope_u
117  float vslope_; //@@ FKA protoSlope_v
118  LocalPoint intercept_; //@@ FKA protoIntercept
119  LocalVector localdir_; //@@ FKA protoDirection
120  double chi2_; //@@ FKA protoChi2
121  int ndof_; //@@ FKA protoNDF, which was double!!
122  double scaleXError_;
123  bool fitdone_;
124 };
125 
126 #endif
127 
LocalPoint intercept_
Definition: CSCSegFit.h:118
void fit(void)
Definition: CSCSegFit.cc:14
CSCSetOfHits hits(void) const
Definition: CSCSegFit.h:82
void fit2(void)
Definition: CSCSegFit.cc:35
LocalVector localdir_
Definition: CSCSegFit.h:119
LocalVector localdir() const
Definition: CSCSegFit.h:88
void fitlsq(void)
Definition: CSCSegFit.cc:85
ROOT::Math::SMatrix< double, 12, 4 > SMatrix12by4
Definition: CSCSegFit.h:42
double scaleXError_
Definition: CSCSegFit.h:122
AlgebraicSymMatrix flipErrors(const SMatrixSym4 &)
Definition: CSCSegFit.cc:406
CSCSegFit(const CSCChamber *csc, CSCSetOfHits hits)
Definition: CSCSegFit.h:58
double chi2_
Definition: CSCSegFit.h:120
float vslope_
Definition: CSCSegFit.h:117
float Rdev(float x, float y, float z) const
Definition: CSCSegFit.cc:473
bool fitdone() const
Definition: CSCSegFit.h:90
size_t nhits(void) const
Definition: CSCSegFit.h:84
double chi2(void) const
Definition: CSCSegFit.h:85
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > SMatrixSym4
Definition: CSCSegFit.h:46
bool fitdone_
Definition: CSCSegFit.h:123
ROOT::Math::SVector< double, 4 > SVector4
Definition: CSCSegFit.h:52
int ndof(void) const
Definition: CSCSegFit.h:86
const CSCChamber * chamber_
Definition: CSCSegFit.h:114
float xfit(float z) const
Definition: CSCSegFit.cc:455
ROOT::Math::SMatrix< double, 12, 12, ROOT::Math::MatRepSym< double, 12 > > SMatrixSym12
Definition: CSCSegFit.h:39
Definition: L1Track.h:19
CSCSetOfHits hits_
Definition: CSCSegFit.h:115
float xdev(float x, float z) const
Definition: CSCSegFit.cc:465
ROOT::Math::SMatrix< double, 4 > SMatrix4
Definition: CSCSegFit.h:45
AlgebraicSymMatrix covarianceMatrix(void)
Definition: CSCSegFit.cc:378
void setOutFromIP(void)
Definition: CSCSegFit.cc:355
std::vector< const CSCRecHit2D * > CSCSetOfHits
Definition: CSCSegFit.h:36
void setScaleXError(double factor)
Definition: CSCSegFit.h:70
float ydev(float y, float z) const
Definition: CSCSegFit.cc:469
const CSCChamber * chamber() const
Definition: CSCSegFit.h:89
SMatrixSym12 weightMatrix(void)
Definition: CSCSegFit.cc:298
LocalPoint intercept() const
Definition: CSCSegFit.h:87
SMatrix12by4 derivativeMatrix(void)
Definition: CSCSegFit.cc:331
virtual ~CSCSegFit()
Definition: CSCSegFit.h:61
CLHEP::HepSymMatrix AlgebraicSymMatrix
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > SMatrixSym2
Definition: CSCSegFit.h:49
float uslope_
Definition: CSCSegFit.h:116
int ndof_
Definition: CSCSegFit.h:121
double scaleXError(void) const
Definition: CSCSegFit.h:83
void setChi2(void)
Definition: CSCSegFit.cc:246
float yfit(float z) const
Definition: CSCSegFit.cc:461