CMS 3D CMS Logo

HitStructures.cc
Go to the documentation of this file.
2 
4 #include "Matriplex/Memory.h"
5 
6 #include "Debug.h"
7 
8 namespace mkfit {
9 
10  void LayerOfHits::Initializator::setup(float qmin, float qmax, float dq) {
11  assert(qmax > qmin);
12  float extent = qmax - qmin;
13  m_nq = std::ceil(extent / dq);
14  float extra = 0.5f * (m_nq * dq - extent);
15  m_qmin = qmin - extra;
16  m_qmax = qmax + extra;
17  }
18 
19  LayerOfHits::Initializator::Initializator(const LayerInfo &li, float qmin, float qmax, unsigned int nq)
20  : m_linfo(li), m_qmin(qmin), m_qmax(qmax), m_nq(nq) {}
21 
22  LayerOfHits::Initializator::Initializator(const LayerInfo &li, float qmin, float qmax, float dq) : m_linfo(li) {
23  setup(qmin, qmax, dq);
24  }
25 
27  if (li.is_barrel())
28  setup(li.zmin(), li.zmax(), li.q_bin());
29  else
30  setup(li.rin(), li.rout(), li.q_bin());
31  }
32 
34  : m_ax_phi(-Const::PI, Const::PI),
35  m_ax_eta(i.m_qmin, i.m_qmax, i.m_nq),
36  m_binnor(m_ax_phi, m_ax_eta, true, false) // yes-radix, no-keep-cons
37  {
38  m_layer_info = &i.m_linfo;
40 
42  }
43 
45 #ifdef COPY_SORTED_HITS
46  free_hits();
47 #endif
48  }
49 
50 #ifdef COPY_SORTED_HITS
51  void LayerOfHits::alloc_hits(int size) {
52  m_hits = (Hit *)Matriplex::aligned_alloc64(sizeof(Hit) * size);
53  m_capacity = size;
54  for (int ihit = 0; ihit < m_capacity; ihit++) {
55  m_hits[ihit] = Hit();
56  }
57  }
58 
59  void LayerOfHits::free_hits() { std::free(m_hits); }
60 #endif
61 
62  //==============================================================================
63 
64  void LayerOfHits::suckInHits(const HitVec &hitv) {
65  m_n_hits = hitv.size();
66  m_ext_hits = &hitv;
67 
68 #ifdef COPY_SORTED_HITS
69  if (m_capacity < m_n_hits) {
70  free_hits();
71  alloc_hits(m_n_hits);
72  }
73 #endif
74 
76  m_hit_phis.resize(m_n_hits);
77  m_hit_qs.resize(m_n_hits);
78  m_hit_infos.resize(m_n_hits);
79  }
80 
83 
84  for (unsigned int i = 0; i < m_n_hits; ++i) {
85  const Hit &h = hitv[i];
86 
87  HitInfo hi = {h.phi(), m_is_barrel ? h.z() : h.r()};
88 
90 
92  m_hit_infos[i] = hi;
93  }
94  }
95 
97 
98  for (unsigned int i = 0; i < m_n_hits; ++i) {
99  unsigned int j = m_binnor.m_ranks[i];
100 #ifdef COPY_SORTED_HITS
101  memcpy(&m_hits[i], &hitv[j], sizeof(Hit));
102 #endif
103  if (Config::usePhiQArrays) {
104  m_hit_phis[i] = m_hit_infos[j].phi;
105  m_hit_qs[i] = m_hit_infos[j].q;
106  }
107  }
108  }
109 
110  //==============================================================================
111 
112  void LayerOfHits::suckInDeads(const DeadVec &deadv) {
113  m_dead_bins.assign(m_dead_bins.size(), false);
114 
115  for (const auto &d : deadv) {
116  bin_index_t q_bin_1 = qBinChecked(d.q1);
117  bin_index_t q_bin_2 = qBinChecked(d.q2) + 1;
118  bin_index_t phi_bin_1 = phiBin(d.phi1);
119  bin_index_t phi_bin_2 = phiMaskApply(phiBin(d.phi2) + 1);
120 
121  for (bin_index_t q_bin = q_bin_1; q_bin != q_bin_2; q_bin++) {
122  const unsigned int qoff = q_bin * m_ax_phi.size_of_N();
123  for (bin_index_t pb = phi_bin_1; pb != phi_bin_2; pb = phiMaskApply(pb + 1)) {
124  m_dead_bins[qoff + pb] = true;
125  }
126  }
127  }
128  }
129 
130  //==============================================================================
131 
133  m_ext_hits = &hitv;
134 
135  m_n_hits = 0;
136  m_hit_infos.clear();
137  m_ext_idcs.clear();
140 
142  m_binnor.begin_registration(128); // initial reserve for cons vectors
143  }
144 
145  void LayerOfHits::registerHit(unsigned int idx) {
146  const Hit &h = (*m_ext_hits)[idx];
147 
148  m_ext_idcs.push_back(idx);
151 
152  HitInfo hi = {h.phi(), m_is_barrel ? h.z() : h.r()};
153 
155 
156  if (Config::usePhiQArrays) {
157  m_hit_infos.emplace_back(hi);
158  }
159  }
160 
161  void LayerOfHits::endRegistrationOfHits(bool build_original_to_internal_map) {
162  m_n_hits = m_ext_idcs.size();
163  if (m_n_hits == 0)
164  return;
165 
167 
168  // copy q/phi
169 
170 #ifdef COPY_SORTED_HITS
171  if (m_capacity < m_n_hits) {
172  free_hits();
173  alloc_hits(m_n_hits);
174  }
175 #endif
176 
177  if (Config::usePhiQArrays) {
178  m_hit_phis.resize(m_n_hits);
179  m_hit_qs.resize(m_n_hits);
180  }
181 
182  for (unsigned int i = 0; i < m_n_hits; ++i) {
183  unsigned int j = m_binnor.m_ranks[i]; // index in intermediate
184  unsigned int k = m_ext_idcs[j]; // index in external hit_vec
185 
186 #ifdef COPY_SORTED_HITS
187  memcpy(&m_hits[i], &hitv[k], sizeof(Hit));
188 #endif
189 
190  if (Config::usePhiQArrays) {
191  m_hit_phis[i] = m_hit_infos[j].phi;
192  m_hit_qs[i] = m_hit_infos[j].q;
193  }
194 
195  // Redirect m_binnor.m_ranks[i] to point to external/original index.
196  m_binnor.m_ranks[i] = k;
197  }
198 
199  if (build_original_to_internal_map) {
200  if (m_max_ext_idx - m_min_ext_idx + 1 > 8 * m_n_hits) {
201  // If this happens we might:
202  // a) Use external indices for everything. -- *** We are now. ***
203  // b) Build these maps for seeding layers only.
204  // c) Have a flag in hit-on-track that tells us if the hit index has been remapped,
205  // essentially, if it is a seed hit. This might be smart anyway.
206  // One could use index < -256 or something similar.
207 
208  printf(
209  "LayerOfHits::endRegistrationOfHits() original_to_internal index map vector is largish: m_n_hits=%d, "
210  "map_vector_size=%d\n",
211  m_n_hits,
213  }
214 
215  m_ext_idcs.resize(m_max_ext_idx - m_min_ext_idx + 1);
216  for (unsigned int i = 0; i < m_n_hits; ++i) {
218  }
219  }
220 
221  // We can release m_hit_infos and, if not used, also m_ext_idcs -- and realloc them
222  // on next beginRegistration().
223  // If binnor had keep_cons on we could use it for pre-selection in selectHitIndices()
224  // instead of q and phi arrays -- assuming sufficient precision can be achieved..
225  }
226 
228  for (bin_index_t qb = 0; qb <= m_ax_eta.m_last_N_bin; ++qb) {
229  printf("%c bin %d\n", is_barrel() ? 'Z' : 'R', qb);
230  for (bin_index_t pb = 0; pb <= m_ax_phi.m_last_N_bin; ++pb) {
231  if (pb % 8 == 0)
232  printf(" Phi %4d: ", pb);
233  auto content = m_binnor.get_content(pb, qb);
234  printf("%5d,%4d %s", content.first, content.count, ((pb + 1) % 8 == 0) ? "\n" : "");
235  }
236  }
237  }
238 
239  //==============================================================================
240  // EventOfHits
241  //==============================================================================
242 
243  EventOfHits::EventOfHits(const TrackerInfo &trk_inf) : m_n_layers(trk_inf.n_layers()) {
244  m_layers_of_hits.reserve(trk_inf.n_layers());
245  for (int ii = 0; ii < trk_inf.n_layers(); ++ii) {
246  m_layers_of_hits.emplace_back(LayerOfHits::Initializator(trk_inf.layer(ii)));
247  }
248  }
249 
250 } // end namespace mkfit
size
Write out results.
void endRegistrationOfHits(bool build_original_to_internal_map)
constexpr int32_t ceil(float num)
void setup(float qmin, float qmax, float dq)
float rin() const
Definition: TrackerInfo.h:58
unsigned int m_n_hits
float q_bin() const
Definition: TrackerInfo.h:65
std::vector< float > m_hit_phis
bin_index_t qBinChecked(float q) const
Definition: HitStructures.h:73
const HitVec * m_ext_hits
C_pair get_content(B_pair n_bin) const
Definition: binnor.h:240
unsigned int m_min_ext_idx
assert(be >=bs)
float zmax() const
Definition: TrackerInfo.h:62
void finalize_registration()
Definition: binnor.h:289
constexpr bool usePhiQArrays
Definition: Config.h:104
std::vector< C > m_ranks
Definition: binnor.h:211
float zmin() const
Definition: TrackerInfo.h:61
unsigned int size_of_N() const
Definition: binnor.h:143
bin_index_t phiBin(float phi) const
Definition: HitStructures.h:76
Definition: EPCuts.h:4
unsigned int * m_hit_ranks
void register_entry_safe(typename A1::real_t r1, typename A2::real_t r2)
Definition: binnor.h:282
int n_layers() const
Definition: TrackerInfo.h:161
void suckInDeads(const DeadVec &deadv)
d
Definition: ztail.py:151
void begin_registration(C n_items)
Definition: binnor.h:264
std::vector< bool > m_dead_bins
SeedingHitSet::ConstRecHitPointer Hit
ii
Definition: cuy.py:589
std::vector< Hit > HitVec
const LayerInfo & layer(int l) const
Definition: TrackerInfo.h:162
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
LayerOfHits(const LayerOfHits::Initializator &i)
unsigned int size_of_N() const
Definition: binnor.h:88
unsigned int m_max_ext_idx
void suckInHits(const HitVec &hitv)
float rout() const
Definition: TrackerInfo.h:59
void beginRegistrationOfHits(const HitVec &hitv)
EventOfHits(const TrackerInfo &trk_inf)
const I m_last_N_bin
Definition: binnor.h:36
void * aligned_alloc64(std::size_t size)
Definition: Memory.h:13
std::vector< unsigned int > m_ext_idcs
bool is_barrel() const
void registerHit(unsigned int idx)
const LayerInfo * m_layer_info
unsigned short bin_index_t
Definition: HitStructures.h:26
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
bin_index_t phiMaskApply(bin_index_t in) const
Definition: HitStructures.h:79
std::vector< LayerOfHits > m_layers_of_hits
std::vector< HitInfo > m_hit_infos
bool is_barrel() const
Definition: TrackerInfo.h:68
void reset_contents(bool shrink_vectors=true)
Definition: binnor.h:252