update (alberto):
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderV2SDD.cxx
CommitLineData
04366a57 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
04366a57 23
24#include "AliITSClusterFinderV2SDD.h"
00a7cc50 25#include "AliITSRecPoint.h"
7d62fb64 26#include "AliITSDetTypeRec.h"
04366a57 27#include "AliRawReader.h"
28#include "AliITSRawStreamSDD.h"
5bfe44ce 29#include "AliITSCalibrationSDD.h"
30#include "AliITSDetTypeRec.h"
31#include "AliITSsegmentationSDD.h"
04366a57 32#include <TClonesArray.h>
04366a57 33#include "AliITSdigitSDD.h"
34
35ClassImp(AliITSClusterFinderV2SDD)
36
37extern AliRun *gAlice;
38
8ba39da9 39AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD(AliITSDetTypeRec* dettyp):AliITSClusterFinderV2(dettyp){
04366a57 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
54void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
55
56 //Find clusters V2
57 SetModule(mod);
58 FindClustersSDD(fDigits);
59
60}
61
62void 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
101void AliITSClusterFinderV2SDD::
102FindClustersSDD(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
00a7cc50 145 AliITSRecPoint c(fDetTypeRec->GetITSgeom());
04366a57 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];
00a7cc50 222 // c.SetY(y);
223 // c.SetZ(z);
5bfe44ce 224 CorrectPosition(z,y);
00a7cc50 225 c.SetYZ(fModule,y,z);
04366a57 226 c.SetNy(maxj-minj+1);
227 c.SetNz(maxi-mini+1);
228 c.SetType(npeaks);
229 c.SetQ(q/12.7); //to be consistent with the SSD charges
230
231 if (c.GetQ() < 20.) continue; //noise cluster
232
233 if (digits) {
234 // AliBin *b=&bins[s][idx[k]];
235 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
236 {
237 //Int_t lab[3];
238 //lab[0]=(d->GetTracks())[0];
239 //lab[1]=(d->GetTracks())[1];
240 //lab[2]=(d->GetTracks())[2];
241 //CheckLabels(lab);
242 CheckLabels2(milab);
243 c.SetLabel(milab[0],0);
244 c.SetLabel(milab[1],1);
245 c.SetLabel(milab[2],2);
246 c.SetLayer(fNlayer[fModule]);
247 }
248 }
00a7cc50 249 if(clusters) new (cl[ncl]) AliITSRecPoint(c);
04366a57 250 else {
00a7cc50 251 fDetTypeRec->AddRecPoint(c);
04366a57 252 }
253 ncl++;
254 }
255 }
256}
257
258
259
260void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
261 //------------------------------------------------------------
262 // This function creates ITS clusters from raw data
263 //------------------------------------------------------------
264 rawReader->Reset();
265 AliITSRawStreamSDD inputSDD(rawReader);
266 FindClustersSDD(&inputSDD,clusters);
267
268}
269
270void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input,
271 TClonesArray** clusters)
272{
273 //------------------------------------------------------------
274 // Actual SDD cluster finder for raw data
275 //------------------------------------------------------------
276 Int_t nClustersSDD = 0;
277 Int_t kNzBins = fNzSDD + 2;
278 Int_t kMaxBin = kNzBins * (fNySDD+2);
d7d9347b 279 AliBin *binsSDDInit = new AliBin[kMaxBin];
280 AliBin *binsSDD1 = new AliBin[kMaxBin];
281 AliBin *binsSDD2 = new AliBin[kMaxBin];
04366a57 282 AliBin* bins[2] = {NULL, NULL};
283
284 // read raw data input stream
285 while (kTRUE) {
286 Bool_t next = input->Next();
287 if (!next || input->IsNewModule()) {
288 Int_t iModule = input->GetPrevModuleID();
289
290 // when all data from a module was read, search for clusters
291 if (bins[0]) {
00a7cc50 292 clusters[iModule] = new TClonesArray("AliITSRecPoint");
04366a57 293 fModule = iModule;
294 FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
295 Int_t nClusters = clusters[iModule]->GetEntriesFast();
296 nClustersSDD += nClusters;
d7d9347b 297 bins[0] = bins[1] = NULL;
298
04366a57 299 }
300
301 if (!next) break;
d7d9347b 302 bins[0]=binsSDD1;
303 bins[1]=binsSDD2;
304 memcpy(binsSDD1,binsSDDInit,sizeof(AliBin)*kMaxBin);
305 memcpy(binsSDD2,binsSDDInit,sizeof(AliBin)*kMaxBin);
306
04366a57 307 }
308
309 // fill the current digit into the bins array
310 if(input->GetSignal()>=3) {
311 Int_t iz = input->GetCoord1()+1;
312 Int_t side = ((iz <= fNzSDD) ? 0 : 1);
313 iz -= side*fNzSDD;
314 Int_t index = (input->GetCoord2()+1) * kNzBins + iz;
315 bins[side][index].SetQ(input->GetSignal());
316 bins[side][index].SetMask(1);
317 bins[side][index].SetIndex(index);
318 }
319 }
d7d9347b 320 delete[] binsSDD1;
321 delete[] binsSDD2;
322 delete[] binsSDDInit;
04366a57 323
324 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
325
326}
327
328
5bfe44ce 329//_________________________________________________________________________
330void AliITSClusterFinderV2SDD::CorrectPosition(Float_t &z, Float_t&y){
331
332 //correction of coordinates using the maps stored in the DB
333
334 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
335 static const Int_t nbint = cal->GetMapTimeNBin();
336 static const Int_t nbina = cal->Chips()*cal->Channels();
337 Float_t stepa = (GetSeg()->Dpz(0))/10000.; //anode pitch in cm
338 Float_t stept = (GetSeg()->Dx()/cal->GetMapTimeNBin()/2.)/10.;
339 Float_t xdet,zdet;
340 fDetTypeRec->GetITSgeom()->TrackingV2ToDetL(fModule,y,z,xdet,zdet);
341
342 Int_t bint = TMath::Abs((Int_t)(xdet/stept));
343 if(xdet>=0) bint+=(Int_t)(nbint/2.);
344 if(bint>nbint) AliError("Wrong bin number!");
345
346 Int_t bina = TMath::Abs((Int_t)(zdet/stepa));
347 if(zdet>=0) bina+=(Int_t)(nbina/2.);
348 if(bina>nbina) AliError("Wrong bin number!");
349
350 Float_t devz = cal->GetMapACell(bina,bint)/10000.;
351 Float_t devx = cal->GetMapTCell(bina,bint)/10000.;
352 zdet+=devz;
353 xdet+=devx;
354 fDetTypeRec->GetITSgeom()->DetLToTrackingV2(fModule,xdet,zdet,y,z);
355
356
357}