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