- for(it=0;it<fMaxNofSamples;it++) {
-
- Int_t lclx = 0;
- Int_t xstart = 0;
- Int_t xstop = 0;
- Int_t id = 0;
- Int_t ilcl =0;
-
- for(m=0;m<mmax;m++) { // find the cluster inside the window
- id = it+m;
- if(id >= fMaxNofSamples) break; // ! no possible for the fadc
-
- if(fMap->TestHit(k,id) == kUnused) { // start of the cluster
- lclx += 1;
- if(lclx == 1) xstart = id;
-
- }
-
- if(lclx > 0 && fMap->TestHit(k,id) == kEmpty) {
- // end of cluster if a gap exists
- xstop = id-1;
- ilcl = 1;
- break;
- }
-
- } // end of m-loop
-
- if(lclx == 0 && ilcl == 0) it = id; // no cluster in the window,
- // continue the "it" loop
-
- if(id >= fMaxNofSamples && lclx == 0) break; // the x row finished
-
- if(id < fMaxNofSamples && ilcl == 0 && lclx > 0) {
- // cluster end is outside of the window,
- mmax += 5; // increase mmax and repeat the cluster
- // finding
- it -= 1;
- }
-
- if(id >= fMaxNofSamples && lclx > 0) { // the x row finished but
- xstop = fMaxNofSamples - 1; // the end cluster exists
- ilcl = 1;
- }
-
- // --- Calculate z and x coordinates for one dimensional clusters
-
- if(ilcl == 1) { // new cluster exists
- it = id;
- mmax = 10;
- nofFoundClusters++;
- Float_t clusterCharge = 0.;
- Float_t zpitch = fSegmentation->Dpz(k+1);
- Float_t clusterZ, dummyX;
- Int_t dummy=0;
- fSegmentation->GetPadCxz(dummy,k,dummyX,clusterZ);
- Float_t zstart = clusterZ - 0.5*zpitch;
- Float_t zstop = clusterZ + 0.5*zpitch;
- Float_t clusterX = 0.;
- Int_t xstartfull = xstart;
- Int_t xstopfull = xstop;
- Int_t clusterSizeX = lclx;
- Int_t clusterSizeZ = 1;
-
- Int_t its;
- for(its=xstart; its<=xstop; its++) {
- Int_t firedpixel=0;
- if (fMap->GetHitIndex(k,its)>=0) firedpixel=1;
- clusterCharge += firedpixel;
- clusterX +=its + 0.5;
- }
- Float_t fRphiPitch = fSegmentation->Dpx(dummy);
- clusterX /= (clusterSizeX/fRphiPitch); // center of gravity for x
-
-
- //printf("ClusterZ ClusterX %f %f \n",clusterZ, clusterX);
-
- // Int_t nclusters = fClusters->GetEntriesFast();
- // cout << nclusters << " clusters" << endl;
- // cout<< "Create point"<<endl;
-
- // Write the points (coordinates and some cluster information) to the
- // AliITSRawClusterSPD object
-
- AliITSRawClusterSPD *clust = new AliITSRawClusterSPD(clusterZ,clusterX,clusterCharge,clusterSizeZ,clusterSizeX,xstart,xstop,xstartfull,xstopfull,zstart,zstop,k);
- // fClusters->Add(point);
- iTS->AddCluster(0,clust);
- delete clust;
- // cout << "Cluster at Ladder: " << fLadder << ", Detector: " <<fDetector<<endl;
-
- // cout<<" end of cluster finding for Z pixel "<<endl;
-
- } // new cluster (ilcl=1)
- } // X direction loop (it)
- } // Z direction loop (k)
-
- //fMap->ClearMap();
- return;
-
-}
-
-//_____________________________________________________________________________
-void AliITSClusterFinderSPD::GroupClusters()
-{
- // Find two dimensional clusters, i.e. group one dimensional clusters
- // into two dimensional ones (go both in x and z directions).
-
- // get number of clusters for this module
- Int_t nofClusters = fClusters->GetEntriesFast();
- nofClusters -= fNclusters;
-
- AliITSRawClusterSPD *clusterI;
- AliITSRawClusterSPD *clusterJ;
-
- Int_t *label=new Int_t[nofClusters];
- Int_t i,j;
- for(i=0; i<nofClusters; i++) label[i] = 0;
- for(i=0; i<nofClusters; i++) {
- if(label[i] != 0) continue;
- for(j=i+1; j<nofClusters; j++) {
- if(label[j] != 0) continue;
- clusterI = (AliITSRawClusterSPD*) fClusters->At(i);
- clusterJ = (AliITSRawClusterSPD*) fClusters->At(j);
- Bool_t pair = clusterI->Brother(clusterJ,fDz,fDx);
- if(pair) {
-
- // if((clusterI->XStop() == clusterJ->XStart()-1)||(clusterI->XStart()==clusterJ->XStop()+1)) cout<<"!! Diagonal cluster"<<endl;
- /*
- cout << "clusters " << i << "," << j << " before grouping" << endl;
- clusterI->PrintInfo();
- clusterJ->PrintInfo();
- */
- clusterI->Add(clusterJ);
- // cout << "remove cluster " << j << endl;
- label[j] = 1;
- fClusters->RemoveAt(j);
- /*
- cout << "cluster " << i << " after grouping" << endl;
- clusterI->PrintInfo();
- */
- } // pair
- } // J clusters
- label[i] = 1;
- } // I clusters
- fClusters->Compress();
- // Int_t totalNofClusters = fClusters->GetEntriesFast();
- // cout << " Nomber of clusters at the group end ="<< totalNofClusters<<endl;
-
- delete [] label;
-
- return;
-
-
-}
-//_____________________________________________________________________________
-
-void AliITSClusterFinderSPD::TracksInCluster()
-{
-
- // Find tracks creating one cluster
-
- // get number of clusters for this module
- Int_t nofClusters = fClusters->GetEntriesFast();
- nofClusters -= fNclusters;
-
- //printf("nofClusters fNclusters %d %d\n",nofClusters,fNclusters); //commented 18-09-00
-
- Int_t i, ix, iz, jx, jz, xstart, xstop, zstart, zstop, nclx, nclz;
- // Int_t signal, track0, track1, track2;
- const Int_t trmax = 100;
- Int_t cltracks[trmax], itr, tracki, ii, is, js, ie, ntr, tr0, tr1, tr2;
-
- for(i=0; i<nofClusters; i++) {
- ii = 0;
- memset(cltracks,-1,sizeof(int)*trmax);
- tr0=tr1=tr2=-3;
-
- AliITSRawClusterSPD *clusterI = (AliITSRawClusterSPD*) fClusters->At(i);
- //printf("clusterI %p\n",clusterI); //commented 18-09-00
-
- nclx = clusterI->NclX();
- nclz = clusterI->NclZ();
- xstart = clusterI->XStartf();
- xstop = clusterI->XStopf();
- zstart = clusterI->Zend()-nclz+1;
- zstop = clusterI->Zend();
-
- Int_t ind;
-
- for(iz=0; iz<nclz; iz++) {
- jz = zstart + iz;
- for(ix=0; ix<nclx; ix++) {
- jx = xstart + ix;
- ind = fMap->GetHitIndex(jz,jx);
- //printf("ind %d\n",ind); // commented 18-09-00
- // this part must be wrong - the index of the digit
- // can be zero but not -1 !!! comment out this part
- // and replace it - see below
- /*
- if(ind == 0 && iz >= 0 && ix > 0) {
- continue;
- }
- if(ind == 0 && iz > 0 && ix >= 0) {
- continue;
- }
- if(ind == 0 && iz == 0 && ix == 0 && i > 0) {
- continue;
- }
- */
- // change the conditions above to :
- if (ind < 0) continue;
-
- AliITSdigitSPD *dig = (AliITSdigitSPD*)fMap->GetHit(jz,jx);
- if (!dig) printf("SPD: something wrong ! dig %p\n",dig);
- /*
- signal=dig->fSignal;
- track0=dig->fTracks[0];
- track1=dig->fTracks[1];
- track2=dig->fTracks[2];
- */
- for(itr=0; itr<3; itr++) {
- tracki = dig->fTracks[itr];
- //printf("tracki %d\n",tracki); //commented 18-09-00
- if(tracki >= 0) {
- ii += 1;
- cltracks[ii-1] = tracki;
- }
- }
- } // ix pixel
- } // iz pixel
-
- for(is=0; is<trmax; is++) {
- if(cltracks[is]<0) continue;
- for(js=is+1; js<trmax; js++) {
- if(cltracks[js]<0) continue;
- if(cltracks[js]==cltracks[is]) cltracks[js]=-5;
- }
- }
-
- ntr = 0;
- for(ie=0; ie<trmax; ie++) {
- if(cltracks[ie] >= 0) {
- ntr=ntr+1;
- if(ntr==1) tr0=cltracks[ie];
- if(ntr==2) tr1=cltracks[ie];
- if(ntr==3) tr2=cltracks[ie];
- }
- }
- // if delta ray only
- if(ntr == 0) ntr = 1;
-
- clusterI->SetNTracks(ntr);
- clusterI->SetTracks(tr0,tr1,tr2);
-
- } // I cluster
-
-}
-//_____________________________________________________________________________
-
-void AliITSClusterFinderSPD::GetRecPoints()
-{
- // get rec points
- AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
-
- // get number of clusters for this module
- Int_t nofClusters = fClusters->GetEntriesFast();
- nofClusters -= fNclusters;
- const Float_t kconv = 1.0e-4;
- const Float_t kRMSx = 12.0*kconv; // microns -> cm ITS TDR Table 1.3
- const Float_t kRMSz = 120.0*kconv; // resolution for 425 micron pixel
-
- Float_t spdLength = fSegmentation->Dz();
- Float_t spdWidth = fSegmentation->Dx();
-
- Int_t i;
- Int_t track0, track1, track2;
-
- for(i=0; i<nofClusters; i++) {
-
- AliITSRawClusterSPD *clusterI = (AliITSRawClusterSPD*) fClusters->At(i);
- clusterI->GetTracks(track0, track1, track2);
- AliITSRecPoint rnew;
-
- rnew.SetX((clusterI->X() - spdWidth/2)*kconv);
- rnew.SetZ((clusterI->Z() - spdLength/2)*kconv);
- rnew.SetQ(1.);
- rnew.SetdEdX(0.);
- rnew.SetSigmaX2(kRMSx*kRMSx);
- rnew.SetSigmaZ2(kRMSz*kRMSz);
- rnew.fTracks[0]=track0;
- rnew.fTracks[1]=track1;
- rnew.fTracks[2]=track2;
- iTS->AddRecPoint(rnew);
- } // I clusters
-
- fMap->ClearMap();
-
+ for (i=0 ; i < ndigits ; i++) iclus[ifpad[i]]++;
+
+ min=0;
+ max=0;
+ // loop on found clusters
+ for (i=0 ; i < nclus ; i++){
+ min = max;
+ max += iclus[i];
+ deltax = GetSeg()->Dpx(0);
+ if (iclus[i]!=1){
+ //cluster with more than one digit
+ nd=iclus[i];
+ ndig=(Double_t) nd;
+ Int_t count=0;
+ for (k=min;k<min+nd;k++){
+ xpad[count] = digx[k];
+ zpad[count] = digz[k];
+
+ tr1pad[count] = digtr1[k];
+ tr2pad[count] = digtr2[k];
+ tr3pad[count] = digtr3[k];
+ tr4pad[count] = digtr4[k];
+
+ count++;
+ } // end for k
+ ndxmin = xpad[TMath::LocMin(nd,xpad)];
+ ndxmax = xpad[TMath::LocMax(nd,xpad)];
+ ndzmin = zpad[TMath::LocMin(nd,zpad)];
+ ndzmax = zpad[TMath::LocMax(nd,zpad)];
+ ndx = ndxmax - ndxmin+1;
+ ndz = ndzmax - ndzmin+1;
+
+ // calculate x and z coordinates of the center of the cluster
+ GetSeg()->GetPadCxz(digx[min],digz[min]-1,xdum, zdum);
+
+ if (ndx == 1) {
+ xcenter[i] = xdum;
+ }else{
+ xcenter[i] = 0.;
+ for (k=0;k<nd;k++) {
+ GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
+ xcenter[i] += (xdum / nd);
+ } // end for k
+ } // end if ndx
+
+ if (ndz == 1) {
+ zcenter[i] = zdum;
+ } else {
+ zcenter[i] = 0.;
+ for (k=0;k<nd;k++) {
+ GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
+ zcenter[i] += (zdum / nd);
+ } // end for k
+ } // end if ndz
+
+ // error on points in x and z directions
+
+ if (ndx == 1) {
+ errxcenter[i] = deltax / TMath::Sqrt(12.);
+ } else {
+ errxcenter[i] = 0.;
+ for (k=0;k<nd;k++){
+ GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
+ errxcenter[i] += ((xdum-xcenter[i])*(xdum-xcenter[i]))/
+ (nd*(nd-1));
+ } // end for k
+ errxcenter[i] = TMath::Sqrt(errxcenter[i]);
+ } // end if ndx
+ if (ndz == 1) {
+ deltaz = GetSeg()->Dpz(digz[min]);
+ errzcenter[i] = deltaz / TMath::Sqrt(12.);
+ } else {
+ errzcenter[i] = 0.;
+ for (k=0;k<nd;k++){
+ GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
+ errzcenter[i] += ((zdum-zcenter[i])*(zdum-zcenter[i]))/
+ (nd*(nd-1));
+ } // end for k
+ errzcenter[i] = TMath::Sqrt(errzcenter[i]);
+ } // end if ndz
+ // take three track numbers for the cluster
+ // choose the track numbers of the digit with higher signal
+ kmax = 0;
+ sigmax = 0;
+ for (k=0;k<nd;k++){
+ if(tr4pad[k] > sigmax){
+ sigmax = tr4pad[k];
+ kmax = k;
+ } // end if tr4pad[k]
+ } // end for k
+ if(sigmax != 0) {
+ tr1clus[i]= tr1pad[kmax];
+ tr2clus[i]= tr2pad[kmax];
+ tr3clus[i]= tr3pad[kmax];
+ } else {
+ tr1clus[i]= -2;
+ tr2clus[i]= -2;
+ tr3clus[i]= -2;
+ } // end if sigmax
+ } else {
+ // cluster with single digit
+ ndig= 1.;
+ ndx = 1;
+ ndz = 1;
+ GetSeg()->GetPadCxz(digx[min],digz[min]-1,xdum,zdum);
+ xcenter[i] = xdum;
+ zcenter[i] = zdum;
+ tr1clus[i]=digtr1[min];
+ tr2clus[i]=digtr2[min];
+ tr3clus[i]=digtr3[min];
+ deltaz = GetSeg()->Dpz(digz[min]);
+ errxcenter[i] = deltax / TMath::Sqrt(12.);
+ errzcenter[i] = deltaz / TMath::Sqrt(12.);
+ } // end if iclus[i]
+
+ // store the cluster information to the AliITSRawCLusterSPD object
+
+
+ //put the cluster center in local reference frame of the detector
+ // and in microns
+ xcenter[i] = xcenter[i] - GetSeg()->Dx()/2.;
+ zcenter[i] = zcenter[i] - GetSeg()->Dz()/2.;
+
+ AliITSRawClusterSPD *clust = new AliITSRawClusterSPD(zcenter[i], //f
+ xcenter[i], //f
+ ndig, //f
+ ndz,ndx, //ii
+ ndxmin,ndxmax,//ii
+ (Double_t) ndzmin,
+ (Double_t) ndzmax,
+ 0,GetModule());
+ fDetTypeRec->AddCluster(0,clust);
+ delete clust;
+ }//end loop on clusters
+ delete[] ifpad;
+ delete[] xpad ;
+ delete[] zpad ;
+ delete[] iclus;
+ delete[] tr1pad;
+ delete[] tr2pad;
+ delete[] tr3pad;
+ delete[] tr4pad;