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