]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSClusterFinderV2SDD.cxx
Commented unnecessary include AliLog
[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 "AliITSRecPointContainer.h"
32 #include "AliITSDetTypeRec.h"
33 #include "AliRawReader.h"
34 #include "AliITSRawStreamSDD.h"
35 #include "AliITSRawStreamSDDCompressed.h"
36 #include "AliITSCalibrationSDD.h"
37 #include "AliITSresponseSDD.h"
38 #include "AliITSDetTypeRec.h"
39 #include "AliITSReconstructor.h"
40 #include "AliITSsegmentationSDD.h"
41 #include "AliITSdigitSDD.h"
42 #include "AliITSgeomTGeo.h"
43
44 ClassImp(AliITSClusterFinderV2SDD)
45
46 AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD(AliITSDetTypeRec* dettyp):AliITSClusterFinder(dettyp),
47   fNAnodes(0),
48   fNTimeBins(0),
49   fNZbins(0),
50   fNXbins(0),
51   fCutOnPeakLoose(0.),
52   fCutOnPeakTight(0.),
53   fMaxDrTimeForTightCut(0.)
54 {
55   //Default constructor
56
57   fNAnodes = GetSeg()->NpzHalf();
58   fNZbins = fNAnodes+2;
59   fNTimeBins = GetSeg()->Npx();
60   fNXbins = fNTimeBins+2;
61   AliDebug(2,Form("Cells in SDD cluster finder: Andoes=%d  TimeBins=%d",fNAnodes,fNTimeBins));
62   const Int_t kMaxBin=fNZbins*fNXbins;
63   for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++){
64    fDDLBins[iHyb]=new AliBin[kMaxBin];
65   }
66   SetPeakSelection(15.,30.,2000.);
67 }
68  
69
70 //______________________________________________________________________
71 AliITSClusterFinderV2SDD::~AliITSClusterFinderV2SDD()
72 {
73   //Destructor
74   for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++){ 
75     delete [] fDDLBins[iHyb];
76   }
77 }
78
79 //______________________________________________________________________
80 void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
81
82   //Find clusters V2
83   SetModule(mod);
84   FindClustersSDD(fDigits);
85
86 }
87
88 //______________________________________________________________________
89 void AliITSClusterFinderV2SDD::FindClustersSDD(TClonesArray *digits) {
90   //------------------------------------------------------------
91   // Actual SDD cluster finder
92   //------------------------------------------------------------
93
94   const Int_t kMaxBin=fNZbins*fNXbins;
95   AliBin *bins[2];
96   bins[0]=new AliBin[kMaxBin];
97   bins[1]=new AliBin[kMaxBin];
98   TBits *anodeFired[2];
99   anodeFired[0]=new TBits(fNAnodes);
100   anodeFired[1]=new TBits(fNAnodes);
101   anodeFired[0]->ResetAllBits();
102   anodeFired[1]->ResetAllBits();
103   AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
104   if(cal==0){
105     AliError(Form("Calibration object not present for SDD module %d\n",fModule));
106     return;
107   }
108
109   AliITSdigitSDD *d=0;
110   Int_t i, ndigits=digits->GetEntriesFast();
111   for (i=0; i<ndigits; i++) {
112      d=(AliITSdigitSDD*)digits->UncheckedAt(i);
113      Int_t ian=d->GetCoord1();
114      Int_t itb=d->GetCoord2();
115      Int_t iSide=0;
116      if (ian >= fNAnodes) iSide=1;    
117      Float_t gain=cal->GetChannelGain(ian)/fDetTypeRec->GetAverageGainSDD();
118      Float_t charge=d->GetSignal(); // returns expanded signal 
119                                     // (10 bit, low threshold already added)
120      Float_t baseline = cal->GetBaseline(ian);
121      if(charge>baseline) charge-=baseline;
122      else charge=0;
123
124      if(gain>0.){ // Bad channels have gain=0.
125        charge/=gain;
126        if(charge<cal->GetThresholdAnode(ian)) continue;
127        Int_t q=(Int_t)(charge+0.5);
128        Int_t y=itb+1;   
129        Int_t z=ian+1;   
130        if (z <= fNAnodes){
131          bins[0][y*fNZbins+z].SetQ(q);
132          bins[0][y*fNZbins+z].SetMask(1);
133          bins[0][y*fNZbins+z].SetIndex(i);
134          anodeFired[0]->SetBitNumber(ian);
135        } else {
136          z-=fNAnodes;
137          bins[1][y*fNZbins+z].SetQ(q);
138          bins[1][y*fNZbins+z].SetMask(1);
139          bins[1][y*fNZbins+z].SetIndex(i);
140          anodeFired[1]->SetBitNumber(ian-fNAnodes);
141        }
142      }
143   }
144   
145   FindClustersSDD(bins, anodeFired, digits);
146
147   delete[] bins[0];
148   delete[] bins[1];
149   delete anodeFired[0];
150   delete anodeFired[1];
151
152 }
153
154 //______________________________________________________________________
155 void AliITSClusterFinderV2SDD::
156 FindClustersSDD(AliBin* bins[2], TBits* anodeFired[2],  
157                 TClonesArray *digits, TClonesArray *clusters, Int_t jitter) {
158   //------------------------------------------------------------
159   // Actual SDD cluster finder
160   //------------------------------------------------------------
161
162   static AliITSRecoParam *repa = NULL;
163   if(!repa){
164     repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
165     if(!repa){
166       repa = AliITSRecoParam::GetHighFluxParam();
167       AliWarning("Using default AliITSRecoParam class");
168     }
169   }
170   const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(fModule);
171   AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
172   if(cal==0){
173     AliError(Form("Calibration object not present for SDD module %d\n",fModule));
174     return;
175   }
176   const Int_t kMaxBin=fNZbins*fNXbins;
177   Int_t ncl=0; 
178   TClonesArray &cl=*clusters;
179   for (Int_t s=0; s<2; s++){
180     for(Int_t iAnode=0; iAnode<GetSeg()->NpzHalf(); iAnode++){
181       if(anodeFired[s]->TestBitNumber(iAnode)==kFALSE) continue;
182       for(Int_t iTimeBin=0; iTimeBin<GetSeg()->Npx(); iTimeBin++){
183         Int_t index=(iTimeBin+1)*fNZbins+(iAnode+1);
184         if (bins[s][index].IsUsed()) continue;
185         if(NoiseSuppress(index,s,bins[s],cal)) continue;
186         Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
187         FindPeaks(index, fNZbins, bins[s], idx, msk, npeaks);
188
189         if (npeaks>30) continue;
190         if (npeaks==0) continue;
191
192         Int_t k,l;
193         Int_t nClust;
194         if(repa->GetUseUnfoldingInClusterFinderSDD()){
195           for (k=0; k<npeaks-1; k++){//mark adjacent peaks          
196             if (idx[k] < 0) continue; //this peak is already removed
197             for (l=k+1; l<npeaks; l++) {
198               if (idx[l] < 0) continue; //this peak is already removed
199               Int_t ki=idx[k]/fNZbins, kj=idx[k] - ki*fNZbins;
200               Int_t li=idx[l]/fNZbins, lj=idx[l] - li*fNZbins;
201               Int_t di=TMath::Abs(ki - li);
202               Int_t dj=TMath::Abs(kj - lj);
203               if (di>1 || dj>1) continue;
204               if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
205                 msk[l]=msk[k];
206                 idx[l]*=-1;
207               } else {
208                 msk[k]=msk[l];
209                 idx[k]*=-1;
210                 break;
211               } 
212             }
213           }
214           nClust=npeaks;
215         }else{
216           for (k=1; k<npeaks; k++) msk[k]=msk[0];
217           nClust=1;
218         }
219         Float_t maxADC=0;
220         for (k=0; k<npeaks; k++) {
221           if(idx[k]>0. && bins[s][idx[k]].GetQ() > maxADC) maxADC=bins[s][idx[k]].GetQ();
222           MarkPeak(TMath::Abs(idx[k]), fNZbins, bins[s], msk[k]);
223         }
224         if(maxADC<fCutOnPeakLoose) continue;
225
226         for (k=0; k<nClust; k++) {
227           if (idx[k] < 0) continue; //removed peak
228           AliITSRecPoint c;
229           MakeCluster(idx[k], fNZbins, bins[s], msk[k], c);
230           //mi change
231           Int_t milab[10];
232           for (Int_t ilab=0;ilab<10;ilab++){
233             milab[ilab]=-2;
234           }
235           
236           if(digits) {
237             for (Int_t di=-2; di<=2;di++){
238               for (Int_t dj=-2;dj<=2;dj++){
239                 index = idx[k]+di+dj*fNZbins;
240                 if (index<0) continue;
241                 if (index>=kMaxBin) continue;
242                 AliBin *b=&bins[s][index];
243                 if(b->GetQ()<0.1) continue;
244                 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
245                 for (Int_t itrack=0;itrack<10;itrack++){
246                   Int_t track = (d->GetTracks())[itrack];
247                   if (track>=0) {
248                     AddLabel(milab, track); 
249                   }
250                 }
251               }
252             }
253           } 
254           else { // raw data
255             if (fRawID2ClusID) milab[0] = fNClusters+1; // RS: store clID+1 as a reference to the cluster
256           }
257           
258
259           Int_t clSizAnode=fZmax-fZmin+1;
260           Int_t clSizTb=fXmax-fXmin+1;    
261           if(repa->GetUseSDDClusterSizeSelection()){
262             if(clSizTb==1) continue; // cut common mode noise spikes
263             if(clSizAnode>5)  continue; // cut common mode noise spikes
264             if(clSizTb>10)  continue; // cut clusters on noisy anodes
265             if(cal-> IsAMAt20MHz() && clSizTb>8)  continue; // cut clusters on noisy anodes
266           }
267           
268           AliITSresponseSDD* rsdd = fDetTypeRec->GetResponseSDD();
269           Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
270           y/=q; z/=q;
271           Float_t zAnode=z-0.5;  // to have anode in range 0.-255. and centered on the mid of the pitch
272           Float_t timebin=y-0.5;  // to have time bin in range 0.-255. amd centered on the mid of the bin
273           if(s==1) zAnode += GetSeg()->NpzHalf();  // right side has anodes from 256. to 511.
274           Float_t zdet = GetSeg()->GetLocalZFromAnode(zAnode);
275           Float_t driftTimeUncorr = GetSeg()->GetDriftTimeFromTb(timebin)+jitter*rsdd->GetCarlosRXClockPeriod();
276           Float_t driftTime=driftTimeUncorr-rsdd->GetTimeZero(fModule);
277           if(driftTime<fMaxDrTimeForTightCut && maxADC<fCutOnPeakTight) continue;
278
279           Float_t driftSpeed = cal->GetDriftSpeedAtAnode(zAnode) + rsdd->GetDeltaVDrift(fModule,zAnode>255);
280           Float_t driftPathMicron = driftTime*driftSpeed;
281           const Double_t kMicronTocm = 1.0e-4; 
282           Float_t xdet=(driftPathMicron-GetSeg()->Dx())*kMicronTocm; // xdet is negative
283           if (s==0) xdet=-xdet; // left side has positive local x
284           
285           if(repa->GetUseSDDCorrectionMaps()){
286             Float_t corrx=0, corrz=0;
287             cal->GetCorrections(zdet,xdet,corrz,corrx,GetSeg());
288             zdet+=corrz;
289             xdet+=corrx;
290           }
291           
292           Double_t loc[3]={xdet,0.,zdet},trk[3]={0.,0.,0.};
293           mT2L->MasterToLocal(loc,trk);
294           y=trk[1];
295           z=trk[2]; 
296           
297           q+=(driftTime*rsdd->GetADCvsDriftTime(fModule)); // correction for zero supp.
298           q/=rsdd->GetADCtokeV(fModule);
299           if(cal-> IsAMAt20MHz()) q*=2.; // account for 1/2 sampling freq.
300           if(q<repa->GetMinClusterChargeSDD()) continue; // remove noise clusters
301           
302           Float_t hit[6] = {y, z, 0.0030*0.0030, 0.0020*0.0020, q, 0.};
303           Int_t  info[3] = {clSizTb, clSizAnode, fNlayer[fModule]};
304           if (digits) CheckLabels2(milab);
305           milab[3]=fNdet[fModule];
306           AliITSRecPoint cc(milab,hit,info);
307           cc.SetType(nClust*100+npeaks);
308           cc.SetDriftTime(driftTimeUncorr);
309           cc.SetDriftSide(s);
310           cc.SetChargeRatio(maxADC);
311           if(clusters) new (cl[ncl]) AliITSRecPoint(cc); 
312           else {
313             fDetTypeRec->AddRecPoint(cc);
314           }
315           fNClusters++; // RS
316           ncl++;
317         }
318       }
319     }
320   }
321   AliDebug(2,Form("Clusters found on SDD module %d (unfolding %d) = %d\n",fModule,repa->GetUseUnfoldingInClusterFinderSDD(),ncl));
322
323
324 //______________________________________________________________________
325 void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader){
326     //------------------------------------------------------------
327   // This function creates ITS clusters from raw data
328   //------------------------------------------------------------
329   fNClusters = 0; //RS
330   AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
331   AliDebug(1,Form("%s is used",inputSDD->ClassName()));
332
333   AliITSDDLModuleMapSDD *ddlmap=(AliITSDDLModuleMapSDD*)fDetTypeRec->GetDDLModuleMapSDD();
334   inputSDD->SetDDLModuleMap(ddlmap);
335   for(Int_t iddl=0; iddl<AliITSDDLModuleMapSDD::GetNDDLs(); iddl++){
336     for(Int_t icar=0; icar<AliITSDDLModuleMapSDD::GetNModPerDDL();icar++){
337       Int_t iMod=ddlmap->GetModuleNumber(iddl,icar);
338       if(iMod==-1) continue;
339       AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(iMod);
340       if(cal==0){
341         AliError(Form("Calibration object not present for SDD module %d\n",iMod));
342         continue;
343       }
344       Bool_t isZeroSupp=cal->GetZeroSupp();
345       if(isZeroSupp){ 
346         for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-240,iSid,cal->GetZSLowThreshold(iSid));
347       }else{
348         for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-240,iSid,0);
349       }
350     }
351   }
352   FindClustersSDD(inputSDD);
353   delete inputSDD;
354 }
355
356 void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input) 
357 {
358   //------------------------------------------------------------
359   // Actual SDD cluster finder for raw data
360   //------------------------------------------------------------
361   AliITSRecPointContainer* rpc = AliITSRecPointContainer::Instance();
362   Int_t nClustersSDD = 0;
363   AliBin *bins[2];
364   TBits* anodeFired[2];
365   TBits* ddlAnodeFired[kHybridsPerDDL];
366   for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++){
367     ddlAnodeFired[iHyb]=new TBits(fNAnodes);
368     ddlAnodeFired[iHyb]->ResetAllBits();
369   }
370   Int_t vectModId[kModulesPerDDL];
371   for(Int_t iMod=0; iMod<kModulesPerDDL; iMod++) vectModId[iMod]=-1;
372
373   // read raw data input stream
374   int countRW = 0; //RS
375   if (fRawID2ClusID) fRawID2ClusID->Reset(); //RS if array was provided, we shall store the rawID -> ClusterID
376   //
377   while (input->Next()) {
378     Int_t iModule = input->GetModuleID();
379     if(iModule<0){
380       AliWarning(Form("Invalid SDD module number %d\n", iModule));
381       continue;
382     }
383     Int_t iCarlos =input->GetCarlosId();
384     Int_t iSide = input->GetChannel();
385     Int_t iHybrid=iCarlos*2+iSide;
386
387     if (input->IsCompletedModule()) {
388       // store the module number
389       vectModId[iCarlos]=iModule;
390     }
391     else if (input->IsCompletedDDL()) {
392       // when all data from a DDL was read, search for clusters
393       Int_t jitter=input->GetJitter();
394       for(Int_t iMod=0; iMod<kModulesPerDDL; iMod++){
395         if(vectModId[iMod]>=0){
396           fModule = vectModId[iMod];
397           TClonesArray* clusters = rpc->UncheckedGetClusters(fModule);
398           bins[0]=fDDLBins[iMod*2];   // first hybrid of the module
399           bins[1]=fDDLBins[iMod*2+1]; // second hybrid of the module
400           anodeFired[0]=ddlAnodeFired[iMod*2];
401           anodeFired[1]=ddlAnodeFired[iMod*2+1];
402           FindClustersSDD(bins, anodeFired, NULL, clusters,jitter);
403           Int_t nClusters = clusters->GetEntriesFast();
404           nClustersSDD += nClusters;
405           vectModId[iMod]=-1;
406         }
407         for (Int_t s=0; s<2; s++){
408           Int_t indexHyb=iMod*2+s;
409           for(Int_t iAnode=0; iAnode<GetSeg()->NpzHalf(); iAnode++){
410             if(ddlAnodeFired[indexHyb]->TestBitNumber(iAnode)==kFALSE) continue;
411             for(Int_t iTimeBin=0; iTimeBin<GetSeg()->Npx(); iTimeBin++){
412               Int_t index=(iTimeBin+1)*fNZbins+(iAnode+1);
413               fDDLBins[indexHyb][index].Reset();
414             }
415           }
416         }
417         ddlAnodeFired[iMod*2]->ResetAllBits();
418         ddlAnodeFired[iMod*2+1]->ResetAllBits();
419       }
420     }else{
421     // fill the current digit into the bins array
422       if(iHybrid<0 || iHybrid>=kHybridsPerDDL){ 
423         AliWarning(Form("Invalid SDD hybrid number %d on module %d\n", iHybrid,iModule));
424         continue;
425       }
426       AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(iModule);    
427       if(cal==0){
428         AliError(Form("Calibration object not present for SDD module %d\n",iModule));
429         continue;
430       }
431       Float_t charge=input->GetSignal();
432       Int_t chan=input->GetCoord1()+fNAnodes*iSide;
433       Float_t gain=cal->GetChannelGain(chan)/fDetTypeRec->GetAverageGainSDD();;
434       Float_t baseline = cal->GetBaseline(chan);
435       if(charge>baseline) charge-=baseline;
436       else charge=0;
437       if(gain>0.){ // Bad channels have gain=0
438         charge/=gain;
439         if(charge>=cal->GetThresholdAnode(chan)) {
440           Int_t q=(Int_t)(charge+0.5);
441           Int_t iz = input->GetCoord1();
442           Int_t itb = input->GetCoord2();
443           Int_t index = (itb+1) * fNZbins + (iz+1);
444           if((itb < fNTimeBins) && (iz < fNAnodes)) {
445             fDDLBins[iHybrid][index].SetQ(q);
446             fDDLBins[iHybrid][index].SetMask(1);
447             fDDLBins[iHybrid][index].SetIndex(index);
448             fDDLBins[iHybrid][index].SetRawID(countRW); //RS register raw id
449             ddlAnodeFired[iHybrid]->SetBitNumber(iz);
450           }else{
451             AliWarning(Form("Invalid SDD cell: Anode=%d   TimeBin=%d",iz,itb));   
452           }
453         }
454       }
455     }
456     countRW++; //RS
457   }
458   for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++){ 
459    delete ddlAnodeFired[iHyb];
460   }
461   AliDebug(1,Form("found clusters in ITS SDD: %d", nClustersSDD));
462 }
463
464 //______________________________________________________________________
465 Bool_t AliITSClusterFinderV2SDD::NoiseSuppress(Int_t k, Int_t sid, AliBin* bins, const AliITSCalibrationSDD* cal) const {
466   // applies zero suppression using the measured noise of each anode
467   // threshold values from ALICE-INT-1999-28 V10
468   // returns kTRUE if the digit should eb noise suppressed, kFALSE if it should be kept
469   Float_t xfactL=2.2; 
470   Float_t xfactH=4.0;
471   //
472
473   Int_t iAn=(k%fNZbins)-1;
474   if(iAn<0 || iAn>255) return kTRUE;
475   if(sid==1) iAn+=256;
476   Int_t nLow=0, nHigh=0;
477   Float_t noise=cal->GetNoiseAfterElectronics(iAn);
478   Float_t noisem1=noise;
479   if(iAn>1) noisem1=cal->GetNoiseAfterElectronics(iAn-1);
480   Float_t noisep1=noise;
481   if(iAn<511) noisep1=cal->GetNoiseAfterElectronics(iAn+1);
482   Float_t tL=noise*xfactL;
483   Float_t tH=noise*xfactH;
484   Float_t tLp1=noisep1*xfactL;
485   Float_t tHp1=noisep1*xfactH;
486   Float_t tLm1=noisem1*xfactL;
487   Float_t tHm1=noisem1*xfactH;
488   Int_t cC=bins[k].GetQ();
489   if(cC<=tL){
490     bins[k].SetQ(0);
491     bins[k].SetMask(0xFFFFFFFE);
492     return kTRUE;;
493   }
494   nLow++; // cC is greater than tL
495   if(cC>tH) nHigh++;
496   Int_t sS=bins[k-1].GetQ();
497   if(sS>tLm1) nLow++;
498   if(sS>tHm1) nHigh++;
499   Int_t nN=bins[k+1].GetQ();
500   if(nN>tLp1) nLow++;
501   if(nN>tHp1) nHigh++;
502   Int_t eE=bins[k-fNZbins].GetQ();
503   if(eE>tL) nLow++;
504   if(eE>tH) nHigh++;
505   Int_t wW=bins[k+fNZbins].GetQ();
506   if(wW>tL) nLow++;
507   if(wW>tH) nHigh++;
508   if(nLow<2 || nHigh<1) return kTRUE;
509   else return kFALSE;
510 }
511
512
513