Bug fix: x and z local coordinates filled also with AliITSClusterFinderSXD clusterers
[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"
75fb37cc 34#include "AliAlignObj.h"
04366a57 35
36ClassImp(AliITSClusterFinderV2SDD)
37
e56160b8 38AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD(AliITSDetTypeRec* dettyp):AliITSClusterFinderV2(dettyp),
39fNySDD(256),
40fNzSDD(256),
41fYpitchSDD(0.01825),
42fZpitchSDD(0.02940),
43fHwSDD(3.5085),
44fHlSDD(3.7632),
45fYoffSDD(0.0425){
04366a57 46
47 //Default constructor
48
04366a57 49
50}
51
52
53void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
54
55 //Find clusters V2
56 SetModule(mod);
57 FindClustersSDD(fDigits);
58
59}
60
61void AliITSClusterFinderV2SDD::FindClustersSDD(TClonesArray *digits) {
62 //------------------------------------------------------------
63 // Actual SDD cluster finder
64 //------------------------------------------------------------
65 Int_t kNzBins = fNzSDD + 2;
66 const Int_t kMAXBIN=kNzBins*(fNySDD+2);
67
68 AliBin *bins[2];
69 bins[0]=new AliBin[kMAXBIN];
70 bins[1]=new AliBin[kMAXBIN];
71
72 AliITSdigitSDD *d=0;
73 Int_t i, ndigits=digits->GetEntriesFast();
74 for (i=0; i<ndigits; i++) {
75 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
76 Int_t y=d->GetCoord2()+1; //y
77 Int_t z=d->GetCoord1()+1; //z
78 Int_t q=d->GetSignal();
79 if (q<3) continue;
80
81 if (z <= fNzSDD) {
82 bins[0][y*kNzBins+z].SetQ(q);
83 bins[0][y*kNzBins+z].SetMask(1);
84 bins[0][y*kNzBins+z].SetIndex(i);
85 } else {
86 z-=fNzSDD;
87 bins[1][y*kNzBins+z].SetQ(q);
88 bins[1][y*kNzBins+z].SetMask(1);
89 bins[1][y*kNzBins+z].SetIndex(i);
90 }
91 }
92
93 FindClustersSDD(bins, kMAXBIN, kNzBins, digits);
94
95 delete[] bins[0];
96 delete[] bins[1];
97
98}
99
100void AliITSClusterFinderV2SDD::
101FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
102 TClonesArray *digits, TClonesArray *clusters) {
103 //------------------------------------------------------------
104 // Actual SDD cluster finder
105 //------------------------------------------------------------
106 Int_t ncl=0;
107 TClonesArray &cl=*clusters;
108 for (Int_t s=0; s<2; s++)
109 for (Int_t i=0; i<nMaxBin; i++) {
110 if (bins[s][i].IsUsed()) continue;
111 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
112 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
113
114 if (npeaks>30) continue;
115 if (npeaks==0) continue;
116
117 Int_t k,l;
118 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
119 if (idx[k] < 0) continue; //this peak is already removed
120 for (l=k+1; l<npeaks; l++) {
121 if (idx[l] < 0) continue; //this peak is already removed
122 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
123 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
124 Int_t di=TMath::Abs(ki - li);
125 Int_t dj=TMath::Abs(kj - lj);
126 if (di>1 || dj>1) continue;
127 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
128 msk[l]=msk[k];
129 idx[l]*=-1;
130 } else {
131 msk[k]=msk[l];
132 idx[k]*=-1;
133 break;
134 }
135 }
136 }
137
138 for (k=0; k<npeaks; k++) {
139 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
140 }
141
142 for (k=0; k<npeaks; k++) {
143 if (idx[k] < 0) continue; //removed peak
75fb37cc 144 AliITSRecPoint c;
04366a57 145 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
146 //mi change
147 Int_t milab[10];
148 for (Int_t ilab=0;ilab<10;ilab++){
149 milab[ilab]=-2;
150 }
151 Int_t maxi=0,mini=0,maxj=0,minj=0;
152 //AliBin *bmax=&bins[s][idx[k]];
153 //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
154 Float_t max=3;
155 for (Int_t di=-2; di<=2;di++)
156 for (Int_t dj=-3;dj<=3;dj++){
157 Int_t index = idx[k]+di+dj*nzBins;
158 if (index<0) continue;
159 if (index>=nMaxBin) continue;
160 AliBin *b=&bins[s][index];
161 if (TMath::Abs(b->GetQ())>max){
162 if (di>maxi) maxi=di;
163 if (di<mini) mini=di;
164 if (dj>maxj) maxj=dj;
165 if (dj<minj) minj=dj;
166 //
167 if(digits) {
168 if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
169 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
170 for (Int_t itrack=0;itrack<10;itrack++){
171 Int_t track = (d->GetTracks())[itrack];
172 if (track>=0) {
173 AddLabel(milab, track);
174 }
175 }
176 }
177 }
178 }
179 }
180
181 /*
182 Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
183 Float_t w=par->GetPadPitchWidth(sec);
184 c.SetSigmaY2(s2);
185 if (s2 != 0.) {
186 c.SetSigmaY2(c.GetSigmaY2()*0.108);
187 if (sec<par->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
188 }
189 s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
190 w=par->GetZWidth();
191 c.SetSigmaZ2(s2);
192
193 if (s2 != 0.) {
194 c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
195 if (sec<par->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
196 }
197 */
198
199 c.SetSigmaY2(0.0030*0.0030);
200 c.SetSigmaZ2(0.0020*0.0020);
201 c.SetDetectorIndex(fNdet[fModule]);
202
203 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
204 y/=q; z/=q;
205 //
206 //Float_t s2 = c.GetSigmaY2()/c.GetQ() - y*y;
207 // c.SetSigmaY2(s2);
208 //s2 = c.GetSigmaZ2()/c.GetQ() - z*z;
209 //c.SetSigmaZ2(s2);
210 //
211 y=(y-0.5)*fYpitchSDD;
212 y-=fHwSDD;
213 y-=fYoffSDD; //delay ?
214 if (s) y=-y;
215
216 z=(z-0.5)*fZpitchSDD;
217 z-=fHlSDD;
218
219 y=-(-y+fYshift[fModule]);
220 z= -z+fZshift[fModule];
00a7cc50 221 // c.SetY(y);
222 // c.SetZ(z);
5bfe44ce 223 CorrectPosition(z,y);
75fb37cc 224 c.SetY(y);
225 c.SetZ(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]);
75fb37cc 247 UShort_t id=AliAlignObj::LayerToVolUID(fNlayer[fModule]+AliAlignObj::kSPD1,fNdet[fModule]);
248 c.SetVolumeId(id);
04366a57 249 }
250 }
00a7cc50 251 if(clusters) new (cl[ncl]) AliITSRecPoint(c);
04366a57 252 else {
00a7cc50 253 fDetTypeRec->AddRecPoint(c);
04366a57 254 }
255 ncl++;
256 }
257 }
258}
259
260
261
262void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
263 //------------------------------------------------------------
264 // This function creates ITS clusters from raw data
265 //------------------------------------------------------------
266 rawReader->Reset();
267 AliITSRawStreamSDD inputSDD(rawReader);
268 FindClustersSDD(&inputSDD,clusters);
269
270}
271
272void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input,
273 TClonesArray** clusters)
274{
275 //------------------------------------------------------------
276 // Actual SDD cluster finder for raw data
277 //------------------------------------------------------------
278 Int_t nClustersSDD = 0;
279 Int_t kNzBins = fNzSDD + 2;
280 Int_t kMaxBin = kNzBins * (fNySDD+2);
d7d9347b 281 AliBin *binsSDDInit = new AliBin[kMaxBin];
282 AliBin *binsSDD1 = new AliBin[kMaxBin];
283 AliBin *binsSDD2 = new AliBin[kMaxBin];
04366a57 284 AliBin* bins[2] = {NULL, NULL};
285
286 // read raw data input stream
287 while (kTRUE) {
288 Bool_t next = input->Next();
289 if (!next || input->IsNewModule()) {
290 Int_t iModule = input->GetPrevModuleID();
291
292 // when all data from a module was read, search for clusters
293 if (bins[0]) {
00a7cc50 294 clusters[iModule] = new TClonesArray("AliITSRecPoint");
04366a57 295 fModule = iModule;
296 FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
297 Int_t nClusters = clusters[iModule]->GetEntriesFast();
298 nClustersSDD += nClusters;
d7d9347b 299 bins[0] = bins[1] = NULL;
300
04366a57 301 }
302
303 if (!next) break;
d7d9347b 304 bins[0]=binsSDD1;
305 bins[1]=binsSDD2;
306 memcpy(binsSDD1,binsSDDInit,sizeof(AliBin)*kMaxBin);
307 memcpy(binsSDD2,binsSDDInit,sizeof(AliBin)*kMaxBin);
308
04366a57 309 }
310
311 // fill the current digit into the bins array
312 if(input->GetSignal()>=3) {
313 Int_t iz = input->GetCoord1()+1;
314 Int_t side = ((iz <= fNzSDD) ? 0 : 1);
315 iz -= side*fNzSDD;
316 Int_t index = (input->GetCoord2()+1) * kNzBins + iz;
317 bins[side][index].SetQ(input->GetSignal());
318 bins[side][index].SetMask(1);
319 bins[side][index].SetIndex(index);
320 }
321 }
d7d9347b 322 delete[] binsSDD1;
323 delete[] binsSDD2;
324 delete[] binsSDDInit;
04366a57 325
326 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
327
328}
329
330
5bfe44ce 331//_________________________________________________________________________
332void AliITSClusterFinderV2SDD::CorrectPosition(Float_t &z, Float_t&y){
333
334 //correction of coordinates using the maps stored in the DB
335
336 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
337 static const Int_t nbint = cal->GetMapTimeNBin();
338 static const Int_t nbina = cal->Chips()*cal->Channels();
339 Float_t stepa = (GetSeg()->Dpz(0))/10000.; //anode pitch in cm
340 Float_t stept = (GetSeg()->Dx()/cal->GetMapTimeNBin()/2.)/10.;
341 Float_t xdet,zdet;
342 fDetTypeRec->GetITSgeom()->TrackingV2ToDetL(fModule,y,z,xdet,zdet);
343
344 Int_t bint = TMath::Abs((Int_t)(xdet/stept));
345 if(xdet>=0) bint+=(Int_t)(nbint/2.);
346 if(bint>nbint) AliError("Wrong bin number!");
347
348 Int_t bina = TMath::Abs((Int_t)(zdet/stepa));
349 if(zdet>=0) bina+=(Int_t)(nbina/2.);
350 if(bina>nbina) AliError("Wrong bin number!");
351
352 Float_t devz = cal->GetMapACell(bina,bint)/10000.;
353 Float_t devx = cal->GetMapTCell(bina,bint)/10000.;
354 zdet+=devz;
355 xdet+=devx;
356 fDetTypeRec->GetITSgeom()->DetLToTrackingV2(fModule,xdet,zdet,y,z);
357
358
359}