SPD Fast-OR bits decoding (H. Tydesjo)
[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 **************************************************************************/
d76cb3ad 15
16/* $Id$*/
17
04366a57 18////////////////////////////////////////////////////////////////////////////
19// Implementation of the ITS clusterer V2 class //
20// //
21// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch //
22// //
23///////////////////////////////////////////////////////////////////////////
24
25
04366a57 26
ae485645 27#include <TClonesArray.h>
04366a57 28#include "AliITSClusterFinderV2SDD.h"
00a7cc50 29#include "AliITSRecPoint.h"
7d62fb64 30#include "AliITSDetTypeRec.h"
04366a57 31#include "AliRawReader.h"
0599a018 32#include "AliITSRawStreamSDD.h"
5bfe44ce 33#include "AliITSCalibrationSDD.h"
253e68a0 34#include "AliITSresponseSDD.h"
5bfe44ce 35#include "AliITSDetTypeRec.h"
debf7b78 36#include "AliITSReconstructor.h"
5bfe44ce 37#include "AliITSsegmentationSDD.h"
04366a57 38#include "AliITSdigitSDD.h"
b4704be3 39#include "AliITSgeomTGeo.h"
debf7b78 40
04366a57 41ClassImp(AliITSClusterFinderV2SDD)
42
4952f440 43AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD(AliITSDetTypeRec* dettyp):AliITSClusterFinderV2(dettyp)
a66a0eb6 44{
04366a57 45
46 //Default constructor
47
04366a57 48}
49
50
51void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
52
53 //Find clusters V2
54 SetModule(mod);
55 FindClustersSDD(fDigits);
56
57}
58
59void AliITSClusterFinderV2SDD::FindClustersSDD(TClonesArray *digits) {
60 //------------------------------------------------------------
61 // Actual SDD cluster finder
62 //------------------------------------------------------------
4952f440 63 Int_t nAnodes = GetSeg()->NpzHalf();
64 Int_t nzBins = nAnodes+2;
65 Int_t nTimeBins = GetSeg()->Npx();
66 Int_t nxBins = nTimeBins+2;
f6b6d58e 67 const Int_t kMaxBin=nzBins*nxBins;
04366a57 68
69 AliBin *bins[2];
4952f440 70 bins[0]=new AliBin[kMaxBin];
71 bins[1]=new AliBin[kMaxBin];
404c1c29 72 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
9c7f5947 73 if(cal==0){
74 AliError(Form("Calibration object not present for SDD module %d\n",fModule));
75 return;
76 }
83ec5e27 77
04366a57 78 AliITSdigitSDD *d=0;
79 Int_t i, ndigits=digits->GetEntriesFast();
80 for (i=0; i<ndigits; i++) {
81 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
20f3f947 82 Int_t ian=d->GetCoord1();
83 Int_t itb=d->GetCoord2();
84 Int_t iSide=0;
85 if (ian >= nAnodes) iSide=1;
86 Float_t gain=cal->GetChannelGain(ian);
83ec5e27 87 Float_t charge=d->GetSignal(); // returns expanded signal
88 // (10 bit, low threshold already added)
20f3f947 89 Float_t baseline = cal->GetBaseline(ian);
90 if(charge>baseline) charge-=baseline;
91 else charge=0;
5683bd96 92
9c7f5947 93 if(gain>0.){ // Bad channels have gain=0.
94 charge/=gain;
20f3f947 95 if(charge<cal->GetThresholdAnode(ian)) continue;
9c7f5947 96 Int_t q=(Int_t)(charge+0.5);
20f3f947 97 Int_t y=itb+1;
98 Int_t z=ian+1;
9c7f5947 99 if (z <= nAnodes){
100 bins[0][y*nzBins+z].SetQ(q);
101 bins[0][y*nzBins+z].SetMask(1);
102 bins[0][y*nzBins+z].SetIndex(i);
103 } else {
104 z-=nAnodes;
105 bins[1][y*nzBins+z].SetQ(q);
106 bins[1][y*nzBins+z].SetMask(1);
107 bins[1][y*nzBins+z].SetIndex(i);
108 }
04366a57 109 }
110 }
111
4952f440 112 FindClustersSDD(bins, kMaxBin, nzBins, digits);
04366a57 113
114 delete[] bins[0];
115 delete[] bins[1];
116
117}
118
119void AliITSClusterFinderV2SDD::
120FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
121 TClonesArray *digits, TClonesArray *clusters) {
122 //------------------------------------------------------------
123 // Actual SDD cluster finder
124 //------------------------------------------------------------
b4704be3 125
debf7b78 126 static AliITSRecoParam *repa = NULL;
127 if(!repa){
128 repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
129 if(!repa){
ed446fa3 130 repa = AliITSRecoParam::GetHighFluxParam();
debf7b78 131 AliWarning("Using default AliITSRecoParam class");
132 }
133 }
b4704be3 134 const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(fModule);
404c1c29 135 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
9c7f5947 136 if(cal==0){
137 AliError(Form("Calibration object not present for SDD module %d\n",fModule));
138 return;
139 }
04366a57 140 Int_t ncl=0;
141 TClonesArray &cl=*clusters;
142 for (Int_t s=0; s<2; s++)
143 for (Int_t i=0; i<nMaxBin; i++) {
e3ee4984 144 NoiseSuppress(i,s,nzBins,bins[s],cal);
04366a57 145 if (bins[s][i].IsUsed()) continue;
146 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
147 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
148
149 if (npeaks>30) continue;
150 if (npeaks==0) continue;
151
152 Int_t k,l;
153 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
154 if (idx[k] < 0) continue; //this peak is already removed
155 for (l=k+1; l<npeaks; l++) {
f6b6d58e 156 if (idx[l] < 0) continue; //this peak is already removed
157 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
158 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
159 Int_t di=TMath::Abs(ki - li);
160 Int_t dj=TMath::Abs(kj - lj);
161 if (di>1 || dj>1) continue;
162 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
163 msk[l]=msk[k];
164 idx[l]*=-1;
165 } else {
166 msk[k]=msk[l];
167 idx[k]*=-1;
168 break;
169 }
04366a57 170 }
171 }
172
173 for (k=0; k<npeaks; k++) {
debf7b78 174 if(repa->GetUseUnfoldingInClusterFinderSDD()==kFALSE) msk[k]=msk[0];
04366a57 175 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
176 }
177
178 for (k=0; k<npeaks; k++) {
f6b6d58e 179 if (idx[k] < 0) continue; //removed peak
180 AliITSRecPoint c;
181 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
182 //mi change
183 Int_t milab[10];
184 for (Int_t ilab=0;ilab<10;ilab++){
185 milab[ilab]=-2;
186 }
187 Int_t maxi=0,mini=0,maxj=0,minj=0;
188 //AliBin *bmax=&bins[s][idx[k]];
189 //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
190
191 for (Int_t di=-2; di<=2;di++){
192 for (Int_t dj=-3;dj<=3;dj++){
193 Int_t index = idx[k]+di+dj*nzBins;
194 if (index<0) continue;
195 if (index>=nMaxBin) continue;
196 AliBin *b=&bins[s][index];
197 Int_t nAnode=index%nzBins-1;
198 Int_t adcSignal=b->GetQ();
199 if(adcSignal>cal->GetThresholdAnode(nAnode)){
200 if (di>maxi) maxi=di;
201 if (di<mini) mini=di;
202 if (dj>maxj) maxj=dj;
203 if (dj<minj) minj=dj;
204 }
205 //
206 if(digits) {
207 if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
208 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
209 for (Int_t itrack=0;itrack<10;itrack++){
210 Int_t track = (d->GetTracks())[itrack];
211 if (track>=0) {
212 AddLabel(milab, track);
213 }
214 }
215 }
216 }
217 }
218 }
219
220
253e68a0 221 AliITSresponseSDD* rsdd = fDetTypeRec->GetResponseSDD();
222 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
f6b6d58e 223 y/=q; z/=q;
224 Float_t zAnode=z-0.5; // to have anode in range 0.-255. and centered on the mid of the pitch
225 Float_t timebin=y-0.5; // to have time bin in range 0.-255. amd centered on the mid of the bin
226 if(s==1) zAnode += GetSeg()->NpzHalf(); // right side has anodes from 256. to 511.
227 Float_t zdet = GetSeg()->GetLocalZFromAnode(zAnode);
253e68a0 228 Float_t driftTime = GetSeg()->GetDriftTimeFromTb(timebin) - rsdd->GetTimeOffset();
f6b6d58e 229 Float_t driftPathMicron = cal->GetDriftPath(driftTime,zAnode);
230 const Double_t kMicronTocm = 1.0e-4;
231 Float_t xdet=(driftPathMicron-GetSeg()->Dx())*kMicronTocm; // xdet is negative
232 if (s==0) xdet=-xdet; // left side has positive local x
c9a38d3d 233
234 Float_t corrx=0, corrz=0;
235 cal->GetCorrections(zdet,xdet,corrz,corrx,GetSeg());
236 zdet+=corrz;
237 xdet+=corrx;
f6b6d58e 238
239 Double_t loc[3]={xdet,0.,zdet},trk[3]={0.,0.,0.};
240 mT2L->MasterToLocal(loc,trk);
241 y=trk[1];
242 z=trk[2];
243
253e68a0 244 q/=rsdd->GetADC2keV(); //to have MPV 1 MIP = 86.4 KeV
f6b6d58e 245 Float_t hit[5] = {y, z, 0.0030*0.0030, 0.0020*0.0020, q};
246 Int_t info[3] = {maxj-minj+1, maxi-mini+1, fNlayer[fModule]};
247 if (digits) {
248 // AliBin *b=&bins[s][idx[k]];
249 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
250 {
251 //Int_t lab[3];
252 //lab[0]=(d->GetTracks())[0];
253 //lab[1]=(d->GetTracks())[1];
254 //lab[2]=(d->GetTracks())[2];
255 //CheckLabels(lab);
256 CheckLabels2(milab);
257 }
258 }
259 milab[3]=fNdet[fModule];
260
261 AliITSRecPoint cc(milab,hit,info);
262 cc.SetType(npeaks);
263 if(clusters) new (cl[ncl]) AliITSRecPoint(cc);
264 else {
265 fDetTypeRec->AddRecPoint(cc);
266 }
267 ncl++;
04366a57 268 }
269 }
24c98369 270
04366a57 271}
f6b6d58e 272//______________________________________________________________________
04366a57 273void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
274 //------------------------------------------------------------
275 // This function creates ITS clusters from raw data
276 //------------------------------------------------------------
277 rawReader->Reset();
0599a018 278 AliITSRawStreamSDD inputSDD(rawReader);
979b5a5f 279 AliITSDDLModuleMapSDD *ddlmap=(AliITSDDLModuleMapSDD*)fDetTypeRec->GetDDLModuleMapSDD();
280 inputSDD.SetDDLModuleMap(ddlmap);
83ec5e27 281 for(Int_t iddl=0; iddl<AliITSDDLModuleMapSDD::GetNDDLs(); iddl++){
282 for(Int_t icar=0; icar<AliITSDDLModuleMapSDD::GetNModPerDDL();icar++){
283 Int_t iMod=ddlmap->GetModuleNumber(iddl,icar);
284 if(iMod==-1) continue;
285 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(iMod);
286 if(cal==0){
287 AliError(Form("Calibration object not present for SDD module %d\n",iMod));
288 continue;
289 }
253e68a0 290 Bool_t isZeroSupp=cal->GetZeroSupp();
291 if(isZeroSupp){
83ec5e27 292 for(Int_t iSid=0; iSid<2; iSid++) inputSDD.SetZeroSuppLowThreshold(iMod-240,iSid,cal->GetZSLowThreshold(iSid));
293 }else{
294 for(Int_t iSid=0; iSid<2; iSid++) inputSDD.SetZeroSuppLowThreshold(iMod-240,iSid,0);
295 }
296 }
297 }
04366a57 298 FindClustersSDD(&inputSDD,clusters);
299
300}
301
302void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input,
303 TClonesArray** clusters)
304{
305 //------------------------------------------------------------
306 // Actual SDD cluster finder for raw data
307 //------------------------------------------------------------
308 Int_t nClustersSDD = 0;
4952f440 309 Int_t nAnodes = GetSeg()->NpzHalf();
310 Int_t nzBins = nAnodes+2;
311 Int_t nTimeBins = GetSeg()->Npx();
312 Int_t nxBins = nTimeBins+2;
f6b6d58e 313 const Int_t kMaxBin=nzBins*nxBins;
ae485645 314 AliBin *bins[2];
93a93288 315 AliBin *ddlbins[kHybridsPerDDL]; // 12 modules (=24 hybrids) of 1 DDL read "in parallel"
316 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++) ddlbins[iHyb]=new AliBin[kMaxBin];
04366a57 317 // read raw data input stream
14dceddf 318 while (input->Next()) {
e4da2288 319 Int_t iModule = input->GetModuleID();
93a93288 320 if(iModule<0){
321 AliWarning(Form("Invalid SDD module number %d\n", iModule));
322 continue;
323 }
44c5b268 324
14dceddf 325 Int_t iCarlos =((AliITSRawStreamSDD*)input)->GetCarlosId();
326 Int_t iSide = ((AliITSRawStreamSDD*)input)->GetChannel();
327 Int_t iHybrid=iCarlos*2+iSide;
328 if (input->IsCompletedModule()) {
04366a57 329 // when all data from a module was read, search for clusters
44c5b268 330 if(iCarlos<0){
331 AliWarning(Form("Invalid SDD carlos number %d on module %d\n", iCarlos,iModule));
332 continue;
333 }
334 clusters[iModule] = new TClonesArray("AliITSRecPoint");
335 fModule = iModule;
336 bins[0]=ddlbins[iCarlos*2]; // first hybrid of the completed module
337 bins[1]=ddlbins[iCarlos*2+1]; // second hybrid of the completed module
338 FindClustersSDD(bins, kMaxBin, nzBins, NULL, clusters[iModule]);
339 Int_t nClusters = clusters[iModule]->GetEntriesFast();
340 nClustersSDD += nClusters;
341 for(Int_t iBin=0;iBin<kMaxBin; iBin++){
342 ddlbins[iCarlos*2][iBin].Reset();
343 ddlbins[iCarlos*2+1][iBin].Reset();
344 }
5dfa68c5 345 }else{
04366a57 346 // fill the current digit into the bins array
44c5b268 347 if(iHybrid<0 || iHybrid>=kHybridsPerDDL){
348 AliWarning(Form("Invalid SDD hybrid number %d on module %d\n", iHybrid,iModule));
349 continue;
350 }
e4da2288 351 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(iModule);
9c7f5947 352 if(cal==0){
353 AliError(Form("Calibration object not present for SDD module %d\n",iModule));
354 continue;
355 }
5683bd96 356 Float_t charge=input->GetSignal();
14dceddf 357 Int_t chan=input->GetCoord1()+nAnodes*iSide;
358 Float_t gain=cal->GetChannelGain(chan);
20f3f947 359 Float_t baseline = cal->GetBaseline(chan);
360 if(charge>baseline) charge-=baseline;
361 else charge=0;
9c7f5947 362 if(gain>0.){ // Bad channels have gain=0
363 charge/=gain;
364 if(charge>=cal->GetThresholdAnode(chan)) {
365 Int_t q=(Int_t)(charge+0.5);
366 Int_t iz = input->GetCoord1();
367 Int_t itb = input->GetCoord2();
368 Int_t index = (itb+1) * nzBins + (iz+1);
369 if(index<kMaxBin){
370 ddlbins[iHybrid][index].SetQ(q);
371 ddlbins[iHybrid][index].SetMask(1);
372 ddlbins[iHybrid][index].SetIndex(index);
373 }else{
374 AliWarning(Form("Invalid SDD cell: Anode=%d TimeBin=%d",iz,itb));
375 }
93a93288 376 }
5dfa68c5 377 }
04366a57 378 }
379 }
93a93288 380 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++) delete [] ddlbins[iHyb];
04366a57 381 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
04366a57 382}
383
e3ee4984 384//______________________________________________________________________
385void AliITSClusterFinderV2SDD::NoiseSuppress(Int_t k, Int_t sid,Int_t nzBins, AliBin* bins, AliITSCalibrationSDD* cal) const {
386 // applies zero suppression using the measured noise of each anode
387 // threshold values from ALICE-INT-1999-28 V10
83ec5e27 388 Float_t xfactL=2.2;
389 Float_t xfactH=4.0;
e3ee4984 390 //
391
392 Int_t iAn=(k%nzBins)-1;
393 if(iAn<0 || iAn>255) return;
394 if(sid==1) iAn+=256;
395 Int_t nLow=0, nHigh=0;
396 Float_t noise=cal->GetNoiseAfterElectronics(iAn);
397 Float_t noisem1=noise;
398 if(iAn>1) noisem1=cal->GetNoiseAfterElectronics(iAn-1);
399 Float_t noisep1=noise;
400 if(iAn<511) noisep1=cal->GetNoiseAfterElectronics(iAn+1);
83ec5e27 401 Float_t tL=noise*xfactL;
402 Float_t tH=noise*xfactH;
403 Float_t tLp1=noisep1*xfactL;
404 Float_t tHp1=noisep1*xfactH;
405 Float_t tLm1=noisem1*xfactL;
406 Float_t tHm1=noisem1*xfactH;
e3ee4984 407 Float_t cC=bins[k].GetQ();
408 if(cC<=tL){
409 bins[k].SetQ(0);
410 bins[k].SetMask(0xFFFFFFFE);
411 return;
412 }
413 nLow++; // cC is greater than tL
414 if(cC>tH) nHigh++;
415 Int_t sS=bins[k-1].GetQ();
416 if(sS>tLm1) nLow++;
417 if(sS>tHm1) nHigh++;
418 Int_t nN=bins[k+1].GetQ();
419 if(nN>tLp1) nLow++;
420 if(nN>tHp1) nHigh++;
421 Int_t eE=bins[k-nzBins].GetQ();
422 if(eE>tL) nLow++;
423 if(eE>tH) nHigh++;
424 Int_t wW=bins[k+nzBins].GetQ();
425 if(wW>tL) nLow++;
426 if(wW>tH) nHigh++;
427 if(nLow<3 || nHigh<1){
428 bins[k].SetQ(0);
429 bins[k].SetMask(0xFFFFFFFE);
430 }
431}
432
04366a57 433
d97eb3fe 434