1 //-------------------------------------------------------------------------
2 // Implementation of the ITS clusterer V2 class
4 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
5 //-------------------------------------------------------------------------
11 #include "AliITSclustererV2.h"
12 #include "AliITSclusterV2.h"
13 #include "AliITSDetTypeRec.h"
14 #include "AliRawReader.h"
15 #include "AliITSRawStreamSPD.h"
16 #include "AliITSRawStreamSDD.h"
17 #include "AliITSRawStreamSSD.h"
21 #include <TClonesArray.h>
22 #include "AliITSgeomTGeo.h"
23 #include "AliITSdigitSPD.h"
24 #include "AliITSdigitSDD.h"
25 #include "AliITSdigitSSD.h"
28 ClassImp(AliITSclustererV2)
30 extern AliRun *gAlice;
32 AliITSclustererV2::AliITSclustererV2():
58 for(Int_t i=0;i<260;i++)fYSPD[i]=0.;
59 for(Int_t i=0;i<170;i++)fZSPD[i]=0.;
60 for(Int_t i=0;i<2200;i++){
68 AliITSclustererV2::AliITSclustererV2(const Char_t *geom):
69 fNModules(AliITSgeomTGeo::GetNModules()),
72 fLastSPD1(AliITSgeomTGeo::GetModuleIndex(2,1,1)-1),
87 fLastSSD1(AliITSgeomTGeo::GetModuleIndex(6,1,1)-1),
93 //------------------------------------------------------------
94 // Standard constructor
95 //------------------------------------------------------------
97 AliWarning("\"geom\" is actually a dummy argument !");
100 for (m=0; m<fNModules; m++) {
101 Int_t lay,lad,det; AliITSgeomTGeo::GetModuleId(m,lay,lad,det);
102 const TGeoHMatrix *tm=AliITSgeomTGeo::GetTracking2LocalMatrix(m);
103 fYshift[m] = (tm->Inverse()).GetTranslation()[1];
104 fZshift[m] = (tm->Inverse()).GetTranslation()[2];
105 fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
110 fYSPD[0]=0.5*fYpitchSPD;
111 for (m=1; m<fNySPD; m++) fYSPD[m]=fYSPD[m-1]+fYpitchSPD;
112 fZSPD[0]=fZ1pitchSPD;
113 for (m=1; m<fNzSPD; m++) {
114 Double_t dz=fZ1pitchSPD;
115 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
116 m==127 || m==128) dz=fZ2pitchSPD;
117 fZSPD[m]=fZSPD[m-1]+dz;
119 for (m=0; m<fNzSPD; m++) {
120 Double_t dz=0.5*fZ1pitchSPD;
121 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
122 m==127 || m==128) dz=0.5*fZ2pitchSPD;
129 Int_t AliITSclustererV2::Digits2Clusters(TTree *dTree, TTree *cTree) {
130 //------------------------------------------------------------
131 // This function creates ITS clusters
132 //------------------------------------------------------------
136 Error("Digits2Clusters","Can't get the tree with digits !");
140 TClonesArray *digitsSPD=new TClonesArray("AliITSdigitSPD",3000);
141 dTree->SetBranchAddress("ITSDigitsSPD",&digitsSPD);
142 TClonesArray *digitsSDD=new TClonesArray("AliITSdigitSDD",3000);
143 dTree->SetBranchAddress("ITSDigitsSDD",&digitsSDD);
144 TClonesArray *digitsSSD=new TClonesArray("AliITSdigitSSD",3000);
145 dTree->SetBranchAddress("ITSDigitsSSD",&digitsSSD);
147 TClonesArray *clusters=new TClonesArray("AliITSclusterV2",1000);
148 TBranch *branch=cTree->GetBranch("Clusters");
149 if (!branch) cTree->Branch("Clusters",&clusters);
150 else branch->SetAddress(&clusters);
152 Int_t mmax=(Int_t)dTree->GetEntries();
153 if (mmax!=fNModules) {
154 Error("Digits2Clusters","Number of entries != number of modules !");
158 for (fI=0; fI<mmax; fI++) {
161 if (digitsSPD->GetEntriesFast()!=0)
162 FindClustersSPD(digitsSPD,clusters);
164 if(digitsSDD->GetEntriesFast()!=0)
165 FindClustersSDD(digitsSDD,clusters);
166 else if(digitsSSD->GetEntriesFast()!=0)
167 FindClustersSSD(digitsSSD,clusters);
169 ncl+=clusters->GetEntriesFast();
189 Info("Digits2Clusters","Number of found clusters : %d",ncl);
194 void AliITSclustererV2::Digits2Clusters(AliRawReader* rawReader) {
195 //------------------------------------------------------------
196 // This function creates ITS clusters from raw data
197 //------------------------------------------------------------
198 AliRunLoader* runLoader = AliRunLoader::Instance();
200 Error("Digits2Clusters", "no run loader found");
203 runLoader->LoadKinematics();
204 AliLoader* itsLoader = runLoader->GetLoader("ITSLoader");
206 Error("Digits2Clusters", "no loader for ITS found");
209 if (!itsLoader->TreeR()) itsLoader->MakeTree("R");
210 TTree* cTree = itsLoader->TreeR();
212 TClonesArray *array=new TClonesArray("AliITSclusterV2",1000);
213 cTree->Branch("Clusters",&array);
216 TClonesArray** clusters = new TClonesArray*[fNModules];
217 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
218 clusters[iModule] = NULL;
220 // one TClonesArray per module
223 AliITSRawStreamSPD inputSPD(rawReader);
224 FindClustersSPD(&inputSPD, clusters);
227 AliITSRawStreamSDD inputSDD(rawReader);
228 FindClustersSDD(&inputSDD, clusters);
231 AliITSRawStreamSSD inputSSD(rawReader);
232 FindClustersSSD(&inputSSD, clusters);
234 // write all clusters to the tree
236 TClonesArray *emptyArray=new TClonesArray("AliITSclusterV2");
237 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
238 array = clusters[iModule];
240 Error("Digits2Clusters", "data for module %d missing!", iModule);
243 cTree->SetBranchAddress("Clusters", &array);
245 nClusters += array->GetEntriesFast();
249 itsLoader->WriteRecPoints("OVERWRITE");
253 Info("Digits2Clusters", "total number of found clusters in ITS: %d\n",
257 //**** Fast clusters *******************************
258 #include "TParticle.h"
260 //#include "AliITS.h"
261 #include "AliITSmodule.h"
262 #include "AliITSRecPoint.h"
263 #include "AliITSsimulationFastPoints.h"
264 #include "AliITSRecPoint.h"
267 static void CheckLabels(Int_t lab[3]) {
268 //------------------------------------------------------------
269 // Tries to find mother's labels
270 //------------------------------------------------------------
271 AliRunLoader *rl = AliRunLoader::Instance();
272 TTree *trK=(TTree*)rl->TreeK();
277 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
279 while (part->P() < 0.005) {
280 Int_t m=part->GetFirstMother();
282 Info("CheckLabels","Primary momentum: %f",part->P());
285 if (part->GetStatusCode()>0) {
286 Info("CheckLabels","Primary momentum: %f",part->P());
290 part=(TParticle*)gAlice->GetMCApp()->Particle(label);
299 // cerr<<"CheckLabels : No empty labels !\n";
306 static void CheckLabels(Int_t lab[3]) {
307 //------------------------------------------------------------
308 // Tries to find mother's labels
309 //------------------------------------------------------------
311 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
313 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
314 for (Int_t i=0;i<3;i++){
315 Int_t label = lab[i];
316 if (label>=0 && label<ntracks) {
317 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
318 if (part->P() < 0.005) {
319 Int_t m=part->GetFirstMother();
323 if (part->GetStatusCode()>0) {
333 static void CheckLabels2(Int_t lab[10]) {
334 //------------------------------------------------------------
335 // Tries to find mother's labels
336 //------------------------------------------------------------
337 AliRunLoader *rl = AliRunLoader::Instance();
338 TTree *trK=(TTree*)rl->TreeK();
342 for (Int_t i=0;i<10;i++) if (lab[i]>=0) nlabels++;
343 if(nlabels == 0) return; // In case of no labels just exit
345 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
347 for (Int_t i=0;i<10;i++){
348 Int_t label = lab[i];
349 if (label>=0 && label<ntracks) {
350 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
351 if (part->P() < 0.02) {
352 Int_t m=part->GetFirstMother();
356 if (part->GetStatusCode()>0) {
362 if (part->P() < 0.12 && nlabels>3) {
368 if ( (label>ntracks||label <0) && nlabels>3) {
375 for (Int_t i=0;i<10;i++){
377 Int_t label = lab[i];
378 if (label>=0 && label<ntracks) {
379 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
380 if (part->P() < 0.1) {
389 //compress labels -- if multi-times the same
391 for (Int_t i=0;i<10;i++) lab2[i]=-2;
392 for (Int_t i=0;i<10 ;i++){
393 if (lab[i]<0) continue;
394 for (Int_t j=0;j<10 &&lab2[j]!=lab[i];j++){
401 for (Int_t j=0;j<10;j++) lab[j]=lab2[j];
405 static void AddLabel(Int_t lab[10], Int_t label) {
406 // add label of the particle in the kine tree which originates this cluster
407 // (used for reconstruction of MC data only, for comparison purposes)
408 AliRunLoader *rl = AliRunLoader::Instance();
409 TTree *trK=(TTree*)rl->TreeK();
412 if(label<0) return; // In case of no label just exit
414 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
415 if (label>ntracks) return;
416 for (Int_t i=0;i<10;i++){
417 // if (label<0) break;
418 if (lab[i]==label) break;
427 void AliITSclustererV2::RecPoints2Clusters
428 (const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
429 //------------------------------------------------------------
430 // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS
431 // subdetector indexed by idx
432 //------------------------------------------------------------
433 TClonesArray &cl=*clusters;
434 Int_t ncl=points->GetEntriesFast();
435 for (Int_t i=0; i<ncl; i++) {
436 AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
438 lp[0]=-(-p->GetDetLocalX()+fYshift[idx]); if (idx<=fLastSPD1) lp[0]*=-1; //SPD1
439 lp[1]= -p->GetZ()+fZshift[idx];
440 lp[2]=p->GetSigmaDetLocX2();
441 lp[3]=p->GetSigmaZ2();
442 lp[4]=p->GetQ()*36./23333.; //electrons -> ADC
444 lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
447 Int_t dummy[3]={0,0,0};
448 new (cl[i]) AliITSclusterV2(lab,lp, dummy);
452 //***********************************
455 void AliITSclustererV2::
456 FindCluster(Int_t k,Int_t maxz,AliBin *bins,Int_t &n,Int_t *idx) {
457 //------------------------------------------------------------
458 // returns an array of indices of digits belonging to the cluster
459 // (needed when the segmentation is not regular)
460 //------------------------------------------------------------
461 if (n<200) idx[n++]=bins[k].GetIndex();
464 if (bins[k-maxz].IsNotUsed()) FindCluster(k-maxz,maxz,bins,n,idx);
465 if (bins[k-1 ].IsNotUsed()) FindCluster(k-1 ,maxz,bins,n,idx);
466 if (bins[k+maxz].IsNotUsed()) FindCluster(k+maxz,maxz,bins,n,idx);
467 if (bins[k+1 ].IsNotUsed()) FindCluster(k+1 ,maxz,bins,n,idx);
469 if (bins[k-maxz-1].IsNotUsed()) FindCluster(k-maxz-1,maxz,bins,n,idx);
470 if (bins[k-maxz+1].IsNotUsed()) FindCluster(k-maxz+1,maxz,bins,n,idx);
471 if (bins[k+maxz-1].IsNotUsed()) FindCluster(k+maxz-1,maxz,bins,n,idx);
472 if (bins[k+maxz+1].IsNotUsed()) FindCluster(k+maxz+1,maxz,bins,n,idx);
476 void AliITSclustererV2::
477 FindClustersSPD(const TClonesArray *digits, TClonesArray *clusters) {
478 //------------------------------------------------------------
479 // Actual SPD cluster finder
480 //------------------------------------------------------------
481 Int_t kNzBins = fNzSPD + 2;
482 const Int_t kMAXBIN=kNzBins*(fNySPD+2);
484 Int_t ndigits=digits->GetEntriesFast();
485 AliBin *bins=new AliBin[kMAXBIN];
489 for (k=0; k<ndigits; k++) {
490 d=(AliITSdigitSPD*)digits->UncheckedAt(k);
491 Int_t i=d->GetCoord2()+1; //y
492 Int_t j=d->GetCoord1()+1;
493 bins[i*kNzBins+j].SetIndex(k);
494 bins[i*kNzBins+j].SetMask(1);
497 Int_t n=0; TClonesArray &cl=*clusters;
498 for (k=0; k<kMAXBIN; k++) {
499 if (!bins[k].IsNotUsed()) continue;
500 Int_t ni=0, idx[200];
501 FindCluster(k,kNzBins,bins,ni,idx);
503 Info("FindClustersSPD","Too big cluster !");
507 for (Int_t ilab=0;ilab<10;ilab++){
511 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[0]);
512 Int_t ymin=d->GetCoord2(),ymax=ymin;
513 Int_t zmin=d->GetCoord1(),zmax=zmin;
515 for (Int_t l=0; l<ni; l++) {
516 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[l]);
518 if (ymin > d->GetCoord2()) ymin=d->GetCoord2();
519 if (ymax < d->GetCoord2()) ymax=d->GetCoord2();
520 if (zmin > d->GetCoord1()) zmin=d->GetCoord1();
521 if (zmax < d->GetCoord1()) zmax=d->GetCoord1();
522 // MI addition - find all labels in cluster
523 for (Int_t dlab=0;dlab<10;dlab++){
524 Int_t digitlab = (d->GetTracks())[dlab];
525 if (digitlab<0) continue;
526 AddLabel(milab,digitlab);
528 if (milab[9]>0) CheckLabels2(milab);
532 //Int_t idy = (fNlayer[fI]==0)? 2:3;
533 //for (Int_t iz=zmin; iz<=zmax;iz+=2)
534 //Int_t idy = (ymax-ymin)/4.; // max 2 clusters
535 Int_t idy = 0; // max 2 clusters
536 if (fNlayer[fI]==0 &&idy<3) idy=3;
537 if (fNlayer[fI]==1 &&idy<4) idy=4;
539 for (Int_t iz=zmin; iz<=zmax;iz+=idz)
540 for (Int_t iy=ymin; iy<=ymax;iy+=idy){
543 Float_t y=0.,z=0.,q=0.;
544 for (Int_t l=0; l<ni; l++) {
545 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[l]);
546 if (zmax-zmin>=idz || ymax-ymin>=idy){
547 if (TMath::Abs( d->GetCoord2()-iy)>0.75*idy) continue;
548 if (TMath::Abs( d->GetCoord1()-iz)>0.75*idz) continue;
551 Float_t qq=d->GetSignal();
552 y+=qq*fYSPD[d->GetCoord2()]; z+=qq*fZSPD[d->GetCoord1()]; q+=qq;
555 if (nodigits==0) continue;
557 y-=fHwSPD; z-=fHlSPD;
560 lp[0]=-(-y+fYshift[fI]); if (fI<=fLastSPD1) lp[0]=-lp[0];
561 lp[1]= -z+fZshift[fI];
562 // Float_t factor=TMath::Max(double(ni-3.),1.5);
563 Float_t factory=TMath::Max(ymax-ymin,1);
564 Float_t factorz=TMath::Max(zmax-zmin,1);
567 //lp[2]= (fYpitchSPD*fYpitchSPD/12.)*factory;
568 //lp[3]= (fZ1pitchSPD*fZ1pitchSPD/12.)*factorz;
569 lp[2]= (fYpitchSPD*fYpitchSPD/12.);
570 lp[3]= (fZ1pitchSPD*fZ1pitchSPD/12.);
572 lp[4]= (zmax-zmin+1)*100 + (ymax-ymin+1);
575 Int_t info[3] = {ymax-ymin+1,zmax-zmin+1,fNlayer[fI]};
576 new (cl[n]) AliITSclusterV2(milab,lp,info); n++;
583 void AliITSclustererV2::FindClustersSPD(AliITSRawStream* input,
584 TClonesArray** clusters)
586 //------------------------------------------------------------
587 // Actual SPD cluster finder for raw data
588 //------------------------------------------------------------
590 Int_t nClustersSPD = 0;
591 Int_t kNzBins = fNzSPD + 2;
592 Int_t kNyBins = fNySPD + 2;
593 Int_t kMaxBin = kNzBins * kNyBins;
594 AliBin *binsSPD = new AliBin[kMaxBin];
595 AliBin *binsSPDInit = new AliBin[kMaxBin];
598 // read raw data input stream
600 Bool_t next = input->Next();
601 if (!next || input->IsNewModule()) {
602 Int_t iModule = input->GetPrevModuleID();
604 // when all data from a module was read, search for clusters
606 clusters[iModule] = new TClonesArray("AliITSclusterV2");
609 for (Int_t iBin = 0; iBin < kMaxBin; iBin++) {
610 if (bins[iBin].IsUsed()) continue;
613 FindCluster(iBin, kNzBins, bins, nBins, idxBins);
615 Error("FindClustersSPD", "SPD: Too big cluster !\n");
623 // label[3] = iModule;
624 label[3] = fNdet[iModule];
626 Int_t ymin = (idxBins[0] / kNzBins) - 1;
628 Int_t zmin = (idxBins[0] % kNzBins) - 1;
630 for (Int_t idx = 0; idx < nBins; idx++) {
631 Int_t iy = (idxBins[idx] / kNzBins) - 1;
632 Int_t iz = (idxBins[idx] % kNzBins) - 1;
633 if (ymin > iy) ymin = iy;
634 if (ymax < iy) ymax = iy;
635 if (zmin > iz) zmin = iz;
636 if (zmax < iz) zmax = iz;
639 Int_t idy = 0; // max 2 clusters
640 if ((iModule <= fLastSPD1) &&idy<3) idy=3;
641 if ((iModule > fLastSPD1) &&idy<4) idy=4;
643 for (Int_t iiz=zmin; iiz<=zmax;iiz+=idz)
644 for (Int_t iiy=ymin; iiy<=ymax;iiy+=idy){
647 Float_t y=0.,z=0.,q=0.;
648 for (Int_t idx = 0; idx < nBins; idx++) {
649 Int_t iy = (idxBins[idx] / kNzBins) - 1;
650 Int_t iz = (idxBins[idx] % kNzBins) - 1;
651 if (zmax-zmin>=idz || ymax-ymin>=idy){
652 if (TMath::Abs(iy-iiy)>0.75*idy) continue;
653 if (TMath::Abs(iz-iiz)>0.75*idz) continue;
656 Float_t qBin = bins[idxBins[idx]].GetQ();
657 y += qBin * fYSPD[iy];
658 z += qBin * fZSPD[iz];
661 if (ndigits==0) continue;
667 Float_t hit[5]; // y, z, sigma(y)^2, sigma(z)^2, charge
668 hit[0] = -(-y+fYshift[iModule]);
669 if (iModule <= fLastSPD1) hit[0] = -hit[0];
670 hit[1] = -z+fZshift[iModule];
671 hit[2] = fYpitchSPD*fYpitchSPD/12.;
672 hit[3] = fZ1pitchSPD*fZ1pitchSPD/12.;
674 hit[4] = (zmax-zmin+1)*100 + (ymax-ymin+1);
675 // CheckLabels(label);
676 Int_t info[3]={ymax-ymin+1,zmax-zmin+1,fNlayer[iModule]};
677 new (clusters[iModule]->AddrAt(nClusters))
678 AliITSclusterV2(label, hit,info);
683 nClustersSPD += nClusters;
689 memcpy(binsSPD,binsSPDInit,sizeof(AliBin)*kMaxBin);
692 // fill the current digit into the bins array
694 Int_t index = (input->GetCoord2()+1) * kNzBins + (input->GetCoord1()+1);
695 bins[index].SetIndex(index);
696 bins[index].SetMask(1);
701 delete [] binsSPDInit;
704 Info("FindClustersSPD", "found clusters in ITS SPD: %d", nClustersSPD);
708 Bool_t AliITSclustererV2::IsMaximum(Int_t k,Int_t max,const AliBin *bins) {
709 //------------------------------------------------------------
710 //is this a local maximum ?
711 //------------------------------------------------------------
712 UShort_t q=bins[k].GetQ();
713 if (q==1023) return kFALSE;
714 if (bins[k-max].GetQ() > q) return kFALSE;
715 if (bins[k-1 ].GetQ() > q) return kFALSE;
716 if (bins[k+max].GetQ() > q) return kFALSE;
717 if (bins[k+1 ].GetQ() > q) return kFALSE;
718 if (bins[k-max-1].GetQ() > q) return kFALSE;
719 if (bins[k+max-1].GetQ() > q) return kFALSE;
720 if (bins[k+max+1].GetQ() > q) return kFALSE;
721 if (bins[k-max+1].GetQ() > q) return kFALSE;
725 void AliITSclustererV2::
726 FindPeaks(Int_t k,Int_t max,AliBin *b,Int_t *idx,UInt_t *msk,Int_t& n) {
727 //------------------------------------------------------------
729 //------------------------------------------------------------
731 if (IsMaximum(k,max,b)) {
732 idx[n]=k; msk[n]=(2<<n);
736 if (b[k-max].GetMask()&1) FindPeaks(k-max,max,b,idx,msk,n);
737 if (b[k-1 ].GetMask()&1) FindPeaks(k-1 ,max,b,idx,msk,n);
738 if (b[k+max].GetMask()&1) FindPeaks(k+max,max,b,idx,msk,n);
739 if (b[k+1 ].GetMask()&1) FindPeaks(k+1 ,max,b,idx,msk,n);
742 void AliITSclustererV2::
743 MarkPeak(Int_t k, Int_t max, AliBin *bins, UInt_t m) {
744 //------------------------------------------------------------
746 //------------------------------------------------------------
747 UShort_t q=bins[k].GetQ();
749 bins[k].SetMask(bins[k].GetMask()|m);
751 if (bins[k-max].GetQ() <= q)
752 if ((bins[k-max].GetMask()&m) == 0) MarkPeak(k-max,max,bins,m);
753 if (bins[k-1 ].GetQ() <= q)
754 if ((bins[k-1 ].GetMask()&m) == 0) MarkPeak(k-1 ,max,bins,m);
755 if (bins[k+max].GetQ() <= q)
756 if ((bins[k+max].GetMask()&m) == 0) MarkPeak(k+max,max,bins,m);
757 if (bins[k+1 ].GetQ() <= q)
758 if ((bins[k+1 ].GetMask()&m) == 0) MarkPeak(k+1 ,max,bins,m);
761 void AliITSclustererV2::
762 MakeCluster(Int_t k,Int_t max,AliBin *bins,UInt_t m,AliITSclusterV2 &c) {
763 //------------------------------------------------------------
764 //make cluster using digits of this peak
765 //------------------------------------------------------------
766 Float_t q=(Float_t)bins[k].GetQ();
767 Int_t i=k/max, j=k-i*max;
770 c.SetY(c.GetY()+i*q);
771 c.SetZ(c.GetZ()+j*q);
772 c.SetSigmaY2(c.GetSigmaY2()+i*i*q);
773 c.SetSigmaZ2(c.GetSigmaZ2()+j*j*q);
775 bins[k].SetMask(0xFFFFFFFE);
777 if (bins[k-max].GetMask() == m) MakeCluster(k-max,max,bins,m,c);
778 if (bins[k-1 ].GetMask() == m) MakeCluster(k-1 ,max,bins,m,c);
779 if (bins[k+max].GetMask() == m) MakeCluster(k+max,max,bins,m,c);
780 if (bins[k+1 ].GetMask() == m) MakeCluster(k+1 ,max,bins,m,c);
783 void AliITSclustererV2::
784 FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
785 const TClonesArray *digits, TClonesArray *clusters) {
786 //------------------------------------------------------------
787 // Actual SDD cluster finder
788 //------------------------------------------------------------
789 Int_t ncl=0; TClonesArray &cl=*clusters;
790 for (Int_t s=0; s<2; s++)
791 for (Int_t i=0; i<nMaxBin; i++) {
792 if (bins[s][i].IsUsed()) continue;
793 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
794 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
796 if (npeaks>30) continue;
797 if (npeaks==0) continue;
800 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
801 if (idx[k] < 0) continue; //this peak is already removed
802 for (l=k+1; l<npeaks; l++) {
803 if (idx[l] < 0) continue; //this peak is already removed
804 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
805 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
806 Int_t di=TMath::Abs(ki - li);
807 Int_t dj=TMath::Abs(kj - lj);
808 if (di>1 || dj>1) continue;
809 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
820 for (k=0; k<npeaks; k++) {
821 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
824 for (k=0; k<npeaks; k++) {
825 if (idx[k] < 0) continue; //removed peak
827 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
830 for (Int_t ilab=0;ilab<10;ilab++){
833 Int_t maxi=0,mini=0,maxj=0,minj=0;
834 //AliBin *bmax=&bins[s][idx[k]];
835 //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
837 for (Int_t di=-2; di<=2;di++)
838 for (Int_t dj=-3;dj<=3;dj++){
839 Int_t index = idx[k]+di+dj*nzBins;
840 if (index<0) continue;
841 if (index>=nMaxBin) continue;
842 AliBin *b=&bins[s][index];
843 if (TMath::Abs(b->GetQ())>max){
844 if (di>maxi) maxi=di;
845 if (di<mini) mini=di;
846 if (dj>maxj) maxj=dj;
847 if (dj<minj) minj=dj;
850 if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
851 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
852 for (Int_t itrack=0;itrack<10;itrack++){
853 Int_t track = (d->GetTracks())[itrack];
855 AddLabel(milab, track);
864 Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
865 Float_t w=par->GetPadPitchWidth(sec);
868 c.SetSigmaY2(c.GetSigmaY2()*0.108);
869 if (sec<par->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
871 s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
876 c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
877 if (sec<par->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
881 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
884 //Float_t s2 = c.GetSigmaY2()/c.GetQ() - y*y;
886 //s2 = c.GetSigmaZ2()/c.GetQ() - z*z;
889 y=(y-0.5)*fYpitchSDD;
891 y-=fYoffSDD; //delay ?
894 z=(z-0.5)*fZpitchSDD;
900 q/=12.7; //this WAS consistent with SSD. To be reassessed
902 Float_t hit[5] = {y, z, 0.0030*0.0030, 0.0020*0.0020, q};
903 Int_t info[3] = {maxj-minj+1, maxi-mini+1, fNlayer[fI]};
905 if (c.GetQ() < 20.) continue; //noise cluster
908 // AliBin *b=&bins[s][idx[k]];
909 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
912 //lab[0]=(d->GetTracks())[0];
913 //lab[1]=(d->GetTracks())[1];
914 //lab[2]=(d->GetTracks())[2];
921 AliITSclusterV2 *cc = new (cl[ncl]) AliITSclusterV2(milab,hit,info);
928 void AliITSclustererV2::
929 FindClustersSDD(const TClonesArray *digits, TClonesArray *clusters) {
930 //------------------------------------------------------------
931 // Actual SDD cluster finder
932 //------------------------------------------------------------
933 Int_t kNzBins = fNzSDD + 2;
934 const Int_t kMAXBIN=kNzBins*(fNySDD+2);
937 bins[0]=new AliBin[kMAXBIN];
938 bins[1]=new AliBin[kMAXBIN];
941 Int_t i, ndigits=digits->GetEntriesFast();
942 for (i=0; i<ndigits; i++) {
943 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
944 Int_t y=d->GetCoord2()+1; //y
945 Int_t z=d->GetCoord1()+1; //z
946 Int_t q=d->GetSignal();
950 bins[0][y*kNzBins+z].SetQ(q);
951 bins[0][y*kNzBins+z].SetMask(1);
952 bins[0][y*kNzBins+z].SetIndex(i);
955 bins[1][y*kNzBins+z].SetQ(q);
956 bins[1][y*kNzBins+z].SetMask(1);
957 bins[1][y*kNzBins+z].SetIndex(i);
961 FindClustersSDD(bins, kMAXBIN, kNzBins, digits, clusters);
968 void AliITSclustererV2::FindClustersSDD(AliITSRawStream* input,
969 TClonesArray** clusters)
971 //------------------------------------------------------------
972 // Actual SDD cluster finder for raw data
973 //------------------------------------------------------------
974 Int_t nClustersSDD = 0;
975 Int_t kNzBins = fNzSDD + 2;
976 Int_t kMaxBin = kNzBins * (fNySDD+2);
977 AliBin *binsSDDInit = new AliBin[kMaxBin];
978 AliBin *binsSDD1 = new AliBin[kMaxBin];
979 AliBin *binsSDD2 = new AliBin[kMaxBin];
980 AliBin *bins[2] = {NULL, NULL};
982 // read raw data input stream
984 Bool_t next = input->Next();
985 if (!next || input->IsNewModule()) {
986 Int_t iModule = input->GetPrevModuleID();
988 // when all data from a module was read, search for clusters
990 clusters[iModule] = new TClonesArray("AliITSclusterV2");
992 FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
993 Int_t nClusters = clusters[iModule]->GetEntriesFast();
994 nClustersSDD += nClusters;
995 bins[0] = bins[1] = NULL;
1001 memcpy(binsSDD1,binsSDDInit,sizeof(AliBin)*kMaxBin);
1002 memcpy(binsSDD2,binsSDDInit,sizeof(AliBin)*kMaxBin);
1005 // fill the current digit into the bins array
1006 if(input->GetSignal()>=3) {
1007 Int_t iz = input->GetCoord1()+1;
1008 Int_t side = ((iz <= fNzSDD) ? 0 : 1);
1010 Int_t index = (input->GetCoord2()+1) * kNzBins + iz;
1011 bins[side][index].SetQ(input->GetSignal());
1012 bins[side][index].SetMask(1);
1013 bins[side][index].SetIndex(index);
1019 delete[] binsSDDInit;
1021 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
1026 void AliITSclustererV2::
1027 FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
1028 Ali1Dcluster* pos, Int_t np,
1029 TClonesArray *clusters) {
1030 //------------------------------------------------------------
1031 // Actual SSD cluster finder
1032 //------------------------------------------------------------
1033 TClonesArray &cl=*clusters;
1035 Float_t tanp=fTanP, tann=fTanN;
1036 if (fI>fLastSSD1) {tann=fTanP; tanp=fTanN;}
1037 Int_t idet=fNdet[fI];
1040 Int_t negativepair[30000];
1041 Int_t cnegative[3000];
1043 Int_t positivepair[30000];
1044 Int_t cpositive[3000];
1046 for (Int_t i=0;i<3000;i++) {cnegative[i]=0; cused1[i]=0;}
1047 for (Int_t i=0;i<3000;i++) {cpositive[i]=0; cused2[i]=0;}
1048 for (Int_t i=0;i<30000;i++){negativepair[i]=positivepair[i]=0;}
1049 static Short_t pairs[1000][1000];
1050 memset(pairs,0,sizeof(Short_t)*1000000);
1051 // Short_t ** pairs = new Short_t*[1000];
1052 // for (Int_t i=0; i<1000; i++) {
1053 // pairs[i] = new Short_t[1000];
1054 // memset(pairs[i],0,sizeof(Short_t)*1000);
1057 // find available pairs
1059 for (Int_t i=0; i<np; i++) {
1060 Float_t yp=pos[i].GetY()*fYpitchSSD;
1061 if (pos[i].GetQ()<3) continue;
1062 for (Int_t j=0; j<nn; j++) {
1063 if (neg[j].GetQ()<3) continue;
1064 Float_t yn=neg[j].GetY()*fYpitchSSD;
1065 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1066 Float_t yt=yn + tann*zt;
1067 zt-=fHlSSD; yt-=fHwSSD;
1068 if (TMath::Abs(yt)<fHwSSD+0.01)
1069 if (TMath::Abs(zt)<fHlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
1070 negativepair[i*10+cnegative[i]] =j; //index
1071 positivepair[j*10+cpositive[j]] =i;
1072 cnegative[i]++; //counters
1079 for (Int_t i=0; i<np; i++) {
1080 Float_t yp=pos[i].GetY()*fYpitchSSD;
1081 if (pos[i].GetQ()<3) continue;
1082 for (Int_t j=0; j<nn; j++) {
1083 if (neg[j].GetQ()<3) continue;
1084 if (cpositive[j]&&cnegative[i]) continue;
1085 Float_t yn=neg[j].GetY()*fYpitchSSD;
1086 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1087 Float_t yt=yn + tann*zt;
1088 zt-=fHlSSD; yt-=fHwSSD;
1089 if (TMath::Abs(yt)<fHwSSD+0.1)
1090 if (TMath::Abs(zt)<fHlSSD+0.15) {
1091 if (cnegative[i]==0) pos[i].SetNd(100); // not available pair
1092 if (cpositive[j]==0) neg[j].SetNd(100); // not available pair
1093 negativepair[i*10+cnegative[i]] =j; //index
1094 positivepair[j*10+cpositive[j]] =i;
1095 cnegative[i]++; //counters
1109 for (Int_t ip=0;ip<np;ip++){
1110 Float_t ybest=1000,zbest=1000,qbest=0;
1112 // select gold clusters
1113 if ( (cnegative[ip]==1) && cpositive[negativepair[10*ip]]==1){
1114 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1115 Int_t j = negativepair[10*ip];
1116 ratio = (pos[ip].GetQ()-neg[j].GetQ())/(pos[ip].GetQ()+neg[j].GetQ());
1118 Float_t yn=neg[j].GetY()*fYpitchSSD;
1119 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1120 Float_t yt=yn + tann*zt;
1121 zt-=fHlSSD; yt-=fHwSSD;
1123 qbest=0.5*(pos[ip].GetQ()+neg[j].GetQ());
1124 lp[0]=-(-ybest+fYshift[fI]);
1125 lp[1]= -zbest+fZshift[fI];
1126 lp[2]=0.0025*0.0025; //SigmaY2
1127 lp[3]=0.110*0.110; //SigmaZ2
1130 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1131 for (Int_t ilab=0;ilab<3;ilab++){
1132 milab[ilab] = pos[ip].GetLabel(ilab);
1133 milab[ilab+3] = neg[j].GetLabel(ilab);
1136 CheckLabels2(milab);
1137 milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
1138 Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1139 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1141 cl2->SetChargeRatio(ratio);
1144 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1153 for (Int_t ip=0;ip<np;ip++){
1154 Float_t ybest=1000,zbest=1000,qbest=0;
1157 // select "silber" cluster
1158 if ( cnegative[ip]==1 && cpositive[negativepair[10*ip]]==2){
1159 Int_t in = negativepair[10*ip];
1160 Int_t ip2 = positivepair[10*in];
1161 if (ip2==ip) ip2 = positivepair[10*in+1];
1162 Float_t pcharge = pos[ip].GetQ()+pos[ip2].GetQ();
1163 if (TMath::Abs(pcharge-neg[in].GetQ())<10){
1166 if (pairs[ip][in]==100){ //
1167 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1168 Float_t yn=neg[in].GetY()*fYpitchSSD;
1169 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1170 Float_t yt=yn + tann*zt;
1171 zt-=fHlSSD; yt-=fHwSSD;
1172 ybest =yt; zbest=zt;
1173 qbest =pos[ip].GetQ();
1174 lp[0]=-(-ybest+fYshift[fI]);
1175 lp[1]= -zbest+fZshift[fI];
1176 lp[2]=0.0025*0.0025; //SigmaY2
1177 lp[3]=0.110*0.110; //SigmaZ2
1180 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1181 for (Int_t ilab=0;ilab<3;ilab++){
1182 milab[ilab] = pos[ip].GetLabel(ilab);
1183 milab[ilab+3] = neg[in].GetLabel(ilab);
1186 CheckLabels2(milab);
1187 ratio = (pos[ip].GetQ()-neg[in].GetQ())/(pos[ip].GetQ()+neg[in].GetQ());
1188 milab[3]=(((ip<<10) + in)<<10) + idet; // pos|neg|det
1189 Int_t info[3] = {pos[ip].GetNd(),neg[in].GetNd(),fNlayer[fI]};
1190 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1192 cl2->SetChargeRatio(ratio);
1195 if ((pos[ip].GetNd()+neg[in].GetNd())>6){ //multi cluster
1203 // if (!(cused1[ip2] || cused2[in])){ //
1204 if (pairs[ip2][in]==100){
1205 Float_t yp=pos[ip2].GetY()*fYpitchSSD;
1206 Float_t yn=neg[in].GetY()*fYpitchSSD;
1207 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1208 Float_t yt=yn + tann*zt;
1209 zt-=fHlSSD; yt-=fHwSSD;
1210 ybest =yt; zbest=zt;
1211 qbest =pos[ip2].GetQ();
1212 lp[0]=-(-ybest+fYshift[fI]);
1213 lp[1]= -zbest+fZshift[fI];
1214 lp[2]=0.0025*0.0025; //SigmaY2
1215 lp[3]=0.110*0.110; //SigmaZ2
1218 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1219 for (Int_t ilab=0;ilab<3;ilab++){
1220 milab[ilab] = pos[ip2].GetLabel(ilab);
1221 milab[ilab+3] = neg[in].GetLabel(ilab);
1224 CheckLabels2(milab);
1225 ratio = (pos[ip2].GetQ()-neg[in].GetQ())/(pos[ip2].GetQ()+neg[in].GetQ());
1226 milab[3]=(((ip2<<10) + in)<<10) + idet; // pos|neg|det
1227 Int_t info[3] = {pos[ip2].GetNd(),neg[in].GetNd(),fNlayer[fI]};
1228 AliITSclusterV2 *cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1230 cl2->SetChargeRatio(ratio);
1233 if ((pos[ip2].GetNd()+neg[in].GetNd())>6){ //multi cluster
1246 for (Int_t jn=0;jn<nn;jn++){
1247 if (cused2[jn]) continue;
1248 Float_t ybest=1000,zbest=1000,qbest=0;
1249 // select "silber" cluster
1250 if ( cpositive[jn]==1 && cnegative[positivepair[10*jn]]==2){
1251 Int_t ip = positivepair[10*jn];
1252 Int_t jn2 = negativepair[10*ip];
1253 if (jn2==jn) jn2 = negativepair[10*ip+1];
1254 Float_t pcharge = neg[jn].GetQ()+neg[jn2].GetQ();
1256 if (TMath::Abs(pcharge-pos[ip].GetQ())<10){
1259 // if (!(cused1[ip]||cused2[jn])){
1260 if (pairs[ip][jn]==100){
1261 Float_t yn=neg[jn].GetY()*fYpitchSSD;
1262 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1263 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1264 Float_t yt=yn + tann*zt;
1265 zt-=fHlSSD; yt-=fHwSSD;
1266 ybest =yt; zbest=zt;
1267 qbest =neg[jn].GetQ();
1268 lp[0]=-(-ybest+fYshift[fI]);
1269 lp[1]= -zbest+fZshift[fI];
1270 lp[2]=0.0025*0.0025; //SigmaY2
1271 lp[3]=0.110*0.110; //SigmaZ2
1274 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1275 for (Int_t ilab=0;ilab<3;ilab++){
1276 milab[ilab] = pos[ip].GetLabel(ilab);
1277 milab[ilab+3] = neg[jn].GetLabel(ilab);
1280 CheckLabels2(milab);
1281 ratio = (pos[ip].GetQ()-neg[jn].GetQ())/(pos[ip].GetQ()+neg[jn].GetQ());
1282 milab[3]=(((ip<<10) + jn)<<10) + idet; // pos|neg|det
1283 Int_t info[3] = {pos[ip].GetNd(),neg[jn].GetNd(),fNlayer[fI]};
1284 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1286 cl2->SetChargeRatio(ratio);
1289 if ((pos[ip].GetNd()+neg[jn].GetNd())>6){ //multi cluster
1296 // if (!(cused1[ip]||cused2[jn2])){
1297 if (pairs[ip][jn2]==100){
1298 Float_t yn=neg[jn2].GetY()*fYpitchSSD;
1299 Double_t yp=pos[ip].GetY()*fYpitchSSD;
1300 Double_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1301 Double_t yt=yn + tann*zt;
1302 zt-=fHlSSD; yt-=fHwSSD;
1303 ybest =yt; zbest=zt;
1304 qbest =neg[jn2].GetQ();
1305 lp[0]=-(-ybest+fYshift[fI]);
1306 lp[1]= -zbest+fZshift[fI];
1307 lp[2]=0.0025*0.0025; //SigmaY2
1308 lp[3]=0.110*0.110; //SigmaZ2
1311 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1312 for (Int_t ilab=0;ilab<3;ilab++){
1313 milab[ilab] = pos[ip].GetLabel(ilab);
1314 milab[ilab+3] = neg[jn2].GetLabel(ilab);
1317 CheckLabels2(milab);
1318 ratio = (pos[ip].GetQ()-neg[jn2].GetQ())/(pos[ip].GetQ()+neg[jn2].GetQ());
1319 milab[3]=(((ip<<10) + jn2)<<10) + idet; // pos|neg|det
1320 Int_t info[3] = {pos[ip].GetNd(),neg[jn2].GetNd(),fNlayer[fI]};
1321 AliITSclusterV2* cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1323 cl2->SetChargeRatio(ratio);
1326 if ((pos[ip].GetNd()+neg[jn2].GetNd())>6){ //multi cluster
1338 for (Int_t ip=0;ip<np;ip++){
1339 Float_t ybest=1000,zbest=1000,qbest=0;
1343 if ( (cnegative[ip]<5) && cpositive[negativepair[10*ip]]<5){
1344 Float_t minchargediff =4.;
1346 for (Int_t di=0;di<cnegative[ip];di++){
1347 Int_t jc = negativepair[ip*10+di];
1348 Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1349 if (TMath::Abs(chargedif)<minchargediff){
1351 minchargediff = TMath::Abs(chargedif);
1354 if (j<0) continue; // not proper cluster
1356 for (Int_t di=0;di<cnegative[ip];di++){
1357 Int_t jc = negativepair[ip*10+di];
1358 Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1359 if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1361 if (count>1) continue; // more than one "proper" cluster for positive
1364 for (Int_t dj=0;dj<cpositive[j];dj++){
1365 Int_t ic = positivepair[j*10+dj];
1366 Float_t chargedif = pos[ic].GetQ()-neg[j].GetQ();
1367 if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1369 if (count>1) continue; // more than one "proper" cluster for negative
1374 for (Int_t dj=0;dj<cnegative[jp];dj++){
1375 Int_t ic = positivepair[jp*10+dj];
1376 Float_t chargedif = pos[ic].GetQ()-neg[jp].GetQ();
1377 if (TMath::Abs(chargedif)<minchargediff+4.) count++;
1379 if (count>1) continue;
1380 if (pairs[ip][j]<100) continue;
1382 //almost gold clusters
1383 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1384 Float_t yn=neg[j].GetY()*fYpitchSSD;
1385 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1386 Float_t yt=yn + tann*zt;
1387 zt-=fHlSSD; yt-=fHwSSD;
1389 qbest=0.5*(pos[ip].GetQ()+neg[j].GetQ());
1390 lp[0]=-(-ybest+fYshift[fI]);
1391 lp[1]= -zbest+fZshift[fI];
1392 lp[2]=0.0025*0.0025; //SigmaY2
1393 lp[3]=0.110*0.110; //SigmaZ2
1395 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1396 for (Int_t ilab=0;ilab<3;ilab++){
1397 milab[ilab] = pos[ip].GetLabel(ilab);
1398 milab[ilab+3] = neg[j].GetLabel(ilab);
1401 CheckLabels2(milab);
1402 ratio = (pos[ip].GetQ()-neg[j].GetQ())/(pos[ip].GetQ()+neg[j].GetQ());
1403 milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
1404 Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1405 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1407 cl2->SetChargeRatio(ratio);
1410 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1421 for (Int_t i=0; i<np; i++) {
1422 Float_t ybest=1000,zbest=1000,qbest=0;
1423 Float_t yp=pos[i].GetY()*fYpitchSSD;
1424 if (pos[i].GetQ()<3) continue;
1425 for (Int_t j=0; j<nn; j++) {
1426 // for (Int_t di = 0;di<cpositive[i];di++){
1427 // Int_t j = negativepair[10*i+di];
1428 if (neg[j].GetQ()<3) continue;
1429 if (cused2[j]||cused1[i]) continue;
1430 if (pairs[i][j]>0 &&pairs[i][j]<100) continue;
1431 ratio = (pos[i].GetQ()-neg[j].GetQ())/(pos[i].GetQ()+neg[j].GetQ());
1432 Float_t yn=neg[j].GetY()*fYpitchSSD;
1433 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1434 Float_t yt=yn + tann*zt;
1435 zt-=fHlSSD; yt-=fHwSSD;
1436 if (TMath::Abs(yt)<fHwSSD+0.01)
1437 if (TMath::Abs(zt)<fHlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
1439 qbest=0.5*(pos[i].GetQ()+neg[j].GetQ());
1440 lp[0]=-(-ybest+fYshift[fI]);
1441 lp[1]= -zbest+fZshift[fI];
1442 lp[2]=0.0025*0.0025; //SigmaY2
1443 lp[3]=0.110*0.110; //SigmaZ2
1446 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1447 for (Int_t ilab=0;ilab<3;ilab++){
1448 milab[ilab] = pos[i].GetLabel(ilab);
1449 milab[ilab+3] = neg[j].GetLabel(ilab);
1452 CheckLabels2(milab);
1453 milab[3]=(((i<<10) + j)<<10) + idet; // pos|neg|det
1454 Int_t info[3] = {pos[i].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1455 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1457 cl2->SetChargeRatio(ratio);
1458 cl2->SetType(100+cpositive[j]+cnegative[i]);
1461 if (pairs[i][j]<100){
1462 printf("problem:- %d\n", pairs[i][j]);
1464 if (cnegative[i]<2&&cpositive[j]<2){
1465 printf("problem:- %d\n", pairs[i][j]);
1472 // for (Int_t i=0; i<1000; i++) delete [] pairs[i];
1478 void AliITSclustererV2::
1479 FindClustersSSD(const TClonesArray *alldigits, TClonesArray *clusters) {
1480 //------------------------------------------------------------
1481 // Actual SSD cluster finder
1482 //------------------------------------------------------------
1483 Int_t smaxall=alldigits->GetEntriesFast();
1484 if (smaxall==0) return;
1485 TObjArray *digits = new TObjArray;
1486 for (Int_t i=0;i<smaxall; i++){
1487 AliITSdigitSSD *d=(AliITSdigitSSD*)alldigits->UncheckedAt(i);
1488 if (d->GetSignal()<3) continue;
1491 Int_t smax = digits->GetEntriesFast();
1492 if (smax==0) return;
1494 const Int_t MAX=1000;
1496 Ali1Dcluster pos[MAX], neg[MAX];
1497 Float_t y=0., q=0., qmax=0.;
1498 Int_t lab[4]={-2,-2,-2,-2};
1500 AliITSdigitSSD *d=(AliITSdigitSSD*)digits->UncheckedAt(0);
1501 q += d->GetSignal();
1502 y += d->GetCoord2()*d->GetSignal();
1503 qmax=d->GetSignal();
1504 lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
1505 Int_t curr=d->GetCoord2();
1506 Int_t flag=d->GetCoord1();
1508 Ali1Dcluster *c=neg;
1511 for (Int_t ilab=0;ilab<10;ilab++){
1514 milab[0]=d->GetTrack(0); milab[1]=d->GetTrack(1); milab[2]=d->GetTrack(2);
1516 for (Int_t s=1; s<smax; s++) {
1517 d=(AliITSdigitSSD*)digits->UncheckedAt(s);
1518 Int_t strip=d->GetCoord2();
1519 if ((strip-curr) > 1 || flag!=d->GetCoord1()) {
1523 CheckLabels2(milab);
1524 c[*n].SetLabels(milab);
1525 //Split suspiciously big cluster
1528 c[*n].SetY(y/q-0.3*nd);
1532 Error("FindClustersSSD","Too many 1D clusters !");
1535 c[*n].SetY(y/q-0.0*nd);
1540 Error("FindClustersSSD","Too many 1D clusters !");
1544 c[*n].SetY(y/q+0.3*nd);
1547 c[*n].SetLabels(milab);
1552 c[*n].SetY(y/q-0.25*nd);
1556 Error("FindClustersSSD","Too many 1D clusters !");
1559 c[*n].SetY(y/q+0.25*nd);
1562 c[*n].SetLabels(milab);
1566 Error("FindClustersSSD","Too many 1D clusters !");
1571 lab[0]=lab[1]=lab[2]=-2;
1573 for (Int_t ilab=0;ilab<10;ilab++){
1577 if (flag!=d->GetCoord1()) { n=&np; c=pos; }
1579 flag=d->GetCoord1();
1580 q += d->GetSignal();
1581 y += d->GetCoord2()*d->GetSignal();
1583 if (d->GetSignal()>qmax) {
1584 qmax=d->GetSignal();
1585 lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
1587 for (Int_t ilab=0;ilab<10;ilab++) {
1588 if (d->GetTrack(ilab)>=0) AddLabel(milab, (d->GetTrack(ilab)));
1595 c[*n].SetLabels(lab);
1596 //Split suspiciously big cluster
1597 if (nd>4 && nd<25) {
1598 c[*n].SetY(y/q-0.25*nd);
1602 Error("FindClustersSSD","Too many 1D clusters !");
1605 c[*n].SetY(y/q+0.25*nd);
1608 c[*n].SetLabels(lab);
1612 Error("FindClustersSSD","Too many 1D clusters !");
1616 FindClustersSSD(neg, nn, pos, np, clusters);
1619 void AliITSclustererV2::FindClustersSSD(AliITSRawStream* input,
1620 TClonesArray** clusters)
1622 //------------------------------------------------------------
1623 // Actual SSD cluster finder for raw data
1624 //------------------------------------------------------------
1625 Int_t nClustersSSD = 0;
1626 const Int_t MAX = 1000;
1627 Ali1Dcluster clusters1D[2][MAX];
1628 Int_t nClusters[2] = {0, 0};
1629 Int_t lab[3]={-2,-2,-2};
1633 Int_t prevStrip = -1;
1634 Int_t prevFlag = -1;
1635 Int_t prevModule = -1;
1637 // read raw data input stream
1639 Bool_t next = input->Next();
1641 if(input->GetSignal()<3 && next) continue;
1642 // check if a new cluster starts
1643 Int_t strip = input->GetCoord2();
1644 Int_t flag = input->GetCoord1();
1645 if ((!next || (input->GetModuleID() != prevModule)||
1646 (strip-prevStrip > 1) || (flag != prevFlag)) &&
1648 if (nClusters[prevFlag] == MAX) {
1649 Error("FindClustersSSD", "Too many 1D clusters !");
1652 Ali1Dcluster& cluster = clusters1D[prevFlag][nClusters[prevFlag]++];
1655 cluster.SetNd(nDigits);
1656 cluster.SetLabels(lab);
1658 //Split suspiciously big cluster
1659 if (nDigits > 4&&nDigits < 25) {
1660 cluster.SetY(y/q - 0.25*nDigits);
1661 cluster.SetQ(0.5*q);
1662 if (nClusters[prevFlag] == MAX) {
1663 Error("FindClustersSSD", "Too many 1D clusters !");
1666 Ali1Dcluster& cluster2 = clusters1D[prevFlag][nClusters[prevFlag]++];
1667 cluster2.SetY(y/q + 0.25*nDigits);
1668 cluster2.SetQ(0.5*q);
1669 cluster2.SetNd(nDigits);
1670 cluster2.SetLabels(lab);
1676 if (!next || (input->GetModuleID() != prevModule)) {
1677 Int_t iModule = prevModule;
1679 // when all data from a module was read, search for clusters
1680 if (prevFlag >= 0) {
1681 clusters[iModule] = new TClonesArray("AliITSclusterV2");
1683 FindClustersSSD(&clusters1D[0][0], nClusters[0],
1684 &clusters1D[1][0], nClusters[1], clusters[iModule]);
1685 Int_t noClusters = clusters[iModule]->GetEntriesFast();
1686 nClustersSSD += noClusters;
1690 nClusters[0] = nClusters[1] = 0;
1695 // add digit to current cluster
1696 q += input->GetSignal();
1697 y += strip * input->GetSignal();
1701 prevModule = input->GetModuleID();
1705 Info("FindClustersSSD", "found clusters in ITS SSD: %d", nClustersSSD);