CMS 3D CMS Logo

TrackerInfo.h
Go to the documentation of this file.
1 #ifndef RecoTracker_MkFitCore_interface_TrackerInfo_h
2 #define RecoTracker_MkFitCore_interface_TrackerInfo_h
3 
7 #include <string>
8 #include <unordered_map>
9 #include <vector>
10 #include <unordered_map>
11 
12 namespace mkfit {
13 
14  //==============================================================================
15  // WSR -- WithinSensitiveRegion state
16 
18 
19  struct WSR_Result {
20  // Could also store XHitSize count equivalent here : 16;
22  bool m_in_gap : 8;
23 
25 
26  WSR_Result(WithinSensitiveRegion_e wsr, bool in_gap) : m_wsr(wsr), m_in_gap(in_gap) {}
27  };
28 
29  //==============================================================================
30 
31  struct ModuleInfo {
35  float half_length;
36  unsigned int detid;
37 
38  ModuleInfo() = default;
39  ModuleInfo(SVector3 p, SVector3 zd, SVector3 xd, float hl, unsigned int id)
40  : pos(p), zdir(zd), xdir(xd), half_length(hl), detid(id) {}
41  };
42 
43  //==============================================================================
44 
45  class LayerInfo {
46  friend class TrackerInfo;
47 
48  public:
49  enum LayerType_e { Undef = -1, Barrel = 0, EndCapPos = 1, EndCapNeg = 2 };
50 
51  LayerInfo() = default;
53 
55  void set_limits(float r1, float r2, float z1, float z2);
56  void extend_limits(float r, float z);
57  void set_r_in_out(float r1, float r2);
58  void set_propagate_to(float pto) { m_propagate_to = pto; }
59  void set_r_hole_range(float rh1, float rh2);
60  void set_q_bin(float qb) { m_q_bin = qb; }
61  void set_subdet(int sd) { m_subdet = sd; }
62  void set_is_pixel(bool p) { m_is_pixel = p; }
63  void set_is_stereo(bool s) { m_is_stereo = s; }
64 
65  int layer_id() const { return m_layer_id; }
66  LayerType_e layer_type() const { return m_layer_type; }
67  float rin() const { return m_rin; }
68  float rout() const { return m_rout; }
69  float r_mean() const { return 0.5f * (m_rin + m_rout); }
70  float zmin() const { return m_zmin; }
71  float zmax() const { return m_zmax; }
72  float z_mean() const { return 0.5f * (m_zmin + m_zmax); }
73  float propagate_to() const { return m_propagate_to; }
74  float q_bin() const { return m_q_bin; }
75 
76  int subdet() const { return m_subdet; }
77  bool is_barrel() const { return m_layer_type == Barrel; }
78  bool is_pixel() const { return m_is_pixel; }
79  bool is_stereo() const { return m_is_stereo; }
80 
81  bool is_within_z_limits(float z) const { return z > m_zmin && z < m_zmax; }
82  bool is_within_r_limits(float r) const { return r > m_rin && r < m_rout; }
83  bool is_within_q_limits(float q) const { return is_barrel() ? is_within_z_limits(q) : is_within_r_limits(q); }
84 
85  bool is_in_r_hole(float r) const { return m_has_r_range_hole ? is_in_r_hole_no_check(r) : false; }
86 
88  if (z > m_zmax + dz || z < m_zmin - dz)
89  return WSR_Result(WSR_Outside, false);
90  if (z < m_zmax - dz && z > m_zmin + dz)
91  return WSR_Result(WSR_Inside, false);
92  return WSR_Result(WSR_Edge, false);
93  }
94 
96  if (r > m_rout + dr || r < m_rin - dr)
97  return WSR_Result(WSR_Outside, false);
98  if (r < m_rout - dr && r > m_rin + dr) {
99  if (m_has_r_range_hole) {
100  if (r < m_hole_r_max - dr && r > m_hole_r_min + dr)
101  return WSR_Result(WSR_Outside, true);
102  if (r < m_hole_r_max + dr && r > m_hole_r_min - dr)
103  return WSR_Result(WSR_Edge, true);
104  }
105  return WSR_Result(WSR_Inside, false);
106  }
107  return WSR_Result(WSR_Edge, false);
108  }
109 
110  void print_layer() const;
111 
112  // module & detid interface
113  void reserve_modules(int nm) { m_modules.reserve(nm); }
114  unsigned int register_module(ModuleInfo&& mi) {
115  unsigned int pos = m_modules.size();
116  m_modules.emplace_back(mi);
117  m_detid2sid[mi.detid] = pos;
118  return pos;
119  }
120  unsigned int shrink_modules() {
121  m_modules.shrink_to_fit();
122  return m_modules.size() - 1;
123  }
124 
125  unsigned int short_id(unsigned int detid) const { return m_detid2sid.at(detid); }
126  int n_modules() const { return m_modules.size(); }
127  const ModuleInfo& module_info(unsigned int sid) const { return m_modules[sid]; }
128 
129  private:
130  bool is_in_r_hole_no_check(float r) const { return r > m_hole_r_min && r < m_hole_r_max; }
131 
132  int m_layer_id = -1;
134  int m_subdet = -1; // sub-detector id, not used in core mkFit
135 
136  float m_rin = 0, m_rout = 0, m_zmin = 0, m_zmax = 0;
137  float m_propagate_to = 0;
138 
139  float m_q_bin = 0; // > 0 - bin width, < 0 - number of bins
140  float m_hole_r_min = 0, m_hole_r_max = 0; // This could be turned into std::function when needed.
141  bool m_has_r_range_hole = false;
142  bool m_is_stereo = false;
143  bool m_is_pixel = false;
144 
145  std::unordered_map<unsigned int, unsigned int> m_detid2sid;
146  std::vector<ModuleInfo> m_modules;
147  };
148 
149  //==============================================================================
150 
151  template <typename T>
152  class rectvec {
153  public:
154  rectvec(int n1 = 0, int n2 = 0) : m_n1(n1), m_n2(n2), m_vec(n1 * n2) {}
155 
156  void rerect(int n1, int n2) {
157  m_n1 = n1;
158  m_n2 = n2;
159  m_vec.resize(n1 * n2);
160  }
161 
162  const T& operator()(int i1, int i2) const { return m_vec[i1 * m_n2 + i2]; }
163  T& operator()(int i1, int i2) { return m_vec[i1 * m_n2 + i2]; }
164 
165  const T* operator[](int i1) const { return &m_vec[i1 * m_n2]; }
166  T* operator[](int i1) { return &m_vec[i1 * m_n2]; }
167 
168  const std::vector<T>& vector() const { return m_vec; }
169  std::vector<T>& vector() { return m_vec; }
170 
171  int n1() const { return m_n1; }
172  int n2() const { return m_n2; }
173  bool check_idcs(int i1, int i2) const { return i1 >= 0 && i1 < m_n1 && i2 >= 0 && i2 < m_n2; }
174 
175  private:
176  int m_n1, m_n2;
177  std::vector<T> m_vec;
178  };
179 
180  class TrackerInfo {
181  public:
182  enum EtaRegion {
191  };
192  struct Material {
193  float bbxi{0}, radl{0};
194  };
195 
196  void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg);
197  void create_layers(int n_brl, int n_ec_pos, int n_ec_neg);
201 
202  int n_layers() const { return m_layers.size(); }
203  const LayerInfo& layer(int l) const { return m_layers[l]; }
204  LayerInfo& layer_nc(int l) { return m_layers[l]; }
205 
206  int n_total_modules() const;
207 
208  const LayerInfo& operator[](int l) const { return m_layers[l]; }
209 
210  const LayerInfo& outer_barrel_layer() const { return m_layers[m_barrel.back()]; }
211 
212  const std::vector<int>& barrel_layers() const { return m_barrel; }
213  const std::vector<int>& endcap_pos_layers() const { return m_ecap_pos; }
214  const std::vector<int>& endcap_neg_layers() const { return m_ecap_neg; }
215 
216  const PropagationConfig& prop_config() const { return m_prop_config; }
218 
219  void write_bin_file(const std::string& fname) const;
220  void read_bin_file(const std::string& fname);
221  void print_tracker(int level) const;
222 
223  void create_material(int nBinZ, float rngZ, int nBinR, float rngR);
224  int mat_nbins_z() const { return m_mat_vec.n1(); }
225  int mat_nbins_r() const { return m_mat_vec.n2(); }
226  float mat_range_z() const { return m_mat_range_z; }
227  float mat_range_r() const { return m_mat_range_r; }
228  int mat_bin_z(float z) const { return z * m_mat_fac_z; }
229  int mat_bin_r(float r) const { return r * m_mat_fac_r; }
230  bool check_bins(int bz, int br) const { return m_mat_vec.check_idcs(bz, br); }
231 
232  float material_bbxi(int binZ, int binR) const { return m_mat_vec(binZ, binR).bbxi; }
233  float material_radl(int binZ, int binR) const { return m_mat_vec(binZ, binR).radl; }
234  float& material_bbxi(int binZ, int binR) { return m_mat_vec(binZ, binR).bbxi; }
235  float& material_radl(int binZ, int binR) { return m_mat_vec(binZ, binR).radl; }
236 
237  Material material_checked(float z, float r) const {
238  const int zbin = mat_bin_z(z), rbin = mat_bin_r(r);
239  return check_bins(zbin, rbin) ? m_mat_vec(zbin, rbin) : Material();
240  }
241 
242  private:
244 
245  std::vector<LayerInfo> m_layers;
246 
247  std::vector<int> m_barrel;
248  std::vector<int> m_ecap_pos;
249  std::vector<int> m_ecap_neg;
250 
254 
256  };
257 
258 } // end namespace mkfit
259 #endif
void set_is_stereo(bool s)
Definition: TrackerInfo.h:63
void rerect(int n1, int n2)
Definition: TrackerInfo.h:156
const std::vector< int > & barrel_layers() const
Definition: TrackerInfo.h:212
void extend_limits(float r, float z)
Definition: TrackerInfo.cc:33
float z_mean() const
Definition: TrackerInfo.h:72
const T & operator()(int i1, int i2) const
Definition: TrackerInfo.h:162
void read_bin_file(const std::string &fname)
Definition: TrackerInfo.cc:202
bool is_in_r_hole_no_check(float r) const
Definition: TrackerInfo.h:130
float rin() const
Definition: TrackerInfo.h:67
const std::vector< int > & endcap_pos_layers() const
Definition: TrackerInfo.h:213
float q_bin() const
Definition: TrackerInfo.h:74
T * operator[](int i1)
Definition: TrackerInfo.h:166
void set_r_hole_range(float rh1, float rh2)
Definition: TrackerInfo.cc:49
unsigned int short_id(unsigned int detid) const
Definition: TrackerInfo.h:125
std::vector< int > m_barrel
Definition: TrackerInfo.h:247
void set_q_bin(float qb)
Definition: TrackerInfo.h:60
void print_layer() const
Definition: TrackerInfo.cc:55
const std::vector< T > & vector() const
Definition: TrackerInfo.h:168
LayerInfo & new_barrel_layer()
Definition: TrackerInfo.cc:93
ROOT::Math::SVector< float, 3 > SVector3
Definition: MatrixSTypes.h:14
bool check_idcs(int i1, int i2) const
Definition: TrackerInfo.h:173
PropagationConfig & prop_config_nc()
Definition: TrackerInfo.h:217
std::vector< int > m_ecap_neg
Definition: TrackerInfo.h:249
LayerInfo & new_ecap_neg_layer()
Definition: TrackerInfo.cc:103
float propagate_to() const
Definition: TrackerInfo.h:73
unsigned int detid
Definition: TrackerInfo.h:36
void create_material(int nBinZ, float rngZ, int nBinR, float rngR)
Definition: TrackerInfo.cc:118
void set_r_in_out(float r1, float r2)
Definition: TrackerInfo.cc:44
const LayerInfo & operator[](int l) const
Definition: TrackerInfo.h:208
bool is_pixel() const
Definition: TrackerInfo.h:78
WSR_Result(WithinSensitiveRegion_e wsr, bool in_gap)
Definition: TrackerInfo.h:26
LayerInfo & layer_nc(int l)
Definition: TrackerInfo.h:204
const LayerInfo & outer_barrel_layer() const
Definition: TrackerInfo.h:210
T & operator()(int i1, int i2)
Definition: TrackerInfo.h:163
float zmax() const
Definition: TrackerInfo.h:71
std::vector< ModuleInfo > m_modules
Definition: TrackerInfo.h:146
PropagationConfig m_prop_config
Definition: TrackerInfo.h:255
bool is_in_r_hole(float r) const
Definition: TrackerInfo.h:85
WSR_Result is_within_z_sensitive_region(float z, float dz) const
Definition: TrackerInfo.h:87
int mat_nbins_r() const
Definition: TrackerInfo.h:225
const std::vector< int > & endcap_neg_layers() const
Definition: TrackerInfo.h:214
std::vector< T > m_vec
Definition: TrackerInfo.h:177
bool is_within_z_limits(float z) const
Definition: TrackerInfo.h:81
float zmin() const
Definition: TrackerInfo.h:70
float material_radl(int binZ, int binR) const
Definition: TrackerInfo.h:233
int n1() const
Definition: TrackerInfo.h:171
void set_limits(float r1, float r2, float z1, float z2)
Definition: TrackerInfo.cc:26
const ModuleInfo & module_info(unsigned int sid) const
Definition: TrackerInfo.h:127
void set_layer_type(LayerType_e t)
Definition: TrackerInfo.h:54
bool is_within_q_limits(float q) const
Definition: TrackerInfo.h:83
int n_layers() const
Definition: TrackerInfo.h:202
int mat_bin_z(float z) const
Definition: TrackerInfo.h:228
LayerInfo & new_ecap_pos_layer()
Definition: TrackerInfo.cc:98
LayerType_e layer_type() const
Definition: TrackerInfo.h:66
float mat_range_z() const
Definition: TrackerInfo.h:226
int layer_id() const
Definition: TrackerInfo.h:65
unsigned int register_module(ModuleInfo &&mi)
Definition: TrackerInfo.h:114
int new_layer(LayerInfo::LayerType_e type)
Definition: TrackerInfo.cc:87
void set_is_pixel(bool p)
Definition: TrackerInfo.h:62
bool check_bins(int bz, int br) const
Definition: TrackerInfo.h:230
void create_layers(int n_brl, int n_ec_pos, int n_ec_neg)
Definition: TrackerInfo.cc:77
LayerInfo()=default
WSR_Result is_within_r_sensitive_region(float r, float dr) const
Definition: TrackerInfo.h:95
float & material_bbxi(int binZ, int binR)
Definition: TrackerInfo.h:234
int n_modules() const
Definition: TrackerInfo.h:126
float mat_range_r() const
Definition: TrackerInfo.h:227
int mat_bin_r(float r) const
Definition: TrackerInfo.h:229
void reserve_modules(int nm)
Definition: TrackerInfo.h:113
const LayerInfo & layer(int l) const
Definition: TrackerInfo.h:203
const T * operator[](int i1) const
Definition: TrackerInfo.h:165
float & material_radl(int binZ, int binR)
Definition: TrackerInfo.h:235
int n2() const
Definition: TrackerInfo.h:172
rectvec< Material > m_mat_vec
Definition: TrackerInfo.h:253
bool is_stereo() const
Definition: TrackerInfo.h:79
int n_total_modules() const
Definition: TrackerInfo.cc:108
ModuleInfo(SVector3 p, SVector3 zd, SVector3 xd, float hl, unsigned int id)
Definition: TrackerInfo.h:39
rectvec(int n1=0, int n2=0)
Definition: TrackerInfo.h:154
WithinSensitiveRegion_e m_wsr
Definition: TrackerInfo.h:21
float r_mean() const
Definition: TrackerInfo.h:69
void print_tracker(int level) const
Definition: TrackerInfo.cc:275
float material_bbxi(int binZ, int binR) const
Definition: TrackerInfo.h:232
bool is_within_r_limits(float r) const
Definition: TrackerInfo.h:82
float rout() const
Definition: TrackerInfo.h:68
std::vector< int > m_ecap_pos
Definition: TrackerInfo.h:248
string fname
main script
LayerType_e m_layer_type
Definition: TrackerInfo.h:133
int subdet() const
Definition: TrackerInfo.h:76
LayerInfo(int lid, LayerType_e type)
Definition: TrackerInfo.h:52
void set_propagate_to(float pto)
Definition: TrackerInfo.h:58
void write_bin_file(const std::string &fname) const
Definition: TrackerInfo.cc:172
std::unordered_map< unsigned int, unsigned int > m_detid2sid
Definition: TrackerInfo.h:145
Material material_checked(float z, float r) const
Definition: TrackerInfo.h:237
WithinSensitiveRegion_e
Definition: TrackerInfo.h:17
ModuleInfo()=default
std::vector< T > & vector()
Definition: TrackerInfo.h:169
unsigned int shrink_modules()
Definition: TrackerInfo.h:120
long double T
int mat_nbins_z() const
Definition: TrackerInfo.h:224
std::vector< LayerInfo > m_layers
Definition: TrackerInfo.h:245
bool is_barrel() const
Definition: TrackerInfo.h:77
const PropagationConfig & prop_config() const
Definition: TrackerInfo.h:216
void set_subdet(int sd)
Definition: TrackerInfo.h:61
void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg)
Definition: TrackerInfo.cc:70