Initialization of some variables (Bogdan)
[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 **************************************************************************/
15////////////////////////////////////////////////////////////////////////////
16// Implementation of the ITS clusterer V2 class //
17// //
18// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch //
19// //
20///////////////////////////////////////////////////////////////////////////
21
22
04366a57 23
24#include "AliITSClusterFinderV2SDD.h"
00a7cc50 25#include "AliITSRecPoint.h"
7d62fb64 26#include "AliITSDetTypeRec.h"
04366a57 27#include "AliRawReader.h"
28#include "AliITSRawStreamSDD.h"
29
30#include <TClonesArray.h>
04366a57 31#include "AliITSdigitSDD.h"
32
33ClassImp(AliITSClusterFinderV2SDD)
34
35extern AliRun *gAlice;
36
8ba39da9 37AliITSClusterFinderV2SDD::AliITSClusterFinderV2SDD(AliITSDetTypeRec* dettyp):AliITSClusterFinderV2(dettyp){
04366a57 38
39 //Default constructor
40
41 fNySDD=256; fNzSDD=256;
42 fYpitchSDD=0.01825;
43 fZpitchSDD=0.02940;
44 fHwSDD=3.5085; fHlSDD=3.7632;
45 fYoffSDD=0.0425;
46
47
48
49}
50
51
52void AliITSClusterFinderV2SDD::FindRawClusters(Int_t mod){
53
54 //Find clusters V2
55 SetModule(mod);
56 FindClustersSDD(fDigits);
57
58}
59
60void AliITSClusterFinderV2SDD::FindClustersSDD(TClonesArray *digits) {
61 //------------------------------------------------------------
62 // Actual SDD cluster finder
63 //------------------------------------------------------------
64 Int_t kNzBins = fNzSDD + 2;
65 const Int_t kMAXBIN=kNzBins*(fNySDD+2);
66
67 AliBin *bins[2];
68 bins[0]=new AliBin[kMAXBIN];
69 bins[1]=new AliBin[kMAXBIN];
70
71 AliITSdigitSDD *d=0;
72 Int_t i, ndigits=digits->GetEntriesFast();
73 for (i=0; i<ndigits; i++) {
74 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
75 Int_t y=d->GetCoord2()+1; //y
76 Int_t z=d->GetCoord1()+1; //z
77 Int_t q=d->GetSignal();
78 if (q<3) continue;
79
80 if (z <= fNzSDD) {
81 bins[0][y*kNzBins+z].SetQ(q);
82 bins[0][y*kNzBins+z].SetMask(1);
83 bins[0][y*kNzBins+z].SetIndex(i);
84 } else {
85 z-=fNzSDD;
86 bins[1][y*kNzBins+z].SetQ(q);
87 bins[1][y*kNzBins+z].SetMask(1);
88 bins[1][y*kNzBins+z].SetIndex(i);
89 }
90 }
91
92 FindClustersSDD(bins, kMAXBIN, kNzBins, digits);
93
94 delete[] bins[0];
95 delete[] bins[1];
96
97}
98
99void AliITSClusterFinderV2SDD::
100FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
101 TClonesArray *digits, TClonesArray *clusters) {
102 //------------------------------------------------------------
103 // Actual SDD cluster finder
104 //------------------------------------------------------------
105 Int_t ncl=0;
106 TClonesArray &cl=*clusters;
107 for (Int_t s=0; s<2; s++)
108 for (Int_t i=0; i<nMaxBin; i++) {
109 if (bins[s][i].IsUsed()) continue;
110 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
111 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
112
113 if (npeaks>30) continue;
114 if (npeaks==0) continue;
115
116 Int_t k,l;
117 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
118 if (idx[k] < 0) continue; //this peak is already removed
119 for (l=k+1; l<npeaks; l++) {
120 if (idx[l] < 0) continue; //this peak is already removed
121 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
122 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
123 Int_t di=TMath::Abs(ki - li);
124 Int_t dj=TMath::Abs(kj - lj);
125 if (di>1 || dj>1) continue;
126 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
127 msk[l]=msk[k];
128 idx[l]*=-1;
129 } else {
130 msk[k]=msk[l];
131 idx[k]*=-1;
132 break;
133 }
134 }
135 }
136
137 for (k=0; k<npeaks; k++) {
138 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
139 }
140
141 for (k=0; k<npeaks; k++) {
142 if (idx[k] < 0) continue; //removed peak
00a7cc50 143 AliITSRecPoint c(fDetTypeRec->GetITSgeom());
04366a57 144 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
145 //mi change
146 Int_t milab[10];
147 for (Int_t ilab=0;ilab<10;ilab++){
148 milab[ilab]=-2;
149 }
150 Int_t maxi=0,mini=0,maxj=0,minj=0;
151 //AliBin *bmax=&bins[s][idx[k]];
152 //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
153 Float_t max=3;
154 for (Int_t di=-2; di<=2;di++)
155 for (Int_t dj=-3;dj<=3;dj++){
156 Int_t index = idx[k]+di+dj*nzBins;
157 if (index<0) continue;
158 if (index>=nMaxBin) continue;
159 AliBin *b=&bins[s][index];
160 if (TMath::Abs(b->GetQ())>max){
161 if (di>maxi) maxi=di;
162 if (di<mini) mini=di;
163 if (dj>maxj) maxj=dj;
164 if (dj<minj) minj=dj;
165 //
166 if(digits) {
167 if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
168 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
169 for (Int_t itrack=0;itrack<10;itrack++){
170 Int_t track = (d->GetTracks())[itrack];
171 if (track>=0) {
172 AddLabel(milab, track);
173 }
174 }
175 }
176 }
177 }
178 }
179
180 /*
181 Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
182 Float_t w=par->GetPadPitchWidth(sec);
183 c.SetSigmaY2(s2);
184 if (s2 != 0.) {
185 c.SetSigmaY2(c.GetSigmaY2()*0.108);
186 if (sec<par->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
187 }
188 s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
189 w=par->GetZWidth();
190 c.SetSigmaZ2(s2);
191
192 if (s2 != 0.) {
193 c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
194 if (sec<par->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
195 }
196 */
197
198 c.SetSigmaY2(0.0030*0.0030);
199 c.SetSigmaZ2(0.0020*0.0020);
200 c.SetDetectorIndex(fNdet[fModule]);
201
202 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
203 y/=q; z/=q;
204 //
205 //Float_t s2 = c.GetSigmaY2()/c.GetQ() - y*y;
206 // c.SetSigmaY2(s2);
207 //s2 = c.GetSigmaZ2()/c.GetQ() - z*z;
208 //c.SetSigmaZ2(s2);
209 //
210 y=(y-0.5)*fYpitchSDD;
211 y-=fHwSDD;
212 y-=fYoffSDD; //delay ?
213 if (s) y=-y;
214
215 z=(z-0.5)*fZpitchSDD;
216 z-=fHlSDD;
217
218 y=-(-y+fYshift[fModule]);
219 z= -z+fZshift[fModule];
00a7cc50 220 // c.SetY(y);
221 // c.SetZ(z);
222 c.SetYZ(fModule,y,z);
04366a57 223 c.SetNy(maxj-minj+1);
224 c.SetNz(maxi-mini+1);
225 c.SetType(npeaks);
226 c.SetQ(q/12.7); //to be consistent with the SSD charges
227
228 if (c.GetQ() < 20.) continue; //noise cluster
229
230 if (digits) {
231 // AliBin *b=&bins[s][idx[k]];
232 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
233 {
234 //Int_t lab[3];
235 //lab[0]=(d->GetTracks())[0];
236 //lab[1]=(d->GetTracks())[1];
237 //lab[2]=(d->GetTracks())[2];
238 //CheckLabels(lab);
239 CheckLabels2(milab);
240 c.SetLabel(milab[0],0);
241 c.SetLabel(milab[1],1);
242 c.SetLabel(milab[2],2);
243 c.SetLayer(fNlayer[fModule]);
244 }
245 }
00a7cc50 246 if(clusters) new (cl[ncl]) AliITSRecPoint(c);
04366a57 247 else {
00a7cc50 248 fDetTypeRec->AddRecPoint(c);
04366a57 249 }
250 ncl++;
251 }
252 }
253}
254
255
256
257void AliITSClusterFinderV2SDD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
258 //------------------------------------------------------------
259 // This function creates ITS clusters from raw data
260 //------------------------------------------------------------
261 rawReader->Reset();
262 AliITSRawStreamSDD inputSDD(rawReader);
263 FindClustersSDD(&inputSDD,clusters);
264
265}
266
267void AliITSClusterFinderV2SDD::FindClustersSDD(AliITSRawStream* input,
268 TClonesArray** clusters)
269{
270 //------------------------------------------------------------
271 // Actual SDD cluster finder for raw data
272 //------------------------------------------------------------
273 Int_t nClustersSDD = 0;
274 Int_t kNzBins = fNzSDD + 2;
275 Int_t kMaxBin = kNzBins * (fNySDD+2);
d7d9347b 276 AliBin *binsSDDInit = new AliBin[kMaxBin];
277 AliBin *binsSDD1 = new AliBin[kMaxBin];
278 AliBin *binsSDD2 = new AliBin[kMaxBin];
04366a57 279 AliBin* bins[2] = {NULL, NULL};
280
281 // read raw data input stream
282 while (kTRUE) {
283 Bool_t next = input->Next();
284 if (!next || input->IsNewModule()) {
285 Int_t iModule = input->GetPrevModuleID();
286
287 // when all data from a module was read, search for clusters
288 if (bins[0]) {
00a7cc50 289 clusters[iModule] = new TClonesArray("AliITSRecPoint");
04366a57 290 fModule = iModule;
291 FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
292 Int_t nClusters = clusters[iModule]->GetEntriesFast();
293 nClustersSDD += nClusters;
d7d9347b 294 bins[0] = bins[1] = NULL;
295
04366a57 296 }
297
298 if (!next) break;
d7d9347b 299 bins[0]=binsSDD1;
300 bins[1]=binsSDD2;
301 memcpy(binsSDD1,binsSDDInit,sizeof(AliBin)*kMaxBin);
302 memcpy(binsSDD2,binsSDDInit,sizeof(AliBin)*kMaxBin);
303
04366a57 304 }
305
306 // fill the current digit into the bins array
307 if(input->GetSignal()>=3) {
308 Int_t iz = input->GetCoord1()+1;
309 Int_t side = ((iz <= fNzSDD) ? 0 : 1);
310 iz -= side*fNzSDD;
311 Int_t index = (input->GetCoord2()+1) * kNzBins + iz;
312 bins[side][index].SetQ(input->GetSignal());
313 bins[side][index].SetMask(1);
314 bins[side][index].SetIndex(index);
315 }
316 }
d7d9347b 317 delete[] binsSDD1;
318 delete[] binsSDD2;
319 delete[] binsSDDInit;
04366a57 320
321 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
322
323}
324
325