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"
23 //------------------------------------------------------------------------
24 AliHLTITSLayer::AliHLTITSLayer():
49 //--------------------------------------------------------------------
50 //default AliHLTITSLayer constructor
51 //--------------------------------------------------------------------
52 for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++) {
54 fClusterTracks[0][i]=-1;
55 fClusterTracks[1][i]=-1;
56 fClusterTracks[2][i]=-1;
57 fClusterTracks[3][i]=-1;
60 //------------------------------------------------------------------------
62 AliHLTITSLayer(Double_t r,Double_t p,Double_t z,Int_t nl,Int_t nd):
87 //--------------------------------------------------------------------
88 //main AliHLTITSLayer constructor
89 //--------------------------------------------------------------------
90 fDetectors=new AliHLTITSDetector[fNladders*fNdetectors];
91 fRoad=2*fR*TMath::Sqrt(TMath::Pi()/1.);//assuming that there's only one cluster
93 //------------------------------------------------------------------------
94 AliHLTITSLayer::AliHLTITSLayer(const AliHLTITSLayer& layer):
96 fPhiOffset(layer.fPhiOffset),
97 fNladders(layer.fNladders),
98 fZOffset(layer.fZOffset),
99 fNdetectors(layer.fNdetectors),
100 fDetectors(layer.fDetectors),
105 fClustersCs(layer.fClustersCs),
106 fClusterIndexCs(layer.fClusterIndexCs),
110 fCurrentSlice(layer.fCurrentSlice),
117 fAccepted(layer.fAccepted),
121 //------------------------------------------------------------------------
122 AliHLTITSLayer::~AliHLTITSLayer() {
123 //--------------------------------------------------------------------
124 // AliHLTITSLayer destructor
125 //--------------------------------------------------------------------
126 delete [] fDetectors;
127 for (Int_t i=0; i<fN; i++) delete fClusters[i];
128 for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++) {
130 fClusterTracks[0][i]=-1;
131 fClusterTracks[1][i]=-1;
132 fClusterTracks[2][i]=-1;
133 fClusterTracks[3][i]=-1;
136 //------------------------------------------------------------------------
137 void AliHLTITSLayer::ResetClusters() {
138 //--------------------------------------------------------------------
139 // This function removes loaded clusters
140 //--------------------------------------------------------------------
141 for (Int_t i=0; i<fN; i++) delete fClusters[i];
142 for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++){
144 fClusterTracks[0][i]=-1;
145 fClusterTracks[1][i]=-1;
146 fClusterTracks[2][i]=-1;
147 fClusterTracks[3][i]=-1;
153 //------------------------------------------------------------------------
154 void AliHLTITSLayer::ResetWeights() {
155 //--------------------------------------------------------------------
156 // This function reset weights of the clusters
157 //--------------------------------------------------------------------
158 for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++) {
160 fClusterTracks[0][i]=-1;
161 fClusterTracks[1][i]=-1;
162 fClusterTracks[2][i]=-1;
163 fClusterTracks[3][i]=-1;
165 for (Int_t i=0; i<fN;i++) {
166 AliITSRecPoint * cl = (AliITSRecPoint*)GetCluster(i);
167 if (cl&&cl->IsUsed()) cl->Use();
171 //------------------------------------------------------------------------
172 void AliHLTITSLayer::ResetRoad() {
173 //--------------------------------------------------------------------
174 // This function calculates the road defined by the cluster density
175 //--------------------------------------------------------------------
177 for (Int_t i=0; i<fN; i++) {
178 if (TMath::Abs(fClusters[i]->GetZ())<fR) n++;
180 if (n>1) fRoad=2*fR*TMath::Sqrt(TMath::Pi()/n);
182 //------------------------------------------------------------------------
183 Int_t AliHLTITSLayer::InsertCluster(AliITSRecPoint *cl) {
184 //--------------------------------------------------------------------
185 //This function adds a cluster to this layer
186 //--------------------------------------------------------------------
187 if (fN==AliITSRecoParam::GetMaxClusterPerLayer()) {
188 ::Error("InsertCluster","Too many clusters !\n");
194 AliHLTITSDetector &det=GetDetector(cl->GetDetectorIndex());
195 if (cl->GetY()<det.GetYmin()) det.SetYmin(cl->GetY());
196 if (cl->GetY()>det.GetYmax()) det.SetYmax(cl->GetY());
197 if (cl->GetZ()<det.GetZmin()) det.SetZmin(cl->GetZ());
198 if (cl->GetZ()>det.GetZmax()) det.SetZmax(cl->GetZ());
204 //------------------------------------------------------------------------
205 void AliHLTITSLayer::SortClusters()
211 AliITSRecPoint **clusters = new AliITSRecPoint*[fN];
212 Float_t *z = new Float_t[fN];
213 Int_t * index = new Int_t[fN];
215 for (Int_t i=0;i<fN;i++){
216 z[i] = fClusters[i]->GetZ();
218 TMath::Sort(fN,z,index,kFALSE);
220 for (Int_t i=0;i<fN;i++){
221 clusters[i] = fClusters[index[i]];
224 for (Int_t i=0;i<fN;i++){
225 fClusters[i] = clusters[i];
226 fZ[i] = fClusters[i]->GetZ();
227 AliHLTITSDetector &det=GetDetector(fClusters[i]->GetDetectorIndex());
228 Double_t y=fR*det.GetPhi() + fClusters[i]->GetY();
229 if (y>2.*fR*TMath::Pi()) y -= 2.*fR*TMath::Pi();
239 for (Int_t i=0;i<fN;i++){
240 if (fY[i]<fYB[0]) fYB[0]=fY[i];
241 if (fY[i]>fYB[1]) fYB[1]=fY[i];
242 fClusterIndex[i] = i;
246 fDy5 = (fYB[1]-fYB[0])/5.;
247 fDy10 = (fYB[1]-fYB[0])/10.;
248 fDy20 = (fYB[1]-fYB[0])/20.;
249 for (Int_t i=0;i<6;i++) fN5[i] =0;
250 for (Int_t i=0;i<11;i++) fN10[i]=0;
251 for (Int_t i=0;i<21;i++) fN20[i]=0;
253 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;}
254 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;}
255 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;}
258 for (Int_t i=0;i<fN;i++)
259 for (Int_t irot=-1;irot<=1;irot++){
260 Float_t curY = fY[i]+irot*TMath::TwoPi()*fR;
262 for (Int_t slice=0; slice<6;slice++){
263 if (fBy5[slice][0]<curY && curY<fBy5[slice][1]&&fN5[slice]<AliITSRecoParam::GetMaxClusterPerLayer5()){
264 fClusters5[slice][fN5[slice]] = fClusters[i];
265 fY5[slice][fN5[slice]] = curY;
266 fZ5[slice][fN5[slice]] = fZ[i];
267 fClusterIndex5[slice][fN5[slice]]=i;
272 for (Int_t slice=0; slice<11;slice++){
273 if (fBy10[slice][0]<curY && curY<fBy10[slice][1]&&fN10[slice]<AliITSRecoParam::GetMaxClusterPerLayer10()){
274 fClusters10[slice][fN10[slice]] = fClusters[i];
275 fY10[slice][fN10[slice]] = curY;
276 fZ10[slice][fN10[slice]] = fZ[i];
277 fClusterIndex10[slice][fN10[slice]]=i;
282 for (Int_t slice=0; slice<21;slice++){
283 if (fBy20[slice][0]<curY && curY<fBy20[slice][1]&&fN20[slice]<AliITSRecoParam::GetMaxClusterPerLayer20()){
284 fClusters20[slice][fN20[slice]] = fClusters[i];
285 fY20[slice][fN20[slice]] = curY;
286 fZ20[slice][fN20[slice]] = fZ[i];
287 fClusterIndex20[slice][fN20[slice]]=i;
296 for (Int_t i=0;i<fN-1;i++){
302 for (Int_t slice=0;slice<21;slice++)
303 for (Int_t i=0;i<fN20[slice]-1;i++){
304 if (fZ20[slice][i]>fZ20[slice][i+1]){
311 //------------------------------------------------------------------------
312 Int_t AliHLTITSLayer::FindClusterIndex(Float_t z) const {
313 //--------------------------------------------------------------------
314 // This function returns the index of the nearest cluster
315 //--------------------------------------------------------------------
318 if (fCurrentSlice<0) {
327 if (ncl==0) return 0;
328 Int_t b=0, e=ncl-1, m=(b+e)/2;
329 for (; b<e; m=(b+e)/2) {
330 // if (z > fClusters[m]->GetZ()) b=m+1;
331 if (z > zcl[m]) b=m+1;
337 //------------------------------------------------------------------------
338 void AliHLTITSLayer::
339 SelectClusters(Double_t zmin,Double_t zmax,Double_t ymin, Double_t ymax) {
340 //--------------------------------------------------------------------
341 // This function sets the "window"
342 //--------------------------------------------------------------------
344 Double_t circle=2*TMath::Pi()*fR;
345 fYmin = ymin; fYmax =ymax;
346 Float_t ymiddle = (fYmin+fYmax)*0.5;
347 if (ymiddle<fYB[0]) {
348 fYmin+=circle; fYmax+=circle; ymiddle+=circle;
349 } else if (ymiddle>fYB[1]) {
350 fYmin-=circle; fYmax-=circle; ymiddle-=circle;
356 fClustersCs = fClusters;
357 fClusterIndexCs = fClusterIndex;
363 if (fCurrentSlice<0&&TMath::Abs(fYmax-fYmin)<1.49*fDy20){
364 Int_t slice = int(0.5+(ymiddle-fYB[0])/fDy20);
365 if (slice<0) slice=0;
366 if (slice>20) slice=20;
367 Bool_t isOK = (fYmin>fBy20[slice][0]&&fYmax<fBy20[slice][1]);
370 fClustersCs = fClusters20[fCurrentSlice];
371 fClusterIndexCs = fClusterIndex20[fCurrentSlice];
372 fYcs = fY20[fCurrentSlice];
373 fZcs = fZ20[fCurrentSlice];
374 fNcs = fN20[fCurrentSlice];
379 if (fCurrentSlice<0&&TMath::Abs(fYmax-fYmin)<1.49*fDy10){
380 Int_t slice = int(0.5+(ymiddle-fYB[0])/fDy10);
381 if (slice<0) slice=0;
382 if (slice>10) slice=10;
383 Bool_t isOK = (fYmin>fBy10[slice][0]&&fYmax<fBy10[slice][1]);
386 fClustersCs = fClusters10[fCurrentSlice];
387 fClusterIndexCs = fClusterIndex10[fCurrentSlice];
388 fYcs = fY10[fCurrentSlice];
389 fZcs = fZ10[fCurrentSlice];
390 fNcs = fN10[fCurrentSlice];
395 if (fCurrentSlice<0&&TMath::Abs(fYmax-fYmin)<1.49*fDy5){
396 Int_t slice = int(0.5+(ymiddle-fYB[0])/fDy5);
397 if (slice<0) slice=0;
398 if (slice>5) slice=5;
399 Bool_t isOK = (fYmin>fBy5[slice][0]&&fYmax<fBy5[slice][1]);
402 fClustersCs = fClusters5[fCurrentSlice];
403 fClusterIndexCs = fClusterIndex5[fCurrentSlice];
404 fYcs = fY5[fCurrentSlice];
405 fZcs = fZ5[fCurrentSlice];
406 fNcs = fN5[fCurrentSlice];
410 fI=FindClusterIndex(zmin); fZmax=zmax;
411 fImax = TMath::Min(FindClusterIndex(zmax)+1,fNcs);
417 //------------------------------------------------------------------------
418 Int_t AliHLTITSLayer::
419 FindDetectorIndex(Double_t phi, Double_t z) const {
420 //--------------------------------------------------------------------
421 //This function finds the detector crossed by the track
422 //--------------------------------------------------------------------
424 if (fZOffset<0) // old geometry
425 dphi = -(phi-fPhiOffset);
427 dphi = phi-fPhiOffset;
430 if (dphi < 0) dphi += 2*TMath::Pi();
431 else if (dphi >= 2*TMath::Pi()) dphi -= 2*TMath::Pi();
432 Int_t np=Int_t(dphi*fNladders*0.5/TMath::Pi()+0.5);
433 if (np>=fNladders) np-=fNladders;
434 if (np<0) np+=fNladders;
437 Double_t dz=fZOffset-z;
438 Double_t nnz = dz*(fNdetectors-1)*0.5/fZOffset+0.5;
439 Int_t nz = (nnz<0 ? -1 : (Int_t)nnz);
440 if (nz>=fNdetectors) return -1;
443 // ad hoc correction for 3rd ladder of SDD inner layer,
444 // which is reversed (rotated by pi around local y)
445 // this correction is OK only from AliITSv11Hybrid onwards
446 if (GetR()>12. && GetR()<20.) { // SDD inner
447 if(np==2) { // 3rd ladder
448 nz = (fNdetectors-1) - nz;
451 //printf("ndet %d phi %f z %f np %d nz %d\n",fNdetectors,phi,z,np,nz);
454 return np*fNdetectors + nz;
456 //------------------------------------------------------------------------
457 const AliITSRecPoint *AliHLTITSLayer::GetNextCluster(Int_t &ci,Bool_t test)
459 //--------------------------------------------------------------------
460 // This function returns clusters within the "window"
461 //--------------------------------------------------------------------
463 if (fCurrentSlice<0) {
464 Double_t rpi2 = 2.*fR*TMath::Pi();
465 for (Int_t i=fI; i<fImax; i++) {
467 if (fYmax<y) y -= rpi2;
468 if (fYmin>y) y += rpi2;
469 if (y<fYmin) continue;
470 if (y>fYmax) continue;
471 if (fClusters[i]->GetQ()==0&&fSkip==2) continue;
477 for (Int_t i=fI; i<fImax; i++) {
478 if (fYcs[i]<fYmin) continue;
479 if (fYcs[i]>fYmax) continue;
480 if (fClustersCs[i]->GetQ()==0&&fSkip==2) continue;
481 ci=fClusterIndexCs[i];
483 return fClustersCs[i];
488 //------------------------------------------------------------------------
489 Double_t AliHLTITSLayer::GetThickness(Double_t y,Double_t z,Double_t &x0)
491 //--------------------------------------------------------------------
492 // This function returns the layer thickness at this point (units X0)
493 //--------------------------------------------------------------------
495 x0=AliITSRecoParam::GetX0Air();
496 if (43<fR&&fR<45) { //SSD2
499 if (TMath::Abs(y-0.00)>3.40) d+=dd;
500 if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
501 if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
502 for (Int_t i=0; i<12; i++) {
503 if (TMath::Abs(z-3.9*(i+0.5))<0.15) {
504 if (TMath::Abs(y-0.00)>3.40) d+=dd;
508 if (TMath::Abs(z+3.9*(i+0.5))<0.15) {
509 if (TMath::Abs(y-0.00)>3.40) d+=dd;
513 if (TMath::Abs(z-3.4-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
514 if (TMath::Abs(z+0.5+3.9*i)<0.50) {d+=(0.016-0.0034); break;}
517 if (37<fR&&fR<41) { //SSD1
520 if (TMath::Abs(y-0.00)>3.40) d+=dd;
521 if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
522 if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
523 for (Int_t i=0; i<11; i++) {
524 if (TMath::Abs(z-3.9*i)<0.15) {
525 if (TMath::Abs(y-0.00)>3.40) d+=dd;
529 if (TMath::Abs(z+3.9*i)<0.15) {
530 if (TMath::Abs(y-0.00)>3.40) d+=dd;
534 if (TMath::Abs(z-1.85-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
535 if (TMath::Abs(z+2.05+3.9*i)<0.50) {d+=(0.016-0.0034); break;}
538 if (13<fR&&fR<26) { //SDD
541 if (TMath::Abs(y-0.00)>3.30) d+=dd;
543 if (TMath::Abs(y-1.80)<0.55) {
545 for (Int_t j=0; j<20; j++) {
546 if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
547 if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
550 if (TMath::Abs(y+1.80)<0.55) {
552 for (Int_t j=0; j<20; j++) {
553 if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
554 if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
558 for (Int_t i=0; i<4; i++) {
559 if (TMath::Abs(z-7.3*i)<0.60) {
561 if (TMath::Abs(y-0.00)>3.30) d+=dd;
564 if (TMath::Abs(z+7.3*i)<0.60) {
566 if (TMath::Abs(y-0.00)>3.30) d+=dd;
571 if (6<fR&&fR<8) { //SPD2
572 Double_t dd=0.0063; x0=21.5;
574 if (TMath::Abs(y-3.08)>0.5) d+=dd;
575 if (TMath::Abs(y-3.03)<0.10) d+=0.014;
577 if (3<fR&&fR<5) { //SPD1
578 Double_t dd=0.0063; x0=21.5;
580 if (TMath::Abs(y+0.21)>0.6) d+=dd;
581 if (TMath::Abs(y+0.10)<0.10) d+=0.014;
587 //------------------------------------------------------------------------
588 Int_t AliHLTITSLayer::InRoad() const {
589 //-------------------------------------------------------------------
590 // This function returns number of clusters within the "window"
591 //--------------------------------------------------------------------
593 for (Int_t i=fI; i<fN; i++) {
594 const AliITSRecPoint *c=fClusters[i];
595 if (c->GetZ() > fZmax) break;
596 if (c->IsUsed()) continue;
597 const AliHLTITSDetector &det=GetDetector(c->GetDetectorIndex());
598 Double_t y=fR*det.GetPhi() + c->GetY();
600 if (y>2.*fR*TMath::Pi()) y -= 2*fR*TMath::Pi();
601 if (y>1.*fR*TMath::Pi() && fYmax<y) y -= 2*fR*TMath::Pi();
603 if (y<fYmin) continue;
604 if (y>fYmax) continue;