2 #include "AliITSSAPLayer.h"
3 #include "AliITSSAPAux.h"
4 #include "AliITSRecPoint.h"
5 #include "AliITSgeomTGeo.h"
8 #include <TStopwatch.h>
12 using namespace AliITSSAPAux;
14 //_________________________________________________________________
15 AliITSSAPLayer::AliITSSAPLayer() :
34 ,fFoundClusterIterator(0)
42 //_________________________________________________________________
43 AliITSSAPLayer::AliITSSAPLayer(int id, float zspan,int nzbins,int nphibins, int buffer) :
46 ,fVIDOffset((id+1)*2048)
62 ,fFoundClusterIterator(0)
71 //_________________________________________________________________
72 AliITSSAPLayer::~AliITSSAPLayer()
80 //_________________________________________________________________
81 void AliITSSAPLayer::Init(int buffer)
84 printf("Already initialized\n");
87 if (fNZBins<1) fNZBins = 2;
88 if (fNPhiBins<1) fNPhiBins = 1;
89 fDZInv = fNZBins/(fZMax-fZMin);
90 fDPhiInv = fNPhiBins/TMath::TwoPi();
92 fBins = new ClBinInfo_t[fNZBins*fNPhiBins];
93 fOccBins = new int[fNZBins*fNPhiBins];
94 if (buffer<100) buffer = 100;
95 fClusters = new TObjArray(buffer);
96 fSortedClInfo.reserve(buffer);
98 // prepare detectors info
100 Int_t nlad=AliITSgeomTGeo::GetNLadders(id1);
101 Int_t ndet=AliITSgeomTGeo::GetNDetectors(id1);
103 for (Int_t j=1; j<nlad+1; j++) {
104 for (Int_t k=1; k<ndet+1; k++) { //Fill this layer with detectors
108 TGeoHMatrix m; AliITSgeomTGeo::GetOrigMatrix(id1,j,k,m);
109 const TGeoHMatrix *tm=AliITSgeomTGeo::GetTracking2LocalMatrix(id1,j,k);
111 Double_t txyz[3] = {0.}, xyz[3] = {0.};
112 m.LocalToMaster(txyz,xyz);
113 det.xTF = TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
114 det.phiTF = TMath::ATan2(xyz[1],xyz[0]);
115 //BringTo02Pi(det.phiTF);
116 det.sinTF = TMath::Sin(det.phiTF);
117 det.cosTF = TMath::Cos(det.phiTF);
119 // compute the real radius (with misalignment)
120 TGeoHMatrix mmisal(*(AliITSgeomTGeo::GetMatrix(id1,j,k)));
122 xyz[0]=0.;xyz[1]=0.;xyz[2]=0.;
123 mmisal.LocalToMaster(txyz,xyz);
124 det.xTFmisal=TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
126 fDetectors.push_back(det);
127 } // end loop on detectors
128 } // end loop on ladders
132 //_________________________________________________________________
133 void AliITSSAPLayer::SortClusters(const AliVertex* vtx)
135 // sort clusters and build fast lookup table
138 fSortedClInfo.reserve(fNClusters);
141 for (int icl=fNClusters;icl--;) {
142 AliITSRecPoint* cluster = (AliITSRecPoint*)fClusters->UncheckedAt(icl);
143 cluster->GetGlobalXYZ( (float*)&cl );
145 if (vtx) { // phi and r will be computed wrt vertex
150 cl.r = TMath::Sqrt(cl.x*cl.x + cl.y*cl.y);
151 cl.phi = TMath::ATan2(cl.y,cl.x);
154 cl.zphibin = GetBinIndex(GetZBin(cl.z),GetPhiBin(cl.phi));
155 cl.detid = cluster->GetVolumeId() - fVIDOffset;
157 fSortedClInfo.push_back( cl );
160 sort(fSortedClInfo.begin(), fSortedClInfo.end()); // sort in phi, z
162 // fill cells in phi,z
164 for (int icl=0;icl<fNClusters;icl++) {
165 ClsInfo_t &t = fSortedClInfo[icl];
166 if (t.zphibin>currBin) { // register new occupied bin
168 fBins[currBin].first = icl;
169 fBins[currBin].index = fNOccBins;
170 fOccBins[fNOccBins++] = currBin;
172 fBins[currBin].ncl++;
174 // Print("clb"); //RS
177 //_________________________________________________________________
178 void AliITSSAPLayer::Clear(Option_t *)
180 // clear cluster info
183 if (fClusters) fClusters->Clear();
187 //_________________________________________________________________
188 void AliITSSAPLayer::ClearSortedInfo()
190 // clear cluster info
191 fSortedClInfo.clear();
192 memset(fBins,0,fNZBins*fNPhiBins*sizeof(ClBinInfo_t));
193 memset(fOccBins,0,fNZBins*fNPhiBins*sizeof(int));
197 //_________________________________________________________________
198 void AliITSSAPLayer::Print(Option_t *opt) const
200 // dump cluster bins info
203 printf("Stored %d clusters in %d occupied bins\n",fNClusters,fNOccBins);
205 if (opts.Contains("c")) {
206 printf("\nCluster info\n");
207 for (int i=0;i<fNClusters;i++) {
208 const ClsInfo_t &t = fSortedClInfo[i];
209 printf("#%5d Bin(phi/z):%03d/%03d Z:%+8.3f Phi:%+6.3f R:%7.3f Ind:%d ",
210 i,t.zphibin/fNZBins,t.zphibin%fNZBins,t.z,t.phi,t.r,t.index);
211 if (opts.Contains("l")) { // mc labels
212 AliITSRecPoint* rp = (AliITSRecPoint*)fClusters->UncheckedAt(t.index);
213 for (int l=0;l<3;l++) if (rp->GetLabel(l)>=0) printf("| %d ",rp->GetLabel(l));
219 if (opts.Contains("b")) {
220 printf("\nBins info (occupied only)\n");
221 for (int i=0;i<fNOccBins;i++) {
222 printf("%4d %5d(phi/z: %03d/%03d) -> %3d cl from %d\n",i,fOccBins[i],fOccBins[i]/fNZBins,fOccBins[i]%fNZBins,
223 fBins[fOccBins[i]].ncl,fBins[fOccBins[i]].first);
229 //_____________________________________________________________
230 int AliITSSAPLayer::SelectClusters(float zmin,float zmax,float phimin,float phimax)
232 // prepare occupied bins in the requested region
233 //printf("Select: Z %f %f | Phi: %f %f\n",zmin,zmax,phimin,phimax);
234 if (!fNOccBins) return 0;
235 if (zmax<fZMin || zmin>fZMax || zmin>zmax) return 0;
238 fQueryZBmin = GetZBin(zmin);
239 if (fQueryZBmin<0) fQueryZBmin = 0;
240 fQueryZBmax = GetZBin(zmax);
241 if (fQueryZBmax>=fNZBins) fQueryZBmax = fNZBins-1;
244 fQueryPhiBmin = GetPhiBin(phimin);
245 fQueryPhiBmax = GetPhiBin(phimax);
248 int nbcheck = fQueryPhiBmax - fQueryPhiBmin + 1;
249 if (nbcheck>0) { // no wrapping around 0-2pi, fast case
250 for (int ip=fQueryPhiBmin;ip<=fQueryPhiBmax;ip++) {
251 int binID = GetBinIndex(fQueryZBmin,ip);
252 if ( !(dbz=(fQueryZBmax-fQueryZBmin)) ) { // just one Z bin in the query range
253 ClBinInfo_t& binInfo = fBins[binID];
254 if (!binInfo.ncl) continue;
255 fNFoundClusters += binInfo.ncl;
256 fFoundBins.push_back(binID);
259 int binMax = binID+dbz;
260 for (;binID<=binMax;binID++) {
261 ClBinInfo_t& binInfo = fBins[binID];
262 if (!binInfo.ncl) continue;
263 fNFoundClusters += binInfo.ncl;
264 fFoundBins.push_back(binID);
269 nbcheck += fNPhiBins;
270 for (int ip0=0;ip0<=nbcheck;ip0++) {
271 int ip = fQueryPhiBmin+ip0;
272 if (ip>=fNPhiBins) ip -= fNPhiBins;
273 int binID = GetBinIndex(fQueryZBmin,ip);
274 if ( !(dbz=(fQueryZBmax-fQueryZBmin)) ) { // just one Z bin in the query range
275 ClBinInfo_t& binInfo = fBins[binID];
276 if (!binInfo.ncl) continue;
277 fNFoundClusters += binInfo.ncl;
278 fFoundBins.push_back(binID);
281 int binMax = binID+dbz;
282 for (;binID<=binMax;binID++) {
283 ClBinInfo_t& binInfo = fBins[binID];
284 if (!binInfo.ncl) continue;
285 fNFoundClusters += binInfo.ncl;
286 fFoundBins.push_back(binID);
290 fFoundClusterIterator = fFoundBinIterator = 0;
292 //printf("Selected -> %d cl in %d bins\n",fNFoundClusters,(int)fFoundBins.size());
293 for (int i=0;i<(int)fFoundBins.size();i++) {
294 int bn = fFoundBins[i];
295 ClBinInfo_t& bin=fBins[bn];
296 printf("#%d b:%d 1st: %3d Ncl:%d\n",i,bn,bin.first,bin.ncl);
300 return fNFoundClusters;
303 //_____________________________________________________________
304 int AliITSSAPLayer::GetNextClusterInfoID()
306 if (fFoundBinIterator<0) return 0;
307 int currBin = fFoundBins[fFoundBinIterator];
308 if (fFoundClusterIterator<fBins[currBin].ncl) { // same bin
309 return fBins[currBin].first+fFoundClusterIterator++;
311 if (++fFoundBinIterator<int(fFoundBins.size())) { // need to change bin
312 currBin = fFoundBins[fFoundBinIterator];
313 fFoundClusterIterator = 1;
314 return fBins[currBin].first;
316 fFoundBinIterator = -1;
320 //_____________________________________________________________
321 void AliITSSAPLayer::ResetFoundIterator()
323 // prepare for a new loop over found clusters
324 if (fNFoundClusters) fFoundClusterIterator = fFoundBinIterator = 0;