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