CMS 3D CMS Logo

KFTrackletTrack.h
Go to the documentation of this file.
1 #ifndef L1Trigger_TrackFindingTMTT_KFTrackletTrack_h
2 #define L1Trigger_TrackFindingTMTT_KFTrackletTrack_h
3 
12 
13 #include <vector>
14 #include <utility>
15 #include <string>
16 
17 //=== This is used uniquely for HYBRID TRACKING.
18 //=== It is the equivalent of class L1fittedTrack.
19 //===
20 //=== This represents a fitted L1 track candidate found in 3 dimensions.
21 //=== It gives access to the fitted helix parameters & chi2 etc.
22 //=== It also calculates & gives access to associated truth particle (Tracking Particle) if any.
23 //=== It also gives access to the 3D hough-transform track candidate (L1track3D) on which the fit was run.
24 
25 namespace tmtt {
26 
28  public:
29  // Store a new fitted track, specifying the input Hough transform track, the stubs used for the fit,
30  // bit-encoded hit layers,
31  // the fitted helix parameters & chi2,
32  // and the number of helix parameters being fitted (=5 if d0 is fitted, or =4 if d0 is not fitted).
33  // Also specify phi sector and eta region used by track-finding code that this track was in.
34  // And if track fit declared this to be a valid track (enough stubs left on track after fit etc.).
36  const std::vector<const Stub*>& stubs,
37  unsigned int hitPattern,
38  float qOverPt,
39  float d0,
40  float phi0,
41  float z0,
42  float tanLambda,
43  float chi2rphi,
44  float chi2rz,
45  unsigned int nHelixParam,
46  unsigned int iPhiSec,
47  unsigned int iEtaReg,
48  bool accepted = true,
49  bool done_bcon = false,
50  float qOverPt_bcon = 0.,
51  float d0_bcon = 0.,
52  float phi0_bcon = 0.,
53  float chi2rphi_bcon = 0.)
55  stubs_(stubs),
58  d0_(d0),
59  phi0_(phi0),
60  z0_(z0),
63  chi2rz_(chi2rz),
73  nSkippedLayers_(0),
74  numUpdateCalls_(0),
75  numIterations_(0),
77 
78  //--- Set/get additional info about fitted track that is specific to individual track fit algorithms (KF, LR, chi2)
79  //--- and is used for debugging/histogramming purposes.
80 
81  void setInfoKF(unsigned int nSkippedLayers, unsigned int numUpdateCalls) {
82  nSkippedLayers_ = nSkippedLayers;
83  numUpdateCalls_ = numUpdateCalls;
84  }
85 
86  void infoKF(unsigned int& nSkippedLayers, unsigned int& numUpdateCalls) const {
87  nSkippedLayers = nSkippedLayers_;
88  numUpdateCalls = numUpdateCalls_;
89  }
90 
91  const L1track3D* l1track3D() const { return l1track3D_; }
92 
93  // Get stubs on fitted track (can differ from those on HT track if track fit kicked out stubs with bad residuals)
94  const std::vector<const Stub*>& stubs() const { return stubs_; }
95  // Get number of stubs on fitted track.
96  unsigned int numStubs() const { return stubs_.size(); }
97  // Get number of tracker layers these stubs are in.
98  unsigned int numLayers() const { return nLayers_; }
99  // Get number of stubs deleted from track candidate by fitter (because they had large residuals)
100  unsigned int numKilledStubs() const { return l1track3D_->numStubs() - this->numStubs(); }
101 
102  // Get bit-encoded hit pattern (where layer number assigned by increasing distance from origin, according to layers track expected to cross).
103  unsigned int hitPattern() const { return hitPattern_; }
104 
105  //--- Get the fitted track helix parameters.
106 
107  float qOverPt() const { return qOverPt_; }
108  float charge() const { return (qOverPt_ > 0 ? 1 : -1); }
109  float invPt() const { return std::abs(qOverPt_); }
110  // Protect pt against 1/pt = 0.
111  float pt() const {
112  constexpr float small = 1.0e-6;
113  return 1. / (small + this->invPt());
114  }
115  float d0() const { return d0_; }
116  float phi0() const { return phi0_; }
117  float z0() const { return z0_; }
118  float tanLambda() const { return tanLambda_; }
119  float theta() const { return atan2(1., tanLambda_); } // Use atan2 to ensure 0 < theta < pi.
120  float eta() const { return -log(tan(0.5 * this->theta())); }
121 
122  //--- Get the fitted helix parameters with beam-spot constraint.
123  //--- If constraint not applied (e.g. 4 param fit) then these are identical to unconstrained values.
124 
125  bool done_bcon() const { return done_bcon_; } // Was beam-spot constraint aplied?
126  float qOverPt_bcon() const { return qOverPt_bcon_; }
127  float charge_bcon() const { return (qOverPt_bcon_ > 0 ? 1 : -1); }
128  float invPt_bcon() const { return std::abs(qOverPt_bcon_); }
129  float pt_bcon() const { return 1. / (1.0e-6 + this->invPt_bcon()); }
130  float phi0_bcon() const { return phi0_bcon_; }
131  float d0_bcon() const { return d0_bcon_; }
132 
133  // Phi and z coordinates at which track crosses "chosenR" values used by r-phi HT and rapidity sectors respectively.
134  // (Optionally with beam-spot constraint applied).
135  float phiAtChosenR(bool beamConstraint) const {
136  if (beamConstraint) {
137  return reco::deltaPhi(phi0_bcon_ -
140  0.);
141  } else {
143  d0_ / (settings_->chosenRofPhi()),
144  0.);
145  }
146  }
147  float zAtChosenR() const {
148  return (z0_ + (settings_->chosenRofZ()) * tanLambda_);
149  } // neglects transverse impact parameter & track curvature.
150 
151  // Get the number of helix parameters being fitted (=5 if d0 is fitted or =4 if d0 is not fitted).
152  float nHelixParam() const { return nHelixParam_; }
153 
154  // Get the fit degrees of freedom, chi2 & chi2/DOF
155  unsigned int numDOF() const { return 2 * this->numStubs() - nHelixParam_; }
156  unsigned int numDOFrphi() const { return this->numStubs() - (nHelixParam_ - 2); }
157  unsigned int numDOFrz() const { return this->numStubs() - 2; }
158  float chi2rphi() const { return chi2rphi_; }
159  float chi2rz() const { return chi2rz_; }
160  float chi2() const { return chi2rphi_ + chi2rz_; }
161  float chi2dof() const { return (this->chi2()) / this->numDOF(); }
162 
163  //--- Ditto, but if beam-spot constraint is applied.
164  //--- If constraint not applied (e.g. 4 param fit) then these are identical to unconstrained values.
165  unsigned int numDOF_bcon() const { return (this->numDOF() - 1); }
166  unsigned int numDOFrphi_bcon() const { return (this->numDOFrphi() - 1); }
167  float chi2rphi_bcon() const { return chi2rphi_bcon_; }
168  float chi2_bcon() const { return chi2rphi_bcon_ + chi2rz_; }
169  float chi2dof_bcon() const { return (this->chi2_bcon()) / this->numDOF_bcon(); }
170 
171  //--- Get phi sector and eta region used by track finding code that this track is in.
172  unsigned int iPhiSec() const { return iPhiSec_; }
173  unsigned int iEtaReg() const { return iEtaReg_; }
174 
175  //--- Opto-link ID used to send this track from HT to Track Fitter
176  unsigned int optoLinkID() const { return optoLinkID_; }
177 
178  //--- Get whether the track has been rejected or accepted by the fit
179 
180  bool accepted() const { return accepted_; }
181 
182  // Digitize track and degrade helix parameter resolution according to effect of digitisation.
183  void digitizeTrack(const std::string& fitterName);
184 
185  // Access to detailed info about digitized track
186  const DigitalTrack* digitaltrack() const { return digitalTrack_.get(); }
187 
188  private:
189  //--- Configuration parameters
191 
192  //--- The 3D hough-transform track candidate which was fitted.
194 
195  //--- The stubs on the fitted track (can differ from those on HT track if fit kicked off stubs with bad residuals)
196  std::vector<const Stub*> stubs_;
197  unsigned int nLayers_;
198 
199  //--- Bit-encoded hit pattern (where layer number assigned by increasing distance from origin, according to layers track expected to cross).
200  unsigned int hitPattern_;
201 
202  //--- The fitted helix parameters and fit chi-squared.
203  float qOverPt_;
204  float d0_;
205  float phi0_;
206  float z0_;
207  float tanLambda_;
208  float chi2rphi_;
209  float chi2rz_;
210 
211  //--- Ditto with beam-spot constraint applied in case of 5-parameter fit, plus boolean to indicate
214  float d0_bcon_;
215  float phi0_bcon_;
217 
218  //--- The number of helix parameters being fitted (=5 if d0 is fitted or =4 if d0 is not fitted).
219  unsigned int nHelixParam_;
220 
221  //--- Phi sector and eta region used track finding code that this track was in.
222  unsigned int iPhiSec_;
223  unsigned int iEtaReg_;
224  //--- Opto-link ID from HT to Track Fitter.
225  unsigned int optoLinkID_;
226 
227  //--- Information about its association (if any) to a truth Tracking Particle.
228  const TP* matchedTP_;
229  std::vector<const Stub*> matchedStubs_;
230  unsigned int nMatchedLayers_;
231 
232  //--- Info specific to KF fitter.
233  unsigned int nSkippedLayers_;
234  unsigned int numUpdateCalls_;
235  //--- Info specific to LR fitter.
238  std::unordered_map<std::string, int> stateCalls_;
239 
240  std::shared_ptr<DigitalTrack> digitalTrack_; // Class used to digitize track if required.
241 
242  //--- Has the track fit declared this to be a valid track?
243  bool accepted_;
244  };
245 
246 } // namespace tmtt
247 
248 #endif
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
float charge_bcon() const
unsigned int numDOFrphi() const
double invPtToDphi() const
Definition: Settings.h:397
const std::vector< const Stub * > & stubs() const
unsigned int iPhiSec() const
float invPt_bcon() const
std::vector< const Stub * > stubs_
unsigned int hitPattern() const
unsigned int numDOF() const
unsigned int nSkippedLayers_
const DigitalTrack * digitaltrack() const
float chi2dof_bcon() const
void infoKF(unsigned int &nSkippedLayers, unsigned int &numUpdateCalls) const
double chosenRofZ() const
Definition: Settings.h:127
unsigned int optoLinkID() const
Definition: TP.h:23
unsigned int numLayers() const
std::shared_ptr< DigitalTrack > digitalTrack_
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int numKilledStubs() const
unsigned int numStubs() const
float phiAtChosenR(bool beamConstraint) const
float nHelixParam() const
unsigned int numDOFrphi_bcon() const
double chosenRofPhi() const
Definition: Settings.h:112
void setInfoKF(unsigned int nSkippedLayers, unsigned int numUpdateCalls)
unsigned int iEtaReg() const
KFTrackletTrack(const L1track3D *l1track3D, const std::vector< const Stub *> &stubs, unsigned int hitPattern, float qOverPt, float d0, float phi0, float z0, float tanLambda, float chi2rphi, float chi2rz, unsigned int nHelixParam, unsigned int iPhiSec, unsigned int iEtaReg, bool accepted=true, bool done_bcon=false, float qOverPt_bcon=0., float d0_bcon=0., float phi0_bcon=0., float chi2rphi_bcon=0.)
unsigned int nMatchedLayers_
const L1track3D * l1track3D_
float zAtChosenR() const
=== This is the base class for the linearised chi-squared track fit algorithms.
Definition: Array2D.h:16
const Settings * settings_
const L1track3D * l1track3D() const
unsigned int numStubs() const override
Definition: L1track3D.h:97
std::vector< const Stub * > matchedStubs_
unsigned int numDOFrz() const
std::unordered_map< std::string, int > stateCalls_
unsigned int numUpdateCalls_
void digitizeTrack(const std::string &fitterName)
unsigned int numDOF_bcon() const
float chi2rphi_bcon() const
float qOverPt_bcon() const
std::string lostMatchingState_