IslandsTH2.cxx
Go to the documentation of this file.
1 ///////////////////////////////////////////////
2 /// \brief TODO
3 /// \author mbaird42@fnal.gov
4 /// \date
5 /////////////////////////////////////////////
7 
8 #include "TMath.h"
9 
10 namespace hough
11 {
12  //.....................................
14  const char* t,
15  const TH2* h,
16  double q,
17  bool wrapx,
18  bool wrapy) :
19  TH2S(n,
20  t,
21  h->GetNbinsX(),
22  h->GetXaxis()->GetXmin(),
23  h->GetXaxis()->GetXmax(),
24  h->GetNbinsY(),
25  h->GetYaxis()->GetXmin(),
26  h->GetYaxis()->GetXmax()),
27  fPco(q),
28  fWrapX(wrapx),
29  fWrapY(wrapy),
30  fNx(h->GetNbinsX()),
31  fNy(h->GetNbinsY()),
32  fNislands(0)
33  { }
34 
35  //......................................................................
36 
37  void IslandsTH2::LabelIslands(const TH2* h)
38  {
39 
40  int a;
41  int b;
42  double Pave = 0.0; // average peak height
43  double Ps = 0.0; // standard deviation of average peak height
44  double th = 0.0; // threshold to use for peak cutoff
45  int nb = 0; // number of bins counted for avergae peak height
46 
47  // calculate average peak height to determine threshold
48  // empty bins are NOT counted
49  for (a = 1; a <= fNx; ++a) {
50  for (b = 1; b <= fNy; ++b) {
51  if (h->GetBinContent(a,b) != 0) {
52  Pave += h->GetBinContent(a,b);
53  Ps += (h->GetBinContent(a,b))*(h->GetBinContent(a,b));
54  nb++;
55  } // end if
56  } // end for b
57  } // end for a
58 
59  Pave = Pave/nb;
60  Ps = sqrt(Ps/nb - Pave*Pave);
61 
62  th = Pave + fPco*Ps;
63 
64 
65  int i;
66  int j;
67  for (i=1; i<=fNx; ++i) {
68  for (j=1; j<=fNy; ++j) {
69  if (this->GetBinContent(i,j) == 0 && h->GetBinContent(i,j) >= th) {
70  ++fNislands;
71  this->Mark(h,i,j,fNislands,th);
72  } // end if
73  } // end for j
74  } // end for i
75 
76  } // end LabelIslands
77 
78  //......................................................................
79 
80  int IslandsTH2::Neighbor(int i, int m, int n, bool wrap)
81  {
82  int ix = i+m;
83  if (ix==0) {
84  if (wrap) return n;
85  else return -1;
86  }
87  if (ix>n) {
88  if (wrap) return 1;
89  else return -1;
90  }
91  return ix;
92  }
93 
94  //......................................................................
95 
96  void IslandsTH2::Mark(const TH2* h, int i, int j, int isl_indx, double th)
97  {
98  int m, n;
99  int ix, iy;
100 
101  this->SetBinContent(i,j,isl_indx);
102  for (m=-1; m<=1; ++m) {
103  ix = this->Neighbor(i,m,fNx,fWrapX);
104  if (ix==-1) continue;
105  for (n=-1; n<=1; ++n) {
106  if (m==0 && n==0) continue;
107  iy = this->Neighbor(j,n,fNy,fWrapY);
108  if (iy==-1) continue;
109  if (this->GetBinContent(ix,iy) == 0 && h->GetBinContent(ix,iy) >= th) {
110  this->Mark(h,ix,iy,isl_indx,th);
111  }
112  }
113  }
114  }
115 } // end namespace hough
116 ////////////////////////////////////////////////////////////////////////
int Neighbor(int i, int d, int imx, bool wrap)
Definition: IslandsTH2.cxx:80
bool fWrapY
Wrap around the y boundaries?
Definition: IslandsTH2.h:28
Perform a "2 point" Hough transform on a collection of hits.
Definition: Hough2P.cxx:20
correl_xv GetYaxis() -> SetDecimals()
T sqrt(T number)
Definition: d0nt_math.hpp:156
double fPco
Number of sigma above average peak height to use for peak threshold.
Definition: IslandsTH2.h:26
void Mark(const TH2 *h, int i, int j, int isl_indx, double th)
Definition: IslandsTH2.cxx:96
std::void_t< T > n
const double a
correl_xv GetXaxis() -> SetDecimals()
int fNx
Number of bins along x.
Definition: IslandsTH2.h:29
const double j
Definition: BetheBloch.cxx:29
unsigned int fNislands
Number of islands found.
Definition: IslandsTH2.h:31
bool fWrapX
Wrap around the x boundaries?
Definition: IslandsTH2.h:27
void LabelIslands(const TH2 *h)
Definition: IslandsTH2.cxx:37
cout<< "--"<< endl;for(Int_t iP=1;iP<=hyz->GetNbinsX();iP++){for(Int_t iC=1;iC<=hyz->GetNbinsY();iC++){if(hyv->GetBinContent(iP, iC)>-999){goal_hyv-> SetBinContent(iP, iC,-(dy[iP-1][iC-1]))
IslandsTH2(const char *n, const char *t, const TH2 *h, double q, bool wrapx, bool wrapy)
Definition: IslandsTH2.cxx:13
int fNy
Number of bins along y.
Definition: IslandsTH2.h:30
const hit & b
Definition: hits.cxx:21
static const double nb
Definition: Units.h:89