CMS 3D CMS Logo

ChiSquaredFit4.cc
Go to the documentation of this file.
3 
4 using namespace std;
5 
6 namespace tmtt {
7 
8  ChiSquaredFit4::ChiSquaredFit4(const Settings* settings, const uint nPar) : ChiSquaredFitBase(settings, nPar) {
9  largestresid_ = -1.0;
10  ilargestresid_ = -1;
11  }
12 
13  TVectorD ChiSquaredFit4::seed(const L1track3D& l1track3D) {
14  TVectorD x(4);
15  x[INVR] = settings_->invPtToInvR() * l1track3D.qOverPt();
16  x[PHI0] = l1track3D.phi0();
17  x[T] = l1track3D.tanLambda();
18  x[Z0] = l1track3D.z0();
19  return x;
20  }
21 
22  //=== Calculate derivatives of track intercept with respect to track parameters
23 
24  TMatrixD ChiSquaredFit4::D(const TVectorD& x) {
25  TMatrixD D(2 * stubs_.size(), nPar_); // Empty matrix
26  D.Zero();
27  int j = 0;
28  double rInv = x[INVR];
29  double phi0 = x[PHI0];
30  double t = x[T];
31  for (unsigned i = 0; i < stubs_.size(); i++) {
32  double ri = stubs_[i]->r();
33  if (stubs_[i]->barrel()) {
34  // Derivatives of r*phi
35  D(j, INVR) = -0.5 * ri * ri;
36  D(j, PHI0) = ri;
37  j++;
38  // Derivatives of z
39  D(j, T) = ri;
40  D(j, Z0) = 1;
41  j++;
42  } else {
43  double phii = stubs_[i]->phi();
44  int iphi = stubs_[i]->iphi();
45 
46  // N.B. These represent HALF the width and number of strips of sensor.
47  double width = 0.5 * stubs_[i]->trackerModule()->sensorWidth();
48  double nstrip = 0.5 * stubs_[i]->nStrips();
49 
50  double Deltai = width * (iphi - nstrip) / nstrip; // Non-radial endcap 2S strip correction
51  if (stubs_[i]->z() > 0.0)
52  Deltai = -Deltai;
53  double DeltaiOverRi = Deltai / ri;
54  double theta0 = DeltaiOverRi + (2. / 3.) * DeltaiOverRi * DeltaiOverRi * DeltaiOverRi;
55 
56  double phi_track = phi0 - 0.5 * rInv * ri; //Expected phi hit given the track
57 
58  double tInv = 1 / t;
59  // Derivatives of r
60  D(j, INVR) = -1 * ri * ri * ri * rInv;
61  D(j, PHI0) = 0;
62  D(j, T) = -ri * tInv;
63  D(j, Z0) = -1 * tInv;
64  j++;
65  // Derivatives of r*phi
66  D(j, INVR) = -0.5 * ri * ri;
67  D(j, PHI0) = ri;
68  D(j, T) = ri * 0.5 * rInv * ri * tInv - ((phi_track - phii) - theta0) * ri * tInv;
69  D(j, Z0) = ri * 0.5 * rInv * tInv - ((phi_track - phii) - theta0) * tInv;
70  j++;
71  }
72  }
73  return D;
74  }
75 
76  //=== In principle, this is the stub position covariance matrix.
77  //=== In practice, it misses a factor "sigma", because unconventionally, this is absorbed into residuals() function.
78 
79  TMatrixD ChiSquaredFit4::Vinv() {
80  TMatrixD Vinv(2 * stubs_.size(), 2 * stubs_.size());
81  // Scattering term scaling as 1/Pt.
82  double sigmaScat = settings_->kalmanMultiScattTerm() * std::abs(qOverPt_seed_);
83  for (unsigned i = 0; i < stubs_.size(); i++) {
84  double sigmaPerp = stubs_[i]->sigmaPerp();
85  double sigmaPar = stubs_[i]->sigmaPar();
86  double ri = stubs_[i]->r();
87  sigmaPerp = sqrt(sigmaPerp * sigmaPerp + sigmaScat * sigmaScat * ri * ri);
88  if (stubs_[i]->barrel()) {
89  Vinv(2 * i, 2 * i) = 1 / sigmaPerp;
90  Vinv(2 * i + 1, 2 * i + 1) = 1 / sigmaPar;
91  } else {
92  Vinv(2 * i, 2 * i) = 1 / sigmaPar;
93  Vinv(2 * i + 1, 2 * i + 1) = 1 / sigmaPerp;
94  }
95  }
96  return Vinv;
97  }
98 
99  //=== Calculate residuals w.r.t. track divided by uncertainty.
100 
101  TVectorD ChiSquaredFit4::residuals(const TVectorD& x) {
102  unsigned int n = stubs_.size();
103 
104  TVectorD delta(2 * n);
105 
106  double rInv = x[INVR];
107  double phi0 = x[PHI0];
108  double t = x[T];
109  double z0 = x[Z0];
110 
111  unsigned int j = 0;
112 
113  largestresid_ = -1.0;
114  ilargestresid_ = -1;
115 
116  // Scattering term scaling as 1/Pt.
117  double sigmaScat = settings_->kalmanMultiScattTerm() * std::abs(qOverPt_seed_);
118 
119  for (unsigned int i = 0; i < n; i++) {
120  double ri = stubs_[i]->r();
121  double zi = stubs_[i]->z();
122  double phii = stubs_[i]->phi();
123  double sigmaPerp = stubs_[i]->sigmaPerp();
124  double sigmaPar = stubs_[i]->sigmaPar();
125  sigmaPerp = sqrt(sigmaPerp * sigmaPerp + sigmaScat * sigmaScat * ri * ri);
126 
127  if (stubs_[i]->barrel()) {
128  double halfRinvRi = 0.5 * ri * rInv;
129  double aSinHalfRinvRi = halfRinvRi + (2. / 3.) * halfRinvRi * halfRinvRi * halfRinvRi;
130  double deltaphi = reco::deltaPhi(phi0 - aSinHalfRinvRi - phii, 0.);
131  delta[j++] = (ri * deltaphi) / sigmaPerp;
132  delta[j++] = (z0 + (2.0 / rInv) * t * aSinHalfRinvRi - zi) / sigmaPar;
133  } else {
134  double tInv = 1 / t;
135  double r_track = (zi - z0) * tInv;
136  double phi_track = phi0 - 0.5 * rInv * (zi - z0) * tInv;
137  int iphi = stubs_[i]->iphi();
138 
139  // N.B. These represent HALF the width and number of strips of sensor.
140  double width = 0.5 * stubs_[i]->trackerModule()->sensorWidth();
141  double nstrip = 0.5 * stubs_[i]->nStrips();
142 
143  double Deltai = width * (iphi - nstrip) / nstrip; // Non-radial endcap 2S strip correction
144 
145  if (stubs_[i]->z() > 0.0)
146  Deltai = -Deltai;
147 
148  double DeltaiOverRi = Deltai / ri;
149  double theta0 = DeltaiOverRi + (2. / 3.) * DeltaiOverRi * DeltaiOverRi * DeltaiOverRi;
150  double Delta = Deltai - r_track * (theta0 - (phi_track - phii));
151 
152  delta[j++] = (r_track - ri) / sigmaPar;
153  delta[j++] = Delta / sigmaPerp;
154  }
155 
156  if (std::abs(delta[j - 2]) > largestresid_) {
157  largestresid_ = std::abs(delta[j - 2]);
158  ilargestresid_ = i;
159  }
160 
161  if (std::abs(delta[j - 1]) > largestresid_) {
162  largestresid_ = std::abs(delta[j - 1]);
163  ilargestresid_ = i;
164  }
165  }
166 
167  return delta;
168  }
169 
170 } // namespace tmtt
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
float phi0() const override
Definition: L1track3D.h:158
float qOverPt() const override
Definition: L1track3D.h:149
float z0() const
Definition: L1track3D.h:159
float tanLambda() const
Definition: L1track3D.h:160
TVectorD seed(const L1track3D &l1track3D) override
TMatrixD Vinv() override
T sqrt(T t)
Definition: SSEVec.h:19
double kalmanMultiScattTerm() const
Definition: Settings.h:324
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const Settings * settings_
std::vector< Stub * > stubs_
=== This is the base class for the linearised chi-squared track fit algorithms.
Definition: Array2D.h:16
float x
TVectorD residuals(const TVectorD &x) override
long double T
TMatrixD D(const TVectorD &x) override
double invPtToInvR() const
Definition: Settings.h:395