CMS 3D CMS Logo

runFunctions.cc
Go to the documentation of this file.
4 
5 #include "oneapi/tbb/parallel_for.h"
6 
7 #include <memory>
8 
9 namespace mkfit {
10 
11  //==============================================================================
12  // run_OneIteration
13  //
14  // One-stop function for running track building from CMSSW.
15  //==============================================================================
16 
19  const std::vector<const std::vector<bool> *> &m_mask_vector;
20 
21  IterationMaskIfcCmssw(const TrackerInfo &ti, const std::vector<const std::vector<bool> *> &maskvec)
22  : m_trk_info(ti), m_mask_vector(maskvec) {}
23 
24  const std::vector<bool> *get_mask_for_layer(int layer) const override {
25  return m_trk_info.layer(layer).is_pixel() ? m_mask_vector[0] : m_mask_vector[1];
26  }
27  };
28 
29  void run_OneIteration(const TrackerInfo &trackerInfo,
30  const IterationConfig &itconf,
31  const EventOfHits &eoh,
32  const std::vector<const std::vector<bool> *> &hit_masks,
33  MkBuilder &builder,
34  TrackVec &seeds,
35  TrackVec &out_tracks,
36  bool do_seed_clean,
37  bool do_backward_fit,
38  bool do_remove_duplicates) {
39  IterationMaskIfcCmssw it_mask_ifc(trackerInfo, hit_masks);
40 
41  MkJob job({trackerInfo, itconf, eoh, eoh.refBeamSpot(), &it_mask_ifc});
42 
43  builder.begin_event(&job, nullptr, __func__);
44 
45  // Seed cleaning not done on all iterations.
46  do_seed_clean = do_seed_clean && itconf.m_seed_cleaner;
47 
48  if (do_seed_clean)
49  itconf.m_seed_cleaner(seeds, itconf, eoh.refBeamSpot());
50 
51  // Check nans in seeds -- this should not be needed when Slava fixes
52  // the track parameter coordinate transformation.
53  builder.seed_post_cleaning(seeds);
54 
55  if (itconf.m_requires_seed_hit_sorting) {
56  for (auto &s : seeds)
57  s.sortHitsByLayer(); // sort seed hits for the matched hits (I hope it works here)
58  }
59 
60  builder.find_tracks_load_seeds(seeds, do_seed_clean);
61 
62  builder.findTracksCloneEngine();
63 
64  // Pre backward-fit filtering.
65  filter_candidates_func pre_filter;
66  if (do_backward_fit && itconf.m_pre_bkfit_filter)
67  pre_filter = [&](const TrackCand &tc, const MkJob &jb) -> bool {
68  return itconf.m_pre_bkfit_filter(tc, jb) && StdSeq::qfilter_nan_n_silly<TrackCand>(tc, jb);
69  };
70  else if (itconf.m_pre_bkfit_filter)
71  pre_filter = itconf.m_pre_bkfit_filter;
72  else if (do_backward_fit)
73  pre_filter = StdSeq::qfilter_nan_n_silly<TrackCand>;
74  // pre_filter can be null if we are not doing backward fit as nan_n_silly will be run below.
75  if (pre_filter)
76  builder.filter_comb_cands(pre_filter, true);
77 
78  job.switch_to_backward();
79 
80  if (do_backward_fit) {
81  if (itconf.m_backward_search) {
83  }
84 
85  builder.backwardFit();
86 
87  if (itconf.m_backward_search) {
88  builder.beginBkwSearch();
90  }
91  }
92 
93  // Post backward-fit filtering.
94  filter_candidates_func post_filter;
95  if (do_backward_fit && itconf.m_post_bkfit_filter)
96  post_filter = [&](const TrackCand &tc, const MkJob &jb) -> bool {
97  return itconf.m_post_bkfit_filter(tc, jb) && StdSeq::qfilter_nan_n_silly<TrackCand>(tc, jb);
98  };
99  else
100  post_filter = StdSeq::qfilter_nan_n_silly<TrackCand>;
101  // post_filter is always at least doing nan_n_silly filter.
102  builder.filter_comb_cands(post_filter, true);
103 
104  if (do_backward_fit && itconf.m_backward_search)
105  builder.endBkwSearch();
106 
107  builder.export_best_comb_cands(out_tracks, true);
108 
109  if (do_remove_duplicates && itconf.m_duplicate_cleaner) {
110  itconf.m_duplicate_cleaner(out_tracks, itconf);
111  }
112 
113  builder.end_event();
114  builder.release_memory();
115  }
116 
117 } // end namespace mkfit
const BeamSpot & refBeamSpot() const
void compactifyHitStorageForBestCand(bool remove_seed_hits, int backward_fit_min_hits)
Definition: MkBuilder.h:62
void findTracksCloneEngine(SteeringParams::IterationType_e iteration_dir=SteeringParams::IT_FwdSearch)
Definition: MkBuilder.cc:932
void begin_event(MkJob *job, Event *ev, const char *build_type)
Definition: MkBuilder.cc:194
bool is_pixel() const
Definition: TrackerInfo.h:77
clean_seeds_func m_seed_cleaner
void run_OneIteration(const TrackerInfo &trackerInfo, const IterationConfig &itconf, const EventOfHits &eoh, const std::vector< const std::vector< bool > *> &hit_masks, MkBuilder &builder, TrackVec &seeds, TrackVec &out_tracks, bool do_seed_clean, bool do_backward_fit, bool do_remove_duplicates)
Definition: runFunctions.cc:29
std::function< filter_candidates_cf > filter_candidates_func
Definition: FunctionTypes.h:28
void find_tracks_load_seeds(const TrackVec &in_seeds, const bool seeds_sorted)
Definition: MkBuilder.cc:609
void release_memory()
Definition: MkBuilder.cc:222
void seed_post_cleaning(TrackVec &tv)
Definition: MkBuilder.cc:407
int filter_comb_cands(filter_candidates_func filter, bool attempt_all_cands)
Definition: MkBuilder.cc:301
const LayerInfo & layer(int l) const
Definition: TrackerInfo.h:202
filter_candidates_func m_post_bkfit_filter
const std::vector< bool > * get_mask_for_layer(int layer) const override
Definition: runFunctions.cc:24
std::vector< Track > TrackVec
const std::vector< const std::vector< bool > * > & m_mask_vector
Definition: runFunctions.cc:19
clean_duplicates_func m_duplicate_cleaner
void beginBkwSearch()
Definition: MkBuilder.h:66
void export_best_comb_cands(TrackVec &out_vec, bool remove_missing_hits=false)
Definition: MkBuilder.cc:384
void endBkwSearch()
Definition: MkBuilder.h:67
const TrackerInfo & m_trk_info
Definition: runFunctions.cc:18
IterationMaskIfcCmssw(const TrackerInfo &ti, const std::vector< const std::vector< bool > *> &maskvec)
Definition: runFunctions.cc:21
filter_candidates_func m_pre_bkfit_filter