CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 public:
32  // TYPES
33 
34  typedef std::vector<const CSCRecHit2D*> CSCSetOfHits;
35 
36  // 12 x12 Symmetric
37  typedef ROOT::Math::SMatrix<double, 12, 12, ROOT::Math::MatRepSym<double, 12> > SMatrixSym12;
38 
39  // 12 x 4
40  typedef ROOT::Math::SMatrix<double, 12, 4> SMatrix12by4;
41 
42  // 4 x 4 General + Symmetric
43  typedef ROOT::Math::SMatrix<double, 4> SMatrix4;
44  typedef ROOT::Math::SMatrix<double, 4, 4, ROOT::Math::MatRepSym<double, 4> > SMatrixSym4;
45 
46  // 2 x 2 Symmetric
47  typedef ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
48 
49  // 4-dim vector
50  typedef ROOT::Math::SVector<double, 4> SVector4;
51 
52  // PUBLIC FUNCTIONS
53 
54  //@@ WANT OBJECT TO CACHE THE SET OF HITS SO CANNOT PASS BY REF
57 
58  virtual ~CSCSegFit() {}
59 
60  // Least-squares fit
61  void fit(void); // fill uslope_, vslope_, intercept_ @@ FKA fitSlopes()
62  // Calculate covariance matrix of fitted parameters
64 
65  // Change scale factor of rechit x error
66  // - expert use only!
68 
69  // Fit values
70  float xfit(float z) const;
71  float yfit(float z) const;
72 
73  // Deviations from fit for given input (local w.r.t. chamber)
74  float xdev(float x, float z) const;
75  float ydev(float y, float z) const;
76  float Rdev(float x, float y, float z) const;
77 
78  // Other public functions are accessors
79  CSCSetOfHits hits(void) const { return hits_; }
80  double scaleXError(void) const { return scaleXError_; }
81  size_t nhits(void) const { return hits_.size(); }
82  double chi2(void) const { return chi2_; }
83  int ndof(void) const { return ndof_; }
84  LocalPoint intercept() const { return intercept_; }
85  LocalVector localdir() const { return localdir_; }
86  const CSCChamber* chamber() const { return chamber_; }
87  bool fitdone() const { return fitdone_; }
88 
89 private:
90  // PRIVATE FUNCTIONS
91 
92  void fit2(void); // fit for 2 hits
93  void fitlsq(void); // least-squares fit for 3-6 hits
94  void setChi2(void); // fill chi2_ & ndof_ @@ FKA fillChiSquared()
95 
96 protected:
97  // PROTECTED FUNCTIONS - derived class needs access
98 
99  // Set segment direction 'out' from IP
100  void setOutFromIP(void); // fill localdir_ @@ FKA fillLocalDirection()
101 
105 
106  // PROTECTED MEMBER VARIABLES - derived class needs access
107 
109  CSCSetOfHits hits_; //@@ FKA protoSegment
110  float uslope_; //@@ FKA protoSlope_u
111  float vslope_; //@@ FKA protoSlope_v
112  LocalPoint intercept_; //@@ FKA protoIntercept
113  LocalVector localdir_; //@@ FKA protoDirection
114  double chi2_; //@@ FKA protoChi2
115  int ndof_; //@@ FKA protoNDF, which was double!!
116  double scaleXError_;
117  bool fitdone_;
118 };
119 
120 #endif
ROOT::Math::SMatrix< double, 12, 12, ROOT::Math::MatRepSym< double, 12 > > SMatrixSym12
Definition: CSCSegFit.h:37
LocalPoint intercept_
Definition: CSCSegFit.h:112
void fit(void)
Definition: CSCSegFit.cc:13
double chi2(void) const
Definition: CSCSegFit.h:82
void fit2(void)
Definition: CSCSegFit.cc:35
LocalVector localdir_
Definition: CSCSegFit.h:113
void fitlsq(void)
Definition: CSCSegFit.cc:83
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > SMatrixSym4
Definition: CSCSegFit.h:44
double scaleXError_
Definition: CSCSegFit.h:116
AlgebraicSymMatrix flipErrors(const SMatrixSym4 &)
Definition: CSCSegFit.cc:378
LocalPoint intercept() const
Definition: CSCSegFit.h:84
CSCSegFit(const CSCChamber *csc, CSCSetOfHits hits)
Definition: CSCSegFit.h:55
double chi2_
Definition: CSCSegFit.h:114
int ndof(void) const
Definition: CSCSegFit.h:83
float vslope_
Definition: CSCSegFit.h:111
float ydev(float y, float z) const
Definition: CSCSegFit.cc:436
ROOT::Math::SVector< double, 4 > SVector4
Definition: CSCSegFit.h:50
float yfit(float z) const
Definition: CSCSegFit.cc:432
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > SMatrixSym2
Definition: CSCSegFit.h:47
bool fitdone() const
Definition: CSCSegFit.h:87
const CSCChamber * chamber() const
Definition: CSCSegFit.h:86
bool fitdone_
Definition: CSCSegFit.h:117
ROOT::Math::SMatrix< double, 4 > SMatrix4
Definition: CSCSegFit.h:43
const CSCChamber * chamber_
Definition: CSCSegFit.h:108
Definition: L1Track.h:19
float xdev(float x, float z) const
Definition: CSCSegFit.cc:434
CSCSetOfHits hits_
Definition: CSCSegFit.h:109
AlgebraicSymMatrix covarianceMatrix(void)
Definition: CSCSegFit.cc:352
void setOutFromIP(void)
Definition: CSCSegFit.cc:331
std::vector< const CSCRecHit2D * > CSCSetOfHits
Definition: CSCSegFit.h:34
void setScaleXError(double factor)
Definition: CSCSegFit.h:67
SMatrixSym12 weightMatrix(void)
Definition: CSCSegFit.cc:282
float xfit(float z) const
Definition: CSCSegFit.cc:426
SMatrix12by4 derivativeMatrix(void)
Definition: CSCSegFit.cc:310
virtual ~CSCSegFit()
Definition: CSCSegFit.h:58
CLHEP::HepSymMatrix AlgebraicSymMatrix
ROOT::Math::SMatrix< double, 12, 4 > SMatrix12by4
Definition: CSCSegFit.h:40
LocalVector localdir() const
Definition: CSCSegFit.h:85
CSCSetOfHits hits(void) const
Definition: CSCSegFit.h:79
size_t nhits(void) const
Definition: CSCSegFit.h:81
double scaleXError(void) const
Definition: CSCSegFit.h:80
float Rdev(float x, float y, float z) const
Definition: CSCSegFit.cc:438
float uslope_
Definition: CSCSegFit.h:110
int ndof_
Definition: CSCSegFit.h:115
void setChi2(void)
Definition: CSCSegFit.cc:236