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
21 #include "AliITSClusterFinder.h"
22 #include "AliITSdigit.h"
26 ClassImp(AliITSClusterFinder)
28 //----------------------------------------------------------------------
29 AliITSClusterFinder::AliITSClusterFinder(){
30 // default cluster finder
43 //----------------------------------------------------------------------
44 AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg,
45 AliITSresponse *response,
46 TClonesArray *digits){
53 fNdigits = fDigits->GetEntriesFast();
63 //----------------------------------------------------------------------
64 AliITSClusterFinder::~AliITSClusterFinder(){
65 // destructor cluster finder
67 // Zero local pointers. Other classes own these pointers.
79 //__________________________________________________________________________
80 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source){
82 if(&source == this) return;
83 this->fDigits = source.fDigits;
84 this->fNdigits = source.fNdigits;
85 this->fResponse = source.fResponse;
86 this->fSegmentation = source.fSegmentation;
87 this->fNRawClusters = source.fNRawClusters;
88 this->fMap = source.fMap;
89 this->fNperMax = source.fNperMax;
90 this->fDeclusterFlag = source.fDeclusterFlag;
91 this->fClusterSize = source.fClusterSize;
92 this->fNPeaks = source.fNPeaks;
95 //______________________________________________________________________
96 AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder &source) {
97 // Assignment operator
99 if(&source == this) return *this;
100 this->fDigits = source.fDigits;
101 this->fNdigits = source.fNdigits;
102 this->fResponse = source.fResponse;
103 this->fSegmentation = source.fSegmentation;
104 this->fNRawClusters = source.fNRawClusters;
105 this->fMap = source.fMap;
106 this->fNperMax = source.fNperMax;
107 this->fDeclusterFlag = source.fDeclusterFlag;
108 this->fClusterSize = source.fClusterSize;
109 this->fNPeaks = source.fNPeaks;
112 //----------------------------------------------------------------------
113 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
114 // Add a raw cluster copy to the list
116 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
117 iTS->AddCluster(branch,c);
120 //----------------------------------------------------------------------
121 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
123 // Add a raw cluster copy to the list
125 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
126 iTS->AddCluster(branch,c);
128 iTS->AddRecPoint(rp);
130 //______________________________________________________________________
131 void AliITSClusterFinder::FindRawClusters(Int_t module){
132 // Default Cluster finder.
134 // Int_t module Module number for which culster are to be found.
139 const Int_t kelms = 10;
140 Int_t ndigits = fDigits->GetEntriesFast();
141 TObjArray *digs = new TObjArray(ndigits);
142 TObjArray *clusts = new TObjArray(ndigits); // max # cluster
143 TObjArray *clust0=0; // A spacific cluster of digits
144 TObjArray *clust1=0; // A spacific cluster of digits
145 AliITSdigit *dig=0; // locat pointer to a digit
146 Int_t i=0,nc=0,j[4],k,k2=0;
148 // Copy all digits for this module into a local TObjArray.
149 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*((AliITSdigit*)(fDigits->At(i)))),i);
151 // First digit is a cluster.
154 clusts->AddAt(new TObjArray(kelms),nc);
155 clust0 = (TObjArray*)(clusts->At(nc));
156 clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
158 for(i=1;i<ndigits;i++){
159 if(IsNeighbor(digs,i,j)){
160 dig = (AliITSdigit*)(digs->At(j[0]));
161 // Add to existing cluster. Find which cluster this digis
163 clust0 = ((TObjArray*)(clusts->At(k)));
164 if(clust0->IndexOf(dig)>=0) break;
167 Fatal("FindRawClusters","Digit not found as expected");
170 dig = (AliITSdigit*)(digs->At(j[1]));
171 // Add to existing cluster. Find which cluster this digis
172 for(k2=0;k2<nc;k2++){
173 clust1 = ((TObjArray*)(clusts->At(k2)));
174 if(clust1->IndexOf(dig)>=0) break;
177 Fatal("FindRawClusters","Digit not found as expected");
180 // Found cluster with neighboring digits add this one to it.
181 if(clust0==clust1){ // same cluster
182 clust0->AddAtFree(digs->At(i));
183 clust0 = 0; // finished with cluster. zero for safty
184 clust1 = 0; // finished wit hcluster. zero for safty
185 }else{ // two different clusters which need to be merged.
186 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
187 for(k=0;k<clust1->GetEntriesFast();k++){
188 // move clust1 into clust0
189 clust0->AddAtFree(clust1->At(k));//move digit to this cluster
190 clust1->AddAt(0,k); // zero this one
193 clusts->AddAt(0,k2); // zero array of clusters element clust1
194 clust0 = 0; // finished with cluster. zero for safty
195 clust1 = 0; // finished wit hcluster. zero for safty
196 } // end if clust0==clust1
198 clusts->AddAt(new TObjArray(kelms),nc);
199 clust0 = ((TObjArray*)(clusts->At(nc)));
200 clust0->AddAtFree(digs->At(i));// move owner ship from digs to clusts
201 clust0 = 0; // finished with cluster. zero for safty
203 } // End if IsNeighbor
205 // There are now nc clusters in clusts. Each element of clust is an
206 // array of digits which are clustered together.
208 // For each cluster call detector specific CreateRecPoints
209 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
211 // clean up at the end.
213 clust0 =(TObjArray*)(clusts->At(i));
214 // Digits deleted below, so zero this TObjArray
215 for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
216 delete clust0; // Delete this TObjArray
217 clusts->AddAt(0,i); // Contents deleted above, so zero it.
219 delete clusts; // Delete this TObjArray/
220 // Delete the digits then the TObjArray which containted them.
221 for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
224 //______________________________________________________________________
225 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[]) const{
226 // Locagical function which checks to see if digit i has a neighbor.
227 // If so, then it returns kTRUE and its neighbor index j.
228 // This routine checks if the digits are side by side or one before the
229 // other. Requires that the array of digits be in proper order.
230 // Returns kTRUE in the following cases.
231 // ji 0j if kdiagonal j0 0i
232 // 00 0i if kdiagonal 0i j0
234 // TObjArray *digs Array to search for neighbors in
235 // Int_t i Index of digit for which we are searching for
238 // Int_t j[4] Index of one or more of the digits which is a
239 // neighbor of digit a index i.
241 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
243 const Bool_t kdiagonal=kFALSE;
246 // No neighbors found if array empty.
247 if(digs->GetEntriesFast()<=0) return kFALSE;
248 // can not be a digit with first element or elements out or range
249 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
251 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
252 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
253 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
255 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
256 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
257 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
258 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
259 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
260 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
262 if(nei[0]||nei[1]) return kTRUE;
263 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
264 // no Neighbors found.