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  struct HitInfo {
86  float phi;
87  float q;
89  float qbar;
90  };
91  const HitInfo& hit_info(unsigned int i) const { return m_hit_infos[i]; }
92  float hit_phi(unsigned int i) const { return m_hit_infos[i].phi; }
93  float hit_q(unsigned int i) const { return m_hit_infos[i].q; }
94  float hit_q_half_length(unsigned int i) const { return m_hit_infos[i].q_half_length; }
95  float hit_qbar(unsigned int i) const { return m_hit_infos[i].qbar; }
96 
97  // Use this to map original indices to sorted internal ones. m_ext_idcs needs to be initialized.
98  unsigned int getHitIndexFromOriginal(unsigned int i) const { return m_ext_idcs[i - m_min_ext_idx]; }
99  // Use this to remap internal hit index to external one.
100  unsigned int getOriginalHitIndex(unsigned int i) const { return m_binnor.m_ranks[i]; }
101 
102 #ifdef COPY_SORTED_HITS
103  const Hit& refHit(int i) const { return m_hits[i]; }
104  const Hit* hitArray() const { return m_hits; }
105 #else
106  const Hit& refHit(int i) const { return (*m_ext_hits)[i]; }
107  const Hit* hitArray() const { return m_ext_hits->data(); }
108 #endif
109 
110  void printBins();
111 
112  // Geometry / LayerInfo accessors
113  //--------------------------------
114 
115  const LayerInfo& layer_info() const { return *m_layer_info; }
116  int layer_id() const { return m_layer_info->layer_id(); }
117 
118  bool is_barrel() const { return m_is_barrel; }
119  bool is_endcap() const { return !m_is_barrel; }
120 
121  bool is_within_z_limits(float z) const { return m_layer_info->is_within_z_limits(z); }
122  bool is_within_r_limits(float r) const { return m_layer_info->is_within_r_limits(r); }
123 
126  }
127 
128  WSR_Result is_within_r_sensitive_region(float r, float dr) const {
130  }
131 
132  bool is_stereo() const { return m_layer_info->is_stereo(); }
133  bool is_pixel() const { return m_layer_info->is_pixel(); }
134  int subdet() const { return m_layer_info->subdet(); }
135 
136  private:
140 
141 #ifdef COPY_SORTED_HITS
142  void alloc_hits(int size);
143  void free_hits()
144 
145  Hit* m_hits = nullptr;
146  int m_capacity = 0;
147 #else
149 #endif
150  unsigned int* m_hit_ranks = nullptr; // allocated by IceSort via new []
151  std::vector<unsigned int> m_ext_idcs;
153  unsigned int m_n_hits = 0;
154 
155  // Bin information for dead regions
156  std::vector<bool> m_dead_bins;
157 
158  // Geometry / q-binning constants - initialized in setupLayer()
159  const LayerInfo* m_layer_info = nullptr;
161 
162  // Cached hit phi, q and qbar values to minimize Hit memory access
163  std::vector<HitInfo> m_hit_infos;
164  };
165 
166  //==============================================================================
167 
168  class EventOfHits {
169  public:
170  EventOfHits(const TrackerInfo& trk_inf);
171 
172  void reset() {
173  for (auto& i : m_layers_of_hits) {
174  i.reset();
175  }
176  }
177 
178  void suckInHits(int layer, const HitVec& hitv) { m_layers_of_hits[layer].suckInHits(hitv); }
179 
180  void suckInDeads(int layer, const DeadVec& deadv) { m_layers_of_hits[layer].suckInDeads(deadv); }
181 
182  const BeamSpot& refBeamSpot() const { return m_beam_spot; }
183  void setBeamSpot(const BeamSpot& bs) { m_beam_spot = bs; }
184 
185  int nLayers() const { return m_n_layers; }
186 
188  const LayerOfHits& operator[](int i) const { return m_layers_of_hits[i]; }
189 
190  private:
191  std::vector<LayerOfHits> m_layers_of_hits;
194  };
195 
196 } // end namespace mkfit
197 #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:91
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
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:79
const Double_t pi
WSR_Result is_within_z_sensitive_region(float z, float dz) const
Definition: TrackerInfo.h:89
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:83
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:66
void suckInDeads(const DeadVec &deadv)
float hit_qbar(unsigned int i) const
Definition: HitStructures.h:95
WSR_Result is_within_r_sensitive_region(float r, float dr) const
Definition: TrackerInfo.h:97
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
bool isBinDead(bin_index_t pi, bin_index_t qi) const
Definition: HitStructures.h:83
bool is_stereo() const
Definition: TrackerInfo.h:80
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
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:84
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:93
void suckInHits(const HitVec &hitv)
void beginRegistrationOfHits(const HitVec &hitv)
EventOfHits(const TrackerInfo &trk_inf)
int subdet() const
Definition: TrackerInfo.h:77
unsigned int getHitIndexFromOriginal(unsigned int i) const
Definition: HitStructures.h:98
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:26
float hit_phi(unsigned int i) const
Definition: HitStructures.h:92
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
float hit_q_half_length(unsigned int i) const
Definition: HitStructures.h:94
bool is_within_z_limits(float z) const
int subdet() const