Adding resolution parameterization document (Marian)
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderV2SDD.cxx
CommitLineData
04366a57 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 **************************************************************************/
d76cb3ad 15
16/* $Id$*/
17
04366a57 18////////////////////////////////////////////////////////////////////////////
19// Implementation of the ITS clusterer V2 class //
20// //
21// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch //
22// //
23///////////////////////////////////////////////////////////////////////////
24
25
04366a57 26
ae485645 27#include <TClonesArray.h>
04366a57 28#include "AliITSClusterFinderV2SDD.h"
00a7cc50 29#include "AliITSRecPoint.h"
7d62fb64 30#include "AliITSDetTypeRec.h"
04366a57 31#include "AliRawReader.h"
0599a018 32#include "AliITSRawStreamSDD.h"
5bfe44ce 33#include "AliITSCalibrationSDD.h"
34#include "AliITSDetTypeRec.h"
35#include "AliITSsegmentationSDD.h"
04366a57 36#include "AliITSdigitSDD.h"
b4704be3 37#include "AliITSgeomTGeo.h"
04366a57 38ClassImp(AliITSClusterFinderV2SDD)
39
4952f440 40AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD(AliITSDetTypeRec* dettyp):AliITSClusterFinderV2(dettyp)
a66a0eb6 41{
04366a57 42
43 //Default constructor
44
04366a57 45}
46
47
48void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
49
50 //Find clusters V2
51 SetModule(mod);
52 FindClustersSDD(fDigits);
53
54}
55
56void AliITSClusterFinderV2SDD::FindClustersSDD(TClonesArray *digits) {
57 //------------------------------------------------------------
58 // Actual SDD cluster finder
59 //------------------------------------------------------------
4952f440 60 Int_t nAnodes = GetSeg()->NpzHalf();
61 Int_t nzBins = nAnodes+2;
62 Int_t nTimeBins = GetSeg()->Npx();
63 Int_t nxBins = nTimeBins+2;
f6b6d58e 64 const Int_t kMaxBin=nzBins*nxBins;
04366a57 65
66 AliBin *bins[2];
4952f440 67 bins[0]=new AliBin[kMaxBin];
68 bins[1]=new AliBin[kMaxBin];
404c1c29 69 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
9c7f5947 70 if(cal==0){
71 AliError(Form("Calibration object not present for SDD module %d\n",fModule));
72 return;
73 }
0599a018 74 AliITSresponseSDD* res = (AliITSresponseSDD*)cal->GetResponse();
75 const char *option=res->ZeroSuppOption();
04366a57 76 AliITSdigitSDD *d=0;
77 Int_t i, ndigits=digits->GetEntriesFast();
78 for (i=0; i<ndigits; i++) {
79 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
20f3f947 80 Int_t ian=d->GetCoord1();
81 Int_t itb=d->GetCoord2();
82 Int_t iSide=0;
83 if (ian >= nAnodes) iSide=1;
84 Float_t gain=cal->GetChannelGain(ian);
5683bd96 85 Float_t charge=d->GetSignal();
20f3f947 86 if(strstr(option,"ZS")) charge+=(Float_t)cal->GetZSLowThreshold(iSide);
87 Float_t baseline = cal->GetBaseline(ian);
88 if(charge>baseline) charge-=baseline;
89 else charge=0;
5683bd96 90
9c7f5947 91 if(gain>0.){ // Bad channels have gain=0.
92 charge/=gain;
20f3f947 93 if(charge<cal->GetThresholdAnode(ian)) continue;
9c7f5947 94 Int_t q=(Int_t)(charge+0.5);
20f3f947 95 Int_t y=itb+1;
96 Int_t z=ian+1;
9c7f5947 97 if (z <= nAnodes){
98 bins[0][y*nzBins+z].SetQ(q);
99 bins[0][y*nzBins+z].SetMask(1);
100 bins[0][y*nzBins+z].SetIndex(i);
101 } else {
102 z-=nAnodes;
103 bins[1][y*nzBins+z].SetQ(q);
104 bins[1][y*nzBins+z].SetMask(1);
105 bins[1][y*nzBins+z].SetIndex(i);
106 }
04366a57 107 }
108 }
109
4952f440 110 FindClustersSDD(bins, kMaxBin, nzBins, digits);
04366a57 111
112 delete[] bins[0];
113 delete[] bins[1];
114
115}
116
117void AliITSClusterFinderV2SDD::
118FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
119 TClonesArray *digits, TClonesArray *clusters) {
120 //------------------------------------------------------------
121 // Actual SDD cluster finder
122 //------------------------------------------------------------
b4704be3 123
124 const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(fModule);
404c1c29 125 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
9c7f5947 126 if(cal==0){
127 AliError(Form("Calibration object not present for SDD module %d\n",fModule));
128 return;
129 }
04366a57 130 Int_t ncl=0;
131 TClonesArray &cl=*clusters;
132 for (Int_t s=0; s<2; s++)
133 for (Int_t i=0; i<nMaxBin; i++) {
134 if (bins[s][i].IsUsed()) continue;
135 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
136 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
137
138 if (npeaks>30) continue;
139 if (npeaks==0) continue;
140
141 Int_t k,l;
142 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
143 if (idx[k] < 0) continue; //this peak is already removed
144 for (l=k+1; l<npeaks; l++) {
f6b6d58e 145 if (idx[l] < 0) continue; //this peak is already removed
146 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
147 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
148 Int_t di=TMath::Abs(ki - li);
149 Int_t dj=TMath::Abs(kj - lj);
150 if (di>1 || dj>1) continue;
151 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
152 msk[l]=msk[k];
153 idx[l]*=-1;
154 } else {
155 msk[k]=msk[l];
156 idx[k]*=-1;
157 break;
158 }
04366a57 159 }
160 }
161
162 for (k=0; k<npeaks; k++) {
163 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
164 }
165
166 for (k=0; k<npeaks; k++) {
f6b6d58e 167 if (idx[k] < 0) continue; //removed peak
168 AliITSRecPoint c;
169 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
170 //mi change
171 Int_t milab[10];
172 for (Int_t ilab=0;ilab<10;ilab++){
173 milab[ilab]=-2;
174 }
175 Int_t maxi=0,mini=0,maxj=0,minj=0;
176 //AliBin *bmax=&bins[s][idx[k]];
177 //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
178
179 for (Int_t di=-2; di<=2;di++){
180 for (Int_t dj=-3;dj<=3;dj++){
181 Int_t index = idx[k]+di+dj*nzBins;
182 if (index<0) continue;
183 if (index>=nMaxBin) continue;
184 AliBin *b=&bins[s][index];
185 Int_t nAnode=index%nzBins-1;
186 Int_t adcSignal=b->GetQ();
187 if(adcSignal>cal->GetThresholdAnode(nAnode)){
188 if (di>maxi) maxi=di;
189 if (di<mini) mini=di;
190 if (dj>maxj) maxj=dj;
191 if (dj<minj) minj=dj;
192 }
193 //
194 if(digits) {
195 if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
196 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
197 for (Int_t itrack=0;itrack<10;itrack++){
198 Int_t track = (d->GetTracks())[itrack];
199 if (track>=0) {
200 AddLabel(milab, track);
201 }
202 }
203 }
204 }
205 }
206 }
207
208
209 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
210 y/=q; z/=q;
211 Float_t zAnode=z-0.5; // to have anode in range 0.-255. and centered on the mid of the pitch
212 Float_t timebin=y-0.5; // to have time bin in range 0.-255. amd centered on the mid of the bin
213 if(s==1) zAnode += GetSeg()->NpzHalf(); // right side has anodes from 256. to 511.
214 Float_t zdet = GetSeg()->GetLocalZFromAnode(zAnode);
215 Float_t driftTime = GetSeg()->GetDriftTimeFromTb(timebin) - cal->GetTimeOffset();
216 Float_t driftPathMicron = cal->GetDriftPath(driftTime,zAnode);
217 const Double_t kMicronTocm = 1.0e-4;
218 Float_t xdet=(driftPathMicron-GetSeg()->Dx())*kMicronTocm; // xdet is negative
219 if (s==0) xdet=-xdet; // left side has positive local x
c9a38d3d 220
221 Float_t corrx=0, corrz=0;
222 cal->GetCorrections(zdet,xdet,corrz,corrx,GetSeg());
223 zdet+=corrz;
224 xdet+=corrx;
f6b6d58e 225
226 Double_t loc[3]={xdet,0.,zdet},trk[3]={0.,0.,0.};
227 mT2L->MasterToLocal(loc,trk);
228 y=trk[1];
229 z=trk[2];
230
231 q/=cal->GetADC2keV(); //to have MPV 1 MIP = 86.4 KeV
232 Float_t hit[5] = {y, z, 0.0030*0.0030, 0.0020*0.0020, q};
233 Int_t info[3] = {maxj-minj+1, maxi-mini+1, fNlayer[fModule]};
234 if (digits) {
235 // AliBin *b=&bins[s][idx[k]];
236 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
237 {
238 //Int_t lab[3];
239 //lab[0]=(d->GetTracks())[0];
240 //lab[1]=(d->GetTracks())[1];
241 //lab[2]=(d->GetTracks())[2];
242 //CheckLabels(lab);
243 CheckLabels2(milab);
244 }
245 }
246 milab[3]=fNdet[fModule];
247
248 AliITSRecPoint cc(milab,hit,info);
249 cc.SetType(npeaks);
250 if(clusters) new (cl[ncl]) AliITSRecPoint(cc);
251 else {
252 fDetTypeRec->AddRecPoint(cc);
253 }
254 ncl++;
04366a57 255 }
256 }
24c98369 257
04366a57 258}
f6b6d58e 259//______________________________________________________________________
04366a57 260void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
261 //------------------------------------------------------------
262 // This function creates ITS clusters from raw data
263 //------------------------------------------------------------
264 rawReader->Reset();
0599a018 265 AliITSRawStreamSDD inputSDD(rawReader);
979b5a5f 266 AliITSDDLModuleMapSDD *ddlmap=(AliITSDDLModuleMapSDD*)fDetTypeRec->GetDDLModuleMapSDD();
267 inputSDD.SetDDLModuleMap(ddlmap);
04366a57 268 FindClustersSDD(&inputSDD,clusters);
269
270}
271
272void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input,
273 TClonesArray** clusters)
274{
275 //------------------------------------------------------------
276 // Actual SDD cluster finder for raw data
277 //------------------------------------------------------------
278 Int_t nClustersSDD = 0;
4952f440 279 Int_t nAnodes = GetSeg()->NpzHalf();
280 Int_t nzBins = nAnodes+2;
281 Int_t nTimeBins = GetSeg()->Npx();
282 Int_t nxBins = nTimeBins+2;
f6b6d58e 283 const Int_t kMaxBin=nzBins*nxBins;
ae485645 284 AliBin *bins[2];
93a93288 285 AliBin *ddlbins[kHybridsPerDDL]; // 12 modules (=24 hybrids) of 1 DDL read "in parallel"
286 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++) ddlbins[iHyb]=new AliBin[kMaxBin];
04366a57 287 // read raw data input stream
14dceddf 288 while (input->Next()) {
e4da2288 289 Int_t iModule = input->GetModuleID();
93a93288 290 if(iModule<0){
291 AliWarning(Form("Invalid SDD module number %d\n", iModule));
292 continue;
293 }
44c5b268 294
14dceddf 295 Int_t iCarlos =((AliITSRawStreamSDD*)input)->GetCarlosId();
296 Int_t iSide = ((AliITSRawStreamSDD*)input)->GetChannel();
297 Int_t iHybrid=iCarlos*2+iSide;
298 if (input->IsCompletedModule()) {
04366a57 299 // when all data from a module was read, search for clusters
44c5b268 300 if(iCarlos<0){
301 AliWarning(Form("Invalid SDD carlos number %d on module %d\n", iCarlos,iModule));
302 continue;
303 }
304 clusters[iModule] = new TClonesArray("AliITSRecPoint");
305 fModule = iModule;
306 bins[0]=ddlbins[iCarlos*2]; // first hybrid of the completed module
307 bins[1]=ddlbins[iCarlos*2+1]; // second hybrid of the completed module
308 FindClustersSDD(bins, kMaxBin, nzBins, NULL, clusters[iModule]);
309 Int_t nClusters = clusters[iModule]->GetEntriesFast();
310 nClustersSDD += nClusters;
311 for(Int_t iBin=0;iBin<kMaxBin; iBin++){
312 ddlbins[iCarlos*2][iBin].Reset();
313 ddlbins[iCarlos*2+1][iBin].Reset();
314 }
5dfa68c5 315 }else{
04366a57 316 // fill the current digit into the bins array
44c5b268 317 if(iHybrid<0 || iHybrid>=kHybridsPerDDL){
318 AliWarning(Form("Invalid SDD hybrid number %d on module %d\n", iHybrid,iModule));
319 continue;
320 }
e4da2288 321 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(iModule);
9c7f5947 322 if(cal==0){
323 AliError(Form("Calibration object not present for SDD module %d\n",iModule));
324 continue;
325 }
5dfa68c5 326 AliITSresponseSDD* res = (AliITSresponseSDD*)cal->GetResponse();
327 const char *option=res->ZeroSuppOption();
5683bd96 328 Float_t charge=input->GetSignal();
14dceddf 329 Int_t chan=input->GetCoord1()+nAnodes*iSide;
330 Float_t gain=cal->GetChannelGain(chan);
20f3f947 331 if(strstr(option,"ZS")) charge+=(Float_t)cal->GetZSLowThreshold(iSide);
332 Float_t baseline = cal->GetBaseline(chan);
333 if(charge>baseline) charge-=baseline;
334 else charge=0;
9c7f5947 335 if(gain>0.){ // Bad channels have gain=0
336 charge/=gain;
337 if(charge>=cal->GetThresholdAnode(chan)) {
338 Int_t q=(Int_t)(charge+0.5);
339 Int_t iz = input->GetCoord1();
340 Int_t itb = input->GetCoord2();
341 Int_t index = (itb+1) * nzBins + (iz+1);
342 if(index<kMaxBin){
343 ddlbins[iHybrid][index].SetQ(q);
344 ddlbins[iHybrid][index].SetMask(1);
345 ddlbins[iHybrid][index].SetIndex(index);
346 }else{
347 AliWarning(Form("Invalid SDD cell: Anode=%d TimeBin=%d",iz,itb));
348 }
93a93288 349 }
5dfa68c5 350 }
04366a57 351 }
352 }
93a93288 353 for(Int_t iHyb=0;iHyb<kHybridsPerDDL;iHyb++) delete [] ddlbins[iHyb];
04366a57 354 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
04366a57 355}
356
357
d97eb3fe 358