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