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