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