HLT build system fix
[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
e56160b8 40AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD(AliITSDetTypeRec* dettyp):AliITSClusterFinderV2(dettyp),
41fNySDD(256),
42fNzSDD(256),
e56160b8 43fZpitchSDD(0.02940),
44fHwSDD(3.5085),
a66a0eb6 45fHlSDD(3.7632)
46{
04366a57 47
48 //Default constructor
49
04366a57 50}
51
52
53void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
54
55 //Find clusters V2
56 SetModule(mod);
57 FindClustersSDD(fDigits);
58
59}
60
61void AliITSClusterFinderV2SDD::FindClustersSDD(TClonesArray *digits) {
62 //------------------------------------------------------------
63 // Actual SDD cluster finder
64 //------------------------------------------------------------
65 Int_t kNzBins = fNzSDD + 2;
66 const Int_t kMAXBIN=kNzBins*(fNySDD+2);
67
68 AliBin *bins[2];
69 bins[0]=new AliBin[kMAXBIN];
70 bins[1]=new AliBin[kMAXBIN];
404c1c29 71 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
0599a018 72 AliITSresponseSDD* res = (AliITSresponseSDD*)cal->GetResponse();
73 const char *option=res->ZeroSuppOption();
04366a57 74 AliITSdigitSDD *d=0;
75 Int_t i, ndigits=digits->GetEntriesFast();
76 for (i=0; i<ndigits; i++) {
77 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
78 Int_t y=d->GetCoord2()+1; //y
79 Int_t z=d->GetCoord1()+1; //z
80 Int_t q=d->GetSignal();
0599a018 81 if(!((strstr(option,"1D")) || (strstr(option,"2D")))){
82 Float_t baseline = cal->GetBaseline(d->GetCoord1());
83 if(q>baseline) q-=(Int_t)baseline;
84 else q=0;
85 }
9e4d7193 86 if(q<cal->GetThresholdAnode(d->GetCoord1())) continue;
404c1c29 87 //if (q<3) continue;
04366a57 88
89 if (z <= fNzSDD) {
90 bins[0][y*kNzBins+z].SetQ(q);
91 bins[0][y*kNzBins+z].SetMask(1);
92 bins[0][y*kNzBins+z].SetIndex(i);
93 } else {
94 z-=fNzSDD;
95 bins[1][y*kNzBins+z].SetQ(q);
96 bins[1][y*kNzBins+z].SetMask(1);
97 bins[1][y*kNzBins+z].SetIndex(i);
98 }
99 }
100
101 FindClustersSDD(bins, kMAXBIN, kNzBins, digits);
102
103 delete[] bins[0];
104 delete[] bins[1];
105
106}
107
108void AliITSClusterFinderV2SDD::
109FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
110 TClonesArray *digits, TClonesArray *clusters) {
111 //------------------------------------------------------------
112 // Actual SDD cluster finder
113 //------------------------------------------------------------
b4704be3 114
115 const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(fModule);
404c1c29 116 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
04366a57 117 Int_t ncl=0;
118 TClonesArray &cl=*clusters;
119 for (Int_t s=0; s<2; s++)
120 for (Int_t i=0; i<nMaxBin; i++) {
121 if (bins[s][i].IsUsed()) continue;
122 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
123 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
124
125 if (npeaks>30) continue;
126 if (npeaks==0) continue;
127
128 Int_t k,l;
129 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
130 if (idx[k] < 0) continue; //this peak is already removed
131 for (l=k+1; l<npeaks; l++) {
132 if (idx[l] < 0) continue; //this peak is already removed
133 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
134 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
135 Int_t di=TMath::Abs(ki - li);
136 Int_t dj=TMath::Abs(kj - lj);
137 if (di>1 || dj>1) continue;
138 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
139 msk[l]=msk[k];
140 idx[l]*=-1;
141 } else {
142 msk[k]=msk[l];
143 idx[k]*=-1;
144 break;
145 }
146 }
147 }
148
149 for (k=0; k<npeaks; k++) {
150 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
151 }
152
153 for (k=0; k<npeaks; k++) {
154 if (idx[k] < 0) continue; //removed peak
75fb37cc 155 AliITSRecPoint c;
04366a57 156 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
157 //mi change
158 Int_t milab[10];
159 for (Int_t ilab=0;ilab<10;ilab++){
160 milab[ilab]=-2;
161 }
162 Int_t maxi=0,mini=0,maxj=0,minj=0;
163 //AliBin *bmax=&bins[s][idx[k]];
164 //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
24c98369 165
5dfa68c5 166 for (Int_t di=-2; di<=2;di++){
04366a57 167 for (Int_t dj=-3;dj<=3;dj++){
168 Int_t index = idx[k]+di+dj*nzBins;
169 if (index<0) continue;
170 if (index>=nMaxBin) continue;
171 AliBin *b=&bins[s][index];
5dfa68c5 172 Int_t nAnode=index%nzBins-1;
173 Int_t adcSignal=b->GetQ();
174 if(adcSignal>cal->GetThresholdAnode(nAnode)){
175 if (di>maxi) maxi=di;
176 if (di<mini) mini=di;
177 if (dj>maxj) maxj=dj;
178 if (dj<minj) minj=dj;
179 }
24c98369 180 //
181 if(digits) {
182 if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
183 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
184 for (Int_t itrack=0;itrack<10;itrack++){
185 Int_t track = (d->GetTracks())[itrack];
186 if (track>=0) {
187 AddLabel(milab, track);
04366a57 188 }
189 }
190 }
5dfa68c5 191 }
04366a57 192 }
5dfa68c5 193 }
d76cb3ad 194
04366a57 195
04366a57 196 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
197 y/=q; z/=q;
d76cb3ad 198
404c1c29 199
200 Float_t yyyy = y;
04366a57 201
202 z=(z-0.5)*fZpitchSDD;
203 z-=fHlSDD;
404c1c29 204 Float_t zdet = z;
9e4d7193 205 Float_t timebin = GetSeg()->Dpx(0);
a66a0eb6 206 Float_t driftTime = (yyyy-0.5)*timebin - cal->GetTimeOffset();
d76cb3ad 207 Float_t xdet = cal->GetDriftPath(driftTime,0);
208 xdet=xdet/10000.-fHwSDD;
404c1c29 209 if (s) xdet=-xdet;
210
211 CorrectPosition(zdet,xdet);
212
b4704be3 213 {
214 Double_t loc[3]={xdet,0.,zdet},trk[3]={0.,0.,0.};
215 mT2L->MasterToLocal(loc,trk);
216 y=trk[1];
217 z=trk[2];
218 }
a66a0eb6 219 q/=cal->GetADC2keV(); //to have MPV 1 MIP = 86.4 KeV
ecb9da3c 220 Float_t hit[5] = {y, z, 0.0030*0.0030, 0.0020*0.0020, q};
221 Int_t info[3] = {maxj-minj+1, maxi-mini+1, fNlayer[fModule]};
04366a57 222 if (digits) {
223 // AliBin *b=&bins[s][idx[k]];
224 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
225 {
226 //Int_t lab[3];
227 //lab[0]=(d->GetTracks())[0];
228 //lab[1]=(d->GetTracks())[1];
229 //lab[2]=(d->GetTracks())[2];
230 //CheckLabels(lab);
231 CheckLabels2(milab);
04366a57 232 }
233 }
ecb9da3c 234 milab[3]=fNdet[fModule];
235
236 AliITSRecPoint cc(milab,hit,info);
237 cc.SetType(npeaks);
238
239 if(clusters) new (cl[ncl]) AliITSRecPoint(cc);
04366a57 240 else {
ecb9da3c 241 fDetTypeRec->AddRecPoint(cc);
04366a57 242 }
243 ncl++;
244 }
245 }
24c98369 246
04366a57 247}
248
249
250
251void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
252 //------------------------------------------------------------
253 // This function creates ITS clusters from raw data
254 //------------------------------------------------------------
255 rawReader->Reset();
0599a018 256 AliITSRawStreamSDD inputSDD(rawReader);
04366a57 257 FindClustersSDD(&inputSDD,clusters);
258
259}
260
261void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input,
262 TClonesArray** clusters)
263{
264 //------------------------------------------------------------
265 // Actual SDD cluster finder for raw data
266 //------------------------------------------------------------
267 Int_t nClustersSDD = 0;
268 Int_t kNzBins = fNzSDD + 2;
269 Int_t kMaxBin = kNzBins * (fNySDD+2);
ae485645 270 AliBin *bins[2];
271 bins[0]=new AliBin[kMaxBin];
272 bins[1]=new AliBin[kMaxBin];
04366a57 273
274 // read raw data input stream
275 while (kTRUE) {
276 Bool_t next = input->Next();
5dfa68c5 277 if (!next || input->IsCompletedModule()) {
04366a57 278 // when all data from a module was read, search for clusters
5dfa68c5 279 Int_t iModule = input->GetModuleID();
ae485645 280 clusters[iModule] = new TClonesArray("AliITSRecPoint");
281 fModule = iModule;
282 FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
283 Int_t nClusters = clusters[iModule]->GetEntriesFast();
284 nClustersSDD += nClusters;
4b59acab 285 for(Int_t iBin=0;iBin<kMaxBin; iBin++){
286 bins[0][iBin].Reset();
287 bins[1][iBin].Reset();
288 }
04366a57 289 if (!next) break;
5dfa68c5 290 }else{
04366a57 291 // fill the current digit into the bins array
5dfa68c5 292 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(input->GetModuleID());
293 AliITSresponseSDD* res = (AliITSresponseSDD*)cal->GetResponse();
294 const char *option=res->ZeroSuppOption();
295 Int_t q=input->GetSignal();
296 if(!((strstr(option,"1D")) || (strstr(option,"2D")))){
297 Float_t baseline = cal->GetBaseline(input->GetCoord1());
298 if(q>baseline) q-=(Int_t)baseline;
299 else q=0;
300 }
301 if(q>=cal->GetThresholdAnode(input->GetCoord1())) {
302 Int_t iz = input->GetCoord1()+1;
303 //Int_t side = ((iz <= fNzSDD) ? 0 : 1);
304 Int_t side = ((AliITSRawStreamSDD*)input)->GetChannel();
305 // iz -= side*fNzSDD;
306 Int_t index = (input->GetCoord2()+1) * kNzBins + iz;
307 bins[side][index].SetQ(q);
308 bins[side][index].SetMask(1);
309 bins[side][index].SetIndex(index);
310 }
04366a57 311 }
312 }
4b59acab 313 delete [] bins[0];
314 delete [] bins[1];
04366a57 315
316 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
04366a57 317}
318
319
5bfe44ce 320//_________________________________________________________________________
321void AliITSClusterFinderV2SDD::CorrectPosition(Float_t &z, Float_t&y){
322
323 //correction of coordinates using the maps stored in the DB
324
325 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)GetResp(fModule);
a97b3678 326 static const Int_t knbint = cal->GetMapTimeNBin();
327 static const Int_t knbina = cal->Chips()*cal->Channels();
5bfe44ce 328 Float_t stepa = (GetSeg()->Dpz(0))/10000.; //anode pitch in cm
329 Float_t stept = (GetSeg()->Dx()/cal->GetMapTimeNBin()/2.)/10.;
404c1c29 330
331 Int_t bint = TMath::Abs((Int_t)(y/stept));
a97b3678 332 if(y>=0) bint+=(Int_t)(knbint/2.);
333 if(bint>knbint) AliError("Wrong bin number!");
5bfe44ce 334
404c1c29 335 Int_t bina = TMath::Abs((Int_t)(z/stepa));
a97b3678 336 if(z>=0) bina+=(Int_t)(knbina/2.);
337 if(bina>knbina) AliError("Wrong bin number!");
5bfe44ce 338
339 Float_t devz = cal->GetMapACell(bina,bint)/10000.;
340 Float_t devx = cal->GetMapTCell(bina,bint)/10000.;
404c1c29 341 z+=devz;
342 y+=devx;
5bfe44ce 343
344
345}