Public Member Functions | Private Attributes

WCSimHoughTransform Class Reference

#include "WCSimHoughTransform.hh"

List of all members.

Public Member Functions

 WCSimHoughTransform (Int_t phiBins, Int_t costhetaBins)
 ~WCSimHoughTransform ()
void Fill (Double_t nx, Double_t ny, Double_t nz, Double_t weight)
void Fill (Double_t phi, Double_t costheta, Double_t weight)
void Reset ()
Int_t GetEntries ()
Double_t GetIntegral ()
Double_t GetX (Int_t binx)
Double_t GetY (Int_t biny)
Int_t GetBinX (Double_t x)
Int_t GetBinY (Double_t y)
void FindPeak (Double_t &height)
void FindPeak (Double_t &phi, Double_t &costheta, Double_t &height)
void FindPeak (Double_t &hx, Double_t &hy, Double_t &hz, Double_t &height)
TH2D * GetTH2D (const char *histname)
TH2D * GetRotatedTH2D (const char *histname, Double_t deltaPhi=0.0)

Private Attributes

Int_t fEntries
Double_t fIntegral
Int_t fXbins
Int_t fYbins
Double_t * fHoughArray

Detailed Description

Definition at line 8 of file WCSimHoughTransform.hh.


Constructor & Destructor Documentation

WCSimHoughTransform::WCSimHoughTransform ( Int_t  phiBins,
Int_t  costhetaBins 
)
WCSimHoughTransform::~WCSimHoughTransform (  ) 

Definition at line 19 of file WCSimHoughTransform.cc.

References fHoughArray.

{
  delete [] fHoughArray;
}


Member Function Documentation

void WCSimHoughTransform::Fill ( Double_t  nx,
Double_t  ny,
Double_t  nz,
Double_t  weight 
)

Definition at line 38 of file WCSimHoughTransform.cc.

Referenced by WCSimRingFinder::HoughTransform(), and WCSimRingFinder::HoughTransformArray().

{
  Double_t phi = 0.0;
  Double_t costheta = 0.0;

  if( nx!=0.0 ){
    phi = atan(ny/nx);
  }
  if( nx<=0.0 ){
    if( ny>0.0 ) phi += TMath::Pi();
    if( ny<0.0 ) phi -= TMath::Pi();
  }

  phi *= 180.0/TMath::Pi();
  costheta = nz;

  this->Fill(phi,costheta,weight);
}

void WCSimHoughTransform::Fill ( Double_t  phi,
Double_t  costheta,
Double_t  weight 
)

Definition at line 57 of file WCSimHoughTransform.cc.

References fEntries, fHoughArray, fIntegral, fXbins, fYbins, GetBinX(), and GetBinY().

{
  Int_t xbin = this->GetBinX(phi);
  Int_t ybin = this->GetBinY(costheta);
  
  if( xbin>=0 && xbin<fXbins
   && ybin>=0 && ybin<fYbins ){
    fHoughArray[xbin*fYbins+ybin] += weight;
    fEntries  += 1;
    fIntegral += weight;
  }
}

void WCSimHoughTransform::FindPeak ( Double_t &  height  ) 

Definition at line 149 of file WCSimHoughTransform.cc.

Referenced by WCSimHoughTransformArray::FindPeak(), and FindPeak().

{
  Double_t phi = 0.0;
  Double_t costheta = 0.0;
  Double_t tempheight = 0.0;

  this->FindPeak(phi,costheta,tempheight);

  height = tempheight;
}

void WCSimHoughTransform::FindPeak ( Double_t &  phi,
Double_t &  costheta,
Double_t &  height 
)

Definition at line 70 of file WCSimHoughTransform.cc.

References fEntries, fHoughArray, fIntegral, fXbins, fYbins, GetX(), and GetY().

{
  phi = 0.0;
  costheta = 0.0;

  if( fEntries<=0 
   || fIntegral<=0.0 ){ 
    return;
  }

  Int_t xbinmax = -1;
  Int_t ybinmax = -1;
  Double_t max = 0.0;

  for( Int_t xbin=0; xbin<fXbins; xbin++ ){
    for( Int_t ybin=0; ybin<fYbins; ybin++ ){
      if( fHoughArray[xbin*fYbins+ybin]>max ){
        xbinmax = xbin;  ybinmax = ybin;
        max = fHoughArray[xbin*fYbins+ybin]; 
      }
    }
  }

  Int_t window = 2;
  Double_t Swx = 0.0;
  Double_t Swy = 0.0;
  Double_t Sw = 0.0;
  Double_t Sn = 0.0;

  for( Int_t nx=-window; nx<=+window; nx++ ){
    for( Int_t ny=-window; ny<=+window; ny++ ){    
      
      Int_t xbin = xbinmax+nx; 
      if( xbin<0 ) xbin += fXbins;
      if( xbin>=fXbins ) xbin -= fXbins;
      Int_t ybin = ybinmax+ny;

      if( xbin>=0 && xbin<fXbins
       && ybin>=0 && ybin<fYbins ){
        Swx += 360.0*(double(nx)/double(fXbins))*fHoughArray[xbin*fYbins+ybin];
        Swy += 2.0*(double(ny)/double(fYbins))*fHoughArray[xbin*fYbins+ybin];
        Sw += fHoughArray[xbin*fYbins+ybin];
        Sn += 1.0;
      }

    }
  }

  Double_t peakx = this->GetX(xbinmax) + Swx/Sw;
  Double_t peaky = this->GetY(ybinmax) + Swy/Sw;
  Double_t peaksize = Sw/Sn;

  if( peakx<-180.0 ) peakx += 360.0;
  if( peakx>+180.0 ) peakx -= 360.0;

  phi = peakx;
  costheta = peaky;
  height = peaksize;
}

void WCSimHoughTransform::FindPeak ( Double_t &  hx,
Double_t &  hy,
Double_t &  hz,
Double_t &  height 
)

Definition at line 130 of file WCSimHoughTransform.cc.

References FindPeak().

{
  Double_t phi = 0.0;
  Double_t phiradians = 0.0;
  Double_t costheta = 0.0;
  Double_t sintheta = 0.0;
  Double_t tempheight = 0.0;

  this->FindPeak(phi,costheta,tempheight);

  phiradians = (TMath::Pi()/180.0)*phi;
  sintheta = sqrt(1.0-costheta*costheta);

  hx = sintheta*cos(phiradians);
  hy = sintheta*sin(phiradians);
  hz = costheta;
  height = tempheight;
}

Int_t WCSimHoughTransform::GetBinX ( Double_t  x  )  [inline]

Definition at line 24 of file WCSimHoughTransform.hh.

References fXbins.

Referenced by Fill().

{ return (Int_t)(fXbins*(x+180.0)/360.0); }

Int_t WCSimHoughTransform::GetBinY ( Double_t  y  )  [inline]

Definition at line 25 of file WCSimHoughTransform.hh.

References fYbins.

Referenced by Fill().

{ return (Int_t)(fYbins*(y+1.0)/2.0); }

Int_t WCSimHoughTransform::GetEntries (  )  [inline]

Definition at line 18 of file WCSimHoughTransform.hh.

References fEntries.

{ return fEntries; }

Double_t WCSimHoughTransform::GetIntegral (  )  [inline]

Definition at line 19 of file WCSimHoughTransform.hh.

References fIntegral.

{ return fIntegral; }

TH2D * WCSimHoughTransform::GetRotatedTH2D ( const char *  histname,
Double_t  deltaPhi = 0.0 
)

Definition at line 178 of file WCSimHoughTransform.cc.

References fEntries, fHoughArray, fXbins, and fYbins.

{
  TH2D* hist = new TH2D(histname,"",fXbins,-180.0,+180.0,fYbins,-1.0,+1.0);

  Int_t deltaBinX = hist->GetXaxis()->FindBin(deltaPhi)
                  - hist->GetXaxis()->FindBin(0.0);
  Int_t deltaBinY = 0;
  
  for( Int_t nx=0; nx<fXbins; nx++ ){
    Int_t nxbin = nx + deltaBinX;
    if( nxbin>=fXbins ) nxbin -= fXbins;
    for( Int_t ny=0; ny<fYbins; ny++ ){
      Int_t nybin = ny + deltaBinY;
      if( nybin>=fYbins ) nybin -= fYbins;
      hist->SetBinContent(nxbin+1,nybin+1,fHoughArray[nx*fYbins+ny]);
    }
  }

  hist->SetEntries(fEntries);

  hist->GetXaxis()->SetTitle("#phi / degrees");
  hist->GetYaxis()->SetTitle("cos(#theta)");

  return hist;
}

TH2D * WCSimHoughTransform::GetTH2D ( const char *  histname  ) 

Definition at line 160 of file WCSimHoughTransform.cc.

References fEntries, fHoughArray, fXbins, and fYbins.

{
  TH2D* hist = new TH2D(histname,"",fXbins,-180.0,+180.0,fYbins,-1.0,+1.0);

  for( Int_t nx=0; nx<fXbins; nx++ ){
    for( Int_t ny=0; ny<fYbins; ny++ ){
      hist->SetBinContent(nx+1,ny+1,fHoughArray[nx*fYbins+ny]);
    }
  }

  hist->SetEntries(fEntries);

  hist->GetXaxis()->SetTitle("#phi / degrees");
  hist->GetYaxis()->SetTitle("cos(#theta)");

  return hist;
}

Double_t WCSimHoughTransform::GetX ( Int_t  binx  )  [inline]

Definition at line 21 of file WCSimHoughTransform.hh.

References fXbins.

Referenced by FindPeak().

{ return -180.0 + 360.0*(binx+0.5)/fXbins; }

Double_t WCSimHoughTransform::GetY ( Int_t  biny  )  [inline]

Definition at line 22 of file WCSimHoughTransform.hh.

References fYbins.

Referenced by FindPeak().

{ return -1.0 + 2.0*(biny+0.5)/fYbins; }

void WCSimHoughTransform::Reset (  ) 

Definition at line 24 of file WCSimHoughTransform.cc.

References fEntries, fHoughArray, fIntegral, fXbins, and fYbins.

Referenced by WCSimRingFinder::HoughTransform(), and WCSimHoughTransformArray::Reset().

{
  for( Int_t xbin=0; xbin<fXbins; xbin++ ){
    for( Int_t ybin=0; ybin<fYbins; ybin++ ){
      fHoughArray[xbin*fYbins+ybin] = 0.0;
    }
  }

  fEntries = 0;
  fIntegral = 0.0;

  return;
}


Member Data Documentation

Definition at line 37 of file WCSimHoughTransform.hh.

Referenced by Fill(), FindPeak(), GetEntries(), GetRotatedTH2D(), GetTH2D(), and Reset().

Double_t* WCSimHoughTransform::fHoughArray [private]
Double_t WCSimHoughTransform::fIntegral [private]

Definition at line 38 of file WCSimHoughTransform.hh.

Referenced by Fill(), FindPeak(), GetIntegral(), and Reset().

Int_t WCSimHoughTransform::fXbins [private]

Definition at line 40 of file WCSimHoughTransform.hh.

Referenced by Fill(), FindPeak(), GetBinX(), GetRotatedTH2D(), GetTH2D(), GetX(), and Reset().

Int_t WCSimHoughTransform::fYbins [private]

Definition at line 41 of file WCSimHoughTransform.hh.

Referenced by Fill(), FindPeak(), GetBinY(), GetRotatedTH2D(), GetTH2D(), GetY(), and Reset().


The documentation for this class was generated from the following files: