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