108 #include<StMessMgr.h>
112 #include <TTableSorter.h>
114 #include "StPmdUtil/StPmdGeom.h"
115 #include "StPmdUtil/StPmdHit.h"
116 #include "StPmdClustering.h"
117 #include "StPmdClusterMaker.h"
118 #include "StPmdUtil/StPmdClusterCollection.h"
119 #include "StPmdUtil/StPmdCluster.h"
120 #include "StPmdUtil/StPmdModule.h"
121 #include "StPmdUtil/StPmdDetector.h"
123 #include "StThreeVectorD.hh"
124 #include "StHelixD.hh"
125 #include "StPhysicalHelixD.hh"
126 #include "StThreeVector.hh"
127 #include "StHelix.hh"
128 #include "SystemOfUnits.h"
129 #include "StEventTypes.h"
136 Double_t d1[96][72],clusters[6][6912], coord[2][96][72];
137 Double_t crd_org[2][96][72];
139 Int_t iord[2][6912], infocl[2][96][72], inford[3][6912], clno;
141 const Double_t pi=3.141592653, sqrth=sqrt(3.)/2.;
142 const Int_t nmx = 6912;
143 Float_t cell_frac[200][2000];
157 mOptCalibrate = kTRUE;
158 mOptSimulate = kFALSE;
159 mOptRefineCluster = kTRUE;
171 cout<<
"cutoff="<<cutoff<<endl;
177 Int_t i, i1, i2, j,xpad, ypad,nmx1, incr,idet;
183 coord[0][i][j]=i+j/2.; coord[1][i][j]=sqrth*j;
184 crd_org[0][i][j]=i; crd_org[1][i][j]=j;
188 for(Int_t
id=1;
id<=12;
id++)
192 memset(d1[0],0,96*72*
sizeof(Double_t));
202 TIter next(pmd_mod->Hits());
204 for(Int_t im=0; im<nmh; im++)
211 xpad=spmcl->Column();
214 if(mOptSimulate==kTRUE){edep = spmcl->Edep();}
215 gsuper = spmcl->Gsuper();
216 idet=spmcl->SubDetector();
221 if(mOptCalibrate==kTRUE){
223 Float_t cellgain=spmcl->GainCell();
224 Float_t smchaingain=spmcl->GainSmChain();
225 Float_t cellstatus=spmcl->CellStatus();
226 Float_t finalfactor = cellgain*smchaingain*cellstatus;
227 if(finalfactor>0)edep/=finalfactor;
228 if(finalfactor<=0)edep=0;
235 d1[xpad][ypad]=d1[xpad][ypad]+edep;
250 for(Int_t jj=0;jj<nmx; jj++)
252 i1=iord[0][jj]; i2=iord[1][jj];
253 if(d1[i1][i2] > 0.){nmx1=nmx1+1;ave=ave+d1[i1][i2];}
269 incr=
crclust(ave, cutoff, nmx1, idet);
274 if(incr<2000)
refclust(mdet,incr,
id, idet,pmdclus);
286 Float_t x0, y0, x, y,xc,yc,zc, cells;
288 xc = clusters[0][m];yc = clusters[1][m];
290 cells = clusters[3][m];
292 Float_t clusigmaL = clusters[4][m];
293 Float_t clusigmaS = clusters[5][m];
295 Float_t cluedep=zc; y0 = yc/sqrth; x0 = xc - y0/2.;
296 Float_t clueta,cluphi;
300 if(mVertexPos.x()==0 && mVertexPos.y()==0 && mVertexPos.z()==0) {
302 geom->DetCell_xy(i,y0+1,x0+1,x,y,clueta,cluphi);
306 geom->DetCell_xy(i,y0+1,x0+1,x,y,clueta,cluphi);
307 Float_t xwrtv = x-mVertexPos.x();
308 Float_t ywrtv = y-mVertexPos.y();
311 Float_t zreal = -geom->GetPmdZ();
312 Float_t zwrtv = zreal-mVertexPos.z();
316 Cluster_Eta_Phi(xwrtv,ywrtv,zwrtv,clueta,cluphi);
325 pclust->setCluEdep(cluedep);
326 pclust->setCluEta(clueta);
327 pclust->setCluPhi(cluphi);
328 pclust->setCluSigmaL(clusigmaL);
329 pclust->setCluSigmaS(clusigmaS);
330 pclust->setNumofMems(cells);
341 for (
int i1=0; i1<96; i1++) {
342 for(
int i2=0; i2 < 72; i2++){
343 if (d1[i1][i2] > 0.) {
346 while ((j<curl) && (d[j]>=d1[i1][i2])) j++;
347 for (
int k=curl; k>j; k--) {
350 iord[0][k] = iord[0][l];
351 iord[1][k] = iord[1][l];
373 Int_t i, j, k, i1, itest, ihld1, ihld2, ihld3;
377 if(infocl[0][i][j] == 1){i1=i1+1;
378 inford[0][i1]=infocl[1][i][j]; inford[1][i1]=i; inford[2][i1]=j;
380 if(infocl[0][i][j] == 2){i1=i1+1;
381 inford[0][i1]=infocl[1][i][j]; inford[1][i1]=i; inford[2][i1]=j;
385 for(i=1; i < incr; i++){
386 itest=0; ihld1=inford[0][i]; ihld2=inford[1][i]; ihld3=inford[2][i];
388 if(itest == 0 && inford[0][j] > ihld1){
390 for(k=i-1; k>=j; k--){
391 inford[0][k+1]=inford[0][k]; inford[1][k+1]=inford[1][k];
392 inford[2][k+1]=inford[2][k];
394 inford[0][j]=ihld1; inford[1][j]=ihld2; inford[2][j]=ihld3;
407 Int_t clno, i, j, k, i1, i2, id, icl, ncl[2000], iordR[2000], itest, ihld;
409 Double_t x1, y1, z1, x2, y2, z2, rr;
410 Double_t x[2000], y[2000], z[2000];
411 Double_t x_org[2000], y_org[2000];
412 Double_t xc[2000], yc[2000], zc[2000], d[96][72],rcl[2000],rcs[2000],cells[2000];
424 for(i1=0; i1<96; i1++){
425 for(i2=0; i2<72; i2++){
426 d[i1][i2]=d1[i1][i2];
430 for(i=0; i<2000; i++){
440 for(i=0; i<2000; i++){
446 for(i=0; i<incr; i++)
448 if(inford[0][i] != nsupcl)
452 ncl[nsupcl]=ncl[nsupcl]+1;
457 for(i=0; i<=nsupcl; i++)
466 clno=clno+1; i1=inford[1][id]; i2=inford[2][id];
468 clusters[0][clno]=coord[0][i1][i2];
469 clusters[1][clno]=coord[1][i1][i2];
470 clusters[2][clno]=d[i1][i2];
471 clusters[3][clno]=1.;
472 clusters[4][clno]=0.;
473 clusters[5][clno]=0.;
477 pmdclus->addCluster(pclust);
482 StPmdHit* phit =
GetHit(m_pmd_det0,supmod,crd_org[0][i1][i2],crd_org[1][i1][i2]);
483 if(phit)pclust->addHitCollection(phit);
496 pmdclus->addCluster(pclust);
498 clno=clno+1; i1=inford[1][id]; i2=inford[2][id];
499 x1=coord[0][i1][i2]; y1=coord[1][i1][i2]; z1=d[i1][i2];
503 StPmdHit* phit =
GetHit(m_pmd_det0,supmod,crd_org[0][i1][i2],crd_org[1][i1][i2]);
504 if(phit)pclust->addHitCollection(phit);
506 id=
id+1; i1=inford[1][id]; i2=inford[2][id];
507 x2=coord[0][i1][i2]; y2=coord[1][i1][i2]; z2=d[i1][i2];
511 phit =
GetHit(m_pmd_det0,supmod,crd_org[0][i1][i2],crd_org[1][i1][i2]);
512 if(phit)pclust->addHitCollection(phit);
515 Double_t xcell[2],ycell[2],zcell[2],xcl[2000],ycl[2000];
523 xcl[i] = (x1*z1+x2*z2)/(z1+z2);
524 ycl[i] = (y1*z1+y2*z2)/(z1+z2);
525 Double_t sumxx,sumyy,sumxy;
526 sumxx = 0.; sumyy = 0.; sumxy = 0.;
529 sumxx = sumxx + zcell[j]*(xcell[j]-xcl[i])*(xcell[j]-xcl[i])/(z1+z2);
530 sumyy = sumyy + zcell[j]*(ycell[j]-ycl[i])*(ycell[j]-ycl[i])/(z1+z2);
531 sumxy = sumxy + zcell[j]*(xcell[j]-xcl[i])*(ycell[j]-ycl[i])/(z1+z2);
533 Double_t b1 = sumxx + sumyy;
534 Double_t c1 = sumxx*sumyy - sumxy*sumxy;
535 Double_t dis = b1*b1/4.-c1;
536 if (fabs(dis) < 1e-6) dis = 0.;
538 Double_t r1=b1/2.+dis;
539 Double_t r2=b1/2.-dis;
546 clusters[4][clno] = r2;
547 clusters[5][clno] = r1;
551 clusters[4][clno] = r1;
552 clusters[5][clno] = r2;
555 clusters[0][clno]=(x1*z1+x2*z2)/(z1+z2);
556 clusters[1][clno]=(y1*z1+y2*z2)/(z1+z2);
557 clusters[2][clno]=z1+z2;
558 clusters[3][clno]=2.;
569 i1=inford[1][id]; i2=inford[2][id];
570 x[0]=coord[0][i1][i2]; y[0]=coord[1][i1][i2]; z[0]=d[i1][i2];iordR[0]=0;
571 x_org[0]=crd_org[0][i1][i2]; y_org[0]=crd_org[1][i1][i2];
572 for(j=1;j<=ncl[i];j++)
575 i1=inford[1][id]; i2=inford[2][id];iordR[j]=j;
576 x[j]=coord[0][i1][i2]; y[j]=coord[1][i1][i2]; z[j]=d[i1][i2];
577 x_org[j]=crd_org[0][i1][i2]; y_org[j]=crd_org[1][i1][i2];
580 for(j=1;j<=ncl[i];j++)
582 itest=0; ihld=iordR[j];
584 if(itest == 0 && z[iordR[i1]] < z[ihld]){
586 for(i2=j-1;i2>=i1;i2--){
587 iordR[i2+1]=iordR[i2];
595 xc[ig]=x[iordR[0]]; yc[ig]=y[iordR[0]]; zc[ig]=z[iordR[0]];
601 if(mOptRefineCluster==kTRUE){
603 for(j=1;j<=ncl[i];j++)
605 itest=-1; x1=x[iordR[j]]; y1=y[iordR[j]];
608 x2=xc[k]; y2=yc[k]; rr=
Dist(x1,y1,x2,y2);
610 if( rr >= 1.1 && rr < 1.8 && z[iordR[j]] > zc[k]*0.30)itest=itest+1;
611 if( rr >= 1.8 && rr < 2.1 && z[iordR[j]] > zc[k]*0.15)itest=itest+1;
612 if( rr >= 2.1 && rr < 2.8 && z[iordR[j]] > zc[k]*0.05)itest=itest+1;
613 if( rr >= 2.8)itest=itest+1;
617 ig=ig+1; xc[ig]=x1; yc[ig]=y1; zc[ig]=z[iordR[j]];
625 memset(cell_frac[0],0,
sizeof(cell_frac));
628 Int_t censtat=
CentroidCal(ncl[i],ig,x[0],y[0],z[0],xc[0],yc[0],zc[0],rcl[0],rcs[0],cells[0]);
634 Int_t take_cell[2000];
635 for(Int_t jk=0; jk<2000; jk++)
643 for(Int_t pb=0;pb<=ig;pb++)
645 for(Int_t jk=0; jk<=ncl[i]; jk++)
647 if(cell_frac[pb][jk]>temp[jk])
650 temp[jk]=cell_frac[pb][jk];
664 clusters[0][clno]=xc[k];
665 clusters[1][clno]=yc[k];
666 clusters[2][clno]=zc[k];
667 clusters[3][clno]=cells[k];
668 clusters[4][clno]=rcl[k];
669 clusters[5][clno]=rcs[k];
670 if(clusters[3][clno]==1)
672 clusters[4][clno]=0.;
673 clusters[5][clno]=0.;
683 pmdclus->addCluster(pclust);
687 for(Int_t jk=0; jk<=ncl[i]; jk++)
700 if(phit)pclust->addHitCollection(phit);
718 Double_t &y,Double_t &z,Double_t &xc,
719 Double_t &yc,Double_t &zc,
720 Double_t &rcl,Double_t &rcs,Double_t &cells)
723 Int_t cluster[2000][10];
724 Double_t sum,sumx,sum1,sumy,sumxy,sumxx,sumyy;
725 Double_t rr,x1,y1,x2,y2,b,c,r1,r2;
726 Double_t xx[2000],yy[2000],zz[2000];
727 Double_t xxc[2000],yyc[2000];
728 Double_t zzct[2000],cellsc[2000];
729 Double_t str[2000],str1[2000], cln[2000];
730 Double_t xcl[2000], ycl[2000],clust_cell[200][2000];
733 if(nclust>=200 || ncell >=2000){
734 cout<<
"Number of cluster of Ncell crosses limit "<<nclust<<
" "<<ncell<<endl;
738 for(
int i=0;i<=nclust;i++)
745 for(
int i=0;i<=ncell;i++)
752 memset(clust_cell[0],0,200*2000*
sizeof(Double_t));
753 memset(cell_frac[0],0,200*2000*
sizeof(Float_t));
754 memset(cluster[0],0,2000*10*
sizeof(Int_t));
760 for(
int i=0;i<=ncell;i++)
766 for(
int j=0;j<=nclust;j++)
770 rr =
Dist(x1,y1,x2,y2);
779 if(cluster[i][0] ==0){
780 for(
int j=0;j<=nclust;j++){
783 rr=
Dist(x1,y1,x2,y2);
793 if(cluster[i][0] ==0){
794 for(
int j=0;j<=nclust;j++){
797 rr=
Dist(x1,y1,x2,y2);
807 if(cluster[i][0] ==0){
808 for(
int j=0;j<=nclust;j++){
811 rr=
Dist(x1,y1,x2,y2);
825 memset(str,0,2000*
sizeof(Double_t));
826 memset(str1,0,2000*
sizeof(Double_t));
828 for(
int i=0;i<=ncell;i++){
829 if(cluster[i][0]!=0){
831 for(
int j=1;j<=i1;j++){
833 str[i2] = str[i2] + zz[i]/i1;
838 for(
int k=0; k<5; k++){
839 for(
int i=0; i<=ncell; i++){
840 if(cluster[i][0] != 0){
843 for(
int j=1;j<=i1;j++){
844 sum = sum + str[cluster[i][j]];
846 for(
int j=1;j<=i1;j++){
848 str1[i2] = str1[i2] + zz[i]*str[i2]/sum;
849 clust_cell[i2][i] = zz[i]*str[i2]/sum;
853 for(
int j=0; j<=nclust; j++){
860 for(
int i=0;i<=nclust;i++){
861 sumx=0.;sumy=0.;sum=0.;sum1=0.;
862 for(
int j=0;j<=ncell;j++){
863 if(clust_cell[i][j] !=0){
865 sumx=sumx+clust_cell[i][j]*xx[j];
866 sumy=sumy+clust_cell[i][j]*yy[j];
867 sum=sum+clust_cell[i][j];
868 sum1=sum1+clust_cell[i][j]/zz[j];
870 cell_frac[i][j]=clust_cell[i][j]/zz[j];
878 xcl[i]=sumx/sum; ycl[i]=sumy/sum; cln[i]=sum1;
880 sumxx=0.; sumyy=0.; sumxy=0.;
881 for(
int j=0; j<=ncell; j++){
882 sumxx=sumxx+clust_cell[i][j]*(xx[j]-xcl[i])*(xx[j]-xcl[i])/sum;
883 sumyy=sumyy+clust_cell[i][j]*(yy[j]-ycl[i])*(yy[j]-ycl[i])/sum;
884 sumxy=sumxy+clust_cell[i][j]*(xx[j]-xcl[i])*(yy[j]-ycl[i])/sum;
887 c=sumxx*sumyy-sumxy*sumxy;
889 if (fabs(dis) < 1e-6) dis = 0.;
906 *(&cells + i) = cln[i];
913 sumx=0.; sumy=0.; sum=0.; sum1=0.;
915 for(
int j=0; j<=ncell; j++)
917 sumx=sumx+zz[j]*xx[j];
918 sumy=sumy+zz[j]*yy[j];
925 xcl[i]=sumx/sum; ycl[i]=sumy/sum; cln[i]=sum1; str[i]=sum;
927 sumxx=0.; sumyy=0.; sumxy=0.;
928 for(
int j=0; j<=ncell; j++)
930 sumxx=sumxx+zz[j]*(xx[j]-xcl[i])*(xx[j]-xcl[i])/sum;
931 sumyy=sumyy+zz[j]*(yy[j]-ycl[i])*(yy[j]-ycl[i])/sum;
932 sumxy=sumxy+zz[j]*(xx[j]-xcl[i])*(yy[j]-ycl[i])/sum;
937 c=sumxx*sumyy-sumxy*sumxy;
939 if (fabs(dis) < 1e-6) dis = 0.;
954 *(&cells + i) = cln[i];
968 return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
976 Double_t xx, yy, d[96][72];
977 Int_t i,j,k,id1,id2,icl,clust[2][3000], numcell, cellcount;
981 static Int_t neibx[6]={1,0,-1,-1,0,1}, neiby[6]={0,1,1,0,-1,-1};
984 memcpy(d,d1,96*72*
sizeof(Double_t));
986 for (j=0; j < 96; j++){
987 for(k=0; k < 72; k++){
988 for (i=0; i < 2; i++){infocl[i][j][k] = 0;}
992 for(i=0; i < nmx; i++){
993 id1=iord[0][i]; id2=iord[1][i];
994 if(d[id1][id2] <= cutoff){infocl[0][id1][id2]=-1;}
999 for(icell=0; icell <= nmx1; icell++){
1001 id1=iord[0][icell]; id2=iord[1][icell]; xx=id1+id2/2.; yy=sqrth*id2;
1002 if(infocl[0][id1][id2] == 0 ){
1008 icl=icl+1; numcell=0;
1009 for(i=0; i < 3000; i++){
1010 clust[0][i]=0; clust[1][i]=0;
1012 clust[0][numcell]=id1; clust[1][numcell]=id2;
1013 infocl[0][id1][id2]=1; infocl[1][id1][id2]=icl;
1016 jd1=id1+neibx[i]; jd2=id2+neiby[i];
1017 if( (jd1 >= 0 && jd1 < 96) && (jd2 >= 0 && jd2 < 72) &&
1018 d[jd1][jd2] > cutoff && infocl[0][jd1][jd2] == 0)
1020 numcell=numcell+1; clust[0][numcell]=jd1; clust[1][numcell]=jd2;
1021 infocl[0][jd1][jd2]=2; infocl[1][jd1][jd2]=icl;
1022 xx=jd1+jd2/2.; yy=sqrth*jd2;
1025 for(i=1;i < 3000;i++){
1026 if(clust[0][i] != 0){
1027 id1=clust[0][i]; id2=clust[1][i];
1028 for(j=0; j<6 ; j++){
1029 jd1=id1+neibx[j]; jd2=id2+neiby[j];
1030 if( (jd1 >= 0 && jd1 < 96) && (jd2 >= 0 && jd2 < 72) &&
1031 d[jd1][jd2] > cutoff && infocl[0][jd1][jd2] == 0 ){
1032 infocl[0][jd1][jd2]=2; infocl[1][jd1][jd2]=icl;
1034 clust[0][numcell]=jd1; clust[1][numcell]=jd2;
1035 xx=jd1+jd2/2.; yy=sqrth*jd2;
1040 cellcount=cellcount+numcell+1;
1051 Int_t xpad,ypad,super;
1054 TIter next(pmod->Hits());
1057 for(Int_t im=0; im<nmh; im++)
1062 xpad=spmcl->Column();
1063 super = spmcl->Gsuper();
1064 if(
int(yc+1)==ypad &&
int(xc+1)==xpad &&
id == super)
return spmcl;
1072 void StPmdClustering::Cluster_Eta_Phi(Float_t xreal,Float_t yreal,Float_t zreal,Float_t& eta,Float_t& phi){
1073 Float_t rdist = (TMath::Sqrt(xreal*xreal + yreal*yreal))/TMath::Abs(zreal);
1074 Float_t theta = TMath::ATan(rdist);
1077 if(theta !=0.){ eta = TMath::Log(TMath::Tan(0.5*theta));}
1079 if(yreal>0) {phi = 1.571428;}
1080 if(yreal<0) {phi = -1.571428;}
1082 if(xreal != 0) {phi = atan2(yreal,xreal);}
1090 cout<<
"cutoff in findPmdClusters2="<<cutoff<<endl;
1102 for(Int_t ism = 1; ism<=12; ism++){
1104 TClonesArray * mPmdSuperClusters =
new TClonesArray(
"TList",1000);
1113 if(nhits<=0)
continue;
1116 Int_t nSuperClusters = MakeSuperClusters(ism,pmd_mod,mPmdSuperClusters);
1120 if (nSuperClusters==0|| nSuperClusters > nhits){
1121 cout<<
"Warning!!! nent/nsuper "<<nhits<<
"/"<<nSuperClusters<<endl;
1122 cout<<
"The hits of this module will not be added to the outgoing TClonesArray of hits"<<endl;
1127 Int_t gotclusters = MakeClusters(mPmdSuperClusters);
1129 if (gotclusters==0){
1130 cout<<
" Did not get any clusters in this sm"<<endl;
1134 mPmdSuperClusters->Delete();
1135 delete mPmdSuperClusters;
1138 cout<<
"Number of clusters in findPmdClusters2 = "<<pmdclus->
Nclusters()<<endl;
1145 Int_t StPmdClustering::MakeSuperClusters(Int_t modnum,
StPmdModule * mpmdMod , TClonesArray* mPmdSuperClusters){
1147 Int_t Columnneigh[6] = {-1,-1,0,1,1,0};
1148 Int_t Rowneigh[6] = {0,1,1,0,-1,-1};
1154 Int_t hitmap[NRowMax][NColumnMax];
1155 Int_t Flag[NRowMax][NColumnMax];
1156 for( Int_t ncellX = 0; ncellX < NRowMax; ncellX++ ){
1157 for( Int_t ncellY = 0; ncellY < NColumnMax; ncellY++ ){
1158 hitmap[ncellX][ncellY]=-1;
1159 Flag[ncellX][ncellY]=0;
1163 TObjArray * PmdHits = mpmdMod->Hits();
1168 Int_t Ncell_mod = PmdHits->GetEntries();
1176 for (Int_t i = 0; i < Ncell_mod; i++){
1183 if((mPmdHit->
Row()>NRowMax||mPmdHit->
Row()<=0)||
1185 cout<<
"hit out of range :"<<mPmdHit->
Row()-1<<
"/"<<mPmdHit->
Column()-1<<endl;
1187 if (mPmdHit->
Edep() > cutoff ){
1188 hitmap[mPmdHit->
Row()-1][mPmdHit->
Column()-1]= i;
1193 hitmap[mPmdHit->
Row()-1][mPmdHit->
Column()-1] = -1;
1194 Flag[mPmdHit->
Row()-1][mPmdHit->
Column()-1]=2;
1202 if ((NWithin+NAccCut)!=Ncell_mod){
1203 cout<<
" Some hits outside hitmap NWithin/NAccCut/NTotal "<<
1204 NWithin<<
"/"<<NAccCut<<
"/"<<Ncell_mod<<endl;
1214 Int_t nPmdSuperCluster = -1;
1216 for(Int_t icell = 0; icell < Ncell_mod; icell++){
1219 if((mPmdHit->
Row()>NRowMax||mPmdHit->
Row()<=0)||
1221 cout<<
"hit out of range :"<<mPmdHit->
Row()-1<<
"/"<<mPmdHit->
Column()-1<<endl;
1225 if (Flag[mPmdHit->
Row()-1][mPmdHit->
Column()-1]==0){
1228 TList * mPmdSuperCluster = (TList*)mPmdSuperClusters->New(nPmdSuperCluster);
1230 TIter ClusterListIter(mPmdSuperCluster);
1232 mPmdSuperCluster->Add(mPmdHit);
1234 Flag[mPmdHit->
Row()-1][mPmdHit->
Column()-1]=1;
1237 for(Int_t k=0;k<mPmdSuperCluster->GetSize();k++){
1239 Int_t clusterhitRow = clusterhit->
Row();
1240 Int_t clusterhitColumn = clusterhit->
Column();
1241 if(Flag[clusterhitRow-1][clusterhitColumn-1]!=1) cout<<
"???????"<<endl;
1243 for( Int_t ineigh = 0;ineigh < 6; ineigh++ ){
1244 Int_t neighbourRow = clusterhitRow + Rowneigh[ineigh];
1245 Int_t neighbourColumn = clusterhitColumn + Columnneigh[ineigh];
1246 Int_t boundary = CheckBoundary(modnum,neighbourRow-1,neighbourColumn-1);
1248 if (boundary==0 && hitmap[neighbourRow-1][neighbourColumn-1]!=-1){
1252 StPmdHit* neighbour = (
StPmdHit*)PmdHits->At(hitmap[neighbourRow-1][neighbourColumn-1]);
1255 if (neighbour->
Edep()>cutoff
1256 && Flag[neighbourRow-1][neighbourColumn-1]==0){
1257 mPmdSuperCluster->Add(neighbour);
1260 Flag[neighbourRow-1][neighbourColumn-1]=1;
1267 if (mPmdSuperCluster->GetSize()>MaxSuperSize){
1268 cout<<
"The size of supercluster "<<mPmdSuperCluster->GetSize()<<
" exceeds MaxSuperSize("<<MaxSuperSize<<
")"<<endl;
1271 mPmdSuperCluster->Sort(0);
1278 Int_t Nentries = mPmdSuperClusters->GetEntries();
1287 Int_t StPmdClustering::MakeClusters(TClonesArray * mPmdSuperClusters)
1293 Int_t sum_nclusters = 0;
1296 for(Int_t i=0;i<mPmdSuperClusters->GetEntries();i++){
1298 TList *mPmdSuperCluster = (TList*)mPmdSuperClusters->At(i);
1299 Int_t ncell = mPmdSuperCluster->GetSize();
1305 cout<<
"zero cells in this supercluster!!!"<<endl;
1308 if ((ncell<3 && mOptRefineCluster==kTRUE)||(mOptRefineCluster==kFALSE)){
1313 pmdclus->addCluster(pcluster);
1314 Float_t hitfract[ncell];
1316 for(Int_t j = 0; j < ncell; j++ ){
1318 pcluster->addHitCollection(phit);
1322 BuildCluster(pcluster,hitfract);
1334 Int_t jLocalPeak[MaxLocalPeaks];
1335 for (Int_t j=0;j<MaxLocalPeaks;j++){
1339 Int_t *pLocalPeak = &jLocalPeak[0];
1342 nLocalPeak = GetLocalPeaks(pLocalPeak,mPmdSuperCluster);
1351 pmdclus->addCluster(pcluster);
1352 Float_t hitfract[nLocalPeak];
1355 for(Int_t ihit = 0;ihit<mPmdSuperCluster->GetEntries();ihit++){
1358 pcluster->addHitCollection(phit);
1360 Float_t nmem = BuildCluster(pcluster,hitfract);
1362 if(nmem==0) cout<<
" 1 local peak only so I have a cluster with "<<nmem<<
" cells"<<endl;
1365 if (nLocalPeak>1 && nLocalPeak<MaxLocalPeaks){
1366 sum_nclusters+=nLocalPeak;
1376 Bool_t broken = BreakSuperCluster(nLocalPeak,pLocalPeak,mPmdSuperCluster);
1380 cout<<
" too many local peaks I think"<<endl;
1385 cout<<
"Module cut due to nLocalPeaks>MaxLocalPeaks"<<endl;
1392 return sum_nclusters;
1402 void StPmdClustering::CellXY(Int_t row, Int_t
column, Float_t& xx, Float_t& yy){
1405 xx = (Float_t)(column + 0.5*row);
1406 yy = 0.5*sqrt(3.)*row;
1410 Int_t StPmdClustering::CheckBoundary(Int_t nmod,Int_t numRow, Int_t numColumn){
1411 if ((numRow>=0 && numRow< NRowMax) &&
1412 (numColumn>=0 && numColumn<NColumnMax))
1419 Int_t StPmdClustering::GetLocalPeaks(Int_t* jLocalPeak,TList *mPmdSuperCluster){
1421 Int_t nLocalPeak =-1;
1422 Int_t ncell = mPmdSuperCluster->GetSize();
1423 Float_t xLocalPeak[ncell];
1424 Float_t yLocalPeak[ncell];
1425 Float_t adcLocalPeak[ncell];
1429 if(nLocalPeak>=MaxLocalPeaks) cout<<
" Number of Local peaks is "<<nLocalPeak+1<<
" which exceeds the array size MaxLocalPeaks ="<<MaxLocalPeaks<<endl;
1431 Float_t hitx1 = 0; Float_t hity1 = 0;
1432 CellXY(phitj->
Row()-1,phitj->
Column()-1,hitx1,hity1);
1433 Int_t sm = phitj->
Gsuper();
1434 jLocalPeak[nLocalPeak] = 0;
1435 xLocalPeak[nLocalPeak] = hitx1;
1436 yLocalPeak[nLocalPeak] = hity1;
1437 adcLocalPeak[nLocalPeak] = phitj->
Edep();
1444 for (Int_t j = 1; j < ncell; j++){
1447 Float_t hitx = 0; Float_t hity = 0;
1448 CellXY(phitj->
Row()-1,phitj->
Column()-1,hitx,hity);
1451 for (Int_t k = 0; k <= nLocalPeak; k++){
1452 Float_t gap =
Dist(hitx,hity,xLocalPeak[k],yLocalPeak[k]);
1455 if( gap >= 1.1 && gap < 1.8 && phitj->Edep() > adcLocalPeak[k]*0.30) nclear++;
1456 if( gap >= 1.8 && gap < 2.1 && phitj->Edep() > adcLocalPeak[k]*0.15) nclear++;
1457 if( gap >= 2.1 && gap < 2.8 && phitj->Edep() > adcLocalPeak[k]*0.05) nclear++;
1458 if( gap >= 2.8 ) nclear++;
1460 if (nclear==nLocalPeak){
1463 if (nLocalPeak<MaxLocalPeaks){
1464 jLocalPeak[nLocalPeak] = j;
1465 xLocalPeak[nLocalPeak] = hitx;
1466 yLocalPeak[nLocalPeak] = hity;
1467 adcLocalPeak[nLocalPeak] = phitj->
Edep();
1469 cout<<
"number of local peaks is "<<nLocalPeak<<
" which is more than "<<MaxLocalPeaks<<
" for a supercluster of size ="<<ncell<<
" in sm number ="<<sm<<endl;
1474 return ++nLocalPeak;
1478 void StPmdClustering::Cell_eta_phi(Float_t xreal,Float_t yreal,Float_t& eta,Float_t& phi){
1481 xreal = xreal - mVertexPos.x();
1482 yreal = yreal - mVertexPos.y();
1483 Float_t zreal = -1.0*geom->GetPmdZ();
1484 zreal = zreal - mVertexPos.z();
1487 Float_t rdist = (TMath::Sqrt(xreal*xreal + yreal*yreal))/zreal;
1492 rdist=TMath::Abs(rdist);
1495 Float_t theta = TMath::ATan(rdist);
1496 if(theta !=0.)eta = flag*TMath::Log(TMath::Tan(0.5*theta));
1498 if(yreal>0) phi = TMath::Pi()/2.0;
1499 if(yreal<0) phi = -1.0*TMath::Pi()/2.0;
1501 if(xreal != 0) phi = atan2(yreal,xreal);
1508 Float_t StPmdClustering::BuildCluster(
StPmdCluster *pcluster,Float_t* hitfract){
1512 TObjArray* hitCollection = pcluster->HitCollection();
1513 Int_t ncell = hitCollection->GetEntries();
1515 Float_t adchit[ncell],xhit[ncell],yhit[ncell];
1516 Float_t SigmaL = 0, SigmaS = 0;
1517 Float_t cluX=0, cluY=0, cluAdc=0;
1518 Float_t eta=0,phi=0;
1525 Int_t nmod = phit->
Gsuper();
1529 Int_t nmodclu = 12*(2-det) + nmod;
1532 Float_t nmem = Float_t(ncell*1.0);
1533 pcluster->setNumofMems(nmem);
1546 geom->IntDetCell_xy(nmod,(phit->
Row()),(phit->
Column()),cluX,cluY,eta,phi);
1547 cluAdc = phit->
Edep()*1.0;
1553 Float_t sumx=0,sumy=0;
1554 for(Int_t j = 0; j < ncell; j++ ){
1556 if (!phit) cout<<
" Did not get the phit I was hoping for "<<endl;
1561 Float_t xreal=0,yreal=0;
1562 geom->IntDetCell_xy(nmod,(phit->
Row()),(phit->
Column()),xreal,yreal,eta,phi);
1563 adchit[j] = hitfract[j]*phit->
Edep();
1568 sumx+=adchit[j]*xhit[j];
1569 sumy+=adchit[j]*yhit[j];
1578 Float_t sumxx=0,sumxy=0,sumyy=0;
1579 for(Int_t j=0;j<ncell;j++){
1580 sumxx+=adchit[j]*(xhit[j]-cluX)*(xhit[j]-cluX)/cluAdc;
1581 sumyy+=adchit[j]*(yhit[j]-cluY)*(yhit[j]-cluY)/cluAdc;
1582 sumxy+=adchit[j]*(yhit[j]-cluY)*(xhit[j]-cluX)/cluAdc;
1585 Float_t b=sumxx+sumyy;
1586 Float_t c=sumxx*sumyy-sumxy*sumxy;
1588 Float_t r1=b/2.+sqrt(b*b/4.-c);
1589 Float_t r2=b/2.-sqrt(b*b/4.-c);
1598 if(ncell==2) SigmaS=0;
1602 Cell_eta_phi(cluX,cluY,eta,phi);
1606 pcluster->setCluSigmaS(SigmaS);
1607 pcluster->setCluSigmaL(SigmaL);
1609 pcluster->setCluEta(eta);
1610 pcluster->setCluPhi(phi);
1612 Float_t edep = cluAdc*1.0;
1613 pcluster->setCluEdep(edep);
1615 pcluster->setCluX(cluX);
1616 pcluster->setCluY(cluY);
1623 pcluster->setMcCluPID(mcpid);
1624 pcluster->setCluPID(pid);
1625 pcluster->setCluEdepPID(edeppid);
Int_t module_hit(Int_t)
module number
Bool_t findPmdClusters2(StPmdDetector *)
for Pmd clusters
Int_t Nclusters() const
destructor
void printclust(Int_t, Int_t, StPmdCluster *)
distance between two clusters
void setCluster(StPmdClusterCollection *)
number of clusters
StPmdHit * GetHit(StPmdDetector *, Int_t, Double_t, Double_t)
for getting hits of each cluster
Int_t Row() const
function for subdetector
Int_t Column() const
function for row
void findPmdClusters(StPmdDetector *)
for Pmd clusters
void order(Int_t)
for ordering
void setModule(Int_t)
hit collection
Int_t CentroidCal(Int_t, Int_t, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &)
for Calculating cluster properties, those clusters having more then two cells
void arrange(Int_t)
ordering
void refclust(StPmdDetector *, Int_t, Int_t, Int_t, StPmdClusterCollection *)
refined clustering
virtual ~StPmdClustering()
destructor
Int_t Gsuper() const
A destructor.
Int_t crclust(Double_t, Double_t, Int_t, Int_t)
crude clustering
Float_t Edep() const
function for col
StPmdModule * module(unsigned int)
number of hits
Int_t SubDetector() const
function for module
Double_t Dist(Double_t, Double_t, Double_t, Double_t)