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 ModuleShape {
32  float dx1; // half-extent along x (bottom edge for trap)
33  float dx2; // 0 for rect; half-extent along x, top edge for trap
34  float dy; // half extent along y / less precise direction
35  float dz; // half thickness in z
36 
37  // round to 1 mum precision
38  float rmu(float x) { return std::round(1e4f * x) * 1e-4f; }
39  void round_assign(float x1, float x2, float y, float z) {
40  dx1 = rmu(x1);
41  dx2 = rmu(x2);
42  dy = rmu(y);
43  dz = rmu(z);
44  }
45 
46  bool is_rect() const { return dx2 == 0.f; }
47  bool is_trap() const { return dx2 != 0.f; }
48 
49  bool operator==(const ModuleShape& s) const { return dx1 == s.dx1 && dx2 == s.dx2 && dy == s.dy && dz == s.dz; }
50  };
51 
52  struct ModuleInfo {
54  SVector3 zdir; // normal to module plane
55  SVector3 xdir; // the precise / "phi" direction
56  unsigned int detid;
57  unsigned short shapeid;
58 
59  ModuleInfo() = default;
60  ModuleInfo(SVector3 p, SVector3 zd, SVector3 xd, unsigned int did, unsigned short sid)
61  : pos(p), zdir(zd), xdir(xd), detid(did), shapeid(sid) {}
62 
63  SVector3 calc_ydir() const {
64  return {zdir[1] * xdir[2] - zdir[2] * xdir[1],
65  zdir[2] * xdir[0] - zdir[0] * xdir[2],
66  zdir[0] * zdir[1] - zdir[1] * xdir[0]};
67  }
68  };
69 
70  //==============================================================================
71 
72  class LayerInfo {
73  friend class TrackerInfo;
74 
75  public:
76  enum LayerType_e { Undef = -1, Barrel = 0, EndCapPos = 1, EndCapNeg = 2 };
77 
78  LayerInfo() = default;
80 
82  void set_limits(float r1, float r2, float z1, float z2);
83  void extend_limits(float r, float z);
84  void set_r_in_out(float r1, float r2);
85  void set_propagate_to(float pto) { m_propagate_to = pto; }
86  void set_r_hole_range(float rh1, float rh2);
87  void set_q_bin(float qb) { m_q_bin = qb; }
88  void set_subdet(int sd) { m_subdet = sd; }
89  void set_is_pixel(bool p) { m_is_pixel = p; }
90  void set_is_stereo(bool s) { m_is_stereo = s; }
91  void set_has_charge(bool c) { m_has_charge = c; }
92 
93  int layer_id() const { return m_layer_id; }
94  LayerType_e layer_type() const { return m_layer_type; }
95  float rin() const { return m_rin; }
96  float rout() const { return m_rout; }
97  float r_mean() const { return 0.5f * (m_rin + m_rout); }
98  float zmin() const { return m_zmin; }
99  float zmax() const { return m_zmax; }
100  float z_mean() const { return 0.5f * (m_zmin + m_zmax); }
101  float propagate_to() const { return m_propagate_to; }
102  float q_bin() const { return m_q_bin; }
103 
104  int subdet() const { return m_subdet; }
105  bool is_barrel() const { return m_layer_type == Barrel; }
106  bool is_pixel() const { return m_is_pixel; }
107  bool is_stereo() const { return m_is_stereo; }
108  bool has_charge() const { return m_has_charge; }
109 
110  bool is_within_z_limits(float z) const { return z > m_zmin && z < m_zmax; }
111  bool is_within_r_limits(float r) const { return r > m_rin && r < m_rout; }
112  bool is_within_q_limits(float q) const { return is_barrel() ? is_within_z_limits(q) : is_within_r_limits(q); }
113 
114  bool is_in_r_hole(float r) const { return m_has_r_range_hole ? is_in_r_hole_no_check(r) : false; }
115 
117  if (z > m_zmax + dz || z < m_zmin - dz)
118  return WSR_Result(WSR_Outside, false);
119  if (z < m_zmax - dz && z > m_zmin + dz)
120  return WSR_Result(WSR_Inside, false);
121  return WSR_Result(WSR_Edge, false);
122  }
123 
125  if (r > m_rout + dr || r < m_rin - dr)
126  return WSR_Result(WSR_Outside, false);
127  if (r < m_rout - dr && r > m_rin + dr) {
128  if (m_has_r_range_hole) {
129  if (r < m_hole_r_max - dr && r > m_hole_r_min + dr)
130  return WSR_Result(WSR_Outside, true);
131  if (r < m_hole_r_max + dr && r > m_hole_r_min - dr)
132  return WSR_Result(WSR_Edge, true);
133  }
134  return WSR_Result(WSR_Inside, false);
135  }
136  return WSR_Result(WSR_Edge, false);
137  }
138 
139  void print_layer() const;
140 
141  // module & detid interface
142  void reserve_modules(int nm) { m_modules.reserve(nm); }
143  unsigned int register_module(ModuleInfo&& mi) {
144  unsigned int pos = m_modules.size();
145  m_modules.emplace_back(mi);
146  m_detid2sid[mi.detid] = pos;
147  return pos;
148  }
149  unsigned int shrink_modules() {
150  m_modules.shrink_to_fit();
151  return m_modules.size() - 1;
152  }
153 
154  void resize_shapes(int ns) { m_shapes.resize(ns); }
155  void register_shape(const ModuleShape& ms, unsigned short sid) { m_shapes[sid] = ms; }
156 
157  unsigned int short_id(unsigned int detid) const { return m_detid2sid.at(detid); }
158  int n_modules() const { return m_modules.size(); }
159  int n_shapes() const { return m_shapes.size(); }
160  const ModuleInfo& module_info(unsigned int sid) const { return m_modules[sid]; }
161  const ModuleShape& module_shape(unsigned short msid) const { return m_shapes[msid]; }
162 
163  private:
164  bool is_in_r_hole_no_check(float r) const { return r > m_hole_r_min && r < m_hole_r_max; }
165 
166  int m_layer_id = -1;
168  int m_subdet = -1; // sub-detector id, not used in core mkFit
169 
170  float m_rin = 0, m_rout = 0, m_zmin = 0, m_zmax = 0;
171  float m_propagate_to = 0;
172 
173  float m_q_bin = 0; // > 0 - bin width, < 0 - number of bins
174  float m_hole_r_min = 0, m_hole_r_max = 0; // This could be turned into std::function when needed.
175  bool m_has_r_range_hole = false;
176  bool m_is_stereo = false;
177  bool m_is_pixel = false;
178  bool m_has_charge = true;
179  // NOTE: offset of the last element is used in write/read_bin file.
181 
182  std::unordered_map<unsigned int, unsigned int> m_detid2sid;
183  std::vector<ModuleInfo> m_modules;
184  std::vector<ModuleShape> m_shapes;
185  };
186 
187  //==============================================================================
188 
189  template <typename T>
190  class rectvec {
191  public:
192  rectvec(int n1 = 0, int n2 = 0) : m_n1(n1), m_n2(n2), m_vec(n1 * n2) {}
193 
194  void rerect(int n1, int n2) {
195  m_n1 = n1;
196  m_n2 = n2;
197  m_vec.resize(n1 * n2);
198  }
199 
200  const T& operator()(int i1, int i2) const { return m_vec[i1 * m_n2 + i2]; }
201  T& operator()(int i1, int i2) { return m_vec[i1 * m_n2 + i2]; }
202 
203  const T* operator[](int i1) const { return &m_vec[i1 * m_n2]; }
204  T* operator[](int i1) { return &m_vec[i1 * m_n2]; }
205 
206  const std::vector<T>& vector() const { return m_vec; }
207  std::vector<T>& vector() { return m_vec; }
208 
209  int n1() const { return m_n1; }
210  int n2() const { return m_n2; }
211  bool check_idcs(int i1, int i2) const { return i1 >= 0 && i1 < m_n1 && i2 >= 0 && i2 < m_n2; }
212 
213  private:
214  int m_n1, m_n2;
215  std::vector<T> m_vec;
216  };
217 
218  class TrackerInfo {
219  public:
220  enum EtaRegion {
229  };
230  struct Material {
231  float bbxi{0}, radl{0};
232  };
233 
234  void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg);
235  void create_layers(int n_brl, int n_ec_pos, int n_ec_neg);
239 
240  int n_layers() const { return m_layers.size(); }
241  const LayerInfo& layer(int l) const { return m_layers[l]; }
242  LayerInfo& layer_nc(int l) { return m_layers[l]; }
243 
244  int n_total_modules() const;
245 
246  const LayerInfo& operator[](int l) const { return m_layers[l]; }
247 
248  const LayerInfo& outer_barrel_layer() const { return m_layers[m_barrel.back()]; }
249 
250  const std::vector<int>& barrel_layers() const { return m_barrel; }
251  const std::vector<int>& endcap_pos_layers() const { return m_ecap_pos; }
252  const std::vector<int>& endcap_neg_layers() const { return m_ecap_neg; }
253 
254  const PropagationConfig& prop_config() const { return m_prop_config; }
256 
257  void write_bin_file(const std::string& fname) const;
258  void read_bin_file(const std::string& fname);
259  void print_tracker(int level, int precision = 3) const;
260 
261  void create_material(int nBinZ, float rngZ, int nBinR, float rngR);
262  int mat_nbins_z() const { return m_mat_vec.n1(); }
263  int mat_nbins_r() const { return m_mat_vec.n2(); }
264  float mat_range_z() const { return m_mat_range_z; }
265  float mat_range_r() const { return m_mat_range_r; }
266  int mat_bin_z(float z) const { return z * m_mat_fac_z; }
267  int mat_bin_r(float r) const { return r * m_mat_fac_r; }
268  bool check_bins(int bz, int br) const { return m_mat_vec.check_idcs(bz, br); }
269 
270  float material_bbxi(int binZ, int binR) const { return m_mat_vec(binZ, binR).bbxi; }
271  float material_radl(int binZ, int binR) const { return m_mat_vec(binZ, binR).radl; }
272  float& material_bbxi(int binZ, int binR) { return m_mat_vec(binZ, binR).bbxi; }
273  float& material_radl(int binZ, int binR) { return m_mat_vec(binZ, binR).radl; }
274 
275  Material material_checked(float z, float r) const {
276  const int zbin = mat_bin_z(z), rbin = mat_bin_r(r);
277  return check_bins(zbin, rbin) ? m_mat_vec(zbin, rbin) : Material();
278  }
279 
280  private:
282 
283  std::vector<LayerInfo> m_layers;
284 
285  std::vector<int> m_barrel;
286  std::vector<int> m_ecap_pos;
287  std::vector<int> m_ecap_neg;
288 
292 
294  };
295 
296 } // end namespace mkfit
297 #endif
void set_is_stereo(bool s)
Definition: TrackerInfo.h:90
SVector3 calc_ydir() const
Definition: TrackerInfo.h:63
void rerect(int n1, int n2)
Definition: TrackerInfo.h:194
unsigned short shapeid
Definition: TrackerInfo.h:57
ModuleInfo(SVector3 p, SVector3 zd, SVector3 xd, unsigned int did, unsigned short sid)
Definition: TrackerInfo.h:60
const std::vector< int > & barrel_layers() const
Definition: TrackerInfo.h:250
void extend_limits(float r, float z)
Definition: TrackerInfo.cc:33
float z_mean() const
Definition: TrackerInfo.h:100
const T & operator()(int i1, int i2) const
Definition: TrackerInfo.h:200
void read_bin_file(const std::string &fname)
Definition: TrackerInfo.cc:215
bool is_in_r_hole_no_check(float r) const
Definition: TrackerInfo.h:164
float rin() const
Definition: TrackerInfo.h:95
const std::vector< int > & endcap_pos_layers() const
Definition: TrackerInfo.h:251
float q_bin() const
Definition: TrackerInfo.h:102
T * operator[](int i1)
Definition: TrackerInfo.h:204
void set_r_hole_range(float rh1, float rh2)
Definition: TrackerInfo.cc:49
unsigned int short_id(unsigned int detid) const
Definition: TrackerInfo.h:157
std::vector< int > m_barrel
Definition: TrackerInfo.h:285
void set_q_bin(float qb)
Definition: TrackerInfo.h:87
void print_layer() const
Definition: TrackerInfo.cc:55
void resize_shapes(int ns)
Definition: TrackerInfo.h:154
const std::vector< T > & vector() const
Definition: TrackerInfo.h:206
LayerInfo & new_barrel_layer()
Definition: TrackerInfo.cc:93
bool operator==(const ModuleShape &s) const
Definition: TrackerInfo.h:49
ROOT::Math::SVector< float, 3 > SVector3
Definition: MatrixSTypes.h:14
bool check_idcs(int i1, int i2) const
Definition: TrackerInfo.h:211
void register_shape(const ModuleShape &ms, unsigned short sid)
Definition: TrackerInfo.h:155
PropagationConfig & prop_config_nc()
Definition: TrackerInfo.h:255
std::vector< int > m_ecap_neg
Definition: TrackerInfo.h:287
LayerInfo & new_ecap_neg_layer()
Definition: TrackerInfo.cc:103
float propagate_to() const
Definition: TrackerInfo.h:101
unsigned int detid
Definition: TrackerInfo.h:56
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:246
bool is_pixel() const
Definition: TrackerInfo.h:106
WSR_Result(WithinSensitiveRegion_e wsr, bool in_gap)
Definition: TrackerInfo.h:26
LayerInfo & layer_nc(int l)
Definition: TrackerInfo.h:242
const LayerInfo & outer_barrel_layer() const
Definition: TrackerInfo.h:248
int n_shapes() const
Definition: TrackerInfo.h:159
T & operator()(int i1, int i2)
Definition: TrackerInfo.h:201
float zmax() const
Definition: TrackerInfo.h:99
std::vector< ModuleInfo > m_modules
Definition: TrackerInfo.h:183
PropagationConfig m_prop_config
Definition: TrackerInfo.h:293
bool is_in_r_hole(float r) const
Definition: TrackerInfo.h:114
WSR_Result is_within_z_sensitive_region(float z, float dz) const
Definition: TrackerInfo.h:116
int mat_nbins_r() const
Definition: TrackerInfo.h:263
const std::vector< int > & endcap_neg_layers() const
Definition: TrackerInfo.h:252
std::vector< T > m_vec
Definition: TrackerInfo.h:215
bool is_within_z_limits(float z) const
Definition: TrackerInfo.h:110
float zmin() const
Definition: TrackerInfo.h:98
float material_radl(int binZ, int binR) const
Definition: TrackerInfo.h:271
int n1() const
Definition: TrackerInfo.h:209
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:160
bool m_final_member_for_streaming
Definition: TrackerInfo.h:180
void set_layer_type(LayerType_e t)
Definition: TrackerInfo.h:81
bool is_within_q_limits(float q) const
Definition: TrackerInfo.h:112
int n_layers() const
Definition: TrackerInfo.h:240
int mat_bin_z(float z) const
Definition: TrackerInfo.h:266
LayerInfo & new_ecap_pos_layer()
Definition: TrackerInfo.cc:98
LayerType_e layer_type() const
Definition: TrackerInfo.h:94
float rmu(float x)
Definition: TrackerInfo.h:38
float mat_range_z() const
Definition: TrackerInfo.h:264
int layer_id() const
Definition: TrackerInfo.h:93
unsigned int register_module(ModuleInfo &&mi)
Definition: TrackerInfo.h:143
int new_layer(LayerInfo::LayerType_e type)
Definition: TrackerInfo.cc:87
bool is_trap() const
Definition: TrackerInfo.h:47
double f[11][100]
void set_is_pixel(bool p)
Definition: TrackerInfo.h:89
bool check_bins(int bz, int br) const
Definition: TrackerInfo.h:268
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:124
float & material_bbxi(int binZ, int binR)
Definition: TrackerInfo.h:272
int n_modules() const
Definition: TrackerInfo.h:158
float mat_range_r() const
Definition: TrackerInfo.h:265
int mat_bin_r(float r) const
Definition: TrackerInfo.h:267
void reserve_modules(int nm)
Definition: TrackerInfo.h:142
const LayerInfo & layer(int l) const
Definition: TrackerInfo.h:241
const T * operator[](int i1) const
Definition: TrackerInfo.h:203
float & material_radl(int binZ, int binR)
Definition: TrackerInfo.h:273
int n2() const
Definition: TrackerInfo.h:210
rectvec< Material > m_mat_vec
Definition: TrackerInfo.h:291
bool is_stereo() const
Definition: TrackerInfo.h:107
int n_total_modules() const
Definition: TrackerInfo.cc:108
void set_has_charge(bool c)
Definition: TrackerInfo.h:91
rectvec(int n1=0, int n2=0)
Definition: TrackerInfo.h:192
WithinSensitiveRegion_e m_wsr
Definition: TrackerInfo.h:21
float r_mean() const
Definition: TrackerInfo.h:97
float material_bbxi(int binZ, int binR) const
Definition: TrackerInfo.h:270
const ModuleShape & module_shape(unsigned short msid) const
Definition: TrackerInfo.h:161
bool is_within_r_limits(float r) const
Definition: TrackerInfo.h:111
bool has_charge() const
Definition: TrackerInfo.h:108
float rout() const
Definition: TrackerInfo.h:96
std::vector< int > m_ecap_pos
Definition: TrackerInfo.h:286
string fname
main script
LayerType_e m_layer_type
Definition: TrackerInfo.h:167
int subdet() const
Definition: TrackerInfo.h:104
LayerInfo(int lid, LayerType_e type)
Definition: TrackerInfo.h:79
void set_propagate_to(float pto)
Definition: TrackerInfo.h:85
void print_tracker(int level, int precision=3) const
Definition: TrackerInfo.cc:273
void write_bin_file(const std::string &fname) const
Definition: TrackerInfo.cc:184
float x
std::unordered_map< unsigned int, unsigned int > m_detid2sid
Definition: TrackerInfo.h:182
Material material_checked(float z, float r) const
Definition: TrackerInfo.h:275
WithinSensitiveRegion_e
Definition: TrackerInfo.h:17
ModuleInfo()=default
std::vector< T > & vector()
Definition: TrackerInfo.h:207
unsigned int shrink_modules()
Definition: TrackerInfo.h:149
bool is_rect() const
Definition: TrackerInfo.h:46
long double T
std::vector< ModuleShape > m_shapes
Definition: TrackerInfo.h:184
int mat_nbins_z() const
Definition: TrackerInfo.h:262
std::vector< LayerInfo > m_layers
Definition: TrackerInfo.h:283
bool is_barrel() const
Definition: TrackerInfo.h:105
void round_assign(float x1, float x2, float y, float z)
Definition: TrackerInfo.h:39
const PropagationConfig & prop_config() const
Definition: TrackerInfo.h:254
void set_subdet(int sd)
Definition: TrackerInfo.h:88
void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg)
Definition: TrackerInfo.cc:70