CMS 3D CMS Logo

MkFinder.h
Go to the documentation of this file.
1 #ifndef RecoTracker_MkFitCore_src_MkFinder_h
2 #define RecoTracker_MkFitCore_src_MkFinder_h
3 
4 #include "MkBase.h"
7 
10 
11 // Define to get printouts about track and hit chi2.
12 // See also MkBuilder::backwardFit().
13 
14 //#define DEBUG_BACKWARD_FIT_BH
15 //#define DEBUG_BACKWARD_FIT
16 
17 namespace mkfit {
18 
19  class CandCloner;
20  class CombCandidate;
21  class LayerOfHits;
22  class FindingFoos;
23  class IterationParams;
24  class IterationLayerConfig;
25  class SteeringParams;
26 
27 #if defined(DUMPHITWINDOW) or defined(DEBUG_BACKWARD_FIT)
28  class Event;
29 #endif
30 
31  class MkFinder : public MkBase {
32  friend class MkBuilder;
33 
34  public:
35  static constexpr int MPlexHitIdxMax = 16;
36 
39 
40  //----------------------------------------------------------------------------
41 
42  MkFinder() {}
43 
44  void setup(const PropagationConfig &pc,
45  const IterationParams &ip,
46  const IterationLayerConfig &ilc,
47  const std::vector<bool> *ihm);
48  void setup_bkfit(const PropagationConfig &pc);
49  void release();
50 
51  //----------------------------------------------------------------------------
52 
53  void inputTracksAndHitIdx(const std::vector<Track> &tracks, int beg, int end, bool inputProp);
54 
55  void inputTracksAndHitIdx(const std::vector<Track> &tracks,
56  const std::vector<int> &idxs,
57  int beg,
58  int end,
59  bool inputProp,
60  int mp_offset);
61 
62  void inputTracksAndHitIdx(const std::vector<CombCandidate> &tracks,
63  const std::vector<std::pair<int, int>> &idxs,
64  int beg,
65  int end,
66  bool inputProp);
67 
68  void inputTracksAndHitIdx(const std::vector<CombCandidate> &tracks,
69  const std::vector<std::pair<int, IdxChi2List>> &idxs,
70  int beg,
71  int end,
72  bool inputProp);
73 
74  void outputTracksAndHitIdx(std::vector<Track> &tracks, int beg, int end, bool outputProp) const;
75 
77  std::vector<Track> &tracks, const std::vector<int> &idxs, int beg, int end, bool outputProp) const;
78 
79  void outputTrackAndHitIdx(Track &track, int itrack, bool outputProp) const {
80  const int iO = outputProp ? iP : iC;
81  copy_out(track, itrack, iO);
82  }
83 
85  std::vector<Track> &tracks, const std::vector<int> &idxs, int beg, int end, bool outputProp) const {
86  const int iO = outputProp ? iP : iC;
87  for (int i = beg, imp = 0; i < end; ++i, ++imp) {
88  if (!m_Stopped[imp])
89  copy_out(tracks[idxs[i]], imp, iO);
90  }
91  }
92 
93  HitOnTrack bestHitLastHoT(int itrack) const { return m_HoTArrs[itrack][m_NHits(itrack, 0, 0) - 1]; }
94 
95  //----------------------------------------------------------------------------
96 
98  const float invpt, const float theta, float &min_dq, float &max_dq, float &min_dphi, float &max_dphi);
99 
100  float getHitSelDynamicChi2Cut(const int itrk, const int ipar);
101 
102  void selectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc);
103 
104  void addBestHit(const LayerOfHits &layer_of_hits, const int N_proc, const FindingFoos &fnd_foos);
105 
106  //----------------------------------------------------------------------------
107 
108  void findCandidates(const LayerOfHits &layer_of_hits,
109  std::vector<std::vector<TrackCand>> &tmp_candidates,
110  const int offset,
111  const int N_proc,
112  const FindingFoos &fnd_foos);
113 
114  //----------------------------------------------------------------------------
115 
116  void findCandidatesCloneEngine(const LayerOfHits &layer_of_hits,
117  CandCloner &cloner,
118  const int offset,
119  const int N_proc,
120  const FindingFoos &fnd_foos);
121 
122  void updateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc, const FindingFoos &fnd_foos);
123 
124  void copyOutParErr(std::vector<CombCandidate> &seed_cand_vec, int N_proc, bool outputProp) const;
125 
126  //----------------------------------------------------------------------------
127  // Backward fit
128 
129  void bkFitInputTracks(TrackVec &cands, int beg, int end);
130  void bkFitOutputTracks(TrackVec &cands, int beg, int end, bool outputProp);
131 
132  void bkFitInputTracks(EventOfCombCandidates &eocss, int beg, int end);
133  void bkFitOutputTracks(EventOfCombCandidates &eocss, int beg, int end, bool outputProp);
134 
135  void bkFitFitTracksBH(const EventOfHits &eventofhits,
136  const SteeringParams &st_par,
137  const int N_proc,
138  bool chiDebug = false);
139 
140  void bkFitFitTracks(const EventOfHits &eventofhits,
141  const SteeringParams &st_par,
142  const int N_proc,
143  bool chiDebug = false);
144 
145  void bkFitPropTracksToPCA(const int N_proc);
146 
147  //----------------------------------------------------------------------------
148 
149  private:
150  void copy_in(const Track &trk, const int mslot, const int tslot) {
151  m_Err[tslot].copyIn(mslot, trk.errors().Array());
152  m_Par[tslot].copyIn(mslot, trk.parameters().Array());
153 
154  m_Chg(mslot, 0, 0) = trk.charge();
155  m_Chi2(mslot, 0, 0) = trk.chi2();
156  m_Label(mslot, 0, 0) = trk.label();
157 
158  m_NHits(mslot, 0, 0) = trk.nTotalHits();
159  m_NFoundHits(mslot, 0, 0) = trk.nFoundHits();
160 
161  m_NInsideMinusOneHits(mslot, 0, 0) = trk.nInsideMinusOneHits();
162  m_NTailMinusOneHits(mslot, 0, 0) = trk.nTailMinusOneHits();
163 
164  std::copy(trk.beginHitsOnTrack(), trk.endHitsOnTrack(), m_HoTArrs[mslot]);
165  }
166 
167  void copy_out(Track &trk, const int mslot, const int tslot) const {
168  m_Err[tslot].copyOut(mslot, trk.errors_nc().Array());
169  m_Par[tslot].copyOut(mslot, trk.parameters_nc().Array());
170 
171  trk.setCharge(m_Chg(mslot, 0, 0));
172  trk.setChi2(m_Chi2(mslot, 0, 0));
173  trk.setLabel(m_Label(mslot, 0, 0));
174 
175  trk.resizeHits(m_NHits(mslot, 0, 0), m_NFoundHits(mslot, 0, 0));
176  std::copy(m_HoTArrs[mslot], &m_HoTArrs[mslot][m_NHits(mslot, 0, 0)], trk.beginHitsOnTrack_nc());
177  }
178 
179  void copy_in(const TrackCand &trk, const int mslot, const int tslot) {
180  m_Err[tslot].copyIn(mslot, trk.errors().Array());
181  m_Par[tslot].copyIn(mslot, trk.parameters().Array());
182 
183  m_Chg(mslot, 0, 0) = trk.charge();
184  m_Chi2(mslot, 0, 0) = trk.chi2();
185  m_Label(mslot, 0, 0) = trk.label();
186 
187  m_LastHitCcIndex(mslot, 0, 0) = trk.lastCcIndex();
188  m_NFoundHits(mslot, 0, 0) = trk.nFoundHits();
189  m_NMissingHits(mslot, 0, 0) = trk.nMissingHits();
190  m_NOverlapHits(mslot, 0, 0) = trk.nOverlapHits();
191 
192  m_NInsideMinusOneHits(mslot, 0, 0) = trk.nInsideMinusOneHits();
193  m_NTailMinusOneHits(mslot, 0, 0) = trk.nTailMinusOneHits();
194 
195  m_LastHoT[mslot] = trk.getLastHitOnTrack();
196  m_CombCand[mslot] = trk.combCandidate();
197  m_TrkStatus[mslot] = trk.getStatus();
198  }
199 
200  void copy_out(TrackCand &trk, const int mslot, const int tslot) const {
201  m_Err[tslot].copyOut(mslot, trk.errors_nc().Array());
202  m_Par[tslot].copyOut(mslot, trk.parameters_nc().Array());
203 
204  trk.setCharge(m_Chg(mslot, 0, 0));
205  trk.setChi2(m_Chi2(mslot, 0, 0));
206  trk.setLabel(m_Label(mslot, 0, 0));
207 
208  trk.setLastCcIndex(m_LastHitCcIndex(mslot, 0, 0));
209  trk.setNFoundHits(m_NFoundHits(mslot, 0, 0));
210  trk.setNMissingHits(m_NMissingHits(mslot, 0, 0));
211  trk.setNOverlapHits(m_NOverlapHits(mslot, 0, 0));
212 
214  trk.setNTailMinusOneHits(m_NTailMinusOneHits(mslot, 0, 0));
215 
216  trk.setCombCandidate(m_CombCand[mslot]);
217  trk.setStatus(m_TrkStatus[mslot]);
218  }
219 
220  void add_hit(const int mslot, int index, int layer) {
221  // Only used by BestHit.
222  // m_NInsideMinusOneHits and m_NTailMinusOneHits are maintained here but are
223  // not used and are not copied out (as Track does not have these members).
224 
225  int &n_tot_hits = m_NHits(mslot, 0, 0);
226  int &n_fnd_hits = m_NFoundHits(mslot, 0, 0);
227 
228  if (n_tot_hits < Config::nMaxTrkHits) {
229  m_HoTArrs[mslot][n_tot_hits++] = {index, layer};
230  if (index >= 0) {
231  ++n_fnd_hits;
232  m_NInsideMinusOneHits(mslot, 0, 0) += m_NTailMinusOneHits(mslot, 0, 0);
233  m_NTailMinusOneHits(mslot, 0, 0) = 0;
234  } else if (index == -1) {
235  ++m_NTailMinusOneHits(mslot, 0, 0);
236  }
237  } else {
238  // printf("WARNING MkFinder::add_hit hit-on-track limit reached for label=%d\n", label_);
239 
240  const int LH = Config::nMaxTrkHits - 1;
241 
242  if (index >= 0) {
243  if (m_HoTArrs[mslot][LH].index < 0)
244  ++n_fnd_hits;
245  m_HoTArrs[mslot][LH] = {index, layer};
246  } else if (index == -2) {
247  if (m_HoTArrs[mslot][LH].index >= 0)
248  --n_fnd_hits;
249  m_HoTArrs[mslot][LH] = {index, layer};
250  }
251  }
252  }
253 
254  int num_all_minus_one_hits(const int mslot) const {
255  return m_NInsideMinusOneHits(mslot, 0, 0) + m_NTailMinusOneHits(mslot, 0, 0);
256  }
257 
258  int num_inside_minus_one_hits(const int mslot) const { return m_NInsideMinusOneHits(mslot, 0, 0); }
259 
260  //----------------------------------------------------------------------------
261 
263  MPlexQI m_Label; // seed index in global seed vector (for MC truth match)
264 
267 
269 
270 #if defined(DUMPHITWINDOW) or defined(DEBUG_BACKWARD_FIT)
271  MPlexQI m_SeedAlgo; // seed algorithm
272  MPlexQI m_SeedLabel; // seed label
273  Event *m_event;
274 #endif
275 
276  MPlexQI m_SeedIdx; // seed index in local thread (for bookkeeping at thread level)
277  MPlexQI m_CandIdx; // candidate index for the given seed (for bookkeeping of clone engine)
278 
279  MPlexQI m_Stopped; // Flag for BestHit that a track has been stopped (and copied out already)
280 
281  // Additions / substitutions for TrackCand copy_in/out()
282  // One could really access the original TrackCand for all of those, especially the ones that
283  // are STD only. This then requires access back to that TrackCand memory.
284  // So maybe one should just have flags for CopyIn methods (or several versions). Yay, etc.
285  MPlexQI m_NMissingHits; // sub: m_NHits, sort of, STD only
286  MPlexQI m_NOverlapHits; // add: num of overlaps registered in HitOnTrack, STD only
287  MPlexQI m_NInsideMinusOneHits; // sub: before we copied all hit idcs and had a loop counting them only
288  MPlexQI m_NTailMinusOneHits; // sub: before we copied all hit idcs and had a loop counting them only
289  MPlexQI m_LastHitCcIndex; // add: index of last hit in m_CombCand hit tree, STD only
290  TrackBase::Status m_TrkStatus[NN]; // STD only, status bits
293  // const TrackCand *m_TrkCand[NN]; // hmmh, could get all data through this guy ... but scattered
294  // storing it in now for bkfit debug printouts
296 
297  // Hit indices into LayerOfHits to explore.
298  WSR_Result m_XWsrResult[NN]; // Could also merge it with m_XHitSize. Or use smaller arrays.
301 
302  // Hit errors / parameters for hit matching, update.
305 
306  // An idea: Do propagation to hit in FindTracksXYZZ functions.
307  // Have some state / functions here that make this short to write.
308  // This would simplify KalmanUtils (remove the propagate functions).
309  // Track errors / parameters propagated to current hit.
310  // MPlexLS candErrAtCurrHit;
311  // MPlexLV candParAtCurrHit;
312 
316  const std::vector<bool> *m_iteration_hit_mask = nullptr;
317 
318  // Backward fit
319  int m_CurHit[NN];
321  int m_CurNode[NN];
323  };
324 
325 } // end namespace mkfit
326 #endif
int nInsideMinusOneHits() const
const HitOnTrack * endHitsOnTrack() const
Definition: Track.h:500
MPlexQI m_Chg
Definition: MkBase.h:96
int nOverlapHits() const
static constexpr int iC
Definition: MkBase.h:16
void copy_in(const Track &trk, const int mslot, const int tslot)
Definition: MkFinder.h:150
static constexpr int MPlexHitIdxMax
Definition: MkFinder.h:35
void setLabel(int lbl)
Definition: Track.h:191
const SVector6 & parameters() const
Definition: Track.h:144
HitOnTrack getLastHitOnTrack() const
int charge() const
Definition: Track.h:183
MPlexQI m_NFoundHits
Definition: MkFinder.h:266
const IterationLayerConfig * m_iteration_layer_config
Definition: MkFinder.h:315
void setNOverlapHits(int n)
const HitOnTrack * m_HoTArr[NN]
Definition: MkFinder.h:320
int nMissingHits() const
static constexpr int iP
Definition: MkBase.h:17
void copy_out(Track &trk, const int mslot, const int tslot) const
Definition: MkFinder.h:167
void copyIn(idx_t n, const T *arr)
Definition: Matriplex.h:70
void outputTracksAndHitIdx(std::vector< Track > &tracks, int beg, int end, bool outputProp) const
Definition: MkFinder.cc:140
HitOnTrack m_HoTArrs[NN][Config::nMaxTrkHits]
Definition: MkFinder.h:268
void inputTracksAndHitIdx(const std::vector< Track > &tracks, int beg, int end, bool inputProp)
Definition: MkFinder.cc:59
void bkFitInputTracks(TrackVec &cands, int beg, int end)
Definition: MkFinder.cc:1340
int nTailMinusOneHits() const
void setChi2(float chi2)
Definition: Track.h:189
float chi2() const
Definition: Track.h:184
void setLastCcIndex(int i)
MPlexLV m_Par[2]
Definition: MkBase.h:95
MPlexQI m_NMissingHits
Definition: MkFinder.h:285
void setNInsideMinusOneHits(int n)
void selectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc)
Definition: MkFinder.cc:228
int label() const
Definition: Track.h:186
void setNFoundHits(int n)
void bkFitPropTracksToPCA(const int N_proc)
Definition: MkFinder.cc:1749
SMatrixSym66 & errors_nc()
Definition: Track.h:152
void release()
Definition: MkFinder.cc:48
void add_hit(const int mslot, int index, int layer)
Definition: MkFinder.h:220
void resizeHits(int nHits, int nFoundHits)
Definition: Track.h:432
const SMatrixSym66 & errors() const
Definition: Track.h:145
void setNTailMinusOneHits(int n)
void copy_out(TrackCand &trk, const int mslot, const int tslot) const
Definition: MkFinder.h:200
int nInsideMinusOneHits() const
Definition: Track.h:522
const IterationParams * m_iteration_params
Definition: MkFinder.h:314
constexpr std::array< uint8_t, layerIndexSize > layer
MPlexLS m_Err[2]
Definition: MkBase.h:94
void findCandidates(const LayerOfHits &layer_of_hits, std::vector< std::vector< TrackCand >> &tmp_candidates, const int offset, const int N_proc, const FindingFoos &fnd_foos)
Definition: MkFinder.cc:865
int nFoundHits() const
Definition: Track.h:516
void setNMissingHits(int n)
const PropagationConfig * m_prop_config
Definition: MkFinder.h:313
void setup_bkfit(const PropagationConfig &pc)
Definition: MkFinder.cc:46
void setStatus(Status s)
Definition: Track.h:252
int num_all_minus_one_hits(const int mslot) const
Definition: MkFinder.h:254
void outputNonStoppedTracksAndHitIdx(std::vector< Track > &tracks, const std::vector< int > &idxs, int beg, int end, bool outputProp) const
Definition: MkFinder.h:84
constexpr Matriplex::idx_t NN
Definition: Matrix.h:43
TrackBase::Status m_TrkStatus[NN]
Definition: MkFinder.h:290
LH
angular window limits for traco
CombCandidate * combCandidate() const
MPlexQI m_XHitSize
Definition: MkFinder.h:299
MPlexHV m_msPar
Definition: MkFinder.h:304
MPlexQI m_NTailMinusOneHits
Definition: MkFinder.h:288
void copyOut(idx_t n, T *arr) const
Definition: MatriplexSym.h:195
int m_CurNode[NN]
Definition: MkFinder.h:321
void setup(const PropagationConfig &pc, const IterationParams &ip, const IterationLayerConfig &ilc, const std::vector< bool > *ihm)
Definition: MkFinder.cc:36
MPlexQI m_NHits
Definition: MkFinder.h:265
int lastCcIndex() const
MPlexHS m_msErr
Definition: MkFinder.h:303
void updateWithLastHit(const LayerOfHits &layer_of_hits, int N_proc, const FindingFoos &fnd_foos)
Definition: MkFinder.cc:1291
TrackCand * m_TrkCand[NN]
Definition: MkFinder.h:295
MPlexQI m_LastHitCcIndex
Definition: MkFinder.h:289
std::vector< Track > TrackVec
CombCandidate * m_CombCand[NN]
Definition: MkFinder.h:292
HitOnTrack * beginHitsOnTrack_nc()
Definition: Track.h:502
auto const & tracks
cannot be loose
void bkFitFitTracks(const EventOfHits &eventofhits, const SteeringParams &st_par, const int N_proc, bool chiDebug=false)
Definition: MkFinder.cc:1582
int m_CurHit[NN]
Definition: MkFinder.h:319
Status getStatus() const
Definition: Track.h:251
void setCombCandidate(CombCandidate *cc)
HitOnTrack m_LastHoT[NN]
Definition: MkFinder.h:291
MPlexQI m_NOverlapHits
Definition: MkFinder.h:286
int nTotalHits() const
Definition: Track.h:517
MPlexHitIdx m_XHitArr
Definition: MkFinder.h:300
MPlexQF m_Chi2
Definition: MkFinder.h:262
void bkFitOutputTracks(TrackVec &cands, int beg, int end, bool outputProp)
Definition: MkFinder.cc:1397
void bkFitFitTracksBH(const EventOfHits &eventofhits, const SteeringParams &st_par, const int N_proc, bool chiDebug=false)
Definition: MkFinder.cc:1445
void copyIn(idx_t n, const T *arr)
Definition: MatriplexSym.h:87
const HitOnTrack * beginHitsOnTrack() const
Definition: Track.h:499
MPlexQI m_CandIdx
Definition: MkFinder.h:277
MPlexQI m_SeedIdx
Definition: MkFinder.h:276
void copyOutParErr(std::vector< CombCandidate > &seed_cand_vec, int N_proc, bool outputProp) const
Definition: MkFinder.cc:1319
int num_inside_minus_one_hits(const int mslot) const
Definition: MkFinder.h:258
void findCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandCloner &cloner, const int offset, const int N_proc, const FindingFoos &fnd_foos)
Definition: MkFinder.cc:1103
void copyOut(idx_t n, T *arr) const
Definition: Matriplex.h:180
void copy_in(const TrackCand &trk, const int mslot, const int tslot)
Definition: MkFinder.h:179
MPlexQI m_NInsideMinusOneHits
Definition: MkFinder.h:287
HitOnTrack bestHitLastHoT(int itrack) const
Definition: MkFinder.h:93
const std::vector< bool > * m_iteration_hit_mask
Definition: MkFinder.h:316
void setCharge(int chg)
Definition: Track.h:188
float getHitSelDynamicChi2Cut(const int itrk, const int ipar)
Definition: MkFinder.cc:205
const HoTNode * m_HoTNodeArr[NN]
Definition: MkFinder.h:322
int nFoundHits() const
WSR_Result m_XWsrResult[NN]
Definition: MkFinder.h:298
void getHitSelDynamicWindows(const float invpt, const float theta, float &min_dq, float &max_dq, float &min_dphi, float &max_dphi)
Definition: MkFinder.cc:168
Geom::Theta< T > theta() const
MPlexQI m_Stopped
Definition: MkFinder.h:279
SVector6 & parameters_nc()
Definition: Track.h:151
constexpr int nMaxTrkHits
Definition: Config.h:77
int nTailMinusOneHits() const
Definition: Track.h:534
MPlexQI m_Label
Definition: MkFinder.h:263
void outputTrackAndHitIdx(Track &track, int itrack, bool outputProp) const
Definition: MkFinder.h:79
void addBestHit(const LayerOfHits &layer_of_hits, const int N_proc, const FindingFoos &fnd_foos)
Definition: MkFinder.cc:657