]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSClusterFinder.cxx
Removing warnings (alpha)
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinder.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 // Base Class used to find
17 // the reconstructed points for ITS
18 // See also AliITSClusterFinderSPD, AliITSClusterFinderSDD, 
19 // AliITSClusterFinderSDD
20 //
21
22 #include "AliITSClusterFinder.h"
23 #include "AliITSdigitSPD.h"
24 #include "AliITSdigitSDD.h"
25 #include "AliITSdigitSSD.h"
26 #include "AliRun.h"
27 #include "AliITS.h"
28
29 ClassImp(AliITSClusterFinder)
30
31 //----------------------------------------------------------------------
32 AliITSClusterFinder::AliITSClusterFinder(){
33     // default cluster finder
34
35     fSegmentation = 0;
36     fResponse     = 0;
37     fMap          = 0;
38     fDigits       = 0;
39     fNdigits      = 0;
40     fNRawClusters = 0;
41     fNperMax      = 0;
42     fDeclusterFlag= 0;
43     fClusterSize  = 0;
44     fNPeaks       = 0;
45 }
46 //----------------------------------------------------------------------
47 AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg, 
48                                          AliITSresponse *response, 
49                                          TClonesArray *digits){
50   // cluster finder
51     fSegmentation=seg;
52     fResponse=response;
53     fMap = 0;
54     
55     fDigits=digits;
56     fNdigits = fDigits->GetEntriesFast();
57
58     fNRawClusters=0;
59
60     SetNperMax();
61     SetClusterSize();
62     SetDeclusterFlag();
63
64     fNPeaks=-1;
65 }
66 //----------------------------------------------------------------------
67 AliITSClusterFinder::~AliITSClusterFinder(){
68     // destructor cluster finder
69
70     // Zero local pointers. Other classes own these pointers.
71     fSegmentation = 0;
72     fResponse     = 0;
73     fMap          = 0;
74     fDigits       = 0;
75     fNdigits      = 0;
76     fNRawClusters = 0;
77     fNperMax      = 0;
78     fDeclusterFlag= 0;
79     fClusterSize  = 0;
80     fNPeaks       = 0;
81 }
82 //__________________________________________________________________________
83 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) :
84     TObject(source){
85     //     Copy Constructor 
86     if(&source == this) return;
87     this->fDigits = source.fDigits;
88     this->fNdigits = source.fNdigits;
89     this->fResponse = source.fResponse;
90     this->fSegmentation = source.fSegmentation;
91     this->fNRawClusters = source.fNRawClusters;
92     this->fMap = source.fMap;
93     this->fNperMax = source.fNperMax;
94     this->fDeclusterFlag = source.fDeclusterFlag;
95     this->fClusterSize = source.fClusterSize;
96     this->fNPeaks = source.fNPeaks;
97     return;
98 }
99 //______________________________________________________________________
100 AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder &source) {
101     //    Assignment operator
102
103     if(&source == this) return *this;
104     this->fDigits = source.fDigits;
105     this->fNdigits = source.fNdigits;
106     this->fResponse = source.fResponse;
107     this->fSegmentation = source.fSegmentation;
108     this->fNRawClusters = source.fNRawClusters;
109     this->fMap = source.fMap;
110     this->fNperMax = source.fNperMax;
111     this->fDeclusterFlag = source.fDeclusterFlag;
112     this->fClusterSize = source.fClusterSize;
113     this->fNPeaks = source.fNPeaks;
114     return *this;
115 }
116 //----------------------------------------------------------------------
117 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
118     // Add a raw cluster copy to the list
119
120     AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
121     iTS->AddCluster(branch,c); 
122     fNRawClusters++;
123 }
124 //----------------------------------------------------------------------
125 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c, 
126                                      AliITSRecPoint &rp){
127     // Add a raw cluster copy to the list
128
129     AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
130     iTS->AddCluster(branch,c); 
131     fNRawClusters++;
132     iTS->AddRecPoint(rp); 
133 }
134 //______________________________________________________________________
135 void AliITSClusterFinder::FindRawClusters(Int_t module){
136     // Default Cluster finder.
137     // Input:
138     //   Int_t module   Module number for which culster are to be found.
139     // Output:
140     //   none.
141     // Return:
142     //   none.
143     const Int_t kelms = 10;
144     Int_t ndigits = fDigits->GetEntriesFast();
145     TObjArray *digs = new TObjArray(ndigits);
146     TObjArray *clusts = new TObjArray(ndigits); // max # cluster
147     TObjArray *clust0=0; // A spacific cluster of digits
148     TObjArray *clust1=0; // A spacific cluster of digits
149     AliITSdigit *dig=0; // locat pointer to a digit
150     Int_t i=0,nc=0,j[4],k,k2=0;
151
152     // Copy all digits for this module into a local TObjArray.
153     for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*((AliITSdigit*)(fDigits->At(i)))),i);
154     digs->Sort();
155     // First digit is a cluster.
156     i  = 0;
157     nc = 0;
158     clusts->AddAt(new TObjArray(kelms),nc);
159     clust0 = (TObjArray*)(clusts->At(nc));
160     clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
161     nc++;
162     for(i=1;i<ndigits;i++){
163         if(IsNeighbor(digs,i,j)){
164             dig = (AliITSdigit*)(digs->At(j[0]));
165             // Add to existing cluster. Find which cluster this digis 
166             for(k=0;k<nc;k++){
167                 clust0 = ((TObjArray*)(clusts->At(k)));
168                 if(clust0->IndexOf(dig)>=0) break;
169             } // end for k
170             if(k>=nc){
171                 Fatal("FindRawClusters","Digit not found as expected");
172             } // end if
173             if(j[1]>=0){
174                 dig = (AliITSdigit*)(digs->At(j[1]));
175                 // Add to existing cluster. Find which cluster this digis 
176                 for(k2=0;k2<nc;k2++){
177                     clust1 = ((TObjArray*)(clusts->At(k2)));
178                     if(clust1->IndexOf(dig)>=0) break;
179                 } // end for k2
180                 if(k2>=nc){
181                     Fatal("FindRawClusters","Digit not found as expected");
182                 } // end if
183             } // end if j[1]>=0
184             // Found cluster with neighboring digits add this one to it.
185             if(clust0==clust1){ // same cluster
186                 clust0->AddAtFree(digs->At(i));
187                 clust0 = 0; // finished with cluster. zero for safty
188                 clust1 = 0; // finished wit hcluster. zero for safty
189             }else{ // two different clusters which need to be merged.
190                 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
191                 for(k=0;k<clust1->GetEntriesFast();k++){
192                     // move clust1 into clust0
193                     clust0->AddAtFree(clust1->At(k));//move digit to this cluster
194                     clust1->AddAt(0,k); // zero this one
195                 } // end for k
196                 delete clust1;
197                 clusts->AddAt(0,k2); // zero array of clusters element clust1
198                 clust0 = 0; // finished with cluster. zero for safty
199                 clust1 = 0; // finished wit hcluster. zero for safty
200             } // end if clust0==clust1
201         }else{// New cluster
202             clusts->AddAt(new TObjArray(kelms),nc);
203             clust0 = ((TObjArray*)(clusts->At(nc)));
204             clust0->AddAtFree(digs->At(i));// move owner ship from digs to clusts
205             clust0 = 0; // finished with cluster. zero for safty
206             nc++;
207         } // End if IsNeighbor
208     } // end for i
209     // There are now nc clusters in clusts. Each element of clust is an
210     // array of digits which are clustered together.
211
212     // For each cluster call detector specific CreateRecPoints
213     for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
214
215     // clean up at the end.
216     for(i=0;i<nc;i++){ 
217         clust0 =(TObjArray*)(clusts->At(i));
218         // Digits deleted below, so zero this TObjArray
219         for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
220         delete clust0; // Delete this TObjArray
221         clusts->AddAt(0,i); // Contents deleted above, so zero it.
222     } // end for i
223     delete clusts; // Delete this TObjArray/
224     // Delete the digits then the TObjArray which containted them.
225     for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
226     delete digs;
227 }
228 //______________________________________________________________________
229 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[]) const{
230     // Locagical function which checks to see if digit i has a neighbor.
231     // If so, then it returns kTRUE and its neighbor index j.
232     // This routine checks if the digits are side by side or one before the
233     // other. Requires that the array of digits be in proper order.
234     // Returns kTRUE in the following cases.
235     //                 ji   0j   if kdiagonal  j0    0i
236     //                 00   0i   if kdiagonal  0i    j0
237     // Inputs:
238     //    TObjArray *digs   Array to search for neighbors in
239     //    Int_t      i      Index of digit for which we are searching for
240     //                      a neighbor of.
241     // Output:
242     //    Int_t      j[4]   Index of one or more of the digits which is a
243     //                      neighbor of digit a index i.
244     // Return:
245     //    Bool_t            kTRUE if a neighbor was found kFALSE otherwise.
246     Int_t ix,jx,iz,jz,j;
247     const Bool_t kdiagonal=kFALSE;
248     Bool_t nei[4];
249
250     // No neighbors found if array empty.
251     if(digs->GetEntriesFast()<=0) return kFALSE;
252     // can not be a digit with first element or elements out or range
253     if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
254
255     for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
256     ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
257     iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
258     for(j=0;j<i;j++){
259         jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
260         jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
261         if(jx+1==ix && jz  ==iz){n[0] = j;nei[0] = kTRUE;}
262         if(jx  ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
263         if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
264         if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
265     } // end for k
266     if(nei[0]||nei[1]) return kTRUE;
267     if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
268     // no Neighbors found.
269     return kFALSE;
270 }