ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HelixHough_init.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HelixHough_init.cpp
1 #include "HelixHough.h"
2 #include "HelixKalmanState.h"
3 #include "HelixRange.h"
4 #include "HelixResolution.h"
5 #include "SimpleHit3D.h"
6 #include "SimpleTrack3D.h"
7 
8 #include <iostream>
9 #include <utility>
10 #include <vector>
11 
12 using namespace std;
13 
14 
15 HelixHough::HelixHough(unsigned int n_phi, unsigned int n_d, unsigned int n_k, unsigned int n_dzdl, unsigned int n_z0, HelixResolution& min_resolution, HelixResolution& max_resolution, HelixRange& range) : remove_hits(false), vote_time(0.), xy_vote_time(0.), z_vote_time(0.), print_timings(false), separate_by_helicity(true), helicity(false), only_one_helicity(false), check_layers(false), req_layers(0), bin_scale(1.), z_bin_scale(1.), start_zoom(0), max_hits_pairs(0), cluster_start_bin(2), layers_at_a_time(4), n_layers(6), smooth_back(false), cull_input_hits(false), iterate_clustering(false)
16 {
17  initHelixHough(n_phi, n_d, n_k, n_dzdl, n_z0, min_resolution, max_resolution, range);
18  hit_used = new vector<unsigned int>;
19 }
20 
21 
22 HelixHough::HelixHough(vector<vector<unsigned int> >& zoom_profile, unsigned int minzoom, HelixRange& range) : remove_hits(false), vote_time(0.), xy_vote_time(0.), z_vote_time(0.), print_timings(false), separate_by_helicity(true), helicity(false), only_one_helicity(false), check_layers(false), req_layers(0), bin_scale(1.), z_bin_scale(1.), start_zoom(0), max_hits_pairs(0), cluster_start_bin(2), layers_at_a_time(4), n_layers(6), layer_start(-1), layer_end(-1), smooth_back(false), cull_input_hits(false), iterate_clustering(false)
23 {
24  for(unsigned int i=0;i<hits_vec.size();i++){delete hits_vec[i];}
25  hits_vec.clear();
26  for(unsigned int i=0;i<pairs_vec.size();i++)
27  {
28  (*pairs_vec[i]).clear();
29  delete pairs_vec[i];
30  }
31  pairs_vec.clear();
32  for(unsigned int i=0;i<bins_vec.size();i++){delete bins_vec[i];}
33  bins_vec.clear();
34  for(unsigned int i=0;i<seeds_vec.size();i++){delete seeds_vec[i];}
35  seeds_vec.clear();
36  for(unsigned int i=0;i<clusters_vec.size();i++){delete clusters_vec[i];}
37  clusters_vec.clear();
38  num_clusters.clear();
39 
40  for(unsigned int i=0;i<seeds_vec.size();i++){delete seeds_vec[i];}
41  seeds_vec.clear();
42 
43 
44  top_range = range;
45  max_zoom = zoom_profile.size()-1;
46  min_zoom = minzoom;
47  for(unsigned int i=0;i<=(max_zoom);++i)
48  {
49  unsigned int phibins=zoom_profile[i][0];
50  unsigned int dbins=zoom_profile[i][1];
51  unsigned int kbins=zoom_profile[i][2];
52  unsigned int dzdlbins=zoom_profile[i][3];
53  unsigned int z0bins=zoom_profile[i][4];
54 
55  n_phi_bins.push_back(phibins);
56  n_d_bins.push_back(dbins);
57  n_k_bins.push_back(kbins);
58  n_dzdl_bins.push_back(dzdlbins);
59  n_z0_bins.push_back(z0bins);
60 
61  hits_vec.push_back(new vector<SimpleHit3D>);
62  pairs_vec.push_back(new vector<pair<unsigned int,unsigned int> >);
63  bins_vec.push_back(new vector<BinEntryPair5D>);
64  seeds_vec.push_back(new vector<SimpleTrack3D>);
65  clusters_vec.push_back(new vector<ParameterCluster>);
66  num_clusters.push_back(0);
67  }
68 
69  hit_used = new vector<unsigned int>;
70 }
71 
72 
73 void HelixHough::initHelixHough(unsigned int n_phi, unsigned int n_d, unsigned int n_k, unsigned int n_dzdl, unsigned int n_z0, HelixResolution& min_resolution, HelixResolution& max_resolution, HelixRange& range)
74 {
75  for(unsigned int i=0;i<hits_vec.size();i++){delete hits_vec[i];}
76  hits_vec.clear();
77  for(unsigned int i=0;i<pairs_vec.size();i++){delete pairs_vec[i];}
78  pairs_vec.clear();
79  for(unsigned int i=0;i<bins_vec.size();i++){delete bins_vec[i];}
80  bins_vec.clear();
81  for(unsigned int i=0;i<clusters_vec.size();i++){delete clusters_vec[i];}
82  clusters_vec.clear();
83  num_clusters.clear();
84 
85  for(unsigned int i=0;i<seeds_vec.size();i++){delete seeds_vec[i];}
86  seeds_vec.clear();
87 
88  top_range = range;
89 
90  unsigned int zoom_level = 0;
91  float k_res = (range.max_k - range.min_k);
92  float phi_res = (range.max_phi - range.min_phi);
93  float d_res = (range.max_d - range.min_d);
94  float z0_res = (range.max_z0 - range.min_z0);
95  float dzdl_res = (range.max_dzdl - range.min_dzdl);
96  min_zoom=0;
97  bool min_zoom_set=false;
98 
99  unsigned int nzoom_k=0;
100  unsigned int nzoom_d=0;
101  unsigned int nzoom_phi=0;
102  unsigned int nzoom_dzdl=0;
103  unsigned int nzoom_z0=0;
104  // find the number of iterations it takes to get to the maximum zooming for each dimension
105  while(true)
106  {
107  if(zoom_level != 0)
108  {
109  if(k_res<=max_resolution.k_res && phi_res<=max_resolution.phi_res && d_res<=max_resolution.d_res && z0_res<=max_resolution.z0_res && dzdl_res<=max_resolution.dzdl_res)
110  {
111  max_zoom = zoom_level;
112  break;
113  }
114  }
115 
116  unsigned int kbins=1;
117  unsigned int phibins=1;
118  unsigned int dbins=1;
119  unsigned int z0bins=1;
120  unsigned int dzdlbins=1;
121  if(k_res>max_resolution.k_res)
122  {
123  nzoom_k+=1;
124  kbins = (unsigned int)(ceil(k_res/max_resolution.k_res));
125  if(kbins > n_k){kbins = n_k;}
126  k_res/=((float)kbins);
127  }
128  if(phi_res>max_resolution.phi_res)
129  {
130  nzoom_phi+=1;
131  phibins = (unsigned int)(ceil(phi_res/max_resolution.phi_res));
132  if(phibins > n_phi){phibins = n_phi;}
133  phi_res/=((float)phibins);
134  }
135  if(d_res>max_resolution.d_res)
136  {
137  nzoom_d+=1;
138  dbins = (unsigned int)(ceil(d_res/max_resolution.d_res));
139  if(dbins > n_d){dbins = n_d;}
140  d_res/=((float)dbins);
141  }
142  if(z0_res>max_resolution.z0_res)
143  {
144  nzoom_z0+=1;
145  z0bins = (unsigned int)(ceil(z0_res/max_resolution.z0_res));
146  if(z0bins > n_z0){z0bins = n_z0;}
147  z0_res/=((float)z0bins);
148  }
149  if(dzdl_res>max_resolution.dzdl_res)
150  {
151  nzoom_dzdl+=1;
152  dzdlbins = (unsigned int)(ceil(dzdl_res/max_resolution.dzdl_res));
153  if(dzdlbins > n_dzdl){dzdlbins = n_dzdl;}
154  dzdl_res/=((float)dzdlbins);
155  }
156  zoom_level+=1;
157  }
158 
159  k_res = (range.max_k - range.min_k);
160  phi_res = (range.max_phi - range.min_phi);
161  d_res = (range.max_d - range.min_d);
162  z0_res = (range.max_z0 - range.min_z0);
163  dzdl_res = (range.max_dzdl - range.min_dzdl);
164  for(unsigned int zoom=0;zoom<max_zoom;++zoom)
165  {
166  if(k_res<=min_resolution.k_res && phi_res<=min_resolution.phi_res && d_res<=min_resolution.d_res && z0_res<=min_resolution.z0_res && dzdl_res<=min_resolution.dzdl_res && min_zoom_set==false)
167  {
168  min_zoom = zoom;
169  min_zoom_set=true;
170  }
171  //if we need to zoom more, we determine the binning of the next zoom level.
172  unsigned int kbins=1;
173  unsigned int phibins=1;
174  unsigned int dbins=1;
175  unsigned int z0bins=1;
176  unsigned int dzdlbins=1;
177  if((k_res>max_resolution.k_res) && ( (max_zoom - zoom) <= nzoom_k ))
178  {
179  kbins = (unsigned int)(ceil(k_res/max_resolution.k_res));
180  if( kbins > n_k ){kbins = n_k;}
181  k_res/=((float)kbins);
182  }
183  if((phi_res>max_resolution.phi_res) && ( (max_zoom - zoom) <= nzoom_phi ))
184  {
185  phibins = (unsigned int)(ceil(phi_res/max_resolution.phi_res));
186  if( phibins > n_phi ){phibins = n_phi;}
187  phi_res/=((float)phibins);
188  }
189  if((d_res>max_resolution.d_res) && ( (max_zoom - zoom) <= nzoom_d ))
190  {
191  dbins = (unsigned int)(ceil(d_res/max_resolution.d_res));
192  if( dbins > n_d ){dbins = n_d;}
193  d_res/=((float)dbins);
194  }
195  if((z0_res>max_resolution.z0_res) && ( (max_zoom - zoom) <= nzoom_z0 ))
196  {
197  z0bins = (unsigned int)(ceil(z0_res/max_resolution.z0_res));
198  if( z0bins > n_z0 ){z0bins = n_z0;}
199  z0_res/=((float)z0bins);
200  }
201  if((dzdl_res>max_resolution.dzdl_res) && ( (max_zoom - zoom) <= nzoom_dzdl ))
202  {
203  dzdlbins = (unsigned int)(ceil(dzdl_res/max_resolution.dzdl_res));
204  if( dzdlbins > n_dzdl ){dzdlbins = n_dzdl;}
205  dzdl_res/=((float)dzdlbins);
206  }
207  n_phi_bins.push_back(phibins);
208  n_d_bins.push_back(dbins);
209  n_k_bins.push_back(kbins);
210  n_dzdl_bins.push_back(dzdlbins);
211  n_z0_bins.push_back(z0bins);
212 
213  hits_vec.push_back(new vector<SimpleHit3D>);
214  pairs_vec.push_back(new vector<pair<unsigned int,unsigned int> >);
215  bins_vec.push_back(new vector<BinEntryPair5D>);
216  seeds_vec.push_back(new vector<SimpleTrack3D>);
217  clusters_vec.push_back(new vector<ParameterCluster>);
218  num_clusters.push_back(0);
219  }
220  max_zoom -= 1;
221  if(min_zoom_set==false){min_zoom=max_zoom;}
222  cout<<"min_zoom = "<<min_zoom<<endl;
223 }
224 
225 
227 {
228  for(unsigned int i=0;i<hits_vec.size();i++){delete hits_vec[i];}
229  for(unsigned int i=0;i<pairs_vec.size();i++){delete pairs_vec[i];}
230  for(unsigned int i=0;i<bins_vec.size();i++){delete bins_vec[i];}
231  for(unsigned int i=0;i<seeds_vec.size();i++){delete seeds_vec[i];}
232  for(unsigned int i=0;i<clusters_vec.size();i++){delete clusters_vec[i];}
233  delete hit_used;
234 }