1 /**************************************************************************
2 * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
19 // Implementation of the ITS clusterer V2 class //
21 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch //
23 ///////////////////////////////////////////////////////////////////////////
27 #include <TClonesArray.h>
29 #include "AliITSClusterFinderV2SDD.h"
30 #include "AliITSRecPoint.h"
31 #include "AliITSDetTypeRec.h"
32 #include "AliRawReader.h"
33 #include "AliITSRawStreamSDD.h"
34 #include "AliITSRawStreamSDDCompressed.h"
35 #include "AliITSCalibrationSDD.h"
36 #include "AliITSresponseSDD.h"
37 #include "AliITSDetTypeRec.h"
38 #include "AliITSReconstructor.h"
39 #include "AliITSsegmentationSDD.h"
40 #include "AliITSdigitSDD.h"
41 #include "AliITSgeomTGeo.h"
43 ClassImp(AliITSClusterFinderV2SDD)
45 AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD(AliITSDetTypeRec* dettyp):AliITSClusterFinder(dettyp),
52 fMaxDrTimeForTightCut(0.)
56 fNAnodes = GetSeg()->NpzHalf();
58 fNTimeBins = GetSeg()->Npx();
59 fNXbins = fNTimeBins+2;
60 AliDebug(2,Form("Cells in SDD cluster finder: Andoes=%d TimeBins=%d",fNAnodes,fNTimeBins));
61 const Int_t kMaxBin=fNZbins*fNXbins;
62 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++){
63 fDDLBins[iHyb]=new AliBin[kMaxBin];
65 SetPeakSelection(15.,30.,2000.);
69 //______________________________________________________________________
70 AliITSClusterFinderV2SDD::~AliITSClusterFinderV2SDD()
73 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++){
74 delete [] fDDLBins[iHyb];
78 //______________________________________________________________________
79 void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
83 FindClustersSDD(fDigits);
87 //______________________________________________________________________
88 void AliITSClusterFinderV2SDD::FindClustersSDD(TClonesArray *digits) {
89 //------------------------------------------------------------
90 // Actual SDD cluster finder
91 //------------------------------------------------------------
93 const Int_t kMaxBin=fNZbins*fNXbins;
95 bins[0]=new AliBin[kMaxBin];
96 bins[1]=new AliBin[kMaxBin];
98 anodeFired[0]=new TBits(fNAnodes);
99 anodeFired[1]=new TBits(fNAnodes);
100 anodeFired[0]->ResetAllBits();
101 anodeFired[1]->ResetAllBits();
102 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
104 AliError(Form("Calibration object not present for SDD module %d\n",fModule));
109 Int_t i, ndigits=digits->GetEntriesFast();
110 for (i=0; i<ndigits; i++) {
111 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
112 Int_t ian=d->GetCoord1();
113 Int_t itb=d->GetCoord2();
115 if (ian >= fNAnodes) iSide=1;
116 Float_t gain=cal->GetChannelGain(ian)/fDetTypeRec->GetAverageGainSDD();
117 Float_t charge=d->GetSignal(); // returns expanded signal
118 // (10 bit, low threshold already added)
119 Float_t baseline = cal->GetBaseline(ian);
120 if(charge>baseline) charge-=baseline;
123 if(gain>0.){ // Bad channels have gain=0.
125 if(charge<cal->GetThresholdAnode(ian)) continue;
126 Int_t q=(Int_t)(charge+0.5);
130 bins[0][y*fNZbins+z].SetQ(q);
131 bins[0][y*fNZbins+z].SetMask(1);
132 bins[0][y*fNZbins+z].SetIndex(i);
133 anodeFired[0]->SetBitNumber(ian);
136 bins[1][y*fNZbins+z].SetQ(q);
137 bins[1][y*fNZbins+z].SetMask(1);
138 bins[1][y*fNZbins+z].SetIndex(i);
139 anodeFired[1]->SetBitNumber(ian-fNAnodes);
144 FindClustersSDD(bins, anodeFired, digits);
148 delete anodeFired[0];
149 delete anodeFired[1];
153 //______________________________________________________________________
154 void AliITSClusterFinderV2SDD::
155 FindClustersSDD(AliBin* bins[2], TBits* anodeFired[2],
156 TClonesArray *digits, TClonesArray *clusters, Int_t jitter) {
157 //------------------------------------------------------------
158 // Actual SDD cluster finder
159 //------------------------------------------------------------
161 static AliITSRecoParam *repa = NULL;
163 repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
165 repa = AliITSRecoParam::GetHighFluxParam();
166 AliWarning("Using default AliITSRecoParam class");
169 const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(fModule);
170 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
172 AliError(Form("Calibration object not present for SDD module %d\n",fModule));
175 const Int_t kMaxBin=fNZbins*fNXbins;
177 TClonesArray &cl=*clusters;
178 for (Int_t s=0; s<2; s++){
179 for(Int_t iAnode=0; iAnode<GetSeg()->NpzHalf(); iAnode++){
180 if(anodeFired[s]->TestBitNumber(iAnode)==kFALSE) continue;
181 for(Int_t iTimeBin=0; iTimeBin<GetSeg()->Npx(); iTimeBin++){
182 Int_t index=(iTimeBin+1)*fNZbins+(iAnode+1);
183 if (bins[s][index].IsUsed()) continue;
184 if(NoiseSuppress(index,s,bins[s],cal)) continue;
185 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
186 FindPeaks(index, fNZbins, bins[s], idx, msk, npeaks);
188 if (npeaks>30) continue;
189 if (npeaks==0) continue;
193 if(repa->GetUseUnfoldingInClusterFinderSDD()){
194 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
195 if (idx[k] < 0) continue; //this peak is already removed
196 for (l=k+1; l<npeaks; l++) {
197 if (idx[l] < 0) continue; //this peak is already removed
198 Int_t ki=idx[k]/fNZbins, kj=idx[k] - ki*fNZbins;
199 Int_t li=idx[l]/fNZbins, lj=idx[l] - li*fNZbins;
200 Int_t di=TMath::Abs(ki - li);
201 Int_t dj=TMath::Abs(kj - lj);
202 if (di>1 || dj>1) continue;
203 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
215 for (k=1; k<npeaks; k++) msk[k]=msk[0];
219 for (k=0; k<npeaks; k++) {
220 if(idx[k]>0. && bins[s][idx[k]].GetQ() > maxADC) maxADC=bins[s][idx[k]].GetQ();
221 MarkPeak(TMath::Abs(idx[k]), fNZbins, bins[s], msk[k]);
223 if(maxADC<fCutOnPeakLoose) continue;
225 for (k=0; k<nClust; k++) {
226 if (idx[k] < 0) continue; //removed peak
228 MakeCluster(idx[k], fNZbins, bins[s], msk[k], c);
231 for (Int_t ilab=0;ilab<10;ilab++){
236 for (Int_t di=-2; di<=2;di++){
237 for (Int_t dj=-2;dj<=2;dj++){
238 index = idx[k]+di+dj*fNZbins;
239 if (index<0) continue;
240 if (index>=kMaxBin) continue;
241 AliBin *b=&bins[s][index];
242 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
243 for (Int_t itrack=0;itrack<10;itrack++){
244 Int_t track = (d->GetTracks())[itrack];
246 AddLabel(milab, track);
254 Int_t clSizAnode=fZmax-fZmin+1;
255 Int_t clSizTb=fXmax-fXmin+1;
256 if(repa->GetUseSDDClusterSizeSelection()){
257 if(clSizTb==1) continue; // cut common mode noise spikes
258 if(clSizAnode>5) continue; // cut common mode noise spikes
259 if(clSizTb>10) continue; // cut clusters on noisy anodes
260 if(cal-> IsAMAt20MHz() && clSizTb>8) continue; // cut clusters on noisy anodes
263 AliITSresponseSDD* rsdd = fDetTypeRec->GetResponseSDD();
264 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
266 Float_t zAnode=z-0.5; // to have anode in range 0.-255. and centered on the mid of the pitch
267 Float_t timebin=y-0.5; // to have time bin in range 0.-255. amd centered on the mid of the bin
268 if(s==1) zAnode += GetSeg()->NpzHalf(); // right side has anodes from 256. to 511.
269 Float_t zdet = GetSeg()->GetLocalZFromAnode(zAnode);
270 Float_t driftTimeUncorr = GetSeg()->GetDriftTimeFromTb(timebin)+jitter*rsdd->GetCarlosRXClockPeriod();
271 Float_t driftTime=driftTimeUncorr-rsdd->GetTimeZero(fModule);
272 if(driftTime<fMaxDrTimeForTightCut && maxADC<fCutOnPeakTight) continue;
274 Float_t driftSpeed = cal->GetDriftSpeedAtAnode(zAnode) + rsdd->GetDeltaVDrift(fModule,zAnode>255);
275 Float_t driftPathMicron = driftTime*driftSpeed;
276 const Double_t kMicronTocm = 1.0e-4;
277 Float_t xdet=(driftPathMicron-GetSeg()->Dx())*kMicronTocm; // xdet is negative
278 if (s==0) xdet=-xdet; // left side has positive local x
280 if(repa->GetUseSDDCorrectionMaps()){
281 Float_t corrx=0, corrz=0;
282 cal->GetCorrections(zdet,xdet,corrz,corrx,GetSeg());
287 Double_t loc[3]={xdet,0.,zdet},trk[3]={0.,0.,0.};
288 mT2L->MasterToLocal(loc,trk);
292 q/=rsdd->GetADCtokeV(fModule);
293 q+=(driftTime*rsdd->GetChargevsTime()); // correction for zero supp.
294 if(cal-> IsAMAt20MHz()) q*=2.; // account for 1/2 sampling freq.
295 if(q<repa->GetMinClusterChargeSDD()) continue; // remove noise clusters
297 Float_t hit[5] = {y, z, 0.0030*0.0030, 0.0020*0.0020, q};
298 Int_t info[3] = {clSizTb, clSizAnode, fNlayer[fModule]};
299 if (digits) CheckLabels2(milab);
300 milab[3]=fNdet[fModule];
301 AliITSRecPoint cc(milab,hit,info);
302 cc.SetType(nClust*100+npeaks);
303 cc.SetDriftTime(driftTimeUncorr);
305 cc.SetChargeRatio(maxADC);
306 if(clusters) new (cl[ncl]) AliITSRecPoint(cc);
308 fDetTypeRec->AddRecPoint(cc);
315 AliDebug(2,Form("Clusters found on SDD module %d (unfolding %d) = %d\n",fModule,repa->GetUseUnfoldingInClusterFinderSDD(),ncl));
318 //______________________________________________________________________
319 void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
320 //------------------------------------------------------------
321 // This function creates ITS clusters from raw data
322 //------------------------------------------------------------
324 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
325 AliDebug(1,Form("%s is used",inputSDD->ClassName()));
327 AliITSDDLModuleMapSDD *ddlmap=(AliITSDDLModuleMapSDD*)fDetTypeRec->GetDDLModuleMapSDD();
328 inputSDD->SetDDLModuleMap(ddlmap);
329 for(Int_t iddl=0; iddl<AliITSDDLModuleMapSDD::GetNDDLs(); iddl++){
330 for(Int_t icar=0; icar<AliITSDDLModuleMapSDD::GetNModPerDDL();icar++){
331 Int_t iMod=ddlmap->GetModuleNumber(iddl,icar);
332 if(iMod==-1) continue;
333 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(iMod);
335 AliError(Form("Calibration object not present for SDD module %d\n",iMod));
338 Bool_t isZeroSupp=cal->GetZeroSupp();
340 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-240,iSid,cal->GetZSLowThreshold(iSid));
342 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-240,iSid,0);
346 FindClustersSDD(inputSDD,clusters);
350 void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input,
351 TClonesArray** clusters)
353 //------------------------------------------------------------
354 // Actual SDD cluster finder for raw data
355 //------------------------------------------------------------
356 Int_t nClustersSDD = 0;
358 TBits* anodeFired[2];
359 TBits* ddlAnodeFired[kHybridsPerDDL];
360 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++){
361 ddlAnodeFired[iHyb]=new TBits(fNAnodes);
362 ddlAnodeFired[iHyb]->ResetAllBits();
364 Int_t vectModId[kModulesPerDDL];
365 for(Int_t iMod=0; iMod<kModulesPerDDL; iMod++) vectModId[iMod]=-1;
367 // read raw data input stream
368 while (input->Next()) {
369 Int_t iModule = input->GetModuleID();
371 AliWarning(Form("Invalid SDD module number %d\n", iModule));
374 Int_t iCarlos =input->GetCarlosId();
375 Int_t iSide = input->GetChannel();
376 Int_t iHybrid=iCarlos*2+iSide;
378 if (input->IsCompletedModule()) {
379 // store the module number
380 vectModId[iCarlos]=iModule;
382 else if (input->IsCompletedDDL()) {
383 // when all data from a DDL was read, search for clusters
384 Int_t jitter=input->GetJitter();
385 for(Int_t iMod=0; iMod<kModulesPerDDL; iMod++){
386 if(vectModId[iMod]>=0){
387 fModule = vectModId[iMod];
388 clusters[fModule] = new TClonesArray("AliITSRecPoint");
389 bins[0]=fDDLBins[iMod*2]; // first hybrid of the module
390 bins[1]=fDDLBins[iMod*2+1]; // second hybrid of the module
391 anodeFired[0]=ddlAnodeFired[iMod*2];
392 anodeFired[1]=ddlAnodeFired[iMod*2+1];
393 FindClustersSDD(bins, anodeFired, NULL, clusters[fModule],jitter);
394 Int_t nClusters = clusters[fModule]->GetEntriesFast();
395 nClustersSDD += nClusters;
398 for (Int_t s=0; s<2; s++){
399 Int_t indexHyb=iMod*2+s;
400 for(Int_t iAnode=0; iAnode<GetSeg()->NpzHalf(); iAnode++){
401 if(ddlAnodeFired[indexHyb]->TestBitNumber(iAnode)==kFALSE) continue;
402 for(Int_t iTimeBin=0; iTimeBin<GetSeg()->Npx(); iTimeBin++){
403 Int_t index=(iTimeBin+1)*fNZbins+(iAnode+1);
404 fDDLBins[indexHyb][index].Reset();
408 ddlAnodeFired[iMod*2]->ResetAllBits();
409 ddlAnodeFired[iMod*2+1]->ResetAllBits();
412 // fill the current digit into the bins array
413 if(iHybrid<0 || iHybrid>=kHybridsPerDDL){
414 AliWarning(Form("Invalid SDD hybrid number %d on module %d\n", iHybrid,iModule));
417 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(iModule);
419 AliError(Form("Calibration object not present for SDD module %d\n",iModule));
422 Float_t charge=input->GetSignal();
423 Int_t chan=input->GetCoord1()+fNAnodes*iSide;
424 Float_t gain=cal->GetChannelGain(chan)/fDetTypeRec->GetAverageGainSDD();;
425 Float_t baseline = cal->GetBaseline(chan);
426 if(charge>baseline) charge-=baseline;
428 if(gain>0.){ // Bad channels have gain=0
430 if(charge>=cal->GetThresholdAnode(chan)) {
431 Int_t q=(Int_t)(charge+0.5);
432 Int_t iz = input->GetCoord1();
433 Int_t itb = input->GetCoord2();
434 Int_t index = (itb+1) * fNZbins + (iz+1);
435 if((itb < fNTimeBins) && (iz < fNAnodes)) {
436 fDDLBins[iHybrid][index].SetQ(q);
437 fDDLBins[iHybrid][index].SetMask(1);
438 fDDLBins[iHybrid][index].SetIndex(index);
439 ddlAnodeFired[iHybrid]->SetBitNumber(iz);
441 AliWarning(Form("Invalid SDD cell: Anode=%d TimeBin=%d",iz,itb));
447 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++){
448 delete ddlAnodeFired[iHyb];
450 AliDebug(1,Form("found clusters in ITS SDD: %d", nClustersSDD));
453 //______________________________________________________________________
454 Bool_t AliITSClusterFinderV2SDD::NoiseSuppress(Int_t k, Int_t sid, AliBin* bins, AliITSCalibrationSDD* cal) const {
455 // applies zero suppression using the measured noise of each anode
456 // threshold values from ALICE-INT-1999-28 V10
457 // returns kTRUE if the digit should eb noise suppressed, kFALSE if it should be kept
462 Int_t iAn=(k%fNZbins)-1;
463 if(iAn<0 || iAn>255) return kTRUE;
465 Int_t nLow=0, nHigh=0;
466 Float_t noise=cal->GetNoiseAfterElectronics(iAn);
467 Float_t noisem1=noise;
468 if(iAn>1) noisem1=cal->GetNoiseAfterElectronics(iAn-1);
469 Float_t noisep1=noise;
470 if(iAn<511) noisep1=cal->GetNoiseAfterElectronics(iAn+1);
471 Float_t tL=noise*xfactL;
472 Float_t tH=noise*xfactH;
473 Float_t tLp1=noisep1*xfactL;
474 Float_t tHp1=noisep1*xfactH;
475 Float_t tLm1=noisem1*xfactL;
476 Float_t tHm1=noisem1*xfactH;
477 Int_t cC=bins[k].GetQ();
480 bins[k].SetMask(0xFFFFFFFE);
483 nLow++; // cC is greater than tL
485 Int_t sS=bins[k-1].GetQ();
488 Int_t nN=bins[k+1].GetQ();
491 Int_t eE=bins[k-fNZbins].GetQ();
494 Int_t wW=bins[k+fNZbins].GetQ();
497 if(nLow<2 || nHigh<1) return kTRUE;