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  void set_has_charge(bool c) { m_has_charge = c; }
65 
66  int layer_id() const { return m_layer_id; }
67  LayerType_e layer_type() const { return m_layer_type; }
68  float rin() const { return m_rin; }
69  float rout() const { return m_rout; }
70  float r_mean() const { return 0.5f * (m_rin + m_rout); }
71  float zmin() const { return m_zmin; }
72  float zmax() const { return m_zmax; }
73  float z_mean() const { return 0.5f * (m_zmin + m_zmax); }
74  float propagate_to() const { return m_propagate_to; }
75  float q_bin() const { return m_q_bin; }
76 
77  int subdet() const { return m_subdet; }
78  bool is_barrel() const { return m_layer_type == Barrel; }
79  bool is_pixel() const { return m_is_pixel; }
80  bool is_stereo() const { return m_is_stereo; }
81  bool has_charge() const { return m_has_charge; }
82 
83  bool is_within_z_limits(float z) const { return z > m_zmin && z < m_zmax; }
84  bool is_within_r_limits(float r) const { return r > m_rin && r < m_rout; }
85  bool is_within_q_limits(float q) const { return is_barrel() ? is_within_z_limits(q) : is_within_r_limits(q); }
86 
87  bool is_in_r_hole(float r) const { return m_has_r_range_hole ? is_in_r_hole_no_check(r) : false; }
88 
90  if (z > m_zmax + dz || z < m_zmin - dz)
91  return WSR_Result(WSR_Outside, false);
92  if (z < m_zmax - dz && z > m_zmin + dz)
93  return WSR_Result(WSR_Inside, false);
94  return WSR_Result(WSR_Edge, false);
95  }
96 
98  if (r > m_rout + dr || r < m_rin - dr)
99  return WSR_Result(WSR_Outside, false);
100  if (r < m_rout - dr && r > m_rin + dr) {
101  if (m_has_r_range_hole) {
102  if (r < m_hole_r_max - dr && r > m_hole_r_min + dr)
103  return WSR_Result(WSR_Outside, true);
104  if (r < m_hole_r_max + dr && r > m_hole_r_min - dr)
105  return WSR_Result(WSR_Edge, true);
106  }
107  return WSR_Result(WSR_Inside, false);
108  }
109  return WSR_Result(WSR_Edge, false);
110  }
111 
112  void print_layer() const;
113 
114  // module & detid interface
115  void reserve_modules(int nm) { m_modules.reserve(nm); }
116  unsigned int register_module(ModuleInfo&& mi) {
117  unsigned int pos = m_modules.size();
118  m_modules.emplace_back(mi);
119  m_detid2sid[mi.detid] = pos;
120  return pos;
121  }
122  unsigned int shrink_modules() {
123  m_modules.shrink_to_fit();
124  return m_modules.size() - 1;
125  }
126 
127  unsigned int short_id(unsigned int detid) const { return m_detid2sid.at(detid); }
128  int n_modules() const { return m_modules.size(); }
129  const ModuleInfo& module_info(unsigned int sid) const { return m_modules[sid]; }
130 
131  private:
132  bool is_in_r_hole_no_check(float r) const { return r > m_hole_r_min && r < m_hole_r_max; }
133 
134  int m_layer_id = -1;
136  int m_subdet = -1; // sub-detector id, not used in core mkFit
137 
138  float m_rin = 0, m_rout = 0, m_zmin = 0, m_zmax = 0;
139  float m_propagate_to = 0;
140 
141  float m_q_bin = 0; // > 0 - bin width, < 0 - number of bins
142  float m_hole_r_min = 0, m_hole_r_max = 0; // This could be turned into std::function when needed.
143  bool m_has_r_range_hole = false;
144  bool m_is_stereo = false;
145  bool m_is_pixel = false;
146  bool m_has_charge = true;
147 
148  std::unordered_map<unsigned int, unsigned int> m_detid2sid;
149  std::vector<ModuleInfo> m_modules;
150  };
151 
152  //==============================================================================
153 
154  template <typename T>
155  class rectvec {
156  public:
157  rectvec(int n1 = 0, int n2 = 0) : m_n1(n1), m_n2(n2), m_vec(n1 * n2) {}
158 
159  void rerect(int n1, int n2) {
160  m_n1 = n1;
161  m_n2 = n2;
162  m_vec.resize(n1 * n2);
163  }
164 
165  const T& operator()(int i1, int i2) const { return m_vec[i1 * m_n2 + i2]; }
166  T& operator()(int i1, int i2) { return m_vec[i1 * m_n2 + i2]; }
167 
168  const T* operator[](int i1) const { return &m_vec[i1 * m_n2]; }
169  T* operator[](int i1) { return &m_vec[i1 * m_n2]; }
170 
171  const std::vector<T>& vector() const { return m_vec; }
172  std::vector<T>& vector() { return m_vec; }
173 
174  int n1() const { return m_n1; }
175  int n2() const { return m_n2; }
176  bool check_idcs(int i1, int i2) const { return i1 >= 0 && i1 < m_n1 && i2 >= 0 && i2 < m_n2; }
177 
178  private:
179  int m_n1, m_n2;
180  std::vector<T> m_vec;
181  };
182 
183  class TrackerInfo {
184  public:
185  enum EtaRegion {
194  };
195  struct Material {
196  float bbxi{0}, radl{0};
197  };
198 
199  void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg);
200  void create_layers(int n_brl, int n_ec_pos, int n_ec_neg);
204 
205  int n_layers() const { return m_layers.size(); }
206  const LayerInfo& layer(int l) const { return m_layers[l]; }
207  LayerInfo& layer_nc(int l) { return m_layers[l]; }
208 
209  int n_total_modules() const;
210 
211  const LayerInfo& operator[](int l) const { return m_layers[l]; }
212 
213  const LayerInfo& outer_barrel_layer() const { return m_layers[m_barrel.back()]; }
214 
215  const std::vector<int>& barrel_layers() const { return m_barrel; }
216  const std::vector<int>& endcap_pos_layers() const { return m_ecap_pos; }
217  const std::vector<int>& endcap_neg_layers() const { return m_ecap_neg; }
218 
219  const PropagationConfig& prop_config() const { return m_prop_config; }
221 
222  void write_bin_file(const std::string& fname) const;
223  void read_bin_file(const std::string& fname);
224  void print_tracker(int level) const;
225 
226  void create_material(int nBinZ, float rngZ, int nBinR, float rngR);
227  int mat_nbins_z() const { return m_mat_vec.n1(); }
228  int mat_nbins_r() const { return m_mat_vec.n2(); }
229  float mat_range_z() const { return m_mat_range_z; }
230  float mat_range_r() const { return m_mat_range_r; }
231  int mat_bin_z(float z) const { return z * m_mat_fac_z; }
232  int mat_bin_r(float r) const { return r * m_mat_fac_r; }
233  bool check_bins(int bz, int br) const { return m_mat_vec.check_idcs(bz, br); }
234 
235  float material_bbxi(int binZ, int binR) const { return m_mat_vec(binZ, binR).bbxi; }
236  float material_radl(int binZ, int binR) const { return m_mat_vec(binZ, binR).radl; }
237  float& material_bbxi(int binZ, int binR) { return m_mat_vec(binZ, binR).bbxi; }
238  float& material_radl(int binZ, int binR) { return m_mat_vec(binZ, binR).radl; }
239 
240  Material material_checked(float z, float r) const {
241  const int zbin = mat_bin_z(z), rbin = mat_bin_r(r);
242  return check_bins(zbin, rbin) ? m_mat_vec(zbin, rbin) : Material();
243  }
244 
245  private:
247 
248  std::vector<LayerInfo> m_layers;
249 
250  std::vector<int> m_barrel;
251  std::vector<int> m_ecap_pos;
252  std::vector<int> m_ecap_neg;
253 
257 
259  };
260 
261 } // end namespace mkfit
262 #endif
void set_is_stereo(bool s)
Definition: TrackerInfo.h:63
void rerect(int n1, int n2)
Definition: TrackerInfo.h:159
const std::vector< int > & barrel_layers() const
Definition: TrackerInfo.h:215
void extend_limits(float r, float z)
Definition: TrackerInfo.cc:33
float z_mean() const
Definition: TrackerInfo.h:73
const T & operator()(int i1, int i2) const
Definition: TrackerInfo.h:165
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:132
float rin() const
Definition: TrackerInfo.h:68
const std::vector< int > & endcap_pos_layers() const
Definition: TrackerInfo.h:216
float q_bin() const
Definition: TrackerInfo.h:75
T * operator[](int i1)
Definition: TrackerInfo.h:169
void set_r_hole_range(float rh1, float rh2)
Definition: TrackerInfo.cc:49
unsigned int short_id(unsigned int detid) const
Definition: TrackerInfo.h:127
std::vector< int > m_barrel
Definition: TrackerInfo.h:250
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:171
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:176
PropagationConfig & prop_config_nc()
Definition: TrackerInfo.h:220
std::vector< int > m_ecap_neg
Definition: TrackerInfo.h:252
LayerInfo & new_ecap_neg_layer()
Definition: TrackerInfo.cc:103
float propagate_to() const
Definition: TrackerInfo.h:74
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:211
bool is_pixel() const
Definition: TrackerInfo.h:79
WSR_Result(WithinSensitiveRegion_e wsr, bool in_gap)
Definition: TrackerInfo.h:26
LayerInfo & layer_nc(int l)
Definition: TrackerInfo.h:207
const LayerInfo & outer_barrel_layer() const
Definition: TrackerInfo.h:213
T & operator()(int i1, int i2)
Definition: TrackerInfo.h:166
float zmax() const
Definition: TrackerInfo.h:72
std::vector< ModuleInfo > m_modules
Definition: TrackerInfo.h:149
PropagationConfig m_prop_config
Definition: TrackerInfo.h:258
bool is_in_r_hole(float r) const
Definition: TrackerInfo.h:87
WSR_Result is_within_z_sensitive_region(float z, float dz) const
Definition: TrackerInfo.h:89
int mat_nbins_r() const
Definition: TrackerInfo.h:228
const std::vector< int > & endcap_neg_layers() const
Definition: TrackerInfo.h:217
std::vector< T > m_vec
Definition: TrackerInfo.h:180
bool is_within_z_limits(float z) const
Definition: TrackerInfo.h:83
float zmin() const
Definition: TrackerInfo.h:71
float material_radl(int binZ, int binR) const
Definition: TrackerInfo.h:236
int n1() const
Definition: TrackerInfo.h:174
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:129
void set_layer_type(LayerType_e t)
Definition: TrackerInfo.h:54
bool is_within_q_limits(float q) const
Definition: TrackerInfo.h:85
int n_layers() const
Definition: TrackerInfo.h:205
int mat_bin_z(float z) const
Definition: TrackerInfo.h:231
LayerInfo & new_ecap_pos_layer()
Definition: TrackerInfo.cc:98
LayerType_e layer_type() const
Definition: TrackerInfo.h:67
float mat_range_z() const
Definition: TrackerInfo.h:229
int layer_id() const
Definition: TrackerInfo.h:66
unsigned int register_module(ModuleInfo &&mi)
Definition: TrackerInfo.h:116
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:233
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:97
float & material_bbxi(int binZ, int binR)
Definition: TrackerInfo.h:237
int n_modules() const
Definition: TrackerInfo.h:128
float mat_range_r() const
Definition: TrackerInfo.h:230
int mat_bin_r(float r) const
Definition: TrackerInfo.h:232
void reserve_modules(int nm)
Definition: TrackerInfo.h:115
const LayerInfo & layer(int l) const
Definition: TrackerInfo.h:206
const T * operator[](int i1) const
Definition: TrackerInfo.h:168
float & material_radl(int binZ, int binR)
Definition: TrackerInfo.h:238
int n2() const
Definition: TrackerInfo.h:175
rectvec< Material > m_mat_vec
Definition: TrackerInfo.h:256
bool is_stereo() const
Definition: TrackerInfo.h:80
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
void set_has_charge(bool c)
Definition: TrackerInfo.h:64
rectvec(int n1=0, int n2=0)
Definition: TrackerInfo.h:157
WithinSensitiveRegion_e m_wsr
Definition: TrackerInfo.h:21
float r_mean() const
Definition: TrackerInfo.h:70
void print_tracker(int level) const
Definition: TrackerInfo.cc:275
float material_bbxi(int binZ, int binR) const
Definition: TrackerInfo.h:235
bool is_within_r_limits(float r) const
Definition: TrackerInfo.h:84
bool has_charge() const
Definition: TrackerInfo.h:81
float rout() const
Definition: TrackerInfo.h:69
std::vector< int > m_ecap_pos
Definition: TrackerInfo.h:251
string fname
main script
LayerType_e m_layer_type
Definition: TrackerInfo.h:135
int subdet() const
Definition: TrackerInfo.h:77
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:148
Material material_checked(float z, float r) const
Definition: TrackerInfo.h:240
WithinSensitiveRegion_e
Definition: TrackerInfo.h:17
ModuleInfo()=default
std::vector< T > & vector()
Definition: TrackerInfo.h:172
unsigned int shrink_modules()
Definition: TrackerInfo.h:122
long double T
int mat_nbins_z() const
Definition: TrackerInfo.h:227
std::vector< LayerInfo > m_layers
Definition: TrackerInfo.h:248
bool is_barrel() const
Definition: TrackerInfo.h:78
const PropagationConfig & prop_config() const
Definition: TrackerInfo.h:219
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