CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
ME0SegFit Class Reference

#include <ME0SegFit.h>

Public Types

typedef std::vector< const
ME0RecHit * > 
ME0SetOfHits
 
typedef ROOT::Math::SMatrix
< double, 12, 4 > 
SMatrix12by4
 
typedef ROOT::Math::SMatrix
< double, 4 > 
SMatrix4
 
typedef ROOT::Math::SMatrix
< double,
12, 12, ROOT::Math::MatRepSym
< double, 12 > > 
SMatrixSym12
 
typedef ROOT::Math::SMatrix
< double,
2, 2, ROOT::Math::MatRepSym
< double, 2 > > 
SMatrixSym2
 
typedef ROOT::Math::SMatrix
< double,
4, 4, ROOT::Math::MatRepSym
< double, 4 > > 
SMatrixSym4
 
typedef ROOT::Math::SVector
< double, 4 > 
SVector4
 

Public Member Functions

double chi2 (void) const
 
AlgebraicSymMatrix covarianceMatrix (void)
 
void fit (void)
 
bool fitdone () const
 
ME0SetOfHits hits (void) const
 
LocalPoint intercept () const
 
LocalVector localdir () const
 
const ME0EtaPartitionme0etapartition (uint32_t id) const
 
 ME0SegFit (std::map< uint32_t, const ME0EtaPartition * > me0etapartmap, ME0SetOfHits hits)
 
int ndof (void) const
 
size_t nhits (void) const
 
float Rdev (float x, float y, float z) const
 
const ME0EtaPartitionrefme0etapart () const
 
double scaleXError (void) const
 
void setScaleXError (double factor)
 
float xdev (float x, float z) const
 
float xfit (float z) const
 
float ydev (float y, float z) const
 
float yfit (float z) const
 
virtual ~ME0SegFit ()
 

Protected Member Functions

SMatrix12by4 derivativeMatrix (void)
 
AlgebraicSymMatrix flipErrors (const SMatrixSym4 &)
 
void setOutFromIP (void)
 
SMatrixSym12 weightMatrix (void)
 

Protected Attributes

double chi2_
 
bool fitdone_
 
ME0SetOfHits hits_
 
LocalPoint intercept_
 
LocalVector localdir_
 
std::map< uint32_t, const
ME0EtaPartition * > 
me0etapartmap_
 
int ndof_
 
uint32_t refid_
 
double scaleXError_
 
float uslope_
 
float vslope_
 

Private Member Functions

void fit2 (void)
 
void fitlsq (void)
 
void setChi2 (void)
 

Detailed Description

Definition at line 37 of file ME0SegFit.h.

Member Typedef Documentation

typedef std::vector<const ME0RecHit*> ME0SegFit::ME0SetOfHits

Definition at line 43 of file ME0SegFit.h.

typedef ROOT::Math::SMatrix<double,12,4 > ME0SegFit::SMatrix12by4

Definition at line 49 of file ME0SegFit.h.

typedef ROOT::Math::SMatrix<double, 4 > ME0SegFit::SMatrix4

Definition at line 52 of file ME0SegFit.h.

typedef ROOT::Math::SMatrix<double,12,12,ROOT::Math::MatRepSym<double,12> > ME0SegFit::SMatrixSym12

Definition at line 46 of file ME0SegFit.h.

typedef ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2> > ME0SegFit::SMatrixSym2

Definition at line 56 of file ME0SegFit.h.

typedef ROOT::Math::SMatrix<double,4,4,ROOT::Math::MatRepSym<double,4> > ME0SegFit::SMatrixSym4

Definition at line 53 of file ME0SegFit.h.

typedef ROOT::Math::SVector<double,4> ME0SegFit::SVector4

Definition at line 59 of file ME0SegFit.h.

Constructor & Destructor Documentation

ME0SegFit::ME0SegFit ( std::map< uint32_t, const ME0EtaPartition * >  me0etapartmap,
ME0SetOfHits  hits 
)
inline

Definition at line 65 of file ME0SegFit.h.

References me0etapartmap_, and AlCaHLTBitMon_QueryRunRegistry::string.

65  :
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  }
std::map< uint32_t, const ME0EtaPartition * > me0etapartmap_
Definition: ME0SegFit.h:138
bool fitdone_
Definition: ME0SegFit.h:149
ME0SetOfHits hits_
Definition: ME0SegFit.h:140
ME0SetOfHits hits(void) const
Definition: ME0SegFit.h:104
uint32_t refid_
Definition: ME0SegFit.h:148
double scaleXError_
Definition: ME0SegFit.h:147
virtual ME0SegFit::~ME0SegFit ( )
inlinevirtual

Definition at line 83 of file ME0SegFit.h.

83 {}

Member Function Documentation

double ME0SegFit::chi2 ( void  ) const
inline

Definition at line 107 of file ME0SegFit.h.

References chi2_.

107 { return chi2_; }
double chi2_
Definition: ME0SegFit.h:145
AlgebraicSymMatrix ME0SegFit::covarianceMatrix ( void  )

Definition at line 418 of file ME0SegFit.cc.

References HLT_25ns14e33_v1_cff::A, derivativeMatrix(), flipErrors(), convertSQLiteXML::ok, query::result, weightMatrix(), and create_public_pileup_plots::weights.

418  {
419 
422  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::covarianceMatrix] weights matrix W: \n" << weights;
423  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::covarianceMatrix] derivatives matrix A: \n" << A;
424 
425  // (AT W A)^-1
426  // e.g. See http://www.phys.ufl.edu/~avery/fitting.html, part I
427 
428  bool ok;
429  SMatrixSym4 result = ROOT::Math::SimilarityT(A, weights);
430  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::covarianceMatrix] (AT W A): \n" << result;
431  ok = result.Invert(); // inverts in place
432  if ( !ok ) {
433  edm::LogVerbatim("ME0Segment|ME0SegFit") << "[ME0SegFit::calculateError] Failed to invert matrix: \n" << result;
434  // return ok; //@@ SHOULD PASS THIS BACK TO CALLER?
435  }
436  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::covarianceMatrix] (AT W A)^-1: \n" << result;
437 
438  // reorder components to match TrackingRecHit interface (ME0Segment isa TrackingRecHit)
439  // i.e. slopes first, then positions
440  AlgebraicSymMatrix flipped = flipErrors( result );
441 
442  return flipped;
443 }
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > SMatrixSym4
Definition: ME0SegFit.h:53
ROOT::Math::SMatrix< double, 12, 12, ROOT::Math::MatRepSym< double, 12 > > SMatrixSym12
Definition: ME0SegFit.h:46
AlgebraicSymMatrix flipErrors(const SMatrixSym4 &)
Definition: ME0SegFit.cc:446
tuple result
Definition: query.py:137
ROOT::Math::SMatrix< double, 12, 4 > SMatrix12by4
Definition: ME0SegFit.h:49
SMatrix12by4 derivativeMatrix(void)
Definition: ME0SegFit.cc:370
SMatrixSym12 weightMatrix(void)
Definition: ME0SegFit.cc:337
CLHEP::HepSymMatrix AlgebraicSymMatrix
ME0SegFit::SMatrix12by4 ME0SegFit::derivativeMatrix ( void  )
protected

Definition at line 370 of file ME0SegFit.cc.

References ztail::d, hits_, ME0RecHit::localPosition(), makeMuonMisalignmentScenario::matrix, me0etapartition(), TrackingRecHit::rawId(), refme0etapart(), GeomDet::toLocal(), z, and PV3DBase< T, PVType, FrameType >::z().

Referenced by covarianceMatrix().

370  {
371 
372  SMatrix12by4 matrix; // 12x4, init to 0
373  int row = 0;
374 
375  for( ME0SetOfHits::const_iterator it = hits_.begin(); it != hits_.end(); ++it) {
376 
377  const ME0RecHit& hit = (**it);
378  ME0DetId d = ME0DetId(hit.rawId());
379  const ME0EtaPartition* roll = me0etapartition(d);
380  GlobalPoint gp = roll->toGlobal(hit.localPosition());
381  LocalPoint lp = refme0etapart()->toLocal(gp);
382  float z = lp.z();
383 
384  matrix(row, 0) = 1.;
385  matrix(row, 2) = z;
386  ++row;
387  matrix(row, 1) = 1.;
388  matrix(row, 3) = z;
389  ++row;
390  }
391  return matrix;
392 }
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:67
tuple d
Definition: ztail.py:151
const ME0EtaPartition * me0etapartition(uint32_t id) const
Definition: ME0SegFit.h:111
T z() const
Definition: PV3DBase.h:64
virtual LocalPoint localPosition() const
Return the 3-dimensional local position.
Definition: ME0RecHit.h:47
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
id_type rawId() const
void ME0SegFit::fit ( void  )

Definition at line 15 of file ME0SegFit.cc.

References fit2(), fitdone(), fitlsq(), gen::n, and nhits().

15  {
16  if ( fitdone() ) return; // don't redo fit unnecessarily
17  short n = nhits();
18  switch ( n ) {
19  case 1:
20  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::fit] - cannot fit just 1 hit!!";
21  break;
22  case 2:
23  fit2();
24  break;
25  case 3:
26  case 4:
27  case 5:
28  case 6:
29  fitlsq();
30  break;
31  default:
32  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::fit] - cannot fit more than 6 hits!!";
33  }
34 }
bool fitdone() const
Definition: ME0SegFit.h:113
void fitlsq(void)
Definition: ME0SegFit.cc:101
size_t nhits(void) const
Definition: ME0SegFit.h:106
void fit2(void)
Definition: ME0SegFit.cc:36
void ME0SegFit::fit2 ( void  )
private

Definition at line 36 of file ME0SegFit.cc.

References chi2_, fitdone_, hits_, intercept_, ME0DetId::layer(), ME0RecHit::localPosition(), me0etapartition(), ndof_, refme0etapart(), setOutFromIP(), GeomDet::toGlobal(), GeomDet::toLocal(), uslope_, vslope_, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by fit().

36  {
37 
38  // Just join the two points
39  // Equation of straight line between (x1, y1) and (x2, y2) in xy-plane is
40  // y = mx + c
41  // with m = (y2-y1)/(x2-x1)
42  // and c = (y1*x2-x2*y1)/(x2-x1)
43 
44 
45  // 1) Check whether hits are on the same layer
46  // -------------------------------------------
47  ME0SetOfHits::const_iterator ih = hits_.begin();
48 
49  ME0DetId d1 = DetId((*ih)->rawId());
50  int il1 = d1.layer();
51  const ME0RecHit& h1 = (**ih);
52  ++ih;
53  ME0DetId d2 = DetId((*ih)->rawId());
54  int il2 = d2.layer();
55  const ME0RecHit& h2 = (**ih);
56 
57  // Skip if on same layer, but should be impossible :)
58  if (il1 == il2) {
59  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit:fit2] - 2 hits on same layer!!";
60  return;
61  }
62 
63 
64  // 2) Global Positions of hit 1 and 2 and
65  // Local Positions of hit 1 and 2 w.r.t. reference ME0 Eta Partition
66  // ---------------------------------------------------------------------
67  const ME0EtaPartition* roll1 = me0etapartition(d1);
68  GlobalPoint h1glopos = roll1->toGlobal(h1.localPosition());
69  const ME0EtaPartition* roll2 = me0etapartition(d2);
70  GlobalPoint h2glopos = roll2->toGlobal(h2.localPosition());
71 
72  // We want hit wrt first me0 eta partition
73  // ( = reference m00 eta partition)
74  // (and local z will be != 0)
75  LocalPoint h1pos = refme0etapart()->toLocal(h1glopos);
76  LocalPoint h2pos = refme0etapart()->toLocal(h2glopos);
77 
78 
79  // 3) Now make straight line between the two points in local coords
80  // ----------------------------------------------------------------
81  float dz = h2pos.z()-h1pos.z();
82  if(dz != 0.0) {
83  uslope_ = ( h2pos.x() - h1pos.x() ) / dz ;
84  vslope_ = ( h2pos.y() - h1pos.y() ) / dz ;
85  }
86 
87  float uintercept = ( h1pos.x()*h2pos.z() - h2pos.x()*h1pos.z() ) / dz;
88  float vintercept = ( h1pos.y()*h2pos.z() - h2pos.y()*h1pos.z() ) / dz;
89  intercept_ = LocalPoint( uintercept, vintercept, 0.);
90 
91  setOutFromIP();
92 
93  //@@ NOT SURE WHAT IS SENSIBLE FOR THESE...
94  chi2_ = 0.;
95  ndof_ = 0;
96 
97  fitdone_ = true;
98 }
float vslope_
Definition: ME0SegFit.h:142
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:52
T y() const
Definition: PV3DBase.h:63
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:67
const ME0EtaPartition * me0etapartition(uint32_t id) const
Definition: ME0SegFit.h:111
bool fitdone_
Definition: ME0SegFit.h:149
T z() const
Definition: PV3DBase.h:64
double chi2_
Definition: ME0SegFit.h:145
virtual LocalPoint localPosition() const
Return the 3-dimensional local position.
Definition: ME0RecHit.h:47
ME0SetOfHits hits_
Definition: ME0SegFit.h:140
const ME0EtaPartition * refme0etapart() const
Definition: ME0SegFit.h:112
Definition: DetId.h:18
void setOutFromIP(void)
Definition: ME0SegFit.cc:395
LocalPoint intercept_
Definition: ME0SegFit.h:143
int ndof_
Definition: ME0SegFit.h:146
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
int layer() const
Layer id: each chamber has six layers of chambers: layer 1 is the inner layer and layer 6 is the oute...
Definition: ME0DetId.h:56
T x() const
Definition: PV3DBase.h:62
float uslope_
Definition: ME0SegFit.h:141
bool ME0SegFit::fitdone ( ) const
inline

Definition at line 113 of file ME0SegFit.h.

References fitdone_.

Referenced by fit().

113 { return fitdone_; }
bool fitdone_
Definition: ME0SegFit.h:149
void ME0SegFit::fitlsq ( void  )
private

Definition at line 101 of file ME0SegFit.cc.

References ztail::d, fitdone_, hits_, ME0EtaPartition::id(), intercept_, ME0RecHit::localPosition(), ME0RecHit::localPositionError(), LogTrace, me0etapartition(), convertSQLiteXML::ok, AlCaHLTBitMon_ParallelJobs::p, DetId::rawId(), TrackingRecHit::rawId(), refme0etapart(), setChi2(), setOutFromIP(), AlCaHLTBitMon_QueryRunRegistry::string, GeomDet::toLocal(), uslope_, findQualityFiles::v, vslope_, LocalError::xx(), LocalError::xy(), LocalError::yy(), and z.

Referenced by fit().

101  {
102 
103  // Linear least-squares fit to up to 6 ME0 rechits, one per layer in a ME0 chamber.
104  // Comments adapted from Tim Cox' comments in the original ME0SegAlgoSK algorithm.
105 
106  // Fit to the local x, y rechit coordinates in z projection
107  // The strip measurement controls the precision of x
108  // The wire measurement controls the precision of y.
109  // Typical precision: u (strip, sigma~200um), v (wire, sigma~1cm)
110 
111  // Set up the normal equations for the least-squares fit as a matrix equation
112 
113  // We have a vector of measurements m, which is a 2n x 1 dim matrix
114  // The transpose mT is (u1, v1, u2, v2, ..., un, vn) where
115  // ui is the strip-associated measurement and
116  // vi is the wire-associated measurement
117  // for a given rechit i.
118 
119  // The fit is to
120  // u = u0 + uz * z
121  // v = v0 + vz * z
122  // where u0, uz, v0, vz are the parameters to be obtained from the fit.
123 
124  // These are contained in a vector p which is a 4x1 dim matrix, and
125  // its transpose pT is (u0, v0, uz, vz). Note the ordering!
126 
127  // The covariance matrix for each pair of measurements is 2 x 2 and
128  // the inverse of this is the error matrix E.
129  // The error matrix for the whole set of n measurements is a diagonal
130  // matrix with diagonal elements the individual 2 x 2 error matrices
131  // (because the inverse of a diagonal matrix is a diagonal matrix
132  // with each element the inverse of the original.)
133 
134  // In function 'weightMatrix()', the variable 'matrix' is filled with this
135  // block-diagonal overall covariance matrix. Then 'matrix' is inverted to the
136  // block-diagonal error matrix, and returned.
137 
138  // Define the matrix A as
139  // 1 0 z1 0
140  // 0 1 0 z1
141  // 1 0 z2 0
142  // 0 1 0 z2
143  // .. .. .. ..
144  // 1 0 zn 0
145  // 0 1 0 zn
146 
147  // This matrix A is set up and returned by function 'derivativeMatrix()'.
148 
149  // Then the normal equations are described by the matrix equation
150  //
151  // (AT E A)p = (AT E)m
152  //
153  // where AT is the transpose of A.
154 
155  // Call the combined matrix on the LHS, M, and that on the RHS, B:
156  // M p = B
157 
158  // We solve this for the parameter vector, p.
159  // The elements of M and B then involve sums over the hits
160 
161  // The covariance matrix of the parameters is obtained by
162  // (AT E A)^-1 calculated in 'covarianceMatrix()'.
163 
164 
165  // NOTE
166  // We need local position of a RecHit w.r.t. the CHAMBER
167  // and the RecHit itself only knows its local position w.r.t.
168  // the LAYER, so we must explicitly transform global position.
169 
170 
171  SMatrix4 M; // 4x4, init to 0
172  SVector4 B; // 4x1, init to 0;
173 
174  ME0SetOfHits::const_iterator ih = hits_.begin();
175 
176  // LogDebug :: Loop over the TrackingRecHits and print the ME0 Hits
177  for (ih = hits_.begin(); ih != hits_.end(); ++ih)
178  {
179  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::fitlsq] - looping over ME0RecHits";
180  const ME0RecHit& hit = (**ih);
181  ME0DetId d = ME0DetId(hit.rawId());
182  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::fitlsq] - Tracking RecHit in detid ("<<d.rawId()<<")";
183  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::fitlsq] - ME0DetId ("<<ME0DetId(d.rawId())<<")";
184  }
185 
186  // Loop over the ME0RecHits and make small (2x2) matrices used to fill the blockdiagonal covariance matrix E^-1
187  for (ih = hits_.begin(); ih != hits_.end(); ++ih) {
188  const ME0RecHit& hit = (**ih);
189  ME0DetId d = DetId(hit.rawId());
190  const ME0EtaPartition* roll = me0etapartition(d);
191  GlobalPoint gp = roll->toGlobal(hit.localPosition());
192  LocalPoint lp = refme0etapart()->toLocal(gp);
193 
194  // LogDebug
195  #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode
196  std::stringstream lpss; lpss<<lp; std::string lps = lpss.str();
197  std::stringstream gpss; gpss<<gp; std::string gps = gpss.str();
198  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::fitlsq] - Tracking RecHit global position "<<std::setw(30)<<gps<<" and local position "<<std::setw(30)<<lps
199  <<" wrt reference ME0 eta partition "<<refme0etapart()->id().rawId()<<" = "<<refme0etapart()->id();
200  #endif
201 
202  // Local position of hit w.r.t. chamber
203  double u = lp.x();
204  double v = lp.y();
205  double z = lp.z();
206 
207  // Covariance matrix of local errors
208  SMatrixSym2 IC; // 2x2, init to 0
209 
210  IC(0,0) = hit.localPositionError().xx();
211  IC(1,1) = hit.localPositionError().yy();
212  //@@ NOT SURE WHICH OFF-DIAGONAL ELEMENT MUST BE DEFINED BUT (1,0) WORKS
213  //@@ (and SMatrix enforces symmetry)
214  IC(1,0) = hit.localPositionError().xy();
215  // IC(0,1) = IC(1,0);
216 
217  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::fit] 2x2 covariance matrix for this ME0RecHit :: [[" << IC(0,0) <<", "<< IC(0,1) <<"]["<< IC(1,0) <<","<<IC(1,1)<<"]]";
218 
219  // Invert covariance matrix (and trap if it fails!)
220  bool ok = IC.Invert();
221  if ( !ok ) {
222  edm::LogVerbatim("ME0Segment|ME0SegFit") << "[ME0SegFit::fit] Failed to invert covariance matrix: \n" << IC;
223  // return ok; //@@ SHOULD PASS THIS BACK TO CALLER?
224  }
225 
226  M(0,0) += IC(0,0);
227  M(0,1) += IC(0,1);
228  M(0,2) += IC(0,0) * z;
229  M(0,3) += IC(0,1) * z;
230  B(0) += u * IC(0,0) + v * IC(0,1);
231 
232  M(1,0) += IC(1,0);
233  M(1,1) += IC(1,1);
234  M(1,2) += IC(1,0) * z;
235  M(1,3) += IC(1,1) * z;
236  B(1) += u * IC(1,0) + v * IC(1,1);
237 
238  M(2,0) += IC(0,0) * z;
239  M(2,1) += IC(0,1) * z;
240  M(2,2) += IC(0,0) * z * z;
241  M(2,3) += IC(0,1) * z * z;
242  B(2) += ( u * IC(0,0) + v * IC(0,1) ) * z;
243 
244  M(3,0) += IC(1,0) * z;
245  M(3,1) += IC(1,1) * z;
246  M(3,2) += IC(1,0) * z * z;
247  M(3,3) += IC(1,1) * z * z;
248  B(3) += ( u * IC(1,0) + v * IC(1,1) ) * z;
249 
250  }
251 
252  SVector4 p;
253  bool ok = M.Invert();
254  if (!ok ){
255  edm::LogVerbatim("ME0Segment|ME0SegFit") << "[ME0SegFit::fit] Failed to invert matrix: \n" << M;
256  // return ok; //@@ SHOULD PASS THIS BACK TO CALLER?
257  }
258  else {
259  p = M * B;
260  }
261 
262  LogTrace("ME0SegFit") << "[ME0SegFit::fit] p = "
263  << p(0) << ", " << p(1) << ", " << p(2) << ", " << p(3);
264 
265  // fill member variables (note origin has local z = 0)
266  // intercept_
267  intercept_ = LocalPoint(p(0), p(1), 0.);
268 
269  // localdir_ - set so segment points outwards from IP
270  uslope_ = p(2);
271  vslope_ = p(3);
272  setOutFromIP();
273 
274  // calculate chi2 of fit
275  setChi2( );
276 
277  // flag fit has been done
278  fitdone_ = true;
279 
280 }
ROOT::Math::SVector< double, 4 > SVector4
Definition: ME0SegFit.h:59
float xx() const
Definition: LocalError.h:24
double_binary B
Definition: DDStreamer.cc:234
float vslope_
Definition: ME0SegFit.h:142
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:67
ROOT::Math::SMatrix< double, 4 > SMatrix4
Definition: ME0SegFit.h:52
virtual LocalError localPositionError() const
Return the 3-dimensional error on the local position.
Definition: ME0RecHit.h:53
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > SMatrixSym2
Definition: ME0SegFit.h:56
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
tuple d
Definition: ztail.py:151
float xy() const
Definition: LocalError.h:25
const ME0EtaPartition * me0etapartition(uint32_t id) const
Definition: ME0SegFit.h:111
bool fitdone_
Definition: ME0SegFit.h:149
float yy() const
Definition: LocalError.h:26
ME0DetId id() const
virtual LocalPoint localPosition() const
Return the 3-dimensional local position.
Definition: ME0RecHit.h:47
ME0SetOfHits hits_
Definition: ME0SegFit.h:140
const ME0EtaPartition * refme0etapart() const
Definition: ME0SegFit.h:112
#define LogTrace(id)
Definition: DetId.h:18
void setOutFromIP(void)
Definition: ME0SegFit.cc:395
LocalPoint intercept_
Definition: ME0SegFit.h:143
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
float uslope_
Definition: ME0SegFit.h:141
id_type rawId() const
void setChi2(void)
Definition: ME0SegFit.cc:284
AlgebraicSymMatrix ME0SegFit::flipErrors ( const SMatrixSym4 a)
protected

Definition at line 446 of file ME0SegFit.cc.

References a, i, and j.

Referenced by covarianceMatrix().

446  {
447 
448  // The ME0Segment needs the error matrix re-arranged to match
449  // parameters in order (uz, vz, u0, v0)
450  // where uz, vz = slopes, u0, v0 = intercepts
451 
452  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::flipErrors] input: \n" << a;
453 
454  AlgebraicSymMatrix hold(4, 0. );
455 
456  for ( short j=0; j!=4; ++j) {
457  for (short i=0; i!=4; ++i) {
458  hold(i+1,j+1) = a(i,j); // SMatrix counts from 0, AlgebraicMatrix from 1
459  }
460  }
461 
462  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::flipErrors] after copy:";
463  edm::LogVerbatim("ME0SegFit") << "(" << hold(1,1) << " " << hold(1,2) << " " << hold(1,3) << " " << hold(1,4);
464  edm::LogVerbatim("ME0SegFit") << " " << hold(2,1) << " " << hold(2,2) << " " << hold(2,3) << " " << hold(2,4);
465  edm::LogVerbatim("ME0SegFit") << " " << hold(3,1) << " " << hold(3,2) << " " << hold(3,3) << " " << hold(3,4);
466  edm::LogVerbatim("ME0SegFit") << " " << hold(4,1) << " " << hold(4,2) << " " << hold(4,3) << " " << hold(4,4) << ")";
467 
468  // errors on slopes into upper left
469  hold(1,1) = a(2,2);
470  hold(1,2) = a(2,3);
471  hold(2,1) = a(3,2);
472  hold(2,2) = a(3,3);
473 
474  // errors on positions into lower right
475  hold(3,3) = a(0,0);
476  hold(3,4) = a(0,1);
477  hold(4,3) = a(1,0);
478  hold(4,4) = a(1,1);
479 
480  // must also interchange off-diagonal elements of off-diagonal 2x2 submatrices
481  hold(4,1) = a(1,2);
482  hold(3,2) = a(0,3);
483  hold(2,3) = a(3,0); // = a(0,3)
484  hold(1,4) = a(2,1); // = a(1,2)
485 
486  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::flipErrors] after flip:";
487  edm::LogVerbatim("ME0SegFit") << "(" << hold(1,1) << " " << hold(1,2) << " " << hold(1,3) << " " << hold(1,4);
488  edm::LogVerbatim("ME0SegFit") << " " << hold(2,1) << " " << hold(2,2) << " " << hold(2,3) << " " << hold(2,4);
489  edm::LogVerbatim("ME0SegFit") << " " << hold(3,1) << " " << hold(3,2) << " " << hold(3,3) << " " << hold(3,4);
490  edm::LogVerbatim("ME0SegFit") << " " << hold(4,1) << " " << hold(4,2) << " " << hold(4,3) << " " << hold(4,4) << ")";
491 
492  return hold;
493 }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
double a
Definition: hdecay.h:121
CLHEP::HepSymMatrix AlgebraicSymMatrix
ME0SetOfHits ME0SegFit::hits ( void  ) const
inline

Definition at line 104 of file ME0SegFit.h.

References hits_.

104 { return hits_; }
ME0SetOfHits hits_
Definition: ME0SegFit.h:140
LocalPoint ME0SegFit::intercept ( ) const
inline

Definition at line 109 of file ME0SegFit.h.

References intercept_.

109 { return intercept_;}
LocalPoint intercept_
Definition: ME0SegFit.h:143
LocalVector ME0SegFit::localdir ( ) const
inline

Definition at line 110 of file ME0SegFit.h.

References localdir_.

110 { return localdir_;}
LocalVector localdir_
Definition: ME0SegFit.h:144
const ME0EtaPartition* ME0SegFit::me0etapartition ( uint32_t  id) const
inline

Definition at line 111 of file ME0SegFit.h.

References me0etapartmap_.

Referenced by derivativeMatrix(), fit2(), fitlsq(), and setChi2().

111 { return me0etapartmap_.find(id)->second; }
std::map< uint32_t, const ME0EtaPartition * > me0etapartmap_
Definition: ME0SegFit.h:138
int ME0SegFit::ndof ( void  ) const
inline

Definition at line 108 of file ME0SegFit.h.

References ndof_.

108 { return ndof_; }
int ndof_
Definition: ME0SegFit.h:146
size_t ME0SegFit::nhits ( void  ) const
inline

Definition at line 106 of file ME0SegFit.h.

References hits_.

Referenced by fit().

106 { return hits_.size(); }
ME0SetOfHits hits_
Definition: ME0SegFit.h:140
float ME0SegFit::Rdev ( float  x,
float  y,
float  z 
) const

Definition at line 513 of file ME0SegFit.cc.

References mathSSE::sqrt(), xdev(), and ydev().

513  {
514  return sqrt ( xdev(x,z)*xdev(x,z) + ydev(y,z)*ydev(y,z) );
515 }
float ydev(float y, float z) const
Definition: ME0SegFit.cc:509
T sqrt(T t)
Definition: SSEVec.h:48
float xdev(float x, float z) const
Definition: ME0SegFit.cc:505
const ME0EtaPartition* ME0SegFit::refme0etapart ( ) const
inline

Definition at line 112 of file ME0SegFit.h.

References me0etapartmap_, and refid_.

Referenced by derivativeMatrix(), fit2(), fitlsq(), setChi2(), and setOutFromIP().

112 { return me0etapartmap_.find(refid_)->second; }
std::map< uint32_t, const ME0EtaPartition * > me0etapartmap_
Definition: ME0SegFit.h:138
uint32_t refid_
Definition: ME0SegFit.h:148
double ME0SegFit::scaleXError ( void  ) const
inline

Definition at line 105 of file ME0SegFit.h.

References scaleXError_.

Referenced by weightMatrix().

105 { return scaleXError_; }
double scaleXError_
Definition: ME0SegFit.h:147
void ME0SegFit::setChi2 ( void  )
private

Definition at line 284 of file ME0SegFit.cc.

References chi2_, ztail::d, hits_, intercept_, ME0RecHit::localPosition(), ME0RecHit::localPositionError(), me0etapartition(), ndof_, convertSQLiteXML::ok, TrackingRecHit::rawId(), refme0etapart(), GeomDet::toLocal(), uslope_, findQualityFiles::v, vslope_, PV3DBase< T, PVType, FrameType >::x(), LocalError::xx(), LocalError::xy(), PV3DBase< T, PVType, FrameType >::y(), LocalError::yy(), z, and PV3DBase< T, PVType, FrameType >::z().

Referenced by fitlsq().

284  {
285 
286  double chsq = 0.;
287 
288  ME0SetOfHits::const_iterator ih;
289  for (ih = hits_.begin(); ih != hits_.end(); ++ih) {
290 
291  const ME0RecHit& hit = (**ih);
292  ME0DetId d = ME0DetId(hit.rawId());
293  const ME0EtaPartition* roll = me0etapartition(d);
294  GlobalPoint gp = roll->toGlobal(hit.localPosition());
295  LocalPoint lp = refme0etapart()->toLocal(gp);
296 
297  double u = lp.x();
298  double v = lp.y();
299  double z = lp.z();
300 
301  double du = intercept_.x() + uslope_ * z - u;
302  double dv = intercept_.y() + vslope_ * z - v;
303 
304  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::setChi2] u, v, z = " << u << ", " << v << ", " << z;
305 
306  SMatrixSym2 IC; // 2x2, init to 0
307 
308  IC(0,0) = hit.localPositionError().xx();
309  // IC(0,1) = hit.localPositionError().xy();
310  IC(1,0) = hit.localPositionError().xy();
311  IC(1,1) = hit.localPositionError().yy();
312  // IC(1,0) = IC(0,1);
313 
314  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::setChi2] IC before = \n" << IC;
315 
316  // Invert covariance matrix
317  bool ok = IC.Invert();
318  if (!ok ){
319  edm::LogVerbatim("ME0Segment|ME0SegFit") << "[ME0SegFit::setChi2] Failed to invert covariance matrix: \n" << IC;
320  // return ok;
321  }
322  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::setChi2] IC after = \n" << IC;
323  chsq += du*du*IC(0,0) + 2.*du*dv*IC(0,1) + dv*dv*IC(1,1);
324  }
325 
326  // fill member variables
327  chi2_ = chsq;
328  ndof_ = 2.*hits_.size() - 4;
329 
330  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::setChi2] chi2 = " << chi2_ << "/" << ndof_ << " dof";
331 
332 }
float xx() const
Definition: LocalError.h:24
float vslope_
Definition: ME0SegFit.h:142
T y() const
Definition: PV3DBase.h:63
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:67
virtual LocalError localPositionError() const
Return the 3-dimensional error on the local position.
Definition: ME0RecHit.h:53
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > SMatrixSym2
Definition: ME0SegFit.h:56
tuple d
Definition: ztail.py:151
float xy() const
Definition: LocalError.h:25
const ME0EtaPartition * me0etapartition(uint32_t id) const
Definition: ME0SegFit.h:111
float yy() const
Definition: LocalError.h:26
T z() const
Definition: PV3DBase.h:64
double chi2_
Definition: ME0SegFit.h:145
virtual LocalPoint localPosition() const
Return the 3-dimensional local position.
Definition: ME0RecHit.h:47
ME0SetOfHits hits_
Definition: ME0SegFit.h:140
const ME0EtaPartition * refme0etapart() const
Definition: ME0SegFit.h:112
LocalPoint intercept_
Definition: ME0SegFit.h:143
int ndof_
Definition: ME0SegFit.h:146
T x() const
Definition: PV3DBase.h:62
float uslope_
Definition: ME0SegFit.h:141
id_type rawId() const
void ME0SegFit::setOutFromIP ( void  )
protected

Definition at line 395 of file ME0SegFit.cc.

References intercept_, localdir_, refme0etapart(), mathSSE::sqrt(), GeomDet::toGlobal(), csvLumiCalc::unit, uslope_, vslope_, and z.

Referenced by fit2(), and fitlsq().

395  {
396  // Set direction of segment to point from IP outwards
397  // (Incorrect for particles not coming from IP, of course.)
398 
399  double dxdz = uslope_;
400  double dydz = vslope_;
401  double dz = 1./sqrt(1. + dxdz*dxdz + dydz*dydz);
402  double dx = dz*dxdz;
403  double dy = dz*dydz;
404  LocalVector localDir(dx,dy,dz);
405 
406  // localDir sometimes needs a sign flip
407  // Examine its direction and origin in global z: to point outward
408  // the localDir should always have same sign as global z...
409 
410  double globalZpos = ( refme0etapart()->toGlobal( intercept_ ) ).z();
411  double globalZdir = ( refme0etapart()->toGlobal( localDir ) ).z();
412  double directionSign = globalZpos * globalZdir;
413  localdir_ = (directionSign * localDir ).unit();
414 }
float vslope_
Definition: ME0SegFit.h:142
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:52
LocalVector localdir_
Definition: ME0SegFit.h:144
string unit
Definition: csvLumiCalc.py:46
T sqrt(T t)
Definition: SSEVec.h:48
const ME0EtaPartition * refme0etapart() const
Definition: ME0SegFit.h:112
LocalPoint intercept_
Definition: ME0SegFit.h:143
float uslope_
Definition: ME0SegFit.h:141
void ME0SegFit::setScaleXError ( double  factor)
inline

Definition at line 92 of file ME0SegFit.h.

References scaleXError_.

92 { scaleXError_ = factor; }
double scaleXError_
Definition: ME0SegFit.h:147
ME0SegFit::SMatrixSym12 ME0SegFit::weightMatrix ( void  )
protected

Definition at line 337 of file ME0SegFit.cc.

References hits_, ME0RecHit::localPositionError(), makeMuonMisalignmentScenario::matrix, convertSQLiteXML::ok, scaleXError(), LocalError::xx(), LocalError::xy(), and LocalError::yy().

Referenced by covarianceMatrix().

337  {
338 
339  bool ok = true;
340 
341  SMatrixSym12 matrix = ROOT::Math::SMatrixIdentity(); // 12x12, init to 1's on diag
342 
343  int row = 0;
344 
345  for (ME0SetOfHits::const_iterator it = hits_.begin(); it != hits_.end(); ++it) {
346 
347  const ME0RecHit& hit = (**it);
348 
349 // Note scaleXError allows rescaling the x error if necessary
350 
351  matrix(row, row) = scaleXError()*hit.localPositionError().xx();
352  matrix(row, row+1) = hit.localPositionError().xy();
353  ++row;
354  matrix(row, row-1) = hit.localPositionError().xy();
355  matrix(row, row) = hit.localPositionError().yy();
356  ++row;
357  }
358 
359  ok = matrix.Invert(); // invert in place
360  if ( !ok ) {
361  edm::LogVerbatim("ME0SegFit") << "[ME0SegFit::weightMatrix] Failed to invert matrix: \n" << matrix;
362  // return ok; //@@ SHOULD PASS THIS BACK TO CALLER?
363  }
364  return matrix;
365 }
float xx() const
Definition: LocalError.h:24
virtual LocalError localPositionError() const
Return the 3-dimensional error on the local position.
Definition: ME0RecHit.h:53
ROOT::Math::SMatrix< double, 12, 12, ROOT::Math::MatRepSym< double, 12 > > SMatrixSym12
Definition: ME0SegFit.h:46
float xy() const
Definition: LocalError.h:25
float yy() const
Definition: LocalError.h:26
ME0SetOfHits hits_
Definition: ME0SegFit.h:140
double scaleXError(void) const
Definition: ME0SegFit.h:105
float ME0SegFit::xdev ( float  x,
float  z 
) const

Definition at line 505 of file ME0SegFit.cc.

References intercept_, uslope_, x, and PV3DBase< T, PVType, FrameType >::x().

Referenced by Rdev().

505  {
506  return intercept_.x() + uslope_ * z - x;
507 }
LocalPoint intercept_
Definition: ME0SegFit.h:143
T x() const
Definition: PV3DBase.h:62
float uslope_
Definition: ME0SegFit.h:141
float ME0SegFit::xfit ( float  z) const

Definition at line 495 of file ME0SegFit.cc.

References intercept_, uslope_, PV3DBase< T, PVType, FrameType >::x(), and z.

495  {
496  //@@ ADD THIS TO EACH ACCESSOR OF FIT RESULTS?
497  // if ( !fitdone() ) fit();
498  return intercept_.x() + uslope_ * z;
499 }
LocalPoint intercept_
Definition: ME0SegFit.h:143
T x() const
Definition: PV3DBase.h:62
float uslope_
Definition: ME0SegFit.h:141
float ME0SegFit::ydev ( float  y,
float  z 
) const

Definition at line 509 of file ME0SegFit.cc.

References intercept_, vslope_, y, and PV3DBase< T, PVType, FrameType >::y().

Referenced by Rdev().

509  {
510  return intercept_.y() + vslope_ * z - y;
511 }
float vslope_
Definition: ME0SegFit.h:142
T y() const
Definition: PV3DBase.h:63
LocalPoint intercept_
Definition: ME0SegFit.h:143
float ME0SegFit::yfit ( float  z) const

Definition at line 501 of file ME0SegFit.cc.

References intercept_, vslope_, PV3DBase< T, PVType, FrameType >::y(), and z.

501  {
502  return intercept_.y() + vslope_ * z;
503 }
float vslope_
Definition: ME0SegFit.h:142
T y() const
Definition: PV3DBase.h:63
LocalPoint intercept_
Definition: ME0SegFit.h:143

Member Data Documentation

double ME0SegFit::chi2_
protected

Definition at line 145 of file ME0SegFit.h.

Referenced by chi2(), fit2(), and setChi2().

bool ME0SegFit::fitdone_
protected

Definition at line 149 of file ME0SegFit.h.

Referenced by fit2(), fitdone(), and fitlsq().

ME0SetOfHits ME0SegFit::hits_
protected

Definition at line 140 of file ME0SegFit.h.

Referenced by derivativeMatrix(), fit2(), fitlsq(), hits(), nhits(), setChi2(), and weightMatrix().

LocalPoint ME0SegFit::intercept_
protected

Definition at line 143 of file ME0SegFit.h.

Referenced by fit2(), fitlsq(), intercept(), setChi2(), setOutFromIP(), xdev(), xfit(), ydev(), and yfit().

LocalVector ME0SegFit::localdir_
protected

Definition at line 144 of file ME0SegFit.h.

Referenced by localdir(), and setOutFromIP().

std::map<uint32_t, const ME0EtaPartition*> ME0SegFit::me0etapartmap_
protected

Definition at line 138 of file ME0SegFit.h.

Referenced by me0etapartition(), ME0SegFit(), and refme0etapart().

int ME0SegFit::ndof_
protected

Definition at line 146 of file ME0SegFit.h.

Referenced by fit2(), ndof(), and setChi2().

uint32_t ME0SegFit::refid_
protected

Definition at line 148 of file ME0SegFit.h.

Referenced by refme0etapart().

double ME0SegFit::scaleXError_
protected

Definition at line 147 of file ME0SegFit.h.

Referenced by scaleXError(), and setScaleXError().

float ME0SegFit::uslope_
protected

Definition at line 141 of file ME0SegFit.h.

Referenced by fit2(), fitlsq(), setChi2(), setOutFromIP(), xdev(), and xfit().

float ME0SegFit::vslope_
protected

Definition at line 142 of file ME0SegFit.h.

Referenced by fit2(), fitlsq(), setChi2(), setOutFromIP(), ydev(), and yfit().