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 // |
d6d232ba |
19 | // Unfolding switch from AliITSRecoParam: D. Elia, INFN Bari // |
04366a57 |
20 | // // |
d6d232ba |
21 | //////////////////////////////////////////////////////////////////////////// |
04366a57 |
22 | |
04366a57 |
23 | |
8d37cc87 |
24 | #include "AliITSCalibrationSPD.h" |
04366a57 |
25 | #include "AliITSClusterFinderV2SPD.h" |
00a7cc50 |
26 | #include "AliITSRecPoint.h" |
1f3e997f |
27 | #include "AliITSgeomTGeo.h" |
7d62fb64 |
28 | #include "AliITSDetTypeRec.h" |
d6d232ba |
29 | #include "AliITSReconstructor.h" |
04366a57 |
30 | #include "AliRawReader.h" |
31 | #include "AliITSRawStreamSPD.h" |
04366a57 |
32 | #include <TClonesArray.h> |
04366a57 |
33 | #include "AliITSdigitSPD.h" |
ad7f2bfa |
34 | #include "AliITSFOSignalsSPD.h" |
04366a57 |
35 | |
36 | ClassImp(AliITSClusterFinderV2SPD) |
37 | |
ad7f2bfa |
38 | //__________________________________________________________________________ |
5d2c2f86 |
39 | AliITSClusterFinderV2SPD::AliITSClusterFinderV2SPD(AliITSDetTypeRec* dettyp):AliITSClusterFinder(dettyp), |
1f3e997f |
40 | fLastSPD1(AliITSgeomTGeo::GetModuleIndex(2,1,1)-1), |
e56160b8 |
41 | fNySPD(256), |
42 | fNzSPD(160), |
43 | fYpitchSPD(0.0050), |
44 | fZ1pitchSPD(0.0425), |
45 | fZ2pitchSPD(0.0625), |
46 | fHwSPD(0.64), |
47 | fHlSPD(3.48){ |
04366a57 |
48 | |
49 | //Default constructor |
04366a57 |
50 | |
04366a57 |
51 | fYSPD[0]=0.5*fYpitchSPD; |
52 | for (Int_t m=1; m<fNySPD; m++) fYSPD[m]=fYSPD[m-1]+fYpitchSPD; |
53 | fZSPD[0]=fZ1pitchSPD; |
54 | for (Int_t m=1; m<fNzSPD; m++) { |
55 | Double_t dz=fZ1pitchSPD; |
56 | if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 || |
57 | m==127 || m==128) dz=fZ2pitchSPD; |
58 | fZSPD[m]=fZSPD[m-1]+dz; |
59 | } |
60 | for (Int_t m=0; m<fNzSPD; m++) { |
61 | Double_t dz=0.5*fZ1pitchSPD; |
62 | if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 || |
63 | m==127 || m==128) dz=0.5*fZ2pitchSPD; |
64 | fZSPD[m]-=dz; |
65 | } |
66 | |
67 | } |
ad7f2bfa |
68 | //__________________________________________________________________________ |
04366a57 |
69 | void AliITSClusterFinderV2SPD::FindRawClusters(Int_t mod){ |
04366a57 |
70 | //Find clusters V2 |
71 | SetModule(mod); |
72 | FindClustersSPD(fDigits); |
73 | |
74 | } |
ad7f2bfa |
75 | //__________________________________________________________________________ |
04366a57 |
76 | void AliITSClusterFinderV2SPD::RawdataToClusters(AliRawReader* rawReader, TClonesArray** clusters){ |
ad7f2bfa |
77 | //------------------------------------------------------------ |
04366a57 |
78 | // This function creates ITS clusters from raw data |
79 | //------------------------------------------------------------ |
80 | rawReader->Reset(); |
81 | AliITSRawStreamSPD inputSPD(rawReader); |
82 | FindClustersSPD(&inputSPD, clusters); |
83 | |
84 | } |
ad7f2bfa |
85 | //__________________________________________________________________________ |
04366a57 |
86 | Int_t AliITSClusterFinderV2SPD::ClustersSPD(AliBin* bins, TClonesArray* digits,TClonesArray* clusters,Int_t maxBins,Int_t nzbins,Int_t iModule,Bool_t rawdata){ |
87 | |
88 | //Cluster finder for SPD (from digits and from rawdata) |
89 | |
5c47990a |
90 | static AliITSRecoParam *repa = NULL; |
91 | if(!repa){ |
92 | repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam(); |
93 | if(!repa){ |
ed446fa3 |
94 | repa = AliITSRecoParam::GetHighFluxParam(); |
5c47990a |
95 | AliWarning("Using default AliITSRecoParam class"); |
96 | } |
97 | } |
b4704be3 |
98 | const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(iModule); |
8d37cc87 |
99 | |
ad7f2bfa |
100 | if (repa->GetSPDRemoveNoisyFlag()) { |
101 | // Loop on noisy pixels and reset them |
102 | AliITSCalibrationSPD *cal = |
103 | (AliITSCalibrationSPD*) fDetTypeRec->GetCalibrationModel(iModule); |
104 | for(Int_t ipix = 0; ipix<cal->GetNrBad(); ipix++){ |
105 | Int_t row, col; |
106 | cal->GetBadPixel(ipix,row,col); |
107 | printf(" module %d row %d col %d \n",iModule,row,col); |
108 | Int_t index = (row+1) * nzbins + (col+1); |
109 | |
110 | bins[index].SetQ(0); |
111 | bins[index].SetMask(0xFFFFFFFE); |
112 | } |
113 | } |
114 | |
115 | if (repa->GetSPDRemoveDeadFlag()) { |
116 | // Loop on dead pixels and reset them |
117 | AliITSCalibrationSPD *cal = |
118 | (AliITSCalibrationSPD*) fDetTypeRec->GetSPDDeadModel(iModule); |
119 | if (cal->IsBad()) return 0; // if all ladder is dead, return to save time |
120 | for(Int_t ipix = 0; ipix<cal->GetNrBad(); ipix++){ |
121 | Int_t row, col; |
122 | cal->GetBadPixel(ipix,row,col); |
123 | Int_t index = (row+1) * nzbins + (col+1); |
124 | bins[index].SetQ(0); |
125 | bins[index].SetMask(0xFFFFFFFE); |
126 | } |
8d37cc87 |
127 | } |
ad7f2bfa |
128 | |
04366a57 |
129 | Int_t nclu=0; |
130 | for(Int_t iBin =0; iBin < maxBins;iBin++){ |
131 | if(bins[iBin].IsUsed()) continue; |
132 | Int_t nBins = 0; |
133 | Int_t idxBins[200]; |
134 | FindCluster(iBin,nzbins,bins,nBins,idxBins); |
135 | if (nBins == 200){ |
136 | Error("ClustersSPD","SPD Too big cluster !\n"); |
137 | continue; |
138 | } |
139 | Int_t milab[10]; |
140 | for(Int_t ilab=0;ilab<10;ilab++){ |
141 | milab[ilab]=-2; |
142 | } |
143 | if(rawdata){ |
144 | milab[3]=fNdet[iModule]; |
145 | } |
146 | Int_t ymin,ymax,zmin,zmax; |
147 | if(rawdata){ |
148 | ymin = (idxBins[0] / nzbins) - 1; |
149 | ymax = ymin; |
150 | zmin = (idxBins[0] % nzbins) - 1; |
151 | zmax = zmin; |
152 | } |
153 | else{ |
154 | AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[0]); |
155 | ymin=dig->GetCoord2(); |
156 | ymax=ymin; |
157 | zmin=dig->GetCoord1(); |
158 | zmax=zmin; |
159 | } |
ad7f2bfa |
160 | if(iModule == 24 || iModule == 25) printf("\n"); |
04366a57 |
161 | for (Int_t idx = 0; idx < nBins; idx++) { |
162 | Int_t iy; |
163 | Int_t iz; |
164 | if(rawdata){ |
165 | iy = (idxBins[idx] / nzbins) - 1; |
166 | iz = (idxBins[idx] % nzbins) - 1; |
167 | } |
168 | else{ |
169 | AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]); |
170 | iy = dig->GetCoord2(); |
171 | iz = dig->GetCoord1(); |
ad7f2bfa |
172 | //if(iModule == 24 || iModule == 25) printf(" || iy %d iz %d in Module %d \n",iy,iz,iModule); |
04366a57 |
173 | } |
174 | if (ymin > iy) ymin = iy; |
175 | if (ymax < iy) ymax = iy; |
176 | if (zmin > iz) zmin = iz; |
177 | if (zmax < iz) zmax = iz; |
178 | |
179 | } |
180 | if(!rawdata){ |
181 | for(Int_t l=0;l<nBins;l++){ |
182 | AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[l]); |
183 | for(Int_t dlab=0;dlab<10;dlab++){ |
184 | Int_t digitlab = (dig->GetTracks())[dlab]; |
185 | if(digitlab<0) continue; |
186 | AddLabel(milab,digitlab); |
187 | } |
188 | if (milab[9]>0) CheckLabels2(milab); |
189 | } |
190 | CheckLabels2(milab); |
191 | } |
192 | |
193 | Int_t idy =0; //max 2 clusters |
194 | if((iModule <= fLastSPD1) &&idy<3) idy=3; |
195 | if((iModule > fLastSPD1) &&idy<4) idy=4; |
196 | Int_t idz=3; |
d6d232ba |
197 | |
198 | // Switch the unfolding OFF/ON |
5c47990a |
199 | if(!repa->GetUseUnfoldingInClusterFinderSPD()) { |
d6d232ba |
200 | idy=ymax-ymin+1; |
201 | idz=zmax-zmin+1; |
202 | } |
203 | |
04366a57 |
204 | for(Int_t iiz=zmin; iiz<=zmax;iiz+=idz){ |
205 | for(Int_t iiy=ymin;iiy<=ymax;iiy+=idy){ |
206 | |
207 | Int_t ndigits=0; |
208 | Float_t y=0.,z=0.,q=0.; |
209 | for(Int_t idx=0;idx<nBins;idx++){ |
210 | Int_t iy; |
211 | Int_t iz; |
212 | if(rawdata){ |
213 | iy = (idxBins[idx] / nzbins)-1; |
214 | iz = (idxBins[idx] % nzbins)-1; |
215 | } |
216 | else{ |
217 | AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]); |
218 | iy = dig->GetCoord2(); |
219 | iz = dig->GetCoord1(); |
220 | } |
221 | if(zmax-zmin>=idz || ymax-ymin>=idy){ |
222 | if(TMath::Abs(iy-iiy)>0.75*idy) continue; |
223 | if(TMath::Abs(iz-iiz)>0.75*idz) continue; |
224 | } |
225 | ndigits++; |
5af4a2d0 |
226 | Float_t qBin=0.; |
04366a57 |
227 | if(rawdata) qBin = bins[idxBins[idx]].GetQ(); |
228 | if(!rawdata){ |
229 | AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]); |
230 | qBin = (Float_t)dig->GetSignal(); |
231 | } |
232 | y+= qBin * fYSPD[iy]; |
233 | z+= qBin * fZSPD[iz]; |
234 | q+= qBin; |
235 | }// for idx |
236 | if(ndigits==0) continue; |
237 | y /= q; |
238 | z /= q; |
239 | y -= fHwSPD; |
240 | z -= fHlSPD; |
1f3e997f |
241 | |
b4704be3 |
242 | Float_t hit[5]; //y,z,sigma(y)^2, sigma(z)^2, charge |
243 | { |
244 | Double_t loc[3]={y,0.,z},trk[3]={0.,0.,0.}; |
245 | mT2L->MasterToLocal(loc,trk); |
246 | hit[0]=trk[1]; |
247 | hit[1]=trk[2]; |
248 | } |
04366a57 |
249 | hit[2] = fYpitchSPD*fYpitchSPD/12.; |
250 | hit[3] = fZ1pitchSPD*fZ1pitchSPD/12.; |
00a7cc50 |
251 | hit[4] = 1.; |
b4704be3 |
252 | |
04366a57 |
253 | if(!rawdata) milab[3]=fNdet[iModule]; |
254 | Int_t info[3] = {ymax-ymin+1,zmax-zmin+1,fNlayer[iModule]}; |
255 | if(!rawdata){ |
75fb37cc |
256 | AliITSRecPoint cl(milab,hit,info); |
00a7cc50 |
257 | fDetTypeRec->AddRecPoint(cl); |
04366a57 |
258 | } |
259 | else{ |
260 | Int_t label[4]={milab[0],milab[1],milab[2],milab[3]}; |
261 | new (clusters->AddrAt(nclu)) |
75fb37cc |
262 | AliITSRecPoint(label, hit,info); |
04366a57 |
263 | } |
264 | nclu++; |
265 | }// for iiy |
266 | }// for iiz |
267 | }//end for iBin |
268 | return nclu; |
269 | |
270 | } |
ad7f2bfa |
271 | //__________________________________________________________________________ |
ff44c37c |
272 | void AliITSClusterFinderV2SPD::FindClustersSPD(AliITSRawStreamSPD* input, |
04366a57 |
273 | TClonesArray** clusters) |
274 | { |
275 | //------------------------------------------------------------ |
ad7f2bfa |
276 | // SPD cluster finder for raw data (this method is called once per event) |
277 | // Now also fills fast-or fired map |
04366a57 |
278 | //------------------------------------------------------------ |
ad7f2bfa |
279 | |
04366a57 |
280 | Int_t nClustersSPD = 0; |
281 | Int_t kNzBins = fNzSPD + 2; |
282 | Int_t kNyBins = fNySPD + 2; |
283 | Int_t kMaxBin = kNzBins * kNyBins; |
d7d9347b |
284 | AliBin *binsSPD = new AliBin[kMaxBin]; |
285 | AliBin *binsSPDInit = new AliBin[kMaxBin]; |
04366a57 |
286 | AliBin* bins = NULL; |
287 | |
288 | // read raw data input stream |
289 | while (kTRUE) { |
290 | Bool_t next = input->Next(); |
291 | if (!next || input->IsNewModule()) { |
292 | Int_t iModule = input->GetPrevModuleID(); |
293 | |
294 | // when all data from a module was read, search for clusters |
295 | if (bins) { |
00a7cc50 |
296 | clusters[iModule] = new TClonesArray("AliITSRecPoint"); |
04366a57 |
297 | Int_t nClusters = ClustersSPD(bins,0,clusters[iModule],kMaxBin,kNzBins,iModule,kTRUE); |
298 | nClustersSPD += nClusters; |
d7d9347b |
299 | bins = NULL; |
04366a57 |
300 | } |
301 | |
302 | if (!next) break; |
d7d9347b |
303 | bins = binsSPD; |
304 | memcpy(binsSPD,binsSPDInit,sizeof(AliBin)*kMaxBin); |
04366a57 |
305 | } |
306 | |
ad7f2bfa |
307 | if (next) { |
308 | // fill the current digit into the bins array |
309 | Int_t index = (input->GetCoord2()+1) * kNzBins + (input->GetCoord1()+1); |
310 | bins[index].SetIndex(index); |
311 | bins[index].SetQ(1); |
312 | bins[index].SetMask(1); |
ff44c37c |
313 | } |
314 | } |
315 | |
d7d9347b |
316 | delete [] binsSPDInit; |
317 | delete [] binsSPD; |
318 | |
9ba575f7 |
319 | // AliDebug(1,Form("found clusters in ITS SPD: %d", nClustersSPD)); |
320 | Info("FindClustersSPD", "found clusters in ITS SPD: %d", nClustersSPD); |
ad7f2bfa |
321 | |
322 | // Fill the FastOr fired map |
323 | for (UInt_t eq=0; eq<20; eq++) { |
324 | for (UInt_t hs=0; hs<6; hs++) { |
325 | for (UInt_t chip=0; chip<10; chip++) { |
326 | if (input->GetFastOrSignal(eq,hs,chip)) { |
327 | fDetTypeRec->SetFastOrFiredMapOnline(eq,hs,chip); |
328 | } |
329 | } |
330 | } |
331 | } |
332 | |
04366a57 |
333 | } |
ad7f2bfa |
334 | //__________________________________________________________________________ |
04366a57 |
335 | void AliITSClusterFinderV2SPD::FindClustersSPD(TClonesArray *digits) { |
336 | //------------------------------------------------------------ |
ad7f2bfa |
337 | // SPD cluster finder for digits (this method is called for each module) |
338 | // Now also fills the fast-or fired map |
04366a57 |
339 | //------------------------------------------------------------ |
340 | |
341 | |
342 | Int_t kNzBins = fNzSPD + 2; |
343 | const Int_t kMAXBIN=kNzBins*(fNySPD+2); |
344 | |
345 | Int_t ndigits=digits->GetEntriesFast(); |
346 | AliBin *bins=new AliBin[kMAXBIN]; |
347 | |
ad7f2bfa |
348 | Int_t idig; |
349 | AliITSdigitSPD *digit=0; |
350 | for (idig=0; idig<ndigits; idig++) { |
351 | digit=(AliITSdigitSPD*)digits->UncheckedAt(idig); |
352 | Int_t i=digit->GetCoord2()+1; //y |
353 | Int_t j=digit->GetCoord1()+1; |
354 | Int_t index=i*kNzBins+j; |
355 | |
356 | bins[index].SetIndex(idig); |
357 | bins[index].SetQ(1); |
358 | bins[index].SetMask(1); |
04366a57 |
359 | } |
ad7f2bfa |
360 | |
04366a57 |
361 | |
d6d232ba |
362 | Int_t nClustersSPD = ClustersSPD(bins,digits,0,kMAXBIN,kNzBins,fModule,kFALSE); |
04366a57 |
363 | delete [] bins; |
d6d232ba |
364 | |
813020f4 |
365 | AliDebug(1,Form("found clusters in ITS SPD: %d", nClustersSPD)); |
ad7f2bfa |
366 | |
367 | // Fill the FastOr fired map |
368 | AliITSFOSignalsSPD* foSignals = fDetTypeRec->GetFOSignals(); |
369 | if (foSignals) { |
370 | UInt_t eq = AliITSRawStreamSPD::GetOnlineEqIdFromOffline(fModule); |
371 | UInt_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(fModule); |
372 | for(UInt_t ch=0; ch<5; ch++) { |
373 | UInt_t chip = AliITSRawStreamSPD::GetOnlineChipFromOffline(fModule,ch*32); |
374 | if (foSignals->GetSignal(eq,hs,chip)) { |
375 | fDetTypeRec->SetFastOrFiredMapOnline(eq,hs,chip); |
376 | } |
377 | } |
378 | } |
379 | |
04366a57 |
380 | } |