BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
HoughMap.cxx
Go to the documentation of this file.
1#include "HoughMap.h"
2#include "HoughPeak.h"
3#include <algorithm>
4#include <cmath>
5#include <vector>
6
11
13 //_mapHitList=NULL;
14 _houghSpace = NULL;
15}
16
17HoughMap::HoughMap( int charge, HoughHitList& houghHitList, int mapHit, int ntheta, int nrho,
18 double rhoMin, double rhoMax, int peakWidth, int peakHigh,
19 double hitpro ) {
20 _hitList = houghHitList;
21 _mapHit = mapHit;
22 _nTheta = ntheta;
23 _nRho = nrho;
24 _thetaMin = 0;
25 _thetaMax = M_PI;
26 _rhoMin = rhoMin;
27 _rhoMax = rhoMax;
28 _peakWidth = peakWidth;
29 _peakHigh = peakHigh;
30 _hitpro = hitpro;
31 _charge = charge;
32
33 //_mapHitList = new vector<const HoughHit*>*[_nTheta];
34 //_houghS= new double*[_nTheta];
35 //_houghS2= new double*[m_N2];
36 // _houghR= new double*[_nTheta];
37 // _houghRL= new double*[_nTheta];
38 // _houghNL= new double*[_nTheta];
39
40 // for ( int i = 0; i < _nTheta; i++ )
41 // {
42 //_mapHitList[i] = new vector<const HoughHit*>[_nRho];
43 // _houghS[i] = new double[_nRho];
44 // _houghR[i] = new double[_nRho];
45 // _houghRL[i] = new double[_nRho];
46 // _houghNL[i] = new double[_nRho];
47 // for(int j=0; j<_nRho; j++){
48 // _houghS[i][j]=0;
49 // _houghR[i][j]=0;
50 // }
51 // }
52 // for(int i=0; i<m_N2; i++){
53 // _houghS2[i] = new double[m_N2];
54 // for(int j=0; j<m_N2; j++){
55 // _houghS2[i][j]=0;
56 // }
57 // }
58
59 if ( _charge == -1 )
60 _houghSpace = new TH2D( "houghspace", "houghspace", _nTheta, _thetaMin, _thetaMax, _nRho,
61 _rhoMin, _rhoMax );
62 if ( _charge == 1 )
63 _houghSpace = new TH2D( "houghspace2", "houghspace2", _nTheta, _thetaMin, _thetaMax, _nRho,
64 _rhoMin, _rhoMax );
65 // _houghR= new TH2D("houghR","houghR",_nTheta,_thetaMin,_thetaMax,_nRho,_rhoMin,_rhoMax);
66
67 doMap();
68}
69
71 _mapHit = other._mapHit, _nTheta = other._nTheta, _nRho = other._nRho,
72 _thetaMin = other._thetaMin, _thetaMax = other._thetaMax, _rhoMin = other._rhoMin,
73 _rhoMax = other._rhoMax, _hitList = other._hitList, _houghPeakList = other._houghPeakList,
74 _houghTrackList = other._houghTrackList, _houghSpace = other._houghSpace,
75 _charge = other._charge;
76 //_houghR= other._houghR;
77
78 //_mapHitList = new vector<const HoughHit*>*[_nTheta];
79 //_houghNL= new double*[_nTheta];
80 //_houghRL= new double*[_nTheta];
81 //_houghS= new double*[_nTheta];
82 // for(int i=0; i<_nTheta; i++){
83 //_mapHitList[i] = new vector<const HoughHit*>[_nRho];
84 // _houghNL[i] = new double[_nRho];
85 // _houghRL[i] = new double[_nRho];
86 //_houghS[i] = new double[_nRho];
87 //}
88
89 // for(int i=0; i<_nTheta; i++){
90 // for(int j=0; j<_nRho; j++){
91 //_mapHitList[i][j]=other._mapHitList[i][j];
92 // _houghNL[i][j]=other._houghNL[i][j];
93 // _houghRL[i][j]=other._houghRL[i][j];
94 // _houghS[i][j]=other._houghS[i][j];
95 // }
96 // }
97}
98
100 buildMap();
101 // mapDev();
102 // cald_layer();
103 // select_slant();
104 // gravity();
105 // findPeaks();
106 // if(m_debug>0) {cout<<" before sort "<<endl; printPeak();}
107 // {cout<<" before sort "<<endl; printPeak();}
108 sortPeaks();
109 hitFinding();
110 if ( m_debug > 0 )
111 {
112 cout << " after sort " << endl;
113 printPeak();
114 }
115 trackFinder();
116 // {cout<<" after sort "<<endl; printPeak();}
117 // candiTrack();
118 if ( m_debug > 0 ) printTrack();
119}
120
122
123 // for(int i=0; i<_nTheta; i++){ delete []_mapHitList[i];delete []_houghNL; delete
124 // []_houghRL;delete []_houghS;} for(int i=0; i<_nTheta; i++){ delete []_mapHitList[i]; }
125 // delete []_mapHitList;
126 delete _houghSpace;
127 // for(int i=0; i<_nTheta; i++){ delete []_houghS[i];}
128 // delete []_houghS;
129 // delete _houghR;
130 // for(int i=0; i<m_N2; i++) { delete []_houghS2[i];}
131 // delete []_houghS2;
132}
134 cout << "Print Peak in HoughMap sumPeak: " << _houghPeakList.size() << endl;
135 vector<HoughPeak>::iterator iter = _houghPeakList.begin();
136 for ( int i = 0; iter != _houghPeakList.end(); iter++, i++ )
137 {
138 cout << "count of Peak on HoughMap: " << ( *iter ).getHoughHitList().size() << endl;
139 ( *iter ).printAllHit();
140 }
141}
142
144void HoughMap::buildMap() {
145 if ( m_debug > 0 ) cout << "in build map " << endl;
146 // loop over all hits, fill histogram of HoughRec space
147 // std::vector<HoughHit>::const_iterator iter = _hitList.getList().begin();
148 std::vector<HoughHit>::iterator iter = _hitList.getList().begin();
149 for ( ; iter != _hitList.getList().end(); iter++ )
150 {
151 HoughHit* hit = &( *iter );
152 if ( _mapHit == 1 && hit->getSlayerType() != 0 ) continue;
153 if ( hit->driftTime() > 1000 && hit->driftTime() < 0 )
154 continue; // to big hit ,maybe error hit
155 double drift_CF = hit->getR();
156 hit->makeCir( 2 * _nTheta, 0, 2 * M_PI, drift_CF ); // N2
157 for ( int ni = 0; ni < 2 * m_N1; ni++ )
158 { // N1
159 double binwidth = M_PI / _nTheta;
160 double binhigh = ( _rhoMax - _rhoMin ) / _nRho;
161 double theta = hit->getCir( ni ).getTheta();
162 double rho = hit->getCir( ni ).getRho();
163 if ( fabs( rho ) >= _rhoMax ) continue;
164 double slantOfLine = hit->getCir( ni ).getSlant();
165 int chargeOfHitOnCir = ( slantOfLine / fabs( slantOfLine ) ) * ( rho / fabs( rho ) );
166 if ( chargeOfHitOnCir == _charge ) continue;
167 if ( fabs( slantOfLine ) < 0.03 ) continue; // FIXME
168 _houghSpace->Fill( theta, rho );
169 // int rhobinNum = (int)( (rho-_rhoMin)/((_rhoMax-_rhoMin)/m_N1) );
170 // int thetabinNum = (int)( (theta-_thetaMin)/((_thetaMax-_thetaMin)/m_N1) );
171 // _mapHitList[thetabinNum][rhobinNum].push_back(hit) ;
172 }
173 // break; //only first line
174 }
175 // initialize
176 // double hist[1000][1000] ={0};
177 // int max =0 ;
178 double aver( 0 ), sigma( 0 );
179 mapDev( _houghSpace, aver, sigma );
180 // cout<<"aver sigma aver+10sig "<<aver<<" "<<sigma<<" "<<aver+10*sigma<<endl;
181 for ( int iTheta = 0; iTheta < _nTheta; iTheta++ )
182 {
183 for ( int iRho = 0; iRho < _nRho; iRho++ )
184 {
185 int z = _houghSpace->GetBinContent( iTheta + 1, iRho + 1 );
186 double thetabin = _houghSpace->GetXaxis()->GetBinCenter( iTheta + 1 );
187 double rhobin = _houghSpace->GetYaxis()->GetBinCenter( iRho + 1 );
188 double pt = ( 1 / rhobin ) / 333.567;
189 int MINCOUNT = 10; // num at least consider exist a track
190 if ( 0.06 <= pt && pt < 0.07 ) MINCOUNT = 6;
191 if ( pt < 0.06 ) MINCOUNT = 5;
192 double minCount_Cut =
193 ( aver + 4 * sigma > MINCOUNT ) ? ( aver + 4 * sigma ) : MINCOUNT; // 4 temp par
194 // _houghS[iTheta][iRho]=z;
195 // if( z>=MINCOUNT) loopPeak(thetabin,rhobin,iTheta,iRho,hist);
196 // if( z>=MINCOUNT) loopPeak(thetabin,rhobin,iTheta,iRho);
197 if ( z >= minCount_Cut ) loopPeak( thetabin, rhobin, iTheta, iRho );
198 // if( max <z ) max = z ;
199 }
200 }
201 // MAX = max;
202 // if(m_debug>0) printMapHit();
203}
204/*
205 void HoughMap::printMapHit(){
206 double aver(0),sigma(0);
207 mapDev(_houghSpace,aver,sigma);
208//cout<<"AVER SIGMA "<<aver<<" "<<sigma<<endl;
209//cout<<"print Map Hit : "<<_charge<<endl;
210for(int i =0;i<m_N1;i++){
211for(int j =0;j<m_N1;j++){
212if( _mapHitList[i][j].size()>=5 ) cout<<"map :("<<i<<","<<j<<")
213:"<<_mapHitList[i][j].size()<<endl; else continue; for(int k
214=0;k<_mapHitList[i][j].size();k++){ cout<<"Hit:
215("<<_mapHitList[i][j][k]->getLayerId()<<","<<_mapHitList[i][j][k]->getWireId()<<")"<<endl;
216}
217}
218}
219}
220*/
221
222// find local maximum in hough space between 8 neighbor cells
223void HoughMap::findPeaks( vector<vector<int>> vec_hist, double theta_left, double theta_right,
224 double rho_down, double rho_up ) {
225 int minCount_Cut;
226 double rho_peak = 1. / 2. * ( rho_down + rho_up );
227 double pt_peak = ( 1. / rho_peak ) / 333.567;
228 if ( 0.06 <= pt_peak && pt_peak < 0.07 ) minCount_Cut = 4;
229 if ( pt_peak < 0.06 ) minCount_Cut = 3;
230 else minCount_Cut = 5;
231 double aver( 0 ), sigma( 0 );
232 // mapDev(vec_hist,aver,sigma);
233 // int minCount_Cut=( aver+3*sigma> 5)?( aver+3*sigma):5;
234 // cout<<"aver: "<<aver<<" "<<sigma<<endl;
235 int _nTheta = m_N2;
236 int _nRho = m_N2;
237
238 // store peak property
239 // 0: not a peak,
240 // 1: same hight with neighbor cells,
241 // 2: highest peak according to neighbor 8 cells
242 int** hough_trans_CS_peak = new int*[_nTheta];
243 for ( int i = 0; i < _nTheta; i++ )
244 {
245 hough_trans_CS_peak[i] = new int[_nRho];
246 for ( int j = 0; j < _nRho; j++ ) { hough_trans_CS_peak[i][j] = -999; }
247 }
248
249 // loop over hough space
250 for ( int iRho = 0; iRho < _nRho; iRho++ )
251 {
252 for ( int iTheta = 0; iTheta < _nTheta; iTheta++ )
253 {
254 // int height = houghSpace->GetBinContent(iTheta+1,iRho+1);
255 int height = vec_hist[iTheta][iRho];
256 if ( height < minCount_Cut )
257 {
258 hough_trans_CS_peak[iTheta][iRho] = 0;
259 continue;
260 }
261 // loop over around bins
262 int max_around = 0;
263 for ( int ar = iTheta - 1; ar <= iTheta + 1; ar++ )
264 {
265 for ( int rx = iRho - 1; rx <= iRho + 1; rx++ )
266 {
267 int ax;
268 if ( ar < 0 ) { ax = ar + _nTheta; }
269 else if ( ar >= _nTheta ) { ax = ar - _nTheta; }
270 else { ax = ar; }
271 if ( ( ax != iTheta || rx != iRho ) && rx >= 0 && rx < _nRho )
272 {
273 // int heightThisBin =houghSpace->GetBinContent(ax+1,rx+1);
274 int heightThisBin = vec_hist[ax][rx];
275 if ( heightThisBin > max_around ) { max_around = heightThisBin; }
276 }
277 }
278 }
279 if ( height < max_around ) { hough_trans_CS_peak[iTheta][iRho] = 0; }
280 else if ( height == max_around ) { hough_trans_CS_peak[iTheta][iRho] = 1; }
281 else if ( height > max_around ) { hough_trans_CS_peak[iTheta][iRho] = 2; }
282 }
283 }
284 // mergeNeighbor(hough_trans_CS_peak,theta_left,theta_right,rho_down,rho_up);
285 // merge
286 int peakNum_Merge = 0;
287 for ( int iRho = 0; iRho < _nRho; iRho++ )
288 {
289 for ( int iTheta = 0; iTheta < _nTheta; iTheta++ )
290 {
291 if ( hough_trans_CS_peak[iTheta][iRho] == 1 )
292 {
293 hough_trans_CS_peak[iTheta][iRho] = 2;
294 for ( int ar = iTheta - 1; ar <= iTheta + 1; ar++ )
295 {
296 for ( int rx = iRho - 1; rx <= iRho + 1; rx++ )
297 {
298 int ax;
299 if ( ar < 0 ) { ax = ar + _nTheta; }
300 else if ( ar >= _nTheta ) { ax = ar - _nTheta; }
301 else { ax = ar; }
302 if ( ( ax != iTheta || rx != iRho ) && rx >= 0 && rx < _nRho )
303 {
304 if ( hough_trans_CS_peak[ax][rx] == 1 ) { hough_trans_CS_peak[ax][rx] = 0; }
305 }
306 }
307 }
308 }
309 if ( hough_trans_CS_peak[iTheta][iRho] == 2 )
310 {
311 int peak_num = _houghPeakList.size();
312 // _houghPeakList.push_back(
313 // HoughPeak(_houghSpace->GetBinContent(iTheta+1,iRho+1),iTheta,iRho,exTheta(iTheta,theta_left,theta_right,m_N2),exRho(iRho,rho_down,rho_up,m_N2),true,peak_num+1,_charge)
314 //);//store peak
315 _houghPeakList.push_back( HoughPeak( vec_hist[iTheta][iRho], iTheta, iRho,
316 exTheta( iTheta, theta_left, theta_right, m_N2 ),
317 exRho( iRho, rho_down, rho_up, m_N2 ), true,
318 peak_num + 1, _charge ) ); // store peak
319 // cout<<"height "<<vec_hist[iTheta][iRho]<<endl;
320 peakNum_Merge++;
321 }
322 }
323 }
324
325 // end of merge
326 for ( int i = 0; i < _nTheta; i++ ) { delete[] hough_trans_CS_peak[i]; }
327 delete[] hough_trans_CS_peak;
328}
329// merge "1" peaks, 1: same hight with neighbor peaks
330int HoughMap::mergeNeighbor( int** hough_trans_CS_peak, double theta_left, double theta_right,
331 double rho_down, double rho_up ) {
332 // _houghPeakList.reserve(100);
333 int _nTheta = m_N2;
334 int _nRho = m_N2;
335 int peakNum_Merge = 0;
336 for ( int iRho = 0; iRho < _nRho; iRho++ )
337 {
338 for ( int iTheta = 0; iTheta < _nTheta; iTheta++ )
339 {
340 if ( hough_trans_CS_peak[iTheta][iRho] == 1 )
341 {
342 hough_trans_CS_peak[iTheta][iRho] = 2;
343 for ( int ar = iTheta - 1; ar <= iTheta + 1; ar++ )
344 {
345 for ( int rx = iRho - 1; rx <= iRho + 1; rx++ )
346 {
347 int ax;
348 if ( ar < 0 ) { ax = ar + _nTheta; }
349 else if ( ar >= _nTheta ) { ax = ar - _nTheta; }
350 else { ax = ar; }
351 if ( ( ax != iTheta || rx != iRho ) && rx >= 0 && rx < _nRho )
352 {
353 if ( hough_trans_CS_peak[ax][rx] == 1 ) { hough_trans_CS_peak[ax][rx] = 0; }
354 }
355 }
356 }
357 }
358 if ( hough_trans_CS_peak[iTheta][iRho] == 2 )
359 {
360 int peak_num = _houghPeakList.size();
361 // _houghPeakList.push_back(
362 // HoughPeak(_houghSpace->GetBinContent(iTheta+1,iRho+1),iTheta,iRho,exTheta(iTheta,theta_left,theta_right,m_N2),exRho(iRho,rho_down,rho_up,m_N2),true,peak_num+1,_charge)
363 //);//store peak
364 _houghPeakList.push_back(
365 HoughPeak( _houghSpace->GetBinContent( iTheta + 1, iRho + 1 ), iTheta, iRho,
366 exTheta( iTheta, theta_left, theta_right, m_N2 ),
367 exRho( iRho, rho_down, rho_up, m_N2 ), true, peak_num + 1,
368 _charge ) ); // store peak
369 peakNum_Merge++;
370 }
371 }
372 }
373 return peakNum_Merge;
374}
375
376bool less_hits_in_peak( const HoughPeak& peaka, const HoughPeak& peakb ) {
377 return peaka.peakHeight() > peakb.peakHeight();
378}
379void HoughMap::sortPeaks() {
380 std::sort( _houghPeakList.begin(), _houghPeakList.end(), less_hits_in_peak );
381}
382double HoughMap::exRho( int irho, double rhomin, double rhomax, int n ) {
383 // double rho = _rhoMin+(irho+1/2.)*(_rhoMax-_rhoMin)/_nRho;
384 double rho = rhomin + ( irho + 1 / 2. ) * ( rhomax - rhomin ) / n;
385 return rho;
386}
387double HoughMap::exTheta( int itheta, double thetamin, double thetamax, int n ) {
388 double theta = thetamin + ( itheta + 1 / 2. ) * ( thetamax - thetamin ) / n;
389 return theta;
390}
391// int HoughMap::exRhoBin(double rho){
392// int rhobin = ( (int)(rho-_rhoMin)/((_rhoMax-_rhoMin)/_nRho) );
393// return rhobin;
394// }
395// int HoughMap::exThetaBin(double theta){
396// int thetabin = (int)( (theta-_thetaMin)/((_thetaMax-_thetaMin)/_nTheta) );
397// return thetabin;
398// }
399
400void HoughMap::candiTrack() {
401 if ( _houghPeakList.size() == 0 ) return;
402 // cout<<"size "<<_houghPeakList.size()<<endl;
403 for ( int itrack = 0; itrack < _houghPeakList.size(); itrack++ )
404 {
405 // maqm if( _houghPeakList[itrack].getisCandiTrack()==true ) combineNeighbor(itrack);
406 // //if track is true do combine else continue;
407
408 for ( int ipeak = itrack + 1; ipeak < _houghPeakList.size(); ipeak++ )
409 {
410 if ( m_debug > 0 ) cout << " compare track peak : " << itrack << " " << ipeak << endl;
411 compareTrack_and_Peak( _houghTrackList.back(), _houghPeakList[ipeak] );
412 }
413 }
414}
415/*
416 void HoughMap::combineNeighbor(int ipeak){
417//get the hitlist in the exact peak
418// cout<<" ipeak "<<ipeak<<endl;
419int theta=_houghPeakList[ipeak].getThetaBin();
420int rho =_houghPeakList[ipeak].getRhoBin();
421vector< const HoughHit* > centerHitList = _mapHitList[theta][rho];
422for (int px=theta-_peakWidth; px<=theta+_peakWidth; px++) {
423for (int py=rho-_peakHigh; py<=rho+_peakHigh; py++) {
424int ax;
425if (px<0) { ax=px+_nTheta; }
426else if (px>=_nTheta) { ax=px-_nTheta; }
427else { ax=px; }
428if ( (ax!=theta|| py!=rho) && py>=0 && py<_nRho) combine_two_cells(centerHitList,ax,py);
429}
430}
431_houghTrackList.push_back( HoughTrack(_houghPeakList[ipeak],centerHitList , Rho,Theta) );
432}
433
434void HoughMap::combine_two_cells(vector< const HoughHit* > &centerHitList,int ax,int py){
435//cout<<"combine ("<<ax<<","<<py<<endl;
436vector< const HoughHit* > aroundHitList_xy= _mapHitList[ax][py];
437int size_of_center=centerHitList.size();
438int size_of_around=aroundHitList_xy.size();
439
440for(int i=0;i<size_of_around;i++){
441int same_hit=0;
442for(int j=0;j<size_of_center;j++){
443if( centerHitList[j]->digi()==aroundHitList_xy[i]->digi() ) {same_hit=1;break;}
444}
445if(same_hit==0) {
446centerHitList.push_back(aroundHitList_xy[i]);
447// cout<<"push back
448hit("<<aroundHitList_xy[i]->getLayerId()<<","<<aroundHitList_xy[i]->getWireId()<<")"<<endl;
449}
450}
451}
452*/
453
454void HoughMap::compareTrack_and_Peak( HoughTrack& track, HoughPeak& peak ) {
455 int sameHit = 0;
456 int sizeoftrack = track.getHoughHitList().size();
457 int sizeofpeak = peak.getHoughHitList().size();
458 for ( int i = 0; i < sizeoftrack; i++ )
459 {
460 for ( int j = 0; j < sizeofpeak; j++ )
461 {
462 // cout<<" debug digi ("<< ((track.getHoughHitList())[i])->getLayerId()<<"
463 // ,"<<((track.getHoughHitList())[i])->getWireId() <<") ("<<
464 // ((peak.getHoughHitList())[j])->getLayerId()<<"
465 // ,"<<((peak.getHoughHitList())[j])->getWireId()<<" )"<<endl;
466 if ( ( ( track.getHoughHitList() )[i] ).digi() ==
467 ( ( peak.getHoughHitList() )[j] )->digi() )
468 sameHit++;
469 }
470 }
471 int rho_track = track.getRho();
472 int theta_track = track.getTheta();
473 int rho_peak = peak.getRho();
474 int theta_peak = peak.getTheta();
475 if ( m_debug > 0 )
476 cout << "same hit : " << (double)sameHit / peak.getHoughHitList().size() << endl;
477 // if( sameHit>_hitpro*peak.getHoughHitList().size() || (fabs(rho_track-rho_peak)< 0.3 &&
478 // fabs(theta_track-theta_peak)< 0.3) )
479 if ( sameHit > _hitpro * peak.getHoughHitList().size() )
480 {
481 if ( m_debug > 0 ) cout << "DEBUG peak is out " << peak.getPeakNum() << endl;
482 peak.setisCandiTrack( false );
483 // combineTrack_and_Peak(track,peak);
484 }
485 else if ( m_debug > 0 ) cout << " DEBUG peak is reserve " << peak.getPeakNum() << endl;
486}
487
489 cout << "Print Track in HoughMap: " << endl;
490 vector<HoughTrack>::iterator iter = _houghTrackList.begin();
491 for ( int i = 0; iter != _houghTrackList.end(); iter++, i++ )
492 {
493 cout << "Print Track" << i << endl;
494 ( *iter ).printRecHit();
495 }
496}
497
498void HoughMap::loopPeak( double thetabin, double rhobin, int iTheta, int iRho ) {
499 int binx, biny, binz;
500 int ntheta = m_N2;
501 int nrho = m_N2;
502 double theta_left = thetabin - ( 1 / 2. ) * ( M_PI / _nTheta );
503 double theta_right = thetabin + ( 1 / 2. ) * ( M_PI / _nTheta );
504 double rho_down = rhobin - ( 1 / 2. ) * ( ( 2 * _rhoMax ) / _nRho );
505 double rho_up = rhobin + ( 1 / 2. ) * ( ( 2 * _rhoMax ) / _nRho );
506 // cout<<"binx biny "<<binx<<" "<<biny<<endl;
507 std::vector<HoughHit>::iterator iter = _hitList.getList().begin();
508 vector<vector<int>> vec_hist( nrho, vector<int>( ntheta, 0 ) );
509 for ( int itheta = 0; itheta < ntheta; itheta++ )
510 {
511 for ( int irho = 0; irho < nrho; irho++ ) { vec_hist[itheta][irho] = 0; }
512 }
513
514 for ( ; iter != _hitList.getList().end(); iter++ )
515 {
516 HoughHit* hit = &( *iter );
517 if ( _mapHit == 1 && hit->getSlayerType() != 0 ) continue;
518 if ( hit->driftTime() > 1000 ) continue; // to big hit ,maybe error hit
519 double drift_CF = hit->getR();
520
521 // from 0 to M_PI
522 hit->makeCir( m_N2, theta_left, theta_right, drift_CF ); // N2
523 for ( int ni = 0; ni < m_N2; ni++ )
524 {
525 double theta = hit->getCir( ni ).getTheta();
526 double rho = hit->getCir( ni ).getRho();
527 double slantOfLine = hit->getCir( ni ).getSlant();
528 int chargeOfHitOnCir = ( slantOfLine / fabs( slantOfLine ) ) * ( rho / fabs( rho ) );
529 if ( chargeOfHitOnCir == _charge ) continue;
530 if ( fabs( slantOfLine ) < 0.03 ) continue;
531 //
532 if ( theta <= theta_left || theta >= theta_right ) continue;
533 if ( rho <= rho_down || rho >= rho_up ) continue;
534 int rhobinNum = (int)( ( rho - rho_down ) / ( ( rho_up - rho_down ) / m_N2 ) );
535 int thetabinNum =
536 (int)( ( theta - theta_left ) / ( ( theta_right - theta_left ) / m_N2 ) );
537 vec_hist[thetabinNum][rhobinNum]++;
538 // hist[thetabinNum+iTheta*ntheta][rhobinNum+iRho*nrho]++;
539 }
540
541 // from M_PI to 2*M_PI
542 hit->makeCir( m_N2, theta_left + M_PI, theta_right + M_PI, drift_CF ); // N2
543 for ( int ni = 0; ni < m_N2; ni++ )
544 {
545 double theta = hit->getCir( ni ).getTheta();
546 double rho = hit->getCir( ni ).getRho();
547 double slantOfLine = hit->getCir( ni ).getSlant();
548 int chargeOfHitOnCir = ( slantOfLine / fabs( slantOfLine ) ) * ( rho / fabs( rho ) );
549 if ( chargeOfHitOnCir == _charge ) continue;
550 if ( fabs( slantOfLine ) < 0.03 ) continue;
551 //
552 if ( theta <= theta_left || theta >= theta_right ) continue;
553 if ( rho <= rho_down || rho >= rho_up ) continue;
554 int rhobinNum = (int)( ( rho - rho_down ) / ( ( rho_up - rho_down ) / m_N2 ) );
555 int thetabinNum =
556 (int)( ( theta - theta_left ) / ( ( theta_right - theta_left ) / m_N2 ) );
557 vec_hist[thetabinNum][rhobinNum]++;
558 // hist[thetabinNum+iTheta*ntheta][rhobinNum+iRho*nrho]++;
559 // cout<<"("<<thetabinNum+iTheta*ntheta<<","<<rhobinNum+iRho*nrho<<"):
560 // "<<hist[thetabinNum+iTheta*ntheta][rhobinNum+iRho*nrho]<<endl;
561 }
562 } // loop over hit
563
564 findPeaks( vec_hist, theta_left, theta_right, rho_down, rho_up );
565}
566
567/*
568 void HoughMap::gravity(){
569 int binx,biny,binz;
570 _houghSpace->GetMaximumBin(binx,biny,binz);
571 double thetabin = _houghSpace->GetXaxis()->GetBinCenter(binx);
572 double rhobin = _houghSpace->GetYaxis()->GetBinCenter(biny);
573 int ntheta=15;
574 int nrho=10;
575 double theta_left = thetabin-(ntheta+1/2.)*(M_PI/_nTheta);
576 double theta_right= thetabin+(ntheta+1/2.)*(M_PI/_nTheta);
577 double rho_down= rhobin-(nrho+1/2.)*((2*_rhoMax)/_nRho);
578 double rho_up = rhobin+(nrho+1/2.)*((2*_rhoMax)/_nRho);
579 int NbinRho=m_N2;
580 int NbinTheta=m_N2;
581 std::vector<HoughHit>::iterator iter = _hitList.getList().begin();
582 TH2D *_houghSpace2 = new
583 TH2D("houghspace2","houghspace2",NbinTheta,theta_left,theta_right,NbinRho,rho_down,rho_up);
584 //N2 for(; iter!= _hitList.getList().end(); iter++){ HoughHit *hit = &(*iter); if(
585 _mapHit==1 && hit->getSlayerType()!=0 ) continue; double drift_CF = hit->getRTruth();
586 hit->makeCir(NbinTheta,theta_left,theta_right,drift_CF); //N2
587 for( int ni=0;ni<NbinTheta;ni++){
588 double theta = hit->getCir(ni).getTheta();
589 double rho = hit->getCir(ni).getRho();
590 double slantOfLine = hit->getCir(ni).getSlant();
591 int chargeOfHitOnCir = (slantOfLine/fabs(slantOfLine)) * (rho/fabs(rho));
592 if( chargeOfHitOnCir == _charge ) continue;
593 if( fabs(slantOfLine)<0.03 ) continue;
594 _houghSpace2->Fill(theta,rho);
595 }
596 }
597 for (int iRho=0; iRho<NbinRho; iRho++) {
598 for (int iTheta=0; iTheta<NbinTheta; iTheta++) {
599 int z5=_houghSpace2->GetBinContent(iTheta+1,iRho+1);
600 _houghS2[iTheta][iRho]=z5;
601 }
602 }
603 int binx2,biny2,binz2;
604 _houghSpace2->GetMaximumBin(binx2,biny2,binz2);
605 double thetabin2 = _houghSpace2->GetXaxis()->GetBinCenter(binx2);
606 double rhobin2 = _houghSpace2->GetYaxis()->GetBinCenter(biny2);
607 Theta=thetabin2;
608 Rho=rhobin2;
609 Height=_houghSpace2->GetBinContent(binx2,biny2);
610 delete _houghSpace2;
611 }
612 */
613
615 int binx, biny, binz;
616 _houghSpace->GetMaximumBin( binx, biny, binz );
617 double thetabin = _houghSpace->GetXaxis()->GetBinCenter( binx );
618 double rhobin = _houghSpace->GetYaxis()->GetBinCenter( biny );
619 vector<int> vec_layer;
620 std::vector<HoughHit>::iterator iter1 = _hitList.getList().begin();
621 for ( ; iter1 != _hitList.getList().end(); iter1++ )
622 {
623 if ( ( *iter1 ).getSlayerType() != 0 || ( *iter1 ).getStyle() != 0 ||
624 ( *iter1 ).getCirList() != 0 )
625 continue;
626 vec_layer.push_back( ( *iter1 ).getLayerId() );
627 }
628
629 if ( vec_layer.size() == 0 ) return;
630 vector<int>::iterator laymax = max_element( vec_layer.begin(), vec_layer.end() );
631 int maxLayer = *laymax;
632 m_maxlayer = maxLayer;
633 // cout<<"max layer "<<maxLayer<<endl;
634
635 vector<int>::iterator iterlay = vec_layer.begin();
636 for ( ; iterlay != vec_layer.end(); iterlay++ )
637 {
638 if ( *iterlay == *laymax )
639 {
640 vec_layer.erase( laymax );
641 iterlay--;
642 }
643 }
644 vector<int>::iterator laymax2 = max_element( vec_layer.begin(), vec_layer.end() );
645 int maxLayer2 = *laymax2;
646 // cout<<"max layer2 "<<maxLayer2<<endl;
647
648 std::vector<HoughHit>::iterator iter = _hitList.getList().begin();
649 for ( ; iter != _hitList.getList().end(); iter++ )
650 {
651 HoughHit* hit = &( *iter );
652 if ( hit->getSlayerType() != 0 || hit->getStyle() != 0 || hit->getCirList() != 0 )
653 continue;
654 double slantOfLine = hit->getV() * cos( thetabin ) - hit->getU() * sin( thetabin );
655 // cout<<"("<<hit->getLayerId()<<","<<hit->getWireId()<<") "<< slantOfLine<<endl;
656 if ( hit->getLayerId() == maxLayer || hit->getLayerId() == maxLayer2 )
657 { maxlayer_slant.push_back( slantOfLine ); }
658 else
659 {
660 nomaxlayer_slant.push_back( slantOfLine );
661 nomaxlayerid.push_back( hit->getLayerId() );
662 }
663 }
664}
665
666void HoughMap::cald_layer() {
667 // in truth
668 double k, b, theta, rho, x_cross, y_cross;
669 vector<double> vtemp, utemp;
670 std::vector<HoughHit>::iterator iter = _hitList.getList().begin();
671 for ( int iHit = 0; iter != _hitList.getList().end(); iter++, iHit++ )
672 {
673 const HoughHit h = ( *iter );
674 // if( h.getCirList()!=0 ) continue;
675 if ( h.digi()->getTrackIndex() >= 0 && h.getStyle() == 0 && h.getSlayerType() == 0 &&
676 h.getCirList() == 0 && utemp.size() < 10 ) // ??use 2nd half
677 {
678 utemp.push_back( h.getUTruth() );
679 vtemp.push_back( h.getVTruth() );
680 }
681 }
682 Leastfit( utemp, vtemp, k, b );
683 // calcu truth
684 // k,b from truth
685 x_cross = -b / ( k + 1 / k );
686 y_cross = b / ( 1 + k * k );
687 rho = sqrt( x_cross * x_cross + y_cross * y_cross );
688 theta = atan2( y_cross, x_cross );
689 // Rho = rho; //use truth rho, theta
690 // Theta =theta;
691 //
692 double cirr_track = fabs( 1. / ( Rho ) );
693 double cirx_track = ( 1. / Rho ) * cos( Theta );
694 double ciry_track = ( 1. / Rho ) * sin( Theta );
695 // cout<<"track center position "<<cirx_track<<" "<<ciry_track<<endl;
696 std::vector<HoughHit>::iterator iter0 = _hitList.getList().begin();
697 for ( ; iter0 != _hitList.getList().end(); iter0++ )
698 {
699 HoughHit* hit = &( *iter0 );
700 if ( hit->getSlayerType() != 0 ) continue;
701 // if( hit->getCirList()!=0 ) continue; // use in learn distribute
702 // double cirr_hit = hit->getDriftDistTruth();
703 double cirx_hit = hit->getMidX();
704 double ciry_hit = hit->getMidY();
705 double cirr_hit = hit->getDriftDist();
706 double l1l2 = sqrt( ( cirx_hit - cirx_track ) * ( cirx_hit - cirx_track ) +
707 ( ciry_hit - ciry_track ) * ( ciry_hit - ciry_track ) );
708 double deltaD = 1.e9; // add initialize 25-05-15
709 if ( l1l2 > cirr_track ) deltaD = l1l2 - cirr_track - cirr_hit;
710 if ( l1l2 <= cirr_track ) deltaD = l1l2 - cirr_track + cirr_hit;
711 hit->setDeltaD( deltaD );
712 // cal flight length
713
714 double theta_temp;
715 double l_temp = 1.e9; // add initialize 25-05-15
716 if ( cirx_track == 0 || cirx_hit - cirx_track == 0 ) { theta_temp = 0; }
717 else
718 {
719 theta_temp = M_PI - atan2( ciry_hit - ciry_track, cirx_hit - cirx_track ) +
720 atan2( ciry_track, cirx_track );
721 if ( theta_temp > 2 * M_PI ) { theta_temp = theta_temp - 2 * M_PI; }
722 if ( theta_temp < 0 ) { theta_temp = theta_temp + 2 * M_PI; }
723 }
724 // cout<<" charge "<<_charge <<" "<<theta_temp<<endl;
725 if ( _charge == -1 ) { l_temp = cirr_track * theta_temp; }
726 if ( _charge == 1 )
727 {
728 theta_temp = 2 * M_PI - theta_temp;
729 l_temp = cirr_track * ( theta_temp );
730 }
731 // cout<<"("<<hit->getLayerId()<<","<<hit->getWireId()<<") "<<l_temp<<endl;
732 hit->setFltLen( l_temp );
733
734 // cout<<"int map deltaD: ("<<hit->getLayerId()<<","<<hit->getWireId()<<")"<<
735 // hit->getDeltaD()<<endl;
736 }
737}
738
739void HoughMap::hitFinding() {
740 if ( m_debug > 0 ) cout << "in hit finding " << endl;
741 for ( int ipeak = 0; ipeak < _houghPeakList.size(); ipeak++ )
742 {
743 int hitColNum = _houghPeakList[ipeak].collectHits( _hitList );
744 if ( hitColNum < 5 ) _houghPeakList[ipeak].setisCandiTrack( false );
745 }
746}
747void HoughMap::trackFinder() {
748 if ( m_debug > 0 ) cout << "in track finder " << endl;
749 if ( _houghPeakList.size() == 0 ) return;
750 // cout<<"size "<<_houghPeakList.size()<<endl;
751 for ( int itrack = 0; itrack < _houghPeakList.size(); itrack++ )
752 {
753 if ( _houghPeakList[itrack].getisCandiTrack() ) // if track is true do combine
754 _houghTrackList.push_back(
755 HoughTrack( _houghPeakList[itrack], _houghPeakList[itrack].getHoughHitList(),
756 _houghPeakList[itrack].getRho(), _houghPeakList[itrack].getTheta() ) );
757 else continue;
758
759 for ( int ipeak = itrack + 1; ipeak < _houghPeakList.size(); ipeak++ )
760 { compareTrack_and_Peak( _houghTrackList.back(), _houghPeakList[ipeak] ); }
761 }
762}
763void HoughMap::Leastfit( vector<double> u, vector<double> v, double& k, double& b ) {
764 int N = u.size();
765 double* x = new double[N];
766 double* y = new double[N];
767 for ( int i = 0; i < N; i++ )
768 {
769 x[i] = u[i];
770 y[i] = v[i];
771 }
772
773 TF1* fpol1 = new TF1( "fpol1", "pol1", -50, 50 );
774 TGraph* tg = new TGraph( N, x, y );
775 tg->Fit( "fpol1", "QN" );
776 double ktemp = fpol1->GetParameter( 1 );
777 double btemp = fpol1->GetParameter( 0 );
778 k = ktemp;
779 b = btemp;
780 delete[] x;
781 delete[] y;
782 delete fpol1;
783 delete tg;
784}
785void HoughMap::mapDev( vector<vector<int>> vec_hist, double& aver, double& sigma ) {
786 int count_use = 0;
787 double sum = 0;
788 double sum2 = 0;
789 for ( int i = 0; i < m_N2; i++ )
790 {
791 for ( int j = 0; j < m_N2; j++ )
792 {
793 int count = vec_hist[i][j];
794 if ( count != 0 )
795 {
796 count_use++;
797 sum += count;
798 sum2 += count * count;
799 }
800 }
801 }
802 aver = sum / count_use;
803 sigma = sqrt( sum2 / count_use - aver * aver );
804}
805void HoughMap::mapDev( TH2D* houghspace, double& aver, double& sigma ) {
806 int count_use = 0;
807 double sum = 0;
808 double sum2 = 0;
809 for ( int i = 0; i < m_N1; i++ )
810 {
811 for ( int j = 0; j < m_N1; j++ )
812 {
813 int count = houghspace->GetBinContent( i + 1, j + 1 );
814 if ( count != 0 )
815 {
816 count_use++;
817 sum += count;
818 sum2 += count * count;
819 }
820 }
821 }
822 aver = sum / count_use;
823 sigma = sqrt( sum2 / count_use - aver * aver );
824}
const Int_t n
Double_t x[10]
DOUBLE_PRECISION count[3]
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
bool less_hits_in_peak(const HoughPeak &peaka, const HoughPeak &peakb)
Definition HoughMap.cxx:376
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition KarLud.h:35
#define M_PI
Definition TConstant.h:4
double getSlant() const
Definition CFCir.h:16
double getTheta() const
Definition CFCir.h:14
double getRho() const
Definition CFCir.h:15
const std::vector< HoughHit > & getList() const
double getR() const
Definition HoughHit.h:72
double getV() const
Definition HoughHit.h:71
const MdcDigi * digi() const
Definition HoughHit.h:53
double getUTruth() const
Definition HoughHit.h:90
CFCir getCir(int i) const
Definition HoughHit.h:47
int getCirList() const
Definition HoughHit.h:102
void setFltLen(double flt)
Definition HoughHit.h:99
int getSlayerType() const
Definition HoughHit.h:62
double driftTime() const
Definition HoughHit.cxx:170
double getDriftDist() const
Definition HoughHit.h:67
double getMidY() const
Definition HoughHit.h:59
void setDeltaD(double d)
Definition HoughHit.h:98
double getU() const
Definition HoughHit.h:70
double getMidX() const
Definition HoughHit.h:58
int getStyle() const
Definition HoughHit.h:103
void makeCir(int n, double phi_begin, double phi_last, double r)
Definition HoughHit.cxx:243
int getLayerId() const
Definition HoughHit.h:60
double getVTruth() const
Definition HoughHit.h:91
void printPeak()
Definition HoughMap.cxx:133
void clearMap()
Definition HoughMap.cxx:121
double Rho
Definition HoughMap.h:65
void select_slant()
Definition HoughMap.cxx:614
HoughMap(int charge, HoughHitList &houghHitList, int mapHit, int ntheta, int nrho, double rhoMin, double rhoMaxi, int peakWidth, int peakHigh, double hitpro)
Definition HoughMap.cxx:17
void doMap()
Definition HoughMap.cxx:99
double exRho(int, double, double, int)
Definition HoughMap.cxx:382
static int m_useHalfCir
Definition HoughMap.h:60
void printTrack()
Definition HoughMap.cxx:488
static int m_N2
Definition HoughMap.h:62
double Theta
Definition HoughMap.h:66
static int m_N1
Definition HoughMap.h:61
static int m_debug
Definition HoughMap.h:59
double exTheta(int, double, double, int)
Definition HoughMap.cxx:387
double getTheta() const
Definition HoughPeak.h:28
void setisCandiTrack(bool is)
Definition HoughPeak.h:32
vector< const HoughHit * > getHoughHitList() const
Definition HoughPeak.h:23
int getPeakNum() const
Definition HoughPeak.h:25
double getRho() const
Definition HoughPeak.h:29
int peakHeight() const
Definition HoughPeak.h:24
recHitCol & getHoughHitList()
Definition HoughTrack.h:32
double getRho() const
Definition HoughTrack.h:41
double getTheta() const
Definition HoughTrack.h:42
int getTrackIndex() const
Definition RawData.cxx:38