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