new SDD preprocessor + removal of eff C++ warning (base) - E. Crescio
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderV2SPD.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
04366a57 22
23#include "AliITSClusterFinderV2SPD.h"
00a7cc50 24#include "AliITSRecPoint.h"
7d62fb64 25#include "AliITSDetTypeRec.h"
04366a57 26#include "AliRawReader.h"
27#include "AliITSRawStreamSPD.h"
04366a57 28#include <TClonesArray.h>
04366a57 29#include "AliITSdigitSPD.h"
30
31ClassImp(AliITSClusterFinderV2SPD)
32
33extern AliRun *gAlice;
34
e56160b8 35AliITSClusterFinderV2SPD::AliITSClusterFinderV2SPD(AliITSDetTypeRec* dettyp):AliITSClusterFinderV2(dettyp),
36fLastSPD1(0),
37fNySPD(256),
38fNzSPD(160),
39fYpitchSPD(0.0050),
40fZ1pitchSPD(0.0425),
41fZ2pitchSPD(0.0625),
42fHwSPD(0.64),
43fHlSPD(3.48){
04366a57 44
45 //Default constructor
04366a57 46
8ba39da9 47 fLastSPD1=fDetTypeRec->GetITSgeom()->GetModuleIndex(2,1,1)-1;
04366a57 48 fYSPD[0]=0.5*fYpitchSPD;
49 for (Int_t m=1; m<fNySPD; m++) fYSPD[m]=fYSPD[m-1]+fYpitchSPD;
50 fZSPD[0]=fZ1pitchSPD;
51 for (Int_t m=1; m<fNzSPD; m++) {
52 Double_t dz=fZ1pitchSPD;
53 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
54 m==127 || m==128) dz=fZ2pitchSPD;
55 fZSPD[m]=fZSPD[m-1]+dz;
56 }
57 for (Int_t m=0; m<fNzSPD; m++) {
58 Double_t dz=0.5*fZ1pitchSPD;
59 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
60 m==127 || m==128) dz=0.5*fZ2pitchSPD;
61 fZSPD[m]-=dz;
62 }
63
64}
65
66
67void AliITSClusterFinderV2SPD::FindRawClusters(Int_t mod){
68
69 //Find clusters V2
70 SetModule(mod);
71 FindClustersSPD(fDigits);
72
73}
74
75void AliITSClusterFinderV2SPD::RawdataToClusters(AliRawReader* rawReader, TClonesArray** clusters){
76 //------------------------------------------------------------
77 // This function creates ITS clusters from raw data
78 //------------------------------------------------------------
79 rawReader->Reset();
80 AliITSRawStreamSPD inputSPD(rawReader);
81 FindClustersSPD(&inputSPD, clusters);
82
83}
84
85Int_t AliITSClusterFinderV2SPD::ClustersSPD(AliBin* bins, TClonesArray* digits,TClonesArray* clusters,Int_t maxBins,Int_t nzbins,Int_t iModule,Bool_t rawdata){
86
87 //Cluster finder for SPD (from digits and from rawdata)
88
89 Int_t nclu=0;
90 for(Int_t iBin =0; iBin < maxBins;iBin++){
91 if(bins[iBin].IsUsed()) continue;
92 Int_t nBins = 0;
93 Int_t idxBins[200];
94 FindCluster(iBin,nzbins,bins,nBins,idxBins);
95 if (nBins == 200){
96 Error("ClustersSPD","SPD Too big cluster !\n");
97 continue;
98 }
99 Int_t milab[10];
100 for(Int_t ilab=0;ilab<10;ilab++){
101 milab[ilab]=-2;
102 }
103 if(rawdata){
104 milab[3]=fNdet[iModule];
105 }
106 Int_t ymin,ymax,zmin,zmax;
107 if(rawdata){
108 ymin = (idxBins[0] / nzbins) - 1;
109 ymax = ymin;
110 zmin = (idxBins[0] % nzbins) - 1;
111 zmax = zmin;
112 }
113 else{
114 AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[0]);
115 ymin=dig->GetCoord2();
116 ymax=ymin;
117 zmin=dig->GetCoord1();
118 zmax=zmin;
119 }
120 for (Int_t idx = 0; idx < nBins; idx++) {
121 Int_t iy;
122 Int_t iz;
123 if(rawdata){
124 iy = (idxBins[idx] / nzbins) - 1;
125 iz = (idxBins[idx] % nzbins) - 1;
126 }
127 else{
128 AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]);
129 iy = dig->GetCoord2();
130 iz = dig->GetCoord1();
131 }
132 if (ymin > iy) ymin = iy;
133 if (ymax < iy) ymax = iy;
134 if (zmin > iz) zmin = iz;
135 if (zmax < iz) zmax = iz;
136
137 }
138 if(!rawdata){
139 for(Int_t l=0;l<nBins;l++){
140 AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[l]);
141 for(Int_t dlab=0;dlab<10;dlab++){
142 Int_t digitlab = (dig->GetTracks())[dlab];
143 if(digitlab<0) continue;
144 AddLabel(milab,digitlab);
145 }
146 if (milab[9]>0) CheckLabels2(milab);
147 }
148 CheckLabels2(milab);
149 }
150
151 Int_t idy =0; //max 2 clusters
152 if((iModule <= fLastSPD1) &&idy<3) idy=3;
153 if((iModule > fLastSPD1) &&idy<4) idy=4;
154 Int_t idz=3;
155 for(Int_t iiz=zmin; iiz<=zmax;iiz+=idz){
156 for(Int_t iiy=ymin;iiy<=ymax;iiy+=idy){
157
158 Int_t ndigits=0;
159 Float_t y=0.,z=0.,q=0.;
160 for(Int_t idx=0;idx<nBins;idx++){
161 Int_t iy;
162 Int_t iz;
163 if(rawdata){
164 iy = (idxBins[idx] / nzbins)-1;
165 iz = (idxBins[idx] % nzbins)-1;
166 }
167 else{
168 AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]);
169 iy = dig->GetCoord2();
170 iz = dig->GetCoord1();
171 }
172 if(zmax-zmin>=idz || ymax-ymin>=idy){
173 if(TMath::Abs(iy-iiy)>0.75*idy) continue;
174 if(TMath::Abs(iz-iiz)>0.75*idz) continue;
175 }
176 ndigits++;
177 Float_t qBin;
178 if(rawdata) qBin = bins[idxBins[idx]].GetQ();
179 if(!rawdata){
180 AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]);
181 qBin = (Float_t)dig->GetSignal();
182 }
183 y+= qBin * fYSPD[iy];
184 z+= qBin * fZSPD[iz];
185 q+= qBin;
186 }// for idx
187 if(ndigits==0) continue;
188 y /= q;
189 z /= q;
190 y -= fHwSPD;
191 z -= fHlSPD;
192 Float_t hit[5]; //y,z,sigma(y)^2, sigma(z)^2, charge
193 hit[0] = -(-y+fYshift[iModule]);
194 if(iModule <= fLastSPD1) hit[0] = -hit[0];
195 hit[1] = -z+fZshift[iModule];
196 hit[2] = fYpitchSPD*fYpitchSPD/12.;
197 hit[3] = fZ1pitchSPD*fZ1pitchSPD/12.;
00a7cc50 198 hit[4] = 1.;
04366a57 199 if(!rawdata) milab[3]=fNdet[iModule];
200 Int_t info[3] = {ymax-ymin+1,zmax-zmin+1,fNlayer[iModule]};
201 if(!rawdata){
00a7cc50 202 AliITSRecPoint cl(iModule,fDetTypeRec->GetITSgeom(),milab,hit,info);
203 fDetTypeRec->AddRecPoint(cl);
04366a57 204 }
205 else{
206 Int_t label[4]={milab[0],milab[1],milab[2],milab[3]};
207 new (clusters->AddrAt(nclu))
00a7cc50 208 AliITSRecPoint(iModule,fDetTypeRec->GetITSgeom(),label, hit,info);
04366a57 209 }
210 nclu++;
211 }// for iiy
212 }// for iiz
213 }//end for iBin
214 return nclu;
215
216}
217
218
219
220
221void AliITSClusterFinderV2SPD::FindClustersSPD(AliITSRawStream* input,
222 TClonesArray** clusters)
223{
224 //------------------------------------------------------------
225 // Actual SPD cluster finder for raw data
226 //------------------------------------------------------------
227 Int_t nClustersSPD = 0;
228 Int_t kNzBins = fNzSPD + 2;
229 Int_t kNyBins = fNySPD + 2;
230 Int_t kMaxBin = kNzBins * kNyBins;
d7d9347b 231 AliBin *binsSPD = new AliBin[kMaxBin];
232 AliBin *binsSPDInit = new AliBin[kMaxBin];
04366a57 233 AliBin* bins = NULL;
234
235 // read raw data input stream
236 while (kTRUE) {
237 Bool_t next = input->Next();
238 if (!next || input->IsNewModule()) {
239 Int_t iModule = input->GetPrevModuleID();
240
241 // when all data from a module was read, search for clusters
242 if (bins) {
00a7cc50 243 clusters[iModule] = new TClonesArray("AliITSRecPoint");
04366a57 244 Int_t nClusters = ClustersSPD(bins,0,clusters[iModule],kMaxBin,kNzBins,iModule,kTRUE);
245 nClustersSPD += nClusters;
d7d9347b 246 bins = NULL;
04366a57 247 }
248
249 if (!next) break;
d7d9347b 250 bins = binsSPD;
251 memcpy(binsSPD,binsSPDInit,sizeof(AliBin)*kMaxBin);
04366a57 252 }
253
254 // fill the current digit into the bins array
255 Int_t index = (input->GetCoord2()+1) * kNzBins + (input->GetCoord1()+1);
256 bins[index].SetIndex(index);
257 bins[index].SetMask(1);
258 bins[index].SetQ(1);
259 }
260
d7d9347b 261 delete [] binsSPDInit;
262 delete [] binsSPD;
263
04366a57 264 Info("FindClustersSPD", "found clusters in ITS SPD: %d", nClustersSPD);
265}
266
267
268
269void AliITSClusterFinderV2SPD::FindClustersSPD(TClonesArray *digits) {
270 //------------------------------------------------------------
271 // Actual SPD cluster finder
272 //------------------------------------------------------------
273
274
275 Int_t kNzBins = fNzSPD + 2;
276 const Int_t kMAXBIN=kNzBins*(fNySPD+2);
277
278 Int_t ndigits=digits->GetEntriesFast();
279 AliBin *bins=new AliBin[kMAXBIN];
280
281 Int_t k;
282 AliITSdigitSPD *d=0;
283 for (k=0; k<ndigits; k++) {
284 d=(AliITSdigitSPD*)digits->UncheckedAt(k);
285 Int_t i=d->GetCoord2()+1; //y
286 Int_t j=d->GetCoord1()+1;
287 Int_t index=i*kNzBins+j;
288 bins[index].SetIndex(k);
289 bins[index].SetMask(1);
290 }
291
292 ClustersSPD(bins,digits,0,kMAXBIN,kNzBins,fModule,kFALSE);
293 delete [] bins;
294}
295
296