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