1 // **************************************************************************
2 // This file is property of and copyright by the ALICE HLT Project *
3 // ALICE Experiment at CERN, All rights reserved. *
5 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
6 // for The ALICE HLT Project. *
8 // Permission to use, copy, modify and distribute this software and its *
9 // documentation strictly for non-commercial purposes is hereby granted *
10 // without fee, provided that the above copyright notice appears in all *
11 // copies and that both the copyright notice and this permission notice *
12 // appear in the supporting documentation. The authors make no claims *
13 // about the suitability of this software for any purpose. It is *
14 // provided "as is" without express or implied warranty. *
16 //***************************************************************************
19 #include "AliHLTITSLayer.h"
21 //------------------------------------------------------------------------
22 AliHLTITSLayer::AliHLTITSLayer():
47 //--------------------------------------------------------------------
48 //default AliHLTITSLayer constructor
49 //--------------------------------------------------------------------
50 for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++) {
52 fClusterTracks[0][i]=-1;
53 fClusterTracks[1][i]=-1;
54 fClusterTracks[2][i]=-1;
55 fClusterTracks[3][i]=-1;
58 //------------------------------------------------------------------------
60 AliHLTITSLayer(Double_t r,Double_t p,Double_t z,Int_t nl,Int_t nd):
85 //--------------------------------------------------------------------
86 //main AliHLTITSLayer constructor
87 //--------------------------------------------------------------------
88 fDetectors=new AliHLTITSDetector[fNladders*fNdetectors];
89 fRoad=2*fR*TMath::Sqrt(TMath::Pi()/1.);//assuming that there's only one cluster
91 //------------------------------------------------------------------------
92 AliHLTITSLayer::AliHLTITSLayer(const AliHLTITSLayer& layer):
94 fPhiOffset(layer.fPhiOffset),
95 fNladders(layer.fNladders),
96 fZOffset(layer.fZOffset),
97 fNdetectors(layer.fNdetectors),
98 fDetectors(layer.fDetectors),
103 fClustersCs(layer.fClustersCs),
104 fClusterIndexCs(layer.fClusterIndexCs),
108 fCurrentSlice(layer.fCurrentSlice),
115 fAccepted(layer.fAccepted),
119 //------------------------------------------------------------------------
120 AliHLTITSLayer::~AliHLTITSLayer() {
121 //--------------------------------------------------------------------
122 // AliHLTITSLayer destructor
123 //--------------------------------------------------------------------
124 delete [] fDetectors;
125 for (Int_t i=0; i<fN; i++) delete fClusters[i];
126 for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++) {
128 fClusterTracks[0][i]=-1;
129 fClusterTracks[1][i]=-1;
130 fClusterTracks[2][i]=-1;
131 fClusterTracks[3][i]=-1;
134 //------------------------------------------------------------------------
135 void AliHLTITSLayer::ResetClusters() {
136 //--------------------------------------------------------------------
137 // This function removes loaded clusters
138 //--------------------------------------------------------------------
139 for (Int_t i=0; i<fN; i++) delete fClusters[i];
140 for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++){
142 fClusterTracks[0][i]=-1;
143 fClusterTracks[1][i]=-1;
144 fClusterTracks[2][i]=-1;
145 fClusterTracks[3][i]=-1;
151 //------------------------------------------------------------------------
152 void AliHLTITSLayer::ResetWeights() {
153 //--------------------------------------------------------------------
154 // This function reset weights of the clusters
155 //--------------------------------------------------------------------
156 for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++) {
158 fClusterTracks[0][i]=-1;
159 fClusterTracks[1][i]=-1;
160 fClusterTracks[2][i]=-1;
161 fClusterTracks[3][i]=-1;
163 for (Int_t i=0; i<fN;i++) {
164 AliITSRecPoint * cl = (AliITSRecPoint*)GetCluster(i);
165 if (cl&&cl->IsUsed()) cl->Use();
169 //------------------------------------------------------------------------
170 void AliHLTITSLayer::ResetRoad() {
171 //--------------------------------------------------------------------
172 // This function calculates the road defined by the cluster density
173 //--------------------------------------------------------------------
175 for (Int_t i=0; i<fN; i++) {
176 if (TMath::Abs(fClusters[i]->GetZ())<fR) n++;
178 if (n>1) fRoad=2*fR*TMath::Sqrt(TMath::Pi()/n);
180 //------------------------------------------------------------------------
181 Int_t AliHLTITSLayer::InsertCluster(AliITSRecPoint *cl) {
182 //--------------------------------------------------------------------
183 //This function adds a cluster to this layer
184 //--------------------------------------------------------------------
185 if (fN==AliITSRecoParam::GetMaxClusterPerLayer()) {
186 ::Error("InsertCluster","Too many clusters !\n");
192 AliHLTITSDetector &det=GetDetector(cl->GetDetectorIndex());
193 if (cl->GetY()<det.GetYmin()) det.SetYmin(cl->GetY());
194 if (cl->GetY()>det.GetYmax()) det.SetYmax(cl->GetY());
195 if (cl->GetZ()<det.GetZmin()) det.SetZmin(cl->GetZ());
196 if (cl->GetZ()>det.GetZmax()) det.SetZmax(cl->GetZ());
200 //------------------------------------------------------------------------
201 void AliHLTITSLayer::SortClusters()
206 AliITSRecPoint **clusters = new AliITSRecPoint*[fN];
207 Float_t *z = new Float_t[fN];
208 Int_t * index = new Int_t[fN];
210 for (Int_t i=0;i<fN;i++){
211 z[i] = fClusters[i]->GetZ();
213 TMath::Sort(fN,z,index,kFALSE);
214 for (Int_t i=0;i<fN;i++){
215 clusters[i] = fClusters[index[i]];
218 for (Int_t i=0;i<fN;i++){
219 fClusters[i] = clusters[i];
220 fZ[i] = fClusters[i]->GetZ();
221 AliHLTITSDetector &det=GetDetector(fClusters[i]->GetDetectorIndex());
222 Double_t y=fR*det.GetPhi() + fClusters[i]->GetY();
223 if (y>2.*fR*TMath::Pi()) y -= 2.*fR*TMath::Pi();
233 for (Int_t i=0;i<fN;i++){
234 if (fY[i]<fYB[0]) fYB[0]=fY[i];
235 if (fY[i]>fYB[1]) fYB[1]=fY[i];
236 fClusterIndex[i] = i;
240 fDy5 = (fYB[1]-fYB[0])/5.;
241 fDy10 = (fYB[1]-fYB[0])/10.;
242 fDy20 = (fYB[1]-fYB[0])/20.;
243 for (Int_t i=0;i<6;i++) fN5[i] =0;
244 for (Int_t i=0;i<11;i++) fN10[i]=0;
245 for (Int_t i=0;i<21;i++) fN20[i]=0;
247 for (Int_t i=0;i<6;i++) {fBy5[i][0] = fYB[0]+(i-0.75)*fDy5; fBy5[i][1] = fYB[0]+(i+0.75)*fDy5;}
248 for (Int_t i=0;i<11;i++) {fBy10[i][0] = fYB[0]+(i-0.75)*fDy10; fBy10[i][1] = fYB[0]+(i+0.75)*fDy10;}
249 for (Int_t i=0;i<21;i++) {fBy20[i][0] = fYB[0]+(i-0.75)*fDy20; fBy20[i][1] = fYB[0]+(i+0.75)*fDy20;}
252 for (Int_t i=0;i<fN;i++)
253 for (Int_t irot=-1;irot<=1;irot++){
254 Float_t curY = fY[i]+irot*TMath::TwoPi()*fR;
256 for (Int_t slice=0; slice<6;slice++){
257 if (fBy5[slice][0]<curY && curY<fBy5[slice][1]&&fN5[slice]<AliITSRecoParam::GetMaxClusterPerLayer5()){
258 fClusters5[slice][fN5[slice]] = fClusters[i];
259 fY5[slice][fN5[slice]] = curY;
260 fZ5[slice][fN5[slice]] = fZ[i];
261 fClusterIndex5[slice][fN5[slice]]=i;
266 for (Int_t slice=0; slice<11;slice++){
267 if (fBy10[slice][0]<curY && curY<fBy10[slice][1]&&fN10[slice]<AliITSRecoParam::GetMaxClusterPerLayer10()){
268 fClusters10[slice][fN10[slice]] = fClusters[i];
269 fY10[slice][fN10[slice]] = curY;
270 fZ10[slice][fN10[slice]] = fZ[i];
271 fClusterIndex10[slice][fN10[slice]]=i;
276 for (Int_t slice=0; slice<21;slice++){
277 if (fBy20[slice][0]<curY && curY<fBy20[slice][1]&&fN20[slice]<AliITSRecoParam::GetMaxClusterPerLayer20()){
278 fClusters20[slice][fN20[slice]] = fClusters[i];
279 fY20[slice][fN20[slice]] = curY;
280 fZ20[slice][fN20[slice]] = fZ[i];
281 fClusterIndex20[slice][fN20[slice]]=i;
290 for (Int_t i=0;i<fN-1;i++){
296 for (Int_t slice=0;slice<21;slice++)
297 for (Int_t i=0;i<fN20[slice]-1;i++){
298 if (fZ20[slice][i]>fZ20[slice][i+1]){
305 //------------------------------------------------------------------------
306 Int_t AliHLTITSLayer::FindClusterIndex(Float_t z) const {
307 //--------------------------------------------------------------------
308 // This function returns the index of the nearest cluster
309 //--------------------------------------------------------------------
312 if (fCurrentSlice<0) {
321 if (ncl==0) return 0;
322 Int_t b=0, e=ncl-1, m=(b+e)/2;
323 for (; b<e; m=(b+e)/2) {
324 // if (z > fClusters[m]->GetZ()) b=m+1;
325 if (z > zcl[m]) b=m+1;
331 //------------------------------------------------------------------------
332 void AliHLTITSLayer::
333 SelectClusters(Double_t zmin,Double_t zmax,Double_t ymin, Double_t ymax) {
334 //--------------------------------------------------------------------
335 // This function sets the "window"
336 //--------------------------------------------------------------------
338 Double_t circle=2*TMath::Pi()*fR;
339 fYmin = ymin; fYmax =ymax;
340 Float_t ymiddle = (fYmin+fYmax)*0.5;
341 if (ymiddle<fYB[0]) {
342 fYmin+=circle; fYmax+=circle; ymiddle+=circle;
343 } else if (ymiddle>fYB[1]) {
344 fYmin-=circle; fYmax-=circle; ymiddle-=circle;
350 fClustersCs = fClusters;
351 fClusterIndexCs = fClusterIndex;
357 if (fCurrentSlice<0&&TMath::Abs(fYmax-fYmin)<1.49*fDy20){
358 Int_t slice = int(0.5+(ymiddle-fYB[0])/fDy20);
359 if (slice<0) slice=0;
360 if (slice>20) slice=20;
361 Bool_t isOK = (fYmin>fBy20[slice][0]&&fYmax<fBy20[slice][1]);
364 fClustersCs = fClusters20[fCurrentSlice];
365 fClusterIndexCs = fClusterIndex20[fCurrentSlice];
366 fYcs = fY20[fCurrentSlice];
367 fZcs = fZ20[fCurrentSlice];
368 fNcs = fN20[fCurrentSlice];
373 if (fCurrentSlice<0&&TMath::Abs(fYmax-fYmin)<1.49*fDy10){
374 Int_t slice = int(0.5+(ymiddle-fYB[0])/fDy10);
375 if (slice<0) slice=0;
376 if (slice>10) slice=10;
377 Bool_t isOK = (fYmin>fBy10[slice][0]&&fYmax<fBy10[slice][1]);
380 fClustersCs = fClusters10[fCurrentSlice];
381 fClusterIndexCs = fClusterIndex10[fCurrentSlice];
382 fYcs = fY10[fCurrentSlice];
383 fZcs = fZ10[fCurrentSlice];
384 fNcs = fN10[fCurrentSlice];
389 if (fCurrentSlice<0&&TMath::Abs(fYmax-fYmin)<1.49*fDy5){
390 Int_t slice = int(0.5+(ymiddle-fYB[0])/fDy5);
391 if (slice<0) slice=0;
392 if (slice>5) slice=5;
393 Bool_t isOK = (fYmin>fBy5[slice][0]&&fYmax<fBy5[slice][1]);
396 fClustersCs = fClusters5[fCurrentSlice];
397 fClusterIndexCs = fClusterIndex5[fCurrentSlice];
398 fYcs = fY5[fCurrentSlice];
399 fZcs = fZ5[fCurrentSlice];
400 fNcs = fN5[fCurrentSlice];
404 fI=FindClusterIndex(zmin); fZmax=zmax;
405 fImax = TMath::Min(FindClusterIndex(zmax)+1,fNcs);
411 //------------------------------------------------------------------------
412 Int_t AliHLTITSLayer::
413 FindDetectorIndex(Double_t phi, Double_t z) const {
414 //--------------------------------------------------------------------
415 //This function finds the detector crossed by the track
416 //--------------------------------------------------------------------
418 if (fZOffset<0) // old geometry
419 dphi = -(phi-fPhiOffset);
421 dphi = phi-fPhiOffset;
424 if (dphi < 0) dphi += 2*TMath::Pi();
425 else if (dphi >= 2*TMath::Pi()) dphi -= 2*TMath::Pi();
426 Int_t np=Int_t(dphi*fNladders*0.5/TMath::Pi()+0.5);
427 if (np>=fNladders) np-=fNladders;
428 if (np<0) np+=fNladders;
431 Double_t dz=fZOffset-z;
432 Double_t nnz = dz*(fNdetectors-1)*0.5/fZOffset+0.5;
433 Int_t nz = (nnz<0 ? -1 : (Int_t)nnz);
434 if (nz>=fNdetectors) return -1;
437 // ad hoc correction for 3rd ladder of SDD inner layer,
438 // which is reversed (rotated by pi around local y)
439 // this correction is OK only from AliITSv11Hybrid onwards
440 if (GetR()>12. && GetR()<20.) { // SDD inner
441 if(np==2) { // 3rd ladder
442 nz = (fNdetectors-1) - nz;
445 //printf("ndet %d phi %f z %f np %d nz %d\n",fNdetectors,phi,z,np,nz);
448 return np*fNdetectors + nz;
450 //------------------------------------------------------------------------
451 const AliITSRecPoint *AliHLTITSLayer::GetNextCluster(Int_t &ci,Bool_t test)
453 //--------------------------------------------------------------------
454 // This function returns clusters within the "window"
455 //--------------------------------------------------------------------
457 if (fCurrentSlice<0) {
458 Double_t rpi2 = 2.*fR*TMath::Pi();
459 for (Int_t i=fI; i<fImax; i++) {
461 if (fYmax<y) y -= rpi2;
462 if (fYmin>y) y += rpi2;
463 if (y<fYmin) continue;
464 if (y>fYmax) continue;
465 if (fClusters[i]->GetQ()==0&&fSkip==2) continue;
471 for (Int_t i=fI; i<fImax; i++) {
472 if (fYcs[i]<fYmin) continue;
473 if (fYcs[i]>fYmax) continue;
474 if (fClustersCs[i]->GetQ()==0&&fSkip==2) continue;
475 ci=fClusterIndexCs[i];
477 return fClustersCs[i];
482 //------------------------------------------------------------------------
483 Double_t AliHLTITSLayer::GetThickness(Double_t y,Double_t z,Double_t &x0)
485 //--------------------------------------------------------------------
486 // This function returns the layer thickness at this point (units X0)
487 //--------------------------------------------------------------------
489 x0=AliITSRecoParam::GetX0Air();
490 if (43<fR&&fR<45) { //SSD2
493 if (TMath::Abs(y-0.00)>3.40) d+=dd;
494 if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
495 if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
496 for (Int_t i=0; i<12; i++) {
497 if (TMath::Abs(z-3.9*(i+0.5))<0.15) {
498 if (TMath::Abs(y-0.00)>3.40) d+=dd;
502 if (TMath::Abs(z+3.9*(i+0.5))<0.15) {
503 if (TMath::Abs(y-0.00)>3.40) d+=dd;
507 if (TMath::Abs(z-3.4-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
508 if (TMath::Abs(z+0.5+3.9*i)<0.50) {d+=(0.016-0.0034); break;}
511 if (37<fR&&fR<41) { //SSD1
514 if (TMath::Abs(y-0.00)>3.40) d+=dd;
515 if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
516 if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
517 for (Int_t i=0; i<11; i++) {
518 if (TMath::Abs(z-3.9*i)<0.15) {
519 if (TMath::Abs(y-0.00)>3.40) d+=dd;
523 if (TMath::Abs(z+3.9*i)<0.15) {
524 if (TMath::Abs(y-0.00)>3.40) d+=dd;
528 if (TMath::Abs(z-1.85-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
529 if (TMath::Abs(z+2.05+3.9*i)<0.50) {d+=(0.016-0.0034); break;}
532 if (13<fR&&fR<26) { //SDD
535 if (TMath::Abs(y-0.00)>3.30) d+=dd;
537 if (TMath::Abs(y-1.80)<0.55) {
539 for (Int_t j=0; j<20; j++) {
540 if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
541 if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
544 if (TMath::Abs(y+1.80)<0.55) {
546 for (Int_t j=0; j<20; j++) {
547 if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
548 if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
552 for (Int_t i=0; i<4; i++) {
553 if (TMath::Abs(z-7.3*i)<0.60) {
555 if (TMath::Abs(y-0.00)>3.30) d+=dd;
558 if (TMath::Abs(z+7.3*i)<0.60) {
560 if (TMath::Abs(y-0.00)>3.30) d+=dd;
565 if (6<fR&&fR<8) { //SPD2
566 Double_t dd=0.0063; x0=21.5;
568 if (TMath::Abs(y-3.08)>0.5) d+=dd;
569 if (TMath::Abs(y-3.03)<0.10) d+=0.014;
571 if (3<fR&&fR<5) { //SPD1
572 Double_t dd=0.0063; x0=21.5;
574 if (TMath::Abs(y+0.21)>0.6) d+=dd;
575 if (TMath::Abs(y+0.10)<0.10) d+=0.014;
581 //------------------------------------------------------------------------
582 Int_t AliHLTITSLayer::InRoad() const {
583 //-------------------------------------------------------------------
584 // This function returns number of clusters within the "window"
585 //--------------------------------------------------------------------
587 for (Int_t i=fI; i<fN; i++) {
588 const AliITSRecPoint *c=fClusters[i];
589 if (c->GetZ() > fZmax) break;
590 if (c->IsUsed()) continue;
591 const AliHLTITSDetector &det=GetDetector(c->GetDetectorIndex());
592 Double_t y=fR*det.GetPhi() + c->GetY();
594 if (y>2.*fR*TMath::Pi()) y -= 2*fR*TMath::Pi();
595 if (y>1.*fR*TMath::Pi() && fYmax<y) y -= 2*fR*TMath::Pi();
597 if (y<fYmin) continue;
598 if (y>fYmax) continue;