]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSClusterFinder.cxx
Error messages stored in the global raw-reader error log (Cvetan, Chiara)
[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     fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
163     fNlayer[m] = lay-1;
164   }
165 }
166
167
168
169 //----------------------------------------------------------------------
170 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
171     // Add a raw cluster copy to the list
172     // Input:
173     //   Int_t       branch  The branch to which the cluster is to be added to
174     //   AliITSRawCluster *c The cluster to be added to the array of clusters
175     // Output:
176     //   none.
177     // Return:
178     //   none.
179
180    if(!fDetTypeRec) {
181     Error("AddCluster","fDetTypeRec is null!");
182     return;
183   }
184   fDetTypeRec->AddCluster(branch,c); 
185   fNRawClusters++;
186 }
187 //----------------------------------------------------------------------
188 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c, 
189                                      AliITSRecPoint &rp){
190     // Add a raw cluster copy to the list and the RecPoint
191     // Input:
192     //   Int_t       branch  The branch to which the cluster is to be added to
193     //   AliITSRawCluster *c The cluster to be added to the array of clusters
194     //   AliITSRecPoint  &rp The RecPoint to be added to the array of RecPoints
195     // Output:
196     //   none.
197     // Return:
198     //   none.
199   if(!fDetTypeRec) {
200     Error("AddCluster","fDetTypeRec is null!");
201     return;
202   }
203
204   fDetTypeRec->AddCluster(branch,c); 
205   fNRawClusters++;
206   fDetTypeRec->AddRecPoint(rp); 
207
208 }
209 /*
210 //______________________________________________________________________
211 void AliITSClusterFinder::CheckLabels(Int_t lab[3]) {
212   //------------------------------------------------------------
213   // Tries to find mother's labels
214   //------------------------------------------------------------
215
216   if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
217   // Check if simulation
218   AliMC* mc = gAlice->GetMCApp();
219   if(!mc)return;
220
221   Int_t ntracks = mc->GetNtrack();
222   for (Int_t i=0;i<3;i++){
223     Int_t label = lab[i];
224     if (label>=0 && label<ntracks) {
225       TParticle *part=(TParticle*)mc->Particle(label);
226       if (part->P() < 0.005) {
227         Int_t m=part->GetFirstMother();
228         if (m<0) {      
229           continue;
230         }
231         if (part->GetStatusCode()>0) {
232           continue;
233         }
234         lab[i]=m;       
235       }
236     }    
237   }
238   
239 }
240 */
241 //______________________________________________________________________
242 void AliITSClusterFinder::FindRawClusters(Int_t module){
243     // Default Cluster finder.
244     // Input:
245     //   Int_t module   Module number for which culster are to be found.
246     // Output:
247     //   none.
248     // Return:
249     //   none.
250     const Int_t kelms = 10;
251     Int_t ndigits = fDigits->GetEntriesFast();
252     TObjArray *digs = new TObjArray(ndigits);
253     TObjArray *clusts = new TObjArray(ndigits); // max # cluster
254     TObjArray *clust0=0; // A spacific cluster of digits
255     TObjArray *clust1=0; // A spacific cluster of digits
256     AliITSdigit *dig=0; // locat pointer to a digit
257     Int_t i=0,nc=0,j[4],k,k2=0;
258
259     // Copy all digits for this module into a local TObjArray.
260     for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*(GetDigit(i))),i);
261     digs->Sort();
262     // First digit is a cluster.
263     i  = 0;
264     nc = 0;
265     clusts->AddAt(new TObjArray(kelms),nc);
266     clust0 = (TObjArray*)(clusts->At(nc));
267     clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
268     nc++;
269     for(i=1;i<ndigits;i++){
270         if(IsNeighbor(digs,i,j)){
271             dig = (AliITSdigit*)(digs->At(j[0]));
272             // Add to existing cluster. Find which cluster this digis 
273             for(k=0;k<nc;k++){
274                 clust0 = ((TObjArray*)(clusts->At(k)));
275                 if(clust0->IndexOf(dig)>=0) break;
276             } // end for k
277             if(k>=nc){
278                 Fatal("FindRawClusters","Digit not found as expected");
279             } // end if
280             if(j[1]>=0){
281                 dig = (AliITSdigit*)(digs->At(j[1]));
282                 // Add to existing cluster. Find which cluster this digis 
283                 for(k2=0;k2<nc;k2++){
284                     clust1 = ((TObjArray*)(clusts->At(k2)));
285                     if(clust1->IndexOf(dig)>=0) break;
286                 } // end for k2
287                 if(k2>=nc){
288                     Fatal("FindRawClusters","Digit not found as expected");
289                 } // end if
290             } // end if j[1]>=0
291             // Found cluster with neighboring digits add this one to it.
292             if(clust0==clust1){ // same cluster
293                 clust0->AddAtFree(digs->At(i));
294                 clust0 = 0; // finished with cluster. zero for safty
295                 clust1 = 0; // finished wit hcluster. zero for safty
296             }else{ // two different clusters which need to be merged.
297                 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
298                 for(k=0;k<clust1->GetEntriesFast();k++){
299                     // move clust1 into clust0
300                     //move digit to this cluster
301                     clust0->AddAtFree(clust1->At(k));
302                     clust1->AddAt(0,k); // zero this one
303                 } // end for k
304                 delete clust1;
305                 clusts->AddAt(0,k2); // zero array of clusters element clust1
306                 clust0 = 0; // finished with cluster. zero for safty
307                 clust1 = 0; // finished wit hcluster. zero for safty
308             } // end if clust0==clust1
309         }else{// New cluster
310             clusts->AddAt(new TObjArray(kelms),nc);
311             clust0 = ((TObjArray*)(clusts->At(nc)));
312             // move owner ship from digs to clusts
313             clust0->AddAtFree(digs->At(i));
314             clust0 = 0; // finished with cluster. zero for safty
315             nc++;
316         } // End if IsNeighbor
317     } // end for i
318     // There are now nc clusters in clusts. Each element of clust is an
319     // array of digits which are clustered together.
320
321     // For each cluster call detector specific CreateRecPoints
322     for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
323
324     // clean up at the end.
325     for(i=0;i<nc;i++){ 
326         clust0 =(TObjArray*)(clusts->At(i));
327         // Digits deleted below, so zero this TObjArray
328         for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
329         delete clust0; // Delete this TObjArray
330         clusts->AddAt(0,i); // Contents deleted above, so zero it.
331     } // end for i
332     delete clusts; // Delete this TObjArray/
333     // Delete the digits then the TObjArray which containted them.
334     for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
335     delete digs;
336 }
337 //______________________________________________________________________
338 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[])const{
339     // Locagical function which checks to see if digit i has a neighbor.
340     // If so, then it returns kTRUE and its neighbor index j.
341     // This routine checks if the digits are side by side or one before the
342     // other. Requires that the array of digits be in proper order.
343     // Returns kTRUE in the following cases.
344     //                 ji   0j   if kdiagonal  j0    0i
345     //                 00   0i   if kdiagonal  0i    j0
346     // Inputs:
347     //    TObjArray *digs   Array to search for neighbors in
348     //    Int_t      i      Index of digit for which we are searching for
349     //                      a neighbor of.
350     // Output:
351     //    Int_t      j[4]   Index of one or more of the digits which is a
352     //                      neighbor of digit a index i.
353     // Return:
354     //    Bool_t            kTRUE if a neighbor was found kFALSE otherwise.
355     Int_t ix,jx,iz,jz,j;
356     const Bool_t kdiagonal=kFALSE;
357     Bool_t nei[4];
358
359     // No neighbors found if array empty.
360     if(digs->GetEntriesFast()<=0) return kFALSE;
361     // can not be a digit with first element or elements out or range
362     if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
363
364     for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
365     ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
366     iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
367     for(j=0;j<i;j++){
368         jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
369         jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
370         if(jx+1==ix && jz  ==iz){n[0] = j;nei[0] = kTRUE;}
371         if(jx  ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
372         if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
373         if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
374     } // end for k
375     if(nei[0]||nei[1]) return kTRUE;
376     if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
377     // no Neighbors found.
378     return kFALSE;
379 }
380
381 //______________________________________________________________________
382 void AliITSClusterFinder::Print(ostream *os) const{
383     //Standard output format for this class
384     // Inputs:
385     //    ostream *os   Output stream
386     // Output:
387     //    ostream *os   Output stream
388     // Return:
389     //    none.
390
391     *os << fDebug<<",";
392     *os << fModule<<",";
393     *os << fNdigits<<",";
394     *os << fNRawClusters<<",";
395     *os << fNperMax<<",";
396     *os << fDeclusterFlag<<",";
397     *os << fClusterSize<<",";
398     *os << fNPeaks<<endl;
399 }
400 //______________________________________________________________________
401 void AliITSClusterFinder::Read(istream *is)  {
402     //Standard input for this class
403     // Inputs:
404     //    istream *is   Input stream
405     // Output:
406     //    istream *is   Input stream
407     // Return:
408     //    none.
409
410     *is >> fDebug;
411     *is >> fModule;
412     *is >> fNdigits;
413     *is >> fNRawClusters;
414     *is >> fNperMax;
415     *is >> fDeclusterFlag;
416     *is >> fClusterSize;
417     *is >> fNPeaks;
418 }
419 //______________________________________________________________________
420 ostream &operator<<(ostream &os,AliITSClusterFinder &source){
421     // Standard output streaming function.
422     // Inputs:
423     //    ostream             *os     Output stream
424     //    AliITSClusterFinder &source Class to be printed
425     // Output:
426     //    ostream             *os     Output stream
427     // Return:
428     //    none.
429
430     source.Print(&os);
431     return os;
432 }
433 //______________________________________________________________________
434 istream &operator>>(istream &is,AliITSClusterFinder &source){
435     // Standard output streaming function.
436     // Inputs:
437     //    istream              *is      Input stream
438     //     AliITSClusterFinder &source  Class to be read in.
439     // Output:
440     //    istream              *is      Input stream
441     // Return:
442     //    none.
443
444     source.Read(&is);
445     return is;
446 }