test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ME0SegFit.h
Go to the documentation of this file.
1 #ifndef GEMSegment_ME0SegFit_h
2 #define GEMSegment_ME0SegFit_h
3 
4 // ME0SegFit.h - Segment fitting factored oout of ME0 segment builder based on
5 // CSCSegFit.h - Segment fitting factored out of CSC segment builders - Tim Cox
6 // Last mod: 03.02.2015
7 
8 
9 /* This as an object which is initialized by a set of rechits (2 to 6) in a
10  * specific ME0 chamber and has the functionality to make a least squares fit
11  * to a straight line in 2-dim for those rechits.
12  * The covariance matrix and chi2 of the fit are calculated.
13  * The original code made use of CLHEP matrices but this version uses
14  * ROOT SMatrices because they are multithreading compatible.
15  * Because of this, the no. of rechits that can be handled is limited to
16  * a maximum of 6, one per layer of a ME0 chamber. This means maximum dimensions
17  * can be specified at compile time and hence satisfies SMatrix constraints.
18  * This means that if at a later stage we would change the geometry to have
19  * for instance 10 detection layers, we will have to modify this code too.
20  * For 2 hits of course there is no fit - just draw a straight line between them.
21  * Details of the algorithm are in the .cc file
22  *
23  */
24 
28 
30 
31 #include <Math/Functions.h>
32 #include <Math/SVector.h>
33 #include <Math/SMatrix.h>
34 
35 #include <vector>
36 
37 class ME0SegFit {
38 
39 public:
40 
41 // TYPES
42 
43  typedef std::vector<const ME0RecHit*> ME0SetOfHits;
44 
45  // 12 x12 Symmetric
46  typedef ROOT::Math::SMatrix<double,12,12,ROOT::Math::MatRepSym<double,12> > SMatrixSym12;
47 
48  // 12 x 4
49  typedef ROOT::Math::SMatrix<double,12,4 > SMatrix12by4;
50 
51  // 4 x 4 General + Symmetric
52  typedef ROOT::Math::SMatrix<double, 4 > SMatrix4;
53  typedef ROOT::Math::SMatrix<double,4,4,ROOT::Math::MatRepSym<double,4> > SMatrixSym4;
54 
55  // 2 x 2 Symmetric
56  typedef ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2> > SMatrixSym2;
57 
58  // 4-dim vector
59  typedef ROOT::Math::SVector<double,4> SVector4;
60 
61 
62  // PUBLIC FUNCTIONS
63 
64  //@@ WANT OBJECT TO CACHE THE SET OF HITS SO CANNOT PASS BY REF
65  ME0SegFit( std::map<uint32_t, const ME0EtaPartition*> me0etapartmap, ME0SetOfHits hits) :
66  me0etapartmap_( me0etapartmap ), hits_( hits ), scaleXError_( 1.0 ), refid_(me0etapartmap_.begin()->first ), fitdone_( false )
67  {
68  // --- LogDebug info about reading of ME0 Eta Partition map ------------------------------------------
69  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::ctor] cached the me0etapartmap";
70 
71  // --- LogDebug for ME0 Eta Partition map ------------------------------------------------------------
72  std::stringstream gemetapartmapss; gemetapartmapss<<"[ME0SegFit::ctor] :: me0etapartmap :: elements ["<<std::endl;
73  for(std::map<uint32_t, const ME0EtaPartition*>::const_iterator mapIt = me0etapartmap_.begin(); mapIt != me0etapartmap_.end(); ++mapIt)
74  {
75  gemetapartmapss<<"[ME0 DetId "<<mapIt->first<<" ="<<ME0DetId(mapIt->first)<<", ME0 EtaPart "<<mapIt->second<<"],"<<std::endl;
76  }
77  gemetapartmapss<<"]"<<std::endl;
78  std::string gemetapartmapstr = gemetapartmapss.str();
79  edm::LogVerbatim("ME0SegFit") << gemetapartmapstr;
80  // --- End LogDebug -----------------------------------------------------------------------------------
81  }
82 
83  virtual ~ME0SegFit() {}
84 
85  // Least-squares fit
86  void fit( void ); // fill uslope_, vslope_, intercept_ @@ FKA fitSlopes()
87  // Calculate covariance matrix of fitted parameters
89 
90  // Change scale factor of rechit x error
91  // - expert use only!
92  void setScaleXError ( double factor ) { scaleXError_ = factor; }
93 
94  // Fit values
95  float xfit( float z ) const;
96  float yfit( float z ) const;
97 
98  // Deviations from fit for given input (local w.r.t. chamber)
99  float xdev( float x, float z ) const;
100  float ydev ( float y, float z ) const;
101  float Rdev( float x, float y, float z ) const;
102 
103  // Other public functions are accessors
104  ME0SetOfHits hits(void) const { return hits_; }
105  double scaleXError(void) const { return scaleXError_; }
106  size_t nhits(void) const { return hits_.size(); }
107  double chi2(void) const { return chi2_; }
108  int ndof(void) const { return ndof_; }
109  LocalPoint intercept() const { return intercept_;}
110  LocalVector localdir() const { return localdir_;}
111  const ME0EtaPartition* me0etapartition(uint32_t id) const { return me0etapartmap_.find(id)->second; }
112  const ME0EtaPartition* refme0etapart() const { return me0etapartmap_.find(refid_)->second; }
113  bool fitdone() const { return fitdone_; }
114 
115  private:
116 
117  // PRIVATE FUNCTIONS
118 
119  void fit2(void); // fit for 2 hits
120  void fitlsq(void); // least-squares fit for 3-6 hits
121  void setChi2(void); // fill chi2_ & ndof_ @@ FKA fillChiSquared()
122 
123 
124  protected:
125 
126  // PROTECTED FUNCTIONS - derived class needs access
127 
128  // Set segment direction 'out' from IP
129  void setOutFromIP(void); // fill localdir_ @@ FKA fillLocalDirection()
130 
134 
135  // PROTECTED MEMBER VARIABLES - derived class needs access
136 
137  // const ME0Chamber* chamber_;
138  std::map<uint32_t, const ME0EtaPartition*> me0etapartmap_;
139 
140  ME0SetOfHits hits_; //@@ FKA protoSegment
141  float uslope_; //@@ FKA protoSlope_u
142  float vslope_; //@@ FKA protoSlope_v
143  LocalPoint intercept_; //@@ FKA protoIntercept
144  LocalVector localdir_; //@@ FKA protoDirection
145  double chi2_; //@@ FKA protoChi2
146  int ndof_; //@@ FKA protoNDF, which was double!!
147  double scaleXError_;
148  uint32_t refid_;
149  bool fitdone_;
150 };
151 
152 #endif
153 
ROOT::Math::SVector< double, 4 > SVector4
Definition: ME0SegFit.h:59
bool fitdone() const
Definition: ME0SegFit.h:113
float ydev(float y, float z) const
Definition: ME0SegFit.cc:509
LocalPoint intercept() const
Definition: ME0SegFit.h:109
std::map< uint32_t, const ME0EtaPartition * > me0etapartmap_
Definition: ME0SegFit.h:138
float vslope_
Definition: ME0SegFit.h:142
LocalVector localdir_
Definition: ME0SegFit.h:144
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > SMatrixSym4
Definition: ME0SegFit.h:53
ROOT::Math::SMatrix< double, 4 > SMatrix4
Definition: ME0SegFit.h:52
int ndof(void) const
Definition: ME0SegFit.h:108
ROOT::Math::SMatrix< double, 12, 12, ROOT::Math::MatRepSym< double, 12 > > SMatrixSym12
Definition: ME0SegFit.h:46
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > SMatrixSym2
Definition: ME0SegFit.h:56
float Rdev(float x, float y, float z) const
Definition: ME0SegFit.cc:513
AlgebraicSymMatrix flipErrors(const SMatrixSym4 &)
Definition: ME0SegFit.cc:446
const ME0EtaPartition * me0etapartition(uint32_t id) const
Definition: ME0SegFit.h:111
void fitlsq(void)
Definition: ME0SegFit.cc:101
bool fitdone_
Definition: ME0SegFit.h:149
size_t nhits(void) const
Definition: ME0SegFit.h:106
AlgebraicSymMatrix covarianceMatrix(void)
Definition: ME0SegFit.cc:418
double chi2_
Definition: ME0SegFit.h:145
std::vector< const ME0RecHit * > ME0SetOfHits
Definition: ME0SegFit.h:43
ME0SetOfHits hits_
Definition: ME0SegFit.h:140
const ME0EtaPartition * refme0etapart() const
Definition: ME0SegFit.h:112
ROOT::Math::SMatrix< double, 12, 4 > SMatrix12by4
Definition: ME0SegFit.h:49
SMatrix12by4 derivativeMatrix(void)
Definition: ME0SegFit.cc:370
double scaleXError(void) const
Definition: ME0SegFit.h:105
void fit2(void)
Definition: ME0SegFit.cc:36
void setScaleXError(double factor)
Definition: ME0SegFit.h:92
float xfit(float z) const
Definition: ME0SegFit.cc:495
virtual ~ME0SegFit()
Definition: ME0SegFit.h:83
SMatrixSym12 weightMatrix(void)
Definition: ME0SegFit.cc:337
void setOutFromIP(void)
Definition: ME0SegFit.cc:395
void fit(void)
Definition: ME0SegFit.cc:15
LocalVector localdir() const
Definition: ME0SegFit.h:110
#define begin
Definition: vmac.h:30
ME0SetOfHits hits(void) const
Definition: ME0SegFit.h:104
LocalPoint intercept_
Definition: ME0SegFit.h:143
CLHEP::HepSymMatrix AlgebraicSymMatrix
uint32_t refid_
Definition: ME0SegFit.h:148
int ndof_
Definition: ME0SegFit.h:146
ME0SegFit(std::map< uint32_t, const ME0EtaPartition * > me0etapartmap, ME0SetOfHits hits)
Definition: ME0SegFit.h:65
volatile std::atomic< bool > shutdown_flag false
float yfit(float z) const
Definition: ME0SegFit.cc:501
float uslope_
Definition: ME0SegFit.h:141
float xdev(float x, float z) const
Definition: ME0SegFit.cc:505
double scaleXError_
Definition: ME0SegFit.h:147
void setChi2(void)
Definition: ME0SegFit.cc:284
double chi2(void) const
Definition: ME0SegFit.h:107