ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HelixHoughBin_v1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HelixHoughBin_v1.cc
1 #include "HelixHoughBin_v1.h"
2 
3 #include <phool/PHObject.h> // for PHObject
4 #include <phool/phool.h> // for PHWHERE
5 
6 #include <cassert>
7 #include <cstdlib> // for exit, NULL
8 #include <iostream>
9 
10 using namespace std;
11 
13  : _cluster_IDs(),
14  _global_bin(),
15  _bin(),
16  _kappa_bins(),
17  _phi_bins(),
18  _phi_high_bins(),
19  _phi_low_bins(),
20  _d_bins(),
21  _dzdl_bins(),
22  _dzdl_high_bins(),
23  _dzdl_low_bins(),
24  _z0_bins(),
25  _zoomlevel(0),
26  _hough_space(nullptr) {
27 
28  set_bin(_zoomlevel,bin);
29 // cout<<"HoughBin:: bin "<<bin<<endl;
30 }
31 
32 void HelixHoughBin_v1::identify(std::ostream& os) const {
33  os << "---HelixHoughBin_v1-------------" << endl;
34  os << "zoom level: "<< _zoomlevel<<" bin :" <<_bin<<endl;
35  os << " helix hough bins (kappa, phi, d, dzdl, z0) = ("
36  << get_kappa_bin(_zoomlevel) << ","
37  << get_phi_bin(_zoomlevel) << ","
38  << get_d_bin(_zoomlevel) << ","
39  << get_dzdl_bin(_zoomlevel) << ","
40  << get_z0_bin(_zoomlevel) << ")" << endl;
41  os << "--------------------------------" << endl;
42 }
43 
45 
46 // cout<<"HoughBin:: zoom level "<<_zoomlevel<<" bin "<< _bin[_zoomlevel]<<endl;
48 
49 }
50 
52 
53  _hough_space = dynamic_cast<HelixHoughSpace*> (hough_space->CloneMe());
54  assert(_hough_space);
55 }
56 
57 
58 void HelixHoughBin_v1::set_bins(unsigned int zoomlevel, unsigned int bin) {
59 
60  if (!_hough_space)
61  {
62  cerr << PHWHERE << "::Error - HelixHoughSpace is not set!! "<< endl;
63  exit(1);
64  }
65 
66  unsigned int n_kappa_bins = _hough_space->get_n_kappa_bins(zoomlevel);
67  unsigned int n_phi_bins = _hough_space->get_n_phi_bins(zoomlevel);
68  unsigned int n_d_bins = _hough_space->get_n_d_bins(zoomlevel);
69  unsigned int n_dzdl_bins = _hough_space->get_n_dzdl_bins(zoomlevel);
70 
71  unsigned int temp1 = n_kappa_bins * n_phi_bins * n_d_bins * n_dzdl_bins;
72  unsigned int z0_bin = bin/temp1;
73 
74  unsigned int temp2 = bin - z0_bin * temp1;
75  temp1 /= n_dzdl_bins;
76  unsigned int dzdl_bin = temp2/temp1;
77 
78  temp2 -= dzdl_bin * temp1;
79  temp1 /= n_d_bins;
80  unsigned int d_bin = temp2/temp1;
81 
82  temp2 -= d_bin * temp1;
83  temp1 /= n_phi_bins;
84  unsigned int phi_bin = temp2/temp1;
85 
86  temp2 -= phi_bin * temp1;
87  temp1 /= n_kappa_bins;
88  unsigned int kappa_bin = temp2/temp1;
89 
90 
91 // cout<<"HoughBin:: bin "<<bin<<endl;
92 // cout<<"k "<<kappa_bin<<" phi " <<phi_bin<<" d "<<d_bin<<" dzdl "<< dzdl_bin<<" z0 "<< z0_bin<<endl;
93 
94  set_kappa_bin(zoomlevel, kappa_bin);
95  set_phi_bin(zoomlevel, phi_bin);
96  set_d_bin(zoomlevel, d_bin);
97  set_dzdl_bin(zoomlevel, dzdl_bin);
98  set_z0_bin(zoomlevel, z0_bin);
99  set_global_bin(zoomlevel);
100 
101 // bin = kappabin + nkappabin* (phibin + nphibin* (dbin + ndbin *( dzdlbin + ndzdlbin*z0bin) ) )
102 }
103 
104 unsigned int HelixHoughBin_v1::get_global_bin(unsigned int /*zoomlevel*/)
105 {
106  return _global_bin;
107 }
108 
109 void HelixHoughBin_v1::set_global_bin(unsigned int zoomlevel)
110 {
111 
112 // global_bin = zoom2bin + nzoom2bin*(zoom1bin + nzoom1bin*zoom0bin)
113  _global_bin = _bin[0];
114 // cout<<"global bin init"<<_global_bin<<endl;
115  for (unsigned int izoom=1; izoom<zoomlevel+1; izoom++){
116  unsigned int ntotalbins = _hough_space->get_n_kappa_bins(izoom);
117  ntotalbins *= _hough_space->get_n_phi_bins(izoom);
118  ntotalbins *= _hough_space->get_n_d_bins(izoom);
119  ntotalbins *= _hough_space->get_n_dzdl_bins(izoom);
120  ntotalbins *= _hough_space->get_n_z0_bins(izoom);
121  _global_bin += _bin[izoom] + ntotalbins * _global_bin;
122 // cout<<"global bin first "<<_global_bin<<endl;
123  }
124 }
125 
126 
127 unsigned int HelixHoughBin_v1::get_neighbors_global_bin(unsigned int zoomlevel, unsigned int var, unsigned int bit_sign )
128 {
129 
130  unsigned int nbins[5]= {_hough_space->get_n_kappa_bins(zoomlevel),_hough_space->get_n_phi_bins(zoomlevel),_hough_space->get_n_d_bins(zoomlevel),_hough_space->get_n_dzdl_bins(zoomlevel),_hough_space->get_n_z0_bins(zoomlevel)};
131  unsigned int bins[5] = {get_kappa_bin(zoomlevel),get_phi_bin(zoomlevel),get_d_bin(zoomlevel),get_dzdl_bin(zoomlevel),get_z0_bin(zoomlevel)};
132 // cout<<"bins[] "<<bins[var]<<endl;
133 // unsigned int bins_var[5] = {get_kappa_bin(zoomlevel),get_phi_bin(zoomlevel),get_d_bin(zoomlevel),get_dzdl_bin(zoomlevel),get_z0_bin(zoomlevel)};
134  for (unsigned int i=0;i<5;i++)
135  {
136  int sign = 2*((bit_sign>>i)%2)-1;
137  unsigned int bit_var = (var>>i)%2;
138  if (!bit_var || (bins[i]==(nbins[i]-1)&& sign>0) || (bins[i]==0 && sign<0) ) continue;
139  bins[i] += sign;
140  }
141  unsigned int _neighbor_bin = _hough_space->get_bin(zoomlevel,bins);
142 // cout<<"sign "<<sign<< "bins[]"<<bins[var]<<endl;
143 
144  unsigned int _global_neighbor_bin;
145  if (zoomlevel==0) _global_neighbor_bin = _neighbor_bin;
146  else _global_neighbor_bin = _bin[0];
147  for (unsigned int izoom=1; izoom<zoomlevel+1; izoom++){
148  unsigned int ntotalbins = _hough_space->get_n_kappa_bins(izoom);
149  ntotalbins *= _hough_space->get_n_phi_bins(izoom);
150  ntotalbins *= _hough_space->get_n_d_bins(izoom);
151  ntotalbins *= _hough_space->get_n_dzdl_bins(izoom);
152  ntotalbins *= _hough_space->get_n_z0_bins(izoom);
153  if (izoom == zoomlevel){
154  _global_neighbor_bin += _neighbor_bin + ntotalbins * _global_neighbor_bin;
155  }else{
156  _global_neighbor_bin += _bin[izoom] + ntotalbins * _global_neighbor_bin;
157  }
158  }
159  return _global_neighbor_bin;
160 }
161 
162 float HelixHoughBin_v1::get_kappa_center(unsigned int zoomlevel)
163 {
164  float center = _hough_space->get_kappa_min();
165  for (unsigned int i=0; i<zoomlevel+1; i++){
166  center += _hough_space->get_kappa_bin_size(i)*_kappa_bins[i];
167  }
168  center += 0.5*_hough_space->get_kappa_bin_size(zoomlevel);
169  return center;
170 }
171 
172 float HelixHoughBin_v1::get_phi_center(unsigned int zoomlevel)
173 {
174  float center = _hough_space->get_phi_min();
175  for (unsigned int i=0; i<zoomlevel+1; i++){
176  center += _hough_space->get_phi_bin_size(i)*_phi_bins[i];
177  }
178  center += 0.5*_hough_space->get_phi_bin_size(zoomlevel);
179  return center;
180 }
181 
182 float HelixHoughBin_v1::get_d_center(unsigned int zoomlevel)
183 {
184  float center = _hough_space->get_d_min();
185  for (unsigned int i=0; i<zoomlevel+1; i++){
186  center += _hough_space->get_d_bin_size(i)*_d_bins[i];
187  }
188  center += 0.5*_hough_space->get_d_bin_size(zoomlevel);
189  return center;
190 }
191 
192 float HelixHoughBin_v1::get_dzdl_center(unsigned int zoomlevel)
193 {
194  float center = _hough_space->get_dzdl_min();
195  for (unsigned int i=0; i<zoomlevel+1; i++){
196  center += _hough_space->get_dzdl_bin_size(i)*_dzdl_bins[i];
197  }
198  center += 0.5*_hough_space->get_dzdl_bin_size(zoomlevel);
199  return center;
200 }
201 
202 float HelixHoughBin_v1::get_z0_center(unsigned int zoomlevel)
203 {
204  float center = _hough_space->get_z0_min();
205  for (unsigned int i=0; i<zoomlevel+1; i++){
206  center += _hough_space->get_z0_bin_size(i)*_z0_bins[i];
207  }
208  center += 0.5*_hough_space->get_z0_bin_size(zoomlevel);
209  return center;
210 }
211 
212