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