]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSClusterFinder.cxx
Radiator to Pad goes static.
[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//
88cb7938 21
b0f5e3fc 22#include "AliITSClusterFinder.h"
f8d9a5b8 23#include "AliITSdigit.h"
b0f5e3fc 24#include "AliRun.h"
e8189707 25#include "AliITS.h"
b0f5e3fc 26
b0f5e3fc 27ClassImp(AliITSClusterFinder)
28
9de0700b 29//----------------------------------------------------------------------
30AliITSClusterFinder::AliITSClusterFinder(){
31 // default cluster finder
32
33 fSegmentation = 0;
34 fResponse = 0;
35 fMap = 0;
36 fDigits = 0;
37 fNdigits = 0;
38 fNRawClusters = 0;
39 fNperMax = 0;
40 fDeclusterFlag= 0;
41 fClusterSize = 0;
42 fNPeaks = 0;
43}
44//----------------------------------------------------------------------
45AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg,
46 AliITSresponse *response,
47 TClonesArray *digits){
b0f5e3fc 48 // cluster finder
49 fSegmentation=seg;
50 fResponse=response;
51 fMap = 0;
52
53 fDigits=digits;
54 fNdigits = fDigits->GetEntriesFast();
55
56 fNRawClusters=0;
57
58 SetNperMax();
59 SetClusterSize();
60 SetDeclusterFlag();
61
62 fNPeaks=-1;
63}
9de0700b 64//----------------------------------------------------------------------
65AliITSClusterFinder::~AliITSClusterFinder(){
66 // destructor cluster finder
b0f5e3fc 67
9de0700b 68 // Zero local pointers. Other classes own these pointers.
55cd883f 69 fSegmentation = 0;
9de0700b 70 fResponse = 0;
71 fMap = 0;
72 fDigits = 0;
73 fNdigits = 0;
74 fNRawClusters = 0;
75 fNperMax = 0;
76 fDeclusterFlag= 0;
77 fClusterSize = 0;
78 fNPeaks = 0;
b0f5e3fc 79}
b0f5e3fc 80//__________________________________________________________________________
ac74f489 81AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) :
82 TObject(source){
9de0700b 83 // Copy Constructor
84 if(&source == this) return;
85 this->fDigits = source.fDigits;
86 this->fNdigits = source.fNdigits;
87 this->fResponse = source.fResponse;
88 this->fSegmentation = source.fSegmentation;
89 this->fNRawClusters = source.fNRawClusters;
90 this->fMap = source.fMap;
91 this->fNperMax = source.fNperMax;
92 this->fDeclusterFlag = source.fDeclusterFlag;
93 this->fClusterSize = source.fClusterSize;
94 this->fNPeaks = source.fNPeaks;
95 return;
b0f5e3fc 96}
9de0700b 97//______________________________________________________________________
98AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder &source) {
99 // Assignment operator
100
101 if(&source == this) return *this;
102 this->fDigits = source.fDigits;
103 this->fNdigits = source.fNdigits;
104 this->fResponse = source.fResponse;
105 this->fSegmentation = source.fSegmentation;
106 this->fNRawClusters = source.fNRawClusters;
107 this->fMap = source.fMap;
108 this->fNperMax = source.fNperMax;
109 this->fDeclusterFlag = source.fDeclusterFlag;
110 this->fClusterSize = source.fClusterSize;
111 this->fNPeaks = source.fNPeaks;
112 return *this;
b0f5e3fc 113}
9de0700b 114//----------------------------------------------------------------------
115void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
116 // Add a raw cluster copy to the list
b0f5e3fc 117
b0f5e3fc 118 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
119 iTS->AddCluster(branch,c);
120 fNRawClusters++;
9355b256 121}
9de0700b 122//----------------------------------------------------------------------
123void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
124 AliITSRecPoint &rp){
125 // Add a raw cluster copy to the list
9355b256 126
9355b256 127 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
128 iTS->AddCluster(branch,c);
129 fNRawClusters++;
130 iTS->AddRecPoint(rp);
b0f5e3fc 131}
f8d9a5b8 132//______________________________________________________________________
133void AliITSClusterFinder::FindRawClusters(Int_t module){
134 // Default Cluster finder.
135 // Input:
136 // Int_t module Module number for which culster are to be found.
137 // Output:
138 // none.
139 // Return:
140 // none.
141 const Int_t kelms = 10;
142 Int_t ndigits = fDigits->GetEntriesFast();
143 TObjArray *digs = new TObjArray(ndigits);
144 TObjArray *clusts = new TObjArray(ndigits); // max # cluster
145 TObjArray *clust0=0; // A spacific cluster of digits
146 TObjArray *clust1=0; // A spacific cluster of digits
147 AliITSdigit *dig=0; // locat pointer to a digit
f824982a 148 Int_t i=0,nc=0,j[4],k,k2=0;
f8d9a5b8 149
150 // Copy all digits for this module into a local TObjArray.
151 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*((AliITSdigit*)(fDigits->At(i)))),i);
152 digs->Sort();
153 // First digit is a cluster.
154 i = 0;
155 nc = 0;
156 clusts->AddAt(new TObjArray(kelms),nc);
157 clust0 = (TObjArray*)(clusts->At(nc));
158 clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
159 nc++;
160 for(i=1;i<ndigits;i++){
161 if(IsNeighbor(digs,i,j)){
162 dig = (AliITSdigit*)(digs->At(j[0]));
163 // Add to existing cluster. Find which cluster this digis
164 for(k=0;k<nc;k++){
165 clust0 = ((TObjArray*)(clusts->At(k)));
166 if(clust0->IndexOf(dig)>=0) break;
167 } // end for k
168 if(k>=nc){
08d213d6 169 Fatal("FindRawClusters","Digit not found as expected");
f8d9a5b8 170 } // end if
171 if(j[1]>=0){
172 dig = (AliITSdigit*)(digs->At(j[1]));
173 // Add to existing cluster. Find which cluster this digis
174 for(k2=0;k2<nc;k2++){
175 clust1 = ((TObjArray*)(clusts->At(k2)));
176 if(clust1->IndexOf(dig)>=0) break;
177 } // end for k2
178 if(k2>=nc){
08d213d6 179 Fatal("FindRawClusters","Digit not found as expected");
f8d9a5b8 180 } // end if
181 } // end if j[1]>=0
182 // Found cluster with neighboring digits add this one to it.
183 if(clust0==clust1){ // same cluster
184 clust0->AddAtFree(digs->At(i));
185 clust0 = 0; // finished with cluster. zero for safty
186 clust1 = 0; // finished wit hcluster. zero for safty
187 }else{ // two different clusters which need to be merged.
188 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
189 for(k=0;k<clust1->GetEntriesFast();k++){
190 // move clust1 into clust0
191 clust0->AddAtFree(clust1->At(k));//move digit to this cluster
192 clust1->AddAt(0,k); // zero this one
193 } // end for k
194 delete clust1;
195 clusts->AddAt(0,k2); // zero array of clusters element clust1
196 clust0 = 0; // finished with cluster. zero for safty
197 clust1 = 0; // finished wit hcluster. zero for safty
198 } // end if clust0==clust1
199 }else{// New cluster
200 clusts->AddAt(new TObjArray(kelms),nc);
201 clust0 = ((TObjArray*)(clusts->At(nc)));
202 clust0->AddAtFree(digs->At(i));// move owner ship from digs to clusts
203 clust0 = 0; // finished with cluster. zero for safty
204 nc++;
205 } // End if IsNeighbor
206 } // end for i
207 // There are now nc clusters in clusts. Each element of clust is an
208 // array of digits which are clustered together.
209
210 // For each cluster call detector specific CreateRecPoints
211 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
212
213 // clean up at the end.
214 for(i=0;i<nc;i++){
215 clust0 =(TObjArray*)(clusts->At(i));
216 // Digits deleted below, so zero this TObjArray
217 for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
218 delete clust0; // Delete this TObjArray
219 clusts->AddAt(0,i); // Contents deleted above, so zero it.
220 } // end for i
221 delete clusts; // Delete this TObjArray/
222 // Delete the digits then the TObjArray which containted them.
223 for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
224 delete digs;
225}
226//______________________________________________________________________
bf3f2830 227Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[]) const{
f8d9a5b8 228 // Locagical function which checks to see if digit i has a neighbor.
229 // If so, then it returns kTRUE and its neighbor index j.
230 // This routine checks if the digits are side by side or one before the
231 // other. Requires that the array of digits be in proper order.
232 // Returns kTRUE in the following cases.
233 // ji 0j if kdiagonal j0 0i
234 // 00 0i if kdiagonal 0i j0
235 // Inputs:
236 // TObjArray *digs Array to search for neighbors in
237 // Int_t i Index of digit for which we are searching for
238 // a neighbor of.
239 // Output:
240 // Int_t j[4] Index of one or more of the digits which is a
241 // neighbor of digit a index i.
242 // Return:
243 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
244 Int_t ix,jx,iz,jz,j;
245 const Bool_t kdiagonal=kFALSE;
246 Bool_t nei[4];
247
248 // No neighbors found if array empty.
249 if(digs->GetEntriesFast()<=0) return kFALSE;
250 // can not be a digit with first element or elements out or range
251 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
252
253 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
254 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
255 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
256 for(j=0;j<i;j++){
257 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
258 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
259 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
260 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
261 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
262 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
263 } // end for k
264 if(nei[0]||nei[1]) return kTRUE;
265 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
266 // no Neighbors found.
267 return kFALSE;
268}