]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSclustererV2.cxx
New macro to keep track of timing performances of the segmentation methods (Laurent)
[u/mrichter/AliRoot.git] / ITS / AliITSclustererV2.cxx
CommitLineData
7f4044f0 1//-------------------------------------------------------------------------
2// Implementation of the ITS clusterer V2 class
3//
4// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
5//-------------------------------------------------------------------------
60b9526b 6
7f4044f0 7
8#include "AliRun.h"
9
10#include "AliITSclustererV2.h"
11#include "AliITSclusterV2.h"
7d62fb64 12#include "AliITSDetTypeRec.h"
7941072e 13#include "AliRawReader.h"
c391f9d9 14#include "AliITSRawStreamSPD.h"
15#include "AliITSRawStreamSDD.h"
16#include "AliITSRawStreamSSD.h"
7f4044f0 17
7f4044f0 18#include <TFile.h>
19#include <TTree.h>
20#include <TClonesArray.h>
79c75366 21#include "AliITSgeomTGeo.h"
e869281d 22#include "AliITSdigitSPD.h"
23#include "AliITSdigitSDD.h"
24#include "AliITSdigitSSD.h"
5d12ce38 25#include "AliMC.h"
7f4044f0 26
27ClassImp(AliITSclustererV2)
28
29extern AliRun *gAlice;
30
e56160b8 31AliITSclustererV2::AliITSclustererV2():
32fNModules(0),
33fEvent(0),
34fI(0),
35fLastSPD1(0),
36fNySPD(0),
37fNzSPD(0),
38fYpitchSPD(0),
39fZ1pitchSPD(0),
40fZ2pitchSPD(0),
41fHwSPD(0),
42fHlSPD(0),
43fNySDD(0),
44fNzSDD(0),
45fYpitchSDD(0),
46fZpitchSDD(0),
47fHwSDD(0),
48fHlSDD(0),
49fYoffSDD(0),
50fLastSSD1(0),
51fYpitchSSD(0),
52fHwSSD(0),
53fHlSSD(0),
54fTanP(0),
55fTanN(0){
56 //default constructor
57 }
79c75366 58AliITSclustererV2::AliITSclustererV2(const Char_t *geom):
59fNModules(AliITSgeomTGeo::GetNModules()),
e56160b8 60fEvent(0),
61fI(0),
79c75366 62fLastSPD1(AliITSgeomTGeo::GetModuleIndex(2,1,1)-1),
e56160b8 63fNySPD(256),
64fNzSPD(160),
65fYpitchSPD(0.0050),
66fZ1pitchSPD(0.0425),
67fZ2pitchSPD(0.0625),
68fHwSPD(0.64),
69fHlSPD(3.48),
70fNySDD(256),
71fNzSDD(256),
72fYpitchSDD(0.01825),
73fZpitchSDD(0.02940),
74fHwSDD(3.5085),
75fHlSDD(3.7632),
76fYoffSDD(0.0425),
79c75366 77fLastSSD1(AliITSgeomTGeo::GetModuleIndex(6,1,1)-1),
e56160b8 78fYpitchSSD(0.0095),
79fHwSSD(3.65),
80fHlSSD(2.00),
81fTanP(0.0275),
82fTanN(0.0075) {
7f4044f0 83 //------------------------------------------------------------
84 // Standard constructor
85 //------------------------------------------------------------
79c75366 86 if (geom) {
87 AliWarning("\"geom\" is actually a dummy argument !");
c630aafd 88 }
7f4044f0 89 Int_t m;
79c75366 90 for (m=0; m<fNModules; m++) {
91 Int_t lay,lad,det; AliITSgeomTGeo::GetModuleId(m,lay,lad,det);
92 const TGeoHMatrix *tm=AliITSgeomTGeo::GetTracking2LocalMatrix(m);
93 fYshift[m] = (tm->Inverse()).GetTranslation()[1];
94 fZshift[m] = (tm->Inverse()).GetTranslation()[2];
95 fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
e43c066c 96 fNlayer[m] = lay-1;
7f4044f0 97 }
98
99 //SPD geometry
7f4044f0 100 fYSPD[0]=0.5*fYpitchSPD;
101 for (m=1; m<fNySPD; m++) fYSPD[m]=fYSPD[m-1]+fYpitchSPD;
102 fZSPD[0]=fZ1pitchSPD;
103 for (m=1; m<fNzSPD; m++) {
104 Double_t dz=fZ1pitchSPD;
105 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
106 m==127 || m==128) dz=fZ2pitchSPD;
107 fZSPD[m]=fZSPD[m-1]+dz;
108 }
109 for (m=0; m<fNzSPD; m++) {
110 Double_t dz=0.5*fZ1pitchSPD;
111 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
112 m==127 || m==128) dz=0.5*fZ2pitchSPD;
113 fZSPD[m]-=dz;
114 }
115
7f4044f0 116}
117
e3d91d99 118
c630aafd 119Int_t AliITSclustererV2::Digits2Clusters(TTree *dTree, TTree *cTree) {
7f4044f0 120 //------------------------------------------------------------
121 // This function creates ITS clusters
122 //------------------------------------------------------------
123 Int_t ncl=0;
7f4044f0 124
7f4044f0 125 if (!dTree) {
c630aafd 126 Error("Digits2Clusters","Can't get the tree with digits !");
127 return 1;
7f4044f0 128 }
129
130 TClonesArray *digitsSPD=new TClonesArray("AliITSdigitSPD",3000);
131 dTree->SetBranchAddress("ITSDigitsSPD",&digitsSPD);
132 TClonesArray *digitsSDD=new TClonesArray("AliITSdigitSDD",3000);
133 dTree->SetBranchAddress("ITSDigitsSDD",&digitsSDD);
134 TClonesArray *digitsSSD=new TClonesArray("AliITSdigitSSD",3000);
135 dTree->SetBranchAddress("ITSDigitsSSD",&digitsSSD);
136
7f4044f0 137 TClonesArray *clusters=new TClonesArray("AliITSclusterV2",1000);
c630aafd 138 TBranch *branch=cTree->GetBranch("Clusters");
139 if (!branch) cTree->Branch("Clusters",&clusters);
140 else branch->SetAddress(&clusters);
141
142 Int_t mmax=(Int_t)dTree->GetEntries();
cbca22ab 143 if (mmax!=fNModules) {
144 Error("Digits2Clusters","Number of entries != number of modules !");
145 return 1;
146 }
7f4044f0 147
148 for (fI=0; fI<mmax; fI++) {
149 dTree->GetEvent(fI);
150
151 if (digitsSPD->GetEntriesFast()!=0)
babd135a 152 FindClustersSPD(digitsSPD,clusters);
153 else
154 if(digitsSDD->GetEntriesFast()!=0)
155 FindClustersSDD(digitsSDD,clusters);
156 else if(digitsSSD->GetEntriesFast()!=0)
157 FindClustersSSD(digitsSSD,clusters);
158
7f4044f0 159 ncl+=clusters->GetEntriesFast();
160
c630aafd 161 cTree->Fill();
7f4044f0 162
163 digitsSPD->Clear();
164 digitsSDD->Clear();
165 digitsSSD->Clear();
166 clusters->Clear();
167 }
c630aafd 168
169 //cTree->Write();
7f4044f0 170
171 delete clusters;
172
173 delete digitsSPD;
174 delete digitsSDD;
175 delete digitsSSD;
176
7941072e 177 //delete dTree;
178
c630aafd 179 Info("Digits2Clusters","Number of found clusters : %d",ncl);
7f4044f0 180
c630aafd 181 return 0;
7f4044f0 182}
183
7941072e 184void AliITSclustererV2::Digits2Clusters(AliRawReader* rawReader) {
c391f9d9 185 //------------------------------------------------------------
186 // This function creates ITS clusters from raw data
187 //------------------------------------------------------------
33c3c91a 188 AliRunLoader* runLoader = AliRunLoader::Instance();
7941072e 189 if (!runLoader) {
190 Error("Digits2Clusters", "no run loader found");
191 return;
192 }
babd135a 193 runLoader->LoadKinematics();
7941072e 194 AliLoader* itsLoader = runLoader->GetLoader("ITSLoader");
195 if (!itsLoader) {
196 Error("Digits2Clusters", "no loader for ITS found");
c391f9d9 197 return;
198 }
7941072e 199 if (!itsLoader->TreeR()) itsLoader->MakeTree("R");
200 TTree* cTree = itsLoader->TreeR();
c391f9d9 201
c391f9d9 202 TClonesArray *array=new TClonesArray("AliITSclusterV2",1000);
7941072e 203 cTree->Branch("Clusters",&array);
c391f9d9 204 delete array;
205
f1e0c1c5 206 TClonesArray** clusters = new TClonesArray*[fNModules];
04fa961a 207 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
208 clusters[iModule] = NULL;
209 }
c391f9d9 210 // one TClonesArray per module
211
7941072e 212 rawReader->Reset();
213 AliITSRawStreamSPD inputSPD(rawReader);
c391f9d9 214 FindClustersSPD(&inputSPD, clusters);
7941072e 215
216 rawReader->Reset();
217 AliITSRawStreamSDD inputSDD(rawReader);
c391f9d9 218 FindClustersSDD(&inputSDD, clusters);
7941072e 219
220 rawReader->Reset();
221 AliITSRawStreamSSD inputSSD(rawReader);
c391f9d9 222 FindClustersSSD(&inputSSD, clusters);
223
224 // write all clusters to the tree
225 Int_t nClusters = 0;
c157c94e 226 TClonesArray *emptyArray=new TClonesArray("AliITSclusterV2");
c391f9d9 227 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
04fa961a 228 array = clusters[iModule];
c391f9d9 229 if (!array) {
230 Error("Digits2Clusters", "data for module %d missing!", iModule);
c157c94e 231 array = emptyArray;
c391f9d9 232 }
7941072e 233 cTree->SetBranchAddress("Clusters", &array);
234 cTree->Fill();
c391f9d9 235 nClusters += array->GetEntriesFast();
c391f9d9 236 }
c157c94e 237 delete emptyArray;
238
7941072e 239 itsLoader->WriteRecPoints("OVERWRITE");
c391f9d9 240
04fa961a 241 delete[] clusters;
242
c391f9d9 243 Info("Digits2Clusters", "total number of found clusters in ITS: %d\n",
244 nClusters);
245}
246
7f4044f0 247//**** Fast clusters *******************************
248#include "TParticle.h"
249
7d62fb64 250//#include "AliITS.h"
7f4044f0 251#include "AliITSmodule.h"
252#include "AliITSRecPoint.h"
253#include "AliITSsimulationFastPoints.h"
254#include "AliITSRecPoint.h"
255
7d62fb64 256
7f4044f0 257static void CheckLabels(Int_t lab[3]) {
258 //------------------------------------------------------------
259 // Tries to find mother's labels
260 //------------------------------------------------------------
33c3c91a 261 AliRunLoader *rl = AliRunLoader::Instance();
60b9526b 262 TTree *trK=(TTree*)rl->TreeK();
263
264 if(trK){
7f4044f0 265 Int_t label=lab[0];
266 if (label>=0) {
60b9526b 267 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
268 label=-3;
269 while (part->P() < 0.005) {
270 Int_t m=part->GetFirstMother();
271 if (m<0) {
272 Info("CheckLabels","Primary momentum: %f",part->P());
273 break;
274 }
275 if (part->GetStatusCode()>0) {
276 Info("CheckLabels","Primary momentum: %f",part->P());
277 break;
278 }
279 label=m;
280 part=(TParticle*)gAlice->GetMCApp()->Particle(label);
281 }
5af4a2d0 282 if(lab[1]<0){
283 lab[1]=label;
284 }
285 else if (lab[2]<0) {
286 lab[2]=label;
287 }
288 else {
289 // cerr<<"CheckLabels : No empty labels !\n";
290 }
7f4044f0 291 }
60b9526b 292 }
7f4044f0 293}
7d62fb64 294
295/*
babd135a 296static void CheckLabels(Int_t lab[3]) {
297 //------------------------------------------------------------
298 // Tries to find mother's labels
299 //------------------------------------------------------------
300
0e986ef9 301 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
302
babd135a 303 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
304 for (Int_t i=0;i<3;i++){
305 Int_t label = lab[i];
306 if (label>=0 && label<ntracks) {
307 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
308 if (part->P() < 0.005) {
309 Int_t m=part->GetFirstMother();
310 if (m<0) {
311 continue;
312 }
313 if (part->GetStatusCode()>0) {
314 continue;
315 }
316 lab[i]=m;
317 }
318 }
319 }
320
321}
7d62fb64 322*/
babd135a 323static void CheckLabels2(Int_t lab[10]) {
324 //------------------------------------------------------------
325 // Tries to find mother's labels
326 //------------------------------------------------------------
33c3c91a 327 AliRunLoader *rl = AliRunLoader::Instance();
60b9526b 328 TTree *trK=(TTree*)rl->TreeK();
0e986ef9 329
60b9526b 330 if(trK){
331 Int_t nlabels =0;
332 for (Int_t i=0;i<10;i++) if (lab[i]>=0) nlabels++;
333 if(nlabels == 0) return; // In case of no labels just exit
e43c066c 334
60b9526b 335 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
336
337 for (Int_t i=0;i<10;i++){
338 Int_t label = lab[i];
339 if (label>=0 && label<ntracks) {
340 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
341 if (part->P() < 0.02) {
e43c066c 342 Int_t m=part->GetFirstMother();
343 if (m<0) {
344 continue;
345 }
346 if (part->GetStatusCode()>0) {
347 continue;
348 }
349 lab[i]=m;
60b9526b 350 }
351 else
352 if (part->P() < 0.12 && nlabels>3) {
353 lab[i]=-2;
354 nlabels--;
355 }
e43c066c 356 }
60b9526b 357 else{
358 if ( (label>ntracks||label <0) && nlabels>3) {
e43c066c 359 lab[i]=-2;
360 nlabels--;
361 }
60b9526b 362 }
363 }
364 if (nlabels>3){
365 for (Int_t i=0;i<10;i++){
366 if (nlabels>3){
367 Int_t label = lab[i];
368 if (label>=0 && label<ntracks) {
369 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
370 if (part->P() < 0.1) {
371 lab[i]=-2;
372 nlabels--;
373 }
e43c066c 374 }
babd135a 375 }
babd135a 376 }
e43c066c 377 }
e43c066c 378
60b9526b 379 //compress labels -- if multi-times the same
380 Int_t lab2[10];
381 for (Int_t i=0;i<10;i++) lab2[i]=-2;
382 for (Int_t i=0;i<10 ;i++){
383 if (lab[i]<0) continue;
384 for (Int_t j=0;j<10 &&lab2[j]!=lab[i];j++){
385 if (lab2[j]<0) {
386 lab2[j]= lab[i];
387 break;
388 }
babd135a 389 }
390 }
60b9526b 391 for (Int_t j=0;j<10;j++) lab[j]=lab2[j];
babd135a 392 }
babd135a 393}
394
395static void AddLabel(Int_t lab[10], Int_t label) {
60b9526b 396// add label of the particle in the kine tree which originates this cluster
397// (used for reconstruction of MC data only, for comparison purposes)
33c3c91a 398 AliRunLoader *rl = AliRunLoader::Instance();
60b9526b 399 TTree *trK=(TTree*)rl->TreeK();
0e986ef9 400
60b9526b 401 if(trK){
402 if(label<0) return; // In case of no label just exit
0e986ef9 403
60b9526b 404 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
405 if (label>ntracks) return;
406 for (Int_t i=0;i<10;i++){
407 // if (label<0) break;
408 if (lab[i]==label) break;
409 if (lab[i]<0) {
410 lab[i]= label;
411 break;
412 }
babd135a 413 }
414 }
415}
7f4044f0 416
1cca57bf 417void AliITSclustererV2::RecPoints2Clusters
418(const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
7f4044f0 419 //------------------------------------------------------------
1cca57bf 420 // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS
421 // subdetector indexed by idx
7f4044f0 422 //------------------------------------------------------------
423 TClonesArray &cl=*clusters;
424 Int_t ncl=points->GetEntriesFast();
425 for (Int_t i=0; i<ncl; i++) {
426 AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
427 Float_t lp[5];
00a7cc50 428 lp[0]=-(-p->GetDetLocalX()+fYshift[idx]); if (idx<=fLastSPD1) lp[0]*=-1; //SPD1
f363d377 429 lp[1]= -p->GetZ()+fZshift[idx];
00a7cc50 430 lp[2]=p->GetSigmaDetLocX2();
1cca57bf 431 lp[3]=p->GetSigmaZ2();
b6087704 432 lp[4]=p->GetQ()*36./23333.; //electrons -> ADC
7f4044f0 433 Int_t lab[4];
434 lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
1cca57bf 435 lab[3]=fNdet[idx];
7f4044f0 436 CheckLabels(lab);
babd135a 437 Int_t dummy[3]={0,0,0};
438 new (cl[i]) AliITSclusterV2(lab,lp, dummy);
7f4044f0 439 }
440}
441
7f4044f0 442//***********************************
443
7f4044f0 444
445void AliITSclustererV2::
446FindCluster(Int_t k,Int_t maxz,AliBin *bins,Int_t &n,Int_t *idx) {
447 //------------------------------------------------------------
448 // returns an array of indices of digits belonging to the cluster
449 // (needed when the segmentation is not regular)
450 //------------------------------------------------------------
451 if (n<200) idx[n++]=bins[k].GetIndex();
452 bins[k].Use();
453
454 if (bins[k-maxz].IsNotUsed()) FindCluster(k-maxz,maxz,bins,n,idx);
455 if (bins[k-1 ].IsNotUsed()) FindCluster(k-1 ,maxz,bins,n,idx);
456 if (bins[k+maxz].IsNotUsed()) FindCluster(k+maxz,maxz,bins,n,idx);
457 if (bins[k+1 ].IsNotUsed()) FindCluster(k+1 ,maxz,bins,n,idx);
458 /*
459 if (bins[k-maxz-1].IsNotUsed()) FindCluster(k-maxz-1,maxz,bins,n,idx);
460 if (bins[k-maxz+1].IsNotUsed()) FindCluster(k-maxz+1,maxz,bins,n,idx);
461 if (bins[k+maxz-1].IsNotUsed()) FindCluster(k+maxz-1,maxz,bins,n,idx);
462 if (bins[k+maxz+1].IsNotUsed()) FindCluster(k+maxz+1,maxz,bins,n,idx);
463 */
464}
465
466void AliITSclustererV2::
467FindClustersSPD(const TClonesArray *digits, TClonesArray *clusters) {
468 //------------------------------------------------------------
469 // Actual SPD cluster finder
470 //------------------------------------------------------------
c391f9d9 471 Int_t kNzBins = fNzSPD + 2;
472 const Int_t kMAXBIN=kNzBins*(fNySPD+2);
7f4044f0 473
474 Int_t ndigits=digits->GetEntriesFast();
475 AliBin *bins=new AliBin[kMAXBIN];
476
477 Int_t k;
478 AliITSdigitSPD *d=0;
479 for (k=0; k<ndigits; k++) {
480 d=(AliITSdigitSPD*)digits->UncheckedAt(k);
481 Int_t i=d->GetCoord2()+1; //y
482 Int_t j=d->GetCoord1()+1;
c391f9d9 483 bins[i*kNzBins+j].SetIndex(k);
484 bins[i*kNzBins+j].SetMask(1);
7f4044f0 485 }
486
487 Int_t n=0; TClonesArray &cl=*clusters;
488 for (k=0; k<kMAXBIN; k++) {
489 if (!bins[k].IsNotUsed()) continue;
490 Int_t ni=0, idx[200];
c391f9d9 491 FindCluster(k,kNzBins,bins,ni,idx);
c630aafd 492 if (ni==200) {
493 Info("FindClustersSPD","Too big cluster !");
494 continue;
495 }
babd135a 496 Int_t milab[10];
497 for (Int_t ilab=0;ilab<10;ilab++){
498 milab[ilab]=-2;
499 }
500
7f4044f0 501 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[0]);
502 Int_t ymin=d->GetCoord2(),ymax=ymin;
503 Int_t zmin=d->GetCoord1(),zmax=zmin;
e43c066c 504
7f4044f0 505 for (Int_t l=0; l<ni; l++) {
506 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[l]);
507
508 if (ymin > d->GetCoord2()) ymin=d->GetCoord2();
509 if (ymax < d->GetCoord2()) ymax=d->GetCoord2();
510 if (zmin > d->GetCoord1()) zmin=d->GetCoord1();
511 if (zmax < d->GetCoord1()) zmax=d->GetCoord1();
e43c066c 512 // MI addition - find all labels in cluster
513 for (Int_t dlab=0;dlab<10;dlab++){
babd135a 514 Int_t digitlab = (d->GetTracks())[dlab];
515 if (digitlab<0) continue;
e43c066c 516 AddLabel(milab,digitlab);
babd135a 517 }
e43c066c 518 if (milab[9]>0) CheckLabels2(milab);
519 }
babd135a 520 CheckLabels2(milab);
e43c066c 521 //
522 //Int_t idy = (fNlayer[fI]==0)? 2:3;
523 //for (Int_t iz=zmin; iz<=zmax;iz+=2)
524 //Int_t idy = (ymax-ymin)/4.; // max 2 clusters
525 Int_t idy = 0; // max 2 clusters
526 if (fNlayer[fI]==0 &&idy<3) idy=3;
527 if (fNlayer[fI]==1 &&idy<4) idy=4;
528 Int_t idz =3;
529 for (Int_t iz=zmin; iz<=zmax;iz+=idz)
530 for (Int_t iy=ymin; iy<=ymax;iy+=idy){
531 //
e8f4b841 532 Int_t nodigits =0;
0e986ef9 533 Float_t y=0.,z=0.,q=0.;
e43c066c 534 for (Int_t l=0; l<ni; l++) {
535 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[l]);
536 if (zmax-zmin>=idz || ymax-ymin>=idy){
537 if (TMath::Abs( d->GetCoord2()-iy)>0.75*idy) continue;
538 if (TMath::Abs( d->GetCoord1()-iz)>0.75*idz) continue;
539 }
e8f4b841 540 nodigits++;
0e986ef9 541 Float_t qq=d->GetSignal();
e43c066c 542 y+=qq*fYSPD[d->GetCoord2()]; z+=qq*fZSPD[d->GetCoord1()]; q+=qq;
543
544 }
e8f4b841 545 if (nodigits==0) continue;
e43c066c 546 y/=q; z/=q;
547 y-=fHwSPD; z-=fHlSPD;
548
549 Float_t lp[5];
550 lp[0]=-(-y+fYshift[fI]); if (fI<=fLastSPD1) lp[0]=-lp[0];
551 lp[1]= -z+fZshift[fI];
552 // Float_t factor=TMath::Max(double(ni-3.),1.5);
553 Float_t factory=TMath::Max(ymax-ymin,1);
554 Float_t factorz=TMath::Max(zmax-zmin,1);
555 factory*= factory;
556 factorz*= factorz;
557 //lp[2]= (fYpitchSPD*fYpitchSPD/12.)*factory;
558 //lp[3]= (fZ1pitchSPD*fZ1pitchSPD/12.)*factorz;
559 lp[2]= (fYpitchSPD*fYpitchSPD/12.);
560 lp[3]= (fZ1pitchSPD*fZ1pitchSPD/12.);
561 //lp[4]= q;
562 lp[4]= (zmax-zmin+1)*100 + (ymax-ymin+1);
563
564 milab[3]=fNdet[fI];
565 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[0]);
566 Int_t info[3] = {ymax-ymin+1,zmax-zmin+1,fNlayer[fI]};
567 new (cl[n]) AliITSclusterV2(milab,lp,info); n++;
568 }
7f4044f0 569 }
e43c066c 570
38bcdcc1 571 delete [] bins;
7f4044f0 572}
573
c391f9d9 574void AliITSclustererV2::FindClustersSPD(AliITSRawStream* input,
575 TClonesArray** clusters)
576{
577 //------------------------------------------------------------
578 // Actual SPD cluster finder for raw data
579 //------------------------------------------------------------
580
581 Int_t nClustersSPD = 0;
582 Int_t kNzBins = fNzSPD + 2;
583 Int_t kNyBins = fNySPD + 2;
584 Int_t kMaxBin = kNzBins * kNyBins;
5102d526 585 AliBin *binsSPD = new AliBin[kMaxBin];
586 AliBin *binsSPDInit = new AliBin[kMaxBin];
587 AliBin *bins = NULL;
c391f9d9 588
589 // read raw data input stream
590 while (kTRUE) {
591 Bool_t next = input->Next();
592 if (!next || input->IsNewModule()) {
593 Int_t iModule = input->GetPrevModuleID();
594
595 // when all data from a module was read, search for clusters
596 if (bins) {
597 clusters[iModule] = new TClonesArray("AliITSclusterV2");
598 Int_t nClusters = 0;
599
600 for (Int_t iBin = 0; iBin < kMaxBin; iBin++) {
601 if (bins[iBin].IsUsed()) continue;
602 Int_t nBins = 0;
603 Int_t idxBins[200];
604 FindCluster(iBin, kNzBins, bins, nBins, idxBins);
605 if (nBins == 200) {
606 Error("FindClustersSPD", "SPD: Too big cluster !\n");
607 continue;
608 }
609
610 Int_t label[4];
611 label[0] = -2;
612 label[1] = -2;
613 label[2] = -2;
614// label[3] = iModule;
615 label[3] = fNdet[iModule];
616
617 Int_t ymin = (idxBins[0] / kNzBins) - 1;
618 Int_t ymax = ymin;
619 Int_t zmin = (idxBins[0] % kNzBins) - 1;
620 Int_t zmax = zmin;
c391f9d9 621 for (Int_t idx = 0; idx < nBins; idx++) {
622 Int_t iy = (idxBins[idx] / kNzBins) - 1;
623 Int_t iz = (idxBins[idx] % kNzBins) - 1;
624 if (ymin > iy) ymin = iy;
625 if (ymax < iy) ymax = iy;
626 if (zmin > iz) zmin = iz;
627 if (zmax < iz) zmax = iz;
c391f9d9 628 }
0e986ef9 629
630 Int_t idy = 0; // max 2 clusters
631 if ((iModule <= fLastSPD1) &&idy<3) idy=3;
632 if ((iModule > fLastSPD1) &&idy<4) idy=4;
633 Int_t idz =3;
634 for (Int_t iiz=zmin; iiz<=zmax;iiz+=idz)
635 for (Int_t iiy=ymin; iiy<=ymax;iiy+=idy){
636 //
637 Int_t ndigits =0;
638 Float_t y=0.,z=0.,q=0.;
639 for (Int_t idx = 0; idx < nBins; idx++) {
640 Int_t iy = (idxBins[idx] / kNzBins) - 1;
641 Int_t iz = (idxBins[idx] % kNzBins) - 1;
642 if (zmax-zmin>=idz || ymax-ymin>=idy){
643 if (TMath::Abs(iy-iiy)>0.75*idy) continue;
644 if (TMath::Abs(iz-iiz)>0.75*idz) continue;
645 }
646 ndigits++;
647 Float_t qBin = bins[idxBins[idx]].GetQ();
648 y += qBin * fYSPD[iy];
649 z += qBin * fZSPD[iz];
650 q += qBin;
651 }
652 if (ndigits==0) continue;
653 y /= q;
654 z /= q;
655 y -= fHwSPD;
656 z -= fHlSPD;
657
658 Float_t hit[5]; // y, z, sigma(y)^2, sigma(z)^2, charge
659 hit[0] = -(-y+fYshift[iModule]);
660 if (iModule <= fLastSPD1) hit[0] = -hit[0];
661 hit[1] = -z+fZshift[iModule];
662 hit[2] = fYpitchSPD*fYpitchSPD/12.;
663 hit[3] = fZ1pitchSPD*fZ1pitchSPD/12.;
664 // hit[4] = q;
665 hit[4] = (zmax-zmin+1)*100 + (ymax-ymin+1);
666 // CheckLabels(label);
667 Int_t info[3]={ymax-ymin+1,zmax-zmin+1,fNlayer[iModule]};
668 new (clusters[iModule]->AddrAt(nClusters))
669 AliITSclusterV2(label, hit,info);
670 nClusters++;
671 }
c391f9d9 672 }
673
674 nClustersSPD += nClusters;
5102d526 675 bins = NULL;
c391f9d9 676 }
677
678 if (!next) break;
5102d526 679 bins = binsSPD;
680 memcpy(binsSPD,binsSPDInit,sizeof(AliBin)*kMaxBin);
c391f9d9 681 }
682
683 // fill the current digit into the bins array
684 Int_t index = (input->GetCoord2()+1) * kNzBins + (input->GetCoord1()+1);
685 bins[index].SetIndex(index);
686 bins[index].SetMask(1);
687 bins[index].SetQ(1);
688 }
689
5102d526 690 delete [] binsSPDInit;
691 delete [] binsSPD;
692
c391f9d9 693 Info("FindClustersSPD", "found clusters in ITS SPD: %d", nClustersSPD);
694}
695
696
7f4044f0 697Bool_t AliITSclustererV2::IsMaximum(Int_t k,Int_t max,const AliBin *bins) {
698 //------------------------------------------------------------
699 //is this a local maximum ?
700 //------------------------------------------------------------
701 UShort_t q=bins[k].GetQ();
702 if (q==1023) return kFALSE;
703 if (bins[k-max].GetQ() > q) return kFALSE;
704 if (bins[k-1 ].GetQ() > q) return kFALSE;
705 if (bins[k+max].GetQ() > q) return kFALSE;
706 if (bins[k+1 ].GetQ() > q) return kFALSE;
707 if (bins[k-max-1].GetQ() > q) return kFALSE;
708 if (bins[k+max-1].GetQ() > q) return kFALSE;
709 if (bins[k+max+1].GetQ() > q) return kFALSE;
710 if (bins[k-max+1].GetQ() > q) return kFALSE;
711 return kTRUE;
712}
713
714void AliITSclustererV2::
715FindPeaks(Int_t k,Int_t max,AliBin *b,Int_t *idx,UInt_t *msk,Int_t& n) {
716 //------------------------------------------------------------
717 //find local maxima
718 //------------------------------------------------------------
719 if (n<31)
720 if (IsMaximum(k,max,b)) {
721 idx[n]=k; msk[n]=(2<<n);
722 n++;
723 }
724 b[k].SetMask(0);
725 if (b[k-max].GetMask()&1) FindPeaks(k-max,max,b,idx,msk,n);
726 if (b[k-1 ].GetMask()&1) FindPeaks(k-1 ,max,b,idx,msk,n);
727 if (b[k+max].GetMask()&1) FindPeaks(k+max,max,b,idx,msk,n);
728 if (b[k+1 ].GetMask()&1) FindPeaks(k+1 ,max,b,idx,msk,n);
729}
730
731void AliITSclustererV2::
732MarkPeak(Int_t k, Int_t max, AliBin *bins, UInt_t m) {
733 //------------------------------------------------------------
734 //mark this peak
735 //------------------------------------------------------------
736 UShort_t q=bins[k].GetQ();
737
738 bins[k].SetMask(bins[k].GetMask()|m);
739
740 if (bins[k-max].GetQ() <= q)
741 if ((bins[k-max].GetMask()&m) == 0) MarkPeak(k-max,max,bins,m);
742 if (bins[k-1 ].GetQ() <= q)
743 if ((bins[k-1 ].GetMask()&m) == 0) MarkPeak(k-1 ,max,bins,m);
744 if (bins[k+max].GetQ() <= q)
745 if ((bins[k+max].GetMask()&m) == 0) MarkPeak(k+max,max,bins,m);
746 if (bins[k+1 ].GetQ() <= q)
747 if ((bins[k+1 ].GetMask()&m) == 0) MarkPeak(k+1 ,max,bins,m);
748}
749
750void AliITSclustererV2::
751MakeCluster(Int_t k,Int_t max,AliBin *bins,UInt_t m,AliITSclusterV2 &c) {
752 //------------------------------------------------------------
753 //make cluster using digits of this peak
754 //------------------------------------------------------------
755 Float_t q=(Float_t)bins[k].GetQ();
756 Int_t i=k/max, j=k-i*max;
757
758 c.SetQ(c.GetQ()+q);
759 c.SetY(c.GetY()+i*q);
760 c.SetZ(c.GetZ()+j*q);
761 c.SetSigmaY2(c.GetSigmaY2()+i*i*q);
762 c.SetSigmaZ2(c.GetSigmaZ2()+j*j*q);
763
764 bins[k].SetMask(0xFFFFFFFE);
765
766 if (bins[k-max].GetMask() == m) MakeCluster(k-max,max,bins,m,c);
767 if (bins[k-1 ].GetMask() == m) MakeCluster(k-1 ,max,bins,m,c);
768 if (bins[k+max].GetMask() == m) MakeCluster(k+max,max,bins,m,c);
769 if (bins[k+1 ].GetMask() == m) MakeCluster(k+1 ,max,bins,m,c);
770}
771
772void AliITSclustererV2::
c391f9d9 773FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
774 const TClonesArray *digits, TClonesArray *clusters) {
7f4044f0 775 //------------------------------------------------------------
776 // Actual SDD cluster finder
777 //------------------------------------------------------------
7f4044f0 778 Int_t ncl=0; TClonesArray &cl=*clusters;
779 for (Int_t s=0; s<2; s++)
c391f9d9 780 for (Int_t i=0; i<nMaxBin; i++) {
7f4044f0 781 if (bins[s][i].IsUsed()) continue;
782 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
c391f9d9 783 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
7f4044f0 784
785 if (npeaks>30) continue;
e43c066c 786 if (npeaks==0) continue;
7f4044f0 787
788 Int_t k,l;
789 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
790 if (idx[k] < 0) continue; //this peak is already removed
791 for (l=k+1; l<npeaks; l++) {
792 if (idx[l] < 0) continue; //this peak is already removed
c391f9d9 793 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
794 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
7f4044f0 795 Int_t di=TMath::Abs(ki - li);
796 Int_t dj=TMath::Abs(kj - lj);
797 if (di>1 || dj>1) continue;
798 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
799 msk[l]=msk[k];
800 idx[l]*=-1;
801 } else {
802 msk[k]=msk[l];
803 idx[k]*=-1;
804 break;
805 }
806 }
807 }
808
809 for (k=0; k<npeaks; k++) {
c391f9d9 810 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
7f4044f0 811 }
812
813 for (k=0; k<npeaks; k++) {
814 if (idx[k] < 0) continue; //removed peak
815 AliITSclusterV2 c;
c391f9d9 816 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
babd135a 817 //mi change
818 Int_t milab[10];
819 for (Int_t ilab=0;ilab<10;ilab++){
820 milab[ilab]=-2;
821 }
e43c066c 822 Int_t maxi=0,mini=0,maxj=0,minj=0;
823 //AliBin *bmax=&bins[s][idx[k]];
824 //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
825 Float_t max=3;
826 for (Int_t di=-2; di<=2;di++)
827 for (Int_t dj=-3;dj<=3;dj++){
828 Int_t index = idx[k]+di+dj*nzBins;
829 if (index<0) continue;
830 if (index>=nMaxBin) continue;
831 AliBin *b=&bins[s][index];
832 if (TMath::Abs(b->GetQ())>max){
833 if (di>maxi) maxi=di;
834 if (di<mini) mini=di;
835 if (dj>maxj) maxj=dj;
836 if (dj<minj) minj=dj;
837 //
0e986ef9 838 if(digits) {
839 if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
840 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
841 for (Int_t itrack=0;itrack<10;itrack++){
842 Int_t track = (d->GetTracks())[itrack];
843 if (track>=0) {
844 AddLabel(milab, track);
845 }
e43c066c 846 }
847 }
848 }
849 }
850 }
851
852 /*
853 Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
854 Float_t w=par->GetPadPitchWidth(sec);
855 c.SetSigmaY2(s2);
856 if (s2 != 0.) {
857 c.SetSigmaY2(c.GetSigmaY2()*0.108);
858 if (sec<par->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
859 }
860 s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
861 w=par->GetZWidth();
862 c.SetSigmaZ2(s2);
863
864 if (s2 != 0.) {
865 c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
866 if (sec<par->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
867 }
7f4044f0 868 */
869
7f4044f0 870 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
871 y/=q; z/=q;
e43c066c 872 //
873 //Float_t s2 = c.GetSigmaY2()/c.GetQ() - y*y;
874 // c.SetSigmaY2(s2);
875 //s2 = c.GetSigmaZ2()/c.GetQ() - z*z;
876 //c.SetSigmaZ2(s2);
877 //
7f4044f0 878 y=(y-0.5)*fYpitchSDD;
879 y-=fHwSDD;
880 y-=fYoffSDD; //delay ?
881 if (s) y=-y;
882
883 z=(z-0.5)*fZpitchSDD;
884 z-=fHlSDD;
885
f363d377 886 y=-(-y+fYshift[fI]);
887 z= -z+fZshift[fI];
ecb9da3c 888
889 q/=12.7; //this WAS consistent with SSD. To be reassessed
890 // 23-MAR-2007
891 Float_t hit[5] = {y, z, 0.0030*0.0030, 0.0020*0.0020, q};
892 Int_t info[3] = {maxj-minj+1, maxi-mini+1, fNlayer[fI]};
e3d91d99 893
894 if (c.GetQ() < 20.) continue; //noise cluster
e43c066c 895
896 if (digits) {
897 // AliBin *b=&bins[s][idx[k]];
898 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
c391f9d9 899 {
e43c066c 900 //Int_t lab[3];
901 //lab[0]=(d->GetTracks())[0];
902 //lab[1]=(d->GetTracks())[1];
903 //lab[2]=(d->GetTracks())[2];
904 //CheckLabels(lab);
babd135a 905 CheckLabels2(milab);
c391f9d9 906 }
907 }
ecb9da3c 908 milab[3]=fNdet[fI];
909
910 AliITSclusterV2 *cc = new (cl[ncl]) AliITSclusterV2(milab,hit,info);
911 cc->SetType(npeaks);
912 ncl++;
7f4044f0 913 }
914 }
c391f9d9 915}
916
917void AliITSclustererV2::
918FindClustersSDD(const TClonesArray *digits, TClonesArray *clusters) {
919 //------------------------------------------------------------
920 // Actual SDD cluster finder
921 //------------------------------------------------------------
922 Int_t kNzBins = fNzSDD + 2;
923 const Int_t kMAXBIN=kNzBins*(fNySDD+2);
924
925 AliBin *bins[2];
926 bins[0]=new AliBin[kMAXBIN];
927 bins[1]=new AliBin[kMAXBIN];
928
929 AliITSdigitSDD *d=0;
930 Int_t i, ndigits=digits->GetEntriesFast();
931 for (i=0; i<ndigits; i++) {
932 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
933 Int_t y=d->GetCoord2()+1; //y
934 Int_t z=d->GetCoord1()+1; //z
935 Int_t q=d->GetSignal();
e43c066c 936 if (q<3) continue;
e3d91d99 937
c391f9d9 938 if (z <= fNzSDD) {
939 bins[0][y*kNzBins+z].SetQ(q);
940 bins[0][y*kNzBins+z].SetMask(1);
941 bins[0][y*kNzBins+z].SetIndex(i);
942 } else {
943 z-=fNzSDD;
944 bins[1][y*kNzBins+z].SetQ(q);
945 bins[1][y*kNzBins+z].SetMask(1);
946 bins[1][y*kNzBins+z].SetIndex(i);
947 }
948 }
949
950 FindClustersSDD(bins, kMAXBIN, kNzBins, digits, clusters);
7f4044f0 951
952 delete[] bins[0];
953 delete[] bins[1];
0e986ef9 954
7f4044f0 955}
956
c391f9d9 957void AliITSclustererV2::FindClustersSDD(AliITSRawStream* input,
958 TClonesArray** clusters)
959{
960 //------------------------------------------------------------
961 // Actual SDD cluster finder for raw data
962 //------------------------------------------------------------
963 Int_t nClustersSDD = 0;
964 Int_t kNzBins = fNzSDD + 2;
965 Int_t kMaxBin = kNzBins * (fNySDD+2);
5102d526 966 AliBin *binsSDDInit = new AliBin[kMaxBin];
967 AliBin *binsSDD1 = new AliBin[kMaxBin];
968 AliBin *binsSDD2 = new AliBin[kMaxBin];
969 AliBin *bins[2] = {NULL, NULL};
c391f9d9 970
971 // read raw data input stream
972 while (kTRUE) {
973 Bool_t next = input->Next();
974 if (!next || input->IsNewModule()) {
975 Int_t iModule = input->GetPrevModuleID();
976
977 // when all data from a module was read, search for clusters
978 if (bins[0]) {
979 clusters[iModule] = new TClonesArray("AliITSclusterV2");
980 fI = iModule;
981 FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
982 Int_t nClusters = clusters[iModule]->GetEntriesFast();
983 nClustersSDD += nClusters;
5102d526 984 bins[0] = bins[1] = NULL;
c391f9d9 985 }
986
987 if (!next) break;
5102d526 988 bins[0]=binsSDD1;
989 bins[1]=binsSDD2;
990 memcpy(binsSDD1,binsSDDInit,sizeof(AliBin)*kMaxBin);
991 memcpy(binsSDD2,binsSDDInit,sizeof(AliBin)*kMaxBin);
c391f9d9 992 }
993
994 // fill the current digit into the bins array
0e986ef9 995 if(input->GetSignal()>=3) {
996 Int_t iz = input->GetCoord1()+1;
997 Int_t side = ((iz <= fNzSDD) ? 0 : 1);
998 iz -= side*fNzSDD;
999 Int_t index = (input->GetCoord2()+1) * kNzBins + iz;
1000 bins[side][index].SetQ(input->GetSignal());
1001 bins[side][index].SetMask(1);
1002 bins[side][index].SetIndex(index);
1003 }
c391f9d9 1004 }
1005
5102d526 1006 delete[] binsSDD1;
1007 delete[] binsSDD2;
1008 delete[] binsSDDInit;
1009
c391f9d9 1010 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
1011}
1012
e43c066c 1013
1014
c391f9d9 1015void AliITSclustererV2::
1016FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
1017 Ali1Dcluster* pos, Int_t np,
1018 TClonesArray *clusters) {
1019 //------------------------------------------------------------
1020 // Actual SSD cluster finder
1021 //------------------------------------------------------------
1022 TClonesArray &cl=*clusters;
e43c066c 1023 //
c391f9d9 1024 Float_t tanp=fTanP, tann=fTanN;
1025 if (fI>fLastSSD1) {tann=fTanP; tanp=fTanN;}
c391f9d9 1026 Int_t idet=fNdet[fI];
1027 Int_t ncl=0;
e43c066c 1028 //
1029 Int_t negativepair[30000];
1030 Int_t cnegative[3000];
1031 Int_t cused1[3000];
1032 Int_t positivepair[30000];
1033 Int_t cpositive[3000];
1034 Int_t cused2[3000];
1035 for (Int_t i=0;i<3000;i++) {cnegative[i]=0; cused1[i]=0;}
1036 for (Int_t i=0;i<3000;i++) {cpositive[i]=0; cused2[i]=0;}
b66f90a0 1037 for (Int_t i=0;i<30000;i++){negativepair[i]=positivepair[i]=0;}
0774985e 1038 static Short_t pairs[1000][1000];
1039 memset(pairs,0,sizeof(Short_t)*1000000);
1040// Short_t ** pairs = new Short_t*[1000];
1041// for (Int_t i=0; i<1000; i++) {
1042// pairs[i] = new Short_t[1000];
1043// memset(pairs[i],0,sizeof(Short_t)*1000);
1044// }
e43c066c 1045 //
1046 // find available pairs
1047 //
1048 for (Int_t i=0; i<np; i++) {
1049 Float_t yp=pos[i].GetY()*fYpitchSSD;
1050 if (pos[i].GetQ()<3) continue;
1051 for (Int_t j=0; j<nn; j++) {
1052 if (neg[j].GetQ()<3) continue;
1053 Float_t yn=neg[j].GetY()*fYpitchSSD;
1054 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1055 Float_t yt=yn + tann*zt;
1056 zt-=fHlSSD; yt-=fHwSSD;
1057 if (TMath::Abs(yt)<fHwSSD+0.01)
1058 if (TMath::Abs(zt)<fHlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
1059 negativepair[i*10+cnegative[i]] =j; //index
1060 positivepair[j*10+cpositive[j]] =i;
1061 cnegative[i]++; //counters
1062 cpositive[j]++;
1063 pairs[i][j]=100;
1064 }
1065 }
1066 }
1067 //
1068 for (Int_t i=0; i<np; i++) {
1069 Float_t yp=pos[i].GetY()*fYpitchSSD;
1070 if (pos[i].GetQ()<3) continue;
1071 for (Int_t j=0; j<nn; j++) {
1072 if (neg[j].GetQ()<3) continue;
1073 if (cpositive[j]&&cnegative[i]) continue;
1074 Float_t yn=neg[j].GetY()*fYpitchSSD;
1075 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1076 Float_t yt=yn + tann*zt;
1077 zt-=fHlSSD; yt-=fHwSSD;
1078 if (TMath::Abs(yt)<fHwSSD+0.1)
1079 if (TMath::Abs(zt)<fHlSSD+0.15) {
1080 if (cnegative[i]==0) pos[i].SetNd(100); // not available pair
1081 if (cpositive[j]==0) neg[j].SetNd(100); // not available pair
1082 negativepair[i*10+cnegative[i]] =j; //index
1083 positivepair[j*10+cpositive[j]] =i;
1084 cnegative[i]++; //counters
1085 cpositive[j]++;
1086 pairs[i][j]=100;
1087 }
1088 }
1089 }
1090 //
1091 Float_t lp[5];
1092 Int_t milab[10];
1093 Double_t ratio;
1094
1095 //
1096 // sign gold tracks
1097 //
1098 for (Int_t ip=0;ip<np;ip++){
1099 Float_t ybest=1000,zbest=1000,qbest=0;
1100 //
1101 // select gold clusters
1102 if ( (cnegative[ip]==1) && cpositive[negativepair[10*ip]]==1){
1103 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1104 Int_t j = negativepair[10*ip];
1105 ratio = (pos[ip].GetQ()-neg[j].GetQ())/(pos[ip].GetQ()+neg[j].GetQ());
1106 //
1107 Float_t yn=neg[j].GetY()*fYpitchSSD;
1108 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1109 Float_t yt=yn + tann*zt;
1110 zt-=fHlSSD; yt-=fHwSSD;
1111 ybest=yt; zbest=zt;
1112 qbest=0.5*(pos[ip].GetQ()+neg[j].GetQ());
1113 lp[0]=-(-ybest+fYshift[fI]);
1114 lp[1]= -zbest+fZshift[fI];
1115 lp[2]=0.0025*0.0025; //SigmaY2
1116 lp[3]=0.110*0.110; //SigmaZ2
1117
1118 lp[4]=qbest; //Q
1119 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1120 for (Int_t ilab=0;ilab<3;ilab++){
1121 milab[ilab] = pos[ip].GetLabel(ilab);
1122 milab[ilab+3] = neg[j].GetLabel(ilab);
1123 }
1124 //
1125 CheckLabels2(milab);
1126 milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
1127 Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1128 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1129 ncl++;
1130 cl2->SetChargeRatio(ratio);
1131 cl2->SetType(1);
1132 pairs[ip][j]=1;
1133 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1134 cl2->SetType(2);
1135 pairs[ip][j]=2;
1136 }
1137 cused1[ip]++;
1138 cused2[j]++;
1139 }
1140 }
1141
1142 for (Int_t ip=0;ip<np;ip++){
1143 Float_t ybest=1000,zbest=1000,qbest=0;
1144 //
1145 //
1146 // select "silber" cluster
1147 if ( cnegative[ip]==1 && cpositive[negativepair[10*ip]]==2){
1148 Int_t in = negativepair[10*ip];
1149 Int_t ip2 = positivepair[10*in];
1150 if (ip2==ip) ip2 = positivepair[10*in+1];
1151 Float_t pcharge = pos[ip].GetQ()+pos[ip2].GetQ();
1152 if (TMath::Abs(pcharge-neg[in].GetQ())<10){
1153 //
1154 // add first pair
1155 if (pairs[ip][in]==100){ //
1156 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1157 Float_t yn=neg[in].GetY()*fYpitchSSD;
1158 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1159 Float_t yt=yn + tann*zt;
1160 zt-=fHlSSD; yt-=fHwSSD;
1161 ybest =yt; zbest=zt;
1162 qbest =pos[ip].GetQ();
1163 lp[0]=-(-ybest+fYshift[fI]);
1164 lp[1]= -zbest+fZshift[fI];
1165 lp[2]=0.0025*0.0025; //SigmaY2
1166 lp[3]=0.110*0.110; //SigmaZ2
1167
1168 lp[4]=qbest; //Q
1169 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1170 for (Int_t ilab=0;ilab<3;ilab++){
1171 milab[ilab] = pos[ip].GetLabel(ilab);
1172 milab[ilab+3] = neg[in].GetLabel(ilab);
1173 }
1174 //
1175 CheckLabels2(milab);
1176 ratio = (pos[ip].GetQ()-neg[in].GetQ())/(pos[ip].GetQ()+neg[in].GetQ());
1177 milab[3]=(((ip<<10) + in)<<10) + idet; // pos|neg|det
1178 Int_t info[3] = {pos[ip].GetNd(),neg[in].GetNd(),fNlayer[fI]};
1179 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1180 ncl++;
1181 cl2->SetChargeRatio(ratio);
1182 cl2->SetType(5);
1183 pairs[ip][in] = 5;
1184 if ((pos[ip].GetNd()+neg[in].GetNd())>6){ //multi cluster
1185 cl2->SetType(6);
1186 pairs[ip][in] = 6;
1187 }
1188 }
1189 //
1190 // add second pair
1191
1192 // if (!(cused1[ip2] || cused2[in])){ //
1193 if (pairs[ip2][in]==100){
1194 Float_t yp=pos[ip2].GetY()*fYpitchSSD;
1195 Float_t yn=neg[in].GetY()*fYpitchSSD;
1196 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1197 Float_t yt=yn + tann*zt;
1198 zt-=fHlSSD; yt-=fHwSSD;
1199 ybest =yt; zbest=zt;
1200 qbest =pos[ip2].GetQ();
1201 lp[0]=-(-ybest+fYshift[fI]);
1202 lp[1]= -zbest+fZshift[fI];
1203 lp[2]=0.0025*0.0025; //SigmaY2
1204 lp[3]=0.110*0.110; //SigmaZ2
1205
1206 lp[4]=qbest; //Q
1207 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1208 for (Int_t ilab=0;ilab<3;ilab++){
1209 milab[ilab] = pos[ip2].GetLabel(ilab);
1210 milab[ilab+3] = neg[in].GetLabel(ilab);
1211 }
1212 //
1213 CheckLabels2(milab);
1214 ratio = (pos[ip2].GetQ()-neg[in].GetQ())/(pos[ip2].GetQ()+neg[in].GetQ());
1215 milab[3]=(((ip2<<10) + in)<<10) + idet; // pos|neg|det
1216 Int_t info[3] = {pos[ip2].GetNd(),neg[in].GetNd(),fNlayer[fI]};
1217 AliITSclusterV2 *cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1218 ncl++;
1219 cl2->SetChargeRatio(ratio);
1220 cl2->SetType(5);
1221 pairs[ip2][in] =5;
1222 if ((pos[ip2].GetNd()+neg[in].GetNd())>6){ //multi cluster
1223 cl2->SetType(6);
1224 pairs[ip2][in] =6;
1225 }
1226 }
1227 cused1[ip]++;
1228 cused1[ip2]++;
1229 cused2[in]++;
1230 }
1231 }
1232 }
1233
1234 //
1235 for (Int_t jn=0;jn<nn;jn++){
1236 if (cused2[jn]) continue;
1237 Float_t ybest=1000,zbest=1000,qbest=0;
1238 // select "silber" cluster
1239 if ( cpositive[jn]==1 && cnegative[positivepair[10*jn]]==2){
1240 Int_t ip = positivepair[10*jn];
1241 Int_t jn2 = negativepair[10*ip];
1242 if (jn2==jn) jn2 = negativepair[10*ip+1];
1243 Float_t pcharge = neg[jn].GetQ()+neg[jn2].GetQ();
1244 //
1245 if (TMath::Abs(pcharge-pos[ip].GetQ())<10){
1246 //
1247 // add first pair
1248 // if (!(cused1[ip]||cused2[jn])){
1249 if (pairs[ip][jn]==100){
1250 Float_t yn=neg[jn].GetY()*fYpitchSSD;
1251 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1252 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1253 Float_t yt=yn + tann*zt;
1254 zt-=fHlSSD; yt-=fHwSSD;
1255 ybest =yt; zbest=zt;
1256 qbest =neg[jn].GetQ();
1257 lp[0]=-(-ybest+fYshift[fI]);
1258 lp[1]= -zbest+fZshift[fI];
1259 lp[2]=0.0025*0.0025; //SigmaY2
1260 lp[3]=0.110*0.110; //SigmaZ2
1261
1262 lp[4]=qbest; //Q
1263 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1264 for (Int_t ilab=0;ilab<3;ilab++){
1265 milab[ilab] = pos[ip].GetLabel(ilab);
1266 milab[ilab+3] = neg[jn].GetLabel(ilab);
1267 }
1268 //
1269 CheckLabels2(milab);
1270 ratio = (pos[ip].GetQ()-neg[jn].GetQ())/(pos[ip].GetQ()+neg[jn].GetQ());
1271 milab[3]=(((ip<<10) + jn)<<10) + idet; // pos|neg|det
1272 Int_t info[3] = {pos[ip].GetNd(),neg[jn].GetNd(),fNlayer[fI]};
1273 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1274 ncl++;
1275 cl2->SetChargeRatio(ratio);
1276 cl2->SetType(7);
1277 pairs[ip][jn] =7;
1278 if ((pos[ip].GetNd()+neg[jn].GetNd())>6){ //multi cluster
1279 cl2->SetType(8);
1280 pairs[ip][jn]=8;
1281 }
1282 }
1283 //
1284 // add second pair
1285 // if (!(cused1[ip]||cused2[jn2])){
1286 if (pairs[ip][jn2]==100){
1287 Float_t yn=neg[jn2].GetY()*fYpitchSSD;
1288 Double_t yp=pos[ip].GetY()*fYpitchSSD;
1289 Double_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1290 Double_t yt=yn + tann*zt;
1291 zt-=fHlSSD; yt-=fHwSSD;
1292 ybest =yt; zbest=zt;
1293 qbest =neg[jn2].GetQ();
1294 lp[0]=-(-ybest+fYshift[fI]);
1295 lp[1]= -zbest+fZshift[fI];
1296 lp[2]=0.0025*0.0025; //SigmaY2
1297 lp[3]=0.110*0.110; //SigmaZ2
1298
1299 lp[4]=qbest; //Q
1300 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1301 for (Int_t ilab=0;ilab<3;ilab++){
1302 milab[ilab] = pos[ip].GetLabel(ilab);
1303 milab[ilab+3] = neg[jn2].GetLabel(ilab);
1304 }
1305 //
1306 CheckLabels2(milab);
1307 ratio = (pos[ip].GetQ()-neg[jn2].GetQ())/(pos[ip].GetQ()+neg[jn2].GetQ());
1308 milab[3]=(((ip<<10) + jn2)<<10) + idet; // pos|neg|det
1309 Int_t info[3] = {pos[ip].GetNd(),neg[jn2].GetNd(),fNlayer[fI]};
1310 AliITSclusterV2* cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1311 ncl++;
1312 cl2->SetChargeRatio(ratio);
1313 pairs[ip][jn2]=7;
1314 cl2->SetType(7);
1315 if ((pos[ip].GetNd()+neg[jn2].GetNd())>6){ //multi cluster
1316 cl2->SetType(8);
1317 pairs[ip][jn2]=8;
1318 }
1319 }
1320 cused1[ip]++;
1321 cused2[jn]++;
1322 cused2[jn2]++;
1323 }
1324 }
1325 }
1326
1327 for (Int_t ip=0;ip<np;ip++){
1328 Float_t ybest=1000,zbest=1000,qbest=0;
1329 //
1330 // 2x2 clusters
1331 //
1332 if ( (cnegative[ip]<5) && cpositive[negativepair[10*ip]]<5){
1333 Float_t minchargediff =4.;
1334 Int_t j=-1;
1335 for (Int_t di=0;di<cnegative[ip];di++){
1336 Int_t jc = negativepair[ip*10+di];
1337 Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1338 if (TMath::Abs(chargedif)<minchargediff){
1339 j =jc;
1340 minchargediff = TMath::Abs(chargedif);
1341 }
1342 }
1343 if (j<0) continue; // not proper cluster
1344 Int_t count =0;
1345 for (Int_t di=0;di<cnegative[ip];di++){
1346 Int_t jc = negativepair[ip*10+di];
1347 Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1348 if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1349 }
1350 if (count>1) continue; // more than one "proper" cluster for positive
1351 //
1352 count =0;
1353 for (Int_t dj=0;dj<cpositive[j];dj++){
1354 Int_t ic = positivepair[j*10+dj];
1355 Float_t chargedif = pos[ic].GetQ()-neg[j].GetQ();
1356 if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1357 }
1358 if (count>1) continue; // more than one "proper" cluster for negative
1359
1360 Int_t jp = 0;
1361
1362 count =0;
1363 for (Int_t dj=0;dj<cnegative[jp];dj++){
1364 Int_t ic = positivepair[jp*10+dj];
1365 Float_t chargedif = pos[ic].GetQ()-neg[jp].GetQ();
1366 if (TMath::Abs(chargedif)<minchargediff+4.) count++;
1367 }
1368 if (count>1) continue;
1369 if (pairs[ip][j]<100) continue;
1370 //
1371 //almost gold clusters
1372 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1373 Float_t yn=neg[j].GetY()*fYpitchSSD;
1374 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1375 Float_t yt=yn + tann*zt;
1376 zt-=fHlSSD; yt-=fHwSSD;
1377 ybest=yt; zbest=zt;
1378 qbest=0.5*(pos[ip].GetQ()+neg[j].GetQ());
1379 lp[0]=-(-ybest+fYshift[fI]);
1380 lp[1]= -zbest+fZshift[fI];
1381 lp[2]=0.0025*0.0025; //SigmaY2
1382 lp[3]=0.110*0.110; //SigmaZ2
1383 lp[4]=qbest; //Q
1384 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1385 for (Int_t ilab=0;ilab<3;ilab++){
1386 milab[ilab] = pos[ip].GetLabel(ilab);
1387 milab[ilab+3] = neg[j].GetLabel(ilab);
1388 }
1389 //
1390 CheckLabels2(milab);
1391 ratio = (pos[ip].GetQ()-neg[j].GetQ())/(pos[ip].GetQ()+neg[j].GetQ());
1392 milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
1393 Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1394 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1395 ncl++;
1396 cl2->SetChargeRatio(ratio);
1397 cl2->SetType(10);
1398 pairs[ip][j]=10;
1399 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1400 cl2->SetType(11);
1401 pairs[ip][j]=11;
1402 }
1403 cused1[ip]++;
1404 cused2[j]++;
1405 }
1406
1407 }
1408
1409 //
c391f9d9 1410 for (Int_t i=0; i<np; i++) {
c391f9d9 1411 Float_t ybest=1000,zbest=1000,qbest=0;
1412 Float_t yp=pos[i].GetY()*fYpitchSSD;
e43c066c 1413 if (pos[i].GetQ()<3) continue;
c391f9d9 1414 for (Int_t j=0; j<nn; j++) {
e43c066c 1415 // for (Int_t di = 0;di<cpositive[i];di++){
1416 // Int_t j = negativepair[10*i+di];
1417 if (neg[j].GetQ()<3) continue;
1418 if (cused2[j]||cused1[i]) continue;
1419 if (pairs[i][j]>0 &&pairs[i][j]<100) continue;
1420 ratio = (pos[i].GetQ()-neg[j].GetQ())/(pos[i].GetQ()+neg[j].GetQ());
c391f9d9 1421 Float_t yn=neg[j].GetY()*fYpitchSSD;
1422 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1423 Float_t yt=yn + tann*zt;
1424 zt-=fHlSSD; yt-=fHwSSD;
1425 if (TMath::Abs(yt)<fHwSSD+0.01)
e43c066c 1426 if (TMath::Abs(zt)<fHlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
c391f9d9 1427 ybest=yt; zbest=zt;
1428 qbest=0.5*(pos[i].GetQ()+neg[j].GetQ());
f363d377 1429 lp[0]=-(-ybest+fYshift[fI]);
1430 lp[1]= -zbest+fZshift[fI];
e43c066c 1431 lp[2]=0.0025*0.0025; //SigmaY2
1432 lp[3]=0.110*0.110; //SigmaZ2
1433
c391f9d9 1434 lp[4]=qbest; //Q
babd135a 1435 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
e43c066c 1436 for (Int_t ilab=0;ilab<3;ilab++){
1437 milab[ilab] = pos[i].GetLabel(ilab);
1438 milab[ilab+3] = neg[j].GetLabel(ilab);
1439 }
babd135a 1440 //
babd135a 1441 CheckLabels2(milab);
1442 milab[3]=(((i<<10) + j)<<10) + idet; // pos|neg|det
e43c066c 1443 Int_t info[3] = {pos[i].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1444 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1445 ncl++;
1446 cl2->SetChargeRatio(ratio);
1447 cl2->SetType(100+cpositive[j]+cnegative[i]);
1448 //cl2->SetType(0);
1449 /*
1450 if (pairs[i][j]<100){
1451 printf("problem:- %d\n", pairs[i][j]);
1452 }
1453 if (cnegative[i]<2&&cpositive[j]<2){
1454 printf("problem:- %d\n", pairs[i][j]);
1455 }
1456 */
c391f9d9 1457 }
1458 }
c391f9d9 1459 }
a06cb96e 1460
0774985e 1461// for (Int_t i=0; i<1000; i++) delete [] pairs[i];
1462// delete [] pairs;
a06cb96e 1463
c391f9d9 1464}
1465
e43c066c 1466
7f4044f0 1467void AliITSclustererV2::
e43c066c 1468FindClustersSSD(const TClonesArray *alldigits, TClonesArray *clusters) {
7f4044f0 1469 //------------------------------------------------------------
1470 // Actual SSD cluster finder
1471 //------------------------------------------------------------
e43c066c 1472 Int_t smaxall=alldigits->GetEntriesFast();
1473 if (smaxall==0) return;
1474 TObjArray *digits = new TObjArray;
1475 for (Int_t i=0;i<smaxall; i++){
1476 AliITSdigitSSD *d=(AliITSdigitSSD*)alldigits->UncheckedAt(i);
1477 if (d->GetSignal()<3) continue;
1478 digits->AddLast(d);
1479 }
1480 Int_t smax = digits->GetEntriesFast();
7f4044f0 1481 if (smax==0) return;
e43c066c 1482
7f4044f0 1483 const Int_t MAX=1000;
1484 Int_t np=0, nn=0;
1485 Ali1Dcluster pos[MAX], neg[MAX];
1486 Float_t y=0., q=0., qmax=0.;
1487 Int_t lab[4]={-2,-2,-2,-2};
e43c066c 1488
7f4044f0 1489 AliITSdigitSSD *d=(AliITSdigitSSD*)digits->UncheckedAt(0);
1490 q += d->GetSignal();
1491 y += d->GetCoord2()*d->GetSignal();
1492 qmax=d->GetSignal();
1493 lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
1494 Int_t curr=d->GetCoord2();
1495 Int_t flag=d->GetCoord1();
1496 Int_t *n=&nn;
1497 Ali1Dcluster *c=neg;
c391f9d9 1498 Int_t nd=1;
e43c066c 1499 Int_t milab[10];
1500 for (Int_t ilab=0;ilab<10;ilab++){
1501 milab[ilab]=-2;
1502 }
1503 milab[0]=d->GetTrack(0); milab[1]=d->GetTrack(1); milab[2]=d->GetTrack(2);
1504
7f4044f0 1505 for (Int_t s=1; s<smax; s++) {
e43c066c 1506 d=(AliITSdigitSSD*)digits->UncheckedAt(s);
7f4044f0 1507 Int_t strip=d->GetCoord2();
1508 if ((strip-curr) > 1 || flag!=d->GetCoord1()) {
1509 c[*n].SetY(y/q);
1510 c[*n].SetQ(q);
1511 c[*n].SetNd(nd);
e43c066c 1512 CheckLabels2(milab);
1513 c[*n].SetLabels(milab);
7f4044f0 1514 //Split suspiciously big cluster
e43c066c 1515 /*
1516 if (nd>10&&nd<16){
1517 c[*n].SetY(y/q-0.3*nd);
1518 c[*n].SetQ(0.5*q);
1519 (*n)++;
1520 if (*n==MAX) {
1521 Error("FindClustersSSD","Too many 1D clusters !");
7f4044f0 1522 return;
e43c066c 1523 }
1524 c[*n].SetY(y/q-0.0*nd);
1525 c[*n].SetQ(0.5*q);
1526 c[*n].SetNd(nd);
1527 (*n)++;
1528 if (*n==MAX) {
1529 Error("FindClustersSSD","Too many 1D clusters !");
1530 return;
1531 }
1532 //
1533 c[*n].SetY(y/q+0.3*nd);
1534 c[*n].SetQ(0.5*q);
1535 c[*n].SetNd(nd);
1536 c[*n].SetLabels(milab);
1537 }
1538 else{
1539 */
1540 if (nd>4&&nd<25) {
1541 c[*n].SetY(y/q-0.25*nd);
1542 c[*n].SetQ(0.5*q);
1543 (*n)++;
1544 if (*n==MAX) {
1545 Error("FindClustersSSD","Too many 1D clusters !");
1546 return;
1547 }
1548 c[*n].SetY(y/q+0.25*nd);
1549 c[*n].SetQ(0.5*q);
1550 c[*n].SetNd(nd);
1551 c[*n].SetLabels(milab);
1552 }
7f4044f0 1553 (*n)++;
1554 if (*n==MAX) {
c630aafd 1555 Error("FindClustersSSD","Too many 1D clusters !");
7f4044f0 1556 return;
1557 }
1558 y=q=qmax=0.;
1559 nd=0;
1560 lab[0]=lab[1]=lab[2]=-2;
e43c066c 1561 //
1562 for (Int_t ilab=0;ilab<10;ilab++){
1563 milab[ilab]=-2;
1564 }
1565 //
7f4044f0 1566 if (flag!=d->GetCoord1()) { n=&np; c=pos; }
1567 }
1568 flag=d->GetCoord1();
1569 q += d->GetSignal();
1570 y += d->GetCoord2()*d->GetSignal();
1571 nd++;
1572 if (d->GetSignal()>qmax) {
1573 qmax=d->GetSignal();
1574 lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
1575 }
e43c066c 1576 for (Int_t ilab=0;ilab<10;ilab++) {
1577 if (d->GetTrack(ilab)>=0) AddLabel(milab, (d->GetTrack(ilab)));
1578 }
7f4044f0 1579 curr=strip;
1580 }
1581 c[*n].SetY(y/q);
1582 c[*n].SetQ(q);
1583 c[*n].SetNd(nd);
1584 c[*n].SetLabels(lab);
1585 //Split suspiciously big cluster
0e986ef9 1586 if (nd>4 && nd<25) {
1587 c[*n].SetY(y/q-0.25*nd);
7f4044f0 1588 c[*n].SetQ(0.5*q);
1589 (*n)++;
1590 if (*n==MAX) {
c630aafd 1591 Error("FindClustersSSD","Too many 1D clusters !");
7f4044f0 1592 return;
1593 }
0e986ef9 1594 c[*n].SetY(y/q+0.25*nd);
7f4044f0 1595 c[*n].SetQ(0.5*q);
1596 c[*n].SetNd(nd);
1597 c[*n].SetLabels(lab);
1598 }
1599 (*n)++;
1600 if (*n==MAX) {
c630aafd 1601 Error("FindClustersSSD","Too many 1D clusters !");
7f4044f0 1602 return;
1603 }
1604
c391f9d9 1605 FindClustersSSD(neg, nn, pos, np, clusters);
1606}
7f4044f0 1607
c391f9d9 1608void AliITSclustererV2::FindClustersSSD(AliITSRawStream* input,
1609 TClonesArray** clusters)
1610{
1611 //------------------------------------------------------------
1612 // Actual SSD cluster finder for raw data
1613 //------------------------------------------------------------
1614 Int_t nClustersSSD = 0;
1615 const Int_t MAX = 1000;
1616 Ali1Dcluster clusters1D[2][MAX];
1617 Int_t nClusters[2] = {0, 0};
0e986ef9 1618 Int_t lab[3]={-2,-2,-2};
c391f9d9 1619 Float_t q = 0.;
1620 Float_t y = 0.;
1621 Int_t nDigits = 0;
1622 Int_t prevStrip = -1;
1623 Int_t prevFlag = -1;
0e986ef9 1624 Int_t prevModule = -1;
c391f9d9 1625
1626 // read raw data input stream
1627 while (kTRUE) {
1628 Bool_t next = input->Next();
1629
0e986ef9 1630 if(input->GetSignal()<3 && next) continue;
c391f9d9 1631 // check if a new cluster starts
1632 Int_t strip = input->GetCoord2();
1633 Int_t flag = input->GetCoord1();
0e986ef9 1634 if ((!next || (input->GetModuleID() != prevModule)||
c391f9d9 1635 (strip-prevStrip > 1) || (flag != prevFlag)) &&
1636 (nDigits > 0)) {
1637 if (nClusters[prevFlag] == MAX) {
1638 Error("FindClustersSSD", "Too many 1D clusters !");
1639 return;
1640 }
1641 Ali1Dcluster& cluster = clusters1D[prevFlag][nClusters[prevFlag]++];
1642 cluster.SetY(y/q);
1643 cluster.SetQ(q);
1644 cluster.SetNd(nDigits);
0e986ef9 1645 cluster.SetLabels(lab);
c391f9d9 1646
1647 //Split suspiciously big cluster
0e986ef9 1648 if (nDigits > 4&&nDigits < 25) {
1649 cluster.SetY(y/q - 0.25*nDigits);
c391f9d9 1650 cluster.SetQ(0.5*q);
1651 if (nClusters[prevFlag] == MAX) {
1652 Error("FindClustersSSD", "Too many 1D clusters !");
1653 return;
1654 }
1655 Ali1Dcluster& cluster2 = clusters1D[prevFlag][nClusters[prevFlag]++];
0e986ef9 1656 cluster2.SetY(y/q + 0.25*nDigits);
c391f9d9 1657 cluster2.SetQ(0.5*q);
1658 cluster2.SetNd(nDigits);
0e986ef9 1659 cluster2.SetLabels(lab);
7f4044f0 1660 }
c391f9d9 1661 y = q = 0.;
1662 nDigits = 0;
7f4044f0 1663 }
c391f9d9 1664
0e986ef9 1665 if (!next || (input->GetModuleID() != prevModule)) {
1666 Int_t iModule = prevModule;
c391f9d9 1667
1668 // when all data from a module was read, search for clusters
1669 if (prevFlag >= 0) {
1670 clusters[iModule] = new TClonesArray("AliITSclusterV2");
1671 fI = iModule;
1672 FindClustersSSD(&clusters1D[0][0], nClusters[0],
1673 &clusters1D[1][0], nClusters[1], clusters[iModule]);
e8f4b841 1674 Int_t noClusters = clusters[iModule]->GetEntriesFast();
1675 nClustersSSD += noClusters;
c391f9d9 1676 }
1677
1678 if (!next) break;
1679 nClusters[0] = nClusters[1] = 0;
1680 y = q = 0.;
1681 nDigits = 0;
7f4044f0 1682 }
c391f9d9 1683
1684 // add digit to current cluster
1685 q += input->GetSignal();
1686 y += strip * input->GetSignal();
1687 nDigits++;
1688 prevStrip = strip;
1689 prevFlag = flag;
0e986ef9 1690 prevModule = input->GetModuleID();
1691
7f4044f0 1692 }
c391f9d9 1693
1694 Info("FindClustersSSD", "found clusters in ITS SSD: %d", nClustersSSD);
7f4044f0 1695}
1696