Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-11-19 23:58:41

0001 #ifndef RecoTracker_MkFitCore_interface_TrackerInfo_h
0002 #define RecoTracker_MkFitCore_interface_TrackerInfo_h
0003 
0004 #include "RecoTracker/MkFitCore/interface/MatrixSTypes.h"
0005 #include "RecoTracker/MkFitCore/interface/PropagationConfig.h"
0006 #include "RecoTracker/MkFitCore/interface/Config.h"
0007 #include <string>
0008 #include <unordered_map>
0009 #include <vector>
0010 #include <unordered_map>
0011 
0012 namespace mkfit {
0013 
0014   //==============================================================================
0015   // WSR -- WithinSensitiveRegion state
0016 
0017   enum WithinSensitiveRegion_e { WSR_Undef = -1, WSR_Inside = 0, WSR_Edge, WSR_Outside, WSR_Failed };
0018 
0019   struct WSR_Result {
0020     // Could also store XHitSize count equivalent here : 16;
0021     WithinSensitiveRegion_e m_wsr : 8;
0022     bool m_in_gap : 8;
0023 
0024     WSR_Result() : m_wsr(WSR_Undef), m_in_gap(false) {}
0025 
0026     WSR_Result(WithinSensitiveRegion_e wsr, bool in_gap) : m_wsr(wsr), m_in_gap(in_gap) {}
0027   };
0028 
0029   //==============================================================================
0030 
0031   struct ModuleInfo {
0032     SVector3 pos;
0033     SVector3 zdir;
0034     SVector3 xdir;
0035     float half_length;
0036     unsigned int detid;
0037 
0038     ModuleInfo() = default;
0039     ModuleInfo(SVector3 p, SVector3 zd, SVector3 xd, float hl, unsigned int id)
0040         : pos(p), zdir(zd), xdir(xd), half_length(hl), detid(id) {}
0041   };
0042 
0043   //==============================================================================
0044 
0045   class LayerInfo {
0046     friend class TrackerInfo;
0047 
0048   public:
0049     enum LayerType_e { Undef = -1, Barrel = 0, EndCapPos = 1, EndCapNeg = 2 };
0050 
0051     LayerInfo() = default;
0052     LayerInfo(int lid, LayerType_e type) : m_layer_id(lid), m_layer_type(type) {}
0053 
0054     void set_layer_type(LayerType_e t) { m_layer_type = t; }
0055     void set_limits(float r1, float r2, float z1, float z2);
0056     void extend_limits(float r, float z);
0057     void set_r_in_out(float r1, float r2);
0058     void set_propagate_to(float pto) { m_propagate_to = pto; }
0059     void set_r_hole_range(float rh1, float rh2);
0060     void set_q_bin(float qb) { m_q_bin = qb; }
0061     void set_subdet(int sd) { m_subdet = sd; }
0062     void set_is_pixel(bool p) { m_is_pixel = p; }
0063     void set_is_stereo(bool s) { m_is_stereo = s; }
0064 
0065     int layer_id() const { return m_layer_id; }
0066     LayerType_e layer_type() const { return m_layer_type; }
0067     float rin() const { return m_rin; }
0068     float rout() const { return m_rout; }
0069     float r_mean() const { return 0.5f * (m_rin + m_rout); }
0070     float zmin() const { return m_zmin; }
0071     float zmax() const { return m_zmax; }
0072     float z_mean() const { return 0.5f * (m_zmin + m_zmax); }
0073     float propagate_to() const { return m_propagate_to; }
0074     float q_bin() const { return m_q_bin; }
0075 
0076     int subdet() const { return m_subdet; }
0077     bool is_barrel() const { return m_layer_type == Barrel; }
0078     bool is_pixel() const { return m_is_pixel; }
0079     bool is_stereo() const { return m_is_stereo; }
0080 
0081     bool is_within_z_limits(float z) const { return z > m_zmin && z < m_zmax; }
0082     bool is_within_r_limits(float r) const { return r > m_rin && r < m_rout; }
0083     bool is_within_q_limits(float q) const { return is_barrel() ? is_within_z_limits(q) : is_within_r_limits(q); }
0084 
0085     bool is_in_r_hole(float r) const { return m_has_r_range_hole ? is_in_r_hole_no_check(r) : false; }
0086 
0087     WSR_Result is_within_z_sensitive_region(float z, float dz) const {
0088       if (z > m_zmax + dz || z < m_zmin - dz)
0089         return WSR_Result(WSR_Outside, false);
0090       if (z < m_zmax - dz && z > m_zmin + dz)
0091         return WSR_Result(WSR_Inside, false);
0092       return WSR_Result(WSR_Edge, false);
0093     }
0094 
0095     WSR_Result is_within_r_sensitive_region(float r, float dr) const {
0096       if (r > m_rout + dr || r < m_rin - dr)
0097         return WSR_Result(WSR_Outside, false);
0098       if (r < m_rout - dr && r > m_rin + dr) {
0099         if (m_has_r_range_hole) {
0100           if (r < m_hole_r_max - dr && r > m_hole_r_min + dr)
0101             return WSR_Result(WSR_Outside, true);
0102           if (r < m_hole_r_max + dr && r > m_hole_r_min - dr)
0103             return WSR_Result(WSR_Edge, true);
0104         }
0105         return WSR_Result(WSR_Inside, false);
0106       }
0107       return WSR_Result(WSR_Edge, false);
0108     }
0109 
0110     void print_layer() const;
0111 
0112     // module & detid interface
0113     void reserve_modules(int nm) { m_modules.reserve(nm); }
0114     unsigned int register_module(ModuleInfo&& mi) {
0115       unsigned int pos = m_modules.size();
0116       m_modules.emplace_back(mi);
0117       m_detid2sid[mi.detid] = pos;
0118       return pos;
0119     }
0120     unsigned int shrink_modules() {
0121       m_modules.shrink_to_fit();
0122       return m_modules.size() - 1;
0123     }
0124 
0125     unsigned int short_id(unsigned int detid) const { return m_detid2sid.at(detid); }
0126     int n_modules() const { return m_modules.size(); }
0127     const ModuleInfo& module_info(unsigned int sid) const { return m_modules[sid]; }
0128 
0129   private:
0130     bool is_in_r_hole_no_check(float r) const { return r > m_hole_r_min && r < m_hole_r_max; }
0131 
0132     int m_layer_id = -1;
0133     LayerType_e m_layer_type = Undef;
0134     int m_subdet = -1;  // sub-detector id, not used in core mkFit
0135 
0136     float m_rin = 0, m_rout = 0, m_zmin = 0, m_zmax = 0;
0137     float m_propagate_to = 0;
0138 
0139     float m_q_bin = 0;                         // > 0 - bin width, < 0 - number of bins
0140     float m_hole_r_min = 0, m_hole_r_max = 0;  // This could be turned into std::function when needed.
0141     bool m_has_r_range_hole = false;
0142     bool m_is_stereo = false;
0143     bool m_is_pixel = false;
0144 
0145     std::unordered_map<unsigned int, unsigned int> m_detid2sid;
0146     std::vector<ModuleInfo> m_modules;
0147   };
0148 
0149   //==============================================================================
0150 
0151   template <typename T>
0152   class rectvec {
0153   public:
0154     rectvec(int n1 = 0, int n2 = 0) : m_n1(n1), m_n2(n2), m_vec(n1 * n2) {}
0155 
0156     void rerect(int n1, int n2) {
0157       m_n1 = n1;
0158       m_n2 = n2;
0159       m_vec.resize(n1 * n2);
0160     }
0161 
0162     const T& operator()(int i1, int i2) const { return m_vec[i1 * m_n2 + i2]; }
0163     T& operator()(int i1, int i2) { return m_vec[i1 * m_n2 + i2]; }
0164 
0165     const T* operator[](int i1) const { return &m_vec[i1 * m_n2]; }
0166     T* operator[](int i1) { return &m_vec[i1 * m_n2]; }
0167 
0168     const std::vector<T>& vector() const { return m_vec; }
0169     std::vector<T>& vector() { return m_vec; }
0170 
0171     int n1() const { return m_n1; }
0172     int n2() const { return m_n2; }
0173     bool check_idcs(int i1, int i2) const { return i1 >= 0 && i1 < m_n1 && i2 >= 0 && i2 < m_n2; }
0174 
0175   private:
0176     int m_n1, m_n2;
0177     std::vector<T> m_vec;
0178   };
0179 
0180   class TrackerInfo {
0181   public:
0182     enum EtaRegion {
0183       Reg_Begin = 0,
0184       Reg_Endcap_Neg = 0,
0185       Reg_Transition_Neg,
0186       Reg_Barrel,
0187       Reg_Transition_Pos,
0188       Reg_Endcap_Pos,
0189       Reg_End,
0190       Reg_Count = Reg_End
0191     };
0192     struct Material {
0193       float bbxi{0}, radl{0};
0194     };
0195 
0196     void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg);
0197     void create_layers(int n_brl, int n_ec_pos, int n_ec_neg);
0198     LayerInfo& new_barrel_layer();
0199     LayerInfo& new_ecap_pos_layer();
0200     LayerInfo& new_ecap_neg_layer();
0201 
0202     int n_layers() const { return m_layers.size(); }
0203     const LayerInfo& layer(int l) const { return m_layers[l]; }
0204     LayerInfo& layer_nc(int l) { return m_layers[l]; }
0205 
0206     int n_total_modules() const;
0207 
0208     const LayerInfo& operator[](int l) const { return m_layers[l]; }
0209 
0210     const LayerInfo& outer_barrel_layer() const { return m_layers[m_barrel.back()]; }
0211 
0212     const std::vector<int>& barrel_layers() const { return m_barrel; }
0213     const std::vector<int>& endcap_pos_layers() const { return m_ecap_pos; }
0214     const std::vector<int>& endcap_neg_layers() const { return m_ecap_neg; }
0215 
0216     const PropagationConfig& prop_config() const { return m_prop_config; }
0217     PropagationConfig& prop_config_nc() { return m_prop_config; }
0218 
0219     void write_bin_file(const std::string& fname) const;
0220     void read_bin_file(const std::string& fname);
0221     void print_tracker(int level) const;
0222 
0223     void create_material(int nBinZ, float rngZ, int nBinR, float rngR);
0224     int mat_nbins_z() const { return m_mat_vec.n1(); }
0225     int mat_nbins_r() const { return m_mat_vec.n2(); }
0226     float mat_range_z() const { return m_mat_range_z; }
0227     float mat_range_r() const { return m_mat_range_r; }
0228     int mat_bin_z(float z) const { return z * m_mat_fac_z; }
0229     int mat_bin_r(float r) const { return r * m_mat_fac_r; }
0230     bool check_bins(int bz, int br) const { return m_mat_vec.check_idcs(bz, br); }
0231 
0232     float material_bbxi(int binZ, int binR) const { return m_mat_vec(binZ, binR).bbxi; }
0233     float material_radl(int binZ, int binR) const { return m_mat_vec(binZ, binR).radl; }
0234     float& material_bbxi(int binZ, int binR) { return m_mat_vec(binZ, binR).bbxi; }
0235     float& material_radl(int binZ, int binR) { return m_mat_vec(binZ, binR).radl; }
0236 
0237     Material material_checked(float z, float r) const {
0238       const int zbin = mat_bin_z(z), rbin = mat_bin_r(r);
0239       return check_bins(zbin, rbin) ? m_mat_vec(zbin, rbin) : Material();
0240     }
0241 
0242   private:
0243     int new_layer(LayerInfo::LayerType_e type);
0244 
0245     std::vector<LayerInfo> m_layers;
0246 
0247     std::vector<int> m_barrel;
0248     std::vector<int> m_ecap_pos;
0249     std::vector<int> m_ecap_neg;
0250 
0251     float m_mat_range_z, m_mat_range_r;
0252     float m_mat_fac_z, m_mat_fac_r;
0253     rectvec<Material> m_mat_vec;
0254 
0255     PropagationConfig m_prop_config;
0256   };
0257 
0258 }  // end namespace mkfit
0259 #endif