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 "AliITSdigitSPD.h"
24 #include "AliITSdigitSDD.h"
25 #include "AliITSdigitSSD.h"
29 ClassImp(AliITSClusterFinder)
31 //----------------------------------------------------------------------
32 AliITSClusterFinder::AliITSClusterFinder(){
33 // default cluster finder
46 //----------------------------------------------------------------------
47 AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg,
48 AliITSresponse *response,
49 TClonesArray *digits){
56 fNdigits = fDigits->GetEntriesFast();
66 //----------------------------------------------------------------------
67 AliITSClusterFinder::~AliITSClusterFinder(){
68 // destructor cluster finder
70 // Zero local pointers. Other classes own these pointers.
82 //__________________________________________________________________________
83 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) :
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;
99 //______________________________________________________________________
100 AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder &source) {
101 // Assignment operator
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;
116 //----------------------------------------------------------------------
117 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);
124 //----------------------------------------------------------------------
125 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
127 // Add a raw cluster copy to the list
129 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
130 iTS->AddCluster(branch,c);
132 iTS->AddRecPoint(rp);
134 //______________________________________________________________________
135 void AliITSClusterFinder::FindRawClusters(Int_t module){
136 // Default Cluster finder.
138 // Int_t module Module number for which culster are to be found.
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;
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);
155 // First digit is a cluster.
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
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
167 clust0 = ((TObjArray*)(clusts->At(k)));
168 if(clust0->IndexOf(dig)>=0) break;
171 Fatal("FindRawClusters","Digit not found as expected");
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;
181 Fatal("FindRawClusters","Digit not found as expected");
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
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
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
207 } // End if IsNeighbor
209 // There are now nc clusters in clusts. Each element of clust is an
210 // array of digits which are clustered together.
212 // For each cluster call detector specific CreateRecPoints
213 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
215 // clean up at the end.
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.
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)));
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
238 // TObjArray *digs Array to search for neighbors in
239 // Int_t i Index of digit for which we are searching for
242 // Int_t j[4] Index of one or more of the digits which is a
243 // neighbor of digit a index i.
245 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
247 const Bool_t kdiagonal=kFALSE;
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;
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();
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;}
266 if(nei[0]||nei[1]) return kTRUE;
267 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
268 // no Neighbors found.