File indexing completed on 2022-04-07 05:53:42
0001 #ifndef RecoTracker_MkFitCore_interface_TrackerInfo_h
0002 #define RecoTracker_MkFitCore_interface_TrackerInfo_h
0003
0004 #include "RecoTracker/MkFitCore/interface/MatrixSTypes.h"
0005 #include <string>
0006 #include <vector>
0007
0008 namespace mkfit {
0009
0010 enum WithinSensitiveRegion_e { WSR_Undef = -1, WSR_Inside = 0, WSR_Edge, WSR_Outside };
0011
0012 struct WSR_Result {
0013
0014 WithinSensitiveRegion_e m_wsr : 8;
0015 bool m_in_gap : 8;
0016
0017 WSR_Result() : m_wsr(WSR_Undef), m_in_gap(false) {}
0018
0019 WSR_Result(WithinSensitiveRegion_e wsr, bool in_gap) : m_wsr(wsr), m_in_gap(in_gap) {}
0020 };
0021
0022
0023
0024 struct ModuleInfo {
0025 SVector3 pos;
0026 SVector3 zdir;
0027 SVector3 xdir;
0028 unsigned int detid;
0029
0030 ModuleInfo() = default;
0031 ModuleInfo(SVector3 p, SVector3 zd, SVector3 xd, unsigned int id) : pos(p), zdir(zd), xdir(xd), detid(id) {}
0032 };
0033
0034
0035
0036 class LayerInfo {
0037 friend class TrackerInfo;
0038
0039 public:
0040 enum LayerType_e { Undef = -1, Barrel = 0, EndCapPos = 1, EndCapNeg = 2 };
0041
0042 LayerInfo() = default;
0043 LayerInfo(int lid, LayerType_e type) : m_layer_id(lid), m_layer_type(type) {}
0044
0045 void set_layer_type(LayerType_e t) { m_layer_type = t; }
0046 void set_limits(float r1, float r2, float z1, float z2);
0047 void extend_limits(float r, float z);
0048 void set_r_in_out(float r1, float r2);
0049 void set_propagate_to(float pto) { m_propagate_to = pto; }
0050 void set_r_hole_range(float rh1, float rh2);
0051 void set_q_bin(float qb) { m_q_bin = qb; }
0052 void set_subdet(int sd) { m_subdet = sd; }
0053 void set_is_pixel(bool p) { m_is_pixel = p; }
0054 void set_is_stereo(bool s) { m_is_stereo = s; }
0055
0056 int layer_id() const { return m_layer_id; }
0057 LayerType_e layer_type() const { return m_layer_type; }
0058 float rin() const { return m_rin; }
0059 float rout() const { return m_rout; }
0060 float r_mean() const { return 0.5f * (m_rin + m_rout); }
0061 float zmin() const { return m_zmin; }
0062 float zmax() const { return m_zmax; }
0063 float z_mean() const { return 0.5f * (m_zmin + m_zmax); }
0064 float propagate_to() const { return m_propagate_to; }
0065 float q_bin() const { return m_q_bin; }
0066
0067 int subdet() const { return m_subdet; }
0068 bool is_barrel() const { return m_layer_type == Barrel; }
0069 bool is_pixel() const { return m_is_pixel; }
0070 bool is_stereo() const { return m_is_stereo; }
0071
0072 bool is_within_z_limits(float z) const { return z > m_zmin && z < m_zmax; }
0073 bool is_within_r_limits(float r) const { return r > m_rin && r < m_rout; }
0074 bool is_within_q_limits(float q) const { return is_barrel() ? is_within_z_limits(q) : is_within_r_limits(q); }
0075
0076 bool is_in_r_hole(float r) const { return m_has_r_range_hole ? is_in_r_hole_no_check(r) : false; }
0077
0078 WSR_Result is_within_z_sensitive_region(float z, float dz) const {
0079 if (z > m_zmax + dz || z < m_zmin - dz)
0080 return WSR_Result(WSR_Outside, false);
0081 if (z < m_zmax - dz && z > m_zmin + dz)
0082 return WSR_Result(WSR_Inside, false);
0083 return WSR_Result(WSR_Edge, false);
0084 }
0085
0086 WSR_Result is_within_r_sensitive_region(float r, float dr) const {
0087 if (r > m_rout + dr || r < m_rin - dr)
0088 return WSR_Result(WSR_Outside, false);
0089 if (r < m_rout - dr && r > m_rin + dr) {
0090 if (m_has_r_range_hole) {
0091 if (r < m_hole_r_max - dr && r > m_hole_r_min + dr)
0092 return WSR_Result(WSR_Outside, true);
0093 if (r < m_hole_r_max + dr && r > m_hole_r_min - dr)
0094 return WSR_Result(WSR_Edge, true);
0095 }
0096 return WSR_Result(WSR_Inside, false);
0097 }
0098 return WSR_Result(WSR_Edge, false);
0099 }
0100
0101 void print_layer() const;
0102
0103
0104 void reserve_modules(int nm) { m_modules.reserve(nm); }
0105 unsigned int register_module(ModuleInfo&& mi) {
0106 unsigned int pos = m_modules.size();
0107 m_modules.emplace_back(mi);
0108 m_detid2sid[mi.detid] = pos;
0109 return pos;
0110 }
0111 unsigned int shrink_modules() {
0112 m_modules.shrink_to_fit();
0113 return m_modules.size() - 1;
0114 }
0115
0116 unsigned int short_id(unsigned int detid) const { return m_detid2sid.at(detid); }
0117 int n_modules() const { return m_modules.size(); }
0118 const ModuleInfo& module_info(unsigned int sid) const { return m_modules[sid]; }
0119
0120 private:
0121 bool is_in_r_hole_no_check(float r) const { return r > m_hole_r_min && r < m_hole_r_max; }
0122
0123 int m_layer_id = -1;
0124 LayerType_e m_layer_type = Undef;
0125 int m_subdet = -1;
0126
0127 float m_rin = 0, m_rout = 0, m_zmin = 0, m_zmax = 0;
0128 float m_propagate_to = 0;
0129
0130 float m_q_bin = 0;
0131 float m_hole_r_min = 0, m_hole_r_max = 0;
0132 bool m_has_r_range_hole = false;
0133 bool m_is_stereo = false;
0134 bool m_is_pixel = false;
0135
0136 std::unordered_map<unsigned int, unsigned int> m_detid2sid;
0137 std::vector<ModuleInfo> m_modules;
0138 };
0139
0140
0141
0142 class TrackerInfo {
0143 public:
0144 enum EtaRegion {
0145 Reg_Begin = 0,
0146 Reg_Endcap_Neg = 0,
0147 Reg_Transition_Neg,
0148 Reg_Barrel,
0149 Reg_Transition_Pos,
0150 Reg_Endcap_Pos,
0151 Reg_End,
0152 Reg_Count = Reg_End
0153 };
0154
0155 void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg);
0156 void create_layers(int n_brl, int n_ec_pos, int n_ec_neg);
0157 LayerInfo& new_barrel_layer();
0158 LayerInfo& new_ecap_pos_layer();
0159 LayerInfo& new_ecap_neg_layer();
0160
0161 int n_layers() const { return m_layers.size(); }
0162 const LayerInfo& layer(int l) const { return m_layers[l]; }
0163 LayerInfo& layer_nc(int l) { return m_layers[l]; }
0164
0165 int n_total_modules() const;
0166
0167 const LayerInfo& operator[](int l) const { return m_layers[l]; }
0168
0169 const LayerInfo& outer_barrel_layer() const { return m_layers[m_barrel.back()]; }
0170
0171 const std::vector<int>& barrel_layers() const { return m_barrel; }
0172 const std::vector<int>& endcap_pos_layers() const { return m_ecap_pos; }
0173 const std::vector<int>& endcap_neg_layers() const { return m_ecap_neg; }
0174
0175 void write_bin_file(const std::string& fname) const;
0176 void read_bin_file(const std::string& fname);
0177 void print_tracker(int level) const;
0178
0179 private:
0180 int new_layer(LayerInfo::LayerType_e type);
0181
0182 std::vector<LayerInfo> m_layers;
0183
0184 std::vector<int> m_barrel;
0185 std::vector<int> m_ecap_pos;
0186 std::vector<int> m_ecap_neg;
0187 };
0188
0189 }
0190 #endif