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