test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GEMCSCSegFit.h
Go to the documentation of this file.
1 #ifndef GEMCSCSegment_GEMCSCSegFit_h
2 #define GEMCSCSegment_GEMCSCSegFit_h
3 
4 // GEMCSCSegFit.h extension to fit both CSCHits and GEMHits - Piet Verwilligen
5 // Created: 21.04.2015
6 
7 /* Work with general Tracking Rechits, such that GEM and CSC rechits
8  * can be treated at the same level. In case needed the Tracking Rechit can be
9  * cast to the CSCRecHit2D or the GEMRecHit for access to more specific info.
10  */
11 
12 // CSCSegFit.h - Segment fitting factored out of CSC segment builders - Tim Cox
13 // Last mod: 03.02.2015
14 
15 /* This as an object which is initialized by a set of rechits (2 to 6) in a
16  * specific CSC and has the functionality to make a least squares fit to a
17  * straight line in 2-dim for those rechits.
18  * The covariance matrix and chi2 of the fit are calculated.
19  * The original code made use of CLHEP matrices but this version uses
20  * ROOT SMatrices because they are multithreading compatible.
21  * Because of this, the no. of rechits that can be handled is limited to
22  * a maximum of 6, one per layer of a CSC. This means maximum dimensions
23  * can be specified at compile time and hence satisfies SMatrix constraints.
24  * For 2 hits of course there is no fit - just draw a straight line between them.
25  * Details of the algorithm are in the .cc file
26  *
27  */
28 
33 
37 
40 
41 #include <Math/Functions.h>
42 #include <Math/SVector.h>
43 #include <Math/SMatrix.h>
44 
45 #include <vector>
46 
47 class GEMCSCSegFit {
48 
49 public:
50 
51 // TYPES
52 
53  // 16 x 16 Symmetric
54  typedef ROOT::Math::SMatrix<double,16,16,ROOT::Math::MatRepSym<double,16> > SMatrixSym16;
55 
56  // 16 x 4
57  typedef ROOT::Math::SMatrix<double,16,4 > SMatrix16by4;
58 
59  // 4 x 4 General + Symmetric
60  typedef ROOT::Math::SMatrix<double, 4 > SMatrix4;
61  typedef ROOT::Math::SMatrix<double,4,4,ROOT::Math::MatRepSym<double,4> > SMatrixSym4;
62 
63  // 2 x 2 Symmetric
64  typedef ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2> > SMatrixSym2;
65 
66  // 4-dim vector
67  typedef ROOT::Math::SVector<double,4> SVector4;
68 
69 
70  // PUBLIC FUNCTIONS
71 
72  //@@ WANT OBJECT TO CACHE THE SET OF HITS SO CANNOT PASS BY REF
73  GEMCSCSegFit(std::map<uint32_t, const CSCLayer*> csclayermap, std::map<uint32_t, const GEMEtaPartition*> gemrollmap, const std::vector<const TrackingRecHit*> hits) :
74  csclayermap_( csclayermap ), gemetapartmap_( gemrollmap ), hits_( hits ), scaleXError_( 1.0 ), refid_( csclayermap_.begin()->first ), fitdone_( false )
75  {
76  // --- LogDebug info about reading of CSC Layer map and GEM Eta Partition map -----------------------
77  edm::LogVerbatim("GEMCSCSegFit") << "[GEMCSCSegFit::ctor] cached the csclayermap and the gemrollmap";
78 
79  // --- LogDebug for CSC Layer map -------------------------------------------------------------------
80  std::stringstream csclayermapss; csclayermapss<<"[GEMCSCSegFit::ctor] :: csclayermap :: elements ["<<std::endl;
81  for(std::map<uint32_t, const CSCLayer*>::const_iterator mapIt = csclayermap_.begin(); mapIt != csclayermap_.end(); ++mapIt)
82  {
83  csclayermapss<<"[CSC DetId "<<mapIt->first<<" ="<<CSCDetId(mapIt->first)<<", CSC Layer "<<mapIt->second<<" ="<<(mapIt->second)->id()<<"],"<<std::endl;
84  }
85  csclayermapss<<"]"<<std::endl;
86  std::string csclayermapstr = csclayermapss.str();
87  edm::LogVerbatim("GEMCSCSegFit") << csclayermapstr;
88  // --- End LogDebug -----------------------------------------------------------------------------------
89 
90  // --- LogDebug for GEM Eta Partition map ------------------------------------------------------------
91  std::stringstream gemetapartmapss; gemetapartmapss<<"[GEMCSCSegFit::ctor] :: gemetapartmap :: elements ["<<std::endl;
92  for(std::map<uint32_t, const GEMEtaPartition*>::const_iterator mapIt = gemetapartmap_.begin(); mapIt != gemetapartmap_.end(); ++mapIt)
93  {
94  gemetapartmapss<<"[GEM DetId "<<mapIt->first<<" ="<<GEMDetId(mapIt->first)<<", GEM EtaPart "<<mapIt->second<<"],"<<std::endl;
95  }
96  gemetapartmapss<<"]"<<std::endl;
97  std::string gemetapartmapstr = gemetapartmapss.str();
98  edm::LogVerbatim("GEMCSCSegFit") << gemetapartmapstr;
99  // --- End LogDebug -----------------------------------------------------------------------------------
100  }
101 
102  virtual ~GEMCSCSegFit() {}
103 
104  // Least-squares fit
105  void fit( void ); // fill uslope_, vslope_, intercept_ @@ FKA fitSlopes()
106  // Calculate covariance matrix of fitted parameters
108 
109  // Change scale factor of rechit x error
110  // - expert use only!
111  void setScaleXError ( double factor ) { scaleXError_ = factor; }
112 
113  // Fit values
114  float xfit( float z ) const;
115  float yfit( float z ) const;
116 
117  // Deviations from fit for given input (local w.r.t. chamber)
118  float xdev( float x, float z ) const;
119  float ydev ( float y, float z ) const;
120  float Rdev( float x, float y, float z ) const;
121 
122  // Other public functions are accessors
123  std::vector<const TrackingRecHit*> hits(void) const { return hits_; }
124  double scaleXError(void) const { return scaleXError_; }
125  size_t nhits(void) const { return hits_.size(); }
126  double chi2(void) const { return chi2_; }
127  int ndof(void) const { return ndof_; }
128  LocalPoint intercept() const { return intercept_;}
129  LocalVector localdir() const { return localdir_;}
130 
131  const CSCChamber* cscchamber (uint32_t id) const {
132  // Test whether id is found
133  if(csclayermap_.find(id)==csclayermap_.end())
134  { // id is not found
135  throw cms::Exception("InvalidDetId") << "[GEMCSCSegFit] Failed to find CSCChamber in CSCLayerMap"<< std::endl;
136  } // chamber is not found and exception is thrown
137  else
138  { // id is found
139  return (csclayermap_.find(id)->second)->chamber();
140  } // chamber found and returned
141  }
142  const CSCLayer* csclayer (uint32_t id) const {
143  if(csclayermap_.find(id)==csclayermap_.end()) {
144  throw cms::Exception("InvalidDetId") << "[GEMCSCSegFit] Failed to find CSCLayer in CSCLayerMap" << std::endl;
145  }
146  else { return csclayermap_.find(id)->second; }
147  }
148  const GEMEtaPartition* gemetapartition(uint32_t id) const {
149  if(gemetapartmap_.find(id)==gemetapartmap_.end()) {
150  throw cms::Exception("InvalidDetId") << "[GEMCSCSegFit] Failed to find GEMEtaPartition in GEMEtaPartMap" << std::endl;
151  }
152  else { return gemetapartmap_.find(id)->second; }
153  }
154  const CSCChamber* refcscchamber () const {
155  if(csclayermap_.find(refid_)==csclayermap_.end()) {
156  throw cms::Exception("InvalidDetId") << "[GEMCSCSegFit] Failed to find Reference CSCChamber in CSCLayerMap" << std::endl;
157  }
158  else { return (csclayermap_.find(refid_)->second)->chamber(); }
159  }
160  bool fitdone() const { return fitdone_; }
161 
162  private:
163 
164  // PRIVATE FUNCTIONS
165 
166  void fit2(void); // fit for 2 hits
167  void fitlsq(void); // least-squares fit for 3-6 hits
168  void setChi2(void); // fill chi2_ & ndof_ @@ FKA fillChiSquared()
169 
170 
171  protected:
172 
173  // PROTECTED FUNCTIONS - derived class needs access
174 
175  // Set segment direction 'out' from IP
176  void setOutFromIP(void); // fill localdir_ @@ FKA fillLocalDirection()
177 
181 
182  // PROTECTED MEMBER VARIABLES - derived class needs access
183 
184  std::map<uint32_t, const CSCLayer*> csclayermap_;
185  std::map<uint32_t, const GEMEtaPartition*> gemetapartmap_;
187 
188 
189  std::vector<const TrackingRecHit*> hits_; //@@ FKA protoSegment
190  float uslope_; //@@ FKA protoSlope_u
191  float vslope_; //@@ FKA protoSlope_v
192  LocalPoint intercept_; //@@ FKA protoIntercept
193  LocalVector localdir_; //@@ FKA protoDirection
194  double chi2_; //@@ FKA protoChi2
195  int ndof_; //@@ FKA protoNDF, which was double!!
196  double scaleXError_;
197  uint32_t refid_;
198  bool fitdone_;
199  // order needs to be the same here when filled by the constructor
200 
201 };
202 
203 #endif
204 
void setChi2(void)
SMatrix16by4 derivativeMatrix(void)
void setScaleXError(double factor)
Definition: GEMCSCSegFit.h:111
float xdev(float x, float z) const
std::vector< const TrackingRecHit * > hits_
Definition: GEMCSCSegFit.h:189
float ydev(float y, float z) const
const CSCLayer * csclayer(uint32_t id) const
Definition: GEMCSCSegFit.h:142
uint32_t refid_
Definition: GEMCSCSegFit.h:197
double scaleXError_
Definition: GEMCSCSegFit.h:196
float Rdev(float x, float y, float z) const
ROOT::Math::SMatrix< double, 4 > SMatrix4
Definition: GEMCSCSegFit.h:60
std::map< uint32_t, const GEMEtaPartition * > gemetapartmap_
Definition: GEMCSCSegFit.h:185
ROOT::Math::SMatrix< double, 16, 4 > SMatrix16by4
Definition: GEMCSCSegFit.h:57
void fitlsq(void)
float xfit(float z) const
size_t nhits(void) const
Definition: GEMCSCSegFit.h:125
void fit(void)
Definition: GEMCSCSegFit.cc:20
ROOT::Math::SVector< double, 4 > SVector4
Definition: GEMCSCSegFit.h:67
LocalVector localdir() const
Definition: GEMCSCSegFit.h:129
double scaleXError(void) const
Definition: GEMCSCSegFit.h:124
AlgebraicSymMatrix covarianceMatrix(void)
const CSCChamber * refcscchamber() const
Definition: GEMCSCSegFit.h:154
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > SMatrixSym2
Definition: GEMCSCSegFit.h:64
LocalVector localdir_
Definition: GEMCSCSegFit.h:193
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > SMatrixSym4
Definition: GEMCSCSegFit.h:61
std::vector< const TrackingRecHit * > hits(void) const
Definition: GEMCSCSegFit.h:123
float yfit(float z) const
AlgebraicSymMatrix flipErrors(const SMatrixSym4 &)
int ndof(void) const
Definition: GEMCSCSegFit.h:127
bool fitdone() const
Definition: GEMCSCSegFit.h:160
double chi2(void) const
Definition: GEMCSCSegFit.h:126
#define begin
Definition: vmac.h:30
LocalPoint intercept_
Definition: GEMCSCSegFit.h:192
void setOutFromIP(void)
virtual ~GEMCSCSegFit()
Definition: GEMCSCSegFit.h:102
CLHEP::HepSymMatrix AlgebraicSymMatrix
SMatrixSym16 weightMatrix(void)
std::map< uint32_t, const CSCLayer * > csclayermap_
Definition: GEMCSCSegFit.h:184
volatile std::atomic< bool > shutdown_flag false
LocalPoint intercept() const
Definition: GEMCSCSegFit.h:128
const CSCChamber * refcscchamber_
Definition: GEMCSCSegFit.h:186
GEMCSCSegFit(std::map< uint32_t, const CSCLayer * > csclayermap, std::map< uint32_t, const GEMEtaPartition * > gemrollmap, const std::vector< const TrackingRecHit * > hits)
Definition: GEMCSCSegFit.h:73
const CSCChamber * cscchamber(uint32_t id) const
Definition: GEMCSCSegFit.h:131
const GEMEtaPartition * gemetapartition(uint32_t id) const
Definition: GEMCSCSegFit.h:148
ROOT::Math::SMatrix< double, 16, 16, ROOT::Math::MatRepSym< double, 16 > > SMatrixSym16
Definition: GEMCSCSegFit.h:54
void fit2(void)
Definition: GEMCSCSegFit.cc:44