]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSClusterFinderV2SDD.cxx
V2 clusterer moved to the standard framework. V2 clusters and recpoints are still...
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderV2SDD.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2003, 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 //            Implementation of the ITS clusterer V2 class                //
17 //                                                                        //
18 //          Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch            //
19 //                                                                        //
20 ///////////////////////////////////////////////////////////////////////////
21
22
23 #include "AliRun.h"
24
25 #include "AliITSClusterFinderV2SDD.h"
26 #include "AliITSclusterV2.h"
27 #include "AliRawReader.h"
28 #include "AliITSRawStreamSDD.h"
29
30 #include <TClonesArray.h>
31 #include "AliITS.h"
32 #include "AliITSgeom.h"
33 #include "AliITSdigitSDD.h"
34
35 ClassImp(AliITSClusterFinderV2SDD)
36
37 extern AliRun *gAlice;
38
39 AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD():AliITSClusterFinderV2(){
40
41   //Default constructor
42
43   fNySDD=256; fNzSDD=256;
44   fYpitchSDD=0.01825;
45   fZpitchSDD=0.02940;
46   fHwSDD=3.5085; fHlSDD=3.7632;
47   fYoffSDD=0.0425;
48
49
50
51 }
52  
53
54 void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
55
56   //Find clusters V2
57   SetModule(mod);
58   FindClustersSDD(fDigits);
59
60 }
61
62 void AliITSClusterFinderV2SDD::FindClustersSDD(TClonesArray *digits) {
63   //------------------------------------------------------------
64   // Actual SDD cluster finder
65   //------------------------------------------------------------
66   Int_t kNzBins = fNzSDD + 2;
67   const Int_t kMAXBIN=kNzBins*(fNySDD+2);
68
69   AliBin *bins[2];
70   bins[0]=new AliBin[kMAXBIN];
71   bins[1]=new AliBin[kMAXBIN];
72
73   AliITSdigitSDD *d=0;
74   Int_t i, ndigits=digits->GetEntriesFast();
75   for (i=0; i<ndigits; i++) {
76      d=(AliITSdigitSDD*)digits->UncheckedAt(i);
77      Int_t y=d->GetCoord2()+1;   //y
78      Int_t z=d->GetCoord1()+1;   //z
79      Int_t q=d->GetSignal();
80      if (q<3) continue;
81
82      if (z <= fNzSDD) {
83        bins[0][y*kNzBins+z].SetQ(q);
84        bins[0][y*kNzBins+z].SetMask(1);
85        bins[0][y*kNzBins+z].SetIndex(i);
86      } else {
87        z-=fNzSDD; 
88        bins[1][y*kNzBins+z].SetQ(q);
89        bins[1][y*kNzBins+z].SetMask(1);
90        bins[1][y*kNzBins+z].SetIndex(i);
91      }
92   }
93   
94   FindClustersSDD(bins, kMAXBIN, kNzBins, digits);
95
96   delete[] bins[0];
97   delete[] bins[1];
98
99 }
100
101 void AliITSClusterFinderV2SDD::
102 FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins, 
103                 TClonesArray *digits, TClonesArray *clusters) {
104   //------------------------------------------------------------
105   // Actual SDD cluster finder
106   //------------------------------------------------------------
107   Int_t ncl=0; 
108   TClonesArray &cl=*clusters;
109   for (Int_t s=0; s<2; s++)
110     for (Int_t i=0; i<nMaxBin; i++) {
111       if (bins[s][i].IsUsed()) continue;
112       Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
113       FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
114
115       if (npeaks>30) continue;
116       if (npeaks==0) continue;
117
118       Int_t k,l;
119       for (k=0; k<npeaks-1; k++){//mark adjacent peaks
120         if (idx[k] < 0) continue; //this peak is already removed
121         for (l=k+1; l<npeaks; l++) {
122            if (idx[l] < 0) continue; //this peak is already removed
123            Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
124            Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
125            Int_t di=TMath::Abs(ki - li);
126            Int_t dj=TMath::Abs(kj - lj);
127            if (di>1 || dj>1) continue;
128            if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
129               msk[l]=msk[k];
130               idx[l]*=-1;
131            } else {
132               msk[k]=msk[l];
133               idx[k]*=-1;
134               break;
135            } 
136         }
137       }
138
139       for (k=0; k<npeaks; k++) {
140         MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
141       }
142         
143       for (k=0; k<npeaks; k++) {
144          if (idx[k] < 0) continue; //removed peak
145          AliITSclusterV2 c;
146          MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
147          //mi change
148          Int_t milab[10];
149          for (Int_t ilab=0;ilab<10;ilab++){
150            milab[ilab]=-2;
151          }
152          Int_t maxi=0,mini=0,maxj=0,minj=0;
153          //AliBin *bmax=&bins[s][idx[k]];
154          //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
155          Float_t max=3;
156          for (Int_t di=-2; di<=2;di++)
157            for (Int_t dj=-3;dj<=3;dj++){
158              Int_t index = idx[k]+di+dj*nzBins;
159              if (index<0) continue;
160              if (index>=nMaxBin) continue;
161              AliBin *b=&bins[s][index];
162              if (TMath::Abs(b->GetQ())>max){
163                if (di>maxi) maxi=di;
164                if (di<mini) mini=di;
165                if (dj>maxj) maxj=dj;
166                if (dj<minj) minj=dj;
167                //
168                if(digits) {
169                  if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
170                    AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
171                    for (Int_t itrack=0;itrack<10;itrack++){
172                      Int_t track = (d->GetTracks())[itrack];
173                      if (track>=0) {
174                        AddLabel(milab, track); 
175                      }
176                    }
177                  }
178                }
179              }
180            }
181          
182          /* 
183             Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
184             Float_t w=par->GetPadPitchWidth(sec);
185             c.SetSigmaY2(s2);
186             if (s2 != 0.) {
187             c.SetSigmaY2(c.GetSigmaY2()*0.108);
188             if (sec<par->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
189             }    
190             s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
191             w=par->GetZWidth();
192             c.SetSigmaZ2(s2);
193             
194             if (s2 != 0.) {
195             c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
196             if (sec<par->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
197             }
198          */
199
200          c.SetSigmaY2(0.0030*0.0030);
201          c.SetSigmaZ2(0.0020*0.0020);
202          c.SetDetectorIndex(fNdet[fModule]);
203
204          Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
205          y/=q; z/=q;
206          //
207          //Float_t s2 = c.GetSigmaY2()/c.GetQ() - y*y;
208          // c.SetSigmaY2(s2);
209          //s2 = c.GetSigmaZ2()/c.GetQ() - z*z;
210          //c.SetSigmaZ2(s2);
211          //
212          y=(y-0.5)*fYpitchSDD;
213          y-=fHwSDD;
214          y-=fYoffSDD;  //delay ?
215          if (s) y=-y;
216
217          z=(z-0.5)*fZpitchSDD;
218          z-=fHlSDD;
219
220          y=-(-y+fYshift[fModule]);
221          z=  -z+fZshift[fModule];
222          c.SetY(y);
223          c.SetZ(z);
224          c.SetNy(maxj-minj+1);
225          c.SetNz(maxi-mini+1);
226          c.SetType(npeaks);
227          c.SetQ(q/12.7);  //to be consistent with the SSD charges
228
229          if (c.GetQ() < 20.) continue; //noise cluster
230          
231          if (digits) {    
232            //      AliBin *b=&bins[s][idx[k]];
233            //      AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
234            {
235              //Int_t lab[3];
236              //lab[0]=(d->GetTracks())[0];
237              //lab[1]=(d->GetTracks())[1];
238              //lab[2]=(d->GetTracks())[2];
239              //CheckLabels(lab);
240              CheckLabels2(milab); 
241              c.SetLabel(milab[0],0);
242              c.SetLabel(milab[1],1);
243              c.SetLabel(milab[2],2);
244              c.SetLayer(fNlayer[fModule]);
245            }
246          }
247          if(clusters) new (cl[ncl]) AliITSclusterV2(c); 
248          else {
249            fITS->AddClusterV2(c);
250          }
251          ncl++;
252       }
253     }
254 }
255
256
257
258 void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
259     //------------------------------------------------------------
260   // This function creates ITS clusters from raw data
261   //------------------------------------------------------------
262   rawReader->Reset();
263   AliITSRawStreamSDD inputSDD(rawReader);
264   FindClustersSDD(&inputSDD,clusters);
265
266 }
267
268 void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input, 
269                                         TClonesArray** clusters) 
270 {
271   //------------------------------------------------------------
272   // Actual SDD cluster finder for raw data
273   //------------------------------------------------------------
274   Int_t nClustersSDD = 0;
275   Int_t kNzBins = fNzSDD + 2;
276   Int_t kMaxBin = kNzBins * (fNySDD+2);
277   AliBin* bins[2] = {NULL, NULL};
278
279   // read raw data input stream
280   while (kTRUE) {
281     Bool_t next = input->Next();
282     if (!next || input->IsNewModule()) {
283       Int_t iModule = input->GetPrevModuleID();
284
285       // when all data from a module was read, search for clusters
286       if (bins[0]) { 
287         clusters[iModule] = new TClonesArray("AliITSclusterV2");
288         fModule = iModule;
289         FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
290         Int_t nClusters = clusters[iModule]->GetEntriesFast();
291         nClustersSDD += nClusters;
292         delete[] bins[0];
293         delete[] bins[1];
294       }
295
296       if (!next) break;
297       bins[0] = new AliBin[kMaxBin];
298       bins[1] = new AliBin[kMaxBin];
299     }
300
301     // fill the current digit into the bins array
302     if(input->GetSignal()>=3) {
303       Int_t iz = input->GetCoord1()+1;
304       Int_t side = ((iz <= fNzSDD) ? 0 : 1);
305       iz -= side*fNzSDD;
306       Int_t index = (input->GetCoord2()+1) * kNzBins + iz;
307       bins[side][index].SetQ(input->GetSignal());
308       bins[side][index].SetMask(1);
309       bins[side][index].SetIndex(index);
310     }
311   }
312
313   Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
314
315 }
316
317