1 //-------------------------------------------------------------------------
2 // Implementation of the ITS clusterer V2 class
4 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
5 //-------------------------------------------------------------------------
10 #include "AliITSclustererV2.h"
11 #include "AliITSclusterV2.h"
12 #include "AliITSDetTypeRec.h"
13 #include "AliRawReader.h"
14 #include "AliITSRawStreamSPD.h"
15 #include "AliITSRawStreamSDD.h"
16 #include "AliITSRawStreamSSD.h"
20 #include <TClonesArray.h>
21 #include "AliITSgeomTGeo.h"
22 #include "AliITSdigitSPD.h"
23 #include "AliITSdigitSDD.h"
24 #include "AliITSdigitSSD.h"
27 ClassImp(AliITSclustererV2)
29 extern AliRun *gAlice;
31 AliITSclustererV2::AliITSclustererV2():
58 AliITSclustererV2::AliITSclustererV2(const Char_t *geom):
59 fNModules(AliITSgeomTGeo::GetNModules()),
62 fLastSPD1(AliITSgeomTGeo::GetModuleIndex(2,1,1)-1),
77 fLastSSD1(AliITSgeomTGeo::GetModuleIndex(6,1,1)-1),
83 //------------------------------------------------------------
84 // Standard constructor
85 //------------------------------------------------------------
87 AliWarning("\"geom\" is actually a dummy argument !");
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);
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;
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;
119 Int_t AliITSclustererV2::Digits2Clusters(TTree *dTree, TTree *cTree) {
120 //------------------------------------------------------------
121 // This function creates ITS clusters
122 //------------------------------------------------------------
126 Error("Digits2Clusters","Can't get the tree with digits !");
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);
137 TClonesArray *clusters=new TClonesArray("AliITSclusterV2",1000);
138 TBranch *branch=cTree->GetBranch("Clusters");
139 if (!branch) cTree->Branch("Clusters",&clusters);
140 else branch->SetAddress(&clusters);
142 Int_t mmax=(Int_t)dTree->GetEntries();
143 if (mmax!=fNModules) {
144 Error("Digits2Clusters","Number of entries != number of modules !");
148 for (fI=0; fI<mmax; fI++) {
151 if (digitsSPD->GetEntriesFast()!=0)
152 FindClustersSPD(digitsSPD,clusters);
154 if(digitsSDD->GetEntriesFast()!=0)
155 FindClustersSDD(digitsSDD,clusters);
156 else if(digitsSSD->GetEntriesFast()!=0)
157 FindClustersSSD(digitsSSD,clusters);
159 ncl+=clusters->GetEntriesFast();
179 Info("Digits2Clusters","Number of found clusters : %d",ncl);
184 void AliITSclustererV2::Digits2Clusters(AliRawReader* rawReader) {
185 //------------------------------------------------------------
186 // This function creates ITS clusters from raw data
187 //------------------------------------------------------------
188 AliRunLoader* runLoader = AliRunLoader::Instance();
190 Error("Digits2Clusters", "no run loader found");
193 runLoader->LoadKinematics();
194 AliLoader* itsLoader = runLoader->GetLoader("ITSLoader");
196 Error("Digits2Clusters", "no loader for ITS found");
199 if (!itsLoader->TreeR()) itsLoader->MakeTree("R");
200 TTree* cTree = itsLoader->TreeR();
202 TClonesArray *array=new TClonesArray("AliITSclusterV2",1000);
203 cTree->Branch("Clusters",&array);
206 TClonesArray** clusters = new TClonesArray*[fNModules];
207 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
208 clusters[iModule] = NULL;
210 // one TClonesArray per module
213 AliITSRawStreamSPD inputSPD(rawReader);
214 FindClustersSPD(&inputSPD, clusters);
217 AliITSRawStreamSDD inputSDD(rawReader);
218 FindClustersSDD(&inputSDD, clusters);
221 AliITSRawStreamSSD inputSSD(rawReader);
222 FindClustersSSD(&inputSSD, clusters);
224 // write all clusters to the tree
226 TClonesArray *emptyArray=new TClonesArray("AliITSclusterV2");
227 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
228 array = clusters[iModule];
230 Error("Digits2Clusters", "data for module %d missing!", iModule);
233 cTree->SetBranchAddress("Clusters", &array);
235 nClusters += array->GetEntriesFast();
239 itsLoader->WriteRecPoints("OVERWRITE");
243 Info("Digits2Clusters", "total number of found clusters in ITS: %d\n",
247 //**** Fast clusters *******************************
248 #include "TParticle.h"
250 //#include "AliITS.h"
251 #include "AliITSmodule.h"
252 #include "AliITSRecPoint.h"
253 #include "AliITSsimulationFastPoints.h"
254 #include "AliITSRecPoint.h"
257 static void CheckLabels(Int_t lab[3]) {
258 //------------------------------------------------------------
259 // Tries to find mother's labels
260 //------------------------------------------------------------
261 AliRunLoader *rl = AliRunLoader::Instance();
262 TTree *trK=(TTree*)rl->TreeK();
267 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
269 while (part->P() < 0.005) {
270 Int_t m=part->GetFirstMother();
272 Info("CheckLabels","Primary momentum: %f",part->P());
275 if (part->GetStatusCode()>0) {
276 Info("CheckLabels","Primary momentum: %f",part->P());
280 part=(TParticle*)gAlice->GetMCApp()->Particle(label);
289 // cerr<<"CheckLabels : No empty labels !\n";
296 static void CheckLabels(Int_t lab[3]) {
297 //------------------------------------------------------------
298 // Tries to find mother's labels
299 //------------------------------------------------------------
301 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
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();
313 if (part->GetStatusCode()>0) {
323 static void CheckLabels2(Int_t lab[10]) {
324 //------------------------------------------------------------
325 // Tries to find mother's labels
326 //------------------------------------------------------------
327 AliRunLoader *rl = AliRunLoader::Instance();
328 TTree *trK=(TTree*)rl->TreeK();
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
335 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
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) {
342 Int_t m=part->GetFirstMother();
346 if (part->GetStatusCode()>0) {
352 if (part->P() < 0.12 && nlabels>3) {
358 if ( (label>ntracks||label <0) && nlabels>3) {
365 for (Int_t i=0;i<10;i++){
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) {
379 //compress labels -- if multi-times the same
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++){
391 for (Int_t j=0;j<10;j++) lab[j]=lab2[j];
395 static void AddLabel(Int_t lab[10], Int_t label) {
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)
398 AliRunLoader *rl = AliRunLoader::Instance();
399 TTree *trK=(TTree*)rl->TreeK();
402 if(label<0) return; // In case of no label just exit
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;
417 void AliITSclustererV2::RecPoints2Clusters
418 (const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
419 //------------------------------------------------------------
420 // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS
421 // subdetector indexed by idx
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);
428 lp[0]=-(-p->GetDetLocalX()+fYshift[idx]); if (idx<=fLastSPD1) lp[0]*=-1; //SPD1
429 lp[1]= -p->GetZ()+fZshift[idx];
430 lp[2]=p->GetSigmaDetLocX2();
431 lp[3]=p->GetSigmaZ2();
432 lp[4]=p->GetQ()*36./23333.; //electrons -> ADC
434 lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
437 Int_t dummy[3]={0,0,0};
438 new (cl[i]) AliITSclusterV2(lab,lp, dummy);
442 //***********************************
445 void AliITSclustererV2::
446 FindCluster(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();
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);
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);
466 void AliITSclustererV2::
467 FindClustersSPD(const TClonesArray *digits, TClonesArray *clusters) {
468 //------------------------------------------------------------
469 // Actual SPD cluster finder
470 //------------------------------------------------------------
471 Int_t kNzBins = fNzSPD + 2;
472 const Int_t kMAXBIN=kNzBins*(fNySPD+2);
474 Int_t ndigits=digits->GetEntriesFast();
475 AliBin *bins=new AliBin[kMAXBIN];
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;
483 bins[i*kNzBins+j].SetIndex(k);
484 bins[i*kNzBins+j].SetMask(1);
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];
491 FindCluster(k,kNzBins,bins,ni,idx);
493 Info("FindClustersSPD","Too big cluster !");
497 for (Int_t ilab=0;ilab<10;ilab++){
501 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[0]);
502 Int_t ymin=d->GetCoord2(),ymax=ymin;
503 Int_t zmin=d->GetCoord1(),zmax=zmin;
505 for (Int_t l=0; l<ni; l++) {
506 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[l]);
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();
512 // MI addition - find all labels in cluster
513 for (Int_t dlab=0;dlab<10;dlab++){
514 Int_t digitlab = (d->GetTracks())[dlab];
515 if (digitlab<0) continue;
516 AddLabel(milab,digitlab);
518 if (milab[9]>0) CheckLabels2(milab);
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;
529 for (Int_t iz=zmin; iz<=zmax;iz+=idz)
530 for (Int_t iy=ymin; iy<=ymax;iy+=idy){
533 Float_t y=0.,z=0.,q=0.;
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;
541 Float_t qq=d->GetSignal();
542 y+=qq*fYSPD[d->GetCoord2()]; z+=qq*fZSPD[d->GetCoord1()]; q+=qq;
545 if (nodigits==0) continue;
547 y-=fHwSPD; z-=fHlSPD;
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);
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.);
562 lp[4]= (zmax-zmin+1)*100 + (ymax-ymin+1);
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++;
574 void AliITSclustererV2::FindClustersSPD(AliITSRawStream* input,
575 TClonesArray** clusters)
577 //------------------------------------------------------------
578 // Actual SPD cluster finder for raw data
579 //------------------------------------------------------------
581 Int_t nClustersSPD = 0;
582 Int_t kNzBins = fNzSPD + 2;
583 Int_t kNyBins = fNySPD + 2;
584 Int_t kMaxBin = kNzBins * kNyBins;
585 AliBin *binsSPD = new AliBin[kMaxBin];
586 AliBin *binsSPDInit = new AliBin[kMaxBin];
589 // read raw data input stream
591 Bool_t next = input->Next();
592 if (!next || input->IsNewModule()) {
593 Int_t iModule = input->GetPrevModuleID();
595 // when all data from a module was read, search for clusters
597 clusters[iModule] = new TClonesArray("AliITSclusterV2");
600 for (Int_t iBin = 0; iBin < kMaxBin; iBin++) {
601 if (bins[iBin].IsUsed()) continue;
604 FindCluster(iBin, kNzBins, bins, nBins, idxBins);
606 Error("FindClustersSPD", "SPD: Too big cluster !\n");
614 // label[3] = iModule;
615 label[3] = fNdet[iModule];
617 Int_t ymin = (idxBins[0] / kNzBins) - 1;
619 Int_t zmin = (idxBins[0] % kNzBins) - 1;
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;
630 Int_t idy = 0; // max 2 clusters
631 if ((iModule <= fLastSPD1) &&idy<3) idy=3;
632 if ((iModule > fLastSPD1) &&idy<4) idy=4;
634 for (Int_t iiz=zmin; iiz<=zmax;iiz+=idz)
635 for (Int_t iiy=ymin; iiy<=ymax;iiy+=idy){
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;
647 Float_t qBin = bins[idxBins[idx]].GetQ();
648 y += qBin * fYSPD[iy];
649 z += qBin * fZSPD[iz];
652 if (ndigits==0) continue;
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.;
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);
674 nClustersSPD += nClusters;
680 memcpy(binsSPD,binsSPDInit,sizeof(AliBin)*kMaxBin);
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);
690 delete [] binsSPDInit;
693 Info("FindClustersSPD", "found clusters in ITS SPD: %d", nClustersSPD);
697 Bool_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;
714 void AliITSclustererV2::
715 FindPeaks(Int_t k,Int_t max,AliBin *b,Int_t *idx,UInt_t *msk,Int_t& n) {
716 //------------------------------------------------------------
718 //------------------------------------------------------------
720 if (IsMaximum(k,max,b)) {
721 idx[n]=k; msk[n]=(2<<n);
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);
731 void AliITSclustererV2::
732 MarkPeak(Int_t k, Int_t max, AliBin *bins, UInt_t m) {
733 //------------------------------------------------------------
735 //------------------------------------------------------------
736 UShort_t q=bins[k].GetQ();
738 bins[k].SetMask(bins[k].GetMask()|m);
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);
750 void AliITSclustererV2::
751 MakeCluster(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;
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);
764 bins[k].SetMask(0xFFFFFFFE);
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);
772 void AliITSclustererV2::
773 FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
774 const TClonesArray *digits, TClonesArray *clusters) {
775 //------------------------------------------------------------
776 // Actual SDD cluster finder
777 //------------------------------------------------------------
778 Int_t ncl=0; TClonesArray &cl=*clusters;
779 for (Int_t s=0; s<2; s++)
780 for (Int_t i=0; i<nMaxBin; i++) {
781 if (bins[s][i].IsUsed()) continue;
782 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
783 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
785 if (npeaks>30) continue;
786 if (npeaks==0) continue;
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
793 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
794 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
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()) {
809 for (k=0; k<npeaks; k++) {
810 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
813 for (k=0; k<npeaks; k++) {
814 if (idx[k] < 0) continue; //removed peak
816 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
819 for (Int_t ilab=0;ilab<10;ilab++){
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.);
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;
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];
844 AddLabel(milab, track);
853 Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
854 Float_t w=par->GetPadPitchWidth(sec);
857 c.SetSigmaY2(c.GetSigmaY2()*0.108);
858 if (sec<par->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
860 s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
865 c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
866 if (sec<par->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
870 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
873 //Float_t s2 = c.GetSigmaY2()/c.GetQ() - y*y;
875 //s2 = c.GetSigmaZ2()/c.GetQ() - z*z;
878 y=(y-0.5)*fYpitchSDD;
880 y-=fYoffSDD; //delay ?
883 z=(z-0.5)*fZpitchSDD;
889 q/=12.7; //this WAS consistent with SSD. To be reassessed
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]};
894 if (c.GetQ() < 20.) continue; //noise cluster
897 // AliBin *b=&bins[s][idx[k]];
898 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
901 //lab[0]=(d->GetTracks())[0];
902 //lab[1]=(d->GetTracks())[1];
903 //lab[2]=(d->GetTracks())[2];
910 AliITSclusterV2 *cc = new (cl[ncl]) AliITSclusterV2(milab,hit,info);
917 void AliITSclustererV2::
918 FindClustersSDD(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);
926 bins[0]=new AliBin[kMAXBIN];
927 bins[1]=new AliBin[kMAXBIN];
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();
939 bins[0][y*kNzBins+z].SetQ(q);
940 bins[0][y*kNzBins+z].SetMask(1);
941 bins[0][y*kNzBins+z].SetIndex(i);
944 bins[1][y*kNzBins+z].SetQ(q);
945 bins[1][y*kNzBins+z].SetMask(1);
946 bins[1][y*kNzBins+z].SetIndex(i);
950 FindClustersSDD(bins, kMAXBIN, kNzBins, digits, clusters);
957 void AliITSclustererV2::FindClustersSDD(AliITSRawStream* input,
958 TClonesArray** clusters)
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);
966 AliBin *binsSDDInit = new AliBin[kMaxBin];
967 AliBin *binsSDD1 = new AliBin[kMaxBin];
968 AliBin *binsSDD2 = new AliBin[kMaxBin];
969 AliBin *bins[2] = {NULL, NULL};
971 // read raw data input stream
973 Bool_t next = input->Next();
974 if (!next || input->IsNewModule()) {
975 Int_t iModule = input->GetPrevModuleID();
977 // when all data from a module was read, search for clusters
979 clusters[iModule] = new TClonesArray("AliITSclusterV2");
981 FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
982 Int_t nClusters = clusters[iModule]->GetEntriesFast();
983 nClustersSDD += nClusters;
984 bins[0] = bins[1] = NULL;
990 memcpy(binsSDD1,binsSDDInit,sizeof(AliBin)*kMaxBin);
991 memcpy(binsSDD2,binsSDDInit,sizeof(AliBin)*kMaxBin);
994 // fill the current digit into the bins array
995 if(input->GetSignal()>=3) {
996 Int_t iz = input->GetCoord1()+1;
997 Int_t side = ((iz <= fNzSDD) ? 0 : 1);
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);
1008 delete[] binsSDDInit;
1010 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
1015 void AliITSclustererV2::
1016 FindClustersSSD(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;
1024 Float_t tanp=fTanP, tann=fTanN;
1025 if (fI>fLastSSD1) {tann=fTanP; tanp=fTanN;}
1026 Int_t idet=fNdet[fI];
1029 Int_t negativepair[30000];
1030 Int_t cnegative[3000];
1032 Int_t positivepair[30000];
1033 Int_t cpositive[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;}
1037 for (Int_t i=0;i<30000;i++){negativepair[i]=positivepair[i]=0;}
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);
1046 // find available pairs
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
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
1098 for (Int_t ip=0;ip<np;ip++){
1099 Float_t ybest=1000,zbest=1000,qbest=0;
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());
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;
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
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);
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);
1130 cl2->SetChargeRatio(ratio);
1133 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1142 for (Int_t ip=0;ip<np;ip++){
1143 Float_t ybest=1000,zbest=1000,qbest=0;
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){
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
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);
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);
1181 cl2->SetChargeRatio(ratio);
1184 if ((pos[ip].GetNd()+neg[in].GetNd())>6){ //multi cluster
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
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);
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);
1219 cl2->SetChargeRatio(ratio);
1222 if ((pos[ip2].GetNd()+neg[in].GetNd())>6){ //multi cluster
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();
1245 if (TMath::Abs(pcharge-pos[ip].GetQ())<10){
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
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);
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);
1275 cl2->SetChargeRatio(ratio);
1278 if ((pos[ip].GetNd()+neg[jn].GetNd())>6){ //multi cluster
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
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);
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);
1312 cl2->SetChargeRatio(ratio);
1315 if ((pos[ip].GetNd()+neg[jn2].GetNd())>6){ //multi cluster
1327 for (Int_t ip=0;ip<np;ip++){
1328 Float_t ybest=1000,zbest=1000,qbest=0;
1332 if ( (cnegative[ip]<5) && cpositive[negativepair[10*ip]]<5){
1333 Float_t minchargediff =4.;
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){
1340 minchargediff = TMath::Abs(chargedif);
1343 if (j<0) continue; // not proper cluster
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++;
1350 if (count>1) continue; // more than one "proper" cluster for positive
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++;
1358 if (count>1) continue; // more than one "proper" cluster for negative
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++;
1368 if (count>1) continue;
1369 if (pairs[ip][j]<100) continue;
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;
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
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);
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);
1396 cl2->SetChargeRatio(ratio);
1399 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1410 for (Int_t i=0; i<np; i++) {
1411 Float_t ybest=1000,zbest=1000,qbest=0;
1412 Float_t yp=pos[i].GetY()*fYpitchSSD;
1413 if (pos[i].GetQ()<3) continue;
1414 for (Int_t j=0; j<nn; j++) {
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());
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)
1426 if (TMath::Abs(zt)<fHlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
1428 qbest=0.5*(pos[i].GetQ()+neg[j].GetQ());
1429 lp[0]=-(-ybest+fYshift[fI]);
1430 lp[1]= -zbest+fZshift[fI];
1431 lp[2]=0.0025*0.0025; //SigmaY2
1432 lp[3]=0.110*0.110; //SigmaZ2
1435 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1436 for (Int_t ilab=0;ilab<3;ilab++){
1437 milab[ilab] = pos[i].GetLabel(ilab);
1438 milab[ilab+3] = neg[j].GetLabel(ilab);
1441 CheckLabels2(milab);
1442 milab[3]=(((i<<10) + j)<<10) + idet; // pos|neg|det
1443 Int_t info[3] = {pos[i].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1444 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1446 cl2->SetChargeRatio(ratio);
1447 cl2->SetType(100+cpositive[j]+cnegative[i]);
1450 if (pairs[i][j]<100){
1451 printf("problem:- %d\n", pairs[i][j]);
1453 if (cnegative[i]<2&&cpositive[j]<2){
1454 printf("problem:- %d\n", pairs[i][j]);
1461 // for (Int_t i=0; i<1000; i++) delete [] pairs[i];
1467 void AliITSclustererV2::
1468 FindClustersSSD(const TClonesArray *alldigits, TClonesArray *clusters) {
1469 //------------------------------------------------------------
1470 // Actual SSD cluster finder
1471 //------------------------------------------------------------
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;
1480 Int_t smax = digits->GetEntriesFast();
1481 if (smax==0) return;
1483 const Int_t MAX=1000;
1485 Ali1Dcluster pos[MAX], neg[MAX];
1486 Float_t y=0., q=0., qmax=0.;
1487 Int_t lab[4]={-2,-2,-2,-2};
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();
1497 Ali1Dcluster *c=neg;
1500 for (Int_t ilab=0;ilab<10;ilab++){
1503 milab[0]=d->GetTrack(0); milab[1]=d->GetTrack(1); milab[2]=d->GetTrack(2);
1505 for (Int_t s=1; s<smax; s++) {
1506 d=(AliITSdigitSSD*)digits->UncheckedAt(s);
1507 Int_t strip=d->GetCoord2();
1508 if ((strip-curr) > 1 || flag!=d->GetCoord1()) {
1512 CheckLabels2(milab);
1513 c[*n].SetLabels(milab);
1514 //Split suspiciously big cluster
1517 c[*n].SetY(y/q-0.3*nd);
1521 Error("FindClustersSSD","Too many 1D clusters !");
1524 c[*n].SetY(y/q-0.0*nd);
1529 Error("FindClustersSSD","Too many 1D clusters !");
1533 c[*n].SetY(y/q+0.3*nd);
1536 c[*n].SetLabels(milab);
1541 c[*n].SetY(y/q-0.25*nd);
1545 Error("FindClustersSSD","Too many 1D clusters !");
1548 c[*n].SetY(y/q+0.25*nd);
1551 c[*n].SetLabels(milab);
1555 Error("FindClustersSSD","Too many 1D clusters !");
1560 lab[0]=lab[1]=lab[2]=-2;
1562 for (Int_t ilab=0;ilab<10;ilab++){
1566 if (flag!=d->GetCoord1()) { n=&np; c=pos; }
1568 flag=d->GetCoord1();
1569 q += d->GetSignal();
1570 y += d->GetCoord2()*d->GetSignal();
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);
1576 for (Int_t ilab=0;ilab<10;ilab++) {
1577 if (d->GetTrack(ilab)>=0) AddLabel(milab, (d->GetTrack(ilab)));
1584 c[*n].SetLabels(lab);
1585 //Split suspiciously big cluster
1586 if (nd>4 && nd<25) {
1587 c[*n].SetY(y/q-0.25*nd);
1591 Error("FindClustersSSD","Too many 1D clusters !");
1594 c[*n].SetY(y/q+0.25*nd);
1597 c[*n].SetLabels(lab);
1601 Error("FindClustersSSD","Too many 1D clusters !");
1605 FindClustersSSD(neg, nn, pos, np, clusters);
1608 void AliITSclustererV2::FindClustersSSD(AliITSRawStream* input,
1609 TClonesArray** clusters)
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};
1618 Int_t lab[3]={-2,-2,-2};
1622 Int_t prevStrip = -1;
1623 Int_t prevFlag = -1;
1624 Int_t prevModule = -1;
1626 // read raw data input stream
1628 Bool_t next = input->Next();
1630 if(input->GetSignal()<3 && next) continue;
1631 // check if a new cluster starts
1632 Int_t strip = input->GetCoord2();
1633 Int_t flag = input->GetCoord1();
1634 if ((!next || (input->GetModuleID() != prevModule)||
1635 (strip-prevStrip > 1) || (flag != prevFlag)) &&
1637 if (nClusters[prevFlag] == MAX) {
1638 Error("FindClustersSSD", "Too many 1D clusters !");
1641 Ali1Dcluster& cluster = clusters1D[prevFlag][nClusters[prevFlag]++];
1644 cluster.SetNd(nDigits);
1645 cluster.SetLabels(lab);
1647 //Split suspiciously big cluster
1648 if (nDigits > 4&&nDigits < 25) {
1649 cluster.SetY(y/q - 0.25*nDigits);
1650 cluster.SetQ(0.5*q);
1651 if (nClusters[prevFlag] == MAX) {
1652 Error("FindClustersSSD", "Too many 1D clusters !");
1655 Ali1Dcluster& cluster2 = clusters1D[prevFlag][nClusters[prevFlag]++];
1656 cluster2.SetY(y/q + 0.25*nDigits);
1657 cluster2.SetQ(0.5*q);
1658 cluster2.SetNd(nDigits);
1659 cluster2.SetLabels(lab);
1665 if (!next || (input->GetModuleID() != prevModule)) {
1666 Int_t iModule = prevModule;
1668 // when all data from a module was read, search for clusters
1669 if (prevFlag >= 0) {
1670 clusters[iModule] = new TClonesArray("AliITSclusterV2");
1672 FindClustersSSD(&clusters1D[0][0], nClusters[0],
1673 &clusters1D[1][0], nClusters[1], clusters[iModule]);
1674 Int_t noClusters = clusters[iModule]->GetEntriesFast();
1675 nClustersSSD += noClusters;
1679 nClusters[0] = nClusters[1] = 0;
1684 // add digit to current cluster
1685 q += input->GetSignal();
1686 y += strip * input->GetSignal();
1690 prevModule = input->GetModuleID();
1694 Info("FindClustersSSD", "found clusters in ITS SSD: %d", nClustersSSD);