]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/ITS/trackingSAP/AliITSSAPLayer.cxx
flat friend update
[u/mrichter/AliRoot.git] / HLT / ITS / trackingSAP / AliITSSAPLayer.cxx
CommitLineData
c9598e1c 1#include <TMath.h>
2#include "AliITSSAPLayer.h"
3#include "AliITSSAPAux.h"
4#include "AliITSRecPoint.h"
5#include "AliITSgeomTGeo.h"
6#include "AliVertex.h"
7#include <TRandom.h>
8#include <TStopwatch.h>
9#include <TString.h>
10
11
12using namespace AliITSSAPAux;
13
14//_________________________________________________________________
15AliITSSAPLayer::AliITSSAPLayer() :
16 fClusters(0)
17 ,fLrID(-1)
18 ,fVIDOffset(0)
19 ,fNClusters(0)
20 ,fZMin(0)
21 ,fZMax(0)
22 ,fDZInv(-1)
23 ,fDPhiInv(-1)
24 ,fNZBins(20)
25 ,fNPhiBins(20)
26 ,fQueryZBmin(-1)
27 ,fQueryZBmax(-1)
28 ,fQueryPhiBmin(-1)
29 ,fQueryPhiBmax(-1)
30 ,fBins(0)
31 ,fOccBins(0)
32 ,fNOccBins(0)
33 ,fNFoundClusters(0)
34 ,fFoundClusterIterator(0)
35 ,fFoundBinIterator(0)
d83c9170 36 ,fFoundBins()
37 ,fSortedClInfo()
38 ,fDetectors()
c9598e1c 39{
40 // def. c-tor
41}
42
43//_________________________________________________________________
44AliITSSAPLayer::AliITSSAPLayer(int id, float zspan,int nzbins,int nphibins, int buffer) :
45 fClusters(0)
46 ,fLrID(id)
47 ,fVIDOffset((id+1)*2048)
48 ,fNClusters(0)
49 ,fZMin(-zspan)
50 ,fZMax(zspan)
51 ,fDZInv(-1)
52 ,fDPhiInv(-1)
53 ,fNZBins(nzbins)
54 ,fNPhiBins(nphibins)
55 ,fQueryZBmin(-1)
56 ,fQueryZBmax(-1)
57 ,fQueryPhiBmin(-1)
58 ,fQueryPhiBmax(-1)
59 ,fBins(0)
60 ,fOccBins(0)
61 ,fNOccBins(0)
62 ,fNFoundClusters(0)
63 ,fFoundClusterIterator(0)
64 ,fFoundBinIterator(0)
d83c9170 65 ,fFoundBins()
66 ,fSortedClInfo()
67 ,fDetectors()
c9598e1c 68{
69 // c-tor
70 Init(buffer);
71}
72
73//_________________________________________________________________
74AliITSSAPLayer::~AliITSSAPLayer()
75{
76 // d-tor
77 delete[] fBins;
78 delete[] fOccBins;
79 delete fClusters;
80}
81
82//_________________________________________________________________
83void AliITSSAPLayer::Init(int buffer)
84{
85 if (fClusters) {
86 printf("Already initialized\n");
87 return;
88 }
89 if (fNZBins<1) fNZBins = 2;
90 if (fNPhiBins<1) fNPhiBins = 1;
91 fDZInv = fNZBins/(fZMax-fZMin);
92 fDPhiInv = fNPhiBins/TMath::TwoPi();
93 //
94 fBins = new ClBinInfo_t[fNZBins*fNPhiBins];
95 fOccBins = new int[fNZBins*fNPhiBins];
96 if (buffer<100) buffer = 100;
97 fClusters = new TObjArray(buffer);
98 fSortedClInfo.reserve(buffer);
99 //
100 // prepare detectors info
101 int id1 = fLrID+1;
102 Int_t nlad=AliITSgeomTGeo::GetNLadders(id1);
103 Int_t ndet=AliITSgeomTGeo::GetNDetectors(id1);
104 int detID = 0;
105 for (Int_t j=1; j<nlad+1; j++) {
106 for (Int_t k=1; k<ndet+1; k++) { //Fill this layer with detectors
107 ITSDetInfo_t det;
108 det.index = detID++;
109 //
110 TGeoHMatrix m; AliITSgeomTGeo::GetOrigMatrix(id1,j,k,m);
111 const TGeoHMatrix *tm=AliITSgeomTGeo::GetTracking2LocalMatrix(id1,j,k);
112 m.Multiply(tm);
113 Double_t txyz[3] = {0.}, xyz[3] = {0.};
114 m.LocalToMaster(txyz,xyz);
115 det.xTF = TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
116 det.phiTF = TMath::ATan2(xyz[1],xyz[0]);
117 //BringTo02Pi(det.phiTF);
118 det.sinTF = TMath::Sin(det.phiTF);
119 det.cosTF = TMath::Cos(det.phiTF);
120 //
121 // compute the real radius (with misalignment)
122 TGeoHMatrix mmisal(*(AliITSgeomTGeo::GetMatrix(id1,j,k)));
123 mmisal.Multiply(tm);
124 xyz[0]=0.;xyz[1]=0.;xyz[2]=0.;
125 mmisal.LocalToMaster(txyz,xyz);
126 det.xTFmisal=TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
127 //
128 fDetectors.push_back(det);
129 } // end loop on detectors
130 } // end loop on ladders
131
132}
133
134//_________________________________________________________________
135void AliITSSAPLayer::SortClusters(const AliVertex* vtx)
136{
137 // sort clusters and build fast lookup table
138 //
139 ClearSortedInfo();
140 fSortedClInfo.reserve(fNClusters);
141 //
142 ClsInfo_t cl;
143 for (int icl=fNClusters;icl--;) {
144 AliITSRecPoint* cluster = (AliITSRecPoint*)fClusters->UncheckedAt(icl);
145 cluster->GetGlobalXYZ( (float*)&cl );
146 //
147 if (vtx) { // phi and r will be computed wrt vertex
148 cl.x -= vtx->GetX();
149 cl.y -= vtx->GetY();
150 }
151 //
152 cl.r = TMath::Sqrt(cl.x*cl.x + cl.y*cl.y);
153 cl.phi = TMath::ATan2(cl.y,cl.x);
154 BringTo02Pi(cl.phi);
155 cl.index = icl;
156 cl.zphibin = GetBinIndex(GetZBin(cl.z),GetPhiBin(cl.phi));
157 cl.detid = cluster->GetVolumeId() - fVIDOffset;
158 //
159 fSortedClInfo.push_back( cl );
160 //
161 }
162 sort(fSortedClInfo.begin(), fSortedClInfo.end()); // sort in phi, z
163 //
164 // fill cells in phi,z
165 int currBin = -1;
166 for (int icl=0;icl<fNClusters;icl++) {
167 ClsInfo_t &t = fSortedClInfo[icl];
168 if (t.zphibin>currBin) { // register new occupied bin
169 currBin = t.zphibin;
170 fBins[currBin].first = icl;
171 fBins[currBin].index = fNOccBins;
172 fOccBins[fNOccBins++] = currBin;
173 }
174 fBins[currBin].ncl++;
175 }
176 // Print("clb"); //RS
177}
178
179//_________________________________________________________________
180void AliITSSAPLayer::Clear(Option_t *)
181{
182 // clear cluster info
183 ClearSortedInfo();
184 fNClusters = 0;
185 if (fClusters) fClusters->Clear();
186 //
187}
188
189//_________________________________________________________________
190void AliITSSAPLayer::ClearSortedInfo()
191{
192 // clear cluster info
193 fSortedClInfo.clear();
194 memset(fBins,0,fNZBins*fNPhiBins*sizeof(ClBinInfo_t));
195 memset(fOccBins,0,fNZBins*fNPhiBins*sizeof(int));
196 fNOccBins = 0;
197}
198
199//_________________________________________________________________
200void AliITSSAPLayer::Print(Option_t *opt) const
201{
202 // dump cluster bins info
203 TString opts = opt;
204 opts.ToLower();
205 printf("Stored %d clusters in %d occupied bins\n",fNClusters,fNOccBins);
206 //
207 if (opts.Contains("c")) {
208 printf("\nCluster info\n");
209 for (int i=0;i<fNClusters;i++) {
210 const ClsInfo_t &t = fSortedClInfo[i];
211 printf("#%5d Bin(phi/z):%03d/%03d Z:%+8.3f Phi:%+6.3f R:%7.3f Ind:%d ",
212 i,t.zphibin/fNZBins,t.zphibin%fNZBins,t.z,t.phi,t.r,t.index);
213 if (opts.Contains("l")) { // mc labels
214 AliITSRecPoint* rp = (AliITSRecPoint*)fClusters->UncheckedAt(t.index);
215 for (int l=0;l<3;l++) if (rp->GetLabel(l)>=0) printf("| %d ",rp->GetLabel(l));
216 }
217 printf("\n");
218 }
219 }
220 //
221 if (opts.Contains("b")) {
222 printf("\nBins info (occupied only)\n");
223 for (int i=0;i<fNOccBins;i++) {
224 printf("%4d %5d(phi/z: %03d/%03d) -> %3d cl from %d\n",i,fOccBins[i],fOccBins[i]/fNZBins,fOccBins[i]%fNZBins,
225 fBins[fOccBins[i]].ncl,fBins[fOccBins[i]].first);
226 }
227 }
228 //
229}
230
231//_____________________________________________________________
232int AliITSSAPLayer::SelectClusters(float zmin,float zmax,float phimin,float phimax)
233{
234 // prepare occupied bins in the requested region
235 //printf("Select: Z %f %f | Phi: %f %f\n",zmin,zmax,phimin,phimax);
236 if (!fNOccBins) return 0;
237 if (zmax<fZMin || zmin>fZMax || zmin>zmax) return 0;
238 fFoundBins.clear();
239
240 fQueryZBmin = GetZBin(zmin);
241 if (fQueryZBmin<0) fQueryZBmin = 0;
242 fQueryZBmax = GetZBin(zmax);
243 if (fQueryZBmax>=fNZBins) fQueryZBmax = fNZBins-1;
244 BringTo02Pi(phimin);
245 BringTo02Pi(phimax);
246 fQueryPhiBmin = GetPhiBin(phimin);
247 fQueryPhiBmax = GetPhiBin(phimax);
248 int dbz=0;
249 fNFoundClusters = 0;
250 int nbcheck = fQueryPhiBmax - fQueryPhiBmin + 1;
251 if (nbcheck>0) { // no wrapping around 0-2pi, fast case
252 for (int ip=fQueryPhiBmin;ip<=fQueryPhiBmax;ip++) {
253 int binID = GetBinIndex(fQueryZBmin,ip);
254 if ( !(dbz=(fQueryZBmax-fQueryZBmin)) ) { // just one Z bin in the query range
255 ClBinInfo_t& binInfo = fBins[binID];
256 if (!binInfo.ncl) continue;
257 fNFoundClusters += binInfo.ncl;
258 fFoundBins.push_back(binID);
259 continue;
260 }
261 int binMax = binID+dbz;
262 for (;binID<=binMax;binID++) {
263 ClBinInfo_t& binInfo = fBins[binID];
264 if (!binInfo.ncl) continue;
265 fNFoundClusters += binInfo.ncl;
266 fFoundBins.push_back(binID);
267 }
268 }
269 }
270 else { // wrapping
271 nbcheck += fNPhiBins;
272 for (int ip0=0;ip0<=nbcheck;ip0++) {
273 int ip = fQueryPhiBmin+ip0;
274 if (ip>=fNPhiBins) ip -= fNPhiBins;
275 int binID = GetBinIndex(fQueryZBmin,ip);
276 if ( !(dbz=(fQueryZBmax-fQueryZBmin)) ) { // just one Z bin in the query range
277 ClBinInfo_t& binInfo = fBins[binID];
278 if (!binInfo.ncl) continue;
279 fNFoundClusters += binInfo.ncl;
280 fFoundBins.push_back(binID);
281 continue;
282 }
283 int binMax = binID+dbz;
284 for (;binID<=binMax;binID++) {
285 ClBinInfo_t& binInfo = fBins[binID];
286 if (!binInfo.ncl) continue;
287 fNFoundClusters += binInfo.ncl;
288 fFoundBins.push_back(binID);
289 }
290 }
291 }
292 fFoundClusterIterator = fFoundBinIterator = 0;
293 /*
294 //printf("Selected -> %d cl in %d bins\n",fNFoundClusters,(int)fFoundBins.size());
295 for (int i=0;i<(int)fFoundBins.size();i++) {
296 int bn = fFoundBins[i];
297 ClBinInfo_t& bin=fBins[bn];
298 printf("#%d b:%d 1st: %3d Ncl:%d\n",i,bn,bin.first,bin.ncl);
299 }
300 printf("\n");
301 */
302 return fNFoundClusters;
303}
304
305//_____________________________________________________________
306int AliITSSAPLayer::GetNextClusterInfoID()
307{
308 if (fFoundBinIterator<0) return 0;
309 int currBin = fFoundBins[fFoundBinIterator];
310 if (fFoundClusterIterator<fBins[currBin].ncl) { // same bin
311 return fBins[currBin].first+fFoundClusterIterator++;
312 }
313 if (++fFoundBinIterator<int(fFoundBins.size())) { // need to change bin
314 currBin = fFoundBins[fFoundBinIterator];
315 fFoundClusterIterator = 1;
316 return fBins[currBin].first;
317 }
318 fFoundBinIterator = -1;
319 return -1;
320}
321
322//_____________________________________________________________
323void AliITSSAPLayer::ResetFoundIterator()
324{
325 // prepare for a new loop over found clusters
326 if (fNFoundClusters) fFoundClusterIterator = fFoundBinIterator = 0;
327}