Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

HoughTrackSR.cxx

Go to the documentation of this file.
00001 
00002 // $Id: HoughTrackSR.cxx,v 1.17 2007/01/15 20:02:44 rhatcher Exp $
00003 //
00004 // HoughTrackSR
00005 //
00006 // Author:  R. Lee 2002.01.18
00007 //
00009 
00010 #include <iostream>
00011 #include <string>
00012 #include <cmath>
00013 #include "TMath.h"
00014 
00015 #include "CandTrackSR/HoughTrackSR.h"
00016 #include "MessageService/MsgService.h"
00017 #include "CandTrackSR/TrackClusterSR.h"
00018 #include "RecoBase/LinearFit.h"
00019 
00020 ClassImp(HoughTrackSR)
00021 
00022 //______________________________________________________________________
00023 CVSID("$Id: HoughTrackSR.cxx,v 1.17 2007/01/15 20:02:44 rhatcher Exp $");
00024 
00025 HoughTrackSR::HoughTrackSR(TObjArray clusterlist)
00026 {
00027   fSlopeLim[0] = -20.;
00028   fSlopeLim[1] =  21.;
00029   fInterLim[0] = -10.;
00030   fInterLim[1] =  11.;
00031   fMaxBin=40;
00032   fPeakMin = 4;
00033   fPeakMinFrac = .25;
00034   fPeakMinFracZoom = .75;
00035   fMinInterBinSize = .02;
00036   fClusterList = new TObjArray(clusterlist);
00037   fFillHough = kFALSE;
00038 }
00039 
00040 HoughTrackSR::HoughTrackSR(const HoughTrackSR &oldHT) : TObject(oldHT)
00041 {
00042   fSlopeLim[0] = oldHT.fSlopeLim[0];
00043   fSlopeLim[1] = oldHT.fSlopeLim[1];
00044   fInterLim[0] = oldHT.fInterLim[0];
00045   fInterLim[1] = oldHT.fInterLim[1];
00046   fPeakMin = oldHT.fPeakMin;
00047   fPeakMinFrac = oldHT.fPeakMinFrac;
00048   fPeakMinFracZoom = oldHT.fPeakMinFracZoom;
00049   fMinInterBinSize = oldHT.fMinInterBinSize;
00050   fClusterList = new TObjArray(*(oldHT.fClusterList));
00051   fFillHough = oldHT.fFillHough;
00052 
00053   fXZmean[0] = oldHT.fXZmean[0];
00054   fXZmean[1] = oldHT.fXZmean[1];
00055   fXZrms[0] = oldHT.fXZrms[0];
00056   fXZrms[1] = oldHT.fXZrms[1];
00057   fDSlope = oldHT.fDSlope;
00058   fDInter = oldHT.fDInter;
00059   fMaxBin = oldHT.fMaxBin;
00060   fNBinMax = oldHT.fNBinMax;
00061   fNBinCut = oldHT.fNBinCut;
00062 
00063   for (Int_t im=0; im<fNBin; im++) {
00064     for (Int_t ic=0; ic<fNBin; ic++) {
00065       fHough[im][ic] = oldHT.fHough[im][ic];
00066       fMaxHoughBin[im][ic][0] = oldHT.fMaxHoughBin[im][ic][0];
00067       fMaxHoughBin[im][ic][1] = oldHT.fMaxHoughBin[im][ic][1];
00068     }
00069   }
00070 
00071   fNPeak = oldHT.fNPeak;
00072   fNMaxima = oldHT.fNMaxima;
00073 
00074   for (Int_t i=0; i<fNMaxima; i++) {
00075     fMPeak.push_back(oldHT.fMPeak[i]);
00076     fCPeak.push_back(oldHT.fCPeak[i]);
00077     fIPeak.push_back(oldHT.fIPeak[i]);
00078     fSlopePeak.push_back(oldHT.fSlopePeak[i]);
00079   }
00080 
00081 }
00082 
00083 HoughTrackSR::HoughTrackSR()
00084 {
00085   fSlopeLim[0] = -20.;
00086   fSlopeLim[1] =  21.;
00087   fInterLim[0] = -10.;
00088   fInterLim[1] =  11.;
00089   fMaxBin=40;
00090   fPeakMin = 4;
00091   fPeakMinFrac = .5;
00092   fPeakMinFracZoom = .75;
00093   fMinInterBinSize = .02;
00094   fFillHough = kFALSE;
00095 }
00096 
00097 HoughTrackSR::~HoughTrackSR()
00098 {
00099   if (fClusterList) {
00100     delete fClusterList;
00101   }
00102 }
00103 
00104 void HoughTrackSR::SetClusterList(TObjArray clusterlist)
00105 {
00106   fClusterList = new TObjArray(clusterlist);
00107 }
00108 
00109 void HoughTrackSR::FillHough()
00110 {
00111   fFillHough = kTRUE;
00112 
00113   fDSlope = fSlopeLim[1]-fSlopeLim[0];
00114   fDInter = fInterLim[1]-fInterLim[0];
00115   for (int im=0; im<fMaxBin; im++) {
00116     for (int ic=0; ic<fMaxBin; ic++) {
00117       fHough[im][ic] = 0;
00118     }
00119   }
00120   fMPeak.erase(fMPeak.begin(),fMPeak.end());
00121   fCPeak.erase(fCPeak.begin(),fCPeak.end());
00122   fIPeak.erase(fIPeak.begin(),fIPeak.end());
00123   fSlopePeak.erase(fSlopePeak.begin(),fSlopePeak.end());
00124   for (int i=0; i<=fClusterList->GetLast(); i++) {
00125     TrackClusterSR *cluster = dynamic_cast<TrackClusterSR*>(fClusterList->At(i));
00126     if (cluster) {
00127       for (int im=0; im<fMaxBin; im++) {
00128         Double_t slope = (Double_t)(im+.5)/(Double_t)fMaxBin*fDSlope+fSlopeLim[0];
00129         Double_t inter = cluster->GetTPos()-fXZmean[0]-slope*(cluster->GetZPos()-fXZmean[1]);
00130         int ic=-1;
00131         if(fDInter!=0){
00132           ic = (int)((inter-fInterLim[0])/fDInter*fMaxBin+.5);
00133         }
00134         if (ic>=0 && ic<fMaxBin) {
00135           fHough[im][ic]++;
00136         }
00137       }
00138     }
00139   }
00140 // find maximum bin
00141   fNBinMax = 0;
00142   fNPeak = 0;
00143   fNMaxima = 0;
00144   for (int im=0; im<fMaxBin; im++) {
00145     for (int ic=0; ic<fMaxBin; ic++) {
00146       if (fHough[im][ic]>fNBinMax) {
00147         fNBinMax = fHough[im][ic];
00148       }
00149       Int_t nmax = fHough[im][ic];
00150       Int_t nmin=10000;
00151       Int_t immax = 0;
00152       Int_t icmax = 0;
00153       for (int im1=-3; im1<=3; im1++) {
00154         for (int ic1=-3; ic1<=3; ic1++) {
00155           if (im+im1>=0 && im+im1<fNBin && ic+ic1>=0 && ic+ic1<fMaxBin && fHough[im+im1][ic+ic1]>nmax) {
00156             nmax = fHough[im+im1][ic+ic1];
00157             immax = im1;
00158             icmax = ic1;
00159           }
00160           if (im+im1>=0 && im+im1<fMaxBin && ic+ic1>=0 && ic+ic1<fMaxBin && fHough[im+im1][ic+ic1]<nmin) nmin=fHough[im+im1][ic+ic1];
00161         }
00162       }
00163       if((nmax-nmin)<fPeakMin){
00164         immax=-40;
00165         icmax=-40;
00166       }
00167       fMaxHoughBin[im][ic][0] = immax;
00168       fMaxHoughBin[im][ic][1] = icmax;
00169     }
00170   }
00171   /*
00172   MSG("HoughTrackSR", Msg::kInfo)  << " MAX -----";
00173   for (int ic=0; ic<fMaxBin; ic++) {
00174           MSG("HoughTrackSR", Msg::kInfo)  << "---";
00175   }
00176   MSG("HoughTrackSR", Msg::kInfo)  << "\n";
00177   for (int im=0; im<fMaxBin; im++) {
00178     printf("%2d | ",im);
00179     for (int ic=0; ic<fMaxBin; ic++) {
00180       printf("%2d/%2d ",fMaxHoughBin[im][ic][0],fMaxHoughBin[im][ic][1] );
00181     }
00182     MSG("HoughTrackSR", Msg::kInfo)  << "\n";
00183   }
00184   */
00185 
00186 // find peak(s)
00187   Int_t nmuon = 0;
00188   Int_t imaxpeak = 0;
00189   for (int im=0; im<fMaxBin; im++) {
00190     for (int ic=0; ic<fMaxBin; ic++) {
00191       if (fHough[im][ic]>=fPeakMin && fMaxHoughBin[im][ic][0]==0 && fMaxHoughBin[im][ic][1]==0) {
00192         int ifound = 0;
00193         for (int imaxima=0; imaxima<fNMaxima; imaxima++) {
00194           if (abs(fMPeak[imaxima]-im)<=3 && abs(fCPeak[imaxima]-ic)<=3) {
00195             if (!ifound) {
00196               ifound = fIPeak[imaxima];
00197             }
00198             else if (ifound!=fIPeak[imaxima]) {
00199               for (int jmaxima=0; jmaxima<fNMaxima; jmaxima++) {
00200                 if (fIPeak[jmaxima]==fIPeak[imaxima]) {
00201                   fIPeak[jmaxima] = ifound;
00202                 }
00203               }
00204             }
00205           }
00206         }
00207  
00208         fMPeak.push_back(im);
00209         fCPeak.push_back(ic);
00210         if (ifound) {
00211           fIPeak.push_back(ifound);
00212         }
00213         else {
00214           nmuon++;
00215           fIPeak.push_back(nmuon);
00216         }
00217         if (!fNMaxima || fHough[im][ic]==fNBinMax) {
00218           imaxpeak = fNMaxima;
00219         }
00220         fNMaxima++;
00221       }
00222     }
00223   }
00224 // calculate slope in hough space
00225   for (int i=0; i<fNMaxima; i++) {
00226     int ic = fCPeak[i];
00227     Double_t xhough[7] = {-3.,-2.,-1.,0.,1.,2.,3.};
00228     Double_t yhough[7] = {0.,0.,0.,0.,0.,0.,0.};
00229     Double_t whough[7] = {0.,0.,0.,0.,0.,0.,0.};
00230     Int_t ncexist=0;
00231     for (int ic1=-3; ic1<=3; ic1++) {
00232       if (ic+ic1>=0 && ic+ic1<fMaxBin) {
00233         for (int im1=0; im1<fMaxBin; im1++) {
00234           yhough[ic1+3] += (Double_t)(im1*fHough[im1][ic+ic1]);
00235           whough[ic1+3] += (Double_t)(fHough[im1][ic+ic1]);
00236         }
00237       }
00238       if (whough[ic1+3]>0.) {
00239         yhough[ic1+3] /= whough[ic1+3];
00240         ncexist++;
00241       }
00242     }
00243     if (ncexist>1) {
00244       Double_t parm[2];
00245       LinearFit::Weighted(7,xhough,yhough,whough,parm);
00246       fSlopePeak.push_back(parm[1]);
00247     } else {
00248       fSlopePeak.push_back(99999.); // no nearby peaks, set to non physical number so that it does not match any other peaks
00249     }
00250   }
00251 
00252 
00253 
00254 // match local maxima, and remove those below threshold
00255   for (int i=0; i<fNMaxima; i++) {
00256     for (int j=0; j<fNMaxima; j++) {
00257       if (i!=j) {
00258         int  avec = (fCPeak[j] + fCPeak[i])/2;
00259         int  avem = (fMPeak[j] + fMPeak[i])/2;
00260         Double_t peakisum = 0;
00261         Double_t peakjsum = 0;
00262         Double_t valleysum = 0;
00263         for (int ij=-1;ij<=1;ij++){
00264           for (int ik=-1;ik<=1;ik++){
00265             if(fMPeak[i]+ij>=0 && fMPeak[i]+ij<fMaxBin && fCPeak[i]+ik>=0 && fCPeak[i]+ik<fMaxBin)  peakisum += fHough[fMPeak[i]+ij][fCPeak[i]+ik];     
00266             if(fMPeak[j]+ij>=0 && fMPeak[j]+ij<fMaxBin && fCPeak[j]+ik>=0 && fCPeak[j]+ik<fMaxBin)   peakjsum +=fHough[fMPeak[j]+ij][fCPeak[j]+ik];
00267             if(avem+ij>=0 && avem+ij<fMaxBin && avec+ik>=0 && avec+ik<fMaxBin) valleysum += fHough[avem+ij][avec+ik];
00268           }
00269         }
00270         Double_t minpeak  = min(peakisum,peakjsum);
00271         Double_t threshold = 2 * valleysum + fPeakMin;
00272         if(valleysum>10) threshold = valleysum + 2.* TMath::Sqrt(valleysum);
00273         //      cout << i << " " << j << " " << avem << " " << avec << " " << peakisum << " " << peakjsum << " " << valleysum << endl;
00274         if(minpeak<threshold){
00275           //      cout << "remove " << endl;
00276           if(peakisum<peakjsum)fIPeak[i]=-1;
00277           else fIPeak[j]=-1;
00278         }
00279 
00280         
00281       }
00282     }
00283   }
00284 
00285   // remove all peaks that are shorter than 20% of longest
00286   for (int i=0; i<fNMaxima; i++) {
00287     if(fHough[fMPeak[i]][fCPeak[i]]<0.2*fNBinMax)fIPeak[i]=-1;
00288     
00289   }
00290 // require slopes to be within +-3 bins of maximum peak (this only seems to make sense for cosmics)
00291 /*
00292   for (int i=0; i<fNMaxima; i++) {
00293     if (i!=imaxpeak && abs(fMPeak[i]-fMPeak[imaxpeak])>3) {
00294       fIPeak[i] = -1;
00295     }
00296   }
00297 */
00298 
00299   int muonmult[fNBin*fNBin+1];
00300   for (int i=0; i<=fNBin*fNBin; i++) {
00301     muonmult[i] = 0;
00302   }
00303   for (int i=0; i<fNMaxima; i++) {
00304     if (fIPeak[i]>=0) {
00305       muonmult[fIPeak[i]] = 1;
00306     }
00307   }
00308   for (int i=0; i<=fMaxBin*fMaxBin; i++) {
00309     fNPeak += muonmult[i];
00310   } 
00311 }
00312 
00313 Int_t HoughTrackSR::GetNPeak() const
00314 {
00315   return fNPeak;
00316 }
00317 
00318 void HoughTrackSR::Print(Option_t* /* option */) const
00319 {
00320         MSG("HoughTrackSR", Msg::kInfo)  << "MEAN " << fXZmean[0] << " " << fXZmean[1] << "\n";
00321         MSG("HoughTrackSR", Msg::kInfo)  << "RMS  " << fXZrms[0] << " " << fXZrms[1]  << "\n";
00322 
00323         MSG("HoughTrackSR", Msg::kInfo)  << "slope limits: " << fSlopeLim[0] << " / " << fSlopeLim[1] << "\n";
00324         MSG("HoughTrackSR", Msg::kInfo)  << "intercept limits: " << fInterLim[0] << " / " << fInterLim[1] << "\n";
00325         MSG("HoughTrackSR", Msg::kInfo)  << "\n";
00326 
00327         MSG("HoughTrackSR", Msg::kInfo)  << "   | ";
00328   for (int ic=0; ic<fMaxBin; ic++) {
00329     printf("%2d ",ic);
00330   }
00331   MSG("HoughTrackSR", Msg::kInfo)  << "\n";
00332   MSG("HoughTrackSR", Msg::kInfo)  << "-----";
00333   for (int ic=0; ic<fMaxBin; ic++) {
00334           MSG("HoughTrackSR", Msg::kInfo)  << "---";
00335   }
00336   MSG("HoughTrackSR", Msg::kInfo)  << "\n";
00337   for (int im=0; im<fMaxBin; im++) {
00338     printf("%2d | ",im);
00339     for (int ic=0; ic<fMaxBin; ic++) {
00340       printf("%2d ",fHough[im][ic]);
00341     }
00342     MSG("HoughTrackSR", Msg::kInfo)  << "\n";
00343   }
00344   MSG("HoughTrackSR", Msg::kInfo)  << "\n\n";
00345 
00346   MSG("HoughTrackSR", Msg::kInfo)  << "# of found muons = " << fNPeak << "\n";
00347   MSG("HoughTrackSR", Msg::kInfo)  << "# of found local maxima = " << fNMaxima << "\n";
00348 
00349   for (int i=0; i<fNMaxima; i++) {
00350           MSG("HoughTrackSR", Msg::kInfo)  << "  " << i << " " << fMPeak[i] << " " << fCPeak[i] << " " << fIPeak[i] << " " << fSlopePeak[i] << " " << fHough[fMPeak[i]][fCPeak[i]] << "\n";
00351     if (fIPeak[i]>=0) {
00352                 MSG("HoughTrackSR", Msg::kInfo)  << "  PEAK: " << GetSlope(i) << " " << GetInter(i) << "\n";
00353     }
00354   }
00355   MSG("HoughTrackSR", Msg::kInfo)  << "\n\n";
00356 
00357 }
00358 
00359 TObjArray HoughTrackSR::Iterate()
00360 {
00361   TObjArray tracklist;
00362   if (fFillHough) {
00363     Double_t SlopeLim[2] = {fSlopeLim[0],fSlopeLim[1]};
00364     Double_t InterLim[2] = {fInterLim[0],fInterLim[1]};
00365     if (fNPeak>1) {
00366       Int_t imuon=0;
00367       Double_t newslopelim[2] = { 0, 0 }, newinterlim[2] = { 0, 0 };
00368       for (Int_t i=0; i<fNMaxima; i++) {
00369         if (fIPeak[i]>=0) {
00370           Int_t nentry = fHough[fMPeak[i]][fCPeak[i]];
00371           fNBinCut = max(fPeakMin,(Int_t)(fPeakMinFracZoom*nentry));
00372           Int_t impeak = (Int_t)(GetSlope(i)+.5);
00373           Int_t icpeak = (Int_t)(GetInter(i)+.5);
00374           Int_t minbin[2] = {impeak-5,icpeak-5};
00375           Int_t maxbin[2] = {impeak+5,icpeak+5};
00376           /*
00377           Int_t found=1;
00378           for (Int_t ic1=icpeak-1; ic1>=0 && found; ic1--) {
00379             found = 0;
00380             Int_t im1 = (Int_t)((ic1-icpeak)*fSlopePeak[i]+.5)+impeak;
00381             for (Int_t im2=-3; im2<=3; im2++) {
00382               if (im1+im2>=0 && im1+im2<fMaxBin && fHough[im1+im2][ic1]>=fNBinCut) {
00383                 found = 1;
00384                 minbin[1] = ic1;
00385                 minbin[0] = min(minbin[0],im1+im2);
00386                 maxbin[0] = max(maxbin[0],im1+im2);
00387               }
00388             }
00389           }
00390           found = 1;
00391           for (Int_t ic1=icpeak+1; ic1<fMaxBin && found; ic1++) {
00392             found = 0;
00393             Int_t im1 = (Int_t)((ic1-icpeak)*fSlopePeak[i]+.5)+impeak;
00394             for (Int_t im2=-3; im2<=3; im2++) {
00395               if (im1+im2>=0 && im1+im2<fMaxBin && fHough[im1+im2][ic1]>=fNBinCut) {
00396                 found = 1;
00397                 maxbin[1] = ic1;
00398                 minbin[0] = min(minbin[0],im1+im2);
00399                 maxbin[0] = max(maxbin[0],im1+im2);
00400               }
00401             }
00402           }
00403           */
00404           // expand intercept bin range to minimum allowed if we have specified
00405           // a range that is smaller than allowed by fMinInterBinSize
00406           Int_t dMinInterBin = (Int_t)(fMinInterBinSize*(Double_t)(fMaxBin*fMaxBin)/fDInter);
00407           while (dMinInterBin<fMaxBin && maxbin[1]-minbin[1]+1<dMinInterBin) {
00408             minbin[1]--;
00409             if (minbin[1]<0) minbin[1]=0;
00410             if (maxbin[1]-minbin[1]<dMinInterBin) {
00411               maxbin[1]++;
00412               if (maxbin[1]>=fMaxBin) maxbin[1]=fMaxBin-1;
00413             }
00414           }
00415 
00416           if (!imuon) {
00417             // set new limits on original track space
00418             if (fMPeak[i]-minbin[0]<fMaxBin/4) minbin[0] = max(0,fMPeak[i]-fMaxBin/4);
00419             if (fCPeak[i]-minbin[1]<fMaxBin/4) minbin[1] = max(0,fCPeak[i]-fMaxBin/4);
00420             if (maxbin[0]-fMPeak[i]<fMaxBin/4) maxbin[0] = min(fMaxBin-1,fMPeak[i]+fMaxBin/4);
00421             if (maxbin[1]-fCPeak[i]<fMaxBin/4) maxbin[1] = min(fMaxBin-1,fCPeak[i]+fMaxBin/4);
00422             minbin[0] = min(minbin[0],fMPeak[i]);
00423             minbin[1] = min(minbin[1],fCPeak[i]);
00424             maxbin[0] = max(maxbin[0],fMPeak[i]);
00425             maxbin[1] = max(maxbin[1],fCPeak[i]);
00426 
00427             newslopelim[0] = SlopeLim[0]+(Double_t)minbin[0]/(Double_t)fMaxBin*fDSlope;
00428             newslopelim[1] = SlopeLim[0]+(Double_t)maxbin[0]/(Double_t)fMaxBin*fDSlope;
00429             newinterlim[0] = InterLim[0]+(Double_t)minbin[1]/(Double_t)fMaxBin*fDInter;
00430             newinterlim[1] = InterLim[0]+(Double_t)maxbin[1]/(Double_t)fMaxBin*fDInter;
00431           }
00432           else {
00433             // create new hough track space centered on peak
00434             HoughTrackSR *newhough = new HoughTrackSR(*fClusterList);
00435             newhough->SetX0(fXZmean[0]);
00436             newhough->SetZ0(fXZmean[1]);
00437             newhough->SetXRMS(fXZrms[0]);
00438             newhough->SetZRMS(fXZrms[1]);
00439             newhough->SetPeakMin(fPeakMin);
00440             newhough->SetPeakMinFrac(fPeakMinFrac);
00441 
00442             newhough->SetSlopeMin(SlopeLim[0]+(Double_t)minbin[0]/(Double_t)fMaxBin*fDSlope);
00443             newhough->SetSlopeMax(SlopeLim[0]+(Double_t)maxbin[0]/(Double_t)fMaxBin*fDSlope);
00444             newhough->SetInterceptMin(InterLim[0]+(Double_t)minbin[1]/(Double_t)fMaxBin*fDInter);
00445             newhough->SetInterceptMax(InterLim[0]+(Double_t)maxbin[1]/(Double_t)fMaxBin*fDInter);
00446             newhough->FillHough();
00447             tracklist.Add(newhough);
00448           }
00449           imuon++;
00450         }
00451       }
00452 
00453       // set new space limits and refill this track
00454       fSlopeLim[0] = newslopelim[0];
00455       fSlopeLim[1] = newslopelim[1];
00456       fInterLim[0] = newinterlim[0];
00457       fInterLim[1] = newinterlim[1];
00458       FillHough();
00459     }
00460     else if (fNPeak==1) {
00461       Int_t i;
00462       for (i=0; i<fNMaxima && fIPeak[i]<0; i++);
00463 
00464       // we now determine what bin count we use to define new boundaries of
00465       // slope/int space
00466       fNBinCut = max(fPeakMin,(Int_t)(fPeakMinFrac*fHough[fMPeak[i]][fCPeak[i]]));
00467       Int_t minbin[2] = {fMaxBin,fMaxBin};
00468       Int_t maxbin[2] = {0,0};
00469       for (Int_t im=0; im<fMaxBin; im++) {
00470         for (Int_t ic=0; ic<fMaxBin; ic++) {
00471           if (fHough[im][ic]>=fNBinCut) {
00472             minbin[0] = min(minbin[0],im);
00473             minbin[1] = min(minbin[1],ic);
00474             maxbin[0] = max(maxbin[0],im);
00475             maxbin[1] = max(maxbin[1],ic);
00476           }
00477         }
00478       }
00479       Int_t dinter = (Int_t)(fMinInterBinSize*(Double_t)(fMaxBin*fMaxBin)/fDInter);
00480       while (dinter<fMaxBin && maxbin[1]-minbin[1]+1<dinter) {
00481         minbin[1]--;
00482         if (minbin[1]<0) minbin[1]=0;
00483         if (maxbin[1]-minbin[1]<dinter) {
00484           maxbin[1]++;
00485           if (maxbin[1]>=fMaxBin) maxbin[1]=fMaxBin-1;
00486         }
00487       }
00488 
00489       // don't allow excessive scale change in one iteration
00490       if (fMPeak[i]-minbin[0]<fMaxBin/4) minbin[0] = max(0,fMPeak[i]-fMaxBin/4);
00491       if (fCPeak[i]-minbin[1]<fMaxBin/4) minbin[1] = max(0,fCPeak[i]-fMaxBin/4);
00492       if (maxbin[0]-fMPeak[i]<fMaxBin/4) maxbin[0] = min(fMaxBin-1,fMPeak[i]+fMaxBin/4);
00493       if (maxbin[1]-fCPeak[i]<fMaxBin/4) maxbin[1] = min(fMaxBin-1,fCPeak[i]+fMaxBin/4);
00494       minbin[0] = min(minbin[0],fMPeak[i]);
00495       minbin[1] = min(minbin[1],fCPeak[i]);
00496       maxbin[0] = max(maxbin[0],fMPeak[i]);
00497       maxbin[1] = max(maxbin[1],fCPeak[i]);
00498       fSlopeLim[1] = fSlopeLim[0]+(Double_t)maxbin[0]/(Double_t)(fMaxBin-1)*fDSlope;
00499       fSlopeLim[0] += (Double_t)minbin[0]/(Double_t)(fMaxBin-1)*fDSlope;
00500       fInterLim[1] = fInterLim[0]+(Double_t)maxbin[1]/(Double_t)(fMaxBin-1)*fDInter;
00501       fInterLim[0] += (Double_t)minbin[1]/(Double_t)(fMaxBin-1)*fDInter;
00502       FillHough();
00503     }
00504   }
00505   else {
00506     int nrms = 1;
00507     fInterLim[0] = min(-nrms*fXZrms[0]-fSlopeLim[1]*nrms*fXZrms[1],
00508                        -nrms*fXZrms[0]+fSlopeLim[0]*nrms*fXZrms[1]);
00509     fInterLim[1] = max(nrms*fXZrms[0]+fSlopeLim[1]*nrms*fXZrms[1],
00510                        nrms*fXZrms[0]-fSlopeLim[0]*nrms*fXZrms[1]);
00511     FillHough();
00512   }
00513 
00514 
00515   return tracklist;
00516 
00517 }
00518 
00519 Int_t HoughTrackSR::GetNBin() const
00520 {
00521   return fMaxBin;
00522 }
00523 
00524 void HoughTrackSR::SetPeakMin(Int_t nbin)
00525 {
00526   fPeakMin = nbin;
00527 }
00528 
00529 void HoughTrackSR::SetPeakMinFrac(Double_t dvar)
00530 {
00531   fPeakMinFrac = dvar;
00532 }
00533 
00534 void HoughTrackSR::SetPeakMinFracZoom(Double_t dvar)
00535 {
00536   fPeakMinFracZoom = dvar;
00537 }
00538 
00539 void HoughTrackSR::SetMinInterBinSize(Double_t dvar)
00540 {
00541   fMinInterBinSize = dvar;
00542 }
00543 
00544 Double_t HoughTrackSR::GetSlopeMin() const
00545 {
00546   return fSlopeLim[0];
00547 }
00548 
00549 Double_t HoughTrackSR::GetSlopeMax() const
00550 {
00551   return fSlopeLim[1];
00552 }
00553 
00554 Double_t HoughTrackSR::GetInterceptMin() const
00555 {
00556   return fInterLim[0];
00557 }
00558 
00559 Double_t HoughTrackSR::GetInterceptMax() const
00560 {
00561   return fInterLim[1];
00562 }
00563 
00564 void HoughTrackSR::SetX0(Double_t dvar)
00565 {
00566   fXZmean[0] = dvar;
00567 }
00568 
00569 void HoughTrackSR::SetZ0(Double_t dvar)
00570 {
00571   fXZmean[1] = dvar;
00572 }
00573 
00574 void HoughTrackSR::SetXRMS(Double_t dvar)
00575 {
00576   fXZrms[0] = dvar;
00577 }
00578 
00579 void HoughTrackSR::SetZRMS(Double_t dvar)
00580 {
00581   fXZrms[1] = dvar;
00582 }
00583 
00584 
00585 void HoughTrackSR::SetSlopeMin(Double_t dvar)
00586 {
00587   fSlopeLim[0] = dvar;
00588 }
00589 
00590 void HoughTrackSR::SetSlopeMax(Double_t dvar)
00591 {
00592   fSlopeLim[1] = dvar;
00593 }
00594 
00595 void HoughTrackSR::SetInterceptMin(Double_t dvar)
00596 {
00597   fInterLim[0] = dvar;
00598 }
00599 
00600 void HoughTrackSR::SetInterceptMax(Double_t dvar)
00601 {
00602   fInterLim[1] = dvar;
00603 }
00604 
00605 Double_t HoughTrackSR::GetPeakSlope(Int_t i) const
00606 {
00607   if (fNPeak==0) return -9999.;
00608   if (i<0 || i>=fNPeak) i = 0;
00609   Int_t j;
00610   Int_t n=0;
00611   for (j=0; j<fNMaxima && n<=i; j++) {
00612     if (fIPeak[j]>=0) n++;
00613   }
00614   j--;
00615   Double_t slope = fMPeak[j]*fDSlope/fMaxBin+fSlopeLim[0];
00616   return slope;
00617 }
00618 
00619 Double_t HoughTrackSR::GetPeakIntercept(Int_t i) const
00620 {
00621   if (fNPeak==0) return -9999.;
00622   if (i<0 || i>=fNPeak) i = 0;
00623   Int_t j;
00624   Int_t n=0;
00625   for (j=0; j<fNMaxima && n<=i; j++) {
00626     if (fIPeak[j]>=0) n++;
00627   }
00628   j--;
00629 
00630   Double_t slope = fMPeak[j]*fDSlope/fMaxBin+fSlopeLim[0];
00631   Double_t inter = fCPeak[j]*fDInter/fMaxBin+fInterLim[0];
00632 
00633   return inter-slope*fXZmean[1]+fXZmean[0]; 
00634 }
00635 
00636 Int_t HoughTrackSR::GetPeakBin(Int_t i) const
00637 {
00638   if (fNPeak==0) return -9999;
00639   if (i<0 || i>=fNPeak) i = 0;
00640   Int_t j;
00641   Int_t n=0;
00642   for (j=0; j<fNMaxima && n<=i; j++) {
00643     if (fIPeak[j]>=0) n++;
00644   }
00645   j--;
00646   return fHough[fMPeak[j]][fCPeak[j]];
00647 }
00648 
00649 Int_t HoughTrackSR::GetLargestPeakIndex() const
00650 {
00651   Int_t nmaxbin = 0;
00652   Int_t imax = -9999;
00653   Int_t ipeak = 0;
00654   for (Int_t i=0; i<fNMaxima; i++) {
00655     if (fIPeak[i]>=0) {
00656       if (fHough[fMPeak[i]][fCPeak[i]]>nmaxbin) {
00657         nmaxbin = fHough[fMPeak[i]][fCPeak[i]];
00658         imax = ipeak;
00659       }
00660       ipeak++;
00661     }
00662   }
00663   return imax;
00664 }
00665 
00666 Double_t HoughTrackSR::GetSlope(Int_t i) const
00667 {
00668   Int_t impeak = fMPeak[i];
00669   Int_t icpeak = fCPeak[i];
00670   Int_t nentry = fHough[impeak][icpeak];
00671   Int_t found=1;
00672   Int_t nskip=0;
00673   Int_t nfound = 0;
00674   Double_t mpeak = 0.;
00675   Double_t cpeak = 0.;
00676   for (Int_t ic1=icpeak-1; ic1>=0 && nskip<2; ic1--) {
00677     found = 0;
00678     Int_t im1 = (Int_t)((ic1-icpeak)*fSlopePeak[i]+.5)+impeak;
00679     for (Int_t im2=-3; im2<=3; im2++) {
00680       if (im1+im2>=0 && im1+im2<fMaxBin && fHough[im1+im2][ic1]==nentry) {
00681         found = 1;
00682         nfound++;
00683         mpeak += (Double_t)(im1+im2);
00684         cpeak += (Double_t)(ic1);
00685       }
00686     }
00687     if (!found) {
00688       nskip++;
00689     }
00690     else {
00691       nskip = 0;
00692     }
00693   }
00694   found=1;
00695   nskip=0;
00696   for (Int_t ic1=icpeak; ic1<fMaxBin && nskip<2; ic1++) {
00697     found = 0;
00698     Int_t im1 = (Int_t)((ic1-icpeak)*fSlopePeak[i]+.5)+impeak;
00699     for (Int_t im2=-3; im2<=3; im2++) {
00700       if (im1+im2>=0 && im1+im2<fMaxBin && fHough[im1+im2][ic1]==nentry) {
00701         found = 1;
00702         nfound++;
00703         mpeak += (Double_t)(im1+im2);
00704         cpeak += (Double_t)(ic1);
00705       }
00706     }
00707     if (!found) {
00708       nskip++;
00709     }
00710     else {
00711       nskip = 0;
00712     }
00713   }
00714   if (!nfound) return -1.;
00715   mpeak /= (Double_t)nfound;
00716   cpeak /= (Double_t)nfound;
00717   return mpeak;
00718 }
00719 
00720 Double_t HoughTrackSR::GetInter(Int_t i) const
00721 {
00722   Int_t impeak = fMPeak[i];
00723   Int_t icpeak = fCPeak[i];
00724   Int_t nentry = fHough[impeak][icpeak];
00725   Int_t found=1;
00726   Int_t nskip=0;
00727   Int_t nfound = 0;
00728   Double_t mpeak = 0.;
00729   Double_t cpeak = 0.;
00730   for (Int_t ic1=icpeak-1; ic1>=0 && nskip<2; ic1--) {
00731     found = 0;
00732     Int_t im1 = (Int_t)((ic1-icpeak)*fSlopePeak[i]+.5)+impeak;
00733     for (Int_t im2=-3; im2<=3; im2++) {
00734       if (im1+im2>=0 && im1+im2<fMaxBin && fHough[im1+im2][ic1]==nentry) {
00735         found = 1;
00736         nfound++;
00737         mpeak += (Double_t)(im1+im2);
00738         cpeak += (Double_t)(ic1);
00739       }
00740     }
00741     if (!found) {
00742       nskip++;
00743     }
00744     else {
00745       nskip = 0;
00746     }
00747   }
00748   found=1;
00749   nskip=0;
00750   for (Int_t ic1=icpeak; ic1<fMaxBin && nskip<2; ic1++) {
00751     found = 0;
00752     Int_t im1 = (Int_t)((ic1-icpeak)*fSlopePeak[i]+.5)+impeak;
00753     for (Int_t im2=-3; im2<=3; im2++) {
00754       if (im1+im2>=0 && im1+im2<fMaxBin && fHough[im1+im2][ic1]==nentry) {
00755         found = 1;
00756         nfound++;
00757         mpeak += (Double_t)(im1+im2);
00758         cpeak += (Double_t)(ic1);
00759       }
00760     }
00761     if (!found) {
00762       nskip++;
00763     }
00764     else {
00765       nskip = 0;
00766     }
00767   }
00768   if (!nfound) return -1.;
00769   mpeak /= (Double_t)nfound;
00770   cpeak /= (Double_t)nfound;
00771   return cpeak;
00772 }

Generated on Mon Feb 15 11:06:47 2010 for loon by  doxygen 1.3.9.1