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 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
Vector3DBase< float, LocalTag >
CSCSegFit::chamber
const CSCChamber * chamber() const
Definition: CSCSegFit.h:86
CSCSegFit::vslope_
float vslope_
Definition: CSCSegFit.h:111
DDAxes::y
CSCSegFit::fit2
void fit2(void)
Definition: CSCSegFit.cc:35
funct::false
false
Definition: Factorize.h:34
CSCSegFit::hits
CSCSetOfHits hits(void) const
Definition: CSCSegFit.h:79
CSCSegFit::weightMatrix
SMatrixSym12 weightMatrix(void)
Definition: CSCSegFit.cc:282
CSCSegFit::SMatrixSym4
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > SMatrixSym4
Definition: CSCSegFit.h:44
CSCSegFit::uslope_
float uslope_
Definition: CSCSegFit.h:110
CSCSegFit::covarianceMatrix
AlgebraicSymMatrix covarianceMatrix(void)
Definition: CSCSegFit.cc:352
CSCSegFit::chamber_
const CSCChamber * chamber_
Definition: CSCSegFit.h:108
CSCSegFit::scaleXError_
double scaleXError_
Definition: CSCSegFit.h:116
CSCSegFit::derivativeMatrix
SMatrix12by4 derivativeMatrix(void)
Definition: CSCSegFit.cc:310
CSCSegFit
Definition: CSCSegFit.h:30
CSCSegFit::localdir
LocalVector localdir() const
Definition: CSCSegFit.h:85
DDAxes::x
CSCSegFit::fit
void fit(void)
Definition: CSCSegFit.cc:13
CSCSegFit::fitdone_
bool fitdone_
Definition: CSCSegFit.h:117
CSCSegFit::setOutFromIP
void setOutFromIP(void)
Definition: CSCSegFit.cc:331
CSCSegFit::Rdev
float Rdev(float x, float y, float z) const
Definition: CSCSegFit.cc:438
csc
Definition: L1Track.h:19
CSCSegFit::SMatrixSym12
ROOT::Math::SMatrix< double, 12, 12, ROOT::Math::MatRepSym< double, 12 > > SMatrixSym12
Definition: CSCSegFit.h:37
CSCSegFit::SMatrix4
ROOT::Math::SMatrix< double, 4 > SMatrix4
Definition: CSCSegFit.h:43
CSCSegFit::CSCSetOfHits
std::vector< const CSCRecHit2D * > CSCSetOfHits
Definition: CSCSegFit.h:34
CSCSegFit::ndof
int ndof(void) const
Definition: CSCSegFit.h:83
CSCSegFit::ydev
float ydev(float y, float z) const
Definition: CSCSegFit.cc:436
CSCSegFit::flipErrors
AlgebraicSymMatrix flipErrors(const SMatrixSym4 &)
Definition: CSCSegFit.cc:378
DDAxes::z
CSCChamber
Definition: CSCChamber.h:22
DQMScaleToClient_cfi.factor
factor
Definition: DQMScaleToClient_cfi.py:8
Point3DBase< float, LocalTag >
CSCSegFit::chi2
double chi2(void) const
Definition: CSCSegFit.h:82
CSCSegFit::SMatrix12by4
ROOT::Math::SMatrix< double, 12, 4 > SMatrix12by4
Definition: CSCSegFit.h:40
CSCSegFit::setScaleXError
void setScaleXError(double factor)
Definition: CSCSegFit.h:67
CSCSegFit::fitdone
bool fitdone() const
Definition: CSCSegFit.h:87
CSCSegFit::setChi2
void setChi2(void)
Definition: CSCSegFit.cc:236
CSCSegFit::xdev
float xdev(float x, float z) const
Definition: CSCSegFit.cc:434
CSCSegFit::~CSCSegFit
virtual ~CSCSegFit()
Definition: CSCSegFit.h:58
CSCSegFit::yfit
float yfit(float z) const
Definition: CSCSegFit.cc:432
CSCSegFit::ndof_
int ndof_
Definition: CSCSegFit.h:115
AlgebraicSymMatrix
CLHEP::HepSymMatrix AlgebraicSymMatrix
Definition: AlgebraicObjects.h:15
CSCSegFit::SVector4
ROOT::Math::SVector< double, 4 > SVector4
Definition: CSCSegFit.h:50
CSCSegFit::nhits
size_t nhits(void) const
Definition: CSCSegFit.h:81
CSCSegFit::fitlsq
void fitlsq(void)
Definition: CSCSegFit.cc:83
CSCSegFit::hits_
CSCSetOfHits hits_
Definition: CSCSegFit.h:109
CSCSegFit::CSCSegFit
CSCSegFit(const CSCChamber *csc, CSCSetOfHits hits)
Definition: CSCSegFit.h:55
CSCSegFit::chi2_
double chi2_
Definition: CSCSegFit.h:114
CSCSegFit::intercept_
LocalPoint intercept_
Definition: CSCSegFit.h:112
CSCRecHit2D.h
CSCSegFit::localdir_
LocalVector localdir_
Definition: CSCSegFit.h:113
CSCChamber.h
CSCSegFit::scaleXError
double scaleXError(void) const
Definition: CSCSegFit.h:80
CSCSegFit::SMatrixSym2
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > SMatrixSym2
Definition: CSCSegFit.h:47
CSCSegFit::xfit
float xfit(float z) const
Definition: CSCSegFit.cc:426
CSCSegFit::intercept
LocalPoint intercept() const
Definition: CSCSegFit.h:84