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