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