1#include "MdcHoughFinder/HoughMap.h"
2#include "MdcHoughFinder/HoughPeak.h"
20HoughMap::HoughMap(
int charge,
HoughHitList &houghHitList,
int mapHit ,
int ntheta,
int nrho,
double rhoMin,
double rhoMax,
int peakWidth,
int peakHigh,
double hitpro){
21 _hitList=houghHitList;
59 if(_charge==-1) _houghSpace =
new TH2D(
"houghspace",
"houghspace",_nTheta,_thetaMin,_thetaMax,_nRho,_rhoMin,_rhoMax);
60 if(_charge==1 ) _houghSpace =
new TH2D(
"houghspace2",
"houghspace2",_nTheta,_thetaMin,_thetaMax,_nRho,_rhoMin,_rhoMax);
68 _mapHit =other._mapHit,
69 _nTheta =other._nTheta,
71 _thetaMin=other._thetaMin,
72 _thetaMax=other._thetaMax,
73 _rhoMin =other._rhoMin,
74 _rhoMax =other._rhoMax,
75 _hitList =other._hitList,
76 _houghPeakList=other._houghPeakList,
77 _houghTrackList=other._houghTrackList,
78 _houghSpace = other._houghSpace,
79 _charge = other._charge;
143void HoughMap::buildMap(){
144 if(
m_debug>0) cout<<
"in build map "<<endl;
148 std::vector<HoughHit>::iterator
iter = _hitList.
getList().begin();
155 double drift_CF = hit->
getR();
158 for(
int ni=0;ni<2*
m_N1;ni++){
159 double binwidth =
M_PI/_nTheta;
160 double binhigh = (_rhoMax-_rhoMin)/_nRho;
164 if( fabs(rho) >=_rhoMax )
continue;
166 int chargeOfHitOnCir = (slantOfLine/fabs(slantOfLine)) * (rho/fabs(rho));
167 if(chargeOfHitOnCir == _charge)
continue;
169 _houghSpace->Fill(theta,rho);
179 double aver(0),sigma(0);
180 mapDev(_houghSpace,aver,sigma);
186 for (
int iTheta=0; iTheta<_nTheta; iTheta++) {
187 for (
int iRho=0; iRho<_nRho; iRho++) {
188 int z=_houghSpace->GetBinContent(iTheta+1,iRho+1);
189 double thetabin = _houghSpace->GetXaxis()->GetBinCenter(iTheta+1);
190 double rhobin = _houghSpace->GetYaxis()->GetBinCenter(iRho+1);
191 double pt = (1/rhobin)/333.567;
193 if(0.06<=pt&&pt<0.07 ) MINCOUNT = 6;
194 if(pt<0.06) MINCOUNT = 5;
195 double minCount_Cut=( aver+4*sigma >MINCOUNT)? (aver+4*sigma):MINCOUNT;
202 if( z>=minCount_Cut) loopPeak(thetabin,rhobin,iTheta,iRho);
212void HoughMap::buildHoughMap(
int x_bin,
double x_min,
double x_max,
int y_bin,
double y_min,
double y_max,
int nPoint,
int peak)
216 string sname = ssname.str();
217 const char * name = sname.c_str() ;
218 _houghMap =
new TH2D(name,name, x_bin, x_min, x_max, y_bin, y_min, y_max);
219 std::vector<HoughHit>::iterator
iter = _hitList.
getList().begin();
221 if((
iter)->getSlayerType()!=0)
continue;
222 if( (
iter)->driftTime()>1000 && (
iter)->driftTime()<0 )
continue;
223 (
iter)->buildMap(x_bin, x_min, x_max, y_bin, y_min, y_max,
m_nPoint2D,_charge);
224 _houghMap->Add((
iter)->getHitMap());
228void HoughMap::clearHoughMap()
230 std::vector<HoughHit>::iterator
iter = _hitList.
getList().begin();
234 if(_houghMap != NULL)
delete _houghMap;
238void HoughMap::findHoughPeaks(vector<HoughPeak>& vecPeak)
240 int binx(0),biny(0),binz(0);
241 double theta(0) , rho(0);
244 int peak = vecPeak.size();
245 _houghMap->GetMaximumBin(binx,biny,binz);
246 height = _houghMap->GetBinContent(binx,biny);
251 _houghMap->GetMaximumBin(binx,biny,binz);
252 theta = _houghMap->GetXaxis()->GetBinCenter(binx);
253 rho = _houghMap->GetYaxis()->GetBinCenter(biny);
254 height = _houghMap->GetBinContent(binx,biny);
262 vecPeak.push_back(
HoughPeak(height,binx,biny,theta,rho,
true,peak,_charge) );
264 std::vector<HoughHit>::iterator
iter = _hitList.
getList().begin();
266 if((
iter)->getHitMap() == NULL)
continue;
267 if((
iter)->getHitMap()->GetBinContent(binx,biny)>0){
268 _houghMap->Add((
iter)->getHitMap(),-1);
276 _houghMap->GetMaximumBin(binx,biny,binz);
277 height = _houghMap->GetBinContent(binx,biny);
288void HoughMap::findPeaks()
295 double x_min = _thetaMin;
296 double x_max = _thetaMax;
297 double y_min = _rhoMin;
298 double y_max = _rhoMax;
299 double dx = (x_max - x_min)/x_bin;
300 double dy = (y_max - y_min)/y_bin;
302 vector<HoughPeak> vecPeak_tmp;
303 buildHoughMap(x_bin, x_min, x_max, y_bin, y_min, y_max,nPoint,peak);
304 findHoughPeaks(vecPeak_tmp);
307 std::vector<HoughPeak>::iterator
iter = vecPeak_tmp.begin();
308 for(;
iter != vecPeak_tmp.end();
iter++){
311 peak =
iter->getPeakNum();
313 x_bin = 10*(2*ext[0]+1);
314 y_bin = 10*(2*ext[1]+1);
315 x_min =
iter->getTheta() - (0.5+ext[0])*dx;
316 x_max =
iter->getTheta() + (0.5+ext[0])*dx;
317 y_min =
iter->getRho() - (0.5+ext[1])*dy;
318 y_max =
iter->getRho() + (0.5+ext[1])*dy;
325 buildHoughMap(x_bin, x_min, x_max, y_bin, y_min, y_max,nPoint,peak);
326 findHoughPeaks(_houghPeakList);
348void HoughMap::loopPeak(
double thetabin,
double rhobin,
int iTheta,
int iRho){
352 double theta_left = thetabin-(5/2.)*(
M_PI/_nTheta);
353 double theta_right= thetabin+(5/2.)*(
M_PI/_nTheta);
354 double rho_down= rhobin-(5/2.)*((2*_rhoMax)/_nRho);
355 double rho_up = rhobin+(5/2.)*((2*_rhoMax)/_nRho);
356 cout<<
"("<<theta_left<<
", "<<theta_right<<
")"<<
" ("<<rho_down<<
", "<<rho_up<<
")"<<endl;
358 vector< vector<int> > vec_hist(nrho,vector<int>(ntheta,0) );
359 for(
int itheta =0;itheta<ntheta;itheta++){
360 for(
int irho=0;irho<nrho;irho++){
361 vec_hist[itheta][irho]=0;
365 std::vector<HoughHit>::iterator
iter = _hitList.
getList().begin();
371 double drift_CF = hit->
getR();
375 hit->
makeCir(
m_N2,theta_left,theta_right,drift_CF);
376 for(
int ni=0;ni<
m_N2;ni++){
380 int chargeOfHitOnCir = (slantOfLine/fabs(slantOfLine)) * (rho/fabs(rho));
381 if(chargeOfHitOnCir == _charge )
continue;
386 if( theta<=theta_left|| theta>=theta_right)
continue;
387 if( rho<=rho_down || rho>=rho_up )
continue;
388 int rhobinNum = (int)( (rho-rho_down)/((rho_up-rho_down)/
m_N2) );
389 int thetabinNum = (int)( (theta-theta_left)/((theta_right-theta_left)/
m_N2) );
390 vec_hist[thetabinNum][rhobinNum]++;
397 for(
int ni=0;ni<
m_N2;ni++){
401 int chargeOfHitOnCir = (slantOfLine/fabs(slantOfLine)) * (rho/fabs(rho));
402 if(chargeOfHitOnCir == _charge )
continue;
405 if( theta<=theta_left|| theta>=theta_right)
continue;
406 if( rho<=rho_down || rho>=rho_up )
continue;
407 int rhobinNum = (int)( (rho-rho_down)/((rho_up-rho_down)/
m_N2) );
408 int thetabinNum = (int)( (theta-theta_left)/((theta_right-theta_left)/
m_N2) );
409 vec_hist[thetabinNum][rhobinNum]++;
416 findPeaks(vec_hist,theta_left,theta_right,rho_down,rho_up);
421void HoughMap::findPeaks(vector< vector<int> > vec_hist,
double theta_left,
double theta_right,
double rho_down,
double rho_up){
423 double rho_peak = 1./2.*(rho_down+rho_up);
424 double pt_peak = (1./rho_peak)/333.567;
425 if (0.06<=pt_peak&&pt_peak<0.07 ) minCount_Cut = 4;
426 if (pt_peak <0.06 ) minCount_Cut = 3;
427 else minCount_Cut = 5;
428 double aver(0),sigma(0);
439 int **hough_trans_CS_peak =
new int*[_nTheta];
440 for(
int i=0; i<_nTheta; i++){
441 hough_trans_CS_peak[i] =
new int[_nRho];
442 for(
int j=0; j<_nRho; j++){ hough_trans_CS_peak[i][j]=-999;}
446 for (
int iRho=0; iRho<_nRho; iRho++) {
447 for (
int iTheta=0; iTheta<_nTheta; iTheta++) {
449 int height = vec_hist[iTheta][iRho];
451 if(height < minCount_Cut) {
452 hough_trans_CS_peak[iTheta][iRho]=0;
457 for (
int ar=iTheta-1; ar<=iTheta+1; ar++) {
458 for (
int rx=iRho-1; rx<=iRho+1; rx++) {
460 if (ar<0) { ax=ar+_nTheta; }
461 else if (ar>=_nTheta) { ax=ar-_nTheta; }
463 if ( (ax!=iTheta || rx!=iRho) && rx>=0 && rx<_nRho) {
465 int heightThisBin = vec_hist[ax][rx];
466 if (heightThisBin>max_around) { max_around=heightThisBin; }
470 if (height<max_around) { hough_trans_CS_peak[iTheta][iRho]=0; }
471 else if (height==max_around) { hough_trans_CS_peak[iTheta][iRho]=1; }
472 else if (height>max_around) { hough_trans_CS_peak[iTheta][iRho]=2; }
478 for (
int iRho=0; iRho<_nRho; iRho++) {
479 for (
int iTheta=0; iTheta<_nTheta; iTheta++) {
480 if (hough_trans_CS_peak[iTheta][iRho]==1) {
481 hough_trans_CS_peak[iTheta][iRho]=2;
482 for (
int ar=iTheta-1; ar<=iTheta+1; ar++) {
483 for (
int rx=iRho-1; rx<=iRho+1; rx++) {
485 if (ar<0) { ax=ar+_nTheta; }
486 else if (ar>=_nTheta) { ax=ar-_nTheta; }
488 if ( (ax!=iTheta || rx!=iRho) && rx>=0 && rx<_nRho) {
489 if (hough_trans_CS_peak[ax][rx]==1) { hough_trans_CS_peak[ax][rx]=0; }
494 if(hough_trans_CS_peak[iTheta][iRho]==2) {
495 int peak_num = _houghPeakList.size();
497 _houghPeakList.push_back(
HoughPeak(vec_hist[iTheta][iRho],iTheta,iRho,
exTheta(iTheta,theta_left,theta_right,
m_N2),
exRho(iRho,rho_down,rho_up,
m_N2),
true,peak_num+1,_charge) );
500 cout<<setw(3)<<iTheta<<setw(3)<<iRho<<setw(5)<<vec_hist[iTheta][iRho]<<setw(12)<<theta_left<<setw(12)<<theta_right<<setw(12)<<rho_down<<setw(12)<<rho_up<<setw(12)<<
exTheta(iTheta,theta_left,theta_right,
m_N2)<<setw(12)<<
exRho(iRho,rho_down,rho_up,
m_N2)<<endl;
506 for(
int i=0; i<_nTheta; i++){
delete []hough_trans_CS_peak[i]; }
507 delete []hough_trans_CS_peak;
605void HoughMap::hitFinding(){
606 if(
m_debug>0) cout<<
"in hit finding "<<endl;
607 for(
int ipeak=0;ipeak<_houghPeakList.size();ipeak++){
608 int hitColNum = _houghPeakList[ipeak].collectHits(_hitList);
609 if( hitColNum < 3 ) _houghPeakList[ipeak].setisCandiTrack(
false);
615void HoughMap::trackFinder(){
616 if(
m_debug>0) cout<<
"in track finder "<<endl;
618 if( _houghPeakList.size()==0 )
return;
620 for(
int itrack=0;itrack<_houghPeakList.size();itrack++){
621 if( _houghPeakList[itrack].getisCandiTrack()==
true ){
622 _houghTrackList.push_back(
HoughTrack(_houghPeakList[itrack],_houghPeakList[itrack].getHoughHitList(),_houghPeakList[itrack].getRho(),_houghPeakList[itrack].getTheta(), trkid) );
626 for(
int ipeak=itrack+1;ipeak<_houghPeakList.size();ipeak++){
627 if(_houghPeakList[ipeak].getisCandiTrack())compareTrack_and_Peak(_houghTrackList.back(),_houghPeakList[ipeak]);
645 for(
int i=0;i<sizeoftrack;i++){
646 for(
int j=0;j<sizeofpeak;j++){
874void HoughMap::sortPeaks(){
880 double rho = rhomin+(irho+1/2.)*(rhomax-rhomin)/
n;
885 double theta= thetamin+(itheta+1/2.)*(thetamax-thetamin)/
n;
889void HoughMap::mapDev(vector< vector<int> > vec_hist,
double& aver ,
double& sigma){
893 for(
int i=0;i<
m_N2;i++){
894 for(
int j=0;j<
m_N2;j++){
895 int count=vec_hist[i][j];
904 sigma=sqrt(sum2/count_use-aver*aver);
907void HoughMap::mapDev(TH2D* houghspace,
double& aver ,
double& sigma){
911 for(
int i=0;i<
m_N1;i++){
912 for(
int j=0;j<
m_N1;j++){
913 int count=houghspace->GetBinContent(i+1,j+1);
923 sigma=sqrt(sum2/count_use-aver*aver);
930double HoughMap::mapDev(TH2D* houghspace,
double nRMS){
934 for(
int i=0;i<
m_N1;i++){
935 for(
int j=0;j<
m_N1;j++){
936 int count=houghspace->GetBinContent(i+1,j+1);
944 double aver(0),rms(0);
947 if(count_use==1) rms = sqrt(sum2/count_use-aver*aver);
948 else rms = sqrt((sum2-count_use*aver*aver)/(count_use-1));
950 double cut = aver + nRMS*rms;
955 cout<<
"Print Peak in HoughMap sumPeak: "<<_houghPeakList.size()<<endl;
957 vector<HoughPeak>::iterator
iter =_houghPeakList.begin();
958 for(
int i=0;
iter!=_houghPeakList.end();
iter++,i++){
967 cout<<
"Print Track in HoughMap: "<<endl;
969 vector<HoughTrack>::iterator
iter =_houghTrackList.begin();
970 for(
int i=0;
iter!=_houghTrackList.end();
iter++,i++){
974 (*iter).printHoughTrack();
975 (*iter).getCenterPeak().print();
bool less_hits_in_peak(const HoughPeak &peaka, const HoughPeak &peakb)
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared cut
int getHitNumA(int) const
const std::vector< HoughHit > & getList() const
CFCir getCir(int i) const
int getSlayerType() const
void makeCir(int n, double phi_begin, double phi_last, double r)
detectorType getDetectorType() const
const RecCgemCluster * getCluster() const
int getPeakNumber() const
double exRho(int, double, double, int)
int getTrackNumber() const
double exTheta(int, double, double, int)
void setisCandiTrack(bool is)
vector< const HoughHit * > getHoughHitList() const
recHitCol & getHoughHitList()