1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 // Base Class used to find
17 // the reconstructed points for ITS
18 // See also AliITSClusterFinderSPD, AliITSClusterFinderSDD,
19 // AliITSClusterFinderSDD
22 #include "AliITSClusterFinder.h"
23 #include "AliITSdigit.h"
27 ClassImp(AliITSClusterFinder)
29 //----------------------------------------------------------------------
30 AliITSClusterFinder::AliITSClusterFinder(){
31 // default cluster finder
44 //----------------------------------------------------------------------
45 AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg,
46 AliITSresponse *response,
47 TClonesArray *digits){
54 fNdigits = fDigits->GetEntriesFast();
64 //----------------------------------------------------------------------
65 AliITSClusterFinder::~AliITSClusterFinder(){
66 // destructor cluster finder
68 // Zero local pointers. Other classes own these pointers.
80 //__________________________________________________________________________
81 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) :
84 if(&source == this) return;
85 this->fDigits = source.fDigits;
86 this->fNdigits = source.fNdigits;
87 this->fResponse = source.fResponse;
88 this->fSegmentation = source.fSegmentation;
89 this->fNRawClusters = source.fNRawClusters;
90 this->fMap = source.fMap;
91 this->fNperMax = source.fNperMax;
92 this->fDeclusterFlag = source.fDeclusterFlag;
93 this->fClusterSize = source.fClusterSize;
94 this->fNPeaks = source.fNPeaks;
97 //______________________________________________________________________
98 AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder &source) {
99 // Assignment operator
101 if(&source == this) return *this;
102 this->fDigits = source.fDigits;
103 this->fNdigits = source.fNdigits;
104 this->fResponse = source.fResponse;
105 this->fSegmentation = source.fSegmentation;
106 this->fNRawClusters = source.fNRawClusters;
107 this->fMap = source.fMap;
108 this->fNperMax = source.fNperMax;
109 this->fDeclusterFlag = source.fDeclusterFlag;
110 this->fClusterSize = source.fClusterSize;
111 this->fNPeaks = source.fNPeaks;
114 //----------------------------------------------------------------------
115 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
116 // Add a raw cluster copy to the list
118 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
119 iTS->AddCluster(branch,c);
122 //----------------------------------------------------------------------
123 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
125 // Add a raw cluster copy to the list
127 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
128 iTS->AddCluster(branch,c);
130 iTS->AddRecPoint(rp);
132 //______________________________________________________________________
133 void AliITSClusterFinder::FindRawClusters(Int_t module){
134 // Default Cluster finder.
136 // Int_t module Module number for which culster are to be found.
141 const Int_t kelms = 10;
142 Int_t ndigits = fDigits->GetEntriesFast();
143 TObjArray *digs = new TObjArray(ndigits);
144 TObjArray *clusts = new TObjArray(ndigits); // max # cluster
145 TObjArray *clust0=0; // A spacific cluster of digits
146 TObjArray *clust1=0; // A spacific cluster of digits
147 AliITSdigit *dig=0; // locat pointer to a digit
148 Int_t i=0,nc=0,j[4],k,k2=0;
150 // Copy all digits for this module into a local TObjArray.
151 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*((AliITSdigit*)(fDigits->At(i)))),i);
153 // First digit is a cluster.
156 clusts->AddAt(new TObjArray(kelms),nc);
157 clust0 = (TObjArray*)(clusts->At(nc));
158 clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
160 for(i=1;i<ndigits;i++){
161 if(IsNeighbor(digs,i,j)){
162 dig = (AliITSdigit*)(digs->At(j[0]));
163 // Add to existing cluster. Find which cluster this digis
165 clust0 = ((TObjArray*)(clusts->At(k)));
166 if(clust0->IndexOf(dig)>=0) break;
169 Fatal("FindRawClusters","Digit not found as expected");
172 dig = (AliITSdigit*)(digs->At(j[1]));
173 // Add to existing cluster. Find which cluster this digis
174 for(k2=0;k2<nc;k2++){
175 clust1 = ((TObjArray*)(clusts->At(k2)));
176 if(clust1->IndexOf(dig)>=0) break;
179 Fatal("FindRawClusters","Digit not found as expected");
182 // Found cluster with neighboring digits add this one to it.
183 if(clust0==clust1){ // same cluster
184 clust0->AddAtFree(digs->At(i));
185 clust0 = 0; // finished with cluster. zero for safty
186 clust1 = 0; // finished wit hcluster. zero for safty
187 }else{ // two different clusters which need to be merged.
188 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
189 for(k=0;k<clust1->GetEntriesFast();k++){
190 // move clust1 into clust0
191 clust0->AddAtFree(clust1->At(k));//move digit to this cluster
192 clust1->AddAt(0,k); // zero this one
195 clusts->AddAt(0,k2); // zero array of clusters element clust1
196 clust0 = 0; // finished with cluster. zero for safty
197 clust1 = 0; // finished wit hcluster. zero for safty
198 } // end if clust0==clust1
200 clusts->AddAt(new TObjArray(kelms),nc);
201 clust0 = ((TObjArray*)(clusts->At(nc)));
202 clust0->AddAtFree(digs->At(i));// move owner ship from digs to clusts
203 clust0 = 0; // finished with cluster. zero for safty
205 } // End if IsNeighbor
207 // There are now nc clusters in clusts. Each element of clust is an
208 // array of digits which are clustered together.
210 // For each cluster call detector specific CreateRecPoints
211 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
213 // clean up at the end.
215 clust0 =(TObjArray*)(clusts->At(i));
216 // Digits deleted below, so zero this TObjArray
217 for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
218 delete clust0; // Delete this TObjArray
219 clusts->AddAt(0,i); // Contents deleted above, so zero it.
221 delete clusts; // Delete this TObjArray/
222 // Delete the digits then the TObjArray which containted them.
223 for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
226 //______________________________________________________________________
227 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[]) const{
228 // Locagical function which checks to see if digit i has a neighbor.
229 // If so, then it returns kTRUE and its neighbor index j.
230 // This routine checks if the digits are side by side or one before the
231 // other. Requires that the array of digits be in proper order.
232 // Returns kTRUE in the following cases.
233 // ji 0j if kdiagonal j0 0i
234 // 00 0i if kdiagonal 0i j0
236 // TObjArray *digs Array to search for neighbors in
237 // Int_t i Index of digit for which we are searching for
240 // Int_t j[4] Index of one or more of the digits which is a
241 // neighbor of digit a index i.
243 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
245 const Bool_t kdiagonal=kFALSE;
248 // No neighbors found if array empty.
249 if(digs->GetEntriesFast()<=0) return kFALSE;
250 // can not be a digit with first element or elements out or range
251 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
253 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
254 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
255 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
257 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
258 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
259 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
260 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
261 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
262 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
264 if(nei[0]||nei[1]) return kTRUE;
265 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
266 // no Neighbors found.