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