00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 #include<Stiostream.h>
00102 #include<assert.h>
00103 #include<math.h>
00104 #include"TROOT.h"
00105 #include<TRandom.h>
00106 #include<TBrowser.h>
00107 #include<TPad.h>
00108 #include<StMessMgr.h>
00109 #include<TFile.h>
00110
00111
00112 #include <TTableSorter.h>
00113
00114 #include "StPmdUtil/StPmdGeom.h"
00115 #include "StPmdUtil/StPmdHit.h"
00116 #include "StPmdClustering.h"
00117 #include "StPmdClusterMaker.h"
00118 #include "StPmdUtil/StPmdClusterCollection.h"
00119 #include "StPmdUtil/StPmdCluster.h"
00120 #include "StPmdUtil/StPmdModule.h"
00121 #include "StPmdUtil/StPmdDetector.h"
00122
00123 #include "StThreeVectorD.hh"
00124 #include "StHelixD.hh"
00125 #include "StPhysicalHelixD.hh"
00126 #include "StThreeVector.hh"
00127 #include "StHelix.hh"
00128 #include "SystemOfUnits.h"
00129 #include "StEventTypes.h"
00130 #include "StEvent.h"
00131
00132
00133
00134 ClassImp(StPmdClustering)
00135
00136 Double_t d1[96][72],clusters[6][6912], coord[2][96][72];
00137 Double_t crd_org[2][96][72];
00138
00139 Int_t iord[2][6912], infocl[2][96][72], inford[3][6912], clno;
00140
00141 const Double_t pi=3.141592653, sqrth=sqrt(3.)/2.;
00142 const Int_t nmx = 6912;
00143 Float_t cell_frac[200][2000];
00144
00145
00146
00147
00148 StPmdGeom *geom=new StPmdGeom();
00149
00151
00152 StPmdClustering::StPmdClustering(StPmdDetector *pmd_det, StPmdDetector *cpv_det):StPmdAbsClustering(pmd_det,cpv_det){
00153 m_pmd_det=pmd_det;
00154 m_cpv_det=cpv_det;
00155 SetAdcCutOff(7.0);
00156 mVertexPos = StThreeVectorF(0.,0.,0.);
00157 mOptCalibrate = kTRUE;
00158 mOptSimulate = kFALSE;
00159 mOptRefineCluster = kTRUE;
00160
00161 }
00162
00163
00164 StPmdClustering::~StPmdClustering()
00165 {
00166 }
00167
00169 void StPmdClustering::findPmdClusters(StPmdDetector *mdet)
00170 {
00171 cout<<"cutoff="<<cutoff<<endl;
00172 if(mdet)
00173 {
00174 StPmdClusterCollection * pmdclus = new StPmdClusterCollection();
00175 mdet->setCluster(pmdclus);
00176
00177 Int_t i, i1, i2, j,xpad, ypad,nmx1, incr,idet;
00178 Int_t gsuper;
00179 Double_t edep, ave;
00180
00181 for(i=0; i<96; i++){
00182 for(j=0;j<72;j++){
00183 coord[0][i][j]=i+j/2.; coord[1][i][j]=sqrth*j;
00184 crd_org[0][i][j]=i; crd_org[1][i][j]=j;
00185 }
00186 }
00187 i=0;
00188 for(Int_t id=1;id<=12;id++)
00189 {
00190
00192 memset(d1[0],0,96*72*sizeof(Double_t));
00193
00194 StPmdModule * pmd_mod=mdet->module(id);
00195
00196
00197 if(mdet->module_hit(id)>0)
00198 {
00199
00200 Int_t nmh=mdet->module_hit(id);
00201
00202 TIter next(pmd_mod->Hits());
00203 StPmdHit *spmcl;
00204 for(Int_t im=0; im<nmh; im++)
00205 {
00206
00207 spmcl = (StPmdHit*)next();
00208 if(spmcl)
00209 {
00210 ypad=spmcl->Row();
00211 xpad=spmcl->Column();
00212
00213 edep=spmcl->Adc();
00214 if(mOptSimulate==kTRUE){edep = spmcl->Edep();}
00215 gsuper = spmcl->Gsuper();
00216 idet=spmcl->SubDetector();
00217
00218 xpad = xpad -1;
00219 ypad = ypad -1;
00220
00221 if(mOptCalibrate==kTRUE){
00222
00223 Float_t cellgain=spmcl->GainCell();
00224 Float_t smchaingain=spmcl->GainSmChain();
00225 Float_t cellstatus=spmcl->CellStatus();
00226 Float_t finalfactor = cellgain*smchaingain*cellstatus;
00227 if(finalfactor>0)edep/=finalfactor;
00228 if(finalfactor<=0)edep=0;
00229 }
00230
00231
00232
00233
00234
00235 d1[xpad][ypad]=d1[xpad][ypad]+edep;
00236 }
00237 }
00238
00239 order(idet);
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 ave=0.; nmx1=0;
00250 for(Int_t jj=0;jj<nmx; jj++)
00251 {
00252 i1=iord[0][jj]; i2=iord[1][jj];
00253 if(d1[i1][i2] > 0.){nmx1=nmx1+1;ave=ave+d1[i1][i2];}
00254 }
00255
00256 if(nmx1>0){
00257 ave=ave/nmx1;
00258 nmx1--;
00259 }
00260
00262
00263
00264
00265
00266
00267
00268
00269 incr=crclust(ave, cutoff, nmx1, idet);
00270
00271 arrange(incr);
00272
00273
00274 if(incr<2000)refclust(mdet,incr, id, idet,pmdclus);
00275 }
00276 }
00277 }
00278 }
00279
00280
00281 void StPmdClustering::printclust(Int_t i,Int_t m, StPmdCluster* pclust)
00282 {
00283
00286 Float_t x0, y0, x, y,xc,yc,zc, cells;
00287
00288 xc = clusters[0][m];yc = clusters[1][m];
00289 zc = clusters[2][m];
00290 cells = clusters[3][m];
00291
00292 Float_t clusigmaL = clusters[4][m];
00293 Float_t clusigmaS = clusters[5][m];
00294
00295 Float_t cluedep=zc; y0 = yc/sqrth; x0 = xc - y0/2.;
00296 Float_t clueta,cluphi;
00297
00298
00299
00300 if(mVertexPos.x()==0 && mVertexPos.y()==0 && mVertexPos.z()==0) {
00301
00302 geom->DetCell_xy(i,y0+1,x0+1,x,y,clueta,cluphi);
00303
00304 }else{
00305
00306 geom->DetCell_xy(i,y0+1,x0+1,x,y,clueta,cluphi);
00307 Float_t xwrtv = x-mVertexPos.x();
00308 Float_t ywrtv = y-mVertexPos.y();
00309
00310
00311 Float_t zreal = -geom->GetPmdZ();
00312 Float_t zwrtv = zreal-mVertexPos.z();
00313
00314
00315
00316 Cluster_Eta_Phi(xwrtv,ywrtv,zwrtv,clueta,cluphi);
00317
00318 }
00319
00321
00322 pclust->setCluX(x);
00323 pclust->setCluY(y);
00324 pclust->setModule(i);
00325 pclust->setCluEdep(cluedep);
00326 pclust->setCluEta(clueta);
00327 pclust->setCluPhi(cluphi);
00328 pclust->setCluSigmaL(clusigmaL);
00329 pclust->setCluSigmaS(clusigmaS);
00330 pclust->setNumofMems(cells);
00331
00332 }
00333
00334
00336 void StPmdClustering::order(Int_t idet)
00337 {
00338 Double_t d[nmx];
00339 Int_t curl=0;
00340 Int_t curh=nmx-1;
00341 for (int i1=0; i1<96; i1++) {
00342 for(int i2=0; i2 < 72; i2++){
00343 if (d1[i1][i2] > 0.) {
00344
00345 int j = 0;
00346 while ((j<curl) && (d[j]>=d1[i1][i2])) j++;
00347 for (int k=curl; k>j; k--) {
00348 int l = k-1;
00349 d[k] = d[l];
00350 iord[0][k] = iord[0][l];
00351 iord[1][k] = iord[1][l];
00352 }
00353
00354 d[j] = d1[i1][i2];
00355 iord[0][j] = i1;
00356 iord[1][j] = i2;
00357 curl++;
00358 } else {
00359
00360 iord[0][curh] = i1;
00361 iord[1][curh] = i2;
00362 curh--;
00363 }
00364 }
00365 }
00366 }
00367
00368
00369
00371 void StPmdClustering::arrange(Int_t incr)
00372 {
00373 Int_t i, j, k, i1, itest, ihld1, ihld2, ihld3;
00374 i1=-1;
00375 for(i=0; i<96; i++){
00376 for(j=0; j<72; j++){
00377 if(infocl[0][i][j] == 1){i1=i1+1;
00378 inford[0][i1]=infocl[1][i][j]; inford[1][i1]=i; inford[2][i1]=j;
00379 }
00380 if(infocl[0][i][j] == 2){i1=i1+1;
00381 inford[0][i1]=infocl[1][i][j]; inford[1][i1]=i; inford[2][i1]=j;
00382 }
00383 }
00384 }
00385 for(i=1; i < incr; i++){
00386 itest=0; ihld1=inford[0][i]; ihld2=inford[1][i]; ihld3=inford[2][i];
00387 for(j=0; j<i; j++){
00388 if(itest == 0 && inford[0][j] > ihld1){
00389 itest=1;
00390 for(k=i-1; k>=j; k--){
00391 inford[0][k+1]=inford[0][k]; inford[1][k+1]=inford[1][k];
00392 inford[2][k+1]=inford[2][k];
00393 }
00394 inford[0][j]=ihld1; inford[1][j]=ihld2; inford[2][j]=ihld3;
00395 }
00396 }
00397 }
00398 }
00399
00400
00405 void StPmdClustering::refclust(StPmdDetector* m_pmd_det0,Int_t incr, Int_t supmod, Int_t idet,StPmdClusterCollection *pmdclus)
00406 {
00407 Int_t clno, i, j, k, i1, i2, id, icl, ncl[2000], iordR[2000], itest, ihld;
00408 Int_t ig, nsupcl;
00409 Double_t x1, y1, z1, x2, y2, z2, rr;
00410 Double_t x[2000], y[2000], z[2000];
00411 Double_t x_org[2000], y_org[2000];
00412 Double_t xc[2000], yc[2000], zc[2000], d[96][72],rcl[2000],rcs[2000],cells[2000];
00413
00414
00415
00416
00420
00421 clno=-1;
00422 nsupcl=-1;
00423
00424 for(i1=0; i1<96; i1++){
00425 for(i2=0; i2<72; i2++){
00426 d[i1][i2]=d1[i1][i2];
00427 }
00428 }
00429
00430 for(i=0; i<2000; i++){
00431 x[i]=0.;
00432 y[i]=0.;
00433 z[i]=0.;
00434 xc[i]=0.;
00435 yc[i]=0.;
00436 zc[i]=0.;
00437 }
00439
00440 for(i=0; i<2000; i++){
00441 ncl[i]=-1;
00442 rcl[i] = 0.;
00443 rcs[i] = 0.;
00444 cells[i] = 0.;
00445 }
00446 for(i=0; i<incr; i++)
00447 {
00448 if(inford[0][i] != nsupcl)
00449 {
00450 nsupcl=nsupcl+1;
00451 }
00452 ncl[nsupcl]=ncl[nsupcl]+1;
00453 }
00454 id=-1;
00455 icl=-1;
00456
00457 for(i=0; i<=nsupcl; i++)
00458 {
00459 Int_t countr = 0;
00460 if(ncl[i] == 0){
00461 id=id+1; icl=icl+1;
00462
00463 countr +=1;
00465
00466 clno=clno+1; i1=inford[1][id]; i2=inford[2][id];
00467
00468 clusters[0][clno]=coord[0][i1][i2];
00469 clusters[1][clno]=coord[1][i1][i2];
00470 clusters[2][clno]=d[i1][i2];
00471 clusters[3][clno]=1.;
00472 clusters[4][clno]=0.;
00473 clusters[5][clno]=0.;
00474
00475
00476 StPmdCluster *pclust = new StPmdCluster();
00477 pmdclus->addCluster(pclust);
00478
00479 printclust(supmod,clno,pclust);
00480
00481
00482 StPmdHit* phit = GetHit(m_pmd_det0,supmod,crd_org[0][i1][i2],crd_org[1][i1][i2]);
00483 if(phit)pclust->addHitCollection(phit);
00484
00485 }
00486
00487
00488
00489
00490
00491
00492
00493 else if(ncl[i]==1)
00494 {
00495 StPmdCluster *pclust = new StPmdCluster();
00496 pmdclus->addCluster(pclust);
00497 id=id+1; icl=icl+1;
00498 clno=clno+1; i1=inford[1][id]; i2=inford[2][id];
00499 x1=coord[0][i1][i2]; y1=coord[1][i1][i2]; z1=d[i1][i2];
00500
00501 countr +=1;
00502
00503 StPmdHit* phit = GetHit(m_pmd_det0,supmod,crd_org[0][i1][i2],crd_org[1][i1][i2]);
00504 if(phit)pclust->addHitCollection(phit);
00505
00506 id=id+1; i1=inford[1][id]; i2=inford[2][id];
00507 x2=coord[0][i1][i2]; y2=coord[1][i1][i2]; z2=d[i1][i2];
00508
00509
00510
00511 phit = GetHit(m_pmd_det0,supmod,crd_org[0][i1][i2],crd_org[1][i1][i2]);
00512 if(phit)pclust->addHitCollection(phit);
00513
00514
00515 Double_t xcell[2],ycell[2],zcell[2],xcl[2000],ycl[2000];
00516 xcell[0] = x1;
00517 ycell[0] = y1;
00518 zcell[0] = z1;
00519 xcell[1] = x2;
00520 ycell[1] = y2;
00521 zcell[1] = z2;
00522
00523 xcl[i] = (x1*z1+x2*z2)/(z1+z2);
00524 ycl[i] = (y1*z1+y2*z2)/(z1+z2);
00525 Double_t sumxx,sumyy,sumxy;
00526 sumxx = 0.; sumyy = 0.; sumxy = 0.;
00527 for(j=0; j<2; j++)
00528 {
00529 sumxx = sumxx + zcell[j]*(xcell[j]-xcl[i])*(xcell[j]-xcl[i])/(z1+z2);
00530 sumyy = sumyy + zcell[j]*(ycell[j]-ycl[i])*(ycell[j]-ycl[i])/(z1+z2);
00531 sumxy = sumxy + zcell[j]*(xcell[j]-xcl[i])*(ycell[j]-ycl[i])/(z1+z2);
00532 }
00533 Double_t b1 = sumxx + sumyy;
00534 Double_t c1 = sumxx*sumyy - sumxy*sumxy;
00535 Double_t dis = b1*b1/4.-c1;
00536 if (fabs(dis) < 1e-6) dis = 0.;
00537 dis = sqrt(dis);
00538 Double_t r1=b1/2.+dis;
00539 Double_t r2=b1/2.-dis;
00540
00541
00544 if(r1 < r2)
00545 {
00546 clusters[4][clno] = r2;
00547 clusters[5][clno] = r1;
00548 }
00549 else
00550 {
00551 clusters[4][clno] = r1;
00552 clusters[5][clno] = r2;
00553 }
00554
00555 clusters[0][clno]=(x1*z1+x2*z2)/(z1+z2);
00556 clusters[1][clno]=(y1*z1+y2*z2)/(z1+z2);
00557 clusters[2][clno]=z1+z2;
00558 clusters[3][clno]=2.;
00559
00560 printclust(supmod,clno,pclust);
00561
00562 }
00563 else
00564 {
00565
00566 id=id+1; iordR[0]=0;
00567
00568
00569 i1=inford[1][id]; i2=inford[2][id];
00570 x[0]=coord[0][i1][i2]; y[0]=coord[1][i1][i2]; z[0]=d[i1][i2];iordR[0]=0;
00571 x_org[0]=crd_org[0][i1][i2]; y_org[0]=crd_org[1][i1][i2];
00572 for(j=1;j<=ncl[i];j++)
00573 {
00574 id=id+1;
00575 i1=inford[1][id]; i2=inford[2][id];iordR[j]=j;
00576 x[j]=coord[0][i1][i2]; y[j]=coord[1][i1][i2]; z[j]=d[i1][i2];
00577 x_org[j]=crd_org[0][i1][i2]; y_org[j]=crd_org[1][i1][i2];
00578 }
00580 for(j=1;j<=ncl[i];j++)
00581 {
00582 itest=0; ihld=iordR[j];
00583 for(i1=0;i1<j;i1++){
00584 if(itest == 0 && z[iordR[i1]] < z[ihld]){
00585 itest=1;
00586 for(i2=j-1;i2>=i1;i2--){
00587 iordR[i2+1]=iordR[i2];
00588 }
00589 iordR[i1]=ihld;
00590 }
00591 }
00592 }
00594 ig=0;
00595 xc[ig]=x[iordR[0]]; yc[ig]=y[iordR[0]]; zc[ig]=z[iordR[0]];
00596
00597
00598
00599
00600
00601 if(mOptRefineCluster==kTRUE){
00602
00603 for(j=1;j<=ncl[i];j++)
00604 {
00605 itest=-1; x1=x[iordR[j]]; y1=y[iordR[j]];
00606 for(k=0;k<=ig;k++)
00607 {
00608 x2=xc[k]; y2=yc[k]; rr=Dist(x1,y1,x2,y2);
00609
00610 if( rr >= 1.1 && rr < 1.8 && z[iordR[j]] > zc[k]*0.30)itest=itest+1;
00611 if( rr >= 1.8 && rr < 2.1 && z[iordR[j]] > zc[k]*0.15)itest=itest+1;
00612 if( rr >= 2.1 && rr < 2.8 && z[iordR[j]] > zc[k]*0.05)itest=itest+1;
00613 if( rr >= 2.8)itest=itest+1;
00614 }
00615 if(itest == ig)
00616 {
00617 ig=ig+1; xc[ig]=x1; yc[ig]=y1; zc[ig]=z[iordR[j]];
00618 }
00619 }
00620
00621 }
00622
00623
00624
00625 memset(cell_frac[0],0,sizeof(cell_frac));
00626
00627
00628 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]);
00629 if(censtat==kStOK){
00630
00631 icl=icl+ig+1;
00632
00633 Float_t temp[2000];
00634 Int_t take_cell[2000];
00635 for(Int_t jk=0; jk<2000; jk++)
00636 {
00637 temp[jk]=0.;
00638 take_cell[jk]=-999;
00639 }
00640
00641
00642
00643 for(Int_t pb=0;pb<=ig;pb++)
00644 {
00645 for(Int_t jk=0; jk<=ncl[i]; jk++)
00646 {
00647 if(cell_frac[pb][jk]>temp[jk])
00648 {
00649 take_cell[jk]=pb;
00650 temp[jk]=cell_frac[pb][jk];
00651 }
00652 }
00653 }
00654
00655
00656
00657
00658
00660 for(k=0; k<=ig; k++)
00661 {
00662 countr +=1;
00663 clno=clno+1;
00664 clusters[0][clno]=xc[k];
00665 clusters[1][clno]=yc[k];
00666 clusters[2][clno]=zc[k];
00667 clusters[3][clno]=cells[k];
00668 clusters[4][clno]=rcl[k];
00669 clusters[5][clno]=rcs[k];
00670 if(clusters[3][clno]==1)
00671 {
00672 clusters[4][clno]=0.;
00673 clusters[5][clno]=0.;
00674 }
00675
00676
00677
00678
00679
00680
00681
00682 StPmdCluster *pclust = new StPmdCluster();
00683 pmdclus->addCluster(pclust);
00684
00685 printclust(supmod,clno,pclust);
00686
00687 for(Int_t jk=0; jk<=ncl[i]; jk++)
00688 {
00689
00690
00691
00692
00693
00694
00695
00696
00697 if(take_cell[jk]==k)
00698 {
00699 StPmdHit* phit = GetHit(m_pmd_det0,supmod,x_org[jk],y_org[jk]);
00700 if(phit)pclust->addHitCollection(phit);
00701 }
00702
00703 }
00704 }
00705 }
00706 }
00707
00708
00709
00710 }
00711
00712
00713 }
00714
00715
00716
00717 Int_t StPmdClustering::CentroidCal(Int_t ncell,Int_t nclust,Double_t &x,
00718 Double_t &y,Double_t &z,Double_t &xc,
00719 Double_t &yc,Double_t &zc,
00720 Double_t &rcl,Double_t &rcs,Double_t &cells)
00721 {
00722 Int_t i1,i2;
00723 Int_t cluster[2000][10];
00724 Double_t sum,sumx,sum1,sumy,sumxy,sumxx,sumyy;
00725 Double_t rr,x1,y1,x2,y2,b,c,r1,r2;
00726 Double_t xx[2000],yy[2000],zz[2000];
00727 Double_t xxc[2000],yyc[2000];
00728 Double_t zzct[2000],cellsc[2000];
00729 Double_t str[2000],str1[2000], cln[2000];
00730 Double_t xcl[2000], ycl[2000],clust_cell[200][2000];
00731
00732 double dis;
00733 if(nclust>=200 || ncell >=2000){
00734 cout<<"Number of cluster of Ncell crosses limit "<<nclust<<" "<<ncell<<endl;
00735 return kStWarn;
00736 }
00737
00738 for(int i=0;i<=nclust;i++)
00739 {
00740 xxc[i] = *(&xc+i);
00741 yyc[i] = *(&yc+i);
00742 cellsc[i] = 0.;
00743 zzct[i] = 0.;
00744 }
00745 for(int i=0;i<=ncell;i++)
00746 {
00747 xx[i] = *(&x+i);
00748 yy[i] = *(&y+i);
00749 zz[i] = *(&z+i);
00750 }
00751
00752 memset(clust_cell[0],0,200*2000*sizeof(Double_t));
00753 memset(cell_frac[0],0,200*2000*sizeof(Float_t));
00754 memset(cluster[0],0,2000*10*sizeof(Int_t));
00755
00756
00757
00758 if(nclust>0)
00759 {
00760 for(int i=0;i<=ncell;i++)
00761 {
00762 x1 = xx[i];
00763 y1 = yy[i];
00764 cluster[i][0] = 0;
00765
00766 for(int j=0;j<=nclust;j++)
00767 {
00768 x2 = xxc[j];
00769 y2 = yyc[j];
00770 rr = Dist(x1,y1,x2,y2);
00771 if(rr < 1.)
00772 {
00773 cluster[i][0]++;
00774 i1 = cluster[i][0];
00775 cluster[i][i1] = j;
00776 }
00777 }
00778
00779 if(cluster[i][0] ==0){
00780 for(int j=0;j<=nclust;j++){
00781 x2=xxc[j];
00782 y2=yyc[j];
00783 rr=Dist(x1,y1,x2,y2);
00784
00785 if(rr<= sqrt(3.))
00786 {
00787 cluster[i][0]++;
00788 i1=cluster[i][0];
00789 cluster[i][i1] = j;
00790 }
00791 }
00792 }
00793 if(cluster[i][0] ==0){
00794 for(int j=0;j<=nclust;j++){
00795 x2=xxc[j];
00796 y2=yyc[j];
00797 rr=Dist(x1,y1,x2,y2);
00798 if(rr<= 2.)
00799 {
00800 cluster[i][0]++;
00801 i1=cluster[i][0];
00802 cluster[i][i1] = j;
00803 }
00804 }
00805 }
00806
00807 if(cluster[i][0] ==0){
00808 for(int j=0;j<=nclust;j++){
00809 x2=xxc[j];
00810 y2=yyc[j];
00811 rr=Dist(x1,y1,x2,y2);
00812 if(rr<= 2.7)
00813 {
00814 cluster[i][0]++;
00815 i1=cluster[i][0];
00816 cluster[i][i1] = j;
00817 }
00818 }
00819 }
00820 }
00822
00823
00824
00825 memset(str,0,2000*sizeof(Double_t));
00826 memset(str1,0,2000*sizeof(Double_t));
00827
00828 for(int i=0;i<=ncell;i++){
00829 if(cluster[i][0]!=0){
00830 i1 = cluster[i][0];
00831 for(int j=1;j<=i1;j++){
00832 i2 = cluster[i][j];
00833 str[i2] = str[i2] + zz[i]/i1;
00834 }
00835 }
00836 }
00837
00838 for(int k=0; k<5; k++){
00839 for(int i=0; i<=ncell; i++){
00840 if(cluster[i][0] != 0){
00841 i1=cluster[i][0];
00842 sum = 0;
00843 for(int j=1;j<=i1;j++){
00844 sum = sum + str[cluster[i][j]];
00845 }
00846 for(int j=1;j<=i1;j++){
00847 i2 = cluster[i][j];
00848 str1[i2] = str1[i2] + zz[i]*str[i2]/sum;
00849 clust_cell[i2][i] = zz[i]*str[i2]/sum;
00850 }
00851 }
00852 }
00853 for(int j=0; j<=nclust; j++){
00854 str[j]=str1[j];
00855 str1[j]=0.;
00856 }
00857 }
00858
00859
00860 for(int i=0;i<=nclust;i++){
00861 sumx=0.;sumy=0.;sum=0.;sum1=0.;
00862 for(int j=0;j<=ncell;j++){
00863 if(clust_cell[i][j] !=0){
00864
00865 sumx=sumx+clust_cell[i][j]*xx[j];
00866 sumy=sumy+clust_cell[i][j]*yy[j];
00867 sum=sum+clust_cell[i][j];
00868 sum1=sum1+clust_cell[i][j]/zz[j];
00869
00870 cell_frac[i][j]=clust_cell[i][j]/zz[j];
00871
00872
00873
00874
00875
00876 }
00877 }
00878 xcl[i]=sumx/sum; ycl[i]=sumy/sum; cln[i]=sum1;
00879
00880 sumxx=0.; sumyy=0.; sumxy=0.;
00881 for(int j=0; j<=ncell; j++){
00882 sumxx=sumxx+clust_cell[i][j]*(xx[j]-xcl[i])*(xx[j]-xcl[i])/sum;
00883 sumyy=sumyy+clust_cell[i][j]*(yy[j]-ycl[i])*(yy[j]-ycl[i])/sum;
00884 sumxy=sumxy+clust_cell[i][j]*(xx[j]-xcl[i])*(yy[j]-ycl[i])/sum;
00885 }
00886 b=sumxx+sumyy;
00887 c=sumxx*sumyy-sumxy*sumxy;
00888 dis = b*b/4.-c;
00889 if (fabs(dis) < 1e-6) dis = 0.;
00890 dis = sqrt(dis);
00891 r1=b/2.+dis;
00892 r2=b/2.-dis;
00893 if(r1 < r2){
00894 *(&rcl+i) = r2;
00895 *(&rcs+i) = r1;
00896 }else{
00897 *(&rcl+i) = r1;
00898 *(&rcs+i) = r2;
00899 }
00900
00901
00902
00903 *(&xc + i) = xcl[i];
00904 *(&yc + i) = ycl[i];
00905 *(&zc + i) = str[i];
00906 *(&cells + i) = cln[i];
00907
00908 }
00909 }
00910 else
00911 {
00912
00913 sumx=0.; sumy=0.; sum=0.; sum1=0.;
00914 int i=0;
00915 for(int j=0; j<=ncell; j++)
00916 {
00917 sumx=sumx+zz[j]*xx[j];
00918 sumy=sumy+zz[j]*yy[j];
00919 sum=sum+zz[j];
00920 sum1=sum1+1.;
00921
00922 cell_frac[i][j]=1;
00923
00924 }
00925 xcl[i]=sumx/sum; ycl[i]=sumy/sum; cln[i]=sum1; str[i]=sum;
00926
00927 sumxx=0.; sumyy=0.; sumxy=0.;
00928 for(int j=0; j<=ncell; j++)
00929 {
00930 sumxx=sumxx+zz[j]*(xx[j]-xcl[i])*(xx[j]-xcl[i])/sum;
00931 sumyy=sumyy+zz[j]*(yy[j]-ycl[i])*(yy[j]-ycl[i])/sum;
00932 sumxy=sumxy+zz[j]*(xx[j]-xcl[i])*(yy[j]-ycl[i])/sum;
00933 }
00934
00935
00936 b=sumxx+sumyy;
00937 c=sumxx*sumyy-sumxy*sumxy;
00938 dis = b*b/4.-c;
00939 if (fabs(dis) < 1e-6) dis = 0.;
00940 dis = sqrt(dis);
00941 r1=b/2.+dis;
00942 r2=b/2.-dis;
00943 if(r1 < r2){
00944 *(&rcl+i) = r2;
00945 *(&rcs+i) = r1;
00946 }else{
00947 *(&rcl+i) = r1;
00948 *(&rcs+i) = r2;
00949 }
00950
00951 *(&xc + i) = xcl[i];
00952 *(&yc + i) = ycl[i];
00953 *(&zc + i) = str[i];
00954 *(&cells + i) = cln[i];
00955
00956
00957
00958 }
00959 return kStOK;
00960
00961 }
00962
00963
00964
00966 Double_t StPmdClustering::Dist(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
00967 {
00968 return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
00969 }
00970
00974 Int_t StPmdClustering::crclust(Double_t ave, Double_t cutoff, Int_t nmx1, Int_t idet)
00975 {
00976 Double_t xx, yy, d[96][72];
00977 Int_t i,j,k,id1,id2,icl,clust[2][3000], numcell, cellcount;
00978 Int_t jd1,jd2,icell;
00979
00981 static Int_t neibx[6]={1,0,-1,-1,0,1}, neiby[6]={0,1,1,0,-1,-1};
00982
00983
00984 memcpy(d,d1,96*72*sizeof(Double_t));
00985
00986 for (j=0; j < 96; j++){
00987 for(k=0; k < 72; k++){
00988 for (i=0; i < 2; i++){infocl[i][j][k] = 0;}
00989 }
00990 }
00991 cellcount=0;
00992 for(i=0; i < nmx; i++){
00993 id1=iord[0][i]; id2=iord[1][i];
00994 if(d[id1][id2] <= cutoff){infocl[0][id1][id2]=-1;}
00995 }
00998 icl=-1;
00999 for(icell=0; icell <= nmx1; icell++){
01000
01001 id1=iord[0][icell]; id2=iord[1][icell]; xx=id1+id2/2.; yy=sqrth*id2;
01002 if(infocl[0][id1][id2] == 0 ){
01003
01008 icl=icl+1; numcell=0;
01009 for(i=0; i < 3000; i++){
01010 clust[0][i]=0; clust[1][i]=0;
01011 }
01012 clust[0][numcell]=id1; clust[1][numcell]=id2;
01013 infocl[0][id1][id2]=1; infocl[1][id1][id2]=icl;
01015 for(i=0; i<6; i++){
01016 jd1=id1+neibx[i]; jd2=id2+neiby[i];
01017 if( (jd1 >= 0 && jd1 < 96) && (jd2 >= 0 && jd2 < 72) &&
01018 d[jd1][jd2] > cutoff && infocl[0][jd1][jd2] == 0)
01019 {
01020 numcell=numcell+1; clust[0][numcell]=jd1; clust[1][numcell]=jd2;
01021 infocl[0][jd1][jd2]=2; infocl[1][jd1][jd2]=icl;
01022 xx=jd1+jd2/2.; yy=sqrth*jd2;
01023 }
01024 }
01025 for(i=1;i < 3000;i++){
01026 if(clust[0][i] != 0){
01027 id1=clust[0][i]; id2=clust[1][i];
01028 for(j=0; j<6 ; j++){
01029 jd1=id1+neibx[j]; jd2=id2+neiby[j];
01030 if( (jd1 >= 0 && jd1 < 96) && (jd2 >= 0 && jd2 < 72) &&
01031 d[jd1][jd2] > cutoff && infocl[0][jd1][jd2] == 0 ){
01032 infocl[0][jd1][jd2]=2; infocl[1][jd1][jd2]=icl;
01033 numcell=numcell+1;
01034 clust[0][numcell]=jd1; clust[1][numcell]=jd2;
01035 xx=jd1+jd2/2.; yy=sqrth*jd2;
01036 }
01037 }
01038 }
01039 }
01040 cellcount=cellcount+numcell+1;
01041 }
01042 }
01043
01044 return cellcount;
01045 }
01046
01047
01048 StPmdHit*
01049 StPmdClustering::GetHit(StPmdDetector* pdet,Int_t id,Double_t xc, Double_t yc)
01050 {
01051 Int_t xpad,ypad,super;
01052 Int_t nmh=pdet->module_hit(id);
01053 StPmdModule * pmod=pdet->module(id);
01054 TIter next(pmod->Hits());
01055 StPmdHit *spmcl;
01056
01057 for(Int_t im=0; im<nmh; im++)
01058 {
01059 spmcl = (StPmdHit*)next();
01060 if(spmcl){
01061 ypad=spmcl->Row();
01062 xpad=spmcl->Column();
01063 super = spmcl->Gsuper();
01064 if(int(yc+1)==ypad && int(xc+1)==xpad && id == super) return spmcl;
01065 }
01066 }
01067 return NULL;
01068 }
01069
01070
01071
01072 void StPmdClustering::Cluster_Eta_Phi(Float_t xreal,Float_t yreal,Float_t zreal,Float_t& eta,Float_t& phi){
01073 Float_t rdist = (TMath::Sqrt(xreal*xreal + yreal*yreal))/TMath::Abs(zreal);
01074 Float_t theta = TMath::ATan(rdist);
01075
01076
01077 if(theta !=0.){ eta = TMath::Log(TMath::Tan(0.5*theta));}
01078 if( xreal==0) {
01079 if(yreal>0) {phi = 1.571428;}
01080 if(yreal<0) {phi = -1.571428;}
01081 }
01082 if(xreal != 0) {phi = atan2(yreal,xreal);}
01083
01084 }
01085
01086
01088 Bool_t StPmdClustering::findPmdClusters2(StPmdDetector *mdet)
01089 {
01090 cout<<"cutoff in findPmdClusters2="<<cutoff<<endl;
01091
01092
01093
01094
01095
01096 pmdclus = new StPmdClusterCollection();
01097 mdet->setCluster(pmdclus);
01098
01099 if(mdet){
01100
01101
01102 for(Int_t ism = 1; ism<=12; ism++){
01103
01104 TClonesArray * mPmdSuperClusters = new TClonesArray("TList",1000);
01105
01106
01107
01108 StPmdModule * pmd_mod = mdet->module(ism);
01109 Int_t nhits = mdet->module_hit(ism);
01110
01111
01112
01113 if(nhits<=0) continue;
01114
01115
01116 Int_t nSuperClusters = MakeSuperClusters(ism,pmd_mod,mPmdSuperClusters);
01117
01118
01119
01120 if (nSuperClusters==0|| nSuperClusters > nhits){
01121 cout<<"Warning!!! nent/nsuper "<<nhits<<"/"<<nSuperClusters<<endl;
01122 cout<<"The hits of this module will not be added to the outgoing TClonesArray of hits"<<endl;
01123
01124 }else{
01125
01126
01127 Int_t gotclusters = MakeClusters(mPmdSuperClusters);
01128
01129 if (gotclusters==0){
01130 cout<<" Did not get any clusters in this sm"<<endl;
01131 }
01132
01133 }
01134 mPmdSuperClusters->Delete();
01135 delete mPmdSuperClusters;
01136 }
01137 }
01138 cout<<"Number of clusters in findPmdClusters2 = "<<pmdclus->Nclusters()<<endl;
01139
01140 return kStOK;
01141 }
01142
01143
01144
01145 Int_t StPmdClustering::MakeSuperClusters(Int_t modnum,StPmdModule * mpmdMod , TClonesArray* mPmdSuperClusters){
01146
01147 Int_t Columnneigh[6] = {-1,-1,0,1,1,0};
01148 Int_t Rowneigh[6] = {0,1,1,0,-1,-1};
01149
01150
01151
01152
01153
01154 Int_t hitmap[NRowMax][NColumnMax];
01155 Int_t Flag[NRowMax][NColumnMax];
01156 for( Int_t ncellX = 0; ncellX < NRowMax; ncellX++ ){
01157 for( Int_t ncellY = 0; ncellY < NColumnMax; ncellY++ ){
01158 hitmap[ncellX][ncellY]=-1;
01159 Flag[ncellX][ncellY]=0;
01160 }
01161 }
01162
01163 TObjArray * PmdHits = mpmdMod->Hits();
01164
01165
01166 PmdHits->Sort(0);
01167
01168 Int_t Ncell_mod = PmdHits->GetEntries();
01169
01170
01171 Int_t NWithin=0;
01172 Int_t NAccCut=0;
01173
01174
01175
01176 for (Int_t i = 0; i < Ncell_mod; i++){
01177
01178 StPmdHit * mPmdHit = (StPmdHit*)PmdHits->At(i);
01179
01180
01181
01182
01183 if((mPmdHit->Row()>NRowMax||mPmdHit->Row()<=0)||
01184 (mPmdHit->Column()>NColumnMax||mPmdHit->Column()<=0)){
01185 cout<<"hit out of range :"<<mPmdHit->Row()-1<<"/"<<mPmdHit->Column()-1<<endl;
01186 }else{
01187 if (mPmdHit->Edep() > cutoff ){
01188 hitmap[mPmdHit->Row()-1][mPmdHit->Column()-1]= i;
01189 NWithin++;
01190 }else {
01191
01192
01193 hitmap[mPmdHit->Row()-1][mPmdHit->Column()-1] = -1;
01194 Flag[mPmdHit->Row()-1][mPmdHit->Column()-1]=2;
01195 NAccCut++;
01196 }
01197 }
01198 }
01199
01200
01201
01202 if ((NWithin+NAccCut)!=Ncell_mod){
01203 cout<<" Some hits outside hitmap NWithin/NAccCut/NTotal "<<
01204 NWithin<<"/"<<NAccCut<<"/"<<Ncell_mod<<endl;
01205 }
01206 if (NWithin==0){
01207 return 0;
01208 }
01209
01210
01211
01212
01213
01214 Int_t nPmdSuperCluster = -1;
01215
01216 for(Int_t icell = 0; icell < Ncell_mod; icell++){
01217 StPmdHit *mPmdHit = (StPmdHit*)PmdHits->At(icell);
01218
01219 if((mPmdHit->Row()>NRowMax||mPmdHit->Row()<=0)||
01220 (mPmdHit->Column()>NColumnMax||mPmdHit->Column()<=0)){
01221 cout<<"hit out of range :"<<mPmdHit->Row()-1<<"/"<<mPmdHit->Column()-1<<endl;
01222 continue;
01223 }
01224
01225 if (Flag[mPmdHit->Row()-1][mPmdHit->Column()-1]==0){
01226 nPmdSuperCluster++;
01227
01228 TList * mPmdSuperCluster = (TList*)mPmdSuperClusters->New(nPmdSuperCluster);
01229
01230 TIter ClusterListIter(mPmdSuperCluster);
01231
01232 mPmdSuperCluster->Add(mPmdHit);
01233
01234 Flag[mPmdHit->Row()-1][mPmdHit->Column()-1]=1;
01235
01236
01237 for(Int_t k=0;k<mPmdSuperCluster->GetSize();k++){
01238 StPmdHit* clusterhit = (StPmdHit*)mPmdSuperCluster->At(k);
01239 Int_t clusterhitRow = clusterhit->Row();
01240 Int_t clusterhitColumn = clusterhit->Column();
01241 if(Flag[clusterhitRow-1][clusterhitColumn-1]!=1) cout<<"???????"<<endl;
01242
01243 for( Int_t ineigh = 0;ineigh < 6; ineigh++ ){
01244 Int_t neighbourRow = clusterhitRow + Rowneigh[ineigh];
01245 Int_t neighbourColumn = clusterhitColumn + Columnneigh[ineigh];
01246 Int_t boundary = CheckBoundary(modnum,neighbourRow-1,neighbourColumn-1);
01247
01248 if (boundary==0 && hitmap[neighbourRow-1][neighbourColumn-1]!=-1){
01249
01250
01251
01252 StPmdHit* neighbour = (StPmdHit*)PmdHits->At(hitmap[neighbourRow-1][neighbourColumn-1]);
01253
01254 if (neighbour){
01255 if (neighbour->Edep()>cutoff
01256 && Flag[neighbourRow-1][neighbourColumn-1]==0){
01257 mPmdSuperCluster->Add(neighbour);
01258
01259
01260 Flag[neighbourRow-1][neighbourColumn-1]=1;
01261 }
01262 }
01263 }
01264 }
01265 }
01266
01267 if (mPmdSuperCluster->GetSize()>MaxSuperSize){
01268 cout<<"The size of supercluster "<<mPmdSuperCluster->GetSize()<<" exceeds MaxSuperSize("<<MaxSuperSize<<")"<<endl;
01269 return 0;
01270 }
01271 mPmdSuperCluster->Sort(0);
01272
01273 }
01274
01275 }
01276
01277
01278 Int_t Nentries = mPmdSuperClusters->GetEntries();
01279
01280
01281 return Nentries;
01282 }
01283
01284
01285
01286
01287 Int_t StPmdClustering::MakeClusters(TClonesArray * mPmdSuperClusters)
01288 {
01289
01290
01291
01292 Int_t nLocalPeak=0;
01293 Int_t sum_nclusters = 0;
01294
01295
01296 for(Int_t i=0;i<mPmdSuperClusters->GetEntries();i++){
01297
01298 TList *mPmdSuperCluster = (TList*)mPmdSuperClusters->At(i);
01299 Int_t ncell = mPmdSuperCluster->GetSize();
01300
01301
01302
01303 if (ncell==0) {
01304 break;
01305 cout<<"zero cells in this supercluster!!!"<<endl;
01306 }else{
01307
01308 if ((ncell<3 && mOptRefineCluster==kTRUE)||(mOptRefineCluster==kFALSE)){
01309
01310
01311
01312 StPmdCluster *pcluster = new StPmdCluster();;
01313 pmdclus->addCluster(pcluster);
01314 Float_t hitfract[ncell];
01315
01316 for(Int_t j = 0; j < ncell; j++ ){
01317 StPmdHit * phit = (StPmdHit*)mPmdSuperCluster->At(j);
01318 pcluster->addHitCollection(phit);
01319 hitfract[j]=1.0;
01320 }
01321
01322 BuildCluster(pcluster,hitfract);
01323
01324
01325 sum_nclusters++;
01326 }
01327
01328
01329 else{
01330
01331
01332
01333
01334 Int_t jLocalPeak[MaxLocalPeaks];
01335 for (Int_t j=0;j<MaxLocalPeaks;j++){
01336 jLocalPeak[j] = -1;
01337 }
01338
01339 Int_t *pLocalPeak = &jLocalPeak[0];
01340
01341
01342 nLocalPeak = GetLocalPeaks(pLocalPeak,mPmdSuperCluster);
01343
01344
01345
01346
01347
01348 if(nLocalPeak==1){
01349
01350 StPmdCluster *pcluster = new StPmdCluster();;
01351 pmdclus->addCluster(pcluster);
01352 Float_t hitfract[nLocalPeak];
01353
01354
01355 for(Int_t ihit = 0;ihit<mPmdSuperCluster->GetEntries();ihit++){
01356 hitfract[ihit]=1.0;
01357 StPmdHit * phit = (StPmdHit*)mPmdSuperCluster->At(ihit);
01358 pcluster->addHitCollection(phit);
01359 }
01360 Float_t nmem = BuildCluster(pcluster,hitfract);
01361
01362 if(nmem==0) cout<<" 1 local peak only so I have a cluster with "<<nmem<<" cells"<<endl;
01363 }
01364
01365 if (nLocalPeak>1 && nLocalPeak<MaxLocalPeaks){
01366 sum_nclusters+=nLocalPeak;
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376 Bool_t broken = BreakSuperCluster(nLocalPeak,pLocalPeak,mPmdSuperCluster);
01377
01378
01379 if(broken==1){
01380 cout<<" too many local peaks I think"<<endl;
01381 }
01382 }else{
01383
01384
01385 cout<<"Module cut due to nLocalPeaks>MaxLocalPeaks"<<endl;
01386 return 0;
01387 }
01388 }
01389 }
01390 }
01391
01392 return sum_nclusters;
01393 }
01394
01395
01396
01397
01398
01399
01400
01401
01402 void StPmdClustering::CellXY(Int_t row, Int_t column, Float_t& xx, Float_t& yy){
01403
01404
01405 xx = (Float_t)(column + 0.5*row);
01406 yy = 0.5*sqrt(3.)*row;
01407 }
01408
01409
01410 Int_t StPmdClustering::CheckBoundary(Int_t nmod,Int_t numRow, Int_t numColumn){
01411 if ((numRow>=0 && numRow< NRowMax) &&
01412 (numColumn>=0 && numColumn<NColumnMax))
01413 {
01414 return 0;}
01415 else return 1;
01416 }
01417
01418
01419 Int_t StPmdClustering::GetLocalPeaks(Int_t* jLocalPeak,TList *mPmdSuperCluster){
01420
01421 Int_t nLocalPeak =-1;
01422 Int_t ncell = mPmdSuperCluster->GetSize();
01423 Float_t xLocalPeak[ncell];
01424 Float_t yLocalPeak[ncell];
01425 Float_t adcLocalPeak[ncell];
01426
01427
01428 nLocalPeak++;
01429 if(nLocalPeak>=MaxLocalPeaks) cout<<" Number of Local peaks is "<<nLocalPeak+1<<" which exceeds the array size MaxLocalPeaks ="<<MaxLocalPeaks<<endl;
01430 StPmdHit * phitj = (StPmdHit*)mPmdSuperCluster->At(0);
01431 Float_t hitx1 = 0; Float_t hity1 = 0;
01432 CellXY(phitj->Row()-1,phitj->Column()-1,hitx1,hity1);
01433 Int_t sm = phitj->Gsuper();
01434 jLocalPeak[nLocalPeak] = 0;
01435 xLocalPeak[nLocalPeak] = hitx1;
01436 yLocalPeak[nLocalPeak] = hity1;
01437 adcLocalPeak[nLocalPeak] = phitj->Edep();
01438
01439
01440
01441
01442
01443
01444 for (Int_t j = 1; j < ncell; j++){
01445 StPmdHit * phitj = (StPmdHit*)mPmdSuperCluster->At(j);
01446
01447 Float_t hitx = 0; Float_t hity = 0;
01448 CellXY(phitj->Row()-1,phitj->Column()-1,hitx,hity);
01449
01450 Int_t nclear = -1;
01451 for (Int_t k = 0; k <= nLocalPeak; k++){
01452 Float_t gap = Dist(hitx,hity,xLocalPeak[k],yLocalPeak[k]);
01453
01454
01455 if( gap >= 1.1 && gap < 1.8 && phitj->Edep() > adcLocalPeak[k]*0.30) nclear++;
01456 if( gap >= 1.8 && gap < 2.1 && phitj->Edep() > adcLocalPeak[k]*0.15) nclear++;
01457 if( gap >= 2.1 && gap < 2.8 && phitj->Edep() > adcLocalPeak[k]*0.05) nclear++;
01458 if( gap >= 2.8 ) nclear++;
01459 }
01460 if (nclear==nLocalPeak){
01461
01462 nLocalPeak++;
01463 if (nLocalPeak<MaxLocalPeaks){
01464 jLocalPeak[nLocalPeak] = j;
01465 xLocalPeak[nLocalPeak] = hitx;
01466 yLocalPeak[nLocalPeak] = hity;
01467 adcLocalPeak[nLocalPeak] = phitj->Edep();
01468 }else{
01469 cout<<"number of local peaks is "<<nLocalPeak<<" which is more than "<<MaxLocalPeaks<<" for a supercluster of size ="<<ncell<<" in sm number ="<<sm<<endl;
01470 return 0;
01471 }
01472 }
01473 }
01474 return ++nLocalPeak;
01475
01476 }
01477
01478 void StPmdClustering::Cell_eta_phi(Float_t xreal,Float_t yreal,Float_t& eta,Float_t& phi){
01479
01480
01481 xreal = xreal - mVertexPos.x();
01482 yreal = yreal - mVertexPos.y();
01483 Float_t zreal = -1.0*geom->GetPmdZ();
01484 zreal = zreal - mVertexPos.z();
01485
01486
01487 Float_t rdist = (TMath::Sqrt(xreal*xreal + yreal*yreal))/zreal;
01488
01489 Int_t flag = -1;
01490 if (rdist<0.) {
01491 flag = +1;
01492 rdist=TMath::Abs(rdist);
01493 }
01494
01495 Float_t theta = TMath::ATan(rdist);
01496 if(theta !=0.)eta = flag*TMath::Log(TMath::Tan(0.5*theta));
01497 if( xreal==0) {
01498 if(yreal>0) phi = TMath::Pi()/2.0;
01499 if(yreal<0) phi = -1.0*TMath::Pi()/2.0;
01500 }
01501 if(xreal != 0) phi = atan2(yreal,xreal);
01502
01503
01504 }
01505
01506
01507
01508 Float_t StPmdClustering::BuildCluster( StPmdCluster *pcluster,Float_t* hitfract){
01509
01510
01511
01512 TObjArray* hitCollection = pcluster->HitCollection();
01513 Int_t ncell = hitCollection->GetEntries();
01514
01515 Float_t adchit[ncell],xhit[ncell],yhit[ncell];
01516 Float_t SigmaL = 0, SigmaS = 0;
01517 Float_t cluX=0, cluY=0, cluAdc=0;
01518 Float_t eta=0,phi=0;
01519
01520
01521
01522
01523
01524 StPmdHit* phit = (StPmdHit*)hitCollection->At(0);
01525 Int_t nmod = phit->Gsuper();
01526 Int_t det = phit->SubDetector();
01527
01528
01529 Int_t nmodclu = 12*(2-det) + nmod;
01530
01531 pcluster->setModule(nmodclu);
01532 Float_t nmem = Float_t(ncell*1.0);
01533 pcluster->setNumofMems(nmem);
01534
01535
01536
01537
01538
01539 if (ncell==1){
01540 SigmaL=0;
01541 SigmaS=0;
01542 StPmdHit * phit = (StPmdHit*)hitCollection->At(0);
01543
01544
01545
01546 geom->IntDetCell_xy(nmod,(phit->Row()),(phit->Column()),cluX,cluY,eta,phi);
01547 cluAdc = phit->Edep()*1.0;
01548
01549
01550 }else{
01551
01552
01553 Float_t sumx=0,sumy=0;
01554 for(Int_t j = 0; j < ncell; j++ ){
01555 StPmdHit * phit = (StPmdHit*)hitCollection->At(j);
01556 if (!phit) cout<<" Did not get the phit I was hoping for "<<endl;
01557 if (!phit) break;
01558
01559
01560
01561 Float_t xreal=0,yreal=0;
01562 geom->IntDetCell_xy(nmod,(phit->Row()),(phit->Column()),xreal,yreal,eta,phi);
01563 adchit[j] = hitfract[j]*phit->Edep();
01564 xhit[j] = xreal;
01565 yhit[j] = yreal;
01566
01567
01568 sumx+=adchit[j]*xhit[j];
01569 sumy+=adchit[j]*yhit[j];
01570 cluAdc+=adchit[j];
01571
01572 }
01573
01574 cluX = sumx/cluAdc;
01575 cluY = sumy/cluAdc;
01576
01577
01578 Float_t sumxx=0,sumxy=0,sumyy=0;
01579 for(Int_t j=0;j<ncell;j++){
01580 sumxx+=adchit[j]*(xhit[j]-cluX)*(xhit[j]-cluX)/cluAdc;
01581 sumyy+=adchit[j]*(yhit[j]-cluY)*(yhit[j]-cluY)/cluAdc;
01582 sumxy+=adchit[j]*(yhit[j]-cluY)*(xhit[j]-cluX)/cluAdc;
01583 }
01584
01585 Float_t b=sumxx+sumyy;
01586 Float_t c=sumxx*sumyy-sumxy*sumxy;
01587
01588 Float_t r1=b/2.+sqrt(b*b/4.-c);
01589 Float_t r2=b/2.-sqrt(b*b/4.-c);
01590
01591 if (r1<r2) {
01592 SigmaS = r1;
01593 SigmaL = r2;
01594 }else{
01595 SigmaS = r2;
01596 SigmaL = r1;
01597 }
01598 if(ncell==2) SigmaS=0;
01599 }
01600
01601
01602 Cell_eta_phi(cluX,cluY,eta,phi);
01603
01604
01605
01606 pcluster->setCluSigmaS(SigmaS);
01607 pcluster->setCluSigmaL(SigmaL);
01608
01609 pcluster->setCluEta(eta);
01610 pcluster->setCluPhi(phi);
01611
01612 Float_t edep = cluAdc*1.0;
01613 pcluster->setCluEdep(edep);
01614
01615 pcluster->setCluX(cluX);
01616 pcluster->setCluY(cluY);
01617
01618 Int_t pid = 0;
01619 Int_t edeppid = 0;
01620 Int_t mcpid = 0;
01621
01622
01623 pcluster->setMcCluPID(mcpid);
01624 pcluster->setCluPID(pid);
01625 pcluster->setCluEdepPID(edeppid);
01626
01627
01628
01629
01630 return nmem;
01631
01632 }
01633