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 
5 #include <string>
6 #include <vector>
7 
8 namespace mkfit {
9 
11 
12  struct WSR_Result {
13  // Could also store XHitSize count equivalent here : 16;
15  bool m_in_gap : 8;
16 
18 
19  WSR_Result(WithinSensitiveRegion_e wsr, bool in_gap) : m_wsr(wsr), m_in_gap(in_gap) {}
20  };
21 
22  //==============================================================================
23 
24  struct ModuleInfo {
28  unsigned int detid;
29 
30  ModuleInfo() = default;
31  ModuleInfo(SVector3 p, SVector3 zd, SVector3 xd, unsigned int id) : pos(p), zdir(zd), xdir(xd), detid(id) {}
32  };
33 
34  //==============================================================================
35 
36  class LayerInfo {
37  friend class TrackerInfo;
38 
39  public:
40  enum LayerType_e { Undef = -1, Barrel = 0, EndCapPos = 1, EndCapNeg = 2 };
41 
42  LayerInfo() = default;
44 
46  void set_limits(float r1, float r2, float z1, float z2);
47  void extend_limits(float r, float z);
48  void set_r_in_out(float r1, float r2);
49  void set_propagate_to(float pto) { m_propagate_to = pto; }
50  void set_r_hole_range(float rh1, float rh2);
51  void set_q_bin(float qb) { m_q_bin = qb; }
52  void set_subdet(int sd) { m_subdet = sd; }
53  void set_is_pixel(bool p) { m_is_pixel = p; }
54  void set_is_stereo(bool s) { m_is_stereo = s; }
55 
56  int layer_id() const { return m_layer_id; }
57  LayerType_e layer_type() const { return m_layer_type; }
58  float rin() const { return m_rin; }
59  float rout() const { return m_rout; }
60  float r_mean() const { return 0.5f * (m_rin + m_rout); }
61  float zmin() const { return m_zmin; }
62  float zmax() const { return m_zmax; }
63  float z_mean() const { return 0.5f * (m_zmin + m_zmax); }
64  float propagate_to() const { return m_propagate_to; }
65  float q_bin() const { return m_q_bin; }
66 
67  int subdet() const { return m_subdet; }
68  bool is_barrel() const { return m_layer_type == Barrel; }
69  bool is_pixel() const { return m_is_pixel; }
70  bool is_stereo() const { return m_is_stereo; }
71 
72  bool is_within_z_limits(float z) const { return z > m_zmin && z < m_zmax; }
73  bool is_within_r_limits(float r) const { return r > m_rin && r < m_rout; }
74  bool is_within_q_limits(float q) const { return is_barrel() ? is_within_z_limits(q) : is_within_r_limits(q); }
75 
76  bool is_in_r_hole(float r) const { return m_has_r_range_hole ? is_in_r_hole_no_check(r) : false; }
77 
79  if (z > m_zmax + dz || z < m_zmin - dz)
80  return WSR_Result(WSR_Outside, false);
81  if (z < m_zmax - dz && z > m_zmin + dz)
82  return WSR_Result(WSR_Inside, false);
83  return WSR_Result(WSR_Edge, false);
84  }
85 
87  if (r > m_rout + dr || r < m_rin - dr)
88  return WSR_Result(WSR_Outside, false);
89  if (r < m_rout - dr && r > m_rin + dr) {
90  if (m_has_r_range_hole) {
91  if (r < m_hole_r_max - dr && r > m_hole_r_min + dr)
92  return WSR_Result(WSR_Outside, true);
93  if (r < m_hole_r_max + dr && r > m_hole_r_min - dr)
94  return WSR_Result(WSR_Edge, true);
95  }
96  return WSR_Result(WSR_Inside, false);
97  }
98  return WSR_Result(WSR_Edge, false);
99  }
100 
101  void print_layer() const;
102 
103  // module & detid interface
104  void reserve_modules(int nm) { m_modules.reserve(nm); }
105  unsigned int register_module(ModuleInfo&& mi) {
106  unsigned int pos = m_modules.size();
107  m_modules.emplace_back(mi);
108  m_detid2sid[mi.detid] = pos;
109  return pos;
110  }
111  unsigned int shrink_modules() {
112  m_modules.shrink_to_fit();
113  return m_modules.size() - 1;
114  }
115 
116  unsigned int short_id(unsigned int detid) const { return m_detid2sid.at(detid); }
117  int n_modules() const { return m_modules.size(); }
118  const ModuleInfo& module_info(unsigned int sid) const { return m_modules[sid]; }
119 
120  private:
121  bool is_in_r_hole_no_check(float r) const { return r > m_hole_r_min && r < m_hole_r_max; }
122 
123  int m_layer_id = -1;
125  int m_subdet = -1; // sub-detector id, not used in core mkFit
126 
127  float m_rin = 0, m_rout = 0, m_zmin = 0, m_zmax = 0;
128  float m_propagate_to = 0;
129 
130  float m_q_bin = 0; // > 0 - bin width, < 0 - number of bins
131  float m_hole_r_min = 0, m_hole_r_max = 0; // This could be turned into std::function when needed.
132  bool m_has_r_range_hole = false;
133  bool m_is_stereo = false;
134  bool m_is_pixel = false;
135 
136  std::unordered_map<unsigned int, unsigned int> m_detid2sid;
137  std::vector<ModuleInfo> m_modules;
138  };
139 
140  //==============================================================================
141 
142  class TrackerInfo {
143  public:
144  enum EtaRegion {
153  };
154 
155  void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg);
156  void create_layers(int n_brl, int n_ec_pos, int n_ec_neg);
160 
161  int n_layers() const { return m_layers.size(); }
162  const LayerInfo& layer(int l) const { return m_layers[l]; }
163  LayerInfo& layer_nc(int l) { return m_layers[l]; }
164 
165  int n_total_modules() const;
166 
167  const LayerInfo& operator[](int l) const { return m_layers[l]; }
168 
169  const LayerInfo& outer_barrel_layer() const { return m_layers[m_barrel.back()]; }
170 
171  const std::vector<int>& barrel_layers() const { return m_barrel; }
172  const std::vector<int>& endcap_pos_layers() const { return m_ecap_pos; }
173  const std::vector<int>& endcap_neg_layers() const { return m_ecap_neg; }
174 
175  void write_bin_file(const std::string& fname) const;
176  void read_bin_file(const std::string& fname);
177  void print_tracker(int level) const;
178 
179  private:
181 
182  std::vector<LayerInfo> m_layers;
183 
184  std::vector<int> m_barrel;
185  std::vector<int> m_ecap_pos;
186  std::vector<int> m_ecap_neg;
187  };
188 
189 } // end namespace mkfit
190 #endif
void set_is_stereo(bool s)
Definition: TrackerInfo.h:54
const std::vector< int > & barrel_layers() const
Definition: TrackerInfo.h:171
void extend_limits(float r, float z)
Definition: TrackerInfo.cc:15
float z_mean() const
Definition: TrackerInfo.h:63
void read_bin_file(const std::string &fname)
Definition: TrackerInfo.cc:168
bool is_in_r_hole_no_check(float r) const
Definition: TrackerInfo.h:121
float rin() const
Definition: TrackerInfo.h:58
const std::vector< int > & endcap_pos_layers() const
Definition: TrackerInfo.h:172
float q_bin() const
Definition: TrackerInfo.h:65
void set_r_hole_range(float rh1, float rh2)
Definition: TrackerInfo.cc:31
unsigned int short_id(unsigned int detid) const
Definition: TrackerInfo.h:116
std::vector< int > m_barrel
Definition: TrackerInfo.h:184
void set_q_bin(float qb)
Definition: TrackerInfo.h:51
void print_layer() const
Definition: TrackerInfo.cc:37
LayerInfo & new_barrel_layer()
Definition: TrackerInfo.cc:75
ROOT::Math::SVector< float, 3 > SVector3
Definition: MatrixSTypes.h:14
std::vector< int > m_ecap_neg
Definition: TrackerInfo.h:186
LayerInfo & new_ecap_neg_layer()
Definition: TrackerInfo.cc:85
float propagate_to() const
Definition: TrackerInfo.h:64
unsigned int detid
Definition: TrackerInfo.h:28
void set_r_in_out(float r1, float r2)
Definition: TrackerInfo.cc:26
const LayerInfo & operator[](int l) const
Definition: TrackerInfo.h:167
bool is_pixel() const
Definition: TrackerInfo.h:69
WSR_Result(WithinSensitiveRegion_e wsr, bool in_gap)
Definition: TrackerInfo.h:19
LayerInfo & layer_nc(int l)
Definition: TrackerInfo.h:163
const LayerInfo & outer_barrel_layer() const
Definition: TrackerInfo.h:169
float zmax() const
Definition: TrackerInfo.h:62
std::vector< ModuleInfo > m_modules
Definition: TrackerInfo.h:137
bool is_in_r_hole(float r) const
Definition: TrackerInfo.h:76
WSR_Result is_within_z_sensitive_region(float z, float dz) const
Definition: TrackerInfo.h:78
const std::vector< int > & endcap_neg_layers() const
Definition: TrackerInfo.h:173
bool is_within_z_limits(float z) const
Definition: TrackerInfo.h:72
float zmin() const
Definition: TrackerInfo.h:61
void set_limits(float r1, float r2, float z1, float z2)
Definition: TrackerInfo.cc:8
const ModuleInfo & module_info(unsigned int sid) const
Definition: TrackerInfo.h:118
void set_layer_type(LayerType_e t)
Definition: TrackerInfo.h:45
bool is_within_q_limits(float q) const
Definition: TrackerInfo.h:74
int n_layers() const
Definition: TrackerInfo.h:161
LayerInfo & new_ecap_pos_layer()
Definition: TrackerInfo.cc:80
LayerType_e layer_type() const
Definition: TrackerInfo.h:57
int layer_id() const
Definition: TrackerInfo.h:56
unsigned int register_module(ModuleInfo &&mi)
Definition: TrackerInfo.h:105
int new_layer(LayerInfo::LayerType_e type)
Definition: TrackerInfo.cc:69
void set_is_pixel(bool p)
Definition: TrackerInfo.h:53
void create_layers(int n_brl, int n_ec_pos, int n_ec_neg)
Definition: TrackerInfo.cc:59
LayerInfo()=default
WSR_Result is_within_r_sensitive_region(float r, float dr) const
Definition: TrackerInfo.h:86
int n_modules() const
Definition: TrackerInfo.h:117
void reserve_modules(int nm)
Definition: TrackerInfo.h:104
const LayerInfo & layer(int l) const
Definition: TrackerInfo.h:162
bool is_stereo() const
Definition: TrackerInfo.h:70
int n_total_modules() const
Definition: TrackerInfo.cc:90
WithinSensitiveRegion_e m_wsr
Definition: TrackerInfo.h:14
float r_mean() const
Definition: TrackerInfo.h:60
void print_tracker(int level) const
Definition: TrackerInfo.cc:237
bool is_within_r_limits(float r) const
Definition: TrackerInfo.h:73
float rout() const
Definition: TrackerInfo.h:59
std::vector< int > m_ecap_pos
Definition: TrackerInfo.h:185
string fname
main script
LayerType_e m_layer_type
Definition: TrackerInfo.h:124
int subdet() const
Definition: TrackerInfo.h:67
LayerInfo(int lid, LayerType_e type)
Definition: TrackerInfo.h:43
void set_propagate_to(float pto)
Definition: TrackerInfo.h:49
void write_bin_file(const std::string &fname) const
Definition: TrackerInfo.cc:142
std::unordered_map< unsigned int, unsigned int > m_detid2sid
Definition: TrackerInfo.h:136
ModuleInfo(SVector3 p, SVector3 zd, SVector3 xd, unsigned int id)
Definition: TrackerInfo.h:31
WithinSensitiveRegion_e
Definition: TrackerInfo.h:10
ModuleInfo()=default
unsigned int shrink_modules()
Definition: TrackerInfo.h:111
std::vector< LayerInfo > m_layers
Definition: TrackerInfo.h:182
bool is_barrel() const
Definition: TrackerInfo.h:68
void set_subdet(int sd)
Definition: TrackerInfo.h:52
void reserve_layers(int n_brl, int n_ec_pos, int n_ec_neg)
Definition: TrackerInfo.cc:52