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
tmtt::ChiSquaredFitBase::Vinv
virtual TMatrixD Vinv()=0
tmtt::ChiSquaredFitBase::residuals
virtual TVectorD residuals(const TVectorD &x)=0
L1fittedTrack.h
tmtt::Settings::numTrackFitIterations
unsigned int numTrackFitIterations() const
Definition: Settings.h:260
tmtt::L1track3D::qOverPt
float qOverPt() const override
Definition: L1track3D.h:149
tmtt::ChiSquaredFitBase::Z0
Definition: ChiSquaredFitBase.h:23
mps_fire.i
i
Definition: mps_fire.py:355
ChiSquaredFitBase.h
tmtt::ChiSquaredFitBase::calculateDeltaChiSq
void calculateDeltaChiSq(const TVectorD &deltaX, const TVectorD &covX)
Definition: ChiSquaredFitBase.cc:39
tmtt::ChiSquaredFitBase::INVR
Definition: ChiSquaredFitBase.h:23
tmtt::ChiSquaredFitBase::PHI0
Definition: ChiSquaredFitBase.h:23
tmtt::Utility::countLayers
unsigned int countLayers(const Settings *settings, const std::vector< const Stub * > &stubs, bool disableReducedLayerID=false, bool onlyPS=false)
Definition: Utility.cc:25
tmtt::ChiSquaredFitBase::calculateChiSq
void calculateChiSq(const TVectorD &resids)
Definition: ChiSquaredFitBase.cc:30
tmtt::ChiSquaredFitBase::fit
L1fittedTrack fit(const L1track3D &l1track3D) override
Definition: ChiSquaredFitBase.cc:45
tmtt::L1track3D::stubs
const std::vector< Stub * > & stubs() const override
Definition: L1track3D.h:95
tmtt::Settings::minStubLayers
unsigned int minStubLayers() const
Definition: Settings.h:216
Stub.h
tmtt::Settings::killingResidualCut
double killingResidualCut() const
Definition: Settings.h:267
tmtt::L1track3D::iEtaReg
unsigned int iEtaReg() const override
Definition: L1track3D.h:175
tmtt::ChiSquaredFitBase::nPar_
uint nPar_
Definition: ChiSquaredFitBase.h:41
L1track3D.h
tmtt::ChiSquaredFitBase::minStubLayersRed_
unsigned int minStubLayersRed_
Definition: ChiSquaredFitBase.h:56
parallelization.uint
uint
Definition: parallelization.py:124
validateGeometry_cfg.valid
valid
Definition: validateGeometry_cfg.py:21
HcalResponse_cfi.nPar
nPar
Definition: HcalResponse_cfi.py:33
Utility.h
tmtt::Utility::FIT
Definition: Utility.h:28
tmtt::TrackFitGeneric::settings_
const Settings * settings_
Definition: TrackFitGeneric.h:31
tmtt::L1track3D::iPhiSec
unsigned int iPhiSec() const override
Definition: L1track3D.h:174
tmtt::TrackFitGeneric
Definition: TrackFitGeneric.h:18
tmtt::ChiSquaredFitBase::generalResidualCut_
double generalResidualCut_
Definition: ChiSquaredFitBase.h:52
tmtt::ChiSquaredFitBase::killingResidualCut_
double killingResidualCut_
Definition: ChiSquaredFitBase.h:53
tmtt::ChiSquaredFitBase::minStubLayers_
unsigned int minStubLayers_
Definition: ChiSquaredFitBase.h:55
MuonTCMETValueMapProducer_cff.nLayers
nLayers
Definition: MuonTCMETValueMapProducer_cff.py:38
tmtt::ChiSquaredFitBase::D
virtual TMatrixD D(const TVectorD &x)=0
tmtt::L1fittedTrack
Definition: L1fittedTrack.h:30
tmtt::ChiSquaredFitBase::seed
virtual TVectorD seed(const L1track3D &l1track3D)=0
tmtt::Settings
Definition: Settings.h:17
tmtt::ChiSquaredFitBase::numFittingIterations_
int numFittingIterations_
Definition: ChiSquaredFitBase.h:50
tmtt::Utility::numLayerCut
unsigned int numLayerCut(Utility::AlgoStep algo, const Settings *settings, unsigned int iPhiSec, unsigned int iEtaReg, float invPt, float eta=0.)
Definition: Utility.cc:141
tmtt::ChiSquaredFitBase::qOverPt_seed_
double qOverPt_seed_
Definition: ChiSquaredFitBase.h:38
tmtt::Settings::generalResidualCut
double generalResidualCut() const
Definition: Settings.h:266
tmtt::ChiSquaredFitBase::largestresid_
float largestresid_
Definition: ChiSquaredFitBase.h:42
tmtt::ChiSquaredFitBase::stubs_
std::vector< Stub * > stubs_
Definition: ChiSquaredFitBase.h:39
T
long double T
Definition: Basic3DVectorLD.h:48
tmtt::ChiSquaredFitBase::killTrackFitWorstHit_
int killTrackFitWorstHit_
Definition: ChiSquaredFitBase.h:51
tmtt::Settings::killTrackFitWorstHit
bool killTrackFitWorstHit() const
Definition: Settings.h:262
tmtt::ChiSquaredFitBase::ChiSquaredFitBase
ChiSquaredFitBase(const Settings *settings, const uint nPar)
Definition: ChiSquaredFitBase.cc:17
ztail.d
d
Definition: ztail.py:151
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
tmtt::L1track3D
Definition: L1track3D.h:24
tmtt
=== This is the base class for the linearised chi-squared track fit algorithms.
Definition: ChiSquaredFit4.h:6
tmtt::L1track3D::eta
float eta() const
Definition: L1track3D.h:162
tmtt::Settings::invPtToInvR
double invPtToInvR() const
Definition: Settings.h:393
tmtt::ChiSquaredFitBase::chiSq_
double chiSq_
Definition: ChiSquaredFitBase.h:44
tmtt::ChiSquaredFitBase::ilargestresid_
int ilargestresid_
Definition: ChiSquaredFitBase.h:43