CMS 3D CMS Logo

MkBuilder.h
Go to the documentation of this file.
1 #ifndef RecoTracker_MkFitCore_interface_MkBuilder_h
2 #define RecoTracker_MkFitCore_interface_MkBuilder_h
3 
7 
8 #include <atomic>
9 #include <functional>
10 #include <map>
11 #include <vector>
12 
13 namespace mkfit {
14 
15  class CandCloner;
16  class LayerInfo;
17  class MkFinder;
18  class MkFitter;
19  class TrackerInfo;
20 
21  class Event;
22 
23  //==============================================================================
24  // MkJob
25  //==============================================================================
26 
27  class MkJob {
28  public:
30  // Config &config; // If we want to get rid of namespace / global config
33 
35 
36  int num_regions() const { return m_iter_config.m_n_regions; }
37  const auto regions_begin() const { return m_iter_config.m_region_order.begin(); }
38  const auto regions_end() const { return m_iter_config.m_region_order.end(); }
39 
40  const auto &steering_params(int i) { return m_iter_config.m_steering_params[i]; }
41 
42  const auto &params() const { return m_iter_config.m_params; }
43  const auto &params_bks() const { return m_iter_config.m_backward_params; }
44 
45  int max_max_cands() const { return std::max(params().maxCandsPerSeed, params_bks().maxCandsPerSeed); }
46 
47  const std::vector<bool> *get_mask_for_layer(int layer) {
49  }
50  };
51 
52  //==============================================================================
53  // MkBuilder
54  //==============================================================================
55 
56  class MkBuilder {
57  public:
58  using insert_seed_foo = void(const Track &, int, int);
60 
61  typedef std::vector<std::pair<int, int>> CandIdx_t;
62 
63  MkBuilder(bool silent = true) : m_silent(silent) {}
64  ~MkBuilder() = default;
65 
66  // --------
67 
68  static std::unique_ptr<MkBuilder> make_builder(bool silent = true);
69  static void populate();
70 
71  int total_cands() const;
72  std::pair<int, int> max_hits_layer(const EventOfHits &eoh) const;
73 
74  // --------
75 
76  void begin_event(MkJob *job, Event *ev, const char *build_type);
77  void end_event();
78  void release_memory();
79 
80  void import_seeds(const TrackVec &in_seeds, const bool seeds_sorted, std::function<insert_seed_foo> insert_seed);
81 
82  // filter for rearranging cands that will / will not do backward search.
83  int filter_comb_cands(std::function<filter_track_cand_foo> filter);
84 
86 
87  void select_best_comb_cands(bool clear_m_tracks = false, bool remove_missing_hits = false);
88  void export_best_comb_cands(TrackVec &out_vec, bool remove_missing_hits = false);
89  void export_tracks(TrackVec &out_vec);
90 
91  void compactifyHitStorageForBestCand(bool remove_seed_hits, int backward_fit_min_hits) {
92  m_event_of_comb_cands.compactifyHitStorageForBestCand(remove_seed_hits, backward_fit_min_hits);
93  }
94 
97 
98  // MIMI hack to export tracks for BH
99  const TrackVec &ref_tracks() const { return m_tracks; }
101 
102  // --------
103 
104  void find_tracks_load_seeds_BH(const TrackVec &in_seeds, const bool seeds_sorted); // for FindTracksBestHit
105  void find_tracks_load_seeds(const TrackVec &in_seeds, const bool seeds_sorted);
106 
107  int find_tracks_unroll_candidates(std::vector<std::pair<int, int>> &seed_cand_vec,
108  int start_seed,
109  int end_seed,
110  int layer,
111  int prev_layer,
112  bool pickup_only,
113  SteeringParams::IterationType_e iteration_dir);
114 
116  const LayerInfo &layer_info,
117  std::vector<std::vector<TrackCand>> &tmp_cands,
118  const std::vector<std::pair<int, int>> &seed_cand_idx,
119  const int region,
120  const int start_seed,
121  const int itrack,
122  const int end);
123 
124  void find_tracks_in_layers(CandCloner &cloner,
125  MkFinder *mkfndr,
126  SteeringParams::IterationType_e iteration_dir,
127  const int start_seed,
128  const int end_seed,
129  const int region);
130 
131  // --------
132 
133  void seed_post_cleaning(TrackVec &tv);
134 
138 
139  void backwardFitBH();
140  void fit_cands_BH(MkFinder *mkfndr, int start_cand, int end_cand, int region);
141 
142  void backwardFit();
143  void fit_cands(MkFinder *mkfndr, int start_cand, int end_cand, int region);
144 
145  private:
146  void fit_one_seed_set(TrackVec &simtracks, int itrack, int end, MkFitter *mkfttr, const bool is_brl[]);
147 
148  MkJob *m_job = nullptr;
149 
150  // MIMI -- Used by seed processing / validation.
151  Event *m_event = nullptr;
152 
153  // State for BestHit
155 
156  // State for Std / CloneEngine
158 
159  // Per-region seed information
160  std::vector<int> m_seedEtaSeparators;
161  std::vector<int> m_seedMinLastLayer;
162  std::vector<int> m_seedMaxLastLayer;
163 
165 
166  bool m_silent;
167  };
168 
169 } // end namespace mkfit
170 
171 #endif
const IterationConfig & m_iter_config
Definition: MkBuilder.h:31
void import_seeds(const TrackVec &in_seeds, const bool seeds_sorted, std::function< insert_seed_foo > insert_seed)
Definition: MkBuilder.cc:230
int find_tracks_unroll_candidates(std::vector< std::pair< int, int >> &seed_cand_vec, int start_seed, int end_seed, int layer, int prev_layer, bool pickup_only, SteeringParams::IterationType_e iteration_dir)
Definition: MkBuilder.cc:624
IterationParams m_params
static void populate()
Definition: MkBuilder.cc:170
std::pair< int, int > max_hits_layer(const EventOfHits &eoh) const
Definition: MkBuilder.cc:172
void export_tracks(TrackVec &out_vec)
Definition: MkBuilder.cc:386
IterationParams m_backward_params
void findTracksBestHit(SteeringParams::IterationType_e iteration_dir=SteeringParams::IT_FwdSearch)
Definition: MkBuilder.cc:463
~MkBuilder()=default
std::atomic< int > m_nan_n_silly_per_layer_count
Definition: MkBuilder.h:164
void find_min_max_hots_size()
Definition: MkBuilder.cc:343
const auto regions_begin() const
Definition: MkBuilder.h:37
int filter_comb_cands(std::function< filter_track_cand_foo > filter)
Definition: MkBuilder.cc:303
void compactifyHitStorageForBestCand(bool remove_seed_hits, int backward_fit_min_hits)
Definition: MkBuilder.h:91
void findTracksCloneEngine(SteeringParams::IterationType_e iteration_dir=SteeringParams::IT_FwdSearch)
Definition: MkBuilder.cc:926
void begin_event(MkJob *job, Event *ev, const char *build_type)
Definition: MkBuilder.cc:196
bool(const TrackCand &) filter_track_cand_foo
Definition: MkBuilder.h:59
const auto & params() const
Definition: MkBuilder.h:42
const EventOfHits & m_event_of_hits
Definition: MkBuilder.h:32
std::vector< int > m_region_order
void compactifyHitStorageForBestCand(bool remove_seed_hits, int backward_fit_min_hits)
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
constexpr std::array< uint8_t, layerIndexSize > layer
void backwardFitBH()
Definition: MkBuilder.cc:1158
void find_tracks_load_seeds_BH(const TrackVec &in_seeds, const bool seeds_sorted)
Definition: MkBuilder.cc:448
void findTracksStandard(SteeringParams::IterationType_e iteration_dir=SteeringParams::IT_FwdSearch)
Definition: MkBuilder.cc:747
void find_tracks_load_seeds(const TrackVec &in_seeds, const bool seeds_sorted)
Definition: MkBuilder.cc:612
void release_memory()
Definition: MkBuilder.cc:224
TrackVec m_tracks
Definition: MkBuilder.h:154
TrackVec & ref_tracks_nc()
Definition: MkBuilder.h:100
std::vector< int > m_seedEtaSeparators
Definition: MkBuilder.h:160
void seed_post_cleaning(TrackVec &tv)
Definition: MkBuilder.cc:397
Event * m_event
Definition: MkBuilder.h:151
void select_best_comb_cands(bool clear_m_tracks=false, bool remove_missing_hits=false)
Definition: MkBuilder.cc:365
int total_cands() const
Definition: MkBuilder.cc:185
const TrackVec & ref_tracks() const
Definition: MkBuilder.h:99
const auto & steering_params(int i)
Definition: MkBuilder.h:40
const TrackerInfo & m_trk_info
Definition: MkBuilder.h:29
const IterationMaskIfcBase * m_iter_mask_ifc
Definition: MkBuilder.h:34
std::vector< Track > TrackVec
EventOfCombCandidates m_event_of_comb_cands
Definition: MkBuilder.h:157
void find_tracks_handle_missed_layers(MkFinder *mkfndr, const LayerInfo &layer_info, std::vector< std::vector< TrackCand >> &tmp_cands, const std::vector< std::pair< int, int >> &seed_cand_idx, const int region, const int start_seed, const int itrack, const int end)
Definition: MkBuilder.cc:689
void beginBkwSearch()
Definition: MkBuilder.h:95
std::vector< int > m_seedMaxLastLayer
Definition: MkBuilder.h:162
void export_best_comb_cands(TrackVec &out_vec, bool remove_missing_hits=false)
Definition: MkBuilder.cc:371
void(const Track &, int, int) insert_seed_foo
Definition: MkBuilder.h:58
static std::unique_ptr< MkBuilder > make_builder(bool silent=true)
Definition: MkBuilder.cc:168
MkBuilder(bool silent=true)
Definition: MkBuilder.h:63
const auto regions_end() const
Definition: MkBuilder.h:38
void fit_cands(MkFinder *mkfndr, int start_cand, int end_cand, int region)
Definition: MkBuilder.cc:1313
const std::vector< bool > * get_mask_for_layer(int layer)
Definition: MkBuilder.h:47
const auto & params_bks() const
Definition: MkBuilder.h:43
void endBkwSearch()
Definition: MkBuilder.h:96
int max_max_cands() const
Definition: MkBuilder.h:45
std::vector< int > m_seedMinLastLayer
Definition: MkBuilder.h:161
void fit_one_seed_set(TrackVec &simtracks, int itrack, int end, MkFitter *mkfttr, const bool is_brl[])
std::vector< SteeringParams > m_steering_params
virtual const std::vector< bool > * get_mask_for_layer(int layer) const
int num_regions() const
Definition: MkBuilder.h:36
std::vector< std::pair< int, int > > CandIdx_t
Definition: MkBuilder.h:61
void fit_cands_BH(MkFinder *mkfndr, int start_cand, int end_cand, int region)
Definition: MkBuilder.cc:1177
void find_tracks_in_layers(CandCloner &cloner, MkFinder *mkfndr, SteeringParams::IterationType_e iteration_dir, const int start_seed, const int end_seed, const int region)
Definition: MkBuilder.cc:961