]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSClusterFinder.cxx
Modifications associated with remerging the Ba/Sa and Dubna pixel simulations,
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinder.cxx
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  **************************************************************************/
15 //
16 // Base Class used to find
17 // the reconstructed points for ITS
18 // See also AliITSClusterFinderSPD, AliITSClusterFinderSDD, 
19 // AliITSClusterFinderSDD
20 //
21
22 #include "AliITSClusterFinder.h"
23 #include "AliITSdigitSPD.h"
24 #include "AliITSdigitSDD.h"
25 #include "AliITSdigitSSD.h"
26 #include "AliITSMap.h"
27 #include "AliRun.h"
28 #include "AliITS.h"
29
30 ClassImp(AliITSClusterFinder)
31
32 //----------------------------------------------------------------------
33 AliITSClusterFinder::AliITSClusterFinder():
34 TObject(),
35 fDebug(0),
36 fModule(0),
37 fDigits(0),
38 fNdigits(0),
39 fResponse(0),
40 fSegmentation(0),
41 fClusters(0),
42 fNRawClusters(0),
43 fMap(0),
44 fNperMax(0),
45 fDeclusterFlag(0),
46 fClusterSize(0),
47 fNPeaks(-1){
48     // default cluster finder
49     // Input:
50     //   none.
51     // Output:
52     //   none.
53     // Return:
54     //   A default constructed AliITSCulsterFinder
55 }
56 //----------------------------------------------------------------------
57 AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg, 
58                                          AliITSresponse *res):
59 TObject(),
60 fDebug(0),
61 fModule(0),
62 fDigits(0),
63 fNdigits(0),
64 fResponse(res),
65 fSegmentation(seg),
66 fClusters(0),
67 fNRawClusters(0),
68 fMap(0),
69 fNperMax(0),
70 fDeclusterFlag(0),
71 fClusterSize(0),
72 fNPeaks(-1){
73     // Standard constructor for cluster finder
74     // Input:
75     //   AliITSsegmentation *seg  The segmentation class to be used
76     //   AliITSresponse     *res  The response class to be used
77     // Output:
78     //   none.
79     // Return:
80     //   A Standard constructed AliITSCulsterFinder
81
82     SetNperMax();
83     SetClusterSize();
84     SetDeclusterFlag();
85 }
86 //----------------------------------------------------------------------
87 AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg, 
88                                          AliITSresponse *response, 
89                                          TClonesArray *digits):
90 TObject(),
91 fDebug(0),
92 fModule(0),
93 fDigits(digits),
94 fNdigits(0),
95 fResponse(response),
96 fSegmentation(seg),
97 fClusters(0),
98 fNRawClusters(0),
99 fMap(0),
100 fNperMax(0),
101 fDeclusterFlag(0),
102 fClusterSize(0),
103 fNPeaks(-1){
104     // Standard + cluster finder constructor
105     // Input:
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
109     // Output:
110     //   none.
111     // Return:
112     //   A Standard constructed AliITSCulsterFinder
113
114     fNdigits = fDigits->GetEntriesFast();
115     SetNperMax();
116     SetClusterSize();
117     SetDeclusterFlag();
118 }
119 //----------------------------------------------------------------------
120 AliITSClusterFinder::~AliITSClusterFinder(){
121     // destructor cluster finder
122     // Input:
123     //   none.
124     // Output:
125     //   none.
126     // Return:
127     //   none.
128
129     if(fMap) {delete fMap;}
130     // Zero local pointers. Other classes own these pointers.
131     fSegmentation = 0;
132     fResponse     = 0;
133     fMap          = 0;
134     fDigits       = 0;
135     fNdigits      = 0;
136     fNRawClusters = 0;
137     fNperMax      = 0;
138     fDeclusterFlag= 0;
139     fClusterSize  = 0;
140     fNPeaks       = 0;
141 }
142 //__________________________________________________________________________
143 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) :
144     TObject(source){
145     //     Copy Constructor
146     // Input:
147     //   AliITSClusterFinder &source  The class which will become a copy of 
148     //                                this class
149     // Output:
150     //   none.
151     // Return:
152     //   A copy of this class
153
154     if(&source == this) return;
155     *this = source;
156     return;
157 }
158 //______________________________________________________________________
159 AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder 
160                                                     &source) {
161     //    Assignment operator
162     // Input:
163     //   AliITSClusterFinder &source  The class which will become a copy of 
164     //                                this class
165     // Output:
166     //   none.
167     // Return:
168     //   A copy of this class
169
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;
181     return *this;
182 }
183 //----------------------------------------------------------------------
184 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
185     // Add a raw cluster copy to the list
186     // Input:
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
189     // Output:
190     //   none.
191     // Return:
192     //   none.
193
194     AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
195     iTS->AddCluster(branch,c); 
196     fNRawClusters++;
197 }
198 //----------------------------------------------------------------------
199 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c, 
200                                      AliITSRecPoint &rp){
201     // Add a raw cluster copy to the list and the RecPoint
202     // Input:
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
206     // Output:
207     //   none.
208     // Return:
209     //   none.
210
211     AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
212     iTS->AddCluster(branch,c); 
213     fNRawClusters++;
214     iTS->AddRecPoint(rp); 
215 }
216 //______________________________________________________________________
217 void AliITSClusterFinder::FindRawClusters(Int_t module){
218     // Default Cluster finder.
219     // Input:
220     //   Int_t module   Module number for which culster are to be found.
221     // Output:
222     //   none.
223     // Return:
224     //   none.
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;
233
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);
236     digs->Sort();
237     // First digit is a cluster.
238     i  = 0;
239     nc = 0;
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
243     nc++;
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 
248             for(k=0;k<nc;k++){
249                 clust0 = ((TObjArray*)(clusts->At(k)));
250                 if(clust0->IndexOf(dig)>=0) break;
251             } // end for k
252             if(k>=nc){
253                 Fatal("FindRawClusters","Digit not found as expected");
254             } // end if
255             if(j[1]>=0){
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;
261                 } // end for k2
262                 if(k2>=nc){
263                     Fatal("FindRawClusters","Digit not found as expected");
264                 } // end if
265             } // end if j[1]>=0
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
278                 } // end for k
279                 delete clust1;
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
284         }else{// New cluster
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
290             nc++;
291         } // End if IsNeighbor
292     } // end for i
293     // There are now nc clusters in clusts. Each element of clust is an
294     // array of digits which are clustered together.
295
296     // For each cluster call detector specific CreateRecPoints
297     for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
298
299     // clean up at the end.
300     for(i=0;i<nc;i++){ 
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.
306     } // end for i
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)));
310     delete digs;
311 }
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
321     // Inputs:
322     //    TObjArray *digs   Array to search for neighbors in
323     //    Int_t      i      Index of digit for which we are searching for
324     //                      a neighbor of.
325     // Output:
326     //    Int_t      j[4]   Index of one or more of the digits which is a
327     //                      neighbor of digit a index i.
328     // Return:
329     //    Bool_t            kTRUE if a neighbor was found kFALSE otherwise.
330     Int_t ix,jx,iz,jz,j;
331     const Bool_t kdiagonal=kFALSE;
332     Bool_t nei[4];
333
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;
338
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();
342     for(j=0;j<i;j++){
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;}
349     } // end for k
350     if(nei[0]||nei[1]) return kTRUE;
351     if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
352     // no Neighbors found.
353     return kFALSE;
354 }
355
356 //______________________________________________________________________
357 void AliITSClusterFinder::Print(ostream *os){
358     //Standard output format for this class
359     // Inputs:
360     //    ostream *os   Output stream
361     // Output:
362     //    ostream *os   Output stream
363     // Return:
364     //    none.
365
366     *os << fDebug<<",";
367     *os << fModule<<",";
368     *os << fNdigits<<",";
369     *os << fNRawClusters<<",";
370     *os << fNperMax<<",";
371     *os << fDeclusterFlag<<",";
372     *os << fClusterSize<<",";
373     *os << fNPeaks<<endl;
374 }
375 //______________________________________________________________________
376 void AliITSClusterFinder::Read(istream *is){
377     //Standard input for this class
378     // Inputs:
379     //    istream *is   Input stream
380     // Output:
381     //    istream *is   Input stream
382     // Return:
383     //    none.
384
385     *is >> fDebug;
386     *is >> fModule;
387     *is >> fNdigits;
388     *is >> fNRawClusters;
389     *is >> fNperMax;
390     *is >> fDeclusterFlag;
391     *is >> fClusterSize;
392     *is >> fNPeaks;
393 }
394 //______________________________________________________________________
395 ostream &operator<<(ostream &os,AliITSClusterFinder &source){
396     // Standard output streaming function.
397     // Inputs:
398     //    ostream             *os     Output stream
399     //    AliITSClusterFinder &source Class to be printed
400     // Output:
401     //    ostream             *os     Output stream
402     // Return:
403     //    none.
404
405     source.Print(&os);
406     return os;
407 }
408 //______________________________________________________________________
409 istream &operator>>(istream &is,AliITSClusterFinder &source){
410     // Standard output streaming function.
411     // Inputs:
412     //    istream              *is      Input stream
413     //     AliITSClusterFinder &source  Class to be read in.
414     // Output:
415     //    istream              *is      Input stream
416     // Return:
417     //    none.
418
419     source.Read(&is);
420     return is;
421 }