]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSClusterFinderSPD.cxx
New version of TOF tracker which uses TOF clusters as an input (A. De Caro)
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderSPD.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15 ////////////////////////////////////////////////////////////////////////////
16 //  Cluster finder                                                       ///
17 //  for Silicon pixels                                                    // 
18 //                                                                        //
19 ////////////////////////////////////////////////////////////////////////////        
20
21 #include "AliITSClusterFinderSPD.h"
22 #include "AliITSDetTypeRec.h"
23 #include "AliITSRawClusterSPD.h"
24 #include "AliITSRecPoint.h"
25 #include "AliITSdigitSPD.h"
26 #include "AliITSsegmentationSPD.h"
27 #include "AliLog.h"
28
29 //#define DEBUG
30
31 ClassImp(AliITSClusterFinderSPD)
32
33 //______________________________________________________________________
34 AliITSClusterFinderSPD::AliITSClusterFinderSPD():AliITSClusterFinder(),
35 fDz(0.0),
36 fDx(0.0),
37 fMinNCells(0){
38     // constructor
39 }
40 //----------------------------------------------------------
41 AliITSClusterFinderSPD::AliITSClusterFinderSPD(AliITSsegmentation *seg,
42                                                AliITSresponse *res):
43 AliITSClusterFinder(seg,res),
44 fDz(0.0),
45 fDx(0.0),
46 fMinNCells(0){
47     // constructor
48
49     SetDx();
50     SetDz();
51 }
52 //----------------------------------------------------------
53 AliITSClusterFinderSPD::AliITSClusterFinderSPD(AliITSsegmentation *seg,
54                                                TClonesArray *digits,
55                                                TClonesArray *recp):
56 AliITSClusterFinder(seg,0),
57 fDz(0.0),
58 fDx(0.0),
59 fMinNCells(0){
60     // constructor
61
62     SetDigits(digits);
63     SetClusters(recp);
64     SetDx();
65     SetDz();
66 }
67
68 //______________________________________________________________________
69 AliITSClusterFinderSPD::AliITSClusterFinderSPD(const AliITSClusterFinderSPD &source) : AliITSClusterFinder(source) {
70   // Copy constructor
71   // Copies are not allowed. The method is protected to avoid misuse.
72   Fatal("AliITSClusterFinderSPD","Copy constructor not allowed\n");
73 }
74
75 //______________________________________________________________________
76 AliITSClusterFinderSPD& AliITSClusterFinderSPD::operator=(const AliITSClusterFinderSPD& /* source */){
77   // Assignment operator
78   // Assignment is not allowed. The method is protected to avoid misuse.
79   Fatal("= operator","Assignment operator not allowed\n");
80   return *this;
81 }
82 //______________________________________________________________________
83 void AliITSClusterFinderSPD::FindRawClusters(Int_t module){   
84     // input of Cluster Finder
85     Int_t   digitcount  = 0;
86     Int_t   numberd     = 100000;
87     Int_t   *digx       = new Int_t[numberd];
88     Int_t   *digz       = new Int_t[numberd];
89     Int_t   *digtr1     = new Int_t[numberd];
90     Int_t   *digtr2     = new Int_t[numberd];
91     Int_t   *digtr3     = new Int_t[numberd];
92     Int_t   *digtr4     = new Int_t[numberd];
93     //  output of Cluster Finder    
94     Int_t   numberc     = 10000;
95     Double_t *xcenterl   = new Double_t[numberc];
96     Double_t *zcenterl   = new Double_t[numberc];
97     Double_t *errxcenter = new Double_t[numberc];
98     Double_t *errzcenter = new Double_t[numberc];
99     Int_t   *tr1clus    = new Int_t[numberc];
100     Int_t   *tr2clus    = new Int_t[numberc];
101     Int_t   *tr3clus    = new Int_t[numberc];
102     Int_t   nclus;
103
104     SetModule(module);
105     digitcount=0;
106     Int_t ndigits = Digits()->GetEntriesFast();  
107     if (!ndigits) return;
108
109     AliITSdigitSPD *dig;
110     Int_t ndig=0,i;
111     /*
112     AliDebug(4," ");
113         scanf("%d",&ndig);
114     */
115     for(ndig=0; ndig<ndigits; ndig++) {
116         dig= (AliITSdigitSPD*)GetDigit(ndig);
117         digx[digitcount] = dig->GetCoord2()+1;  //starts at 1
118         digz[digitcount] = dig->GetCoord1()+1;  //starts at 1
119         digtr1[digitcount] = dig->GetTrack(0);
120         digtr2[digitcount] = -3;
121         digtr3[digitcount] = -3;
122         AliDebug(5,Form("digtr1[%d]=%d fTracks[%d]=%d: ",
123                         digitcount,digtr1[digitcount],0,dig->GetTrack(0)));
124         i=1;
125         while(digtr1[digitcount]==dig->GetTrack(i) && i<dig->GetNTracks()) i++;
126         AliDebug(5,Form(" fTracks[%d]=%d",i,dig->GetTrack(i)));
127         if(i<dig->GetNTracks()){
128             digtr2[digitcount] = dig->GetTrack(i);
129             AliDebug(5,Form("digtr2[%d]=%d: ",digitcount,digtr2[digitcount]));
130             while((digtr1[digitcount]==dig->GetTrack(i) || 
131                    digtr2[digitcount]==dig->GetTrack(i))&&
132                   i<=dig->GetNTracks()) i++;
133             if(i<dig->GetNTracks()) digtr3[digitcount] = dig->GetTrack(i);
134             AliDebug(5,Form(" fTracks[%d]=%d digtr3[%d]=%d",
135                             i,i<dig->GetNTracks()?dig->GetTrack(i):-1,digitcount,digtr3[digitcount]));
136         } // end if
137     //        if(GetDebug(4)) cout<<endl;
138         digtr4[digitcount] = dig->GetSignal();
139         digitcount++;
140     } // end for ndig
141     ClusterFinder(digitcount,digx,digz,digtr1,digtr2,digtr3,digtr4,
142                   nclus,xcenterl,zcenterl,errxcenter,errzcenter,
143                   tr1clus, tr2clus, tr3clus);
144     DigitToPoint(nclus,xcenterl,zcenterl,errxcenter,errzcenter,
145                  tr1clus, tr2clus, tr3clus);
146     delete[] digx;
147     delete[] digz;
148     delete[] digtr1;
149     delete[] digtr2;
150     delete[] digtr3;
151     delete[] digtr4;
152     delete[] xcenterl;
153     delete[] zcenterl;
154     delete[] errxcenter;
155     delete[] errzcenter;
156     delete[] tr1clus;
157     delete[] tr2clus;
158     delete[] tr3clus;
159 }
160 //----------------------------------------------------------------------
161 void AliITSClusterFinderSPD::ClusterFinder(Int_t ndigits,Int_t digx[],
162                                            Int_t digz[],Int_t digtr1[],
163                                            Int_t digtr2[],Int_t digtr3[],
164                                            Int_t digtr4[],Int_t &nclus,
165                                            Double_t xcenter[],Double_t zcenter[],
166                                            Double_t errxcenter[],
167                                            Double_t errzcenter[],
168                                            Int_t tr1clus[],Int_t tr2clus[],
169                                            Int_t tr3clus[]){
170     // Search for clusters of fired pixels (digits). Two digits are linked
171     // inside a cluster if they are countiguous both in row or column
172     // direction.  Diagonal digits are not linked.
173     // xcenter, ycenter, zcenter are the coordinates of the center
174     // of each found cluster, calculated from the averaging the corresponding
175     // coordinate of the center of the linked digits. The coordinates are
176     // given in the local reference sistem. 
177     // errxcenter, errycenter, errzcenter are the errors associated to
178     // the corresponding average.
179     Int_t   if1, min, max, nd;
180     Int_t   x1, z1, t1, t2, t3, t4;
181     Int_t   ndx, ndz, ndxmin=0, ndxmax=0, ndzmin=0, ndzmax=0;
182     Double_t dx, dz; 
183     Int_t   i,k,ipos=0;
184     Float_t xdum, zdum;      
185     Int_t   kmax, sigmax;
186     Double_t deltax, deltaz;
187     Double_t ndig;
188     Int_t   numberd = 10000;
189     Int_t   *ifpad  = new Int_t[numberd];
190     Int_t   *xpad   = new Int_t[numberd];
191     Int_t   *zpad   = new Int_t[numberd];
192     Int_t   *tr1pad = new Int_t[numberd];
193     Int_t   *tr2pad = new Int_t[numberd];
194     Int_t   *tr3pad = new Int_t[numberd];
195     Int_t   *tr4pad = new Int_t[numberd];
196     Int_t   *iclus  = new Int_t[numberd];
197
198     nclus=1;
199     for (i=0; i < ndigits ; i++){
200         ifpad[i] = -1;
201         iclus[i] = 0;
202     } // end for i
203
204     ifpad[0]=0;
205     for (i=0; i < ndigits-1 ; i++) {
206         if ( ifpad[i] == -1 ) { 
207             nclus++;
208             ipos++;
209             ifpad[i]=nclus-1;
210         } // end if ipad[i]
211         for (Int_t j=i+1 ; j < ndigits ; j++)  {  
212             if (ifpad[j]== -1 ) {
213                 dx = TMath::Abs(digx[i]-digx[j]);
214                 dz = TMath::Abs(digz[i]-digz[j]);
215                 // if ( ( dx+dz )==1 )  //clusters are not diagonal
216                 if(( dx+dz )==1 || (dx==1 && dz==1)){
217                     //diagonal clusters allowed
218                     ipos++;
219                     ifpad[j] = ifpad[i];
220                     
221                     x1         = digx[j];
222                     z1         = digz[j];
223                     digx[j]    = digx[ipos];
224                     digz[j]    = digz[ipos];
225                     digx[ipos] = x1;
226                     digz[ipos] = z1;
227                     
228                     t1 = digtr1[j];
229                     t2 = digtr2[j];
230                     t3 = digtr3[j];
231                     t4 = digtr4[j];
232                     digtr1[j] = digtr1[ipos];
233                     digtr2[j] = digtr2[ipos];
234                     digtr3[j] = digtr3[ipos];
235                     digtr4[j] = digtr4[ipos];
236                     digtr1[ipos] = t1;
237                     digtr2[ipos] = t2;
238                     digtr3[ipos] = t3;
239                     digtr4[ipos] = t4;
240                     
241                     if1 = ifpad[j];
242                     ifpad[j] = ifpad[ipos];
243                     ifpad[ipos] = if1;
244                 } // end dx+dx...
245             }// end if ifpad[j]== -1 
246         } // end for j
247     }//end loop on digits
248     if ( ifpad[ndigits-1] == -1 ) {
249         nclus++;
250         ifpad[ndigits-1]=nclus-1;
251     } // end if ifpad[ndigits-1] == -1
252     
253     for (i=0 ; i < ndigits ; i++) iclus[ifpad[i]]++;
254
255     min=0;
256     max=0;
257     // loop on found clusters 
258     for (i=0 ; i < nclus ; i++){
259         min = max;
260         max += iclus[i];
261         deltax = GetSeg()->Dpx(0);
262         if (iclus[i]!=1){
263             //cluster with more than one digit
264             nd=iclus[i];
265             ndig=(Double_t) nd;
266             Int_t count=0;
267             for (k=min;k<min+nd;k++){
268                 xpad[count] = digx[k];     
269                 zpad[count] = digz[k];
270
271                 tr1pad[count] = digtr1[k];         
272                 tr2pad[count] = digtr2[k];         
273                 tr3pad[count] = digtr3[k];         
274                 tr4pad[count] = digtr4[k];         
275                 
276                 count++; 
277             } // end for k
278             ndxmin = xpad[TMath::LocMin(nd,xpad)];
279             ndxmax = xpad[TMath::LocMax(nd,xpad)];
280             ndzmin = zpad[TMath::LocMin(nd,zpad)];
281             ndzmax = zpad[TMath::LocMax(nd,zpad)];
282             ndx = ndxmax - ndxmin+1;
283             ndz = ndzmax - ndzmin+1;
284             
285             // calculate x and z coordinates of the center of the cluster
286             GetSeg()->GetPadCxz(digx[min],digz[min]-1,xdum, zdum);
287             
288             if (ndx == 1) {
289                 xcenter[i] = xdum;
290             }else{ 
291                 xcenter[i] = 0.;
292                 for (k=0;k<nd;k++) {
293                     GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
294                     xcenter[i] += (xdum / nd);
295                 } // end for k               
296             } // end if ndx
297             
298             if (ndz == 1) {
299                 zcenter[i] = zdum;
300             } else {
301                 zcenter[i] = 0.;
302                 for (k=0;k<nd;k++) {          
303                     GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
304                     zcenter[i] += (zdum / nd);
305                 } // end for k
306             } // end if ndz
307             
308             // error on points in x and z directions
309             
310             if (ndx == 1) {
311                 errxcenter[i] = deltax / TMath::Sqrt(12.);
312             } else {
313                 errxcenter[i] = 0.;                     
314                 for (k=0;k<nd;k++){ 
315                     GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
316                     errxcenter[i] += ((xdum-xcenter[i])*(xdum-xcenter[i]))/
317                         (nd*(nd-1)); 
318                 } // end for k
319                 errxcenter[i] = TMath::Sqrt(errxcenter[i]);
320             } // end if ndx     
321             if (ndz == 1) {
322                 deltaz = GetSeg()->Dpz(digz[min]);                    
323                 errzcenter[i] = deltaz / TMath::Sqrt(12.);
324             } else {
325                 errzcenter[i] = 0.;
326                 for (k=0;k<nd;k++){ 
327                     GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
328                     errzcenter[i] += ((zdum-zcenter[i])*(zdum-zcenter[i]))/
329                         (nd*(nd-1));
330                 } // end for k
331                 errzcenter[i] = TMath::Sqrt(errzcenter[i]);
332             } // end if ndz
333             // take three track numbers for the cluster
334             // choose the track numbers of the digit with higher signal 
335             kmax = 0;
336             sigmax = 0;
337             for (k=0;k<nd;k++){
338                 if(tr4pad[k] > sigmax){
339                     sigmax = tr4pad[k];
340                     kmax   = k;
341                 } // end if tr4pad[k]
342             } // end for k
343             if(sigmax != 0) {
344                 tr1clus[i]= tr1pad[kmax];
345                 tr2clus[i]= tr2pad[kmax];
346                 tr3clus[i]= tr3pad[kmax];
347             } else {
348                 tr1clus[i]= -2;
349                 tr2clus[i]= -2;
350                 tr3clus[i]= -2;
351             } // end if sigmax
352         } else {
353             // cluster with single digit
354             ndig= 1.;
355             ndx = 1;
356             ndz = 1;
357             GetSeg()->GetPadCxz(digx[min],digz[min]-1,xdum,zdum);
358             xcenter[i] = xdum;
359             zcenter[i] = zdum;
360             tr1clus[i]=digtr1[min];
361             tr2clus[i]=digtr2[min];
362             tr3clus[i]=digtr3[min];
363             deltaz = GetSeg()->Dpz(digz[min]);
364             errxcenter[i] = deltax / TMath::Sqrt(12.);
365             errzcenter[i] = deltaz / TMath::Sqrt(12.);
366         } // end if iclus[i]
367
368         // store the cluster information to the AliITSRawCLusterSPD object
369    
370
371         //put the cluster center in local reference frame of the detector
372         // and in microns
373         xcenter[i] = xcenter[i] - GetSeg()->Dx()/2.; 
374         zcenter[i] = zcenter[i] - GetSeg()->Dz()/2.;
375
376         AliITSRawClusterSPD *clust = new AliITSRawClusterSPD(zcenter[i], //f
377                                                              xcenter[i], //f
378                                                              ndig, //f
379                                                              ndz,ndx, //ii
380                                                              ndxmin,ndxmax,//ii
381                                                              (Double_t) ndzmin,
382                                                              (Double_t) ndzmax,
383                                                              0,GetModule());
384         fDetTypeRec->AddCluster(0,clust);
385         delete clust;
386     }//end loop on clusters   
387     delete[] ifpad;
388     delete[] xpad ;
389     delete[] zpad ;
390     delete[] iclus;
391     delete[] tr1pad;
392     delete[] tr2pad;
393     delete[] tr3pad;
394     delete[] tr4pad;
395 }
396 //______________________________________________________----------------
397 void AliITSClusterFinderSPD::DigitToPoint(Int_t nclus,
398                                           Double_t *xcenter,Double_t *zcenter,
399                                           Double_t *errxcenter,
400                                           Double_t *errzcenter, 
401                                           Int_t *tr1clus, Int_t *tr2clus,
402                                           Int_t *tr3clus){
403     // A point is associated to each cluster of SPD digits. The points
404     // and their associated errors are stored in the file galiceSP.root.
405     Double_t l[3],xg,zg;
406     const Double_t kconv = 1.0e-4; // micron -> cm
407
408     // get rec points
409     for (Int_t i=0; i<nclus; i++){
410         l[0] = kconv*xcenter[i];
411         l[1] = kconv*GetSeg()->Dy()/2.;
412         l[2] = kconv*zcenter[i];
413
414         xg = l[0]; 
415         zg = l[2]; 
416
417         Double_t sigma2x = (kconv*errxcenter[i]) * (kconv*errxcenter[i]);
418         Double_t sigma2z = (kconv*errzcenter[i]) * (kconv*errzcenter[i]);
419         AliITSRecPoint rnew;
420         rnew.SetX(xg);
421         rnew.SetZ(zg);
422         rnew.SetQ(1.);
423         rnew.SetdEdX(0.);
424         rnew.SetSigmaX2(sigma2x);
425         rnew.SetSigmaZ2(sigma2z);
426         rnew.fTracks[0]=tr1clus[i];
427         rnew.fTracks[1]=tr2clus[i];
428         rnew.fTracks[2]=tr3clus[i];
429         fDetTypeRec->AddRecPoint(rnew); 
430     } // end for i
431 }