CMS 3D CMS Logo

ChiSquaredFitBase.cc
Go to the documentation of this file.
1 
4 
10 
11 #include <algorithm>
12 #include <functional>
13 #include <set>
14 
15 namespace tmtt {
16 
18  : TrackFitGeneric(settings), chiSq_(0.0) {
19  // Bad stub killing settings
22  generalResidualCut_ = settings_->generalResidualCut(); // The cut used to remove bad stubs (if nStubs > minLayers)
23  killingResidualCut_ = settings_->killingResidualCut(); // The cut used to kill off tracks entirely
24 
25  //--- These two parameters are used to check if after the fit, there are still enough stubs on the track
27  nPar_ = nPar;
28  }
29 
30  void ChiSquaredFitBase::calculateChiSq(const TVectorD& resids) {
31  chiSq_ = 0.0;
32  uint j = 0;
33  for (uint i = 0; i < stubs_.size(); i++) {
34  chiSq_ += resids[j] * resids[j] + resids[j + 1] * resids[j + 1];
35  j = j + 2;
36  }
37  }
38 
39  void ChiSquaredFitBase::calculateDeltaChiSq(const TVectorD& delX, const TVectorD& covX) {
40  for (int i = 0; i < covX.GetNrows(); i++) {
41  chiSq_ -= (delX[i]) * covX[i];
42  }
43  }
44 
46  qOverPt_seed_ = l1track3D.qOverPt();
47  stubs_ = l1track3D.stubs();
48 
49  // Get cut on number of layers including variation due to dead sectors, pt dependence etc.
51  settings_,
52  l1track3D.iPhiSec(),
53  l1track3D.iEtaReg(),
54  std::abs(l1track3D.qOverPt()),
55  l1track3D.eta());
56 
57  TVectorD x = seed(l1track3D);
58 
59  for (int i = 0; i < numFittingIterations_; i++) {
60  TMatrixD d = D(x);
61  TMatrixD dTrans(TMatrixD::kTransposed, d);
62  TMatrixD dtVinv = dTrans * Vinv();
63  TMatrixD dtVinvTrans(TMatrixD::kTransposed, dtVinv);
64  //TMatrixD M = dtVinv * d; // Must insert extra factor Vinv, due to unconventional Vinv() definition.
65  TMatrixD M = dtVinv * dtVinvTrans;
66  TMatrixD Minv(TMatrixD::kInverted, M);
67  TVectorD resids = residuals(x);
68  TVectorD deltaX = Minv * dtVinv * resids;
69  x = x - deltaX;
70  TVectorD covX = dTrans * Vinv() * resids;
71  calculateChiSq(resids);
72  calculateDeltaChiSq(deltaX, covX);
73 
74  if (i < numFittingIterations_ - 1) { // Don't kill stub if will not refit.
75 
76  resids = residuals(x); // update resids & largestresid_
77 
78  bool killWorstStub = false;
81  killWorstStub = true;
82  } else if (largestresid_ > generalResidualCut_) {
83  std::vector<Stub*> stubsTmp = stubs_;
84  stubsTmp.erase(stubsTmp.begin() + ilargestresid_);
86  killWorstStub = true;
87  } else {
88  // Get better apparent tracking performance by always killing worst stub until only 4 layers left.
90  killWorstStub = true;
91  }
92  }
93 
94  if (killWorstStub) {
95  stubs_.erase(stubs_.begin() + ilargestresid_);
96 
97  // Reject tracks with too many killed stubs & stop iterating.
98  unsigned int nLayers = Utility::countLayers(settings_, stubs_); // Count tracker layers with stubs
100 
101  if (not valid) {
102  L1fittedTrack rejectedTrk;
103  return rejectedTrk;
104  }
105  } else {
106  break;
107  }
108  }
109  }
110 
111  // Reject tracks with too many killed stubs
112  unsigned int nLayers = Utility::countLayers(settings_, stubs_); // Count tracker layers with stubs
113  bool valid = nLayers >= minStubLayersRed_;
114 
115  if (valid) {
116  const unsigned int hitPattern = 0; // FIX: Needs setting
117  const float chi2rz = 0; // FIX: Needs setting
118  return L1fittedTrack(settings_,
119  &l1track3D,
120  stubs_,
121  hitPattern,
122  x[INVR] / (settings_->invPtToInvR()),
123  0,
124  x[PHI0],
125  x[Z0],
126  x[T],
127  chiSq_,
128  chi2rz,
129  nPar_);
130  } else {
131  L1fittedTrack rejectedTrk;
132  return rejectedTrk;
133  }
134  }
135 
136 } // namespace tmtt
unsigned int iEtaReg() const override
Definition: L1track3D.h:175
float qOverPt() const override
Definition: L1track3D.h:149
virtual TVectorD residuals(const TVectorD &x)=0
unsigned int numTrackFitIterations() const
Definition: Settings.h:260
void calculateChiSq(const TVectorD &resids)
virtual TMatrixD D(const TVectorD &x)=0
const std::vector< Stub * > & stubs() const override
Definition: L1track3D.h:95
virtual TMatrixD Vinv()=0
unsigned int iPhiSec() const override
Definition: L1track3D.h:174
bool killTrackFitWorstHit() const
Definition: Settings.h:262
virtual TVectorD seed(const L1track3D &l1track3D)=0
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const Settings * settings_
ChiSquaredFitBase(const Settings *settings, const uint nPar)
std::vector< Stub * > stubs_
L1fittedTrack fit(const L1track3D &l1track3D) override
void calculateDeltaChiSq(const TVectorD &deltaX, const TVectorD &covX)
d
Definition: ztail.py:151
=== This is the base class for the linearised chi-squared track fit algorithms.
Definition: Array2D.h:16
unsigned int minStubLayers() const
Definition: Settings.h:216
float eta() const
Definition: L1track3D.h:162
float x
double generalResidualCut() const
Definition: Settings.h:266
double killingResidualCut() const
Definition: Settings.h:267
unsigned int numLayerCut(Utility::AlgoStep algo, const Settings *settings, unsigned int iPhiSec, unsigned int iEtaReg, float invPt, float eta=0.)
Definition: Utility.cc:141
unsigned int countLayers(const Settings *settings, const std::vector< const Stub *> &stubs, bool disableReducedLayerID=false, bool onlyPS=false)
Definition: Utility.cc:25
long double T
double invPtToInvR() const
Definition: Settings.h:395