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>
28 #include "AliITSClusterFinderV2SDD.h"
29 #include "AliITSRecPoint.h"
30 #include "AliITSDetTypeRec.h"
31 #include "AliRawReader.h"
32 #include "AliITSRawStreamSDD.h"
33 #include "AliITSCalibrationSDD.h"
34 #include "AliITSDetTypeRec.h"
35 #include "AliITSsegmentationSDD.h"
36 #include "AliITSdigitSDD.h"
37 #include "AliITSgeomTGeo.h"
38 ClassImp(AliITSClusterFinderV2SDD)
40 AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD(AliITSDetTypeRec* dettyp):AliITSClusterFinderV2(dettyp)
48 void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
52 FindClustersSDD(fDigits);
56 void AliITSClusterFinderV2SDD::FindClustersSDD(TClonesArray *digits) {
57 //------------------------------------------------------------
58 // Actual SDD cluster finder
59 //------------------------------------------------------------
60 Int_t nAnodes = GetSeg()->NpzHalf();
61 Int_t nzBins = nAnodes+2;
62 Int_t nTimeBins = GetSeg()->Npx();
63 Int_t nxBins = nTimeBins+2;
64 const Int_t kMaxBin=nzBins*(nxBins+2);
67 bins[0]=new AliBin[kMaxBin];
68 bins[1]=new AliBin[kMaxBin];
69 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
70 AliITSresponseSDD* res = (AliITSresponseSDD*)cal->GetResponse();
71 const char *option=res->ZeroSuppOption();
73 Int_t i, ndigits=digits->GetEntriesFast();
74 for (i=0; i<ndigits; i++) {
75 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
76 Int_t y=d->GetCoord2()+1; //y
77 Int_t z=d->GetCoord1()+1; //z
78 Float_t gain=cal->GetChannelGain(d->GetCoord1());
79 Float_t charge=d->GetSignal();
81 if(!((strstr(option,"1D")) || (strstr(option,"2D")))){
82 Float_t baseline = cal->GetBaseline(d->GetCoord1());
83 if(charge>baseline) charge-=baseline;
87 if(gain>0) charge/=gain;
88 if(charge<cal->GetThresholdAnode(d->GetCoord1())) continue;
89 Int_t q=(Int_t)(charge+0.5);
91 bins[0][y*nzBins+z].SetQ(q);
92 bins[0][y*nzBins+z].SetMask(1);
93 bins[0][y*nzBins+z].SetIndex(i);
96 bins[1][y*nzBins+z].SetQ(q);
97 bins[1][y*nzBins+z].SetMask(1);
98 bins[1][y*nzBins+z].SetIndex(i);
102 FindClustersSDD(bins, kMaxBin, nzBins, digits);
109 void AliITSClusterFinderV2SDD::
110 FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
111 TClonesArray *digits, TClonesArray *clusters) {
112 //------------------------------------------------------------
113 // Actual SDD cluster finder
114 //------------------------------------------------------------
116 const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(fModule);
117 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
119 TClonesArray &cl=*clusters;
120 for (Int_t s=0; s<2; s++)
121 for (Int_t i=0; i<nMaxBin; i++) {
122 if (bins[s][i].IsUsed()) continue;
123 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
124 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
126 if (npeaks>30) continue;
127 if (npeaks==0) continue;
130 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
131 if (idx[k] < 0) continue; //this peak is already removed
132 for (l=k+1; l<npeaks; l++) {
133 if (idx[l] < 0) continue; //this peak is already removed
134 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
135 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
136 Int_t di=TMath::Abs(ki - li);
137 Int_t dj=TMath::Abs(kj - lj);
138 if (di>1 || dj>1) continue;
139 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
150 for (k=0; k<npeaks; k++) {
151 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
154 for (k=0; k<npeaks; k++) {
155 if (idx[k] < 0) continue; //removed peak
157 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
160 for (Int_t ilab=0;ilab<10;ilab++){
163 Int_t maxi=0,mini=0,maxj=0,minj=0;
164 //AliBin *bmax=&bins[s][idx[k]];
165 //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
167 for (Int_t di=-2; di<=2;di++){
168 for (Int_t dj=-3;dj<=3;dj++){
169 Int_t index = idx[k]+di+dj*nzBins;
170 if (index<0) continue;
171 if (index>=nMaxBin) continue;
172 AliBin *b=&bins[s][index];
173 Int_t nAnode=index%nzBins-1;
174 Int_t adcSignal=b->GetQ();
175 if(adcSignal>cal->GetThresholdAnode(nAnode)){
176 if (di>maxi) maxi=di;
177 if (di<mini) mini=di;
178 if (dj>maxj) maxj=dj;
179 if (dj<minj) minj=dj;
183 if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
184 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
185 for (Int_t itrack=0;itrack<10;itrack++){
186 Int_t track = (d->GetTracks())[itrack];
188 AddLabel(milab, track);
197 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
201 const Double_t kMicronTocm = 1.0e-4;
202 Float_t timeBinCenter = y-0.5;
203 Float_t zAnode=z-0.5;
204 Float_t zdet = (zAnode*GetSeg()->Dpz(0)-GetSeg()->Dz()/2.)*kMicronTocm;
205 Float_t driftTime = timeBinCenter*GetSeg()->Dpx(0) - cal->GetTimeOffset();
206 Float_t xdet = cal->GetDriftPath(driftTime,zAnode);
207 xdet=(xdet-GetSeg()->Dx())*kMicronTocm;
211 CorrectPosition(zdet,xdet);
213 Double_t loc[3]={xdet,0.,zdet},trk[3]={0.,0.,0.};
214 mT2L->MasterToLocal(loc,trk);
218 q/=cal->GetADC2keV(); //to have MPV 1 MIP = 86.4 KeV
219 Float_t hit[5] = {y, z, 0.0030*0.0030, 0.0020*0.0020, q};
220 Int_t info[3] = {maxj-minj+1, maxi-mini+1, fNlayer[fModule]};
222 // AliBin *b=&bins[s][idx[k]];
223 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
226 //lab[0]=(d->GetTracks())[0];
227 //lab[1]=(d->GetTracks())[1];
228 //lab[2]=(d->GetTracks())[2];
233 milab[3]=fNdet[fModule];
235 AliITSRecPoint cc(milab,hit,info);
238 if(clusters) new (cl[ncl]) AliITSRecPoint(cc);
240 fDetTypeRec->AddRecPoint(cc);
250 void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
251 //------------------------------------------------------------
252 // This function creates ITS clusters from raw data
253 //------------------------------------------------------------
255 AliITSRawStreamSDD inputSDD(rawReader);
257 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(240);
258 printf("gain anode 10=%f\n",cal->GetDriftSpeedAtAnode(10));
259 printf("drift speed anode 10=%f\n",cal->GetChannelGain(10));
261 AliITSDDLModuleMapSDD *ddlmap=(AliITSDDLModuleMapSDD*)fDetTypeRec->GetDDLModuleMapSDD();
262 inputSDD.SetDDLModuleMap(ddlmap);
263 FindClustersSDD(&inputSDD,clusters);
267 void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input,
268 TClonesArray** clusters)
270 //------------------------------------------------------------
271 // Actual SDD cluster finder for raw data
272 //------------------------------------------------------------
273 Int_t nClustersSDD = 0;
274 Int_t nAnodes = GetSeg()->NpzHalf();
275 Int_t nzBins = nAnodes+2;
276 Int_t nTimeBins = GetSeg()->Npx();
277 Int_t nxBins = nTimeBins+2;
278 const Int_t kMaxBin=nzBins*(nxBins+2);
280 AliBin *ddlbins[kHybridsPerDDL]; // 12 modules (=24 hybrids) of 1 DDL read "in parallel"
281 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++) ddlbins[iHyb]=new AliBin[kMaxBin];
282 // read raw data input stream
283 while (input->Next()) {
284 Int_t iModule = input->GetModuleID();
286 AliWarning(Form("Invalid SDD module number %d\n", iModule));
290 Int_t iCarlos =((AliITSRawStreamSDD*)input)->GetCarlosId();
291 Int_t iSide = ((AliITSRawStreamSDD*)input)->GetChannel();
292 Int_t iHybrid=iCarlos*2+iSide;
293 if (input->IsCompletedModule()) {
294 // when all data from a module was read, search for clusters
296 AliWarning(Form("Invalid SDD carlos number %d on module %d\n", iCarlos,iModule));
299 clusters[iModule] = new TClonesArray("AliITSRecPoint");
301 bins[0]=ddlbins[iCarlos*2]; // first hybrid of the completed module
302 bins[1]=ddlbins[iCarlos*2+1]; // second hybrid of the completed module
303 FindClustersSDD(bins, kMaxBin, nzBins, NULL, clusters[iModule]);
304 Int_t nClusters = clusters[iModule]->GetEntriesFast();
305 nClustersSDD += nClusters;
306 for(Int_t iBin=0;iBin<kMaxBin; iBin++){
307 ddlbins[iCarlos*2][iBin].Reset();
308 ddlbins[iCarlos*2+1][iBin].Reset();
311 // fill the current digit into the bins array
312 if(iHybrid<0 || iHybrid>=kHybridsPerDDL){
313 AliWarning(Form("Invalid SDD hybrid number %d on module %d\n", iHybrid,iModule));
316 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(iModule);
317 AliITSresponseSDD* res = (AliITSresponseSDD*)cal->GetResponse();
318 const char *option=res->ZeroSuppOption();
319 Float_t charge=input->GetSignal();
320 Int_t chan=input->GetCoord1()+nAnodes*iSide;
321 Float_t gain=cal->GetChannelGain(chan);
322 if(!((strstr(option,"1D")) || (strstr(option,"2D")))){
323 Float_t baseline = cal->GetBaseline(chan);
324 if(charge>baseline) charge-=baseline;
327 if(gain>0) charge/=gain;
328 if(charge>=cal->GetThresholdAnode(chan)) {
329 Int_t q=(Int_t)(charge+0.5);
330 Int_t iz = input->GetCoord1();
331 Int_t itb = input->GetCoord2();
332 Int_t index = (itb+1) * nzBins + (iz+1);
334 ddlbins[iHybrid][index].SetQ(q);
335 ddlbins[iHybrid][index].SetMask(1);
336 ddlbins[iHybrid][index].SetIndex(index);
339 AliWarning(Form("Invalid SDD cell: Anode=%d TimeBin=%d",iz,itb));
344 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++) delete [] ddlbins[iHyb];
345 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
349 //_________________________________________________________________________
350 void AliITSClusterFinderV2SDD::CorrectPosition(Float_t &z, Float_t&y){
352 //correction of coordinates using the maps stored in the DB
354 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
355 static const Int_t knbint = cal->GetMapTimeNBin();
356 static const Int_t knbina = cal->Chips()*cal->Channels();
357 const Double_t kMicronTocm = 1.0e-4;
358 Float_t stepa = (GetSeg()->Dpz(0))*kMicronTocm; //anode pitch in cm
359 Float_t stept = (GetSeg()->Dx()/cal->GetMapTimeNBin()/2.)/10.;
361 Int_t bint = TMath::Abs((Int_t)(y/stept));
362 if(y>=0) bint+=(Int_t)(knbint/2.);
363 if(bint>knbint) AliError("Wrong bin number!");
365 Int_t bina = TMath::Abs((Int_t)(z/stepa));
366 if(z>=0) bina+=(Int_t)(knbina/2.);
367 if(bina>knbina) AliError("Wrong bin number!");
369 Float_t devz = cal->GetMapACell(bina,bint)*kMicronTocm;
370 Float_t devx = cal->GetMapTCell(bina,bint)*kMicronTocm;