18 double rhoMin,
double rhoMax,
int peakWidth,
int peakHigh,
20 _hitList = houghHitList;
28 _peakWidth = peakWidth;
60 _houghSpace =
new TH2D(
"houghspace",
"houghspace", _nTheta, _thetaMin, _thetaMax, _nRho,
63 _houghSpace =
new TH2D(
"houghspace2",
"houghspace2", _nTheta, _thetaMin, _thetaMax, _nRho,
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;
112 cout <<
" after sort " << endl;
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++ )
138 cout <<
"count of Peak on HoughMap: " << ( *iter ).getHoughHitList().size() << endl;
139 ( *iter ).printAllHit();
144void HoughMap::buildMap() {
145 if (
m_debug > 0 ) cout <<
"in build map " << endl;
148 std::vector<HoughHit>::iterator
iter = _hitList.
getList().begin();
155 double drift_CF = hit->
getR();
156 hit->
makeCir( 2 * _nTheta, 0, 2 *
M_PI, drift_CF );
157 for (
int ni = 0; ni < 2 *
m_N1; ni++ )
159 double binwidth =
M_PI / _nTheta;
160 double binhigh = ( _rhoMax - _rhoMin ) / _nRho;
163 if ( fabs( rho ) >= _rhoMax )
continue;
165 int chargeOfHitOnCir = ( slantOfLine / fabs( slantOfLine ) ) * ( rho / fabs( rho ) );
166 if ( chargeOfHitOnCir == _charge )
continue;
167 if ( fabs( slantOfLine ) < 0.03 )
continue;
168 _houghSpace->Fill( theta, rho );
178 double aver( 0 ), sigma( 0 );
179 mapDev( _houghSpace, aver, sigma );
181 for (
int iTheta = 0; iTheta < _nTheta; iTheta++ )
183 for (
int iRho = 0; iRho < _nRho; iRho++ )
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;
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;
197 if ( z >= minCount_Cut ) loopPeak( thetabin, rhobin, iTheta, iRho );
223void HoughMap::findPeaks( vector<vector<int>> vec_hist,
double theta_left,
double theta_right,
224 double rho_down,
double rho_up ) {
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 );
242 int** hough_trans_CS_peak =
new int*[_nTheta];
243 for (
int i = 0; i < _nTheta; i++ )
245 hough_trans_CS_peak[i] =
new int[_nRho];
246 for (
int j = 0; j < _nRho; j++ ) { hough_trans_CS_peak[i][j] = -999; }
250 for (
int iRho = 0; iRho < _nRho; iRho++ )
252 for (
int iTheta = 0; iTheta < _nTheta; iTheta++ )
255 int height = vec_hist[iTheta][iRho];
256 if ( height < minCount_Cut )
258 hough_trans_CS_peak[iTheta][iRho] = 0;
263 for (
int ar = iTheta - 1; ar <= iTheta + 1; ar++ )
265 for (
int rx = iRho - 1; rx <= iRho + 1; rx++ )
268 if ( ar < 0 ) { ax = ar + _nTheta; }
269 else if ( ar >= _nTheta ) { ax = ar - _nTheta; }
271 if ( ( ax != iTheta || rx != iRho ) && rx >= 0 && rx < _nRho )
274 int heightThisBin = vec_hist[ax][rx];
275 if ( heightThisBin > max_around ) { max_around = heightThisBin; }
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; }
286 int peakNum_Merge = 0;
287 for (
int iRho = 0; iRho < _nRho; iRho++ )
289 for (
int iTheta = 0; iTheta < _nTheta; iTheta++ )
291 if ( hough_trans_CS_peak[iTheta][iRho] == 1 )
293 hough_trans_CS_peak[iTheta][iRho] = 2;
294 for (
int ar = iTheta - 1; ar <= iTheta + 1; ar++ )
296 for (
int rx = iRho - 1; rx <= iRho + 1; rx++ )
299 if ( ar < 0 ) { ax = ar + _nTheta; }
300 else if ( ar >= _nTheta ) { ax = ar - _nTheta; }
302 if ( ( ax != iTheta || rx != iRho ) && rx >= 0 && rx < _nRho )
304 if ( hough_trans_CS_peak[ax][rx] == 1 ) { hough_trans_CS_peak[ax][rx] = 0; }
309 if ( hough_trans_CS_peak[iTheta][iRho] == 2 )
311 int peak_num = _houghPeakList.size();
315 _houghPeakList.push_back( HoughPeak( vec_hist[iTheta][iRho], iTheta, iRho,
317 exRho( iRho, rho_down, rho_up,
m_N2 ),
true,
318 peak_num + 1, _charge ) );
326 for (
int i = 0; i < _nTheta; i++ ) {
delete[] hough_trans_CS_peak[i]; }
327 delete[] hough_trans_CS_peak;
330int HoughMap::mergeNeighbor(
int** hough_trans_CS_peak,
double theta_left,
double theta_right,
331 double rho_down,
double rho_up ) {
335 int peakNum_Merge = 0;
336 for (
int iRho = 0; iRho < _nRho; iRho++ )
338 for (
int iTheta = 0; iTheta < _nTheta; iTheta++ )
340 if ( hough_trans_CS_peak[iTheta][iRho] == 1 )
342 hough_trans_CS_peak[iTheta][iRho] = 2;
343 for (
int ar = iTheta - 1; ar <= iTheta + 1; ar++ )
345 for (
int rx = iRho - 1; rx <= iRho + 1; rx++ )
348 if ( ar < 0 ) { ax = ar + _nTheta; }
349 else if ( ar >= _nTheta ) { ax = ar - _nTheta; }
351 if ( ( ax != iTheta || rx != iRho ) && rx >= 0 && rx < _nRho )
353 if ( hough_trans_CS_peak[ax][rx] == 1 ) { hough_trans_CS_peak[ax][rx] = 0; }
358 if ( hough_trans_CS_peak[iTheta][iRho] == 2 )
360 int peak_num = _houghPeakList.size();
364 _houghPeakList.push_back(
365 HoughPeak( _houghSpace->GetBinContent( iTheta + 1, iRho + 1 ), iTheta, iRho,
367 exRho( iRho, rho_down, rho_up,
m_N2 ),
true, peak_num + 1,
373 return peakNum_Merge;
379void HoughMap::sortPeaks() {
384 double rho = rhomin + ( irho + 1 / 2. ) * ( rhomax - rhomin ) /
n;
388 double theta = thetamin + ( itheta + 1 / 2. ) * ( thetamax - thetamin ) /
n;
400void HoughMap::candiTrack() {
401 if ( _houghPeakList.size() == 0 )
return;
403 for (
int itrack = 0; itrack < _houghPeakList.size(); itrack++ )
408 for (
int ipeak = itrack + 1; ipeak < _houghPeakList.size(); ipeak++ )
410 if (
m_debug > 0 ) cout <<
" compare track peak : " << itrack <<
" " << ipeak << endl;
411 compareTrack_and_Peak( _houghTrackList.back(), _houghPeakList[ipeak] );
458 for (
int i = 0; i < sizeoftrack; i++ )
460 for (
int j = 0; j < sizeofpeak; j++ )
471 int rho_track = track.
getRho();
473 int rho_peak = peak.
getRho();
476 cout <<
"same hit : " << (double)sameHit / peak.
getHoughHitList().size() << endl;
485 else if (
m_debug > 0 ) cout <<
" DEBUG peak is reserve " << peak.
getPeakNum() << endl;
489 cout <<
"Print Track in HoughMap: " << endl;
490 vector<HoughTrack>::iterator
iter = _houghTrackList.begin();
491 for (
int i = 0;
iter != _houghTrackList.end();
iter++, i++ )
493 cout <<
"Print Track" << i << endl;
494 ( *iter ).printRecHit();
498void HoughMap::loopPeak(
double thetabin,
double rhobin,
int iTheta,
int iRho ) {
499 int binx, biny, binz;
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 );
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++ )
511 for (
int irho = 0; irho < nrho; irho++ ) { vec_hist[itheta][irho] = 0; }
514 for ( ;
iter != _hitList.getList().end();
iter++ )
516 HoughHit* hit = &( *iter );
519 double drift_CF = hit->
getR();
522 hit->
makeCir(
m_N2, theta_left, theta_right, drift_CF );
523 for (
int ni = 0; ni <
m_N2; ni++ )
528 int chargeOfHitOnCir = ( slantOfLine / fabs( slantOfLine ) ) * ( rho / fabs( rho ) );
529 if ( chargeOfHitOnCir == _charge )
continue;
530 if ( fabs( slantOfLine ) < 0.03 )
continue;
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 ) );
536 (int)( ( theta - theta_left ) / ( ( theta_right - theta_left ) /
m_N2 ) );
537 vec_hist[thetabinNum][rhobinNum]++;
543 for (
int ni = 0; ni <
m_N2; ni++ )
548 int chargeOfHitOnCir = ( slantOfLine / fabs( slantOfLine ) ) * ( rho / fabs( rho ) );
549 if ( chargeOfHitOnCir == _charge )
continue;
550 if ( fabs( slantOfLine ) < 0.03 )
continue;
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 ) );
556 (int)( ( theta - theta_left ) / ( ( theta_right - theta_left ) /
m_N2 ) );
557 vec_hist[thetabinNum][rhobinNum]++;
564 findPeaks( vec_hist, theta_left, theta_right, rho_down, rho_up );
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++ )
623 if ( ( *iter1 ).getSlayerType() != 0 || ( *iter1 ).getStyle() != 0 ||
624 ( *iter1 ).getCirList() != 0 )
626 vec_layer.push_back( ( *iter1 ).getLayerId() );
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;
635 vector<int>::iterator iterlay = vec_layer.begin();
636 for ( ; iterlay != vec_layer.end(); iterlay++ )
638 if ( *iterlay == *laymax )
640 vec_layer.erase( laymax );
644 vector<int>::iterator laymax2 = max_element( vec_layer.begin(), vec_layer.end() );
645 int maxLayer2 = *laymax2;
648 std::vector<HoughHit>::iterator
iter = _hitList.getList().begin();
649 for ( ;
iter != _hitList.getList().end();
iter++ )
654 double slantOfLine = hit->
getV() *
cos( thetabin ) - hit->
getU() *
sin( thetabin );
657 { maxlayer_slant.push_back( slantOfLine ); }
660 nomaxlayer_slant.push_back( slantOfLine );
666void HoughMap::cald_layer() {
668 double k, b, theta, rho, x_cross, y_cross;
669 vector<double> vtemp, utemp;
670 std::vector<HoughHit>::iterator
iter = _hitList.
getList().begin();
682 Leastfit( utemp, vtemp, k, b );
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 );
692 double cirr_track = fabs( 1. / (
Rho ) );
696 std::vector<HoughHit>::iterator iter0 = _hitList.getList().begin();
697 for ( ; iter0 != _hitList.getList().end(); iter0++ )
699 HoughHit* hit = &( *iter0 );
703 double cirx_hit = hit->
getMidX();
704 double ciry_hit = hit->
getMidY();
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;
709 if ( l1l2 > cirr_track ) deltaD = l1l2 - cirr_track - cirr_hit;
710 if ( l1l2 <= cirr_track ) deltaD = l1l2 - cirr_track + cirr_hit;
715 double l_temp = 1.e9;
716 if ( cirx_track == 0 || cirx_hit - cirx_track == 0 ) { theta_temp = 0; }
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; }
725 if ( _charge == -1 ) { l_temp = cirr_track * theta_temp; }
728 theta_temp = 2 *
M_PI - theta_temp;
729 l_temp = cirr_track * ( theta_temp );
739void HoughMap::hitFinding() {
740 if (
m_debug > 0 ) cout <<
"in hit finding " << endl;
741 for (
int ipeak = 0; ipeak < _houghPeakList.size(); ipeak++ )
743 int hitColNum = _houghPeakList[ipeak].collectHits( _hitList );
744 if ( hitColNum < 5 ) _houghPeakList[ipeak].setisCandiTrack(
false );
747void HoughMap::trackFinder() {
748 if (
m_debug > 0 ) cout <<
"in track finder " << endl;
749 if ( _houghPeakList.size() == 0 )
return;
751 for (
int itrack = 0; itrack < _houghPeakList.size(); itrack++ )
753 if ( _houghPeakList[itrack].getisCandiTrack() )
754 _houghTrackList.push_back(
755 HoughTrack( _houghPeakList[itrack], _houghPeakList[itrack].getHoughHitList(),
756 _houghPeakList[itrack].getRho(), _houghPeakList[itrack].getTheta() ) );
759 for (
int ipeak = itrack + 1; ipeak < _houghPeakList.size(); ipeak++ )
760 { compareTrack_and_Peak( _houghTrackList.back(), _houghPeakList[ipeak] ); }
763void HoughMap::Leastfit( vector<double> u, vector<double>
v,
double& k,
double& b ) {
765 double*
x =
new double[N];
766 double* y =
new double[N];
767 for (
int i = 0; i < N; i++ )
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 );
785void HoughMap::mapDev( vector<vector<int>> vec_hist,
double& aver,
double& sigma ) {
789 for (
int i = 0; i <
m_N2; i++ )
791 for (
int j = 0; j <
m_N2; j++ )
793 int count = vec_hist[i][j];
802 aver = sum / count_use;
803 sigma = sqrt( sum2 / count_use - aver * aver );
805void HoughMap::mapDev( TH2D* houghspace,
double& aver,
double& sigma ) {
809 for (
int i = 0; i <
m_N1; i++ )
811 for (
int j = 0; j <
m_N1; j++ )
813 int count = houghspace->GetBinContent( i + 1, j + 1 );
822 aver = sum / count_use;
823 sigma = sqrt( sum2 / count_use - aver * aver );
DOUBLE_PRECISION count[3]
bool less_hits_in_peak(const HoughPeak &peaka, const HoughPeak &peakb)
double sin(const BesAngle a)
double cos(const BesAngle a)
**********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
const std::vector< HoughHit > & getList() const
const MdcDigi * digi() const
CFCir getCir(int i) const
void setFltLen(double flt)
int getSlayerType() const
double getDriftDist() const
void makeCir(int n, double phi_begin, double phi_last, double r)
HoughMap(int charge, HoughHitList &houghHitList, int mapHit, int ntheta, int nrho, double rhoMin, double rhoMaxi, int peakWidth, int peakHigh, double hitpro)
double exRho(int, double, double, int)
double exTheta(int, double, double, int)
void setisCandiTrack(bool is)
vector< const HoughHit * > getHoughHitList() const
recHitCol & getHoughHitList()
int getTrackIndex() const