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 #include "AliITSClusterFinder.h"
17 #include "AliITSdigit.h"
21 ClassImp(AliITSClusterFinder)
23 //----------------------------------------------------------------------
24 AliITSClusterFinder::AliITSClusterFinder(){
25 // default cluster finder
38 //----------------------------------------------------------------------
39 AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg,
40 AliITSresponse *response,
41 TClonesArray *digits){
48 fNdigits = fDigits->GetEntriesFast();
58 //----------------------------------------------------------------------
59 AliITSClusterFinder::~AliITSClusterFinder(){
60 // destructor cluster finder
62 // Zero local pointers. Other classes own these pointers.
74 //__________________________________________________________________________
75 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source){
77 if(&source == this) return;
78 this->fDigits = source.fDigits;
79 this->fNdigits = source.fNdigits;
80 this->fResponse = source.fResponse;
81 this->fSegmentation = source.fSegmentation;
82 this->fNRawClusters = source.fNRawClusters;
83 this->fMap = source.fMap;
84 this->fNperMax = source.fNperMax;
85 this->fDeclusterFlag = source.fDeclusterFlag;
86 this->fClusterSize = source.fClusterSize;
87 this->fNPeaks = source.fNPeaks;
90 //______________________________________________________________________
91 AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder &source) {
92 // Assignment operator
94 if(&source == this) return *this;
95 this->fDigits = source.fDigits;
96 this->fNdigits = source.fNdigits;
97 this->fResponse = source.fResponse;
98 this->fSegmentation = source.fSegmentation;
99 this->fNRawClusters = source.fNRawClusters;
100 this->fMap = source.fMap;
101 this->fNperMax = source.fNperMax;
102 this->fDeclusterFlag = source.fDeclusterFlag;
103 this->fClusterSize = source.fClusterSize;
104 this->fNPeaks = source.fNPeaks;
107 //----------------------------------------------------------------------
108 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
109 // Add a raw cluster copy to the list
111 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
112 iTS->AddCluster(branch,c);
115 //----------------------------------------------------------------------
116 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
118 // Add a raw cluster copy to the list
120 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
121 iTS->AddCluster(branch,c);
123 iTS->AddRecPoint(rp);
125 //______________________________________________________________________
126 void AliITSClusterFinder::FindRawClusters(Int_t module){
127 // Default Cluster finder.
129 // Int_t module Module number for which culster are to be found.
134 const Int_t kelms = 10;
135 Int_t ndigits = fDigits->GetEntriesFast();
136 TObjArray *digs = new TObjArray(ndigits);
137 TObjArray *clusts = new TObjArray(ndigits); // max # cluster
138 TObjArray *clust0=0; // A spacific cluster of digits
139 TObjArray *clust1=0; // A spacific cluster of digits
140 AliITSdigit *dig=0; // locat pointer to a digit
141 Int_t i=0,nc=0,j[4],k,k2=0;
143 // Copy all digits for this module into a local TObjArray.
144 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*((AliITSdigit*)(fDigits->At(i)))),i);
146 // First digit is a cluster.
149 clusts->AddAt(new TObjArray(kelms),nc);
150 clust0 = (TObjArray*)(clusts->At(nc));
151 clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
153 for(i=1;i<ndigits;i++){
154 if(IsNeighbor(digs,i,j)){
155 dig = (AliITSdigit*)(digs->At(j[0]));
156 // Add to existing cluster. Find which cluster this digis
158 clust0 = ((TObjArray*)(clusts->At(k)));
159 if(clust0->IndexOf(dig)>=0) break;
162 Fatal("FindRawClusters","Digit not found as expected");
165 dig = (AliITSdigit*)(digs->At(j[1]));
166 // Add to existing cluster. Find which cluster this digis
167 for(k2=0;k2<nc;k2++){
168 clust1 = ((TObjArray*)(clusts->At(k2)));
169 if(clust1->IndexOf(dig)>=0) break;
172 Fatal("FindRawClusters","Digit not found as expected");
175 // Found cluster with neighboring digits add this one to it.
176 if(clust0==clust1){ // same cluster
177 clust0->AddAtFree(digs->At(i));
178 clust0 = 0; // finished with cluster. zero for safty
179 clust1 = 0; // finished wit hcluster. zero for safty
180 }else{ // two different clusters which need to be merged.
181 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
182 for(k=0;k<clust1->GetEntriesFast();k++){
183 // move clust1 into clust0
184 clust0->AddAtFree(clust1->At(k));//move digit to this cluster
185 clust1->AddAt(0,k); // zero this one
188 clusts->AddAt(0,k2); // zero array of clusters element clust1
189 clust0 = 0; // finished with cluster. zero for safty
190 clust1 = 0; // finished wit hcluster. zero for safty
191 } // end if clust0==clust1
193 clusts->AddAt(new TObjArray(kelms),nc);
194 clust0 = ((TObjArray*)(clusts->At(nc)));
195 clust0->AddAtFree(digs->At(i));// move owner ship from digs to clusts
196 clust0 = 0; // finished with cluster. zero for safty
198 } // End if IsNeighbor
200 // There are now nc clusters in clusts. Each element of clust is an
201 // array of digits which are clustered together.
203 // For each cluster call detector specific CreateRecPoints
204 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
206 // clean up at the end.
208 clust0 =(TObjArray*)(clusts->At(i));
209 // Digits deleted below, so zero this TObjArray
210 for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
211 delete clust0; // Delete this TObjArray
212 clusts->AddAt(0,i); // Contents deleted above, so zero it.
214 delete clusts; // Delete this TObjArray/
215 // Delete the digits then the TObjArray which containted them.
216 for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
219 //______________________________________________________________________
220 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[]){
221 // Locagical function which checks to see if digit i has a neighbor.
222 // If so, then it returns kTRUE and its neighbor index j.
223 // This routine checks if the digits are side by side or one before the
224 // other. Requires that the array of digits be in proper order.
225 // Returns kTRUE in the following cases.
226 // ji 0j if kdiagonal j0 0i
227 // 00 0i if kdiagonal 0i j0
229 // TObjArray *digs Array to search for neighbors in
230 // Int_t i Index of digit for which we are searching for
233 // Int_t j[4] Index of one or more of the digits which is a
234 // neighbor of digit a index i.
236 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
238 const Bool_t kdiagonal=kFALSE;
241 // No neighbors found if array empty.
242 if(digs->GetEntriesFast()<=0) return kFALSE;
243 // can not be a digit with first element or elements out or range
244 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
246 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
247 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
248 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
250 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
251 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
252 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
253 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
254 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
255 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
257 if(nei[0]||nei[1]) return kTRUE;
258 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
259 // no Neighbors found.