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){
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;
96 //______________________________________________________________________
97 AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder &source) {
98 // Assignment operator
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;
113 //----------------------------------------------------------------------
114 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
115 // Add a raw cluster copy to the list
117 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
118 iTS->AddCluster(branch,c);
121 //----------------------------------------------------------------------
122 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
124 // Add a raw cluster copy to the list
126 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
127 iTS->AddCluster(branch,c);
129 iTS->AddRecPoint(rp);
131 //______________________________________________________________________
132 void AliITSClusterFinder::FindRawClusters(Int_t module){
133 // Default Cluster finder.
135 // Int_t module Module number for which culster are to be found.
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;
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);
152 // First digit is a cluster.
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
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
164 clust0 = ((TObjArray*)(clusts->At(k)));
165 if(clust0->IndexOf(dig)>=0) break;
168 Fatal("FindRawClusters","Digit not found as expected");
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;
178 Fatal("FindRawClusters","Digit not found as expected");
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
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
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
204 } // End if IsNeighbor
206 // There are now nc clusters in clusts. Each element of clust is an
207 // array of digits which are clustered together.
209 // For each cluster call detector specific CreateRecPoints
210 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
212 // clean up at the end.
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.
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)));
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
235 // TObjArray *digs Array to search for neighbors in
236 // Int_t i Index of digit for which we are searching for
239 // Int_t j[4] Index of one or more of the digits which is a
240 // neighbor of digit a index i.
242 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
244 const Bool_t kdiagonal=kFALSE;
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;
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();
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;}
263 if(nei[0]||nei[1]) return kTRUE;
264 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
265 // no Neighbors found.