CMS 3D CMS Logo

KFbase.h
Go to the documentation of this file.
1 #ifndef L1Trigger_TrackFindingTMTT_KFbase_h
2 #define L1Trigger_TrackFindingTMTT_KFbase_h
3 
10 #include <TMatrixD.h>
11 #include <TVectorD.h>
12 
13 #include <map>
14 #include <vector>
15 #include <fstream>
16 #include <memory>
17 #include <TString.h>
18 
19 class TH1F;
20 class TH2F;
21 
25 
26 namespace tmtt {
27 
28  class TP;
29  class KalmanState;
30 
31  class KFbase : public TrackFitGeneric {
32  public:
33  enum PAR_IDS { INV2R, PHI0, T, Z0, D0 };
34  enum PAR_IDS_VAR { QOVERPT };
35  enum MEAS_IDS { PHI, Z };
36 
37  public:
38  // Initialize configuration
39  KFbase(const Settings *settings, const uint nHelixPar, const std::string &fitterName = "", const uint nMeas = 2);
40 
41  ~KFbase() override { this->resetStates(); }
42 
43  KFbase(const KFbase &kf) = delete; // Disable copy & move of this class.
44  KFbase(KFbase &&kf) = delete;
45  KFbase &operator=(const KFbase &kf) = delete;
46  KFbase &operator=(KFbase &&kf) = delete;
47 
48  // Do KF fit
49  L1fittedTrack fit(const L1track3D &l1track3D) override;
50 
51  protected:
52  // Do KF fit (internal)
53  const KalmanState *doKF(const L1track3D &l1track3D, const std::vector<Stub *> &stubs, const TP *tpa);
54 
55  // Add one stub to a helix state
56  virtual const KalmanState *kalmanUpdate(
57  unsigned nSkipped, unsigned layer, Stub *stub, const KalmanState *state, const TP *tp);
58 
59  // Create a KalmanState, containing a helix state & next stub it is to be updated with.
60  const KalmanState *mkState(const L1track3D &candidate,
61  unsigned nSkipped,
62  unsigned layer,
63  const KalmanState *last_state,
64  const TVectorD &x,
65  const TMatrixD &pxx,
66  const TMatrixD &K,
67  const TMatrixD &dcov,
68  Stub *stub,
69  double chi2rphi,
70  double chi2rz);
71 
72  //--- Input data
73 
74  // Seed track helix params & covariance matrix
75  virtual TVectorD seedX(const L1track3D &l1track3D) const = 0;
76  virtual TMatrixD seedC(const L1track3D &l1track3D) const = 0;
77 
78  // Stub coordinate measurements & resolution
79  virtual TVectorD vectorM(const Stub *stub) const = 0;
80  virtual TMatrixD matrixV(const Stub *stub, const KalmanState *state) const = 0;
81 
82  //--- KF maths matrix multiplications
83 
84  // Derivate of helix intercept point w.r.t. helix params.
85  virtual TMatrixD matrixH(const Stub *stub) const = 0;
86  // Kalman helix ref point extrapolation matrix
87  virtual TMatrixD matrixF(const Stub *stub = nullptr, const KalmanState *state = nullptr) const = 0;
88  // Product of H*C*H(transpose) (where C = helix covariance matrix)
89  TMatrixD matrixHCHt(const TMatrixD &h, const TMatrixD &c) const;
90  // Get inverted Kalman R matrix: inverse(V + HCHt)
91  TMatrixD matrixRinv(const TMatrixD &matH, const TMatrixD &matCref, const TMatrixD &matV) const;
92  // Kalman gain matrix
93  TMatrixD getKalmanGainMatrix(const TMatrixD &h, const TMatrixD &pxcov, const TMatrixD &covRinv) const;
94 
95  // Residuals of stub with respect to helix.
96  virtual TVectorD residual(const Stub *stub, const TVectorD &x, double candQoverPt) const;
97 
98  // Update helix state & its covariance matrix with new stub
99  void adjustState(const TMatrixD &K,
100  const TMatrixD &pxcov,
101  const TVectorD &x,
102  const TMatrixD &h,
103  const TVectorD &delta,
104  TVectorD &new_x,
105  TMatrixD &new_xcov) const;
106  // Update track fit chi2 with new stub
107  virtual void adjustChi2(const KalmanState *state,
108  const TMatrixD &covRinv,
109  const TVectorD &delta,
110  double &chi2rphi,
111  double &chi2rz) const;
112 
113  //--- Utilities
114 
115  // Reset internal data ready for next track.
116  void resetStates();
117 
118  // Convert to physical helix params instead of local ones used by KF
119  virtual TVectorD trackParams(const KalmanState *state) const = 0;
120  // Ditto after applying beam-spot constraint.
121  virtual TVectorD trackParams_BeamConstr(const KalmanState *state, double &chi2rphi_bcon) const = 0;
122 
123  // Get phi of centre of sector containing track.
124  double sectorPhi() const {
125  float phiCentreSec0 = -M_PI / float(settings_->numPhiNonants()) + M_PI / float(settings_->numPhiSectors());
126  return 2. * M_PI * float(iPhiSec_) / float(settings_->numPhiSectors()) + phiCentreSec0;
127  }
128 
129  // Get KF layer (which is integer representing order layers cross)
130  virtual unsigned int kalmanLayer(
131  unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const;
132  // Check if it is unclear whether a particle is expect to cross this layer.
133  virtual bool kalmanAmbiguousLayer(unsigned int iEtaReg, unsigned int kfLayer);
134  // KF algo mods to cope with dead tracker layers.
135  std::set<unsigned> kalmanDeadLayers(bool &remove2PSCut) const;
136 
137  // Function to calculate approximation for tilted barrel modules (aka B) copied from Stub class.
138  float approxB(float z, float r) const;
139 
140  // Is this HLS code?
141  virtual bool isHLS() { return false; };
142 
143  // Helix state pases cuts.
144  virtual bool isGoodState(const KalmanState &state) const = 0;
145 
146  //--- Debug printout
147  void printTP(const TP *tp) const;
148  void printStubLayers(const std::vector<Stub *> &stubs, unsigned int iEtaReg) const;
149  void printStub(const Stub *stub) const;
150  void printStubs(const std::vector<Stub *> &stubs) const;
151 
152  protected:
153  unsigned nHelixPar_;
154  unsigned nMeas_;
155  unsigned numEtaRegions_;
156 
157  unsigned int iPhiSec_;
158  unsigned int iEtaReg_;
159 
160  unsigned int numUpdateCalls_;
161 
162  // All helix states KF produces for current track.
163  std::vector<std::unique_ptr<const KalmanState>> listAllStates_;
164 
165  const TP *tpa_;
166  };
167 
168 } // namespace tmtt
169 
170 #endif
tmtt::KFbase::matrixF
virtual TMatrixD matrixF(const Stub *stub=nullptr, const KalmanState *state=nullptr) const =0
L1fittedTrack.h
tmtt::KFbase::adjustChi2
virtual void adjustChi2(const KalmanState *state, const TMatrixD &covRinv, const TVectorD &delta, double &chi2rphi, double &chi2rz) const
Definition: KFbase.cc:659
tmtt::KFbase::isGoodState
virtual bool isGoodState(const KalmanState &state) const =0
Reference_intrackfit_cff.barrel
list barrel
Definition: Reference_intrackfit_cff.py:37
tmtt::KFbase::printStubs
void printStubs(const std::vector< Stub * > &stubs) const
Definition: KFbase.cc:962
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
tmtt::KFbase::doKF
const KalmanState * doKF(const L1track3D &l1track3D, const std::vector< Stub * > &stubs, const TP *tpa)
Definition: KFbase.cc:166
tmtt::Settings::numPhiNonants
unsigned int numPhiNonants() const
Definition: Settings.h:109
tmtt::KFbase::iPhiSec_
unsigned int iPhiSec_
Definition: KFbase.h:157
tmtt::KFbase::nMeas_
unsigned nMeas_
Definition: KFbase.h:154
Stub.h
tmtt::KFbase::resetStates
void resetStates()
Definition: KFbase.cc:678
tmtt::KFbase::QOVERPT
Definition: KFbase.h:34
tmtt::KFbase::numEtaRegions_
unsigned numEtaRegions_
Definition: KFbase.h:155
tmtt::KFbase::D0
Definition: KFbase.h:33
DigiToRawDM_cff.TP
TP
Definition: DigiToRawDM_cff.py:51
tmtt::KFbase::residual
virtual TVectorD residual(const Stub *stub, const TVectorD &x, double candQoverPt) const
Definition: KFbase.cc:588
tmtt::KFbase::numUpdateCalls_
unsigned int numUpdateCalls_
Definition: KFbase.h:160
tmtt::KFbase::PHI0
Definition: KFbase.h:33
tmtt::TP
Definition: TP.h:23
tmtt::KFbase::matrixHCHt
TMatrixD matrixHCHt(const TMatrixD &h, const TMatrixD &c) const
Definition: KFbase.cc:549
L1track3D.h
parallelization.uint
uint
Definition: parallelization.py:124
tmtt::KFbase::printStub
void printStub(const Stub *stub) const
Definition: KFbase.cc:942
tmtt::KFbase::Z0
Definition: KFbase.h:33
tmtt::KFbase::PHI
Definition: KFbase.h:35
tmtt::KFbase::trackParams
virtual TVectorD trackParams(const KalmanState *state) const =0
tmtt::TrackFitGeneric::settings_
const Settings * settings_
Definition: TrackFitGeneric.h:31
tmtt::KFbase::matrixH
virtual TMatrixD matrixH(const Stub *stub) const =0
tmtt::KFbase::fit
L1fittedTrack fit(const L1track3D &l1track3D) override
Definition: KFbase.cc:38
tmtt::TrackFitGeneric
Definition: TrackFitGeneric.h:18
tmtt::KFbase::PAR_IDS_VAR
PAR_IDS_VAR
Definition: KFbase.h:34
tmtt::KFbase::mkState
const KalmanState * mkState(const L1track3D &candidate, unsigned nSkipped, unsigned layer, const KalmanState *last_state, const TVectorD &x, const TMatrixD &pxx, const TMatrixD &K, const TMatrixD &dcov, Stub *stub, double chi2rphi, double chi2rz)
Definition: KFbase.cc:528
tmtt::KFbase::iEtaReg_
unsigned int iEtaReg_
Definition: KFbase.h:158
h
tmtt::KFbase::T
Definition: KFbase.h:33
tmtt::KFbase::MEAS_IDS
MEAS_IDS
Definition: KFbase.h:35
tmtt::KFbase::kalmanUpdate
virtual const KalmanState * kalmanUpdate(unsigned nSkipped, unsigned layer, Stub *stub, const KalmanState *state, const TP *tp)
Definition: KFbase.cc:408
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
tmtt::KFbase::nHelixPar_
unsigned nHelixPar_
Definition: KFbase.h:153
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
tmtt::KFbase::KFbase
KFbase(const Settings *settings, const uint nHelixPar, const std::string &fitterName="", const uint nMeas=2)
tmtt::L1fittedTrack
Definition: L1fittedTrack.h:30
KalmanState.h
tmtt::KFbase::vectorM
virtual TVectorD vectorM(const Stub *stub) const =0
tmtt::KalmanState
Definition: KalmanState.h:22
tmtt::KFbase::approxB
float approxB(float z, float r) const
Definition: KFbase.cc:880
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
tmtt::KFbase::isHLS
virtual bool isHLS()
Definition: KFbase.h:141
tmtt::Settings
Definition: Settings.h:17
tmtt::KFbase::getKalmanGainMatrix
TMatrixD getKalmanGainMatrix(const TMatrixD &h, const TMatrixD &pxcov, const TMatrixD &covRinv) const
Definition: KFbase.cc:579
tmtt::KFbase::printStubLayers
void printStubLayers(const std::vector< Stub * > &stubs, unsigned int iEtaReg) const
Definition: KFbase.cc:914
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
tmtt::KFbase
Definition: KFbase.h:31
tmtt::Settings::numPhiSectors
unsigned int numPhiSectors() const
Definition: Settings.h:110
tmtt::KFbase::Z
Definition: KFbase.h:35
tmtt::KFbase::kalmanDeadLayers
std::set< unsigned > kalmanDeadLayers(bool &remove2PSCut) const
Definition: KFbase.cc:825
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
tmtt::KFbase::trackParams_BeamConstr
virtual TVectorD trackParams_BeamConstr(const KalmanState *state, double &chi2rphi_bcon) const =0
alignCSCRings.r
r
Definition: alignCSCRings.py:93
tmtt::KFbase::kalmanAmbiguousLayer
virtual bool kalmanAmbiguousLayer(unsigned int iEtaReg, unsigned int kfLayer)
Definition: KFbase.cc:790
tmtt::KFbase::matrixV
virtual TMatrixD matrixV(const Stub *stub, const KalmanState *state) const =0
tmtt::KFbase::PAR_IDS
PAR_IDS
Definition: KFbase.h:33
tmtt::KFbase::seedX
virtual TVectorD seedX(const L1track3D &l1track3D) const =0
Settings.h
TrackFitGeneric.h
tmtt::KFbase::tpa_
const TP * tpa_
Definition: KFbase.h:165
tmtt::KFbase::printTP
void printTP(const TP *tp) const
Definition: KFbase.cc:886
tmtt::KFbase::kalmanLayer
virtual unsigned int kalmanLayer(unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const
Definition: KFbase.cc:682
tmtt::KFbase::INV2R
Definition: KFbase.h:33
tmtt::Stub
Definition: Stub.h:43
tmtt::L1track3D
Definition: L1track3D.h:24
tmtt::KFbase::~KFbase
~KFbase() override
Definition: KFbase.h:41
tmtt
=== This is the base class for the linearised chi-squared track fit algorithms.
Definition: ChiSquaredFit4.h:6
tmtt::KFbase::operator=
KFbase & operator=(const KFbase &kf)=delete
tmtt::KFbase::seedC
virtual TMatrixD seedC(const L1track3D &l1track3D) const =0
tmtt::KFbase::adjustState
void adjustState(const TMatrixD &K, const TMatrixD &pxcov, const TVectorD &x, const TMatrixD &h, const TVectorD &delta, TVectorD &new_x, TMatrixD &new_xcov) const
Definition: KFbase.cc:644
tmtt::KFbase::sectorPhi
double sectorPhi() const
Definition: KFbase.h:124
tmtt::KFbase::matrixRinv
TMatrixD matrixRinv(const TMatrixD &matH, const TMatrixD &matCref, const TMatrixD &matV) const
Definition: KFbase.cc:556
tmtt::KFbase::listAllStates_
std::vector< std::unique_ptr< const KalmanState > > listAllStates_
Definition: KFbase.h:163