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"
26 #include "AliITSMap.h"
30 ClassImp(AliITSClusterFinder)
32 //----------------------------------------------------------------------
33 AliITSClusterFinder::AliITSClusterFinder():
48 // default cluster finder
54 // A default constructed AliITSCulsterFinder
56 //----------------------------------------------------------------------
57 AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg,
73 // Standard constructor for cluster finder
75 // AliITSsegmentation *seg The segmentation class to be used
76 // AliITSresponse *res The response class to be used
80 // A Standard constructed AliITSCulsterFinder
86 //----------------------------------------------------------------------
87 AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg,
88 AliITSresponse *response,
89 TClonesArray *digits):
104 // Standard + cluster finder constructor
106 // AliITSsegmentation *seg The segmentation class to be used
107 // AliITSresponse *res The response class to be used
108 // TClonesArray *digits Array of digits to be used
112 // A Standard constructed AliITSCulsterFinder
114 fNdigits = fDigits->GetEntriesFast();
119 //----------------------------------------------------------------------
120 AliITSClusterFinder::~AliITSClusterFinder(){
121 // destructor cluster finder
129 if(fMap) {delete fMap;}
130 // Zero local pointers. Other classes own these pointers.
142 //__________________________________________________________________________
143 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) :
147 // AliITSClusterFinder &source The class which will become a copy of
152 // A copy of this class
154 if(&source == this) return;
158 //______________________________________________________________________
159 AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder
161 // Assignment operator
163 // AliITSClusterFinder &source The class which will become a copy of
168 // A copy of this class
170 if(&source == this) return *this;
171 this->fDigits = source.fDigits;
172 this->fNdigits = source.fNdigits;
173 this->fResponse = source.fResponse;
174 this->fSegmentation = source.fSegmentation;
175 this->fNRawClusters = source.fNRawClusters;
176 this->fMap = source.fMap;
177 this->fNperMax = source.fNperMax;
178 this->fDeclusterFlag = source.fDeclusterFlag;
179 this->fClusterSize = source.fClusterSize;
180 this->fNPeaks = source.fNPeaks;
183 //----------------------------------------------------------------------
184 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
185 // Add a raw cluster copy to the list
187 // Int_t branch The branch to which the cluster is to be added to
188 // AliITSRawCluster *c The cluster to be added to the array of clusters
194 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
195 iTS->AddCluster(branch,c);
198 //----------------------------------------------------------------------
199 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
201 // Add a raw cluster copy to the list and the RecPoint
203 // Int_t branch The branch to which the cluster is to be added to
204 // AliITSRawCluster *c The cluster to be added to the array of clusters
205 // AliITSRecPoint &rp The RecPoint to be added to the array of RecPoints
211 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
212 iTS->AddCluster(branch,c);
214 iTS->AddRecPoint(rp);
216 //______________________________________________________________________
217 void AliITSClusterFinder::FindRawClusters(Int_t module){
218 // Default Cluster finder.
220 // Int_t module Module number for which culster are to be found.
225 const Int_t kelms = 10;
226 Int_t ndigits = fDigits->GetEntriesFast();
227 TObjArray *digs = new TObjArray(ndigits);
228 TObjArray *clusts = new TObjArray(ndigits); // max # cluster
229 TObjArray *clust0=0; // A spacific cluster of digits
230 TObjArray *clust1=0; // A spacific cluster of digits
231 AliITSdigit *dig=0; // locat pointer to a digit
232 Int_t i=0,nc=0,j[4],k,k2=0;
234 // Copy all digits for this module into a local TObjArray.
235 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*(GetDigit(i))),i);
237 // First digit is a cluster.
240 clusts->AddAt(new TObjArray(kelms),nc);
241 clust0 = (TObjArray*)(clusts->At(nc));
242 clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
244 for(i=1;i<ndigits;i++){
245 if(IsNeighbor(digs,i,j)){
246 dig = (AliITSdigit*)(digs->At(j[0]));
247 // Add to existing cluster. Find which cluster this digis
249 clust0 = ((TObjArray*)(clusts->At(k)));
250 if(clust0->IndexOf(dig)>=0) break;
253 Fatal("FindRawClusters","Digit not found as expected");
256 dig = (AliITSdigit*)(digs->At(j[1]));
257 // Add to existing cluster. Find which cluster this digis
258 for(k2=0;k2<nc;k2++){
259 clust1 = ((TObjArray*)(clusts->At(k2)));
260 if(clust1->IndexOf(dig)>=0) break;
263 Fatal("FindRawClusters","Digit not found as expected");
266 // Found cluster with neighboring digits add this one to it.
267 if(clust0==clust1){ // same cluster
268 clust0->AddAtFree(digs->At(i));
269 clust0 = 0; // finished with cluster. zero for safty
270 clust1 = 0; // finished wit hcluster. zero for safty
271 }else{ // two different clusters which need to be merged.
272 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
273 for(k=0;k<clust1->GetEntriesFast();k++){
274 // move clust1 into clust0
275 //move digit to this cluster
276 clust0->AddAtFree(clust1->At(k));
277 clust1->AddAt(0,k); // zero this one
280 clusts->AddAt(0,k2); // zero array of clusters element clust1
281 clust0 = 0; // finished with cluster. zero for safty
282 clust1 = 0; // finished wit hcluster. zero for safty
283 } // end if clust0==clust1
285 clusts->AddAt(new TObjArray(kelms),nc);
286 clust0 = ((TObjArray*)(clusts->At(nc)));
287 // move owner ship from digs to clusts
288 clust0->AddAtFree(digs->At(i));
289 clust0 = 0; // finished with cluster. zero for safty
291 } // End if IsNeighbor
293 // There are now nc clusters in clusts. Each element of clust is an
294 // array of digits which are clustered together.
296 // For each cluster call detector specific CreateRecPoints
297 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
299 // clean up at the end.
301 clust0 =(TObjArray*)(clusts->At(i));
302 // Digits deleted below, so zero this TObjArray
303 for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
304 delete clust0; // Delete this TObjArray
305 clusts->AddAt(0,i); // Contents deleted above, so zero it.
307 delete clusts; // Delete this TObjArray/
308 // Delete the digits then the TObjArray which containted them.
309 for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
312 //______________________________________________________________________
313 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[])const{
314 // Locagical function which checks to see if digit i has a neighbor.
315 // If so, then it returns kTRUE and its neighbor index j.
316 // This routine checks if the digits are side by side or one before the
317 // other. Requires that the array of digits be in proper order.
318 // Returns kTRUE in the following cases.
319 // ji 0j if kdiagonal j0 0i
320 // 00 0i if kdiagonal 0i j0
322 // TObjArray *digs Array to search for neighbors in
323 // Int_t i Index of digit for which we are searching for
326 // Int_t j[4] Index of one or more of the digits which is a
327 // neighbor of digit a index i.
329 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
331 const Bool_t kdiagonal=kFALSE;
334 // No neighbors found if array empty.
335 if(digs->GetEntriesFast()<=0) return kFALSE;
336 // can not be a digit with first element or elements out or range
337 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
339 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
340 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
341 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
343 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
344 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
345 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
346 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
347 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
348 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
350 if(nei[0]||nei[1]) return kTRUE;
351 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
352 // no Neighbors found.
356 //______________________________________________________________________
357 void AliITSClusterFinder::Print(ostream *os){
358 //Standard output format for this class
360 // ostream *os Output stream
362 // ostream *os Output stream
368 *os << fNdigits<<",";
369 *os << fNRawClusters<<",";
370 *os << fNperMax<<",";
371 *os << fDeclusterFlag<<",";
372 *os << fClusterSize<<",";
373 *os << fNPeaks<<endl;
375 //______________________________________________________________________
376 void AliITSClusterFinder::Read(istream *is){
377 //Standard input for this class
379 // istream *is Input stream
381 // istream *is Input stream
388 *is >> fNRawClusters;
390 *is >> fDeclusterFlag;
394 //______________________________________________________________________
395 ostream &operator<<(ostream &os,AliITSClusterFinder &source){
396 // Standard output streaming function.
398 // ostream *os Output stream
399 // AliITSClusterFinder &source Class to be printed
401 // ostream *os Output stream
408 //______________________________________________________________________
409 istream &operator>>(istream &is,AliITSClusterFinder &source){
410 // Standard output streaming function.
412 // istream *is Input stream
413 // AliITSClusterFinder &source Class to be read in.
415 // istream *is Input stream