Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:16

0001 #ifndef RecoTracker_MkFitCore_interface_SteeringParams_h
0002 #define RecoTracker_MkFitCore_interface_SteeringParams_h
0003 
0004 #include "RecoTracker/MkFitCore/interface/FunctionTypes.h"
0005 
0006 #include <vector>
0007 #include <stdexcept>
0008 
0009 namespace mkfit {
0010 
0011   //==============================================================================
0012   // LayerControl
0013   //==============================================================================
0014 
0015   struct LayerControl {
0016     int m_layer;
0017 
0018     // Idea only ... need some parallel structure for candidates to make sense (where i can store it).
0019     // Or have per layer containers where I place track indices to enable. Or something. Sigh.
0020     // int  m_on_miss_jump_to = -999;
0021     // int  m_on_hit_jump_to  = -999;
0022 
0023     // Used to have pickup-only / bk-fit only bools etc.
0024     // Moved to SteeringParams as layer indices where pickup/bkfit/bksrch start/end/start.
0025 
0026     //----------------------------------------------------------------------------
0027 
0028     LayerControl() : m_layer(-1) {}
0029     LayerControl(int lay) : m_layer(lay) {}
0030   };
0031 
0032   //==============================================================================
0033   // SteeringParams
0034   //==============================================================================
0035 
0036   class SteeringParams {
0037   public:
0038     enum IterationType_e { IT_FwdSearch, IT_BkwFit, IT_BkwSearch };
0039 
0040     class iterator {
0041       friend class SteeringParams;
0042 
0043       const SteeringParams& m_steering_params;
0044       IterationType_e m_type;
0045       int m_cur_index = -1;
0046       int m_end_index = -1;
0047 
0048       iterator(const SteeringParams& sp, IterationType_e t) : m_steering_params(sp), m_type(t) {}
0049 
0050     public:
0051       const LayerControl& layer_control() const { return m_steering_params.m_layer_plan[m_cur_index]; }
0052       int layer() const { return layer_control().m_layer; }
0053       int index() const { return m_cur_index; }
0054       int region() const { return m_steering_params.m_region; }
0055 
0056       bool is_valid() const { return m_cur_index != -1; }
0057 
0058       const LayerControl& operator->() const { return layer_control(); }
0059 
0060       bool is_pickup_only() const {
0061         if (m_type == IT_FwdSearch)
0062           return m_cur_index == m_steering_params.m_fwd_search_pickup;
0063         else if (m_type == IT_BkwSearch)
0064           return m_cur_index == m_steering_params.m_bkw_search_pickup;
0065         else
0066           throw std::runtime_error("invalid iteration type");
0067       }
0068 
0069       bool operator++() {
0070         if (!is_valid())
0071           return false;
0072         if (m_type == IT_FwdSearch) {
0073           if (++m_cur_index == m_end_index)
0074             m_cur_index = -1;
0075         } else {
0076           if (--m_cur_index == m_end_index)
0077             m_cur_index = -1;
0078         }
0079         return is_valid();
0080       }
0081 
0082       // Functions for debug printouts
0083       int end_index() const { return m_end_index; }
0084       int next_layer() const {
0085         if (m_type == IT_FwdSearch)
0086           return m_steering_params.m_layer_plan[m_cur_index + 1].m_layer;
0087         else
0088           return m_steering_params.m_layer_plan[m_cur_index - 1].m_layer;
0089       }
0090       int last_layer() const {
0091         if (m_type == IT_FwdSearch)
0092           return m_steering_params.m_layer_plan[m_end_index - 1].m_layer;
0093         else
0094           return m_steering_params.m_layer_plan[m_end_index + 1].m_layer;
0095       }
0096     };  // class iterator
0097 
0098     std::vector<LayerControl> m_layer_plan;
0099     track_score_func m_track_scorer;
0100     std::string m_track_scorer_name;
0101 
0102     int m_region;
0103 
0104     int m_fwd_search_pickup = 0;
0105     int m_bkw_fit_last = 0;
0106     int m_bkw_search_pickup = -1;
0107 
0108     //----------------------------------------------------------------------------
0109 
0110     SteeringParams() {}
0111 
0112     void reserve_plan(int n) { m_layer_plan.reserve(n); }
0113 
0114     void append_plan(int layer) { m_layer_plan.emplace_back(LayerControl(layer)); }
0115 
0116     void fill_plan(int first, int last) {
0117       for (int i = first; i <= last; ++i)
0118         append_plan(i);
0119     }
0120 
0121     void set_iterator_limits(int fwd_search_pu, int bkw_fit_last, int bkw_search_pu = -1) {
0122       m_fwd_search_pickup = fwd_search_pu;
0123       m_bkw_fit_last = bkw_fit_last;
0124       m_bkw_search_pickup = bkw_search_pu;
0125     }
0126 
0127     bool has_bksearch_plan() const { return m_bkw_search_pickup != -1; }
0128 
0129     iterator make_iterator(IterationType_e type) const {
0130       iterator it(*this, type);
0131 
0132       if (type == IT_FwdSearch) {
0133         it.m_cur_index = m_fwd_search_pickup;
0134         it.m_end_index = m_layer_plan.size();
0135       } else if (type == IT_BkwFit) {
0136         it.m_cur_index = m_layer_plan.size() - 1;
0137         it.m_end_index = m_bkw_fit_last - 1;
0138       } else if (type == IT_BkwSearch) {
0139         it.m_cur_index = m_bkw_search_pickup;
0140         it.m_end_index = -1;
0141       } else
0142         throw std::invalid_argument("unknown iteration type");
0143 
0144       if (!it.is_valid())
0145         throw std::runtime_error("invalid iterator constructed");
0146 
0147       return it;
0148     }
0149   };
0150 
0151 }  // end namespace mkfit
0152 
0153 #endif