]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSClusterFinder.cxx
New hybrid geometry using both new code and old parts. Improved SDD geometry (L....
[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 //                                                                        //
17 // Base Class used to find                                                //
18 // the reconstructed points for ITS                                       //
19 // See also AliITSClusterFinderSPD, AliITSClusterFinderSDD,               //
20 // AliITSClusterFinderSDD  AliITSClusterFinderV2                          //
21 ////////////////////////////////////////////////////////////////////////////
22
23 #include "AliITSClusterFinder.h"
24 #include "AliITSRecPoint.h"
25 #include "AliITSdigit.h"
26 #include "AliITSDetTypeRec.h"
27 #include "AliITSMap.h"
28 #include "AliITSgeomTGeo.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 fDetTypeRec(0),
40 fClusters(0),
41 fNRawClusters(0),
42 fMap(0),
43 fNperMax(0),
44 fDeclusterFlag(0),
45 fClusterSize(0),
46 fNPeaks(-1){
47     // default cluster finder
48     // Input:
49     //   none.
50     // Output:
51     //   none.
52     // Return:
53     //   A default constructed AliITSCulsterFinder
54 }
55 //----------------------------------------------------------------------
56 AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp):
57 TObject(),
58 fDebug(0),
59 fModule(0),
60 fDigits(0),
61 fNdigits(0),
62 fDetTypeRec(dettyp),
63 fClusters(0),
64 fNRawClusters(0),
65 fMap(0),
66 fNperMax(0),
67 fDeclusterFlag(0),
68 fClusterSize(0),
69 fNPeaks(-1){
70     // Standard constructor for cluster finder
71     // Input:
72     //   AliITSsegmentation *seg  The segmentation class to be used
73     //   AliITSresponse     *res  The response class to be used
74     // Output:
75     //   none.
76     // Return:
77     //   A Standard constructed AliITSCulsterFinder
78
79     SetNperMax();
80     SetClusterSize();
81     SetDeclusterFlag();
82 }
83 //----------------------------------------------------------------------
84 AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp,
85                                          TClonesArray *digits):
86 TObject(),
87 fDebug(0),
88 fModule(0),
89 fDigits(digits),
90 fNdigits(0),
91 fDetTypeRec(dettyp),
92 fClusters(0),
93 fNRawClusters(0),
94 fMap(0),
95 fNperMax(0),
96 fDeclusterFlag(0),
97 fClusterSize(0),
98 fNPeaks(-1){
99     // Standard + cluster finder constructor
100     // Input:
101     //   AliITSsegmentation *seg  The segmentation class to be used
102     //   AliITSresponse     *res  The response class to be used
103     //   TClonesArray    *digits  Array of digits to be used
104     // Output:
105     //   none.
106     // Return:
107     //   A Standard constructed AliITSCulsterFinder
108
109     fNdigits = fDigits->GetEntriesFast();
110     SetNperMax();
111     SetClusterSize();
112     SetDeclusterFlag();
113 }
114 /*
115 //______________________________________________________________________
116 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) : TObject(source) {
117   // Copy constructor
118   // Copies are not allowed. The method is protected to avoid misuse.
119   Fatal("AliITSClusterFinder","Copy constructor not allowed\n");
120 }
121 */
122
123 //______________________________________________________________________
124 //AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder& /* source */){
125   // Assignment operator
126   // Assignment is not allowed. The method is protected to avoid misuse.
127 //  Fatal("= operator","Assignment operator not allowed\n");
128 //  return *this;
129 //}
130
131 //----------------------------------------------------------------------
132 AliITSClusterFinder::~AliITSClusterFinder(){
133     // destructor cluster finder
134     // Input:
135     //   none.
136     // Output:
137     //   none.
138     // Return:
139     //   none.
140
141     if(fMap) {delete fMap;}
142     // Zero local pointers. Other classes own these pointers.
143     fMap          = 0;
144     fDigits       = 0;
145     fNdigits      = 0;
146     fNRawClusters = 0;
147     fNperMax      = 0;
148     fDeclusterFlag= 0;
149     fClusterSize  = 0;
150     fNPeaks       = 0;
151     fDetTypeRec   = 0;
152
153 }
154 //__________________________________________________________________________
155 void AliITSClusterFinder::InitGeometry(){
156  //
157  // Initialisation of ITS geometry
158  //
159   Int_t mmax=AliITSgeomTGeo::GetNModules();
160   for (Int_t m=0; m<mmax; m++) {
161     Int_t lay,lad,det; AliITSgeomTGeo::GetModuleId(m,lay,lad,det);
162     const TGeoHMatrix *tm=AliITSgeomTGeo::GetTracking2LocalMatrix(m);
163     fYshift[m] = (tm->Inverse()).GetTranslation()[1];
164     fZshift[m] = (tm->Inverse()).GetTranslation()[2];
165     fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
166     fNlayer[m] = lay-1;
167   }
168 }
169
170
171
172 //----------------------------------------------------------------------
173 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
174     // Add a raw cluster copy to the list
175     // Input:
176     //   Int_t       branch  The branch to which the cluster is to be added to
177     //   AliITSRawCluster *c The cluster to be added to the array of clusters
178     // Output:
179     //   none.
180     // Return:
181     //   none.
182
183    if(!fDetTypeRec) {
184     Error("AddCluster","fDetTypeRec is null!");
185     return;
186   }
187   fDetTypeRec->AddCluster(branch,c); 
188   fNRawClusters++;
189 }
190 //----------------------------------------------------------------------
191 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c, 
192                                      AliITSRecPoint &rp){
193     // Add a raw cluster copy to the list and the RecPoint
194     // Input:
195     //   Int_t       branch  The branch to which the cluster is to be added to
196     //   AliITSRawCluster *c The cluster to be added to the array of clusters
197     //   AliITSRecPoint  &rp The RecPoint to be added to the array of RecPoints
198     // Output:
199     //   none.
200     // Return:
201     //   none.
202   if(!fDetTypeRec) {
203     Error("AddCluster","fDetTypeRec is null!");
204     return;
205   }
206
207   fDetTypeRec->AddCluster(branch,c); 
208   fNRawClusters++;
209   fDetTypeRec->AddRecPoint(rp); 
210
211 }
212 /*
213 //______________________________________________________________________
214 void AliITSClusterFinder::CheckLabels(Int_t lab[3]) {
215   //------------------------------------------------------------
216   // Tries to find mother's labels
217   //------------------------------------------------------------
218
219   if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
220   // Check if simulation
221   AliMC* mc = gAlice->GetMCApp();
222   if(!mc)return;
223
224   Int_t ntracks = mc->GetNtrack();
225   for (Int_t i=0;i<3;i++){
226     Int_t label = lab[i];
227     if (label>=0 && label<ntracks) {
228       TParticle *part=(TParticle*)mc->Particle(label);
229       if (part->P() < 0.005) {
230         Int_t m=part->GetFirstMother();
231         if (m<0) {      
232           continue;
233         }
234         if (part->GetStatusCode()>0) {
235           continue;
236         }
237         lab[i]=m;       
238       }
239     }    
240   }
241   
242 }
243 */
244 //______________________________________________________________________
245 void AliITSClusterFinder::FindRawClusters(Int_t module){
246     // Default Cluster finder.
247     // Input:
248     //   Int_t module   Module number for which culster are to be found.
249     // Output:
250     //   none.
251     // Return:
252     //   none.
253     const Int_t kelms = 10;
254     Int_t ndigits = fDigits->GetEntriesFast();
255     TObjArray *digs = new TObjArray(ndigits);
256     TObjArray *clusts = new TObjArray(ndigits); // max # cluster
257     TObjArray *clust0=0; // A spacific cluster of digits
258     TObjArray *clust1=0; // A spacific cluster of digits
259     AliITSdigit *dig=0; // locat pointer to a digit
260     Int_t i=0,nc=0,j[4],k,k2=0;
261
262     // Copy all digits for this module into a local TObjArray.
263     for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*(GetDigit(i))),i);
264     digs->Sort();
265     // First digit is a cluster.
266     i  = 0;
267     nc = 0;
268     clusts->AddAt(new TObjArray(kelms),nc);
269     clust0 = (TObjArray*)(clusts->At(nc));
270     clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
271     nc++;
272     for(i=1;i<ndigits;i++){
273         if(IsNeighbor(digs,i,j)){
274             dig = (AliITSdigit*)(digs->At(j[0]));
275             // Add to existing cluster. Find which cluster this digis 
276             for(k=0;k<nc;k++){
277                 clust0 = ((TObjArray*)(clusts->At(k)));
278                 if(clust0->IndexOf(dig)>=0) break;
279             } // end for k
280             if(k>=nc){
281                 Fatal("FindRawClusters","Digit not found as expected");
282             } // end if
283             if(j[1]>=0){
284                 dig = (AliITSdigit*)(digs->At(j[1]));
285                 // Add to existing cluster. Find which cluster this digis 
286                 for(k2=0;k2<nc;k2++){
287                     clust1 = ((TObjArray*)(clusts->At(k2)));
288                     if(clust1->IndexOf(dig)>=0) break;
289                 } // end for k2
290                 if(k2>=nc){
291                     Fatal("FindRawClusters","Digit not found as expected");
292                 } // end if
293             } // end if j[1]>=0
294             // Found cluster with neighboring digits add this one to it.
295             if(clust0==clust1){ // same cluster
296                 clust0->AddAtFree(digs->At(i));
297                 clust0 = 0; // finished with cluster. zero for safty
298                 clust1 = 0; // finished wit hcluster. zero for safty
299             }else{ // two different clusters which need to be merged.
300                 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
301                 for(k=0;k<clust1->GetEntriesFast();k++){
302                     // move clust1 into clust0
303                     //move digit to this cluster
304                     clust0->AddAtFree(clust1->At(k));
305                     clust1->AddAt(0,k); // zero this one
306                 } // end for k
307                 delete clust1;
308                 clusts->AddAt(0,k2); // zero array of clusters element clust1
309                 clust0 = 0; // finished with cluster. zero for safty
310                 clust1 = 0; // finished wit hcluster. zero for safty
311             } // end if clust0==clust1
312         }else{// New cluster
313             clusts->AddAt(new TObjArray(kelms),nc);
314             clust0 = ((TObjArray*)(clusts->At(nc)));
315             // move owner ship from digs to clusts
316             clust0->AddAtFree(digs->At(i));
317             clust0 = 0; // finished with cluster. zero for safty
318             nc++;
319         } // End if IsNeighbor
320     } // end for i
321     // There are now nc clusters in clusts. Each element of clust is an
322     // array of digits which are clustered together.
323
324     // For each cluster call detector specific CreateRecPoints
325     for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
326
327     // clean up at the end.
328     for(i=0;i<nc;i++){ 
329         clust0 =(TObjArray*)(clusts->At(i));
330         // Digits deleted below, so zero this TObjArray
331         for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
332         delete clust0; // Delete this TObjArray
333         clusts->AddAt(0,i); // Contents deleted above, so zero it.
334     } // end for i
335     delete clusts; // Delete this TObjArray/
336     // Delete the digits then the TObjArray which containted them.
337     for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
338     delete digs;
339 }
340 //______________________________________________________________________
341 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[])const{
342     // Locagical function which checks to see if digit i has a neighbor.
343     // If so, then it returns kTRUE and its neighbor index j.
344     // This routine checks if the digits are side by side or one before the
345     // other. Requires that the array of digits be in proper order.
346     // Returns kTRUE in the following cases.
347     //                 ji   0j   if kdiagonal  j0    0i
348     //                 00   0i   if kdiagonal  0i    j0
349     // Inputs:
350     //    TObjArray *digs   Array to search for neighbors in
351     //    Int_t      i      Index of digit for which we are searching for
352     //                      a neighbor of.
353     // Output:
354     //    Int_t      j[4]   Index of one or more of the digits which is a
355     //                      neighbor of digit a index i.
356     // Return:
357     //    Bool_t            kTRUE if a neighbor was found kFALSE otherwise.
358     Int_t ix,jx,iz,jz,j;
359     const Bool_t kdiagonal=kFALSE;
360     Bool_t nei[4];
361
362     // No neighbors found if array empty.
363     if(digs->GetEntriesFast()<=0) return kFALSE;
364     // can not be a digit with first element or elements out or range
365     if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
366
367     for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
368     ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
369     iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
370     for(j=0;j<i;j++){
371         jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
372         jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
373         if(jx+1==ix && jz  ==iz){n[0] = j;nei[0] = kTRUE;}
374         if(jx  ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
375         if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
376         if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
377     } // end for k
378     if(nei[0]||nei[1]) return kTRUE;
379     if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
380     // no Neighbors found.
381     return kFALSE;
382 }
383
384 //______________________________________________________________________
385 void AliITSClusterFinder::Print(ostream *os) const{
386     //Standard output format for this class
387     // Inputs:
388     //    ostream *os   Output stream
389     // Output:
390     //    ostream *os   Output stream
391     // Return:
392     //    none.
393
394     *os << fDebug<<",";
395     *os << fModule<<",";
396     *os << fNdigits<<",";
397     *os << fNRawClusters<<",";
398     *os << fNperMax<<",";
399     *os << fDeclusterFlag<<",";
400     *os << fClusterSize<<",";
401     *os << fNPeaks<<endl;
402 }
403 //______________________________________________________________________
404 void AliITSClusterFinder::Read(istream *is)  {
405     //Standard input for this class
406     // Inputs:
407     //    istream *is   Input stream
408     // Output:
409     //    istream *is   Input stream
410     // Return:
411     //    none.
412
413     *is >> fDebug;
414     *is >> fModule;
415     *is >> fNdigits;
416     *is >> fNRawClusters;
417     *is >> fNperMax;
418     *is >> fDeclusterFlag;
419     *is >> fClusterSize;
420     *is >> fNPeaks;
421 }
422 //______________________________________________________________________
423 ostream &operator<<(ostream &os,AliITSClusterFinder &source){
424     // Standard output streaming function.
425     // Inputs:
426     //    ostream             *os     Output stream
427     //    AliITSClusterFinder &source Class to be printed
428     // Output:
429     //    ostream             *os     Output stream
430     // Return:
431     //    none.
432
433     source.Print(&os);
434     return os;
435 }
436 //______________________________________________________________________
437 istream &operator>>(istream &is,AliITSClusterFinder &source){
438     // Standard output streaming function.
439     // Inputs:
440     //    istream              *is      Input stream
441     //     AliITSClusterFinder &source  Class to be read in.
442     // Output:
443     //    istream              *is      Input stream
444     // Return:
445     //    none.
446
447     source.Read(&is);
448     return is;
449 }