CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CollinearFitAtTM.cc
Go to the documentation of this file.
3 
5 {
6  //
7  // Jacobian
8  //
9  for ( int i=0; i<12; ++i ) {
10  for ( int j=0; j<6; ++j ) jacobian_(i,j) = 0;
11  }
12  for ( int i=1; i<5; ++i ) {
14  }
15  jacobian_(0,ParQpIn) = 1.;
16  jacobian_(5,ParQpOut) = 1.;
17 }
18 
19 bool
22  ResultMatrix& covariance,
23  double& chi2)
24 {
25  //
26  // check input
27  //
28  if ( !tm.forwardPredictedState().isValid() ||
30  !tm.updatedState().isValid() ) {
31  edm::LogWarning("CollinearFitAtTM") << "Invalid state in TrajectoryMeasurement";
32  return false;
33  }
34  //
35  // prepare fit
36  //
41 
42  LocalPoint hitPos(0.,0.,0.);
43  LocalError hitErr(-1.,-1.,-1.);
44  if ( tm.recHit()->isValid() ) {
45  hitPos = tm.recHit()->localPosition();
46  hitErr = tm.recHit()->localPositionError();
47  }
48 
49  return fit(fwdPar,fwdCov,bwdPar,bwdCov,
50  hitPos,hitErr,
51  parameters,covariance,chi2);
52 }
53 
54 bool
55 CollinearFitAtTM::fit (const AlgebraicVector5& fwdParameters,
56  const AlgebraicSymMatrix55& fwdCovariance,
57  const AlgebraicVector5& bwdParameters,
58  const AlgebraicSymMatrix55& bwdCovariance,
59  const LocalPoint& hitPos, const LocalError& hitErr,
60  ResultVector& parameters, ResultMatrix& covariance,
61  double& chi2)
62 {
63 
64  if ( hitErr.xx()>0 )
65  jacobian_(10,ParX) = jacobian_(11,ParY) = 1;
66  else
67  jacobian_(10,ParX) = jacobian_(11,ParY) = 0;
68 
69  for ( int i=0; i<12; ++i ) {
70  for ( int j=0; j<12; ++j ) weightMatrix_(i,j) = 0;
71  }
72 
73  for ( int i=0; i<5; ++i ) measurements_(i) = fwdParameters(i);
74  weightMatrix_.Place_at(fwdCovariance,0,0);
75  for ( int i=0; i<5; ++i ) measurements_(i+5) = bwdParameters(i);
76  weightMatrix_.Place_at(bwdCovariance,5,5);
77  if ( hitErr.xx()>0 ) {
78  measurements_(10) = hitPos.x();
79  measurements_(11) = hitPos.y();
80  weightMatrix_(10,10) = hitErr.xx();
81  weightMatrix_(10,11) = weightMatrix_(11,10) = hitErr.xy();
82  weightMatrix_(11,11) = hitErr.yy();
83  }
84  else {
85  measurements_(10) = measurements_(11) = 0.;
86  weightMatrix_(10,10) = weightMatrix_(11,11) = 1.;
87  weightMatrix_(10,11) = weightMatrix_(11,10) = 0.;
88  }
89  //
90  // invert covariance matrix
91  //
92  if ( !weightMatrix_.Invert() ) {
93  edm::LogWarning("CollinearFitAtTM") << "Inversion of input covariance matrix failed";
94  return false;
95  }
96 
97  //
99  //
100  // Fitted parameters and covariance matrix
101  //
102  covariance = ROOT::Math::SimilarityT(jacobian_,weightMatrix_);
103  if ( !covariance.Invert() ) {
104  edm::LogWarning("CollinearFitAtTM") << "Inversion of resulting weight matrix failed";
105  return false;
106  }
107 
108  parameters = covariance*projectedMeasurements_;
109 
110  //
111  // chi2
112  //
113  chi2 = ROOT::Math::Similarity(measurements_,weightMatrix_) -
114  ROOT::Math::Similarity(projectedMeasurements_,covariance);
115 
116  return true;
117 }
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:24
dictionary parameters
Definition: Parameters.py:2
ConstRecHitPointer const & recHit() const
const LocalTrajectoryParameters & localParameters() const
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > ResultMatrix
ROOT::Math::SVector< double, 6 > projectedMeasurements_
bool fit(const TrajectoryMeasurement &tm, ResultVector &parameters, ResultMatrix &covariance, double &chi2)
Fit for one TM. Return value &quot;true&quot; for success.
T y() const
Definition: PV3DBase.h:63
ROOT::Math::SMatrix< double, 12, 12, ROOT::Math::MatRepSym< double, 12 > > weightMatrix_
ROOT::Math::SVector< double, 6 > ResultVector
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
AlgebraicVector5 vector() const
float xy() const
Definition: LocalError.h:25
float yy() const
Definition: LocalError.h:26
int j
Definition: DBlmapReader.cc:9
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
ROOT::Math::SVector< double, 5 > AlgebraicVector5
ROOT::Math::SMatrix< double, 12, 6 > jacobian_
TrajectoryStateOnSurface const & updatedState() const
T x() const
Definition: PV3DBase.h:62
ROOT::Math::SVector< double, 12 > measurements_
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)