1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 // **************************************************************************
17 // * The package was revised and changed by Boris Batiounia in the time *
18 // * period of March - June 2001 *
19 // **************************************************************************/
21 #include <Riostream.h>
25 #include "AliITSdigitSSD.h"
26 #include "AliITSRawClusterSSD.h"
27 #include "AliITSRecPoint.h"
28 #include "AliITSMapA1.h"
29 #include "AliITSClusterFinderSSD.h"
30 #include "AliITSclusterSSD.h"
31 #include "AliITSpackageSSD.h"
32 #include "AliITSsegmentation.h"
33 #include "AliITSgeom.h"
35 const Bool_t AliITSClusterFinderSSD::fgkSIDEP=kTRUE;
36 const Bool_t AliITSClusterFinderSSD::fgkSIDEN=kFALSE;
39 ClassImp(AliITSClusterFinderSSD)
41 //____________________________________________________________________
44 //______________________________________________________________________
45 AliITSClusterFinderSSD::AliITSClusterFinderSSD(){
51 fITS = (AliITS*)gAlice->GetModule("ITS");
65 //______________________________________________________________________}
66 AliITSClusterFinderSSD::AliITSClusterFinderSSD(AliITSsegmentation *seg,
67 TClonesArray *digits){
68 //Standard constructor
72 fMap = new AliITSMapA1(fSegmentation,fDigits);
73 fITS = (AliITS*)gAlice->GetModule("ITS");
74 fClusterP = new TClonesArray ("AliITSclusterSSD",200);
76 fClusterN = new TClonesArray ("AliITSclusterSSD",200);
78 fPackages = new TClonesArray ("AliITSpackageSSD",200); //packages
80 fDigitsIndexP = new TArrayI(300);
82 fDigitsIndexN = new TArrayI(300);
84 fPitch = fSegmentation->Dpx(0);
85 fPNsignalRatio= 7./8.; // warning: hard-wired number
87 //______________________________________________________________________
88 AliITSClusterFinderSSD::~AliITSClusterFinderSSD(){
98 //______________________________________________________________________
99 void AliITSClusterFinderSSD::InitReconstruction(){
100 // initialization of the cluster finder
102 register Int_t i; //iterator
104 for (i=0;i<fNClusterP;i++) fClusterP->RemoveAt(i);
106 for (i=0;i<fNClusterN;i++) fClusterN->RemoveAt(i);
108 for (i=0;i<fNPackages;i++) fPackages->RemoveAt(i);
112 Float_t stereoP,stereoN;
113 fSegmentation->Angles(stereoP,stereoN);
114 CalcStepFactor(stereoP,stereoN);
115 if (debug) cout<<"fSFF = "<<fSFF<<" fSFB = "<<fSFB<<"\n";
117 //______________________________________________________________________
118 void AliITSClusterFinderSSD::FindRawClusters(Int_t module){
119 // This function findes out all clusters belonging to one module
120 // 1. Zeroes all space after previous module reconstruction
121 // 2. Finds all neighbouring digits, create clusters
122 // 3. If necesery, resolves for each group of neighbouring digits
123 // how many clusters creates it.
124 // 4. Colculate the x and z coordinate
125 Int_t lay, lad, detect;
126 AliITSgeom *geom = fITS->GetITSgeom();
128 geom->GetModuleId(module,lay, lad, detect);
129 if ( lay == 6 ) ((AliITSsegmentationSSD*)fSegmentation)->SetLayer(6);
130 if ( lay == 5 ) ((AliITSsegmentationSSD*)fSegmentation)->SetLayer(5);
132 InitReconstruction(); //ad. 1
136 FindNeighbouringDigits(); //ad. 2
137 //SeparateOverlappedClusters(); //ad. 3
138 ClustersToPackages(); //ad. 4
141 //______________________________________________________________________
142 void AliITSClusterFinderSSD::FindNeighbouringDigits(){
143 //If there are any digits on this side, create 1st Cluster,
144 // add to it this digit, and increment number of clusters
147 if ((fNDigitsP>0 ) && (fNDigitsN > 0 )) {
148 Int_t currentstripNo;
149 Int_t *dbuffer = new Int_t [300]; //buffer for strip numbers
150 Int_t dnumber; //curent number of digits in buffer
151 TArrayI &lDigitsIndexP = *fDigitsIndexP;
152 TArrayI &lDigitsIndexN = *fDigitsIndexN;
153 TObjArray &lDigits = *(Digits());
154 TClonesArray &lClusterP = *fClusterP;
155 TClonesArray &lClusterN = *fClusterN;
158 dbuffer[0]=lDigitsIndexP[0];
159 //If next digit is a neigh. of previous, adds to last clust. this digit
160 for (i=1; i<fNDigitsP; i++) {
162 currentstripNo = ((AliITSdigitSSD*)lDigits[lDigitsIndexP[i]])->
164 //check if it is a neighbour of a previous one
165 if((((AliITSdigitSSD*)lDigits[lDigitsIndexP[i-1]])->
167 == (currentstripNo-1) ) dbuffer[dnumber++]=lDigitsIndexP[i];
169 //create a new one side cluster
170 new(lClusterP[fNClusterP++]) AliITSclusterSSD(dnumber,dbuffer,
173 dbuffer[0]=lDigitsIndexP[i];
176 } // end loop over fNDigitsP
177 new(lClusterP[fNClusterP++]) AliITSclusterSSD(dnumber,dbuffer,
180 //for comments, see above
182 dbuffer[0]=lDigitsIndexN[0];
183 //If next digit is a neigh. of previous, adds to last clust. this digit
184 for (i=1; i<fNDigitsN; i++) {
185 currentstripNo = ((AliITSdigitSSD*)(lDigits[lDigitsIndexN[i]]))->
187 if ( (((AliITSdigitSSD*)lDigits[lDigitsIndexN[i-1]])->
189 == (currentstripNo-1) ) dbuffer[dnumber++]=lDigitsIndexN[i];
191 new(lClusterN[fNClusterN++]) AliITSclusterSSD(dnumber,dbuffer,
194 dbuffer[0]=lDigitsIndexN[i];
197 } // end loop over fNDigitsN
198 new(lClusterN[fNClusterN++]) AliITSclusterSSD(dnumber,dbuffer,
202 } // end condition on NDigits
204 if (debug) cout<<"\n Found clusters: fNClusterP = "<<fNClusterP
205 <<" fNClusterN ="<<fNClusterN<<"\n";
207 //______________________________________________________________________
208 void AliITSClusterFinderSSD::SeparateOverlappedClusters(){
209 // overlapped clusters separation
210 register Int_t i; //iterator
211 Float_t factor=0.75; // How many percent must be lower signal
212 // on the middle one digit
213 // from its neighbours
214 Int_t signal0; //signal on the strip before the current one
215 Int_t signal1; //signal on the current one signal
216 Int_t signal2; //signal on the strip after the current one
217 TArrayI *splitlist; // List of splits
218 Int_t numerofsplits=0; // number of splits
219 Int_t initPsize = fNClusterP; //initial size of the arrays
220 Int_t initNsize = fNClusterN; //we have to keep it because it will grow
221 // in this function and it doasn't make
222 // sense to pass through it again
223 splitlist = new TArrayI(300);
225 for (i=0;i<initPsize;i++){
226 if (( ((AliITSclusterSSD*)(*fClusterP)[i])->
227 GetNumOfDigits())==1) continue;
228 if (( ((AliITSclusterSSD*)(*fClusterP)[i])->
229 GetNumOfDigits())==2) continue;
230 Int_t nj=(((AliITSclusterSSD*)(*fClusterP)[i])->GetNumOfDigits()-1);
231 for (Int_t j=1; j<nj; j++){
232 signal1=((AliITSclusterSSD*)(*fClusterP)[i])->GetDigitSignal(j);
233 signal0=((AliITSclusterSSD*)(*fClusterP)[i])->GetDigitSignal(j-1);
234 signal2=((AliITSclusterSSD*)(*fClusterP)[i])->GetDigitSignal(j+1);
235 //if signal is less then factor*signal of its neighbours
236 if ( (signal1<(factor*signal0)) && (signal1<(factor*signal2)) ){
237 (*splitlist)[numerofsplits++]=j;
239 } // end loop over number of digits
240 //split this cluster if necessary
241 if(numerofsplits>0) SplitCluster(splitlist,numerofsplits,i,fgkSIDEP);
243 //in signed places (splitlist)
244 } // end loop over clusters on Pside
246 for (i=0;i<initNsize;i++) {
247 if (( ((AliITSclusterSSD*)(*fClusterN)[i])->
248 GetNumOfDigits())==1) continue;
249 if (( ((AliITSclusterSSD*)(*fClusterN)[i])->
250 GetNumOfDigits())==2) continue;
251 Int_t nj=(((AliITSclusterSSD*)(*fClusterN)[i])->GetNumOfDigits()-1);
252 for (Int_t j=1; j<nj; j++){
253 signal1=((AliITSclusterSSD*)(*fClusterN)[i])->GetDigitSignal(j);
254 signal0=((AliITSclusterSSD*)(*fClusterN)[i])->GetDigitSignal(j-1);
255 signal2=((AliITSclusterSSD*)(*fClusterN)[i])->GetDigitSignal(j+1);
256 //if signal is less then factor*signal of its neighbours
257 if ( (signal1<(factor*signal0)) && (signal1<(factor*signal2)) )
258 (*splitlist)[numerofsplits++]=j;
259 } // end loop over number of digits
260 //split this cluster into more clusters
261 if(numerofsplits>0) SplitCluster(splitlist,numerofsplits,i,fgkSIDEN);
263 //in signed places (splitlist)
264 } // end loop over clusters on Nside
268 //______________________________________________________________________
269 void AliITSClusterFinderSSD::SplitCluster(TArrayI *list, Int_t nsplits,
270 Int_t index, Bool_t side){
271 //This function splits one side cluster into more clusters
272 //number of splits is defined by "nsplits"
273 //Place of splits are defined in the TArray "list"
274 // For further optimisation: Replace this function by two
275 // specialised ones (each for one side)
277 //For comlete comments see AliITSclusterSSD::SplitCluster
278 register Int_t i; //iterator
279 AliITSclusterSSD* curentcluster;
280 Int_t *tmpdigits = new Int_t[100];
283 // side true means P side
285 curentcluster =((AliITSclusterSSD*)((*fClusterP)[index])) ;
286 for (i = nsplits; i>0 ;i--) {
287 nn=curentcluster->SplitCluster((*list)[(i-1)],tmpdigits);
288 new ((*fClusterP)[fNClusterP]) AliITSclusterSSD(nn,tmpdigits,
290 ( (AliITSclusterSSD*)((*fClusterP)[fNClusterP]) )->
291 SetLeftNeighbour(kTRUE);
292 //if left cluster had neighbour on the right before split
293 //new should have it too
294 if ( curentcluster->GetRightNeighbour() )
295 ( (AliITSclusterSSD*)((*fClusterP)[fNClusterP]) )->
296 SetRightNeighbour(kTRUE);
297 else curentcluster->SetRightNeighbour(kTRUE);
299 } // end loop over nplits
301 curentcluster =((AliITSclusterSSD*)((*fClusterN)[index]));
302 for (i = nsplits; i>0 ;i--) {
303 nn=curentcluster->SplitCluster((*list)[(i-1)],tmpdigits);
304 new ((*fClusterN)[fNClusterN]) AliITSclusterSSD(nn,tmpdigits,
306 ((AliITSclusterSSD*)((*fClusterN)[fNClusterN]))->
307 SetRightNeighbour(kTRUE);
308 if (curentcluster->GetRightNeighbour())
309 ( (AliITSclusterSSD*)( (*fClusterN)[fNClusterN]) )->
310 SetRightNeighbour(kTRUE);
311 else curentcluster->SetRightNeighbour(kTRUE);
313 } // end loop over nplits
317 //______________________________________________________________________
318 Int_t AliITSClusterFinderSSD::SortDigitsP(Int_t start, Int_t end){
319 // sort digits on the P side
323 if (start != (end - 1) ){
324 left=this->SortDigitsP(start,(start+end)/2);
325 right=this->SortDigitsP((start+end)/2,end);
326 return (left || right);
328 left = ((AliITSdigitSSD*)((*(Digits()))[(*fDigitsIndexP)[start]]))->
330 right= ((AliITSdigitSSD*)((*(Digits()))[(*fDigitsIndexP)[end]]))->
333 Int_t tmp = (*fDigitsIndexP)[start];
334 (*fDigitsIndexP)[start]=(*fDigitsIndexP)[end];
335 (*fDigitsIndexP)[end]=tmp;
340 //______________________________________________________________________
341 Int_t AliITSClusterFinderSSD::SortDigitsN(Int_t start, Int_t end){
342 // sort digits on the N side
346 if (start != (end - 1)){
347 left=this->SortDigitsN(start,(start+end)/2);
348 right=this->SortDigitsN((start+end)/2,end);
349 return (left || right);
351 left =((AliITSdigitSSD*)((*(Digits()))[(*fDigitsIndexN)[start]]))->
353 right=((AliITSdigitSSD*)((*(Digits()))[(*fDigitsIndexN)[end]]))->
356 Int_t tmp = (*fDigitsIndexN)[start];
357 (*fDigitsIndexN)[start]=(*fDigitsIndexN)[end];
358 (*fDigitsIndexN)[end]=tmp;
363 //______________________________________________________________________
364 void AliITSClusterFinderSSD::FillDigitsIndex(){
365 //Fill the indexes of the clusters belonging to a given ITS module
371 noentries = fDigits->GetEntriesFast();
373 Int_t* psidx = new Int_t [noentries*sizeof(Int_t)];
374 Int_t* nsidx = new Int_t [noentries*sizeof(Int_t)];
375 if (fDigitsIndexP==NULL) fDigitsIndexP = new TArrayI(noentries);
376 if (fDigitsIndexN==NULL) fDigitsIndexN = new TArrayI(noentries);
380 for ( i = 0 ; i< noentries; i++ ) {
381 dig = (AliITSdigitSSD*)GetDigit(i);
384 tmp=dig->GetStripNumber();
385 // I find this totally unnecessary - it's just a
386 // CPU consuming double check
389 if (debug) cout<<"Such a digit exists \n";
395 fDigitsIndexP->AddAt(i,fNDigitsP++);
400 tmp=dig->GetStripNumber();
404 if (debug) cout<<"Such a digit exists \n";
410 fDigitsIndexN->AddAt(i,fNDigitsN++);
419 if (debug) cout<<"Digits : P = "<<fNDigitsP<<" N = "<<fNDigitsN<<endl;
421 //______________________________________________________________________
422 void AliITSClusterFinderSSD::SortDigits(){
426 if(fNDigitsP>1) for (i=0;i<fNDigitsP-1;i++)
427 if (SortDigitsP(0,(fNDigitsP-1-i))==0) break;
428 if(fNDigitsN>1) for (i=0;i<fNDigitsN-1;i++)
429 if(SortDigitsN(0,(fNDigitsN-1-i))==0) break;
431 //______________________________________________________________________
432 void AliITSClusterFinderSSD::FillClIndexArrays(Int_t* arrayP, Int_t *arrayN) const{
433 // fill cluster index array
436 for (i=0; i<fNClusterP;i++) arrayP[i]=i;
437 for (i=0; i<fNClusterN;i++) arrayN[i]=i;
439 //______________________________________________________________________
440 void AliITSClusterFinderSSD::SortClusters(Int_t* arrayP, Int_t *arrayN){
444 if(fNClusterP>1) for (i=0;i<fNClusterP-1;i++)
445 if (SortClustersP(0,(fNClusterP-1),arrayP)==0) break;
446 if(fNClusterN>1) for (i=0;i<fNClusterN-1;i++)
447 if (SortClustersN(0,(fNClusterN-1),arrayN)==0) break;
449 //______________________________________________________________________
450 Int_t AliITSClusterFinderSSD::SortClustersP(Int_t start, Int_t end,
452 //Sort P side clusters
456 if (start != (end - 1) ) {
457 left=this->SortClustersP(start,(start+end)/2,array);
458 right=this->SortClustersP((start+end)/2,end,array);
459 return (left || right);
461 left =((AliITSclusterSSD*)((*fClusterP)[array[start]]))->
463 right=((AliITSclusterSSD*)((*fClusterP)[array[ end ]]))->
466 Int_t tmp = array[start];
467 array[start]=array[end];
473 //______________________________________________________________________
474 Int_t AliITSClusterFinderSSD::SortClustersN(Int_t start, Int_t end,
476 //Sort N side clusters
480 if (start != (end - 1) ) {
481 left=this->SortClustersN(start,(start+end)/2,array);
482 right=this->SortClustersN((start+end)/2,end,array);
483 return (left || right);
485 left =((AliITSclusterSSD*)((*fClusterN)[array[start]]))->
487 right=((AliITSclusterSSD*)((*fClusterN)[array[ end ]]))->
490 Int_t tmp = array[start];
491 array[start]=array[end];
497 //______________________________________________________________________
498 void AliITSClusterFinderSSD::ClustersToPackages(){
501 Int_t *oneSclP = new Int_t[fNClusterP];//I want to have sorted 1 S clusters
502 Int_t *oneSclN = new Int_t[fNClusterN];//I can not sort it in TClonesArray
503 //so, I create table of indexes and
505 //I do not use TArrayI on purpose
506 //MB: well, that's not true that one
507 //cannot sort objs in TClonesArray
508 AliITSclusterSSD *currentP;
509 AliITSclusterSSD *currentN;
512 //Fills in One Side Clusters Index Array
513 FillClIndexArrays(oneSclP,oneSclN);
514 //Sorts filled Arrays
515 //SortClusters(oneSclP,oneSclN);
518 new ((*fPackages)[0]) AliITSpackageSSD(fClusterP,fClusterN);
520 //This part was includede by Boris Batiounia in March 2001.
521 // Take all recpoint pairs (x coordinates) in both P and N sides
522 // to calculate z coordinates of the recpoints
524 for (j1=0;j1<fNClusterP;j1++) {
525 currentP = GetPSideCluster(oneSclP[j1]);
526 Double_t xP = currentP->GetPosition();
527 Float_t signalP = currentP->GetTotalSignal();
528 for (j2=0;j2<fNClusterN;j2++) {
529 currentN = GetNSideCluster(oneSclN[j2]);
530 Double_t xN = currentN->GetPosition();
531 Float_t signalN = currentN->GetTotalSignal();
532 CreateNewRecPoint(xP,1,xN,1,signalP,signalN,currentP,currentN,
540 //______________________________________________________________________
541 Bool_t AliITSClusterFinderSSD::CreateNewRecPoint(Float_t P,Float_t dP,
542 Float_t N, Float_t dN,
543 Float_t SigP,Float_t SigN,
544 AliITSclusterSSD *clusterP,
545 AliITSclusterSSD *clusterN,
547 // create the recpoints
548 const Float_t kADCtoKeV = 2.16;
549 // 50 ADC units -> 30000 e-h pairs; 1e-h pair -> 3.6e-3 KeV;
550 // 1 ADC unit -> (30000/50)*3.6e-3 = 2.16 KeV
551 const Float_t kconv = 1.0e-4;
552 const Float_t kRMSx = 20.0*kconv;
553 const Float_t kRMSz = 800.0*kconv;
558 if (GetCrossing(P,N)) {
559 //GetCrossingError(dP,dN);
560 dP = dN = prob = 0.0; // to remove unused variable warning.
561 AliITSRawClusterSSD cnew;
562 Int_t nstripsP=clusterP->GetNumOfDigits();
563 Int_t nstripsN=clusterN->GetNumOfDigits();
568 dedx = SigP*kADCtoKeV;
571 dedx = SigN*kADCtoKeV;
572 } // end if SigP>SigN
573 tr = (Int_t*) clusterP->GetTracks(n);
574 ntracks = clusterP->GetNTracks();
575 cnew.SetSignalP(SigP);
576 cnew.SetSignalN(SigN);
577 cnew.SetMultiplicity(nstripsP);
578 cnew.SetMultN(nstripsN);
579 cnew.SetQErr(TMath::Abs(SigP-SigN));
580 cnew.SetNTrack(ntracks);
581 fITS->AddCluster(2,&cnew);
587 rnew.SetSigmaX2( kRMSx* kRMSx);
588 rnew.SetSigmaZ2( kRMSz* kRMSz);
589 rnew.fTracks[0]=tr[0];
590 rnew.fTracks[1]=tr[1];
591 rnew.fTracks[2]=tr[2];
592 fITS->AddRecPoint(rnew);
597 //______________________________________________________________________
598 void AliITSClusterFinderSSD::CalcStepFactor(Float_t Psteo, Float_t Nsteo){
599 // calculate the step factor for matching clusters
600 // 95 is the pitch, 4000 - dimension along z ?
601 Float_t dz=fSegmentation->Dz();
603 fSFF = ( (Int_t) (Psteo*dz/fPitch ) );// +1;
604 fSFB = ( (Int_t) (Nsteo*dz/fPitch ) );// +1;
606 //______________________________________________________________________
607 AliITSclusterSSD* AliITSClusterFinderSSD::GetPSideCluster(Int_t idx){
608 // get P side clusters
610 if((idx<0)||(idx>=fNClusterP)){
611 printf("AliITSClusterFinderSSD::GetPSideCluster: index out of range\n");
614 return (AliITSclusterSSD*)((*fClusterP)[idx]);
617 //______________________________________________________________________
618 AliITSclusterSSD* AliITSClusterFinderSSD::GetNSideCluster(Int_t idx){
619 // get N side clusters
621 if((idx<0)||(idx>=fNClusterN)){
622 printf("AliITSClusterFinderSSD::GetNSideCluster: index out of range\n");
625 return (AliITSclusterSSD*)((*fClusterN)[idx]);
628 //______________________________________________________________________
629 AliITSclusterSSD* AliITSClusterFinderSSD::GetCluster(Int_t idx, Bool_t side){
632 return (side) ? GetPSideCluster(idx) : GetNSideCluster(idx);
634 //______________________________________________________________________
635 Bool_t AliITSClusterFinderSSD::GetCrossing (Float_t &P, Float_t &N){
637 // This function was rivised and changed by Boris Batiounia in March 2001
638 Float_t dx = fSegmentation->Dx(); // detector size in x direction, microns
639 Float_t dz = fSegmentation->Dz(); // detector size in z direction, microns
640 Float_t xL; // x local coordinate
641 Float_t zL; // z local coordinate
642 Float_t x; // x = xL + dx/2
643 Float_t z; // z = zL + dz/2
644 Float_t xP; // x coordinate in the P side from the first P strip
645 Float_t xN; // x coordinate in the N side from the first N strip
646 Float_t stereoP,stereoN;
648 fSegmentation->Angles(stereoP,stereoN);
649 fTanP=TMath::Tan(stereoP);
650 fTanN=TMath::Tan(stereoN);
651 Float_t kP = fTanP; // Tangent of 0.0075 mrad
652 Float_t kN = fTanN; // Tangent of 0.0275 mrad
656 xP = N; // change the mistake for the P/N
657 xN = P; // coordinates correspondence in this function
659 x = xP + kP*(dz*kN-xP+xN)/(kP+kN);
660 z = (dz*kN-xP+xN)/(kP+kN);
666 if(TMath::Abs(xL) > dx/2 || TMath::Abs(zL) > dz/2) return kFALSE;
668 // Check that xL and zL are inside the detector for the
669 // correspondent xP and xN coordinates
673 //______________________________________________________________________
674 void AliITSClusterFinderSSD::GetCrossingError(Float_t& dP, Float_t& dN){
675 // get crossing error
678 dz = TMath::Abs(( dP + dN )*fPitch/(fTanP + fTanN) );
679 dx = fPitch*(TMath::Abs(dP*(1 - fTanP/(fTanP + fTanN))) +
680 TMath::Abs(dN *fTanP/(fTanP + fTanN) ));