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