CMS 3D CMS Logo

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 public:
49  // TYPES
50 
51  // 16 x 16 Symmetric
52  typedef ROOT::Math::SMatrix<double, 16, 16, ROOT::Math::MatRepSym<double, 16> > SMatrixSym16;
53 
54  // 16 x 4
55  typedef ROOT::Math::SMatrix<double, 16, 4> SMatrix16by4;
56 
57  // 4 x 4 General + Symmetric
58  typedef ROOT::Math::SMatrix<double, 4> SMatrix4;
59  typedef ROOT::Math::SMatrix<double, 4, 4, ROOT::Math::MatRepSym<double, 4> > SMatrixSym4;
60 
61  // 2 x 2 Symmetric
62  typedef ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
63 
64  // 4-dim vector
65  typedef ROOT::Math::SVector<double, 4> SVector4;
66 
67  // PUBLIC FUNCTIONS
68 
69  //@@ WANT OBJECT TO CACHE THE SET OF HITS SO CANNOT PASS BY REF
70  GEMCSCSegFit(std::map<uint32_t, const CSCLayer*> csclayermap,
71  std::map<uint32_t, const GEMEtaPartition*> gemrollmap,
72  const std::vector<const TrackingRecHit*> hits)
73  : csclayermap_(csclayermap),
74  gemetapartmap_(gemrollmap),
75  hits_(hits),
76  scaleXError_(1.0),
77  refid_(csclayermap_.begin()->first),
78  fitdone_(false) {
79  // --- LogDebug info about reading of CSC Layer map and GEM Eta Partition map -----------------------
80  edm::LogVerbatim("GEMCSCSegFit") << "[GEMCSCSegFit::ctor] cached the csclayermap and the gemrollmap";
81 
82  // --- LogDebug for CSC Layer map -------------------------------------------------------------------
83  std::stringstream csclayermapss;
84  csclayermapss << "[GEMCSCSegFit::ctor] :: csclayermap :: elements [" << std::endl;
85  for (std::map<uint32_t, const CSCLayer*>::const_iterator mapIt = csclayermap_.begin(); mapIt != csclayermap_.end();
86  ++mapIt) {
87  csclayermapss << "[CSC DetId " << mapIt->first << " =" << CSCDetId(mapIt->first) << ", CSC Layer "
88  << mapIt->second << " =" << (mapIt->second)->id() << "]," << std::endl;
89  }
90  csclayermapss << "]" << std::endl;
91  std::string csclayermapstr = csclayermapss.str();
92  edm::LogVerbatim("GEMCSCSegFit") << csclayermapstr;
93  // --- End LogDebug -----------------------------------------------------------------------------------
94 
95  // --- LogDebug for GEM Eta Partition map ------------------------------------------------------------
96  std::stringstream gemetapartmapss;
97  gemetapartmapss << "[GEMCSCSegFit::ctor] :: gemetapartmap :: elements [" << std::endl;
98  for (std::map<uint32_t, const GEMEtaPartition*>::const_iterator mapIt = gemetapartmap_.begin();
99  mapIt != gemetapartmap_.end();
100  ++mapIt) {
101  gemetapartmapss << "[GEM DetId " << mapIt->first << " =" << GEMDetId(mapIt->first) << ", GEM EtaPart "
102  << mapIt->second << "]," << std::endl;
103  }
104  gemetapartmapss << "]" << std::endl;
105  std::string gemetapartmapstr = gemetapartmapss.str();
106  edm::LogVerbatim("GEMCSCSegFit") << gemetapartmapstr;
107  // --- End LogDebug -----------------------------------------------------------------------------------
108  }
109 
110  virtual ~GEMCSCSegFit() {}
111 
112  // Least-squares fit
113  void fit(void); // fill uslope_, vslope_, intercept_ @@ FKA fitSlopes()
114  // Calculate covariance matrix of fitted parameters
116 
117  // Change scale factor of rechit x error
118  // - expert use only!
120 
121  // Fit values
122  float xfit(float z) const;
123  float yfit(float z) const;
124 
125  // Deviations from fit for given input (local w.r.t. chamber)
126  float xdev(float x, float z) const;
127  float ydev(float y, float z) const;
128  float Rdev(float x, float y, float z) const;
129 
130  // Other public functions are accessors
131  std::vector<const TrackingRecHit*> hits(void) const { return hits_; }
132  double scaleXError(void) const { return scaleXError_; }
133  size_t nhits(void) const { return hits_.size(); }
134  double chi2(void) const { return chi2_; }
135  int ndof(void) const { return ndof_; }
136  LocalPoint intercept() const { return intercept_; }
137  LocalVector localdir() const { return localdir_; }
138 
139  const CSCChamber* cscchamber(uint32_t id) const {
140  // Test whether id is found
141  if (csclayermap_.find(id) == csclayermap_.end()) { // id is not found
142  throw cms::Exception("InvalidDetId") << "[GEMCSCSegFit] Failed to find CSCChamber in CSCLayerMap" << std::endl;
143  } // chamber is not found and exception is thrown
144  else { // id is found
145  return (csclayermap_.find(id)->second)->chamber();
146  } // chamber found and returned
147  }
148  const CSCLayer* csclayer(uint32_t id) const {
149  if (csclayermap_.find(id) == csclayermap_.end()) {
150  throw cms::Exception("InvalidDetId") << "[GEMCSCSegFit] Failed to find CSCLayer in CSCLayerMap" << std::endl;
151  } else {
152  return csclayermap_.find(id)->second;
153  }
154  }
155  const GEMEtaPartition* gemetapartition(uint32_t id) const {
156  if (gemetapartmap_.find(id) == gemetapartmap_.end()) {
157  throw cms::Exception("InvalidDetId")
158  << "[GEMCSCSegFit] Failed to find GEMEtaPartition in GEMEtaPartMap" << std::endl;
159  } else {
160  return gemetapartmap_.find(id)->second;
161  }
162  }
163  const CSCChamber* refcscchamber() const {
164  if (csclayermap_.find(refid_) == csclayermap_.end()) {
165  throw cms::Exception("InvalidDetId")
166  << "[GEMCSCSegFit] Failed to find Reference CSCChamber in CSCLayerMap" << std::endl;
167  } else {
168  return (csclayermap_.find(refid_)->second)->chamber();
169  }
170  }
171  bool fitdone() const { return fitdone_; }
172 
173 private:
174  // PRIVATE FUNCTIONS
175 
176  void fit2(void); // fit for 2 hits
177  void fitlsq(void); // least-squares fit for 3-6 hits
178  void setChi2(void); // fill chi2_ & ndof_ @@ FKA fillChiSquared()
179 
180 protected:
181  // PROTECTED FUNCTIONS - derived class needs access
182 
183  // Set segment direction 'out' from IP
184  void setOutFromIP(void); // fill localdir_ @@ FKA fillLocalDirection()
185 
189 
190  // PROTECTED MEMBER VARIABLES - derived class needs access
191 
192  std::map<uint32_t, const CSCLayer*> csclayermap_;
193  std::map<uint32_t, const GEMEtaPartition*> gemetapartmap_;
195 
196  std::vector<const TrackingRecHit*> hits_; //@@ FKA protoSegment
197  float uslope_; //@@ FKA protoSlope_u
198  float vslope_; //@@ FKA protoSlope_v
199  LocalPoint intercept_; //@@ FKA protoIntercept
200  LocalVector localdir_; //@@ FKA protoDirection
201  double chi2_; //@@ FKA protoChi2
202  int ndof_; //@@ FKA protoNDF, which was double!!
203  double scaleXError_;
204  uint32_t refid_;
205  bool fitdone_;
206  // order needs to be the same here when filled by the constructor
207 };
208 
209 #endif
Vector3DBase< float, LocalTag >
GEMCSCSegFit::refcscchamber
const CSCChamber * refcscchamber() const
Definition: GEMCSCSegFit.h:163
GEMCSCSegFit
Definition: GEMCSCSegFit.h:47
GEMCSCSegFit::SMatrixSym16
ROOT::Math::SMatrix< double, 16, 16, ROOT::Math::MatRepSym< double, 16 > > SMatrixSym16
Definition: GEMCSCSegFit.h:52
GEMCSCSegFit::csclayermap_
std::map< uint32_t, const CSCLayer * > csclayermap_
Definition: GEMCSCSegFit.h:192
DDAxes::y
GEMCSCSegFit::SMatrixSym2
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > SMatrixSym2
Definition: GEMCSCSegFit.h:62
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
GEMRecHit.h
GEMCSCSegFit::cscchamber
const CSCChamber * cscchamber(uint32_t id) const
Definition: GEMCSCSegFit.h:139
GEMEtaPartition
Definition: GEMEtaPartition.h:12
GEMCSCSegFit::refcscchamber_
const CSCChamber * refcscchamber_
Definition: GEMCSCSegFit.h:194
GEMCSCSegFit::flipErrors
AlgebraicSymMatrix flipErrors(const SMatrixSym4 &)
GEMCSCSegFit::yfit
float yfit(float z) const
GEMCSCSegFit::SMatrix16by4
ROOT::Math::SMatrix< double, 16, 4 > SMatrix16by4
Definition: GEMCSCSegFit.h:55
GEMCSCSegFit::covarianceMatrix
AlgebraicSymMatrix covarianceMatrix(void)
GEMCSCSegFit::setChi2
void setChi2(void)
CSCLayer
Definition: CSCLayer.h:24
DDAxes::x
GEMCSCSegFit::hits_
std::vector< const TrackingRecHit * > hits_
Definition: GEMCSCSegFit.h:196
GEMCSCSegFit::~GEMCSCSegFit
virtual ~GEMCSCSegFit()
Definition: GEMCSCSegFit.h:110
CSCDetId.h
GEMCSCSegFit::nhits
size_t nhits(void) const
Definition: GEMCSCSegFit.h:133
GEMCSCSegFit::SMatrix4
ROOT::Math::SMatrix< double, 4 > SMatrix4
Definition: GEMCSCSegFit.h:58
TrackingRecHit.h
DDAxes::z
GEMCSCSegFit::ydev
float ydev(float y, float z) const
CSCChamber
Definition: CSCChamber.h:22
GEMCSCSegFit::xfit
float xfit(float z) const
DQMScaleToClient_cfi.factor
factor
Definition: DQMScaleToClient_cfi.py:8
GEMCSCSegFit::fit
void fit(void)
Definition: GEMCSCSegFit.cc:19
GEMCSCSegFit::SMatrixSym4
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > SMatrixSym4
Definition: GEMCSCSegFit.h:59
GEMCSCSegFit::chi2_
double chi2_
Definition: GEMCSCSegFit.h:201
Point3DBase< float, LocalTag >
GEMCSCSegFit::GEMCSCSegFit
GEMCSCSegFit(std::map< uint32_t, const CSCLayer * > csclayermap, std::map< uint32_t, const GEMEtaPartition * > gemrollmap, const std::vector< const TrackingRecHit * > hits)
Definition: GEMCSCSegFit.h:70
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
GEMCSCSegFit::ndof_
int ndof_
Definition: GEMCSCSegFit.h:202
GEMCSCSegFit::fit2
void fit2(void)
Definition: GEMCSCSegFit.cc:44
GEMCSCSegFit::setScaleXError
void setScaleXError(double factor)
Definition: GEMCSCSegFit.h:119
GEMCSCSegFit::hits
std::vector< const TrackingRecHit * > hits(void) const
Definition: GEMCSCSegFit.h:131
GEMCSCSegFit::localdir
LocalVector localdir() const
Definition: GEMCSCSegFit.h:137
GEMDetId
Definition: GEMDetId.h:18
GEMCSCSegFit::refid_
uint32_t refid_
Definition: GEMCSCSegFit.h:204
CSCDetId
Definition: CSCDetId.h:26
GEMCSCSegFit::intercept_
LocalPoint intercept_
Definition: GEMCSCSegFit.h:199
GEMCSCSegFit::uslope_
float uslope_
Definition: GEMCSCSegFit.h:197
GEMCSCSegFit::fitdone_
bool fitdone_
Definition: GEMCSCSegFit.h:205
AlgebraicSymMatrix
CLHEP::HepSymMatrix AlgebraicSymMatrix
Definition: AlgebraicObjects.h:15
GEMCSCSegFit::Rdev
float Rdev(float x, float y, float z) const
GEMChamber.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
GEMCSCSegFit::fitlsq
void fitlsq(void)
Definition: GEMCSCSegFit.cc:133
GEMCSCSegFit::scaleXError
double scaleXError(void) const
Definition: GEMCSCSegFit.h:132
GEMCSCSegFit::SVector4
ROOT::Math::SVector< double, 4 > SVector4
Definition: GEMCSCSegFit.h:65
GEMCSCSegFit::derivativeMatrix
SMatrix16by4 derivativeMatrix(void)
CSCLayer.h
GEMCSCSegFit::fitdone
bool fitdone() const
Definition: GEMCSCSegFit.h:171
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
Exception
Definition: hltDiff.cc:245
relativeConstraints.chamber
chamber
Definition: relativeConstraints.py:53
Exception.h
GEMCSCSegFit::vslope_
float vslope_
Definition: GEMCSCSegFit.h:198
GEMCSCSegFit::gemetapartition
const GEMEtaPartition * gemetapartition(uint32_t id) const
Definition: GEMCSCSegFit.h:155
CSCRecHit2D.h
GEMCSCSegFit::ndof
int ndof(void) const
Definition: GEMCSCSegFit.h:135
GEMCSCSegFit::weightMatrix
SMatrixSym16 weightMatrix(void)
CSCChamber.h
GEMCSCSegFit::intercept
LocalPoint intercept() const
Definition: GEMCSCSegFit.h:136
GEMCSCSegFit::csclayer
const CSCLayer * csclayer(uint32_t id) const
Definition: GEMCSCSegFit.h:148
GEMCSCSegFit::setOutFromIP
void setOutFromIP(void)
GEMCSCSegFit::xdev
float xdev(float x, float z) const
GEMCSCSegFit::chi2
double chi2(void) const
Definition: GEMCSCSegFit.h:134
GEMCSCSegFit::localdir_
LocalVector localdir_
Definition: GEMCSCSegFit.h:200
GEMCSCSegFit::gemetapartmap_
std::map< uint32_t, const GEMEtaPartition * > gemetapartmap_
Definition: GEMCSCSegFit.h:193
GEMCSCSegFit::scaleXError_
double scaleXError_
Definition: GEMCSCSegFit.h:203