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