CMS 3D CMS Logo

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