For macosx: add GLU to external libs.
[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"
404c1c29 28#include "AliITSRawStreamSDDv3.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];
404c1c29 71 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
72
04366a57 73 AliITSdigitSDD *d=0;
74 Int_t i, ndigits=digits->GetEntriesFast();
75 for (i=0; i<ndigits; i++) {
76 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
404c1c29 77 Float_t baseline = cal->GetBaseline(d->GetCoord1());
78
04366a57 79 Int_t y=d->GetCoord2()+1; //y
80 Int_t z=d->GetCoord1()+1; //z
81 Int_t q=d->GetSignal();
404c1c29 82
83 if(q<cal->GetThresholdAnode(d->GetCoord1())) continue;
84 if(q>baseline) q-=(Int_t)baseline;
85 else q=0;
86
87 //if (q<3) continue;
04366a57 88
89 if (z <= fNzSDD) {
90 bins[0][y*kNzBins+z].SetQ(q);
91 bins[0][y*kNzBins+z].SetMask(1);
92 bins[0][y*kNzBins+z].SetIndex(i);
93 } else {
94 z-=fNzSDD;
95 bins[1][y*kNzBins+z].SetQ(q);
96 bins[1][y*kNzBins+z].SetMask(1);
97 bins[1][y*kNzBins+z].SetIndex(i);
98 }
99 }
100
101 FindClustersSDD(bins, kMAXBIN, kNzBins, digits);
102
103 delete[] bins[0];
104 delete[] bins[1];
105
106}
107
108void AliITSClusterFinderV2SDD::
109FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
110 TClonesArray *digits, TClonesArray *clusters) {
111 //------------------------------------------------------------
112 // Actual SDD cluster finder
113 //------------------------------------------------------------
404c1c29 114 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
04366a57 115 Int_t ncl=0;
116 TClonesArray &cl=*clusters;
117 for (Int_t s=0; s<2; s++)
118 for (Int_t i=0; i<nMaxBin; i++) {
119 if (bins[s][i].IsUsed()) continue;
120 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
121 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
122
123 if (npeaks>30) continue;
124 if (npeaks==0) continue;
125
126 Int_t k,l;
127 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
128 if (idx[k] < 0) continue; //this peak is already removed
129 for (l=k+1; l<npeaks; l++) {
130 if (idx[l] < 0) continue; //this peak is already removed
131 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
132 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
133 Int_t di=TMath::Abs(ki - li);
134 Int_t dj=TMath::Abs(kj - lj);
135 if (di>1 || dj>1) continue;
136 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
137 msk[l]=msk[k];
138 idx[l]*=-1;
139 } else {
140 msk[k]=msk[l];
141 idx[k]*=-1;
142 break;
143 }
144 }
145 }
146
147 for (k=0; k<npeaks; k++) {
148 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
149 }
150
151 for (k=0; k<npeaks; k++) {
152 if (idx[k] < 0) continue; //removed peak
75fb37cc 153 AliITSRecPoint c;
04366a57 154 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
155 //mi change
156 Int_t milab[10];
157 for (Int_t ilab=0;ilab<10;ilab++){
158 milab[ilab]=-2;
159 }
160 Int_t maxi=0,mini=0,maxj=0,minj=0;
161 //AliBin *bmax=&bins[s][idx[k]];
162 //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
163 Float_t max=3;
164 for (Int_t di=-2; di<=2;di++)
165 for (Int_t dj=-3;dj<=3;dj++){
166 Int_t index = idx[k]+di+dj*nzBins;
167 if (index<0) continue;
168 if (index>=nMaxBin) continue;
169 AliBin *b=&bins[s][index];
170 if (TMath::Abs(b->GetQ())>max){
171 if (di>maxi) maxi=di;
172 if (di<mini) mini=di;
173 if (dj>maxj) maxj=dj;
174 if (dj<minj) minj=dj;
175 //
176 if(digits) {
177 if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
178 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
179 for (Int_t itrack=0;itrack<10;itrack++){
180 Int_t track = (d->GetTracks())[itrack];
181 if (track>=0) {
182 AddLabel(milab, track);
183 }
184 }
185 }
186 }
187 }
188 }
189
190 /*
191 Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
192 Float_t w=par->GetPadPitchWidth(sec);
193 c.SetSigmaY2(s2);
194 if (s2 != 0.) {
195 c.SetSigmaY2(c.GetSigmaY2()*0.108);
196 if (sec<par->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
197 }
198 s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
199 w=par->GetZWidth();
200 c.SetSigmaZ2(s2);
201
202 if (s2 != 0.) {
203 c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
204 if (sec<par->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
205 }
206 */
207
208 c.SetSigmaY2(0.0030*0.0030);
209 c.SetSigmaZ2(0.0020*0.0020);
210 c.SetDetectorIndex(fNdet[fModule]);
211
212 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
213 y/=q; z/=q;
214 //
215 //Float_t s2 = c.GetSigmaY2()/c.GetQ() - y*y;
216 // c.SetSigmaY2(s2);
217 //s2 = c.GetSigmaZ2()/c.GetQ() - z*z;
218 //c.SetSigmaZ2(s2);
219 //
404c1c29 220
221 Float_t yyyy = y;
222 //y=(y-0.5)*fYpitchSDD;
223 //y-=fHwSDD;
224 //y-=fYoffSDD; //delay ?
225 //if (s) y=-y;
04366a57 226
227 z=(z-0.5)*fZpitchSDD;
228 z-=fHlSDD;
404c1c29 229 Float_t zdet = z;
230 // y=-(-y+fYshift[fModule]);
231 // z= -z+fZshift[fModule];
00a7cc50 232 // c.SetY(y);
233 // c.SetZ(z);
404c1c29 234 Float_t xdet = cal->GetDriftPath((yyyy-0.5)*25,0);
235 xdet=xdet/10000.-fHwSDD-fYoffSDD;
236 if (s) xdet=-xdet;
237
238 CorrectPosition(zdet,xdet);
239
240 y=-(-xdet+fYshift[fModule]);
241 z= -zdet+fZshift[fModule];
242
75fb37cc 243 c.SetY(y);
244 c.SetZ(z);
04366a57 245 c.SetNy(maxj-minj+1);
246 c.SetNz(maxi-mini+1);
247 c.SetType(npeaks);
404c1c29 248 c.SetQ(q/12.7); //this WAS consistent with SSD. To be reassessed
249 // 23-MAR-2007
04366a57 250
404c1c29 251 //if (c.GetQ() < 20.) continue; //noise cluster
04366a57 252
253 if (digits) {
254 // AliBin *b=&bins[s][idx[k]];
255 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
256 {
257 //Int_t lab[3];
258 //lab[0]=(d->GetTracks())[0];
259 //lab[1]=(d->GetTracks())[1];
260 //lab[2]=(d->GetTracks())[2];
261 //CheckLabels(lab);
262 CheckLabels2(milab);
263 c.SetLabel(milab[0],0);
264 c.SetLabel(milab[1],1);
265 c.SetLabel(milab[2],2);
266 c.SetLayer(fNlayer[fModule]);
75fb37cc 267 UShort_t id=AliAlignObj::LayerToVolUID(fNlayer[fModule]+AliAlignObj::kSPD1,fNdet[fModule]);
268 c.SetVolumeId(id);
04366a57 269 }
270 }
00a7cc50 271 if(clusters) new (cl[ncl]) AliITSRecPoint(c);
04366a57 272 else {
00a7cc50 273 fDetTypeRec->AddRecPoint(c);
04366a57 274 }
275 ncl++;
276 }
277 }
278}
279
280
281
282void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
283 //------------------------------------------------------------
284 // This function creates ITS clusters from raw data
285 //------------------------------------------------------------
286 rawReader->Reset();
404c1c29 287 AliITSRawStreamSDDv3 inputSDD(rawReader);
04366a57 288 FindClustersSDD(&inputSDD,clusters);
289
290}
291
292void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input,
293 TClonesArray** clusters)
294{
295 //------------------------------------------------------------
296 // Actual SDD cluster finder for raw data
297 //------------------------------------------------------------
298 Int_t nClustersSDD = 0;
299 Int_t kNzBins = fNzSDD + 2;
300 Int_t kMaxBin = kNzBins * (fNySDD+2);
d7d9347b 301 AliBin *binsSDDInit = new AliBin[kMaxBin];
302 AliBin *binsSDD1 = new AliBin[kMaxBin];
303 AliBin *binsSDD2 = new AliBin[kMaxBin];
04366a57 304 AliBin* bins[2] = {NULL, NULL};
305
306 // read raw data input stream
307 while (kTRUE) {
308 Bool_t next = input->Next();
309 if (!next || input->IsNewModule()) {
310 Int_t iModule = input->GetPrevModuleID();
311
312 // when all data from a module was read, search for clusters
313 if (bins[0]) {
00a7cc50 314 clusters[iModule] = new TClonesArray("AliITSRecPoint");
04366a57 315 fModule = iModule;
316 FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
317 Int_t nClusters = clusters[iModule]->GetEntriesFast();
318 nClustersSDD += nClusters;
d7d9347b 319 bins[0] = bins[1] = NULL;
320
04366a57 321 }
322
323 if (!next) break;
d7d9347b 324 bins[0]=binsSDD1;
325 bins[1]=binsSDD2;
326 memcpy(binsSDD1,binsSDDInit,sizeof(AliBin)*kMaxBin);
327 memcpy(binsSDD2,binsSDDInit,sizeof(AliBin)*kMaxBin);
328
04366a57 329 }
330
331 // fill the current digit into the bins array
332 if(input->GetSignal()>=3) {
333 Int_t iz = input->GetCoord1()+1;
334 Int_t side = ((iz <= fNzSDD) ? 0 : 1);
335 iz -= side*fNzSDD;
336 Int_t index = (input->GetCoord2()+1) * kNzBins + iz;
337 bins[side][index].SetQ(input->GetSignal());
338 bins[side][index].SetMask(1);
339 bins[side][index].SetIndex(index);
340 }
341 }
d7d9347b 342 delete[] binsSDD1;
343 delete[] binsSDD2;
344 delete[] binsSDDInit;
04366a57 345
346 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
347
348}
349
350
5bfe44ce 351//_________________________________________________________________________
352void AliITSClusterFinderV2SDD::CorrectPosition(Float_t &z, Float_t&y){
353
354 //correction of coordinates using the maps stored in the DB
355
356 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
357 static const Int_t nbint = cal->GetMapTimeNBin();
358 static const Int_t nbina = cal->Chips()*cal->Channels();
359 Float_t stepa = (GetSeg()->Dpz(0))/10000.; //anode pitch in cm
360 Float_t stept = (GetSeg()->Dx()/cal->GetMapTimeNBin()/2.)/10.;
404c1c29 361
362 Int_t bint = TMath::Abs((Int_t)(y/stept));
363 if(y>=0) bint+=(Int_t)(nbint/2.);
5bfe44ce 364 if(bint>nbint) AliError("Wrong bin number!");
365
404c1c29 366 Int_t bina = TMath::Abs((Int_t)(z/stepa));
367 if(z>=0) bina+=(Int_t)(nbina/2.);
5bfe44ce 368 if(bina>nbina) AliError("Wrong bin number!");
369
370 Float_t devz = cal->GetMapACell(bina,bint)/10000.;
371 Float_t devx = cal->GetMapTCell(bina,bint)/10000.;
404c1c29 372 z+=devz;
373 y+=devx;
5bfe44ce 374
375
376}