]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSClusterFinderV2SDD.cxx
Update
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderV2SDD.cxx
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 /* $Id$*/
17
18 ////////////////////////////////////////////////////////////////////////////
19 //            Implementation of the ITS clusterer V2 class                //
20 //                                                                        //
21 //          Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch            //
22 //                                                                        //
23 ///////////////////////////////////////////////////////////////////////////
24
25
26
27 #include <TClonesArray.h>
28 #include <TBits.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"
42
43 ClassImp(AliITSClusterFinderV2SDD)
44
45 AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD(AliITSDetTypeRec* dettyp):AliITSClusterFinder(dettyp),
46   fNAnodes(0),
47   fNTimeBins(0),
48   fNZbins(0),
49   fNXbins(0),
50   fCutOnPeakLoose(0.),
51   fCutOnPeakTight(0.),
52   fMaxDrTimeForTightCut(0.)
53 {
54   //Default constructor
55
56   fNAnodes = GetSeg()->NpzHalf();
57   fNZbins = fNAnodes+2;
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];
64   }
65   SetPeakSelection(15.,30.,2000.);
66 }
67  
68
69 //______________________________________________________________________
70 AliITSClusterFinderV2SDD::~AliITSClusterFinderV2SDD()
71 {
72   //Destructor
73   for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++){ 
74     delete [] fDDLBins[iHyb];
75   }
76 }
77
78 //______________________________________________________________________
79 void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
80
81   //Find clusters V2
82   SetModule(mod);
83   FindClustersSDD(fDigits);
84
85 }
86
87 //______________________________________________________________________
88 void AliITSClusterFinderV2SDD::FindClustersSDD(TClonesArray *digits) {
89   //------------------------------------------------------------
90   // Actual SDD cluster finder
91   //------------------------------------------------------------
92
93   const Int_t kMaxBin=fNZbins*fNXbins;
94   AliBin *bins[2];
95   bins[0]=new AliBin[kMaxBin];
96   bins[1]=new AliBin[kMaxBin];
97   TBits *anodeFired[2];
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);
103   if(cal==0){
104     AliError(Form("Calibration object not present for SDD module %d\n",fModule));
105     return;
106   }
107
108   AliITSdigitSDD *d=0;
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();
114      Int_t iSide=0;
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;
121      else charge=0;
122
123      if(gain>0.){ // Bad channels have gain=0.
124        charge/=gain;
125        if(charge<cal->GetThresholdAnode(ian)) continue;
126        Int_t q=(Int_t)(charge+0.5);
127        Int_t y=itb+1;   
128        Int_t z=ian+1;   
129        if (z <= fNAnodes){
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);
134        } else {
135          z-=fNAnodes;
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);
140        }
141      }
142   }
143   
144   FindClustersSDD(bins, anodeFired, digits);
145
146   delete[] bins[0];
147   delete[] bins[1];
148   delete anodeFired[0];
149   delete anodeFired[1];
150
151 }
152
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   //------------------------------------------------------------
160
161   static AliITSRecoParam *repa = NULL;
162   if(!repa){
163     repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
164     if(!repa){
165       repa = AliITSRecoParam::GetHighFluxParam();
166       AliWarning("Using default AliITSRecoParam class");
167     }
168   }
169   const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(fModule);
170   AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
171   if(cal==0){
172     AliError(Form("Calibration object not present for SDD module %d\n",fModule));
173     return;
174   }
175   const Int_t kMaxBin=fNZbins*fNXbins;
176   Int_t ncl=0; 
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);
187
188         if (npeaks>30) continue;
189         if (npeaks==0) continue;
190
191         Int_t k,l;
192         Int_t nClust;
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()) {
204                 msk[l]=msk[k];
205                 idx[l]*=-1;
206               } else {
207                 msk[k]=msk[l];
208                 idx[k]*=-1;
209                 break;
210               } 
211             }
212           }
213           nClust=npeaks;
214         }else{
215           for (k=1; k<npeaks; k++) msk[k]=msk[0];
216           nClust=1;
217         }
218         Float_t maxADC=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]);
222         }
223         if(maxADC<fCutOnPeakLoose) continue;
224
225         for (k=0; k<nClust; k++) {
226           if (idx[k] < 0) continue; //removed peak
227           AliITSRecPoint c;
228           MakeCluster(idx[k], fNZbins, bins[s], msk[k], c);
229           //mi change
230           Int_t milab[10];
231           for (Int_t ilab=0;ilab<10;ilab++){
232             milab[ilab]=-2;
233           }
234           
235           if(digits) {
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];
245                   if (track>=0) {
246                     AddLabel(milab, track); 
247                   }
248                 }
249               }
250             }
251           }
252           
253
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
261           }
262           
263           AliITSresponseSDD* rsdd = fDetTypeRec->GetResponseSDD();
264           Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
265           y/=q; z/=q;
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;
273
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
279           
280           if(repa->GetUseSDDCorrectionMaps()){
281             Float_t corrx=0, corrz=0;
282             cal->GetCorrections(zdet,xdet,corrz,corrx,GetSeg());
283             zdet+=corrz;
284             xdet+=corrx;
285           }
286           
287           Double_t loc[3]={xdet,0.,zdet},trk[3]={0.,0.,0.};
288           mT2L->MasterToLocal(loc,trk);
289           y=trk[1];
290           z=trk[2]; 
291           
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
296           
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);
304           cc.SetDriftSide(s);
305           cc.SetChargeRatio(maxADC);
306           if(clusters) new (cl[ncl]) AliITSRecPoint(cc); 
307           else {
308             fDetTypeRec->AddRecPoint(cc);
309           }
310           ncl++;
311         }
312       }
313     }
314   }
315   AliDebug(2,Form("Clusters found on SDD module %d (unfolding %d) = %d\n",fModule,repa->GetUseUnfoldingInClusterFinderSDD(),ncl));
316
317
318 //______________________________________________________________________
319 void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
320     //------------------------------------------------------------
321   // This function creates ITS clusters from raw data
322   //------------------------------------------------------------
323
324   AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
325   AliDebug(1,Form("%s is used",inputSDD->ClassName()));
326
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);
334       if(cal==0){
335         AliError(Form("Calibration object not present for SDD module %d\n",iMod));
336         continue;
337       }
338       Bool_t isZeroSupp=cal->GetZeroSupp();
339       if(isZeroSupp){ 
340         for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-240,iSid,cal->GetZSLowThreshold(iSid));
341       }else{
342         for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-240,iSid,0);
343       }
344     }
345   }
346   FindClustersSDD(inputSDD,clusters);
347   delete inputSDD;
348 }
349
350 void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input, 
351                                         TClonesArray** clusters) 
352 {
353   //------------------------------------------------------------
354   // Actual SDD cluster finder for raw data
355   //------------------------------------------------------------
356   Int_t nClustersSDD = 0;
357   AliBin *bins[2];
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();
363   }
364   Int_t vectModId[kModulesPerDDL];
365   for(Int_t iMod=0; iMod<kModulesPerDDL; iMod++) vectModId[iMod]=-1;
366
367   // read raw data input stream
368   while (input->Next()) {
369     Int_t iModule = input->GetModuleID();
370     if(iModule<0){
371       AliWarning(Form("Invalid SDD module number %d\n", iModule));
372       continue;
373     }
374     Int_t iCarlos =input->GetCarlosId();
375     Int_t iSide = input->GetChannel();
376     Int_t iHybrid=iCarlos*2+iSide;
377
378     if (input->IsCompletedModule()) {
379       // store the module number
380       vectModId[iCarlos]=iModule;
381     }
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;
396           vectModId[iMod]=-1;
397         }
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();
405             }
406           }
407         }
408         ddlAnodeFired[iMod*2]->ResetAllBits();
409         ddlAnodeFired[iMod*2+1]->ResetAllBits();
410       }
411     }else{
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));
415         continue;
416       }
417       AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(iModule);    
418       if(cal==0){
419         AliError(Form("Calibration object not present for SDD module %d\n",iModule));
420         continue;
421       }
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;
427       else charge=0;
428       if(gain>0.){ // Bad channels have gain=0
429         charge/=gain;
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);
440           }else{
441             AliWarning(Form("Invalid SDD cell: Anode=%d   TimeBin=%d",iz,itb));   
442           }
443         }
444       }
445     }
446   }
447   for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++){ 
448    delete ddlAnodeFired[iHyb];
449   }
450   AliDebug(1,Form("found clusters in ITS SDD: %d", nClustersSDD));
451 }
452
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
458   Float_t xfactL=2.2; 
459   Float_t xfactH=4.0;
460   //
461
462   Int_t iAn=(k%fNZbins)-1;
463   if(iAn<0 || iAn>255) return kTRUE;
464   if(sid==1) iAn+=256;
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();
478   if(cC<=tL){
479     bins[k].SetQ(0);
480     bins[k].SetMask(0xFFFFFFFE);
481     return kTRUE;;
482   }
483   nLow++; // cC is greater than tL
484   if(cC>tH) nHigh++;
485   Int_t sS=bins[k-1].GetQ();
486   if(sS>tLm1) nLow++;
487   if(sS>tHm1) nHigh++;
488   Int_t nN=bins[k+1].GetQ();
489   if(nN>tLp1) nLow++;
490   if(nN>tHp1) nHigh++;
491   Int_t eE=bins[k-fNZbins].GetQ();
492   if(eE>tL) nLow++;
493   if(eE>tH) nHigh++;
494   Int_t wW=bins[k+fNZbins].GetQ();
495   if(wW>tL) nLow++;
496   if(wW>tH) nHigh++;
497   if(nLow<2 || nHigh<1) return kTRUE;
498   else return kFALSE;
499 }
500
501
502