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
Vector3DBase< float, LocalTag >
DDAxes::y
MuonSegFit::setChi2
void setChi2(void)
Definition: MuonSegFit.cc:229
MuonSegFit::hits_
MuonRecHitContainer hits_
Definition: MuonSegFit.h:114
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
MuonSegFit::ndof_
int ndof_
Definition: MuonSegFit.h:120
MuonSegFit::chi2
double chi2(void) const
Definition: MuonSegFit.h:89
MuonSegFit::Rdev
float Rdev(float x, float y, float z) const
Definition: MuonSegFit.cc:466
MuonSegFit::ydev
float ydev(float y, float z) const
Definition: MuonSegFit.cc:464
MuonSegFit::fitdone_
bool fitdone_
Definition: MuonSegFit.h:122
MuonSegFit::MuonRecHitContainer
std::vector< MuonRecHitPtr > MuonRecHitContainer
Definition: MuonSegFit.h:39
MuonSegFit::covarianceMatrix
AlgebraicSymMatrix covarianceMatrix(void)
Definition: MuonSegFit.cc:359
MuonSegFit::MuonSegFit
MuonSegFit(MuonRecHitContainer hits)
Definition: MuonSegFit.h:62
MuonSegFit::setScaleXError
void setScaleXError(double factor)
Definition: MuonSegFit.h:74
DDAxes::x
MuonSegFit::scaleXError_
double scaleXError_
Definition: MuonSegFit.h:121
MuonSegFit::hits
MuonRecHitContainer hits(void) const
Definition: MuonSegFit.h:86
MuonSegFit::fit2
void fit2(void)
Definition: MuonSegFit.cc:29
MuonSegFit::uslope_
float uslope_
Definition: MuonSegFit.h:115
TrackingRecHit.h
MuonSegFit::SMatrixSym12
ROOT::Math::SMatrix< double, MaxHits2, MaxHits2, ROOT::Math::MatRepSym< double, MaxHits2 > > SMatrixSym12
Definition: MuonSegFit.h:43
DDAxes::z
DQMScaleToClient_cfi.factor
factor
Definition: DQMScaleToClient_cfi.py:8
MuonSegFit::MaxHits2
static const int MaxHits2
Definition: MuonSegFit.h:41
MuonSegFit::fitdone
bool fitdone() const
Definition: MuonSegFit.h:93
Point3DBase< float, LocalTag >
MuonSegFit::fitlsq
void fitlsq(void)
Definition: MuonSegFit.cc:76
MuonSegFit::localdir
LocalVector localdir() const
Definition: MuonSegFit.h:92
MuonSegFit::SMatrix12by4
ROOT::Math::SMatrix< double, MaxHits2, 4 > SMatrix12by4
Definition: MuonSegFit.h:46
MuonSegFit::nhits
size_t nhits(void) const
Definition: MuonSegFit.h:88
MuonSegFit::localdir_
LocalVector localdir_
Definition: MuonSegFit.h:118
MuonSegFit::intercept
LocalPoint intercept() const
Definition: MuonSegFit.h:91
MuonSegFit::flipErrors
AlgebraicSymMatrix flipErrors(const SMatrixSym4 &)
Definition: MuonSegFit.cc:392
MuonSegFit::MuonRecHitPtr
std::shared_ptr< TrackingRecHit > MuonRecHitPtr
Definition: MuonSegFit.h:38
MuonSegFit::xfit
float xfit(float z) const
Definition: MuonSegFit.cc:454
MuonSegFit
Definition: MuonSegFit.h:34
MuonSegFit::intercept_
LocalPoint intercept_
Definition: MuonSegFit.h:117
MuonSegFit::SMatrix4
ROOT::Math::SMatrix< double, 4 > SMatrix4
Definition: MuonSegFit.h:49
MuonSegFit::yfit
float yfit(float z) const
Definition: MuonSegFit.cc:460
AlgebraicSymMatrix
CLHEP::HepSymMatrix AlgebraicSymMatrix
Definition: AlgebraicObjects.h:15
MuonSegFit::derivativeMatrix
SMatrix12by4 derivativeMatrix(void)
Definition: MuonSegFit.cc:320
MuonSegFit::weightMatrix
SMatrixSym12 weightMatrix(void)
Definition: MuonSegFit.cc:295
MuonSegFit::vslope_
float vslope_
Definition: MuonSegFit.h:116
MuonSegFit::~MuonSegFit
virtual ~MuonSegFit()
Definition: MuonSegFit.h:65
MuonSegFit::scaleXError
double scaleXError(void) const
Definition: MuonSegFit.h:87
MuonSegFit::ndof
int ndof(void) const
Definition: MuonSegFit.h:90
MuonSegFit::SVector4
ROOT::Math::SVector< double, 4 > SVector4
Definition: MuonSegFit.h:56
MuonSegFit::fit
bool fit(void)
Definition: MuonSegFit.cc:13
MuonSegFit::setOutFromIP
void setOutFromIP(void)
Definition: MuonSegFit.cc:339
MuonSegFit::SMatrixSym4
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > SMatrixSym4
Definition: MuonSegFit.h:50
MuonSegFit::chi2_
double chi2_
Definition: MuonSegFit.h:119
MuonSegFit::SMatrixSym2
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > SMatrixSym2
Definition: MuonSegFit.h:53
MuonSegFit::xdev
float xdev(float x, float z) const
Definition: MuonSegFit.cc:462