5 #include "AliL3TrackArray.h"
6 #include "AliL3HoughTrack.h"
7 #include "AliL3HoughMaxFinder.h"
9 ClassImp(AliL3HoughMaxFinder)
12 AliL3HoughMaxFinder::AliL3HoughMaxFinder()
21 AliL3HoughMaxFinder::AliL3HoughMaxFinder(Char_t *histotype)
25 //fTracks = new AliL3TrackArray("AliL3HoughTrack");
26 if(strcmp(histotype,"KappaPhi")==0) fHistoType='c';
27 if(strcmp(histotype,"DPsi")==0) fHistoType='l';
32 AliL3HoughMaxFinder::~AliL3HoughMaxFinder()
39 AliL3TrackArray *AliL3HoughMaxFinder::FindMaxima(TH2F *hist,Int_t *rowrange,Int_t ref_row)
41 //Locate all the maxima in input histogram.
42 //Maxima is defined as bins with more entries than the
43 //immediately neighbouring bins.
45 Int_t xmin = hist->GetXaxis()->GetFirst();
46 Int_t xmax = hist->GetXaxis()->GetLast();
47 Int_t ymin = hist->GetYaxis()->GetFirst();
48 Int_t ymax = hist->GetYaxis()->GetLast();
49 Int_t bin[9],track_counter=0;
52 AliL3TrackArray *tracks = new AliL3TrackArray("AliL3HoughTrack");
53 AliL3HoughTrack *track;
55 for(Int_t xbin=xmin+1; xbin<xmax-1; xbin++)
57 for(Int_t ybin=ymin+1; ybin<ymax-1; ybin++)
59 bin[0] = hist->GetBin(xbin-1,ybin-1);
60 bin[1] = hist->GetBin(xbin,ybin-1);
61 bin[2] = hist->GetBin(xbin+1,ybin-1);
62 bin[3] = hist->GetBin(xbin-1,ybin);
63 bin[4] = hist->GetBin(xbin,ybin);
64 bin[5] = hist->GetBin(xbin+1,ybin);
65 bin[6] = hist->GetBin(xbin-1,ybin+1);
66 bin[7] = hist->GetBin(xbin,ybin+1);
67 bin[8] = hist->GetBin(xbin+1,ybin+1);
68 value[0] = hist->GetBinContent(bin[0]);
69 value[1] = hist->GetBinContent(bin[1]);
70 value[2] = hist->GetBinContent(bin[2]);
71 value[3] = hist->GetBinContent(bin[3]);
72 value[4] = hist->GetBinContent(bin[4]);
73 value[5] = hist->GetBinContent(bin[5]);
74 value[6] = hist->GetBinContent(bin[6]);
75 value[7] = hist->GetBinContent(bin[7]);
76 value[8] = hist->GetBinContent(bin[8]);
78 if(value[4] <= fThreshold) continue;//central bin below threshold
80 if(value[4]>value[0] && value[4]>value[1] && value[4]>value[2]
81 && value[4]>value[3] && value[4]>value[5] && value[4]>value[6]
82 && value[4]>value[7] && value[4]>value[8])
84 //Found a local maxima
85 Float_t max_x = hist->GetXaxis()->GetBinCenter(xbin);
86 Float_t max_y = hist->GetYaxis()->GetBinCenter(ybin);
88 track = (AliL3HoughTrack*)tracks->NextTrack();
94 track->SetTrackParameters(max_x,max_y,(Int_t)value[4]);
97 track->SetLineParameters(max_x,max_y,(Int_t)value[4],rowrange,ref_row);
100 printf("AliL3HoughMaxFinder: Error in tracktype\n");
108 continue; //not a maxima
115 AliL3TrackArray *AliL3HoughMaxFinder::FindPeak(TH2F *hist,Int_t t1,Double_t t2,Int_t t3)
117 //Attempt of a more sophisticated peak finder.
119 AliL3TrackArray *tracks = new AliL3TrackArray("AliL3HoughTrack");
121 Int_t xmin = hist->GetXaxis()->GetFirst();
122 Int_t xmax = hist->GetXaxis()->GetLast();
123 Int_t ymin = hist->GetYaxis()->GetFirst();
124 Int_t ymax = hist->GetYaxis()->GetLast();
125 Int_t nbinsx = hist->GetXaxis()->GetNbins();
127 Int_t *m = new Int_t[nbinsx];
128 Int_t *m_low = new Int_t[nbinsx];
129 Int_t *m_up = new Int_t[nbinsx];
132 recompute: //this is a goto.
134 for(Int_t i=0; i<nbinsx; i++)
141 Int_t max_x=0,sum=0,max_xbin=0,bin;
143 for(Int_t xbin=xmin; xbin<=xmax; xbin++)
145 for(Int_t ybin=ymin; ybin < ymax - t1; ybin++)
148 for(Int_t y=ybin; y < ybin+t1; y++)
151 bin = hist->GetBin(xbin,y);
152 sum += (Int_t)hist->GetBinContent(bin);
155 if(sum > m[xbin]) //Max value locally in this xbin
159 m_up[xbin]=ybin + t1 - 1;
164 if(m[xbin] > max_x) //Max value globally in x-direction
167 max_x = m[xbin];//sum;
170 //printf("max_xbin %d max_x %d m_low %d m_up %d\n",max_xbin,max_x,m_low[max_xbin],m_up[max_xbin]);
171 //printf("ylow %f yup %f\n",hist->GetYaxis()->GetBinCenter(m_low[max_xbin]),hist->GetYaxis()->GetBinCenter(m_up[max_xbin]));
173 //Determine a width in the x-direction
174 Int_t x_low=0,x_up=0;
175 for(Int_t xbin=max_xbin-1; xbin >= xmin; xbin--)
177 if(m[xbin]*t2 < max_x)
183 for(Int_t xbin = max_xbin+1; xbin <=xmax; xbin++)
185 if(m[xbin]*t2 < max_x)
192 Double_t top=0,butt=0,value,x_peak;
193 if(x_up - x_low + 1 > t3)
196 printf("\nxrange out if limit x_up %d x_low %d\n\n",x_low,x_up);
201 x_peak = hist->GetXaxis()->GetBinCenter(max_xbin);
206 //printf("xlow %f xup %f\n",hist->GetXaxis()->GetBinCenter(x_low),hist->GetXaxis()->GetBinCenter(x_up));
207 //printf("Spread in x %d\n",x_up-x_low +1);
209 //Now, calculate the center of mass in x-direction
210 for(Int_t xbin=x_low; xbin <= x_up; xbin++)
212 value = hist->GetXaxis()->GetBinCenter(xbin);
213 top += value*m[xbin];
220 //Find the peak in y direction:
221 Int_t x_l = hist->GetXaxis()->FindBin(x_peak);
222 if(hist->GetXaxis()->GetBinCenter(x_l) > x_peak)
227 if(hist->GetXaxis()->GetBinCenter(x_l) > x_peak || hist->GetXaxis()->GetBinCenter(x_u) <= x_peak)
228 printf("\nAliL3HoughMaxFinder::FindPeak : Wrong xrange %f %f %f\n\n",hist->GetXaxis()->GetBinCenter(x_l),x_peak,hist->GetXaxis()->GetBinCenter(x_u));
230 //printf("\nxlow %f xup %f\n",hist->GetXaxis()->GetBinCenter(x_l),hist->GetXaxis()->GetBinCenter(x_u));
234 //printf("ylow %f yup %f\n",hist->GetYaxis()->GetBinCenter(m_low[x_l]),hist->GetYaxis()->GetBinCenter(m_up[x_l]));
235 //printf("ylow %f yup %f\n",hist->GetYaxis()->GetBinCenter(m_low[x_u]),hist->GetYaxis()->GetBinCenter(m_up[x_u]));
237 for(Int_t ybin=m_low[x_l]; ybin <= m_up[x_l]; ybin++)
239 value = hist->GetYaxis()->GetBinCenter(ybin);
240 bin = hist->GetBin(x_l,ybin);
241 top += value*hist->GetBinContent(bin);
242 butt += hist->GetBinContent(bin);
244 Double_t y_peak_low = top/butt;
246 //printf("y_peak_low %f\n",y_peak_low);
249 for(Int_t ybin=m_low[x_u]; ybin <= m_up[x_u]; ybin++)
251 value = hist->GetYaxis()->GetBinCenter(ybin);
252 bin = hist->GetBin(x_u,ybin);
253 top += value*hist->GetBinContent(bin);
254 butt += hist->GetBinContent(bin);
256 Double_t y_peak_up = top/butt;
258 //printf("y_peak_up %f\n",y_peak_up);
260 Double_t x_value_up = hist->GetXaxis()->GetBinCenter(x_u);
261 Double_t x_value_low = hist->GetXaxis()->GetBinCenter(x_l);
263 Double_t y_peak = (y_peak_low*(x_value_up - x_peak) + y_peak_up*(x_peak - x_value_low))/(x_value_up - x_value_low);
267 bin = hist->FindBin(x_peak,y_peak);
268 Int_t weight = (Int_t)hist->GetBinContent(bin);
270 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->NextTrack();
271 track->SetTrackParameters(x_peak,y_peak,weight);