Update of Macros
[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"
debf7b78 35#include "AliITSReconstructor.h"
5bfe44ce 36#include "AliITSsegmentationSDD.h"
04366a57 37#include "AliITSdigitSDD.h"
b4704be3 38#include "AliITSgeomTGeo.h"
debf7b78 39
04366a57 40ClassImp(AliITSClusterFinderV2SDD)
41
4952f440 42AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD(AliITSDetTypeRec* dettyp):AliITSClusterFinderV2(dettyp)
a66a0eb6 43{
04366a57 44
45 //Default constructor
46
04366a57 47}
48
49
50void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
51
52 //Find clusters V2
53 SetModule(mod);
54 FindClustersSDD(fDigits);
55
56}
57
58void AliITSClusterFinderV2SDD::FindClustersSDD(TClonesArray *digits) {
59 //------------------------------------------------------------
60 // Actual SDD cluster finder
61 //------------------------------------------------------------
4952f440 62 Int_t nAnodes = GetSeg()->NpzHalf();
63 Int_t nzBins = nAnodes+2;
64 Int_t nTimeBins = GetSeg()->Npx();
65 Int_t nxBins = nTimeBins+2;
f6b6d58e 66 const Int_t kMaxBin=nzBins*nxBins;
04366a57 67
68 AliBin *bins[2];
4952f440 69 bins[0]=new AliBin[kMaxBin];
70 bins[1]=new AliBin[kMaxBin];
404c1c29 71 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
9c7f5947 72 if(cal==0){
73 AliError(Form("Calibration object not present for SDD module %d\n",fModule));
74 return;
75 }
0599a018 76 AliITSresponseSDD* res = (AliITSresponseSDD*)cal->GetResponse();
77 const char *option=res->ZeroSuppOption();
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);
5683bd96 87 Float_t charge=d->GetSignal();
20f3f947 88 if(strstr(option,"ZS")) charge+=(Float_t)cal->GetZSLowThreshold(iSide);
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){
130 repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParamDefault();
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
221 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
222 y/=q; z/=q;
223 Float_t zAnode=z-0.5; // to have anode in range 0.-255. and centered on the mid of the pitch
224 Float_t timebin=y-0.5; // to have time bin in range 0.-255. amd centered on the mid of the bin
225 if(s==1) zAnode += GetSeg()->NpzHalf(); // right side has anodes from 256. to 511.
226 Float_t zdet = GetSeg()->GetLocalZFromAnode(zAnode);
227 Float_t driftTime = GetSeg()->GetDriftTimeFromTb(timebin) - cal->GetTimeOffset();
228 Float_t driftPathMicron = cal->GetDriftPath(driftTime,zAnode);
229 const Double_t kMicronTocm = 1.0e-4;
230 Float_t xdet=(driftPathMicron-GetSeg()->Dx())*kMicronTocm; // xdet is negative
231 if (s==0) xdet=-xdet; // left side has positive local x
c9a38d3d 232
233 Float_t corrx=0, corrz=0;
234 cal->GetCorrections(zdet,xdet,corrz,corrx,GetSeg());
235 zdet+=corrz;
236 xdet+=corrx;
f6b6d58e 237
238 Double_t loc[3]={xdet,0.,zdet},trk[3]={0.,0.,0.};
239 mT2L->MasterToLocal(loc,trk);
240 y=trk[1];
241 z=trk[2];
242
243 q/=cal->GetADC2keV(); //to have MPV 1 MIP = 86.4 KeV
244 Float_t hit[5] = {y, z, 0.0030*0.0030, 0.0020*0.0020, q};
245 Int_t info[3] = {maxj-minj+1, maxi-mini+1, fNlayer[fModule]};
246 if (digits) {
247 // AliBin *b=&bins[s][idx[k]];
248 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
249 {
250 //Int_t lab[3];
251 //lab[0]=(d->GetTracks())[0];
252 //lab[1]=(d->GetTracks())[1];
253 //lab[2]=(d->GetTracks())[2];
254 //CheckLabels(lab);
255 CheckLabels2(milab);
256 }
257 }
258 milab[3]=fNdet[fModule];
259
260 AliITSRecPoint cc(milab,hit,info);
261 cc.SetType(npeaks);
262 if(clusters) new (cl[ncl]) AliITSRecPoint(cc);
263 else {
264 fDetTypeRec->AddRecPoint(cc);
265 }
266 ncl++;
04366a57 267 }
268 }
24c98369 269
04366a57 270}
f6b6d58e 271//______________________________________________________________________
04366a57 272void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
273 //------------------------------------------------------------
274 // This function creates ITS clusters from raw data
275 //------------------------------------------------------------
276 rawReader->Reset();
0599a018 277 AliITSRawStreamSDD inputSDD(rawReader);
979b5a5f 278 AliITSDDLModuleMapSDD *ddlmap=(AliITSDDLModuleMapSDD*)fDetTypeRec->GetDDLModuleMapSDD();
279 inputSDD.SetDDLModuleMap(ddlmap);
04366a57 280 FindClustersSDD(&inputSDD,clusters);
281
282}
283
284void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input,
285 TClonesArray** clusters)
286{
287 //------------------------------------------------------------
288 // Actual SDD cluster finder for raw data
289 //------------------------------------------------------------
290 Int_t nClustersSDD = 0;
4952f440 291 Int_t nAnodes = GetSeg()->NpzHalf();
292 Int_t nzBins = nAnodes+2;
293 Int_t nTimeBins = GetSeg()->Npx();
294 Int_t nxBins = nTimeBins+2;
f6b6d58e 295 const Int_t kMaxBin=nzBins*nxBins;
ae485645 296 AliBin *bins[2];
93a93288 297 AliBin *ddlbins[kHybridsPerDDL]; // 12 modules (=24 hybrids) of 1 DDL read "in parallel"
298 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++) ddlbins[iHyb]=new AliBin[kMaxBin];
04366a57 299 // read raw data input stream
14dceddf 300 while (input->Next()) {
e4da2288 301 Int_t iModule = input->GetModuleID();
93a93288 302 if(iModule<0){
303 AliWarning(Form("Invalid SDD module number %d\n", iModule));
304 continue;
305 }
44c5b268 306
14dceddf 307 Int_t iCarlos =((AliITSRawStreamSDD*)input)->GetCarlosId();
308 Int_t iSide = ((AliITSRawStreamSDD*)input)->GetChannel();
309 Int_t iHybrid=iCarlos*2+iSide;
310 if (input->IsCompletedModule()) {
04366a57 311 // when all data from a module was read, search for clusters
44c5b268 312 if(iCarlos<0){
313 AliWarning(Form("Invalid SDD carlos number %d on module %d\n", iCarlos,iModule));
314 continue;
315 }
316 clusters[iModule] = new TClonesArray("AliITSRecPoint");
317 fModule = iModule;
318 bins[0]=ddlbins[iCarlos*2]; // first hybrid of the completed module
319 bins[1]=ddlbins[iCarlos*2+1]; // second hybrid of the completed module
320 FindClustersSDD(bins, kMaxBin, nzBins, NULL, clusters[iModule]);
321 Int_t nClusters = clusters[iModule]->GetEntriesFast();
322 nClustersSDD += nClusters;
323 for(Int_t iBin=0;iBin<kMaxBin; iBin++){
324 ddlbins[iCarlos*2][iBin].Reset();
325 ddlbins[iCarlos*2+1][iBin].Reset();
326 }
5dfa68c5 327 }else{
04366a57 328 // fill the current digit into the bins array
44c5b268 329 if(iHybrid<0 || iHybrid>=kHybridsPerDDL){
330 AliWarning(Form("Invalid SDD hybrid number %d on module %d\n", iHybrid,iModule));
331 continue;
332 }
e4da2288 333 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(iModule);
9c7f5947 334 if(cal==0){
335 AliError(Form("Calibration object not present for SDD module %d\n",iModule));
336 continue;
337 }
5dfa68c5 338 AliITSresponseSDD* res = (AliITSresponseSDD*)cal->GetResponse();
339 const char *option=res->ZeroSuppOption();
5683bd96 340 Float_t charge=input->GetSignal();
14dceddf 341 Int_t chan=input->GetCoord1()+nAnodes*iSide;
342 Float_t gain=cal->GetChannelGain(chan);
20f3f947 343 if(strstr(option,"ZS")) charge+=(Float_t)cal->GetZSLowThreshold(iSide);
344 Float_t baseline = cal->GetBaseline(chan);
345 if(charge>baseline) charge-=baseline;
346 else charge=0;
9c7f5947 347 if(gain>0.){ // Bad channels have gain=0
348 charge/=gain;
349 if(charge>=cal->GetThresholdAnode(chan)) {
350 Int_t q=(Int_t)(charge+0.5);
351 Int_t iz = input->GetCoord1();
352 Int_t itb = input->GetCoord2();
353 Int_t index = (itb+1) * nzBins + (iz+1);
354 if(index<kMaxBin){
355 ddlbins[iHybrid][index].SetQ(q);
356 ddlbins[iHybrid][index].SetMask(1);
357 ddlbins[iHybrid][index].SetIndex(index);
358 }else{
359 AliWarning(Form("Invalid SDD cell: Anode=%d TimeBin=%d",iz,itb));
360 }
93a93288 361 }
5dfa68c5 362 }
04366a57 363 }
364 }
93a93288 365 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++) delete [] ddlbins[iHyb];
04366a57 366 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
04366a57 367}
368
e3ee4984 369//______________________________________________________________________
370void AliITSClusterFinderV2SDD::NoiseSuppress(Int_t k, Int_t sid,Int_t nzBins, AliBin* bins, AliITSCalibrationSDD* cal) const {
371 // applies zero suppression using the measured noise of each anode
372 // threshold values from ALICE-INT-1999-28 V10
373 Float_t factL=2.2;
374 Float_t factH=4.0;
375 //
376
377 Int_t iAn=(k%nzBins)-1;
378 if(iAn<0 || iAn>255) return;
379 if(sid==1) iAn+=256;
380 Int_t nLow=0, nHigh=0;
381 Float_t noise=cal->GetNoiseAfterElectronics(iAn);
382 Float_t noisem1=noise;
383 if(iAn>1) noisem1=cal->GetNoiseAfterElectronics(iAn-1);
384 Float_t noisep1=noise;
385 if(iAn<511) noisep1=cal->GetNoiseAfterElectronics(iAn+1);
386 Float_t tL=noise*factL;
387 Float_t tH=noise*factH;
388 Float_t tLp1=noisep1*factL;
389 Float_t tHp1=noisep1*factH;
390 Float_t tLm1=noisem1*factL;
391 Float_t tHm1=noisem1*factH;
392 Float_t cC=bins[k].GetQ();
393 if(cC<=tL){
394 bins[k].SetQ(0);
395 bins[k].SetMask(0xFFFFFFFE);
396 return;
397 }
398 nLow++; // cC is greater than tL
399 if(cC>tH) nHigh++;
400 Int_t sS=bins[k-1].GetQ();
401 if(sS>tLm1) nLow++;
402 if(sS>tHm1) nHigh++;
403 Int_t nN=bins[k+1].GetQ();
404 if(nN>tLp1) nLow++;
405 if(nN>tHp1) nHigh++;
406 Int_t eE=bins[k-nzBins].GetQ();
407 if(eE>tL) nLow++;
408 if(eE>tH) nHigh++;
409 Int_t wW=bins[k+nzBins].GetQ();
410 if(wW>tL) nLow++;
411 if(wW>tH) nHigh++;
412 if(nLow<3 || nHigh<1){
413 bins[k].SetQ(0);
414 bins[k].SetMask(0xFFFFFFFE);
415 }
416}
417
04366a57 418
d97eb3fe 419