]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSClusterFinderSPDdubna.cxx
Merging the VirtualMC branch to the main development branch (HEAD)
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderSPDdubna.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 $Log$
18 Revision 1.2.8.1  2002/08/28 15:06:50  alibrary
19 Updating to v3-09-01
20
21 Revision 1.4  2002/08/22 13:18:46  nilsen
22 Added = operator and copy constructor in an attempt to fix complilation
23 problems found by Yves Schutz.
24
25 Revision 1.3  2002/08/21 22:04:27  nilsen
26 Added data member to SPD cluters and made related modifications to the
27 SPD Cluster finders. Generaly cleanded up some of the code.
28
29 Revision 1.2  2001/06/14 14:33:53  barbera
30 New version from B. Batyunya to get the Dubna model work with the present HEAD
31
32 Revision 1.15  2001/05/01 22:37:44  nilsen
33 Added a dummy argument to FindRawClusters. Argument used for SSD version.
34
35 Revision 1.14  2001/03/05 14:48:46  nilsen
36 Fixed a reoccuring bug. Array sizes must be declare const.
37
38 */
39
40 #include <iostream.h>
41 #include "AliITSClusterFinderSPDdubna.h"
42 #include "AliITSMapA1.h"
43 #include "AliITS.h"
44 #include "AliITSdigit.h"
45 #include "AliITSRawCluster.h"
46 #include "AliITSRecPoint.h"
47 #include "AliITSsegmentation.h"
48 #include "AliITSresponse.h"
49 #include "AliRun.h"
50
51 //#define DEBUG
52
53 ClassImp(AliITSClusterFinderSPDdubna)
54
55 //----------------------------------------------------------------------
56 AliITSClusterFinderSPDdubna::AliITSClusterFinderSPDdubna(
57            AliITSsegmentation *seg, TClonesArray *digits, TClonesArray *recp){
58     // constructor
59
60     fSegmentation = seg;
61     fDigits       = digits;
62     fClusters     = recp;
63     fNclusters    = 0;
64     fMap          = new AliITSMapA1(fSegmentation,fDigits);
65     SetDx();
66     SetDz();
67     SetNCells();
68 }
69 //_______________________________________________________________________
70 AliITSClusterFinderSPDdubna::AliITSClusterFinderSPDdubna(){
71     // constructor
72
73     fSegmentation = 0;
74     fDigits       = 0;
75     fClusters     = 0;
76     fNclusters    = 0;
77     fMap          = 0;
78     SetDx();
79     SetDz();
80     SetNCells();
81 }
82 //______________________________________________________________________
83 AliITSClusterFinderSPDdubna &AliITSClusterFinderSPDdubna::operator=(const
84                                           AliITSClusterFinderSPDdubna &s){
85     // The = operator for the class AliITSClusterFinderSPDdugna
86     // Inputs:
87     //    AliITSClusterFinderSPDdubna @s  The AliITSClusterFinderSPDdubna
88     //                                    class to be copy constructed.
89     // Outputs:
90     //    none.
91     // Returned:
92     //    this, a copy of the class s.
93
94     this->fNclusters = s.fNclusters;
95     this->fDz        = s.fDz;
96     this->fDx        = s.fDx;
97     this->fMinNCells = s.fMinNCells;
98     this->fClusters  = new TClonesArray(*(s.fClusters));
99     return *this;
100 }
101 //______________________________________________________________________
102 AliITSClusterFinderSPDdubna::AliITSClusterFinderSPDdubna(const
103                                          AliITSClusterFinderSPDdubna &s){
104     // The Copy constructortor the class AliITSClusterFinderSPDdugna
105     // It calles the = operator.
106     // Inputs:
107     //    AliITSClusterFinderSPDdubna @s  The AliITSClusterFinderSPDdubna
108     //                                    class to be copy constructed.
109     // Outputs:
110     //    none.
111     // Returned:
112     //    none.
113
114     *this = s;
115     return;
116 }
117 //______________________________________________________________________
118 AliITSClusterFinderSPDdubna::~AliITSClusterFinderSPDdubna(){
119     // destructor
120
121     if (fMap) delete fMap;
122 }
123 //______________________________________________________________________
124 void AliITSClusterFinderSPDdubna::Find1DClusters(Int_t mod){
125     // Find one dimensional clusters, i.e.
126     // in r*phi(x) direction for each colunm in z direction
127
128     static AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
129   
130     // retrieve the parameters 
131     Int_t fNofPixels     = fSegmentation->Npz(); 
132     Int_t fMaxNofSamples = fSegmentation->Npx();
133
134     // read in digits -> do not apply threshold 
135     // signal in fired pixels is always 1
136     fMap->FillMap();
137
138     Int_t nofFoundClusters = 0;
139
140     Int_t k,it,m;
141     for(k=0;k<fNofPixels;k++) {
142         Int_t mmax = 10;  // a size of the window for the cluster finding
143         for(it=0;it<fMaxNofSamples;it++) {
144             Int_t lclx   = 0;
145             Int_t xstart = 0;
146             Int_t xstop  = 0;
147             Int_t id     = 0;
148             Int_t ilcl   = 0;
149             for(m=0;m<mmax;m++) {  // find the cluster inside the window
150                 id = it+m;
151                 if(id >= fMaxNofSamples) break;    // ! no possible for the fadc
152                 if(fMap->TestHit(k,id) == kUnused) {   // start of the cluster
153                     lclx += 1;
154                     if(lclx == 1) xstart = id;
155                 } // end if fMap
156                 if(lclx > 0 && fMap->TestHit(k,id) == kEmpty) {  
157                     // end of cluster if a gap exists
158                     xstop = id-1;
159                     ilcl = 1;
160                     break;
161                 } // end if lclx >0 ...
162             }   //  end of m-loop
163             if(lclx == 0 && ilcl == 0) it = id; // no cluster in the window,
164                                                 // continue the "it" loop
165             if(id >= fMaxNofSamples && lclx == 0) break; // the x row finished
166             if(id < fMaxNofSamples && ilcl == 0 && lclx > 0) {  
167                 // cluster end is outside of the window,
168                 mmax += 5;     // increase mmax and repeat the cluster finding
169                 it -= 1;
170             } // end if id<
171             if(id >= fMaxNofSamples && lclx > 0) {  // the x row finished but
172                 xstop = fMaxNofSamples - 1;           // the end cluster exists
173                 ilcl = 1;
174             }  // end if id>=      
175             // ---  Calculate z and x coordinates for one dimensional clusters
176             if(ilcl == 1) {         // new cluster exists
177                 it = id;
178                 mmax = 10;
179                 nofFoundClusters++;
180                 Float_t clusterCharge = 0.;
181                 Float_t zpitch        = fSegmentation->Dpz(k+1);
182                 Int_t   dummy         = 0;
183                 Float_t clusterZ, dummyX; 
184                 fSegmentation->GetPadCxz(dummy,k,dummyX,clusterZ);
185                 Float_t zstart        = clusterZ - 0.5*zpitch;
186                 Float_t zstop         = clusterZ + 0.5*zpitch;
187                 Float_t clusterX      = 0.;
188                 Int_t   clusterSizeX  = lclx;
189                 Int_t   clusterSizeZ  = 1;
190                 Int_t   its;
191                 for(its=xstart; its<=xstop; its++) {
192                     Int_t firedpixel=0;
193                     if (fMap->GetHitIndex(k,its)>=0) firedpixel=1; 
194                     clusterCharge += firedpixel;
195                     clusterX      += its + 0.5;
196                 } // end for its
197                 Float_t fRphiPitch = fSegmentation->Dpx(dummy);
198                 clusterX /= (clusterSizeX/fRphiPitch); // center of gravity for x
199                 // Write the points (coordinates and some cluster information) 
200                 // to the AliITSRawClusterSPD object
201
202                 AliITSRawClusterSPD clust(clusterZ,clusterX,clusterCharge,
203                                           clusterSizeZ,clusterSizeX,
204                                           xstart,xstop,zstart,zstop,k,mod);
205                 iTS->AddCluster(0,&clust);
206             }    // new cluster (ilcl=1)
207         } // X direction loop (it)
208     } // Z direction loop (k)
209     //fMap->ClearMap();
210     return;
211 }
212 //______________________________________________________________________
213 void  AliITSClusterFinderSPDdubna::GroupClusters(){
214     // Find two dimensional clusters, i.e. group one dimensional clusters
215     // into two dimensional ones (go both in x and z directions).
216     // get number of clusters for this module
217
218     Int_t nofClusters = fClusters->GetEntriesFast();
219     nofClusters -= fNclusters;
220     AliITSRawClusterSPD *clusterI;
221     AliITSRawClusterSPD *clusterJ;
222     Int_t *label=new Int_t[nofClusters];  
223     Int_t i,j;
224     for(i=0; i<nofClusters; i++) label[i] = 0;
225     for(i=0; i<nofClusters; i++) {
226         if(label[i] != 0) continue;
227         for(j=i+1; j<nofClusters; j++) { 
228             if(label[j] != 0) continue;
229             clusterI = (AliITSRawClusterSPD*) fClusters->At(i);
230             clusterJ = (AliITSRawClusterSPD*) fClusters->At(j);
231             Bool_t pair = clusterI->Brother(clusterJ,fDz,fDx);
232             if(pair) {
233 #ifndef DEBUG
234                 cout << "clusters " << i << "," << j << " before grouping" << endl;
235                 clusterI->PrintInfo();
236                 clusterJ->PrintInfo();
237 #endif
238                 clusterI->Add(clusterJ);
239 #ifndef DEBUG
240                 cout << "remove cluster " << j << endl;
241 #endif
242                 label[j] = 1;
243                 fClusters->RemoveAt(j);
244 #ifndef DEBUG
245                 cout << "cluster  " << i << " after grouping" << endl;
246                 clusterI->PrintInfo();
247 #endif
248             }  // pair
249         } // J clusters  
250         label[i] = 1;
251     } // I clusters
252     fClusters->Compress();
253 #ifndef DEBUG
254     Int_t totalNofClusters = fClusters->GetEntriesFast();
255     cout << " Nomber of clusters at the group end ="<< totalNofClusters<<endl;
256 #endif
257     delete [] label;
258     return;
259 }
260 //______________________________________________________________________
261 void AliITSClusterFinderSPDdubna::TracksInCluster(){
262     // Find tracks creating one cluster
263     // get number of clusters for this module
264     Int_t nofClusters = fClusters->GetEntriesFast();
265     Int_t i, ix, iz, jx, jz, xstart, xstop, zstart, zstop, nclx, nclz;
266     const Int_t trmax = 100;
267     Int_t cltracks[trmax], itr, tracki, ii, is, js, ie, ntr, tr0, tr1, tr2;
268
269     nofClusters -= fNclusters;
270     for(i=0; i<nofClusters; i++) { 
271         ii = 0;
272         memset(cltracks,-1,sizeof(int)*trmax);
273         tr0=tr1=tr2=-1;
274         AliITSRawClusterSPD *clusterI = (AliITSRawClusterSPD*) fClusters->At(i);
275         nclx = clusterI->NclX();
276         nclz = clusterI->NclZ();
277         xstart = clusterI->XStartf();
278         xstop = clusterI->XStopf();
279         zstart = clusterI->Zend()-nclz+1;
280         zstop = clusterI->Zend();
281         Int_t ind;
282         for(iz=0; iz<nclz; iz++) { 
283             jz = zstart + iz;
284             for(ix=0; ix<nclx; ix++) { 
285                 jx = xstart + ix;
286                 ind = fMap->GetHitIndex(jz,jx);
287                 if(ind < 0) continue;
288                 if(ind == 0 && iz >= 0 && ix > 0) continue;
289                 if(ind == 0 && iz > 0 && ix >= 0) continue;
290                 if(ind == 0 && iz == 0 && ix == 0 && i > 0) continue;
291                 AliITSdigitSPD *dig = (AliITSdigitSPD*)fMap->GetHit(jz,jx);
292                 for(itr=0; itr<3; itr++) { 
293                     tracki = dig->fTracks[itr];
294                     if(tracki >= 0) {
295                         ii += 1;
296                         if(ii < 99) cltracks[ii-1] = tracki;
297                     } // end if tracki >-0
298                 } // end for itr
299             } // ix pixel
300         }  // iz pixel
301         for(is=0; is<trmax; is++) { 
302             if(cltracks[is]<0) continue;
303             for(js=is+1; js<trmax; js++) { 
304                 if(cltracks[js]<0) continue;
305                 if(cltracks[js]==cltracks[is]) cltracks[js]=-5;
306             } // end for js
307         } // end for is
308         ntr = 0;
309         for(ie=0; ie<trmax; ie++) { 
310             if(cltracks[ie] >= 0) {
311                 ntr=ntr+1;
312                 if(ntr==1) tr0=cltracks[ie];
313                 if(ntr==2) tr1=cltracks[ie];
314                 if(ntr==3) tr2=cltracks[ie];
315             } // end if cltracks[ie] >-=
316         } // end for ie
317         // if delta ray only
318         if(ntr == 0) ntr = 1;
319         clusterI->SetNTracks(ntr);
320         clusterI->SetTracks(tr0,tr1,tr2);
321     } // I cluster
322 }
323 //______________________________________________________________________
324 void AliITSClusterFinderSPDdubna::GetRecPoints(){
325     // get rec points
326     static AliITS *iTS = (AliITS*)gAlice->GetModule("ITS");
327     // get number of clusters for this module
328     Int_t nofClusters   = fClusters->GetEntriesFast();
329     const Float_t kconv = 1.0e-4;
330     const Float_t kRMSx = 12.0*kconv; // microns -> cm ITS TDR Table 1.3
331     const Float_t kRMSz = 70.0*kconv; // microns -> cm ITS TDR Table 1.3
332     Float_t spdLength   = fSegmentation->Dz();
333     Float_t spdWidth    = fSegmentation->Dx();
334     Int_t   dummy       = 0;
335     Float_t xpitch      = fSegmentation->Dpx(dummy);
336     Int_t i;
337     Int_t track0, track1, track2;
338
339     nofClusters -= fNclusters;
340     for(i=0; i<nofClusters; i++) {
341         AliITSRawClusterSPD *clusterI = (AliITSRawClusterSPD*) fClusters->At(i);
342         Int_t clustersizex = clusterI->NclX();
343         Int_t clustersizez = clusterI->NclZ();
344         Int_t xstart = clusterI->XStartf();
345         Float_t clusterx = 0;
346         Float_t clusterz = clusterI->Z();
347         for(Int_t ii=0; ii<clustersizex; ii++) clusterx += (xstart+0.5+ii)*xpitch;
348         clusterx /= clustersizex;
349         clusterz /= clustersizez;   
350         clusterI->GetTracks(track0, track1, track2); 
351         AliITSRecPoint rnew;
352         rnew.SetX((clusterx - spdWidth/2)*kconv);
353         rnew.SetZ((clusterz - spdLength/2)*kconv);
354         rnew.SetQ(1.);
355         rnew.SetdEdX(0.);
356         rnew.SetSigmaX2(kRMSx*kRMSx);
357         rnew.SetSigmaZ2(kRMSz*kRMSz);
358         rnew.fTracks[0]=track0;
359         rnew.fTracks[1]=track1;
360         rnew.fTracks[2]=track2;
361         iTS->AddRecPoint(rnew);
362     } // I clusters
363     fMap->ClearMap();
364 }
365 //______________________________________________________________________
366 void AliITSClusterFinderSPDdubna::FindRawClusters(Int_t mod){
367     // find raw clusters
368
369 #ifndef DEBUG
370     cout<<"SPDdubna: module ="<<mod<<endl;
371 #endif
372     Find1DClusters(mod);
373     GroupClusters();
374     TracksInCluster();
375     GetRecPoints();
376 }