3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliL3StandardIncludes.h"
8 #include "AliL3Logging.h"
9 #include "AliL3HoughClusterTransformer.h"
10 #include "AliL3MemHandler.h"
11 #include "AliL3SpacePointData.h"
12 #include "AliL3Transform.h"
13 #include "AliL3DigitData.h"
14 #include "AliL3Histogram.h"
15 #include "AliL3ClustFinderNew.h"
21 //_____________________________________________________________
22 // AliL3HoughClusterTransformer
24 // Hough transformation class.
26 // This class performs the Hough transform on _clusters_, and not raw data.
27 // Therefore, it first finds the clusters using the HLT cluster finder, and
28 // then uses these as input for the transform.
30 ClassImp(AliL3HoughClusterTransformer)
32 AliL3HoughClusterTransformer::AliL3HoughClusterTransformer()
44 AliL3HoughClusterTransformer::AliL3HoughClusterTransformer(Int_t slice,Int_t patch,Int_t netasegments) : AliL3HoughBaseTransformer(slice,patch,netasegments)
56 AliL3HoughClusterTransformer::~AliL3HoughClusterTransformer()
65 for(Int_t i=0; i<GetNEtaSegments(); i++)
67 if(!fTrackID[i]) continue;
75 //void AliL3HoughClusterTransformer::Init(Int_t slice=0,Int_t patch=0,Int_t netasegments=100){}
77 void AliL3HoughClusterTransformer::DeleteHistograms()
79 //Delete hough space histograms
82 for(Int_t i=0; i<GetNEtaSegments(); i++)
84 if(!fParamSpace[i]) continue;
85 delete fParamSpace[i];
87 delete [] fParamSpace;
91 void AliL3HoughClusterTransformer::CreateHistograms(Int_t nxbin,Float_t ptmin,
92 Int_t nybin,Float_t phimin,Float_t phimax)
94 //Create the histograms (parameter space).
95 //These are 2D histograms, span by kappa (curvature of track) and phi0 (emission angle with x-axis).
96 //The arguments give the range and binning;
97 //nxbin = #bins in kappa
98 //nybin = #bins in phi0
99 //ptmin = mimium Pt of track (corresponding to maximum kappa)
100 //phimin = mimimum phi0 (degrees)
101 //phimax = maximum phi0 (degrees)
103 Double_t x = AliL3Transform::GetBFact()*AliL3Transform::GetBField()/ptmin;
104 Double_t torad = AliL3Transform::Pi()/180;
105 CreateHistograms(nxbin,-1.*x,x,nybin,phimin*torad,phimax*torad);
108 void AliL3HoughClusterTransformer::CreateHistograms(Int_t nxbin,Float_t xmin,Float_t xmax,
109 Int_t nybin,Float_t ymin,Float_t ymax)
111 //Create histograms which contain hough space
112 Char_t histname[256];
114 fParamSpace = new AliL3Histogram*[GetNEtaSegments()];
115 for(Int_t i=0; i<GetNEtaSegments(); i++)
117 sprintf(histname,"paramspace_%d",i);
118 fParamSpace[i] = new AliL3Histogram(histname,"",nxbin,xmin,xmax,nybin,ymin,ymax);
121 Int_t ncells = (nxbin+2)*(nybin+2);
122 cout<<"Allocating "<<GetNEtaSegments()*ncells*sizeof(AliL3TrackIndex)<<" bytes to fTrackID"<<endl;
123 fTrackID = new AliL3TrackIndex*[GetNEtaSegments()];
124 for(Int_t i=0; i<GetNEtaSegments(); i++)
125 fTrackID[i] = new AliL3TrackIndex[ncells];
130 void AliL3HoughClusterTransformer::Reset()
132 //Reset all the histograms
136 LOG(AliL3Log::kWarning,"AliL3HoughClusterTransformer::Reset","Histograms")
137 <<"No histograms to reset"<<ENDLOG;
141 for(Int_t i=0; i<GetNEtaSegments(); i++)
142 fParamSpace[i]->Reset();
149 AliL3Histogram *hist = fParamSpace[0];
150 Int_t ncells = (hist->GetNbinsX()+2)*(hist->GetNbinsY()+2);
151 for(Int_t i=0; i<GetNEtaSegments(); i++)
152 memset(fTrackID[i],0,ncells*sizeof(AliL3TrackIndex));
156 Int_t AliL3HoughClusterTransformer::GetEtaIndex(Double_t eta) const
158 //Return the histogram index of the corresponding eta.
160 Double_t etaslice = (GetEtaMax() - GetEtaMin())/GetNEtaSegments();
161 Double_t index = (eta-GetEtaMin())/etaslice;
165 inline AliL3Histogram *AliL3HoughClusterTransformer::GetHistogram(Int_t etaindex)
167 //Returns the histogram which correspond to a given eta slice
168 if(!fParamSpace || etaindex >= GetNEtaSegments() || etaindex < 0)
170 if(!fParamSpace[etaindex])
172 return fParamSpace[etaindex];
175 Double_t AliL3HoughClusterTransformer::GetEta(Int_t etaindex,Int_t slice) const
177 //Returns eta associated with given eta slice
178 Double_t etaslice = (GetEtaMax()-GetEtaMin())/GetNEtaSegments();
179 Double_t eta=(Double_t)((etaindex+0.5)*etaslice);
180 if(slice>17) eta*=-1;
184 void AliL3HoughClusterTransformer::FindClusters()
187 if(!GetDataPointer())
189 cerr<<"AliL3HoughClusterTransformer::FindClusters : Zero data pointer"<<endl;
193 const Int_t kMaxpoints=100000;
194 const Int_t kPointsize = kMaxpoints * sizeof(AliL3SpacePointData);
196 fMemHandler = new AliL3MemHandler();
197 fClusters = (AliL3SpacePointData*)fMemHandler->Allocate(kPointsize);
198 AliL3ClustFinderNew *cf = new AliL3ClustFinderNew();
199 cf->InitSlice(0,GetPatch(),AliL3Transform::GetFirstRow(GetPatch()),AliL3Transform::GetLastRow(GetPatch()),kMaxpoints);
200 cf->SetDeconv(kFALSE);
201 cf->SetOutputArray(fClusters);
202 cf->Read(1,GetDataPointer());
204 fNClusters = cf->GetNumberOfClusters();
208 void AliL3HoughClusterTransformer::TransformCircle()
210 //Transform the input data with a circle HT.
211 //The function loops over all the data, and transforms each cluster with the equations:
213 //kappa = 2/r*sin(phi - phi0)
215 //where r = sqrt(x*x +y*y), and phi = arctan(y/x)
217 //Each cluster then transforms into a curve in the (kappa,phi0)-space. In order to find
218 //which histogram in which the pixel should be transformed, the eta-value is calcluated
219 //and the proper histogram index is found by GetEtaIndex(eta).
224 LOG(AliL3Log::kError,"AliL3HoughClusterTransformer::TransformCircle","Data")
225 <<"No input data "<<ENDLOG;
230 for(Int_t i=0; i<fNClusters; i++)
232 xyz[0] = fClusters[i].fX;
233 xyz[1] = fClusters[i].fY;
234 xyz[2] = fClusters[i].fZ;
235 Double_t eta = AliL3Transform::GetEta(xyz);
236 Int_t etaindex = GetEtaIndex(eta);
237 if(etaindex < 0 || etaindex >= GetNEtaSegments())
240 AliL3Histogram *hist = fParamSpace[etaindex];
242 //Do the transformation:
243 Double_t r = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
244 Double_t phi = AliL3Transform::GetPhi(xyz);
246 //Fill the histogram along the phirange
247 for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
249 Double_t phi0 = hist->GetBinCenterY(b);
250 Double_t kappa = 2*sin(phi - phi0)/r;
251 hist->Fill(kappa,phi0,1);
253 Int_t bin = hist->FindBin(kappa,phi0);
254 for(Int_t t=0; t<3; t++)
256 Int_t label = fClusters[i].fTrackID[t];
259 for(c=0; c<MaxTrack; c++)
260 if(fTrackID[etaindex][bin].fLabel[c] == label || fTrackID[etaindex][bin].fNHits[c] == 0)
262 if(c == MaxTrack-1) cerr<<"AliL3HoughClusterTransformer::TransformCircle : Array reached maximum!! "<<c<<endl;
263 fTrackID[etaindex][bin].fLabel[c] = label;
264 fTrackID[etaindex][bin].fNHits[c]++;
271 void AliL3HoughClusterTransformer::TransformCircleC(Int_t */*row_range*/,Int_t /*every*/)
273 //Circle transform, using combinations of every 2 points lying
274 //on different padrows and within the same etaslice.
278 LOG(AliL3Log::kError,"AliL3HoughClusterTransformer::TransformCircleC","Data")
279 <<"No input data "<<ENDLOG;
282 Double_t eta,r1,phi1,r2,phi2,kappa,psi;
284 for(Int_t i=0; i<fNClusters; i++)
286 xyz[0] = fClusters[i].fX;
287 xyz[1] = fClusters[i].fY;
288 xyz[2] = fClusters[i].fZ;
289 r1 = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
290 phi1 = atan2(xyz[1],xyz[0]);
291 eta = AliL3Transform::GetEta(xyz);
292 index1 = GetEtaIndex(eta);
293 if(index1 < 0 || index1 >= GetNEtaSegments()) continue;
295 for(Int_t j=i+1; j<fNClusters; j++)
297 if(fClusters[j].fPadRow == fClusters[i].fPadRow) continue;
298 xyz[0] = fClusters[j].fX;
299 xyz[1] = fClusters[j].fY;
300 xyz[2] = fClusters[j].fZ;
301 eta = AliL3Transform::GetEta(xyz);
302 index2 = GetEtaIndex(eta);
303 if(index1 != index2) continue;
305 AliL3Histogram *hist = fParamSpace[index1];
307 r2 = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
308 phi2 = atan2(xyz[1],xyz[0]);
310 psi = atan( (r2*sin(phi1) - r1*sin(phi2)) / (r2*cos(phi1) - r1*cos(phi2)) );
311 kappa = 2*sin(phi1-psi) / r1;
312 hist->Fill(kappa,psi,1);
314 Int_t bin = hist->FindBin(kappa,psi);
315 for(Int_t l=0; l<3; l++)
317 for(Int_t m=0; m<3; m++)
319 if(fClusters[i].fTrackID[l] == fClusters[j].fTrackID[m])
321 Int_t label = fClusters[i].fTrackID[l];
322 if(label < 0) continue;
324 for(c=0; c<MaxTrack; c++)
325 if(fTrackID[index1][bin].fLabel[c] == label || fTrackID[index1][bin].fNHits[c] == 0)
327 if(c == MaxTrack-1) cerr<<"AliL3HoughClusterTransformer::TransformCircleC : Array reached maximum!! "<<c<<endl;
328 fTrackID[index1][bin].fLabel[c] = label;
329 fTrackID[index1][bin].fNHits[c]++;
340 Int_t AliL3HoughClusterTransformer::GetTrackID(Int_t etaindex,Double_t kappa,Double_t psi) const
342 //Returns the mc label for a given bin in the hough space
343 if(etaindex < 0 || etaindex > GetNEtaSegments())
345 cerr<<"AliL3HoughClusterTransformer::GetTrackID : Wrong etaindex "<<etaindex<<endl;
348 AliL3Histogram *hist = fParamSpace[etaindex];
349 Int_t bin = hist->FindBin(kappa,psi);
352 for(UInt_t i=0; i<MaxTrack; i++)
354 Int_t nhits=fTrackID[etaindex][bin].fNHits[i];
355 if(nhits == 0) break;
359 label = fTrackID[etaindex][bin].fLabel[i];
364 Int_t AliL3HoughClusterTransformer::GetTrackID(Int_t /*etaindex*/,Double_t /*kappa*/,Double_t /*psi*/) const
366 // Does nothing if do_mc undefinde
367 cout<<"AliL3HoughClusterTransformer::GetTrackID : Compile with do_mc flag!"<<endl;