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::GetRunLoader();
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 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
227 array = clusters[iModule];
229 Error("Digits2Clusters", "data for module %d missing!", iModule);
230 array = new TClonesArray("AliITSclusterV2");
232 cTree->SetBranchAddress("Clusters", &array);
234 nClusters += array->GetEntriesFast();
237 itsLoader->WriteRecPoints("OVERWRITE");
241 Info("Digits2Clusters", "total number of found clusters in ITS: %d\n",
245 //**** Fast clusters *******************************
246 #include "TParticle.h"
248 //#include "AliITS.h"
249 #include "AliITSmodule.h"
250 #include "AliITSRecPoint.h"
251 #include "AliITSsimulationFastPoints.h"
252 #include "AliITSRecPoint.h"
255 static void CheckLabels(Int_t lab[3]) {
256 //------------------------------------------------------------
257 // Tries to find mother's labels
258 //------------------------------------------------------------
259 AliRunLoader *rl = AliRunLoader::GetRunLoader();
260 TTree *trK=(TTree*)rl->TreeK();
265 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
267 while (part->P() < 0.005) {
268 Int_t m=part->GetFirstMother();
270 Info("CheckLabels","Primary momentum: %f",part->P());
273 if (part->GetStatusCode()>0) {
274 Info("CheckLabels","Primary momentum: %f",part->P());
278 part=(TParticle*)gAlice->GetMCApp()->Particle(label);
280 if (lab[1]<0) lab[1]=label;
281 else if (lab[2]<0) lab[2]=label;
282 else ;//cerr<<"CheckLabels : No empty labels !\n";
288 static void CheckLabels(Int_t lab[3]) {
289 //------------------------------------------------------------
290 // Tries to find mother's labels
291 //------------------------------------------------------------
293 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
295 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
296 for (Int_t i=0;i<3;i++){
297 Int_t label = lab[i];
298 if (label>=0 && label<ntracks) {
299 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
300 if (part->P() < 0.005) {
301 Int_t m=part->GetFirstMother();
305 if (part->GetStatusCode()>0) {
315 static void CheckLabels2(Int_t lab[10]) {
316 //------------------------------------------------------------
317 // Tries to find mother's labels
318 //------------------------------------------------------------
319 AliRunLoader *rl = AliRunLoader::GetRunLoader();
320 TTree *trK=(TTree*)rl->TreeK();
324 for (Int_t i=0;i<10;i++) if (lab[i]>=0) nlabels++;
325 if(nlabels == 0) return; // In case of no labels just exit
327 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
329 for (Int_t i=0;i<10;i++){
330 Int_t label = lab[i];
331 if (label>=0 && label<ntracks) {
332 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
333 if (part->P() < 0.02) {
334 Int_t m=part->GetFirstMother();
338 if (part->GetStatusCode()>0) {
344 if (part->P() < 0.12 && nlabels>3) {
350 if ( (label>ntracks||label <0) && nlabels>3) {
357 for (Int_t i=0;i<10;i++){
359 Int_t label = lab[i];
360 if (label>=0 && label<ntracks) {
361 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
362 if (part->P() < 0.1) {
371 //compress labels -- if multi-times the same
373 for (Int_t i=0;i<10;i++) lab2[i]=-2;
374 for (Int_t i=0;i<10 ;i++){
375 if (lab[i]<0) continue;
376 for (Int_t j=0;j<10 &&lab2[j]!=lab[i];j++){
383 for (Int_t j=0;j<10;j++) lab[j]=lab2[j];
387 static void AddLabel(Int_t lab[10], Int_t label) {
388 // add label of the particle in the kine tree which originates this cluster
389 // (used for reconstruction of MC data only, for comparison purposes)
390 AliRunLoader *rl = AliRunLoader::GetRunLoader();
391 TTree *trK=(TTree*)rl->TreeK();
394 if(label<0) return; // In case of no label just exit
396 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
397 if (label>ntracks) return;
398 for (Int_t i=0;i<10;i++){
399 // if (label<0) break;
400 if (lab[i]==label) break;
409 void AliITSclustererV2::RecPoints2Clusters
410 (const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
411 //------------------------------------------------------------
412 // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS
413 // subdetector indexed by idx
414 //------------------------------------------------------------
415 TClonesArray &cl=*clusters;
416 Int_t ncl=points->GetEntriesFast();
417 for (Int_t i=0; i<ncl; i++) {
418 AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
420 lp[0]=-(-p->GetDetLocalX()+fYshift[idx]); if (idx<=fLastSPD1) lp[0]*=-1; //SPD1
421 lp[1]= -p->GetZ()+fZshift[idx];
422 lp[2]=p->GetSigmaDetLocX2();
423 lp[3]=p->GetSigmaZ2();
424 lp[4]=p->GetQ()*36./23333.; //electrons -> ADC
426 lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
429 Int_t dummy[3]={0,0,0};
430 new (cl[i]) AliITSclusterV2(lab,lp, dummy);
434 //***********************************
437 void AliITSclustererV2::
438 FindCluster(Int_t k,Int_t maxz,AliBin *bins,Int_t &n,Int_t *idx) {
439 //------------------------------------------------------------
440 // returns an array of indices of digits belonging to the cluster
441 // (needed when the segmentation is not regular)
442 //------------------------------------------------------------
443 if (n<200) idx[n++]=bins[k].GetIndex();
446 if (bins[k-maxz].IsNotUsed()) FindCluster(k-maxz,maxz,bins,n,idx);
447 if (bins[k-1 ].IsNotUsed()) FindCluster(k-1 ,maxz,bins,n,idx);
448 if (bins[k+maxz].IsNotUsed()) FindCluster(k+maxz,maxz,bins,n,idx);
449 if (bins[k+1 ].IsNotUsed()) FindCluster(k+1 ,maxz,bins,n,idx);
451 if (bins[k-maxz-1].IsNotUsed()) FindCluster(k-maxz-1,maxz,bins,n,idx);
452 if (bins[k-maxz+1].IsNotUsed()) FindCluster(k-maxz+1,maxz,bins,n,idx);
453 if (bins[k+maxz-1].IsNotUsed()) FindCluster(k+maxz-1,maxz,bins,n,idx);
454 if (bins[k+maxz+1].IsNotUsed()) FindCluster(k+maxz+1,maxz,bins,n,idx);
458 void AliITSclustererV2::
459 FindClustersSPD(const TClonesArray *digits, TClonesArray *clusters) {
460 //------------------------------------------------------------
461 // Actual SPD cluster finder
462 //------------------------------------------------------------
463 Int_t kNzBins = fNzSPD + 2;
464 const Int_t kMAXBIN=kNzBins*(fNySPD+2);
466 Int_t ndigits=digits->GetEntriesFast();
467 AliBin *bins=new AliBin[kMAXBIN];
471 for (k=0; k<ndigits; k++) {
472 d=(AliITSdigitSPD*)digits->UncheckedAt(k);
473 Int_t i=d->GetCoord2()+1; //y
474 Int_t j=d->GetCoord1()+1;
475 bins[i*kNzBins+j].SetIndex(k);
476 bins[i*kNzBins+j].SetMask(1);
479 Int_t n=0; TClonesArray &cl=*clusters;
480 for (k=0; k<kMAXBIN; k++) {
481 if (!bins[k].IsNotUsed()) continue;
482 Int_t ni=0, idx[200];
483 FindCluster(k,kNzBins,bins,ni,idx);
485 Info("FindClustersSPD","Too big cluster !");
489 for (Int_t ilab=0;ilab<10;ilab++){
493 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[0]);
494 Int_t ymin=d->GetCoord2(),ymax=ymin;
495 Int_t zmin=d->GetCoord1(),zmax=zmin;
497 for (Int_t l=0; l<ni; l++) {
498 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[l]);
500 if (ymin > d->GetCoord2()) ymin=d->GetCoord2();
501 if (ymax < d->GetCoord2()) ymax=d->GetCoord2();
502 if (zmin > d->GetCoord1()) zmin=d->GetCoord1();
503 if (zmax < d->GetCoord1()) zmax=d->GetCoord1();
504 // MI addition - find all labels in cluster
505 for (Int_t dlab=0;dlab<10;dlab++){
506 Int_t digitlab = (d->GetTracks())[dlab];
507 if (digitlab<0) continue;
508 AddLabel(milab,digitlab);
510 if (milab[9]>0) CheckLabels2(milab);
514 //Int_t idy = (fNlayer[fI]==0)? 2:3;
515 //for (Int_t iz=zmin; iz<=zmax;iz+=2)
516 //Int_t idy = (ymax-ymin)/4.; // max 2 clusters
517 Int_t idy = 0; // max 2 clusters
518 if (fNlayer[fI]==0 &&idy<3) idy=3;
519 if (fNlayer[fI]==1 &&idy<4) idy=4;
521 for (Int_t iz=zmin; iz<=zmax;iz+=idz)
522 for (Int_t iy=ymin; iy<=ymax;iy+=idy){
525 Float_t y=0.,z=0.,q=0.;
526 for (Int_t l=0; l<ni; l++) {
527 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[l]);
528 if (zmax-zmin>=idz || ymax-ymin>=idy){
529 if (TMath::Abs( d->GetCoord2()-iy)>0.75*idy) continue;
530 if (TMath::Abs( d->GetCoord1()-iz)>0.75*idz) continue;
533 Float_t qq=d->GetSignal();
534 y+=qq*fYSPD[d->GetCoord2()]; z+=qq*fZSPD[d->GetCoord1()]; q+=qq;
537 if (ndigits==0) continue;
539 y-=fHwSPD; z-=fHlSPD;
542 lp[0]=-(-y+fYshift[fI]); if (fI<=fLastSPD1) lp[0]=-lp[0];
543 lp[1]= -z+fZshift[fI];
544 // Float_t factor=TMath::Max(double(ni-3.),1.5);
545 Float_t factory=TMath::Max(ymax-ymin,1);
546 Float_t factorz=TMath::Max(zmax-zmin,1);
549 //lp[2]= (fYpitchSPD*fYpitchSPD/12.)*factory;
550 //lp[3]= (fZ1pitchSPD*fZ1pitchSPD/12.)*factorz;
551 lp[2]= (fYpitchSPD*fYpitchSPD/12.);
552 lp[3]= (fZ1pitchSPD*fZ1pitchSPD/12.);
554 lp[4]= (zmax-zmin+1)*100 + (ymax-ymin+1);
557 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[0]);
558 Int_t info[3] = {ymax-ymin+1,zmax-zmin+1,fNlayer[fI]};
559 new (cl[n]) AliITSclusterV2(milab,lp,info); n++;
566 void AliITSclustererV2::FindClustersSPD(AliITSRawStream* input,
567 TClonesArray** clusters)
569 //------------------------------------------------------------
570 // Actual SPD cluster finder for raw data
571 //------------------------------------------------------------
573 Int_t nClustersSPD = 0;
574 Int_t kNzBins = fNzSPD + 2;
575 Int_t kNyBins = fNySPD + 2;
576 Int_t kMaxBin = kNzBins * kNyBins;
577 AliBin *binsSPD = new AliBin[kMaxBin];
578 AliBin *binsSPDInit = new AliBin[kMaxBin];
581 // read raw data input stream
583 Bool_t next = input->Next();
584 if (!next || input->IsNewModule()) {
585 Int_t iModule = input->GetPrevModuleID();
587 // when all data from a module was read, search for clusters
589 clusters[iModule] = new TClonesArray("AliITSclusterV2");
592 for (Int_t iBin = 0; iBin < kMaxBin; iBin++) {
593 if (bins[iBin].IsUsed()) continue;
596 FindCluster(iBin, kNzBins, bins, nBins, idxBins);
598 Error("FindClustersSPD", "SPD: Too big cluster !\n");
606 // label[3] = iModule;
607 label[3] = fNdet[iModule];
609 Int_t ymin = (idxBins[0] / kNzBins) - 1;
611 Int_t zmin = (idxBins[0] % kNzBins) - 1;
613 for (Int_t idx = 0; idx < nBins; idx++) {
614 Int_t iy = (idxBins[idx] / kNzBins) - 1;
615 Int_t iz = (idxBins[idx] % kNzBins) - 1;
616 if (ymin > iy) ymin = iy;
617 if (ymax < iy) ymax = iy;
618 if (zmin > iz) zmin = iz;
619 if (zmax < iz) zmax = iz;
622 Int_t idy = 0; // max 2 clusters
623 if ((iModule <= fLastSPD1) &&idy<3) idy=3;
624 if ((iModule > fLastSPD1) &&idy<4) idy=4;
626 for (Int_t iiz=zmin; iiz<=zmax;iiz+=idz)
627 for (Int_t iiy=ymin; iiy<=ymax;iiy+=idy){
630 Float_t y=0.,z=0.,q=0.;
631 for (Int_t idx = 0; idx < nBins; idx++) {
632 Int_t iy = (idxBins[idx] / kNzBins) - 1;
633 Int_t iz = (idxBins[idx] % kNzBins) - 1;
634 if (zmax-zmin>=idz || ymax-ymin>=idy){
635 if (TMath::Abs(iy-iiy)>0.75*idy) continue;
636 if (TMath::Abs(iz-iiz)>0.75*idz) continue;
639 Float_t qBin = bins[idxBins[idx]].GetQ();
640 y += qBin * fYSPD[iy];
641 z += qBin * fZSPD[iz];
644 if (ndigits==0) continue;
650 Float_t hit[5]; // y, z, sigma(y)^2, sigma(z)^2, charge
651 hit[0] = -(-y+fYshift[iModule]);
652 if (iModule <= fLastSPD1) hit[0] = -hit[0];
653 hit[1] = -z+fZshift[iModule];
654 hit[2] = fYpitchSPD*fYpitchSPD/12.;
655 hit[3] = fZ1pitchSPD*fZ1pitchSPD/12.;
657 hit[4] = (zmax-zmin+1)*100 + (ymax-ymin+1);
658 // CheckLabels(label);
659 Int_t info[3]={ymax-ymin+1,zmax-zmin+1,fNlayer[iModule]};
660 new (clusters[iModule]->AddrAt(nClusters))
661 AliITSclusterV2(label, hit,info);
666 nClustersSPD += nClusters;
672 memcpy(binsSPD,binsSPDInit,sizeof(AliBin)*kMaxBin);
675 // fill the current digit into the bins array
676 Int_t index = (input->GetCoord2()+1) * kNzBins + (input->GetCoord1()+1);
677 bins[index].SetIndex(index);
678 bins[index].SetMask(1);
682 delete [] binsSPDInit;
685 Info("FindClustersSPD", "found clusters in ITS SPD: %d", nClustersSPD);
689 Bool_t AliITSclustererV2::IsMaximum(Int_t k,Int_t max,const AliBin *bins) {
690 //------------------------------------------------------------
691 //is this a local maximum ?
692 //------------------------------------------------------------
693 UShort_t q=bins[k].GetQ();
694 if (q==1023) return kFALSE;
695 if (bins[k-max].GetQ() > q) return kFALSE;
696 if (bins[k-1 ].GetQ() > q) return kFALSE;
697 if (bins[k+max].GetQ() > q) return kFALSE;
698 if (bins[k+1 ].GetQ() > q) return kFALSE;
699 if (bins[k-max-1].GetQ() > q) return kFALSE;
700 if (bins[k+max-1].GetQ() > q) return kFALSE;
701 if (bins[k+max+1].GetQ() > q) return kFALSE;
702 if (bins[k-max+1].GetQ() > q) return kFALSE;
706 void AliITSclustererV2::
707 FindPeaks(Int_t k,Int_t max,AliBin *b,Int_t *idx,UInt_t *msk,Int_t& n) {
708 //------------------------------------------------------------
710 //------------------------------------------------------------
712 if (IsMaximum(k,max,b)) {
713 idx[n]=k; msk[n]=(2<<n);
717 if (b[k-max].GetMask()&1) FindPeaks(k-max,max,b,idx,msk,n);
718 if (b[k-1 ].GetMask()&1) FindPeaks(k-1 ,max,b,idx,msk,n);
719 if (b[k+max].GetMask()&1) FindPeaks(k+max,max,b,idx,msk,n);
720 if (b[k+1 ].GetMask()&1) FindPeaks(k+1 ,max,b,idx,msk,n);
723 void AliITSclustererV2::
724 MarkPeak(Int_t k, Int_t max, AliBin *bins, UInt_t m) {
725 //------------------------------------------------------------
727 //------------------------------------------------------------
728 UShort_t q=bins[k].GetQ();
730 bins[k].SetMask(bins[k].GetMask()|m);
732 if (bins[k-max].GetQ() <= q)
733 if ((bins[k-max].GetMask()&m) == 0) MarkPeak(k-max,max,bins,m);
734 if (bins[k-1 ].GetQ() <= q)
735 if ((bins[k-1 ].GetMask()&m) == 0) MarkPeak(k-1 ,max,bins,m);
736 if (bins[k+max].GetQ() <= q)
737 if ((bins[k+max].GetMask()&m) == 0) MarkPeak(k+max,max,bins,m);
738 if (bins[k+1 ].GetQ() <= q)
739 if ((bins[k+1 ].GetMask()&m) == 0) MarkPeak(k+1 ,max,bins,m);
742 void AliITSclustererV2::
743 MakeCluster(Int_t k,Int_t max,AliBin *bins,UInt_t m,AliITSclusterV2 &c) {
744 //------------------------------------------------------------
745 //make cluster using digits of this peak
746 //------------------------------------------------------------
747 Float_t q=(Float_t)bins[k].GetQ();
748 Int_t i=k/max, j=k-i*max;
751 c.SetY(c.GetY()+i*q);
752 c.SetZ(c.GetZ()+j*q);
753 c.SetSigmaY2(c.GetSigmaY2()+i*i*q);
754 c.SetSigmaZ2(c.GetSigmaZ2()+j*j*q);
756 bins[k].SetMask(0xFFFFFFFE);
758 if (bins[k-max].GetMask() == m) MakeCluster(k-max,max,bins,m,c);
759 if (bins[k-1 ].GetMask() == m) MakeCluster(k-1 ,max,bins,m,c);
760 if (bins[k+max].GetMask() == m) MakeCluster(k+max,max,bins,m,c);
761 if (bins[k+1 ].GetMask() == m) MakeCluster(k+1 ,max,bins,m,c);
764 void AliITSclustererV2::
765 FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
766 const TClonesArray *digits, TClonesArray *clusters) {
767 //------------------------------------------------------------
768 // Actual SDD cluster finder
769 //------------------------------------------------------------
770 Int_t ncl=0; TClonesArray &cl=*clusters;
771 for (Int_t s=0; s<2; s++)
772 for (Int_t i=0; i<nMaxBin; i++) {
773 if (bins[s][i].IsUsed()) continue;
774 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
775 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
777 if (npeaks>30) continue;
778 if (npeaks==0) continue;
781 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
782 if (idx[k] < 0) continue; //this peak is already removed
783 for (l=k+1; l<npeaks; l++) {
784 if (idx[l] < 0) continue; //this peak is already removed
785 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
786 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
787 Int_t di=TMath::Abs(ki - li);
788 Int_t dj=TMath::Abs(kj - lj);
789 if (di>1 || dj>1) continue;
790 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
801 for (k=0; k<npeaks; k++) {
802 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
805 for (k=0; k<npeaks; k++) {
806 if (idx[k] < 0) continue; //removed peak
808 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
811 for (Int_t ilab=0;ilab<10;ilab++){
814 Int_t maxi=0,mini=0,maxj=0,minj=0;
815 //AliBin *bmax=&bins[s][idx[k]];
816 //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
818 for (Int_t di=-2; di<=2;di++)
819 for (Int_t dj=-3;dj<=3;dj++){
820 Int_t index = idx[k]+di+dj*nzBins;
821 if (index<0) continue;
822 if (index>=nMaxBin) continue;
823 AliBin *b=&bins[s][index];
824 if (TMath::Abs(b->GetQ())>max){
825 if (di>maxi) maxi=di;
826 if (di<mini) mini=di;
827 if (dj>maxj) maxj=dj;
828 if (dj<minj) minj=dj;
831 if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
832 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
833 for (Int_t itrack=0;itrack<10;itrack++){
834 Int_t track = (d->GetTracks())[itrack];
836 AddLabel(milab, track);
845 Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
846 Float_t w=par->GetPadPitchWidth(sec);
849 c.SetSigmaY2(c.GetSigmaY2()*0.108);
850 if (sec<par->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
852 s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
857 c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
858 if (sec<par->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
862 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
865 //Float_t s2 = c.GetSigmaY2()/c.GetQ() - y*y;
867 //s2 = c.GetSigmaZ2()/c.GetQ() - z*z;
870 y=(y-0.5)*fYpitchSDD;
872 y-=fYoffSDD; //delay ?
875 z=(z-0.5)*fZpitchSDD;
881 q/=12.7; //this WAS consistent with SSD. To be reassessed
883 Float_t hit[5] = {y, z, 0.0030*0.0030, 0.0020*0.0020, q};
884 Int_t info[3] = {maxj-minj+1, maxi-mini+1, fNlayer[fI]};
886 if (c.GetQ() < 20.) continue; //noise cluster
889 // AliBin *b=&bins[s][idx[k]];
890 // AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
893 //lab[0]=(d->GetTracks())[0];
894 //lab[1]=(d->GetTracks())[1];
895 //lab[2]=(d->GetTracks())[2];
902 AliITSclusterV2 *cc = new (cl[ncl]) AliITSclusterV2(milab,hit,info);
909 void AliITSclustererV2::
910 FindClustersSDD(const TClonesArray *digits, TClonesArray *clusters) {
911 //------------------------------------------------------------
912 // Actual SDD cluster finder
913 //------------------------------------------------------------
914 Int_t kNzBins = fNzSDD + 2;
915 const Int_t kMAXBIN=kNzBins*(fNySDD+2);
918 bins[0]=new AliBin[kMAXBIN];
919 bins[1]=new AliBin[kMAXBIN];
922 Int_t i, ndigits=digits->GetEntriesFast();
923 for (i=0; i<ndigits; i++) {
924 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
925 Int_t y=d->GetCoord2()+1; //y
926 Int_t z=d->GetCoord1()+1; //z
927 Int_t q=d->GetSignal();
931 bins[0][y*kNzBins+z].SetQ(q);
932 bins[0][y*kNzBins+z].SetMask(1);
933 bins[0][y*kNzBins+z].SetIndex(i);
936 bins[1][y*kNzBins+z].SetQ(q);
937 bins[1][y*kNzBins+z].SetMask(1);
938 bins[1][y*kNzBins+z].SetIndex(i);
942 FindClustersSDD(bins, kMAXBIN, kNzBins, digits, clusters);
949 void AliITSclustererV2::FindClustersSDD(AliITSRawStream* input,
950 TClonesArray** clusters)
952 //------------------------------------------------------------
953 // Actual SDD cluster finder for raw data
954 //------------------------------------------------------------
955 Int_t nClustersSDD = 0;
956 Int_t kNzBins = fNzSDD + 2;
957 Int_t kMaxBin = kNzBins * (fNySDD+2);
958 AliBin *binsSDDInit = new AliBin[kMaxBin];
959 AliBin *binsSDD1 = new AliBin[kMaxBin];
960 AliBin *binsSDD2 = new AliBin[kMaxBin];
961 AliBin *bins[2] = {NULL, NULL};
963 // read raw data input stream
965 Bool_t next = input->Next();
966 if (!next || input->IsNewModule()) {
967 Int_t iModule = input->GetPrevModuleID();
969 // when all data from a module was read, search for clusters
971 clusters[iModule] = new TClonesArray("AliITSclusterV2");
973 FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
974 Int_t nClusters = clusters[iModule]->GetEntriesFast();
975 nClustersSDD += nClusters;
976 bins[0] = bins[1] = NULL;
982 memcpy(binsSDD1,binsSDDInit,sizeof(AliBin)*kMaxBin);
983 memcpy(binsSDD2,binsSDDInit,sizeof(AliBin)*kMaxBin);
986 // fill the current digit into the bins array
987 if(input->GetSignal()>=3) {
988 Int_t iz = input->GetCoord1()+1;
989 Int_t side = ((iz <= fNzSDD) ? 0 : 1);
991 Int_t index = (input->GetCoord2()+1) * kNzBins + iz;
992 bins[side][index].SetQ(input->GetSignal());
993 bins[side][index].SetMask(1);
994 bins[side][index].SetIndex(index);
1000 delete[] binsSDDInit;
1002 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
1007 void AliITSclustererV2::
1008 FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
1009 Ali1Dcluster* pos, Int_t np,
1010 TClonesArray *clusters) {
1011 //------------------------------------------------------------
1012 // Actual SSD cluster finder
1013 //------------------------------------------------------------
1014 TClonesArray &cl=*clusters;
1016 Float_t tanp=fTanP, tann=fTanN;
1017 if (fI>fLastSSD1) {tann=fTanP; tanp=fTanN;}
1018 Int_t idet=fNdet[fI];
1021 Int_t negativepair[30000];
1022 Int_t cnegative[3000];
1024 Int_t positivepair[30000];
1025 Int_t cpositive[3000];
1027 for (Int_t i=0;i<3000;i++) {cnegative[i]=0; cused1[i]=0;}
1028 for (Int_t i=0;i<3000;i++) {cpositive[i]=0; cused2[i]=0;}
1029 for (Int_t i=0;i<30000;i++){negativepair[i]=positivepair[i]=0;}
1030 static Short_t pairs[1000][1000];
1031 memset(pairs,0,sizeof(Short_t)*1000000);
1032 // Short_t ** pairs = new Short_t*[1000];
1033 // for (Int_t i=0; i<1000; i++) {
1034 // pairs[i] = new Short_t[1000];
1035 // memset(pairs[i],0,sizeof(Short_t)*1000);
1038 // find available pairs
1040 for (Int_t i=0; i<np; i++) {
1041 Float_t yp=pos[i].GetY()*fYpitchSSD;
1042 if (pos[i].GetQ()<3) continue;
1043 for (Int_t j=0; j<nn; j++) {
1044 if (neg[j].GetQ()<3) continue;
1045 Float_t yn=neg[j].GetY()*fYpitchSSD;
1046 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1047 Float_t yt=yn + tann*zt;
1048 zt-=fHlSSD; yt-=fHwSSD;
1049 if (TMath::Abs(yt)<fHwSSD+0.01)
1050 if (TMath::Abs(zt)<fHlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
1051 negativepair[i*10+cnegative[i]] =j; //index
1052 positivepair[j*10+cpositive[j]] =i;
1053 cnegative[i]++; //counters
1060 for (Int_t i=0; i<np; i++) {
1061 Float_t yp=pos[i].GetY()*fYpitchSSD;
1062 if (pos[i].GetQ()<3) continue;
1063 for (Int_t j=0; j<nn; j++) {
1064 if (neg[j].GetQ()<3) continue;
1065 if (cpositive[j]&&cnegative[i]) continue;
1066 Float_t yn=neg[j].GetY()*fYpitchSSD;
1067 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1068 Float_t yt=yn + tann*zt;
1069 zt-=fHlSSD; yt-=fHwSSD;
1070 if (TMath::Abs(yt)<fHwSSD+0.1)
1071 if (TMath::Abs(zt)<fHlSSD+0.15) {
1072 if (cnegative[i]==0) pos[i].SetNd(100); // not available pair
1073 if (cpositive[j]==0) neg[j].SetNd(100); // not available pair
1074 negativepair[i*10+cnegative[i]] =j; //index
1075 positivepair[j*10+cpositive[j]] =i;
1076 cnegative[i]++; //counters
1090 for (Int_t ip=0;ip<np;ip++){
1091 Float_t ybest=1000,zbest=1000,qbest=0;
1093 // select gold clusters
1094 if ( (cnegative[ip]==1) && cpositive[negativepair[10*ip]]==1){
1095 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1096 Int_t j = negativepair[10*ip];
1097 ratio = (pos[ip].GetQ()-neg[j].GetQ())/(pos[ip].GetQ()+neg[j].GetQ());
1099 Float_t yn=neg[j].GetY()*fYpitchSSD;
1100 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1101 Float_t yt=yn + tann*zt;
1102 zt-=fHlSSD; yt-=fHwSSD;
1104 qbest=0.5*(pos[ip].GetQ()+neg[j].GetQ());
1105 lp[0]=-(-ybest+fYshift[fI]);
1106 lp[1]= -zbest+fZshift[fI];
1107 lp[2]=0.0025*0.0025; //SigmaY2
1108 lp[3]=0.110*0.110; //SigmaZ2
1111 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1112 for (Int_t ilab=0;ilab<3;ilab++){
1113 milab[ilab] = pos[ip].GetLabel(ilab);
1114 milab[ilab+3] = neg[j].GetLabel(ilab);
1117 CheckLabels2(milab);
1118 milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
1119 Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1120 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1122 cl2->SetChargeRatio(ratio);
1125 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1134 for (Int_t ip=0;ip<np;ip++){
1135 Float_t ybest=1000,zbest=1000,qbest=0;
1138 // select "silber" cluster
1139 if ( cnegative[ip]==1 && cpositive[negativepair[10*ip]]==2){
1140 Int_t in = negativepair[10*ip];
1141 Int_t ip2 = positivepair[10*in];
1142 if (ip2==ip) ip2 = positivepair[10*in+1];
1143 Float_t pcharge = pos[ip].GetQ()+pos[ip2].GetQ();
1144 if (TMath::Abs(pcharge-neg[in].GetQ())<10){
1147 if (pairs[ip][in]==100){ //
1148 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1149 Float_t yn=neg[in].GetY()*fYpitchSSD;
1150 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1151 Float_t yt=yn + tann*zt;
1152 zt-=fHlSSD; yt-=fHwSSD;
1153 ybest =yt; zbest=zt;
1154 qbest =pos[ip].GetQ();
1155 lp[0]=-(-ybest+fYshift[fI]);
1156 lp[1]= -zbest+fZshift[fI];
1157 lp[2]=0.0025*0.0025; //SigmaY2
1158 lp[3]=0.110*0.110; //SigmaZ2
1161 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1162 for (Int_t ilab=0;ilab<3;ilab++){
1163 milab[ilab] = pos[ip].GetLabel(ilab);
1164 milab[ilab+3] = neg[in].GetLabel(ilab);
1167 CheckLabels2(milab);
1168 ratio = (pos[ip].GetQ()-neg[in].GetQ())/(pos[ip].GetQ()+neg[in].GetQ());
1169 milab[3]=(((ip<<10) + in)<<10) + idet; // pos|neg|det
1170 Int_t info[3] = {pos[ip].GetNd(),neg[in].GetNd(),fNlayer[fI]};
1171 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1173 cl2->SetChargeRatio(ratio);
1176 if ((pos[ip].GetNd()+neg[in].GetNd())>6){ //multi cluster
1184 // if (!(cused1[ip2] || cused2[in])){ //
1185 if (pairs[ip2][in]==100){
1186 Float_t yp=pos[ip2].GetY()*fYpitchSSD;
1187 Float_t yn=neg[in].GetY()*fYpitchSSD;
1188 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1189 Float_t yt=yn + tann*zt;
1190 zt-=fHlSSD; yt-=fHwSSD;
1191 ybest =yt; zbest=zt;
1192 qbest =pos[ip2].GetQ();
1193 lp[0]=-(-ybest+fYshift[fI]);
1194 lp[1]= -zbest+fZshift[fI];
1195 lp[2]=0.0025*0.0025; //SigmaY2
1196 lp[3]=0.110*0.110; //SigmaZ2
1199 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1200 for (Int_t ilab=0;ilab<3;ilab++){
1201 milab[ilab] = pos[ip2].GetLabel(ilab);
1202 milab[ilab+3] = neg[in].GetLabel(ilab);
1205 CheckLabels2(milab);
1206 ratio = (pos[ip2].GetQ()-neg[in].GetQ())/(pos[ip2].GetQ()+neg[in].GetQ());
1207 milab[3]=(((ip2<<10) + in)<<10) + idet; // pos|neg|det
1208 Int_t info[3] = {pos[ip2].GetNd(),neg[in].GetNd(),fNlayer[fI]};
1209 AliITSclusterV2 *cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1211 cl2->SetChargeRatio(ratio);
1214 if ((pos[ip2].GetNd()+neg[in].GetNd())>6){ //multi cluster
1227 for (Int_t jn=0;jn<nn;jn++){
1228 if (cused2[jn]) continue;
1229 Float_t ybest=1000,zbest=1000,qbest=0;
1230 // select "silber" cluster
1231 if ( cpositive[jn]==1 && cnegative[positivepair[10*jn]]==2){
1232 Int_t ip = positivepair[10*jn];
1233 Int_t jn2 = negativepair[10*ip];
1234 if (jn2==jn) jn2 = negativepair[10*ip+1];
1235 Float_t pcharge = neg[jn].GetQ()+neg[jn2].GetQ();
1237 if (TMath::Abs(pcharge-pos[ip].GetQ())<10){
1240 // if (!(cused1[ip]||cused2[jn])){
1241 if (pairs[ip][jn]==100){
1242 Float_t yn=neg[jn].GetY()*fYpitchSSD;
1243 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1244 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1245 Float_t yt=yn + tann*zt;
1246 zt-=fHlSSD; yt-=fHwSSD;
1247 ybest =yt; zbest=zt;
1248 qbest =neg[jn].GetQ();
1249 lp[0]=-(-ybest+fYshift[fI]);
1250 lp[1]= -zbest+fZshift[fI];
1251 lp[2]=0.0025*0.0025; //SigmaY2
1252 lp[3]=0.110*0.110; //SigmaZ2
1255 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1256 for (Int_t ilab=0;ilab<3;ilab++){
1257 milab[ilab] = pos[ip].GetLabel(ilab);
1258 milab[ilab+3] = neg[jn].GetLabel(ilab);
1261 CheckLabels2(milab);
1262 ratio = (pos[ip].GetQ()-neg[jn].GetQ())/(pos[ip].GetQ()+neg[jn].GetQ());
1263 milab[3]=(((ip<<10) + jn)<<10) + idet; // pos|neg|det
1264 Int_t info[3] = {pos[ip].GetNd(),neg[jn].GetNd(),fNlayer[fI]};
1265 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1267 cl2->SetChargeRatio(ratio);
1270 if ((pos[ip].GetNd()+neg[jn].GetNd())>6){ //multi cluster
1277 // if (!(cused1[ip]||cused2[jn2])){
1278 if (pairs[ip][jn2]==100){
1279 Float_t yn=neg[jn2].GetY()*fYpitchSSD;
1280 Double_t yp=pos[ip].GetY()*fYpitchSSD;
1281 Double_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1282 Double_t yt=yn + tann*zt;
1283 zt-=fHlSSD; yt-=fHwSSD;
1284 ybest =yt; zbest=zt;
1285 qbest =neg[jn2].GetQ();
1286 lp[0]=-(-ybest+fYshift[fI]);
1287 lp[1]= -zbest+fZshift[fI];
1288 lp[2]=0.0025*0.0025; //SigmaY2
1289 lp[3]=0.110*0.110; //SigmaZ2
1292 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1293 for (Int_t ilab=0;ilab<3;ilab++){
1294 milab[ilab] = pos[ip].GetLabel(ilab);
1295 milab[ilab+3] = neg[jn2].GetLabel(ilab);
1298 CheckLabels2(milab);
1299 ratio = (pos[ip].GetQ()-neg[jn2].GetQ())/(pos[ip].GetQ()+neg[jn2].GetQ());
1300 milab[3]=(((ip<<10) + jn2)<<10) + idet; // pos|neg|det
1301 Int_t info[3] = {pos[ip].GetNd(),neg[jn2].GetNd(),fNlayer[fI]};
1302 AliITSclusterV2* cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1304 cl2->SetChargeRatio(ratio);
1307 if ((pos[ip].GetNd()+neg[jn2].GetNd())>6){ //multi cluster
1319 for (Int_t ip=0;ip<np;ip++){
1320 Float_t ybest=1000,zbest=1000,qbest=0;
1324 if ( (cnegative[ip]<5) && cpositive[negativepair[10*ip]]<5){
1325 Float_t minchargediff =4.;
1327 for (Int_t di=0;di<cnegative[ip];di++){
1328 Int_t jc = negativepair[ip*10+di];
1329 Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1330 if (TMath::Abs(chargedif)<minchargediff){
1332 minchargediff = TMath::Abs(chargedif);
1335 if (j<0) continue; // not proper cluster
1337 for (Int_t di=0;di<cnegative[ip];di++){
1338 Int_t jc = negativepair[ip*10+di];
1339 Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1340 if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1342 if (count>1) continue; // more than one "proper" cluster for positive
1345 for (Int_t dj=0;dj<cpositive[j];dj++){
1346 Int_t ic = positivepair[j*10+dj];
1347 Float_t chargedif = pos[ic].GetQ()-neg[j].GetQ();
1348 if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1350 if (count>1) continue; // more than one "proper" cluster for negative
1355 for (Int_t dj=0;dj<cnegative[jp];dj++){
1356 Int_t ic = positivepair[jp*10+dj];
1357 Float_t chargedif = pos[ic].GetQ()-neg[jp].GetQ();
1358 if (TMath::Abs(chargedif)<minchargediff+4.) count++;
1360 if (count>1) continue;
1361 if (pairs[ip][j]<100) continue;
1363 //almost gold clusters
1364 Float_t yp=pos[ip].GetY()*fYpitchSSD;
1365 Float_t yn=neg[j].GetY()*fYpitchSSD;
1366 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1367 Float_t yt=yn + tann*zt;
1368 zt-=fHlSSD; yt-=fHwSSD;
1370 qbest=0.5*(pos[ip].GetQ()+neg[j].GetQ());
1371 lp[0]=-(-ybest+fYshift[fI]);
1372 lp[1]= -zbest+fZshift[fI];
1373 lp[2]=0.0025*0.0025; //SigmaY2
1374 lp[3]=0.110*0.110; //SigmaZ2
1376 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1377 for (Int_t ilab=0;ilab<3;ilab++){
1378 milab[ilab] = pos[ip].GetLabel(ilab);
1379 milab[ilab+3] = neg[j].GetLabel(ilab);
1382 CheckLabels2(milab);
1383 ratio = (pos[ip].GetQ()-neg[j].GetQ())/(pos[ip].GetQ()+neg[j].GetQ());
1384 milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
1385 Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1386 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1388 cl2->SetChargeRatio(ratio);
1391 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1402 for (Int_t i=0; i<np; i++) {
1403 Float_t ybest=1000,zbest=1000,qbest=0;
1404 Float_t yp=pos[i].GetY()*fYpitchSSD;
1405 if (pos[i].GetQ()<3) continue;
1406 for (Int_t j=0; j<nn; j++) {
1407 // for (Int_t di = 0;di<cpositive[i];di++){
1408 // Int_t j = negativepair[10*i+di];
1409 if (neg[j].GetQ()<3) continue;
1410 if (cused2[j]||cused1[i]) continue;
1411 if (pairs[i][j]>0 &&pairs[i][j]<100) continue;
1412 ratio = (pos[i].GetQ()-neg[j].GetQ())/(pos[i].GetQ()+neg[j].GetQ());
1413 Float_t yn=neg[j].GetY()*fYpitchSSD;
1414 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1415 Float_t yt=yn + tann*zt;
1416 zt-=fHlSSD; yt-=fHwSSD;
1417 if (TMath::Abs(yt)<fHwSSD+0.01)
1418 if (TMath::Abs(zt)<fHlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
1420 qbest=0.5*(pos[i].GetQ()+neg[j].GetQ());
1421 lp[0]=-(-ybest+fYshift[fI]);
1422 lp[1]= -zbest+fZshift[fI];
1423 lp[2]=0.0025*0.0025; //SigmaY2
1424 lp[3]=0.110*0.110; //SigmaZ2
1427 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1428 for (Int_t ilab=0;ilab<3;ilab++){
1429 milab[ilab] = pos[i].GetLabel(ilab);
1430 milab[ilab+3] = neg[j].GetLabel(ilab);
1433 CheckLabels2(milab);
1434 milab[3]=(((i<<10) + j)<<10) + idet; // pos|neg|det
1435 Int_t info[3] = {pos[i].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1436 AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1438 cl2->SetChargeRatio(ratio);
1439 cl2->SetType(100+cpositive[j]+cnegative[i]);
1442 if (pairs[i][j]<100){
1443 printf("problem:- %d\n", pairs[i][j]);
1445 if (cnegative[i]<2&&cpositive[j]<2){
1446 printf("problem:- %d\n", pairs[i][j]);
1453 // for (Int_t i=0; i<1000; i++) delete [] pairs[i];
1459 void AliITSclustererV2::
1460 FindClustersSSD(const TClonesArray *alldigits, TClonesArray *clusters) {
1461 //------------------------------------------------------------
1462 // Actual SSD cluster finder
1463 //------------------------------------------------------------
1464 Int_t smaxall=alldigits->GetEntriesFast();
1465 if (smaxall==0) return;
1466 TObjArray *digits = new TObjArray;
1467 for (Int_t i=0;i<smaxall; i++){
1468 AliITSdigitSSD *d=(AliITSdigitSSD*)alldigits->UncheckedAt(i);
1469 if (d->GetSignal()<3) continue;
1472 Int_t smax = digits->GetEntriesFast();
1473 if (smax==0) return;
1475 const Int_t MAX=1000;
1477 Ali1Dcluster pos[MAX], neg[MAX];
1478 Float_t y=0., q=0., qmax=0.;
1479 Int_t lab[4]={-2,-2,-2,-2};
1481 AliITSdigitSSD *d=(AliITSdigitSSD*)digits->UncheckedAt(0);
1482 q += d->GetSignal();
1483 y += d->GetCoord2()*d->GetSignal();
1484 qmax=d->GetSignal();
1485 lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
1486 Int_t curr=d->GetCoord2();
1487 Int_t flag=d->GetCoord1();
1489 Ali1Dcluster *c=neg;
1492 for (Int_t ilab=0;ilab<10;ilab++){
1495 milab[0]=d->GetTrack(0); milab[1]=d->GetTrack(1); milab[2]=d->GetTrack(2);
1497 for (Int_t s=1; s<smax; s++) {
1498 d=(AliITSdigitSSD*)digits->UncheckedAt(s);
1499 Int_t strip=d->GetCoord2();
1500 if ((strip-curr) > 1 || flag!=d->GetCoord1()) {
1504 CheckLabels2(milab);
1505 c[*n].SetLabels(milab);
1506 //Split suspiciously big cluster
1509 c[*n].SetY(y/q-0.3*nd);
1513 Error("FindClustersSSD","Too many 1D clusters !");
1516 c[*n].SetY(y/q-0.0*nd);
1521 Error("FindClustersSSD","Too many 1D clusters !");
1525 c[*n].SetY(y/q+0.3*nd);
1528 c[*n].SetLabels(milab);
1533 c[*n].SetY(y/q-0.25*nd);
1537 Error("FindClustersSSD","Too many 1D clusters !");
1540 c[*n].SetY(y/q+0.25*nd);
1543 c[*n].SetLabels(milab);
1547 Error("FindClustersSSD","Too many 1D clusters !");
1552 lab[0]=lab[1]=lab[2]=-2;
1554 for (Int_t ilab=0;ilab<10;ilab++){
1558 if (flag!=d->GetCoord1()) { n=&np; c=pos; }
1560 flag=d->GetCoord1();
1561 q += d->GetSignal();
1562 y += d->GetCoord2()*d->GetSignal();
1564 if (d->GetSignal()>qmax) {
1565 qmax=d->GetSignal();
1566 lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
1568 for (Int_t ilab=0;ilab<10;ilab++) {
1569 if (d->GetTrack(ilab)>=0) AddLabel(milab, (d->GetTrack(ilab)));
1576 c[*n].SetLabels(lab);
1577 //Split suspiciously big cluster
1578 if (nd>4 && nd<25) {
1579 c[*n].SetY(y/q-0.25*nd);
1583 Error("FindClustersSSD","Too many 1D clusters !");
1586 c[*n].SetY(y/q+0.25*nd);
1589 c[*n].SetLabels(lab);
1593 Error("FindClustersSSD","Too many 1D clusters !");
1597 FindClustersSSD(neg, nn, pos, np, clusters);
1600 void AliITSclustererV2::FindClustersSSD(AliITSRawStream* input,
1601 TClonesArray** clusters)
1603 //------------------------------------------------------------
1604 // Actual SSD cluster finder for raw data
1605 //------------------------------------------------------------
1606 Int_t nClustersSSD = 0;
1607 const Int_t MAX = 1000;
1608 Ali1Dcluster clusters1D[2][MAX];
1609 Int_t nClusters[2] = {0, 0};
1610 Int_t lab[3]={-2,-2,-2};
1614 Int_t prevStrip = -1;
1615 Int_t prevFlag = -1;
1616 Int_t prevModule = -1;
1618 // read raw data input stream
1620 Bool_t next = input->Next();
1622 if(input->GetSignal()<3 && next) continue;
1623 // check if a new cluster starts
1624 Int_t strip = input->GetCoord2();
1625 Int_t flag = input->GetCoord1();
1626 if ((!next || (input->GetModuleID() != prevModule)||
1627 (strip-prevStrip > 1) || (flag != prevFlag)) &&
1629 if (nClusters[prevFlag] == MAX) {
1630 Error("FindClustersSSD", "Too many 1D clusters !");
1633 Ali1Dcluster& cluster = clusters1D[prevFlag][nClusters[prevFlag]++];
1636 cluster.SetNd(nDigits);
1637 cluster.SetLabels(lab);
1639 //Split suspiciously big cluster
1640 if (nDigits > 4&&nDigits < 25) {
1641 cluster.SetY(y/q - 0.25*nDigits);
1642 cluster.SetQ(0.5*q);
1643 if (nClusters[prevFlag] == MAX) {
1644 Error("FindClustersSSD", "Too many 1D clusters !");
1647 Ali1Dcluster& cluster2 = clusters1D[prevFlag][nClusters[prevFlag]++];
1648 cluster2.SetY(y/q + 0.25*nDigits);
1649 cluster2.SetQ(0.5*q);
1650 cluster2.SetNd(nDigits);
1651 cluster2.SetLabels(lab);
1657 if (!next || (input->GetModuleID() != prevModule)) {
1658 Int_t iModule = prevModule;
1660 // when all data from a module was read, search for clusters
1661 if (prevFlag >= 0) {
1662 clusters[iModule] = new TClonesArray("AliITSclusterV2");
1664 FindClustersSSD(&clusters1D[0][0], nClusters[0],
1665 &clusters1D[1][0], nClusters[1], clusters[iModule]);
1666 Int_t nClusters = clusters[iModule]->GetEntriesFast();
1667 nClustersSSD += nClusters;
1671 nClusters[0] = nClusters[1] = 0;
1676 // add digit to current cluster
1677 q += input->GetSignal();
1678 y += strip * input->GetSignal();
1682 prevModule = input->GetModuleID();
1686 Info("FindClustersSSD", "found clusters in ITS SSD: %d", nClustersSSD);