CMS 3D CMS Logo

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