]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSclusterSSD.cxx
Checking in the seeds of new cluster fitting code.
[u/mrichter/AliRoot.git] / ITS / AliITSclusterSSD.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 /*
17 $Log$
18 Revision 1.10  2002/10/22 14:45:37  alibrary
19 Introducing Riostream.h
20
21 Revision 1.9  2002/10/14 14:57:00  hristov
22 Merging the VirtualMC branch to the main development branch (HEAD)
23
24 Revision 1.7.6.1  2002/10/14 13:14:08  hristov
25 Updating VirtualMC to v3-09-02
26
27 Revision 1.8  2002/09/09 17:23:28  nilsen
28 Minor changes in support of changes to AliITSdigitS?D class'.
29
30 */
31
32 #include <Riostream.h>
33 #include "TArrayI.h"
34 #include "TClonesArray.h"
35 #include "AliITSdigit.h"
36 #include "AliITSclusterSSD.h"
37
38 ClassImp(AliITSclusterSSD)
39
40 //______________________________________________________________________
41 AliITSclusterSSD::AliITSclusterSSD(){
42     // default constructor
43
44     fSide        = kTRUE;
45     fDigits      = 0;
46     fNDigits     = 0;
47     fDigitsIndex = 0;
48     fNCrosses    = 0;
49     fTotalSignal = -1;
50     fNTracks      = -1;
51     fLeftNeighbour  = kFALSE;
52     fRightNeighbour = kFALSE;
53     fCrossedClusterIndexes = 0;
54     fConsumed=kFALSE;
55 }
56 //______________________________________________________________________
57 AliITSclusterSSD::AliITSclusterSSD(Int_t ndigits, Int_t *DigitIndexes, 
58                                    TObjArray *Digits, Bool_t side){
59     // non-default constructor
60
61     fNDigits = ndigits;
62     fDigits = Digits;
63     fSide = side;
64     fDigitsIndex = new TArrayI(fNDigits,DigitIndexes ); 
65     fNCrosses    = 0;
66     fCrossedClusterIndexes = new TArrayI(300);
67     fLeftNeighbour  = kFALSE;
68     fRightNeighbour = kFALSE;
69     fTotalSignal =-1;
70     fNTracks    = -1;
71     fConsumed=kFALSE;
72 }
73 //______________________________________________________________________
74 AliITSclusterSSD::~AliITSclusterSSD(){
75     // destructor
76
77     delete fDigitsIndex;
78     delete fCrossedClusterIndexes;
79 }
80 //______________________________________________________________________
81 AliITSclusterSSD::AliITSclusterSSD(const AliITSclusterSSD &OneSCluster){
82     // copy constructor
83
84     if (this == &OneSCluster) return;
85     fNDigits = OneSCluster.fNDigits;
86     fSide=OneSCluster.fSide;
87     fDigits=OneSCluster.fDigits;
88     fDigitsIndex = new TArrayI(fNDigits);
89     fLeftNeighbour  = OneSCluster.fLeftNeighbour;
90     fRightNeighbour = OneSCluster.fRightNeighbour;
91     fTotalSignal =-1;
92     fNTracks     = -1;
93     fNCrosses = OneSCluster.fNCrosses;
94     fConsumed = OneSCluster.fConsumed;
95     Int_t i;
96     for (i = 0; i< fNCrosses ; i++){
97         fCrossedClusterIndexes[i] = OneSCluster.fCrossedClusterIndexes[i];
98     }
99     for (i = 0; i< fNDigits ; i++){
100         fDigitsIndex[i]=OneSCluster.fDigitsIndex[i];
101     }
102     return;
103 }
104 //______________________________________________________________________
105 AliITSclusterSSD& AliITSclusterSSD::operator=(const AliITSclusterSSD 
106                                               &OneSCluster){
107     // assignment operator
108
109     if (this == &OneSCluster) return *this;
110     fNDigits = OneSCluster.fNDigits;
111     fSide=OneSCluster.fSide;
112     fDigits=OneSCluster.fDigits;
113     fDigitsIndex = new TArrayI(fNDigits);
114     fLeftNeighbour  = OneSCluster.fLeftNeighbour;
115     fRightNeighbour = OneSCluster.fRightNeighbour;
116     fTotalSignal =-1;
117     fNTracks     = -1;
118     fNCrosses = OneSCluster.fNCrosses;
119     fConsumed = OneSCluster.fConsumed;
120     Int_t i;
121     for (i = 0; i< fNCrosses ; i++){
122         fCrossedClusterIndexes[i] = OneSCluster.fCrossedClusterIndexes[i];
123     }
124     for (i = 0; i< fNDigits ; i++){
125         fDigitsIndex[i]=OneSCluster.fDigitsIndex[i];
126     }
127     return *this;
128 }
129 //______________________________________________________________________
130 Int_t AliITSclusterSSD::SplitCluster(Int_t where, Int_t *outdigits){
131     //This methods generate data necessery to make new object of this class
132     //I choosen this way, because methods TClonesArray::Add* dont work
133     //so I have to use constraction: new (a[i]) Creator(params...);
134     //where 'a' is a TClonesArray 
135     //This method generate params - see AliITSmoduleSSD::SplitCluster;
136     Int_t tmp = fNDigits;
137     Int_t ind = 0;
138
139     outdigits[ind++]=(*fDigitsIndex)[where];
140     //coping border strip (it is shared by this two clusters)
141     for (Int_t i = (where+1); i < tmp; i++) {
142         outdigits[ind++]=(*fDigitsIndex)[i];  
143         //"moving" strips from this to the new one 
144         (*fDigitsIndex)[i]=-1;   
145         fNDigits--;   //deleting strips from this cluster
146     } 
147     return ind;         
148 }
149 //______________________________________________________________________
150 Int_t AliITSclusterSSD::GetDigitStripNo(Int_t digit){
151     // return strip no of a digit
152     if (digit<0) return -1;
153     return (digit>(fNDigits-1)) ? -1 :
154         ((AliITSdigitSSD*)(fDigits->At((*fDigitsIndex)[digit])))->GetStripNumber();
155 }
156 //______________________________________________________________________
157 Int_t AliITSclusterSSD::GetDigitSignal(Int_t digit){
158     // returns digit signal
159     Int_t index,signal;
160     if (digit<0||digit>=fNDigits) return -1;
161     index  = (*fDigitsIndex)[digit];
162     signal = ((AliITSdigitSSD*)(fDigits->At(index)))->GetSignal();
163     /*
164       if(signal>1.e5) printf("GetDigitSignal: digit %d index %d signal %d\n",
165       digit,index, signal);
166     */
167     return  signal;
168 }
169 //______________________________________________________________________
170 void  AliITSclusterSSD::AddCross(Int_t clIndex){
171     // add cluster cross to list of cluster crosses
172   
173     (*fCrossedClusterIndexes)[fNCrosses++] = clIndex;
174 }
175 //______________________________________________________________________
176 Int_t AliITSclusterSSD::GetCross(Int_t crIndex){
177     // return crossing cluster
178
179     return ((crIndex>-1)&&(crIndex<fNCrosses))?(*fCrossedClusterIndexes)[crIndex]:-1;
180 }
181 //______________________________________________________________________
182 Double_t AliITSclusterSSD::CentrOfGravity(){
183     // return center of gravity of the cluster
184     Float_t ret=0;
185   
186     if (fLeftNeighbour) ret+=(GetDigitStripNo(0)*0.5*GetDigitSignal(0));
187     else ret+=(GetDigitStripNo(0)*GetDigitSignal(0));
188     if (fRightNeighbour) ret+=(GetDigitStripNo(fNDigits -1)*0.5*GetDigitSignal(fNDigits -1));
189     else ret+=(GetDigitStripNo(fNDigits -1)*GetDigitSignal(fNDigits-1));
190     for (Int_t i=1;i<fNDigits-1;i++){
191         ret +=GetDigitStripNo(i)*GetDigitSignal(i);
192     }// end for i
193   
194     if (fTotalSignal<0) GetTotalSignal();
195         
196     return (ret/fTotalSignal);
197 }
198 //______________________________________________________________________
199 Float_t AliITSclusterSSD::GetTotalSignal(){
200     // return total signal
201   
202     if(fTotalSignal <0){
203         fTotalSignal=0;
204         if (fNDigits ==1)  {
205             fTotalSignal = (Float_t)GetDigitSignal(0);
206             //printf("1 digit: signal %d \n",GetDigitSignal(0)); 
207             return fTotalSignal;
208         }
209         if (fLeftNeighbour) fTotalSignal += (Float_t)(0.5*GetDigitSignal(0));
210         else fTotalSignal += (Float_t) GetDigitSignal(0);
211         //printf("GetTotalSignal :i DigitSignal %d %d \n",0,GetDigitSignal(0));
212         if (fRightNeighbour) fTotalSignal += (Float_t)(0.5*GetDigitSignal(
213                                                                  fNDigits -1));
214       else fTotalSignal += (Float_t)GetDigitSignal(fNDigits-1);
215         //printf("GetTotalSignal :i  DigitSignal %d %d \n",fNDigits -1,GetDigitSignal(fNDigits -1));
216         for (Int_t i = 1;i<fNDigits -1;i++){
217             fTotalSignal += (Float_t)GetDigitSignal(i);
218             //printf("GetTotalSignal :i  DigitSignal %d %d \n",i,GetDigitSignal(i)); 
219         }
220         //printf("GetTotalSignal: fNDigits %d fTotalSignal %.0f \n",fNDigits,fTotalSignal); 
221     }
222     return fTotalSignal;
223 }
224 //______________________________________________________________________
225 Float_t  AliITSclusterSSD::GetTotalSignalError(){
226     // return the error on the signal
227     Float_t err =0;
228     for (Int_t i =1; i<fNDigits -1; i++){
229         err+=0.1*GetDigitSignal(i);   
230     } 
231     if (GetLeftNeighbour()){
232         err+=GetDigitSignal(0);
233     }else{
234         err+=0.1*GetDigitSignal(0);
235     } 
236     if (GetRightNeighbour()){
237         err+=GetDigitSignal(fNDigits -1);
238     }else{
239         err+=0.1*GetDigitSignal(fNDigits -1);
240     }
241     return err;
242 }
243 //______________________________________________________________________
244 void AliITSclusterSSD::DelCross(Int_t index){
245     // remove cross clusters from the list of cross clusters
246     Int_t i,j; //iterators
247
248     for (i =0;i<fNCrosses;i++){
249         if ((*fCrossedClusterIndexes)[i] == index){
250             for (j=i;j<fNCrosses-1;j++){
251                 (*fCrossedClusterIndexes)[j]=(*fCrossedClusterIndexes)[j+1];
252             }
253             fNCrosses--;
254             return; 
255         }
256     }
257 }
258 //______________________________________________________________________
259 Int_t  *AliITSclusterSSD::GetTracks(Int_t &nt){
260     // return the track number of the cluster
261     Int_t ntrk = GetDigit(0)->GetNTracks();
262     Int_t ndig = GetNumOfDigits();
263     Int_t *idig = new Int_t[ndig];
264     Int_t *sdig = new Int_t[ndig];
265     Int_t *itrk = new Int_t[ndig*ntrk];
266     Int_t i,j,k,l,trk;
267     Bool_t b;
268
269     for(i=0;i<ndig;i++){idig[i] = i;sdig[i] = GetDigit(i)->GetSignal();}
270     TMath::Sort(ndig,sdig,idig,kTRUE);
271     for(i=0;i<ndig*ntrk;i++) itrk[i] = -3;
272     j = k = l = 0;
273     for(i=0;i<ndig;i++){ // fill itrk with track numbers in order of digit size
274         j = idig[i];
275         for(k=0;k<ntrk;k++) if((trk = GetDigit(j)->GetTrack(k))>=0) {
276             itrk[l] = trk;
277             l++;
278         } // end for k/if
279     } // end for i
280     for(i=0;i<10;i++) fTrack[i] = -3;
281     fTrack[0] = itrk[0]; // first element
282     k = 1;
283     b = kTRUE;
284     for(i=1;i<l;i++){
285         for(j=0;j<k;j++) if(fTrack[j]==itrk[i]) b = kFALSE;
286         if(b){fTrack[k] = itrk[i]; k++;}
287         if(k>9) break;
288     } // end for i
289     nt = k;
290
291     delete[] idig;
292     delete[] sdig;
293     delete[] itrk;
294
295     return fTrack;
296 /*
297     Int_t *tidx=0;
298     Int_t i, j,n;
299     Int_t bit =0;
300     Int_t ntracks=0;
301     nt=0;
302
303     for (i=0;i<10;i++) fTrack[i] = -3;
304    
305     //cout<<"GetTrack start -------: fNDigits ="<<fNDigits<<endl;
306
307     for (i = 0; i<fNDigits; i++) {
308         tidx = GetDigit(i)->GetTracks();
309         n    = GetDigit(i)->GetNTracks();
310         for (j = 0; j<n && j<10;j++) {
311             if (tidx[j] >= 0) {
312                 if(ntracks == 0){
313                     fTrack[ntracks] = tidx[j];
314                     ntracks++; 
315                 }else if(tidx[j] != fTrack[ntracks-1]){
316                     ntracks++; 
317                     if(ntracks > 9) {
318                         bit = 1;
319                         break;
320                     } // end if ntracks > 9
321                     fTrack[ntracks-1] = tidx[j];
322                 } // end if ntracke == 0
323             } // end if tidx[j] >=0
324         } // 3-tracks loop for the digit 
325         if(bit == 1) break;
326     } // digit loop
327
328     SetNTracks(ntracks); 
329     nt = ntracks;
330     return &(fTrack[0]);
331 */
332 }
333 //______________________________________________________________________
334 Double_t AliITSclusterSSD::GetPosition(){
335     // return position of the cluster
336     Float_t ret;
337
338     switch(fNDigits){
339     case  1:
340         ret = GetDigitStripNo(0);
341         break;
342     case  2:
343         ret = EtaAlgorithm();
344         break;       
345     default:
346         ret = CentrOfGravity();   
347     }
348     return ret;
349 }
350 //______________________________________________________________________
351 Double_t AliITSclusterSSD::EtaAlgorithm(){
352     // algorithm for determing cluster position
353     if (fNDigits != 2) return -1;
354
355     Int_t strip1  = GetDigit(0)->GetStripNumber(); 
356     Int_t strip2  = GetDigit(1)->GetStripNumber();
357     Int_t signal1 = GetDigit(0)->GetSignal();
358     Int_t signal2 = GetDigit(1)->GetSignal();
359
360     Double_t eta;
361   
362  
363     if (strip1<strip2){
364         eta = ((Double_t)signal2)/((Double_t)(signal1+signal2));
365         if (eta<0.04) return strip1;
366         if (eta>0.96) return strip2;
367         return (strip1 + 0.43478261*eta + 0.2826087);   
368     } else{
369         eta = ((Double_t)signal1)/((Double_t)(signal1+signal2));
370         if (eta<0.04) return strip2;
371         if (eta>0.96) return strip1;
372         return (strip2 + 0.43478261*eta + 0.2826087);   
373     }
374 }
375 //______________________________________________________________________
376 Double_t  AliITSclusterSSD::GetPositionError(){
377     // return the position error
378     return (GetNumOfDigits()+1)/2;
379 }
380 //______________________________________________________________________
381 Bool_t AliITSclusterSSD::IsCrossingWith(Int_t idx){
382     // return the cluster to which he crosses
383
384     for (Int_t i =0; i< fNCrosses;i++){
385         if (GetCross(i) == idx) return kTRUE;
386     }
387     return kFALSE;
388 }