- a fast HLT version of the SSD clusterfinder created. The speed on pp mc is ~20kHz...
[u/mrichter/AliRoot.git] / HLT / ITS / clusterfinders / AliHLTITSClusterFinderSPD.cxx
CommitLineData
3f61e9ce 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// Unfolding switch from AliITSRecoParam: D. Elia, INFN Bari //
20// //
21////////////////////////////////////////////////////////////////////////////
22
23
24#include "AliITSCalibrationSPD.h"
25#include "AliHLTITSClusterFinderSPD.h"
26#include "AliITSRecPoint.h"
27#include "AliITSgeomTGeo.h"
28#include "AliITSDetTypeRec.h"
29#include "AliITSReconstructor.h"
30#include "AliRawReader.h"
31#include "AliITSRawStreamSPD.h"
32#include <TClonesArray.h>
33#include "AliITSdigitSPD.h"
34#include "AliITSFOSignalsSPD.h"
35
36ClassImp(AliHLTITSClusterFinderSPD)
37
38//__________________________________________________________________________
39AliHLTITSClusterFinderSPD::AliHLTITSClusterFinderSPD(AliITSDetTypeRec* dettyp)
40 :
b2bac0a3 41 TObject(),
3f61e9ce 42 fRecoParam(0),
43 fDetTypeRec( dettyp ),
44 fNModules(AliITSgeomTGeo::GetNModules()),
45 fLastSPD1(AliITSgeomTGeo::GetModuleIndex(2,1,1)-1),
46 fNySPD(256),
47 fNzSPD(160),
48 fNzBins( fNzSPD + 2 ),
49 fNyBins( fNySPD + 2),
50 fMaxBin( fNzBins * fNyBins ),
51 fYpitchSPD(0.0050),
52 fZ1pitchSPD(0.0425),
53 fZ2pitchSPD(0.0625),
54 fHwSPD(0.64),
55 fHlSPD(3.48),
56 fNSignals(0),
57 fSignal2Bin(0),
58 fBin2Signal(0)
59{
60
61 //Default constructor
62
63 fRecoParam = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
64 if(!fRecoParam){
65 fRecoParam = AliITSRecoParam::GetHighFluxParam();
66 AliWarning("Using default AliITSRecoParam class");
67 }
68
69 //
70 // Initialisation of ITS geometry
71 //
72 Int_t mmax=AliITSgeomTGeo::GetNModules();
73 for (Int_t m=0; m<mmax; m++) {
74 Int_t lay,lad,det; AliITSgeomTGeo::GetModuleId(m,lay,lad,det);
75 fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
76 fNlayer[m] = lay-1;
77 }
78
79 fYSPD[0]=0.5*fYpitchSPD;
80 for (Int_t m=1; m<fNySPD; m++) fYSPD[m]=fYSPD[m-1]+fYpitchSPD;
81 fZSPD[0]=fZ1pitchSPD;
82 for (Int_t m=1; m<fNzSPD; m++) {
83 Double_t dz=fZ1pitchSPD;
84 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
85 m==127 || m==128) dz=fZ2pitchSPD;
86 fZSPD[m]=fZSPD[m-1]+dz;
87 }
88 for (Int_t m=0; m<fNzSPD; m++) {
89 Double_t dz=0.5*fZ1pitchSPD;
90 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
91 m==127 || m==128) dz=0.5*fZ2pitchSPD;
92 fZSPD[m]-=dz;
93 }
94
95 fSignal2Bin = new UShort_t[fMaxBin];
96 fBin2Signal = new UShort_t [fMaxBin];
97 for( int i=0; i<fMaxBin; i++ ) fBin2Signal[i] = 0;
98
99}
100
b2bac0a3 101AliHLTITSClusterFinderSPD::AliHLTITSClusterFinderSPD( const AliHLTITSClusterFinderSPD &)
102 :
103 TObject(),
104 fRecoParam(0),
105 fDetTypeRec(0),
106 fNModules(0),
107 fLastSPD1(0),
108 fNySPD(256),
109 fNzSPD(160),
110 fNzBins( fNzSPD + 2 ),
111 fNyBins( fNySPD + 2),
112 fMaxBin( fNzBins * fNyBins ),
113 fYpitchSPD(0.0050),
114 fZ1pitchSPD(0.0425),
115 fZ2pitchSPD(0.0625),
116 fHwSPD(0.64),
117 fHlSPD(3.48),
118 fNSignals(0),
119 fSignal2Bin(0),
120 fBin2Signal(0)
121{
122 // dummy
123}
124
125AliHLTITSClusterFinderSPD &AliHLTITSClusterFinderSPD::operator=( const AliHLTITSClusterFinderSPD &)
126{
127 // dummy
128 return *this;
129}
3f61e9ce 130
131void AliHLTITSClusterFinderSPD::RawdataToClusters(AliRawReader* rawReader, std::vector<AliITSRecPoint> & clusters){
132 //------------------------------------------------------------
133 // This function creates ITS clusters from raw data
134 //------------------------------------------------------------
135 rawReader->Reset();
136 AliITSRawStreamSPD inputSPD(rawReader);
137 FindClustersSPD(&inputSPD, clusters);
138}
139
140//__________________________________________________________________________
141void AliHLTITSClusterFinderSPD::FindClustersSPD(AliITSRawStreamSPD* input,
142 std::vector<AliITSRecPoint> & clusters)
143{
144 //------------------------------------------------------------
145 // SPD cluster finder for raw data (this method is called once per event)
146 //------------------------------------------------------------
147
148 fNSignals = 0;
149
150 // read raw data input stream
151 while (kTRUE) {
152 Bool_t next = input->Next();
153 if (!next || input->IsNewModule()) {
154 Int_t iModule = input->GetPrevModuleID();
155 // when all data from a module was read, search for clusters
156 if ( fNSignals > 0) {
157 ClustersSPD( clusters, iModule );
158 for( int i=0; i<fNSignals; i++ ){
159 fBin2Signal[fSignal2Bin[i]] = 0;
160 }
161 fNSignals = 0;
162 }
163 if (!next) break;
164 }
165 // fill the current digit into the bins array
166 UShort_t index = (UShort_t ) ( (input->GetCoord2()+1) * fNzBins + (input->GetCoord1()+1) );
167 fSignal2Bin[fNSignals] = index;
168 fBin2Signal[index] = fNSignals+1;
169 fNSignals++;
170 }
171 //cout<<clusters.size()<<endl;
172}
173
174void AliHLTITSClusterFinderSPD::FindCluster(Int_t k,Int_t &n,Int_t *idx) {
175 //------------------------------------------------------------
176 // returns an array of indices of digits belonging to the cluster
177 // (needed when the segmentation is not regular)
178 //------------------------------------------------------------
179 if (n<200) idx[n++]=fBin2Signal[k];
180 fBin2Signal[k]=0;
181
182 if (fBin2Signal[k-fNzBins] ) FindCluster(k-fNzBins,n,idx);
183 if (fBin2Signal[k-1 ] ) FindCluster(k-1 ,n,idx);
184 if (fBin2Signal[k+fNzBins] ) FindCluster(k+fNzBins,n,idx);
185 if (fBin2Signal[k+1 ] ) FindCluster(k+1 ,n,idx);
186}
187
188
189//__________________________________________________________________________
190Int_t AliHLTITSClusterFinderSPD::ClustersSPD( std::vector<AliITSRecPoint> & clusters, Int_t iModule ){
191
192 //Cluster finder for SPD (from digits and from rawdata)
193
194 const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(iModule);
195
196 if (fRecoParam->GetSPDRemoveNoisyFlag()) {
197 // Loop on noisy pixels and reset them
198 AliITSCalibrationSPD *cal =
199 (AliITSCalibrationSPD*) fDetTypeRec->GetCalibrationModel(iModule);
200 for(Int_t ipix = 0; ipix<cal->GetNrBad(); ipix++){
201 Int_t row, col;
202 cal->GetBadPixel(ipix,row,col);
203 Int_t index = (row+1) * fNzBins + (col+1);
204 fBin2Signal[index] = 0;
205 }
206 }
207
208 if (fRecoParam->GetSPDRemoveDeadFlag()) {
209 // Loop on dead pixels and reset them
210 AliITSCalibrationSPD *cal =
211 (AliITSCalibrationSPD*) fDetTypeRec->GetSPDDeadModel(iModule);
212 if (cal->IsBad()) return 0; // if all ladder is dead, return to save time
213 for(Int_t ipix = 0; ipix<cal->GetNrBad(); ipix++){
214 Int_t row, col;
215 cal->GetBadPixel(ipix,row,col);
216 Int_t index = (row+1) * fNzBins + (col+1);
217 fBin2Signal[index] = 0;
218 }
219 }
220
221 Int_t nclu=0;
222
223 for(Int_t is =0; is<fNSignals; is++ ){
224 int iBin = fSignal2Bin[is];
225 if(fBin2Signal[iBin]==0) continue;
226 Int_t nBins = 0;
227 Int_t idxBins[200];
228 Int_t idxSignals[200];
229 FindCluster(iBin,nBins,idxSignals );
230 if (nBins >= 199 ){
231 //Error("ClustersSPD","SPD Too big cluster !\n");
232 continue;
233 }
234 for( int i=0; i<nBins; i++ ) idxBins[i] = fSignal2Bin[idxSignals[i]-1];
235
236 Int_t ymin,ymax,zmin,zmax;
237 ymin = (idxBins[0] / fNzBins) - 1;
238 ymax = ymin;
239 zmin = (idxBins[0] % fNzBins) - 1;
240 zmax = zmin;
241
242 for (Int_t idx = 0; idx < nBins; idx++) {
243 Int_t iy;
244 Int_t iz;
245 iy = (idxBins[idx] / fNzBins) - 1;
246 iz = (idxBins[idx] % fNzBins) - 1;
247 if (ymin > iy) ymin = iy;
248 if (ymax < iy) ymax = iy;
249 if (zmin > iz) zmin = iz;
250 if (zmax < iz) zmax = iz;
251 }
252
253 Int_t idy =0; //max 2 clusters
254 if((iModule <= fLastSPD1) &&idy<3) idy=3;
255 if((iModule > fLastSPD1) &&idy<4) idy=4;
256 Int_t idz=3;
257
258 // Switch the unfolding OFF/ON
259 if(!fRecoParam->GetUseUnfoldingInClusterFinderSPD()) {
260 idy=ymax-ymin+1;
261 idz=zmax-zmin+1;
262 }
263
264 for(Int_t iiz=zmin; iiz<=zmax;iiz+=idz){
265 for(Int_t iiy=ymin;iiy<=ymax;iiy+=idy){
266 Int_t ndigits=0;
267 Float_t y=0.,z=0.,q=0.;
268 for(Int_t idx=0;idx<nBins;idx++){
269 Int_t iy;
270 Int_t iz;
271 iy = (idxBins[idx] / fNzBins)-1;
272 iz = (idxBins[idx] % fNzBins)-1;
273 if(zmax-zmin>=idz || ymax-ymin>=idy){
274 if(TMath::Abs(iy-iiy)>0.75*idy) continue;
275 if(TMath::Abs(iz-iiz)>0.75*idz) continue;
276 }
277 ndigits++;
278 Float_t qBin=0.;
279 qBin = 1;
280 y+= qBin * fYSPD[iy];
281 z+= qBin * fZSPD[iz];
282 q+= qBin;
283 }// for idx
284 if(ndigits==0) continue;
285
286 y /= q;
287 z /= q;
288 y -= fHwSPD;
289 z -= fHlSPD;
290
291 Float_t hit[5]; //y,z,sigma(y)^2, sigma(z)^2, charge
292 {
293 Double_t loc[3]={y,0.,z},trk[3]={0.,0.,0.};
294 mT2L->MasterToLocal(loc,trk);
295 hit[0]=trk[1];
296 hit[1]=trk[2];
297 }
298 hit[2] = fYpitchSPD*fYpitchSPD/12.;
299 hit[3] = fZ1pitchSPD*fZ1pitchSPD/12.;
300 hit[4] = 1.;
301
302 Int_t info[3] = {ymax-ymin+1,zmax-zmin+1,fNlayer[iModule]};
303 Int_t label[4]={-2,-2,-2, fNdet[iModule] };
304 AliITSRecPoint cl(label, hit,info);
305 cl.SetType(nBins);
306 clusters.push_back(cl);
307 nclu++;
308 }// for iiy
309 }// for iiz
310 }//end for iBin
311 return nclu;
312}