CMS 3D CMS Logo

HitStructures.h
Go to the documentation of this file.
1 #ifndef RecoTracker_MkFitCore_interface_HitStructures_h
2 #define RecoTracker_MkFitCore_interface_HitStructures_h
3 
10 
11 namespace mkfit {
12 
13  class IterationParams;
14 
15  //==============================================================================
16  // LayerOfHits
17  //==============================================================================
18 
19  // Note: the same code is used for barrel and endcap. In barrel the longitudinal
20  // bins are in Z and in endcap they are in R -- here this coordinate is called Q.
21 
22  // When COPY_SORTED_HITS is not defined, hits are accessed from the original hit
23  // vector and only sort ranks are kept for proper access.
24  // #define COPY_SORTED_HITS
25 
26  class LayerOfHits {
27  public:
28  using bin_index_t = unsigned short;
29  using bin_content_t = unsigned int;
33 
34  // Initializator
35 
36  struct Initializator {
38  float m_qmin, m_qmax;
39  unsigned int m_nq;
40 
41  void setup(float qmin, float qmax, float dq);
42 
43  Initializator(const LayerInfo& li, float qmin, float qmax, unsigned int nq);
44  Initializator(const LayerInfo& li, float qmin, float qmax, float dq);
45  Initializator(const LayerInfo& li);
46  };
47 
48  // Constructor
49 
51 
52  ~LayerOfHits();
53 
54  // Setup and filling
55  //-------------------
56 
57  void reset();
58 
59  // Get in all hits from given hit-vec
60  void suckInHits(const HitVec& hitv);
61 
62  // Get in all dead regions from given dead-vec
63  void suckInDeads(const DeadVec& deadv);
64 
65  // Use external hit-vec and only use hits that are passed to me.
66  void beginRegistrationOfHits(const HitVec& hitv);
67  void registerHit(unsigned int idx);
68  void endRegistrationOfHits(bool build_original_to_internal_map);
69 
70  unsigned int nHits() const { return m_n_hits; }
71 
72  // Bin access / queries
73  //----------------------
74  bin_index_t qBin(float q) const { return m_ax_eta.from_R_to_N_bin(q); }
76 
77  // if you don't pass phi in (-pi, +pi), mask away the upper bits using m_phi_mask or use the Checked version.
78  bin_index_t phiBin(float phi) const { return m_ax_phi.from_R_to_N_bin(phi); }
79  bin_index_t phiBinChecked(float phi) const { return m_ax_phi.from_R_to_N_bin_safe(phi); }
80 
82 
83  binnor_t::C_pair phiQBinContent(bin_index_t pi, bin_index_t qi) const { return m_binnor.get_content(pi, qi); }
84 
85  bool isBinDead(bin_index_t pi, bin_index_t qi) const { return m_dead_bins[qi * m_ax_phi.size_of_N() + pi]; }
86 
87  struct HitInfo {
88  float phi;
89  float q;
91  float qbar;
92  };
93  const HitInfo& hit_info(unsigned int i) const { return m_hit_infos[i]; }
94  float hit_phi(unsigned int i) const { return m_hit_infos[i].phi; }
95  float hit_q(unsigned int i) const { return m_hit_infos[i].q; }
96  float hit_q_half_length(unsigned int i) const { return m_hit_infos[i].q_half_length; }
97  float hit_qbar(unsigned int i) const { return m_hit_infos[i].qbar; }
98 
99  // Use this to map original indices to sorted internal ones. m_ext_idcs needs to be initialized.
100  unsigned int getHitIndexFromOriginal(unsigned int i) const { return m_ext_idcs[i - m_min_ext_idx]; }
101  // Use this to remap internal hit index to external one.
102  unsigned int getOriginalHitIndex(unsigned int i) const { return m_binnor.m_ranks[i]; }
103 
104 #ifdef COPY_SORTED_HITS
105  const Hit& refHit(int i) const { return m_hits[i]; }
106  const Hit* hitArray() const { return m_hits; }
107 #else
108  const Hit& refHit(int i) const { return (*m_ext_hits)[i]; }
109  const Hit* hitArray() const { return m_ext_hits->data(); }
110 #endif
111 
112  void printBins();
113 
114  // Geometry / LayerInfo accessors
115  //--------------------------------
116 
117  const LayerInfo& layer_info() const { return *m_layer_info; }
118  int layer_id() const { return m_layer_info->layer_id(); }
119 
120  bool is_barrel() const { return m_is_barrel; }
121  bool is_endcap() const { return !m_is_barrel; }
122 
123  bool is_within_z_limits(float z) const { return m_layer_info->is_within_z_limits(z); }
124  bool is_within_r_limits(float r) const { return m_layer_info->is_within_r_limits(r); }
125 
128  }
129 
130  WSR_Result is_within_r_sensitive_region(float r, float dr) const {
132  }
133 
134  bool is_stereo() const { return m_layer_info->is_stereo(); }
135  bool is_pixel() const { return m_layer_info->is_pixel(); }
136  int subdet() const { return m_layer_info->subdet(); }
137 
138  private:
142 
143 #ifdef COPY_SORTED_HITS
144  void alloc_hits(int size);
145  void free_hits()
146 
147  Hit* m_hits = nullptr;
148  int m_capacity = 0;
149 #else
151 #endif
152  unsigned int* m_hit_ranks = nullptr; // allocated by IceSort via new []
153  std::vector<unsigned int> m_ext_idcs;
155  unsigned int m_n_hits = 0;
156 
157  // Bin information for dead regions
158  std::vector<bool> m_dead_bins;
159 
160  // Geometry / q-binning constants - initialized in setupLayer()
161  const LayerInfo* m_layer_info = nullptr;
163 
164  // Cached hit phi, q and qbar values to minimize Hit memory access
165  std::vector<HitInfo> m_hit_infos;
166  };
167 
168  //==============================================================================
169 
170  class EventOfHits {
171  public:
172  EventOfHits(const TrackerInfo& trk_inf);
173 
174  void reset() {
175  for (auto& i : m_layers_of_hits) {
176  i.reset();
177  }
178  }
179 
180  void suckInHits(int layer, const HitVec& hitv) { m_layers_of_hits[layer].suckInHits(hitv); }
181 
182  void suckInDeads(int layer, const DeadVec& deadv) { m_layers_of_hits[layer].suckInDeads(deadv); }
183 
184  const BeamSpot& refBeamSpot() const { return m_beam_spot; }
185  void setBeamSpot(const BeamSpot& bs) { m_beam_spot = bs; }
186 
187  int nLayers() const { return m_n_layers; }
188 
190  const LayerOfHits& operator[](int i) const { return m_layers_of_hits[i]; }
191 
192  private:
193  std::vector<LayerOfHits> m_layers_of_hits;
196  };
197 
198 } // end namespace mkfit
199 #endif
void endRegistrationOfHits(bool build_original_to_internal_map)
const LayerOfHits & operator[](int i) const
unsigned int getOriginalHitIndex(unsigned int i) const
void setup(float qmin, float qmax, float dq)
const BeamSpot & refBeamSpot() const
bool is_within_r_limits(float r) const
unsigned int m_n_hits
const HitInfo & hit_info(unsigned int i) const
Definition: HitStructures.h:93
bool is_stereo() const
WSR_Result is_within_r_sensitive_region(float r, float dr) const
bin_index_t qBinChecked(float q) const
Definition: HitStructures.h:75
const Hit * hitArray() const
const HitVec * m_ext_hits
C_pair get_content(B_pair n_bin) const
Definition: binnor.h:240
bool is_pixel() const
int nLayers() const
unsigned int m_min_ext_idx
bool is_pixel() const
Definition: TrackerInfo.h:106
const Double_t pi
WSR_Result is_within_z_sensitive_region(float z, float dz) const
Definition: TrackerInfo.h:116
unsigned int nHits() const
Definition: HitStructures.h:70
std::vector< C > m_ranks
Definition: binnor.h:211
bool is_within_z_limits(float z) const
Definition: TrackerInfo.h:110
I from_R_to_N_bin_safe(R r) const
Definition: binnor.h:103
bin_index_t phiBin(float phi) const
Definition: HitStructures.h:78
bin_index_t phiBinChecked(float phi) const
Definition: HitStructures.h:79
void setBeamSpot(const BeamSpot &bs)
unsigned int * m_hit_ranks
LayerOfHits & operator[](int i)
unsigned int bin_content_t
Definition: HitStructures.h:29
int layer_id() const
Definition: TrackerInfo.h:93
void suckInDeads(const DeadVec &deadv)
float hit_qbar(unsigned int i) const
Definition: HitStructures.h:97
WSR_Result is_within_r_sensitive_region(float r, float dr) const
Definition: TrackerInfo.h:124
I from_R_to_N_bin(R r) const
Definition: binnor.h:62
binnor_t::C_pair phiQBinContent(bin_index_t pi, bin_index_t qi) const
Definition: HitStructures.h:83
std::vector< bool > m_dead_bins
std::vector< Hit > HitVec
bool isBinDead(bin_index_t pi, bin_index_t qi) const
Definition: HitStructures.h:85
bool is_stereo() const
Definition: TrackerInfo.h:107
WSR_Result is_within_z_sensitive_region(float z, float dz) const
Initializator(const LayerInfo &li, float qmin, float qmax, unsigned int nq)
std::vector< DeadRegion > DeadVec
Definition: DeadRegion.h:11
bin_index_t qBin(float q) const
Definition: HitStructures.h:74
LayerOfHits(const LayerOfHits::Initializator &i)
void suckInHits(int layer, const HitVec &hitv)
bool is_within_r_limits(float r) const
Definition: TrackerInfo.h:111
unsigned int size_of_N() const
Definition: binnor.h:88
unsigned int m_max_ext_idx
float hit_q(unsigned int i) const
Definition: HitStructures.h:95
void suckInHits(const HitVec &hitv)
void beginRegistrationOfHits(const HitVec &hitv)
EventOfHits(const TrackerInfo &trk_inf)
int subdet() const
Definition: TrackerInfo.h:104
unsigned int getHitIndexFromOriginal(unsigned int i) const
static constexpr I c_N_mask
Definition: binnor.h:98
std::vector< unsigned int > m_ext_idcs
bool is_barrel() const
int layer_id() const
void registerHit(unsigned int idx)
const LayerInfo * m_layer_info
bool is_endcap() const
const LayerInfo & layer_info() const
unsigned short bin_index_t
Definition: HitStructures.h:28
float hit_phi(unsigned int i) const
Definition: HitStructures.h:94
bin_index_t phiMaskApply(bin_index_t in) const
Definition: HitStructures.h:81
void suckInDeads(int layer, const DeadVec &deadv)
std::vector< LayerOfHits > m_layers_of_hits
std::vector< HitInfo > m_hit_infos
I from_R_to_N_bin_safe(R r) const
Definition: binnor.h:65
const Hit & refHit(int i) const
float hit_q_half_length(unsigned int i) const
Definition: HitStructures.h:96
bool is_within_z_limits(float z) const
int subdet() const