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

HoughViewSR.cxx

Go to the documentation of this file.
00001 
00002 // $Id: HoughViewSR.cxx,v 1.26 2007/01/15 20:02:44 rhatcher Exp $
00003 //
00004 // HoughViewSR
00005 //
00006 // Author:  R. Lee 2002.01.18
00007 //
00009 
00010 #include <iostream>
00011 #include <string>
00012 #include <cmath>
00013 
00014 #include "CandTrackSR/HoughViewSR.h"
00015 #include "MessageService/MsgService.h"
00016 #include "CandTrackSR/TrackClusterSR.h"
00017 #include "RecoBase/LinearFit.h"
00018 
00019 ClassImp(HoughViewSR)
00020 
00021 //______________________________________________________________________
00022 CVSID("$Id: HoughViewSR.cxx,v 1.26 2007/01/15 20:02:44 rhatcher Exp $");
00023 
00024 //-------------------------------------------------------------------
00025 HoughViewSR::HoughViewSR(TObjArray clusterlist)
00026 {
00027   // set default values for hough fitter parameters.
00028   // these get reset by AlgTrackSRList
00029   fPeakMin = 4;
00030   fPeakMinFrac = .25;
00031   fPeakMinFracZoom = .75;
00032   fMinInterBinSize = 0.02;
00033   fClusterList = new TObjArray(clusterlist);
00034   Init();
00035 }
00036 
00037 //-------------------------------------------------------------------
00038 HoughViewSR::HoughViewSR()
00039 {
00040  // set default values for hough fitter parameters.
00041   // these get reset by AlgTrackSRList 
00042   fPeakMin = 4;
00043   fPeakMinFrac = .5;
00044   fPeakMinFracZoom = .75;
00045   fMinInterBinSize = 0.02;
00046 }
00047 
00048 //-------------------------------------------------------------------
00049 HoughViewSR::~HoughViewSR()
00050 {
00051   if (fClusterList) {
00052     delete fClusterList;
00053   }
00054   for (Int_t i=0; i<=fHoughTrackList.GetLast(); i++) {
00055     HoughTrackSR *htrack = dynamic_cast<HoughTrackSR*>(fHoughTrackList.At(i));
00056     if (htrack) delete htrack;
00057   }
00058 }
00059 //-------------------------------------------------------------------
00060 void HoughViewSR::SetClusterList(TObjArray clusterlist)
00061 {
00062   fClusterList = new TObjArray(clusterlist);
00063   Init();
00064 
00065 }
00066 
00067 //-------------------------------------------------------------------
00068 void HoughViewSR::SetClusterList(TObjArray *  clusterlist,  Double_t minPulseHeight)
00069 {
00070   fClusterList = new TObjArray(1,0);
00071 
00072  for (Int_t i=0; i<=clusterlist->GetLast(); i++) {
00073     TrackClusterSR *cluster = dynamic_cast<TrackClusterSR*>(clusterlist->At(i)); 
00074     if(cluster->GetCharge()>minPulseHeight){
00075       
00076       //loop over the cluster list and look to see if there is a cluster from
00077       //this clusters plane already in the list.  if so, check to see if the 
00078       //current cluster has a larger signal and if it does replace the one in the
00079       //list with the current cluster
00080       fClusterList->AddLast(cluster);
00081       
00082       MSG("TrackSR", Msg::kDebug) << "plane " << cluster->GetPlane() << " cluster " 
00083                                   <<  cluster->GetMaxStrip() << " - " << cluster->GetMinStrip() << endl;
00084     }
00085   }
00086   
00087   MSG("TrackSR", Msg::kDebug) << fClusterList->GetLast()+1 
00088                               << " clusters in the HoughView" << endl;
00089   Init();
00090 
00091 
00092 }
00093 
00094 
00095 
00096 //-------------------------------------------------------------------
00097 void HoughViewSR::Init()
00098 {
00099   fXZmean[0] = 0.;
00100   fXZmean[1] = 0.;
00101   fXZrms[0] = 0.;
00102   fXZrms[1] = 0.;
00103  // reduce requirement for min peak height for < 5 track clusters 
00104   if(fClusterList->GetLast()<4)fPeakMin=3;
00105   int ncluster=0;
00106   for (int i=0; i<=fClusterList->GetLast(); ++i) {
00107     TrackClusterSR *cluster = dynamic_cast<TrackClusterSR*>(fClusterList->At(i));
00108     
00109     Double_t tpos = cluster->GetTPos();
00110     Double_t zpos = cluster->GetZPos();
00111     ++ncluster;
00112     fXZmean[0] += tpos;
00113     fXZrms[0] += tpos*tpos;
00114     fXZmean[1] += zpos;
00115     fXZrms[1] += zpos*zpos;
00116   }
00117   if (ncluster) {
00118     fXZmean[0] /= (Double_t)ncluster;
00119     fXZmean[1] /= (Double_t)ncluster;
00120     fXZrms[0] /= (Double_t)ncluster;
00121     fXZrms[1] /= (Double_t)ncluster;
00122     fXZrms[0] -= fXZmean[0]*fXZmean[0];
00123     if (fXZrms[0]>0.) {
00124       fXZrms[0] = sqrt(fXZrms[0]);
00125     }
00126     else {
00127       fXZrms[0] = 0.;
00128     }
00129     fXZrms[1] -= fXZmean[1]*fXZmean[1];
00130     if (fXZrms[1]>0.) {
00131       fXZrms[1] = sqrt(fXZrms[1]);
00132     }
00133     else {
00134       fXZrms[1] = 0.;
00135     }
00136   }
00137   HoughTrackSR *houghtrack = new HoughTrackSR(*fClusterList);
00138   houghtrack->SetX0(fXZmean[0]);
00139   houghtrack->SetZ0(fXZmean[1]);
00140   houghtrack->SetXRMS(fXZrms[0]);
00141   houghtrack->SetZRMS(fXZrms[1]);
00142   houghtrack->SetPeakMin(fPeakMin);
00143   houghtrack->SetPeakMinFrac(fPeakMinFrac);
00144   houghtrack->SetPeakMinFracZoom(fPeakMinFracZoom);
00145   houghtrack->SetMinInterBinSize(fPeakMinFracZoom);
00146   houghtrack->SetMaxBin(40);
00147   //  if(fClusterList->GetLast()<10) houghtrack->SetMaxBin(20);
00148   houghtrack->Iterate();
00149   fHoughTrackList.Add(houghtrack);
00150   
00151 }
00152 
00153 //-------------------------------------------------------------------
00154 void HoughViewSR::Print(Option_t* /* option */) const
00155 {
00156   for (Int_t i=0; i<=fHoughTrackList.GetLast(); i++) {
00157     HoughTrackSR *houghtrack = dynamic_cast<HoughTrackSR*>(fHoughTrackList.At(i));
00158     cout << "**************************** TRACK " << i << "/" << fHoughTrackList.GetLast() << " ****************************\n\n";
00159     houghtrack->Print();
00160   }
00161 }
00162 
00163 //-------------------------------------------------------------------
00164 Int_t HoughViewSR::Iterate(Int_t imode)
00165 {
00166 
00167   //imode<=0: max # iterations = 20
00168   //imode>0: max # iterations = imode
00169   if (imode<=0) {
00170     Int_t niterate=0;
00171     Int_t icount=0;
00172     do {
00173       MSG("TrackSR",Msg::kDebug) << "ITERATING " << icount << "\n";
00174       niterate = IterateSingle();
00175       ++icount;
00176     } while (niterate && icount<20);
00177     return icount;
00178   }
00179   else {
00180     Int_t niterate=0;
00181     for (Int_t i=0; i<imode; ++i) {
00182       niterate = IterateSingle();
00183     }
00184     return niterate;
00185   }
00186 }
00187 
00188 //-------------------------------------------------------------------
00189 Int_t HoughViewSR::IterateSingle()
00190 {
00191   MSG("TrackSR",Msg::kDebug) << "begin IterateSingle\n";
00192   TObjArray tracklist;
00193   Int_t niterate=0;
00194  
00195   for (Int_t i=0; i<=fHoughTrackList.GetLast(); ++i) {
00196     MSG("TrackSR",Msg::kDebug) << "TRACK " << i << "/" << fHoughTrackList.GetLast() << "\n";
00197     HoughTrackSR *houghtrack = dynamic_cast<HoughTrackSR*>(fHoughTrackList.At(i));
00198     MSG("TrackSR",Msg::kDebug) << "OLD\n"; 
00199     //            houghtrack->Print();
00200     HoughTrackSR *oldHT = 0;
00201     if (houghtrack->GetNPeak()>0 && houghtrack->GetInterceptMax()-houghtrack->GetInterceptMin()>fMinInterBinSize*(Double_t)houghtrack->GetNBin()) {
00202       oldHT = new HoughTrackSR(*houghtrack);
00203       TObjArray newlist(houghtrack->Iterate());
00204       for (Int_t i=0; i<=newlist.GetLast(); ++i) {
00205         HoughTrackSR *htrack = dynamic_cast<HoughTrackSR*>(newlist.At(i));
00206         MSG("TrackSR",Msg::kDebug) << "newly created " << i << "\n";
00207         //      htrack->Print();
00208         if (htrack->GetNPeak()>0) {
00209           fHoughTrackList.Add(htrack);
00210           MSG("TrackSR",Msg::kDebug) << "adding to list\n";
00211         }
00212         else {
00213           delete htrack;
00214         }
00215       }
00216       MSG("TrackSR",Msg::kDebug) << "NEW\n";
00217       //   houghtrack->Print();
00218       if (houghtrack->GetNPeak()>0) {
00219         ++niterate;
00220         delete oldHT;
00221       }
00222       else if (newlist.GetLast()<0) {
00223         delete houghtrack;
00224         houghtrack = oldHT;
00225         MSG("TrackSR",Msg::kDebug) << "NO PEAKS, REVERTING BACK\n";
00226       }
00227       else {
00228         delete oldHT;
00229       }
00230     }
00231     if (houghtrack->GetNPeak()>0) {
00232       tracklist.Add(houghtrack);
00233     }
00234     else {
00235       delete houghtrack;
00236     }
00237     MSG("TrackSR",Msg::kDebug) << "tracklist size " << tracklist.GetLast() << "\n";
00238   }
00239   MSG("TrackSR",Msg::kDebug) << "clearing houghtracklist\n";
00240   fHoughTrackList.Clear();
00241   fHoughTrackList.Compress();
00242   for (Int_t i=0; i<=tracklist.GetLast(); ++i) {
00243   MSG("TrackSR",Msg::kDebug) << "adding to houghtracklist " << i << "/" << tracklist.GetLast() << "\n";
00244     HoughTrackSR *htrack = dynamic_cast<HoughTrackSR*>(tracklist.At(i));
00245     fHoughTrackList.Add(htrack);
00246   }
00247   MSG("TrackSR",Msg::kDebug) << "end iteratesingle\n";
00248   return niterate;
00249 }
00250 
00251 //-------------------------------------------------------------------
00252 void HoughViewSR::SetPeakMin(Int_t nbin)
00253 {
00254   fPeakMin = nbin;
00255 }
00256 
00257 //-------------------------------------------------------------------
00258 void HoughViewSR::SetPeakMinFrac(Double_t frac)
00259 {
00260   fPeakMinFrac = frac;
00261 }
00262 
00263 //-------------------------------------------------------------------
00264 void HoughViewSR::SetPeakMinFracZoom(Double_t frac)
00265 {
00266   fPeakMinFracZoom = frac;
00267 }
00268 
00269 //-------------------------------------------------------------------
00270 void HoughViewSR::SetMinInterBinSize(Double_t frac)
00271 {
00272   fMinInterBinSize = frac;
00273 }
00274 
00275 //-------------------------------------------------------------------
00276 Double_t HoughViewSR::GetX0()
00277 {
00278   return fXZmean[0];
00279 }
00280 
00281 //-------------------------------------------------------------------
00282 Double_t HoughViewSR::GetZ0()
00283 {
00284   return fXZmean[1];
00285 }
00286 
00287 //-------------------------------------------------------------------
00288 Int_t HoughViewSR::GetNTrack() const
00289 {
00290   return fHoughTrackList.GetLast()+1;
00291 }
00292 
00293 //-------------------------------------------------------------------
00294 Int_t HoughViewSR::GetNPeak() const
00295 {
00296   Int_t npeak = 0;
00297   for (Int_t i=0; i<=fHoughTrackList.GetLast(); ++i) {
00298     const HoughTrackSR *houghtrack = dynamic_cast<const HoughTrackSR*>(fHoughTrackList.At(i));
00299     npeak += houghtrack->GetNPeak();
00300   }
00301   return npeak;
00302 }
00303 
00304 //-------------------------------------------------------------------
00305 const HoughTrackSR *HoughViewSR::GetHoughTrack(Int_t itrack)
00306 {
00307   if (itrack<=fHoughTrackList.GetLast()) {
00308     const HoughTrackSR *houghtrack = dynamic_cast<const HoughTrackSR*>(fHoughTrackList.At(itrack));
00309     return houghtrack;
00310   }
00311   else {
00312     return 0;
00313   }
00314 }
00315 
00316 //-------------------------------------------------------------------
00317 Int_t HoughViewSR::GetLargestTrackIndex() const
00318 {
00319   Int_t itrack = -9999;
00320   Int_t nmaxbin = 0;
00321   for (Int_t i=0; i<=fHoughTrackList.GetLast(); ++i) {
00322     const HoughTrackSR *houghtrack = dynamic_cast<const HoughTrackSR*>(fHoughTrackList.At(i));
00323     if (houghtrack->GetPeakBin(houghtrack->GetLargestPeakIndex())>nmaxbin) {
00324       nmaxbin = houghtrack->GetPeakBin(houghtrack->GetLargestPeakIndex());
00325       itrack = i;
00326     }
00327   }
00328   return itrack;
00329 }

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