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