]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSClusterFinder.cxx
Bug in geometry corrected
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinder.cxx
CommitLineData
b0f5e3fc 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
bf3f2830 15//
16// Base Class used to find
17// the reconstructed points for ITS
18// See also AliITSClusterFinderSPD, AliITSClusterFinderSDD,
19// AliITSClusterFinderSDD
20//
b0f5e3fc 21#include "AliITSClusterFinder.h"
f8d9a5b8 22#include "AliITSdigit.h"
b0f5e3fc 23#include "AliRun.h"
e8189707 24#include "AliITS.h"
b0f5e3fc 25
b0f5e3fc 26ClassImp(AliITSClusterFinder)
27
9de0700b 28//----------------------------------------------------------------------
29AliITSClusterFinder::AliITSClusterFinder(){
30 // default cluster finder
31
32 fSegmentation = 0;
33 fResponse = 0;
34 fMap = 0;
35 fDigits = 0;
36 fNdigits = 0;
37 fNRawClusters = 0;
38 fNperMax = 0;
39 fDeclusterFlag= 0;
40 fClusterSize = 0;
41 fNPeaks = 0;
42}
43//----------------------------------------------------------------------
44AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg,
45 AliITSresponse *response,
46 TClonesArray *digits){
b0f5e3fc 47 // cluster finder
48 fSegmentation=seg;
49 fResponse=response;
50 fMap = 0;
51
52 fDigits=digits;
53 fNdigits = fDigits->GetEntriesFast();
54
55 fNRawClusters=0;
56
57 SetNperMax();
58 SetClusterSize();
59 SetDeclusterFlag();
60
61 fNPeaks=-1;
62}
9de0700b 63//----------------------------------------------------------------------
64AliITSClusterFinder::~AliITSClusterFinder(){
65 // destructor cluster finder
b0f5e3fc 66
9de0700b 67 // Zero local pointers. Other classes own these pointers.
55cd883f 68 fSegmentation = 0;
9de0700b 69 fResponse = 0;
70 fMap = 0;
71 fDigits = 0;
72 fNdigits = 0;
73 fNRawClusters = 0;
74 fNperMax = 0;
75 fDeclusterFlag= 0;
76 fClusterSize = 0;
77 fNPeaks = 0;
b0f5e3fc 78}
b0f5e3fc 79//__________________________________________________________________________
80AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source){
9de0700b 81 // Copy Constructor
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;
93 return;
b0f5e3fc 94}
9de0700b 95//______________________________________________________________________
96AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder &source) {
97 // Assignment operator
98
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;
110 return *this;
b0f5e3fc 111}
9de0700b 112//----------------------------------------------------------------------
113void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
114 // Add a raw cluster copy to the list
b0f5e3fc 115
b0f5e3fc 116 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
117 iTS->AddCluster(branch,c);
118 fNRawClusters++;
9355b256 119}
9de0700b 120//----------------------------------------------------------------------
121void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
122 AliITSRecPoint &rp){
123 // Add a raw cluster copy to the list
9355b256 124
9355b256 125 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
126 iTS->AddCluster(branch,c);
127 fNRawClusters++;
128 iTS->AddRecPoint(rp);
b0f5e3fc 129}
f8d9a5b8 130//______________________________________________________________________
131void AliITSClusterFinder::FindRawClusters(Int_t module){
132 // Default Cluster finder.
133 // Input:
134 // Int_t module Module number for which culster are to be found.
135 // Output:
136 // none.
137 // Return:
138 // none.
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
f824982a 146 Int_t i=0,nc=0,j[4],k,k2=0;
f8d9a5b8 147
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);
150 digs->Sort();
151 // First digit is a cluster.
152 i = 0;
153 nc = 0;
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
157 nc++;
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
162 for(k=0;k<nc;k++){
163 clust0 = ((TObjArray*)(clusts->At(k)));
164 if(clust0->IndexOf(dig)>=0) break;
165 } // end for k
166 if(k>=nc){
08d213d6 167 Fatal("FindRawClusters","Digit not found as expected");
f8d9a5b8 168 } // end if
169 if(j[1]>=0){
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;
175 } // end for k2
176 if(k2>=nc){
08d213d6 177 Fatal("FindRawClusters","Digit not found as expected");
f8d9a5b8 178 } // end if
179 } // end if j[1]>=0
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
191 } // end for k
192 delete clust1;
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
197 }else{// New cluster
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
202 nc++;
203 } // End if IsNeighbor
204 } // end for i
205 // There are now nc clusters in clusts. Each element of clust is an
206 // array of digits which are clustered together.
207
208 // For each cluster call detector specific CreateRecPoints
209 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
210
211 // clean up at the end.
212 for(i=0;i<nc;i++){
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.
218 } // end for i
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)));
222 delete digs;
223}
224//______________________________________________________________________
bf3f2830 225Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[]) const{
f8d9a5b8 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
233 // Inputs:
234 // TObjArray *digs Array to search for neighbors in
235 // Int_t i Index of digit for which we are searching for
236 // a neighbor of.
237 // Output:
238 // Int_t j[4] Index of one or more of the digits which is a
239 // neighbor of digit a index i.
240 // Return:
241 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
242 Int_t ix,jx,iz,jz,j;
243 const Bool_t kdiagonal=kFALSE;
244 Bool_t nei[4];
245
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;
250
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();
254 for(j=0;j<i;j++){
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;}
261 } // end for k
262 if(nei[0]||nei[1]) return kTRUE;
263 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
264 // no Neighbors found.
265 return kFALSE;
266}