CMS 3D CMS Logo

SteeringParams.h
Go to the documentation of this file.
1 #ifndef RecoTracker_MkFitCore_interface_SteeringParams_h
2 #define RecoTracker_MkFitCore_interface_SteeringParams_h
3 
5 
6 #include <vector>
7 #include <stdexcept>
8 
9 namespace mkfit {
10 
11  //==============================================================================
12  // LayerControl
13  //==============================================================================
14 
15  struct LayerControl {
16  int m_layer;
17 
18  // Idea only ... need some parallel structure for candidates to make sense (where i can store it).
19  // Or have per layer containers where I place track indices to enable. Or something. Sigh.
20  // int m_on_miss_jump_to = -999;
21  // int m_on_hit_jump_to = -999;
22 
23  // Used to have pickup-only / bk-fit only bools etc.
24  // Moved to SteeringParams as layer indices where pickup/bkfit/bksrch start/end/start.
25 
26  //----------------------------------------------------------------------------
27 
28  LayerControl() : m_layer(-1) {}
29  LayerControl(int lay) : m_layer(lay) {}
30  };
31 
32  //==============================================================================
33  // SteeringParams
34  //==============================================================================
35 
37  public:
39 
40  class iterator {
41  friend class SteeringParams;
42 
45  int m_cur_index = -1;
46  int m_end_index = -1;
47 
49 
50  public:
52  int layer() const { return layer_control().m_layer; }
53  int index() const { return m_cur_index; }
54  int region() const { return m_steering_params.m_region; }
55 
56  bool is_valid() const { return m_cur_index != -1; }
57 
58  const LayerControl& operator->() const { return layer_control(); }
59 
60  bool is_pickup_only() const {
61  if (m_type == IT_FwdSearch)
63  else if (m_type == IT_BkwSearch)
65  else
66  throw std::runtime_error("invalid iteration type");
67  }
68 
69  bool operator++() {
70  if (!is_valid())
71  return false;
72  if (m_type == IT_FwdSearch) {
73  if (++m_cur_index == m_end_index)
74  m_cur_index = -1;
75  } else {
76  if (--m_cur_index == m_end_index)
77  m_cur_index = -1;
78  }
79  return is_valid();
80  }
81 
82  // Functions for debug printouts
83  int end_index() const { return m_end_index; }
84  int next_layer() const {
85  if (m_type == IT_FwdSearch)
86  return m_steering_params.m_layer_plan[m_cur_index + 1].m_layer;
87  else
88  return m_steering_params.m_layer_plan[m_cur_index - 1].m_layer;
89  }
90  int last_layer() const {
91  if (m_type == IT_FwdSearch)
92  return m_steering_params.m_layer_plan[m_end_index - 1].m_layer;
93  else
94  return m_steering_params.m_layer_plan[m_end_index + 1].m_layer;
95  }
96  }; // class iterator
97 
98  std::vector<LayerControl> m_layer_plan;
101 
102  int m_region;
103 
105  int m_bkw_fit_last = 0;
107 
108  //----------------------------------------------------------------------------
109 
111 
112  void reserve_plan(int n) { m_layer_plan.reserve(n); }
113 
114  void append_plan(int layer) { m_layer_plan.emplace_back(LayerControl(layer)); }
115 
116  void fill_plan(int first, int last) {
117  for (int i = first; i <= last; ++i)
118  append_plan(i);
119  }
120 
121  void set_iterator_limits(int fwd_search_pu, int bkw_fit_last, int bkw_search_pu = -1) {
122  m_fwd_search_pickup = fwd_search_pu;
123  m_bkw_fit_last = bkw_fit_last;
124  m_bkw_search_pickup = bkw_search_pu;
125  }
126 
127  bool has_bksearch_plan() const { return m_bkw_search_pickup != -1; }
128 
130  iterator it(*this, type);
131 
132  if (type == IT_FwdSearch) {
133  it.m_cur_index = m_fwd_search_pickup;
134  it.m_end_index = m_layer_plan.size();
135  } else if (type == IT_BkwFit) {
136  it.m_cur_index = m_layer_plan.size() - 1;
137  it.m_end_index = m_bkw_fit_last - 1;
138  } else if (type == IT_BkwSearch) {
139  it.m_cur_index = m_bkw_search_pickup;
140  it.m_end_index = -1;
141  } else
142  throw std::invalid_argument("unknown iteration type");
143 
144  if (!it.is_valid())
145  throw std::runtime_error("invalid iterator constructed");
146 
147  return it;
148  }
149  };
150 
151 } // end namespace mkfit
152 
153 #endif
void append_plan(int layer)
const SteeringParams & m_steering_params
const LayerControl & layer_control() const
void set_iterator_limits(int fwd_search_pu, int bkw_fit_last, int bkw_search_pu=-1)
std::function< track_score_cf > track_score_func
Definition: FunctionTypes.h:40
bool has_bksearch_plan() const
void fill_plan(int first, int last)
track_score_func m_track_scorer
iterator make_iterator(IterationType_e type) const
const LayerControl & operator->() const
iterator(const SteeringParams &sp, IterationType_e t)
std::vector< LayerControl > m_layer_plan
std::string m_track_scorer_name