14 #include "StFgtAlignmentMaker.h"
15 #include "StEventTypes.h"
16 #include "StMessMgr.h"
17 #include "StDcaGeometry.h"
26 #include "TArrayL64.h"
27 #include "StThreeVectorF.hh"
28 #include "StPhysicalHelix.hh"
29 #include "SystemOfUnits.h"
30 #include "THelixTrack.h"
31 #include "StDetectorName.h"
32 #include "fgtAlignment.h"
33 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
34 #include "StTpcDb/StTpcDb.h"
35 #include "StDetectorDbMaker/St_vertexSeedC.h"
36 #include "StRoot/StFgtDbMaker/StFgtDbMaker.h"
37 #include "StRoot/StFgtDbMaker/StFgtDb.h"
39 #include "StMuDSTMaker/COMMON/StMuDst.h"
40 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
41 #include "StMuDSTMaker/COMMON/StMuDst.h"
42 #include "StMuDSTMaker/COMMON/StMuEvent.h"
43 #include "StarClassLibrary/StThreeVectorF.hh"
45 #include "StRoot/StFgtPool/StFgtClusterTools/StFgtGeneralBase.h"
46 #include "StRoot/StFgtPool/StFgtClusterTools/StFgtStraightTrackMaker.h"
48 #include "StRoot/StEEmcPool/StEEmcIUPi0/StEEmcIUPointMaker.h"
49 #include "StRoot/StEmcUtil/geometry/StEmcGeom.h"
51 static const int mDebug=0;
52 static const int mEventDisp=0;
54 static const int MAXTRK=500000;
55 static const int MAXHIT=8;
56 static const int NPAR=24*6;
58 static const int NAXIS=4;
59 static TH1F *hist1[kFgtNumDiscs+6][kFgtNumQuads][NAXIS];
60 static TH2F *hist2[kFgtNumDiscs+6][kFgtNumQuads][NAXIS*2];
63 static const double PI = 4.0*atan(1);
65 const float ISOCUT=0.5;
66 const float maxdfgt=0.15, maxdvtx=0.5, maxdtpc=10.0, maxdemc=10.0;
67 const float maxpfgt=0.005, maxpvtx=0.5, maxptpc= 0.3, maxpemc=0.3;
70 int run,evt,nhit,nhitUse,nhitFgt,nhitVtx,nhitTpc,nhitPrompt,nhitEemc,used;
71 float dca, chi2, trkz, dz, eta, phi, opt;
73 float x[MAXHIT],y[MAXHIT],z[MAXHIT];
74 float ex[MAXHIT],ey[MAXHIT],ez[MAXHIT];
75 float lr[MAXHIT],lp[MAXHIT],r[MAXHIT],p[MAXHIT];
76 float dx[MAXHIT],dy[MAXHIT],dr[MAXHIT],dp[MAXHIT];
77 float tw[MAXHIT],p1[MAXHIT],p2[MAXHIT],po[MAXHIT];
78 float su[MAXHIT],sv[MAXHIT];
79 int nrl[MAXHIT],nsu[MAXHIT],nsv[MAXHIT];
80 float ele[4],trk[4],bemc[4],eemc[4],tot[4],rec[4],iso[4];
85 static int mNtrk[kFgtNumQuads];
86 static int mNtrkUse[kFgtNumQuads];
87 static TRKHIT mHit[kFgtNumQuads][MAXTRK];
91 static int mHitMaskDisc;
92 static int mResidMaskDisc;
93 static int mFgtInputRPhi;
96 static int mReqFgtHit=0;
98 static int mReqTpcHit=0;
99 static int mReqPromptHit=0;
100 static int mReqEemcHit=0;
101 static float mErrFGT=0;
102 static float mErrVTX=0;
103 static float mErrVTXZ=0;
104 static float mErrTPCI=0;
105 static float mErrTPCO=0;
106 static float mErrTPCZ=0;
107 static float mErrPPT=0;
108 static float mErrEMC=0;
109 static int mBeamLine=1;
112 static fgtAlignment_st* orig_algpar;
115 static float ptbal,riso;
117 #define SMALL_NUM 1e-4
121 Vector(
double vx=0,
double vy=0,
double vz=0):x(vx),y(vy),z(vz){}
125 Vector operator=(
const Vector& v) {x=v.x; y=v.y; z=v.z;}
129 friend Vector operator*(
const double d,
const Vector& v) {
return Vector(d*v.x,d*v.y,d*v.z);}
130 friend Vector operator*(
const Vector& v,
const double d) {
return Vector(d*v.x,d*v.y,d*v.z);}
131 friend double operator*(
const Vector& v1,
const Vector& v2) {
return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z;}
132 double length() {
return sqrt((*
this)*(*
this));}
133 void print(){printf(
"x=%8.3f y=%8.3f z=%8.3f\n",x,y,z);}
156 tc = (b>c ? d/b : e/c);
157 printf(
"SMALL NUM!!!\n");
159 sc = (b*e - c*d) / D;
160 tc = (a*e - b*d) / D;
171 void getZvtxAndDca(
double* p,
double& dca,
double& z,
double zmin=-900,
double zmax=900){
172 double x0=0,y0=0,dxdz=0,dydz=0;
175 x0=vSeed->x0(); dxdz=vSeed->dxdz();
176 y0=vSeed->y0(); dydz=vSeed->dydz();
178 Vector p1(p[0]+p[1]*zmin, p[2]+p[3]*zmin, zmin);
179 Vector p2(p[0]+p[1]*zmax, p[2]+p[3]*zmax, zmax);
180 Vector p3(x0+dxdz*zmin, y0+dydz*zmin, zmin);
181 Vector p4(x0+dxdz*zmax, y0+dydz*zmax, zmax);
183 Line l1(p1,p2), l2(p3,p4);
184 dca=distance(l1,l2,p5,p6);
189 inline StPhysicalHelix getStPhysicalHelix(
double x0,
double y0,
double curve,
double dip,
double slp){
192 int sign=int(curve/fabs(curve));
193 double phase=slp - sign*PI/2.0;
205 inline StPhysicalHelix getStPhysicalHelix(
double *p) {
return getStPhysicalHelix(p[0],p[1],p[2],p[3],p[4]);}
207 inline StPhysicalHelix getStPhysicalHelix(
double x0,
double y0,
double dxdz,
double dydz,
double curve,
int sign) {
208 double dr=sqrt(dxdz*dxdz+dydz*dydz);
209 double dip = atan2(1.0,dr);
210 double slp = atan2(dydz,dxdz);
211 return getStPhysicalHelix(x0,y0,curve*sign,dip,slp);
214 void getZvtxAndDcaFromHelix(
double* par,
double& dca,
double& z,
double &eta,
double &phi,
double& opt){
227 double xyz2[3]={par[0], par[1], 0.0};
228 double dir2[3]={cos(par[4])/tan(par[3]),sin(par[4])/tan(par[3]),1.0};
235 double x0=0, y0=0, z0=0;
236 if(mFgtInputRPhi>0){ x0=vSeed->x0(); y0=vSeed->y0();}
238 for(
int i=0; i<5; i++){
243 x0=vSeed->x0()+vSeed->dxdz()*z0;
244 y0=vSeed->y0()+vSeed->dydz()*z0;
246 double x=hh.Pos()[0], y=hh.Pos()[1], z=hh.Pos()[2];
247 double dx=x-x0, dy=y-y0, dz=z-z0;
248 dca=sqrt(dx*dx+dy*dy+dz*dz);
253 double bfield=0.5*tesla;
258 int sign=h.charge(bfield);
259 eta=p.pseudoRapidity();
307 void getAlign(
int itrk, fgtAlignment_st* algpar){
308 memcpy(&mHitAlg,&mHit[mQuad][itrk],
sizeof(mHitAlg));
309 if(mFgtInputRPhi==0)
return;
310 if(mDebug>3) printf(
"getAlign quad=%1d trk=%d mHitAlg.nhit=%d %d\n",mQuad,itrk,mHitAlg.nhit,mHit[mQuad][itrk].nhit);
311 for(
int i=0; i<mHitAlg.nhit; i++){
312 if(mHitAlg.det[i]<24){
313 double r=mHitAlg.lr[i];
314 double phi=mHitAlg.lp[i];
315 int disc=mHitAlg.det[i]/4;
316 int quad=mHitAlg.det[i]%4;
318 mDb->getStarXYZ(disc,quad,r,phi,xyz,2,algpar);
321 double local[3]={0,0,0}, global[3]={0,0,0};
323 TGeoHMatrix globalMatrix = gStTpcDb->Tpc2GlobalMatrix();
324 globalMatrix.LocalToMaster(local,global);
325 gxyz.SetXYZ(global[0],global[1],global[2]);
332 printf(
"StFgtAlignmentMaker::Make could not get gStTpcDb... global xyz is same as fgt local xyz\n");
337 mHitAlg.x[i]=gxyz.X();
338 mHitAlg.y[i]=gxyz.Y();
339 mHitAlg.z[i]=gxyz.Z();
340 mHitAlg.r[i]=sqrt(mHitAlg.x[i]*mHitAlg.x[i]+mHitAlg.y[i]*mHitAlg.y[i]);
341 mHitAlg.p[i]=atan2(mHitAlg.y[i],mHitAlg.x[i]);
344 if(mDebug>3) printf(
"mHit[%3d] x=%8.3f y=%8.3f z=%8.3f det=%2d\n",i,
345 mHitAlg.x[i],mHitAlg.y[i],mHitAlg.z[i],mHitAlg.det[i]);
350 void fillHist(
int disc,
int quad,
float dx,
float dy,
float dr,
float dp,
float x,
float y,
float r,
float p){
351 hist1[disc][quad][0]->Fill(dx);
352 hist1[disc][quad][1]->Fill(dy);
353 hist1[disc][quad][2]->Fill(dr);
354 hist1[disc][quad][3]->Fill(dp);
355 hist2[disc][quad][0]->Fill(x,dx);
356 hist2[disc][quad][1]->Fill(x,dy);
357 hist2[disc][quad][2]->Fill(r,dr);
358 hist2[disc][quad][3]->Fill(r,dp);
359 hist2[disc][quad][4]->Fill(y,dx);
360 hist2[disc][quad][5]->Fill(y,dy);
361 hist2[disc][quad][6]->Fill(p,dr);
362 hist2[disc][quad][7]->Fill(p,dp);
363 if(mDebug>3) cout << Form(
"FillHist d=%1d q=%1d dx=%8.3f dy=%8.3f dr=%8.3f dp=%9.5f",
364 disc,quad,dx,dy,dr,dp) <<endl;
370 void eventDisplay(
double *par){
375 TGraph *hitxz=
new TGraph(mHitAlg.nhit); hitxz->SetMarkerStyle(21); hitxz->SetMarkerSize(0.4); hitxz->SetMarkerColor(kBlue);
376 TGraph *hityz=
new TGraph(mHitAlg.nhit); hityz->SetMarkerStyle(21); hityz->SetMarkerSize(0.4); hityz->SetMarkerColor(kBlue);
377 TGraph *hitpr=
new TGraph(mHitAlg.nhit); hitpr->SetMarkerStyle(21); hitpr->SetMarkerSize(0.4); hitpr->SetMarkerColor(kBlue);
379 for(
int i=0; i<mHitAlg.nhit; i++){
384 double dx = x - mHitAlg.x[i];
385 double dy = y - mHitAlg.y[i];
387 double dp = atan2(y,x) - atan2(mHitAlg.y[i],mHitAlg.x[i]);
390 double hx=mHitAlg.x[i];
391 double hy=mHitAlg.y[i];
392 double hz=mHitAlg.z[i];
393 double hr=sqrt(hx*hx+hy*hy);
395 hitxz->SetPoint(i,hz,dx);
396 hityz->SetPoint(i,hz,dy);
397 if(fabs(dp)<0.1) hitpr->SetPoint(i,hr,dp);
400 TCanvas *c1=
new TCanvas(
"EventDisp",
"Event Disp",0,0,800,800);
402 c1->cd(1); hitxz->Draw(
"AP");
403 c1->cd(2); hityz->Draw(
"AP");
404 c1->cd(3); hitpr->Draw(
"AP");
410 void fitHelix(Int_t &npar, Double_t* gin, Double_t &f, Double_t *par, Int_t iflag){
411 if(mDebug>4) printf(
"fitHelix nhit=%d\n",mHitAlg.nhit);
417 for(
int i=0; i<mHitAlg.nhit; i++){
418 if(mHitAlg.use[i]==
false)
continue;
419 if(mHitAlg.det[i]/4==6) ifvtx=1;
422 double dx = h.
x(s) - mHitAlg.x[i];
423 double dy = h.y(s) - mHitAlg.y[i];
424 f += (dx*dx+dy*dy)/(mHitAlg.ex[i]*mHitAlg.ex[i]+mHitAlg.ey[i]*mHitAlg.ey[i]);
426 if(mDebug>5) printf(
"Helix1 Curve=%12.9f x=%8.3f y=%8.3f dx=%8.4f dy=%8.4f f=%8.4fe\n",par[2],h.
x(s),h.y(s),dx,dy,f);
428 if(ifvtx==0 && mBeamLine==1){
429 double z,dca,eta,phi,opt;
430 getZvtxAndDcaFromHelix(par,dca,z,eta,phi,opt);
431 f += dca*dca/mErrVTX/mErrVTX;
435 if(ndf<=0) printf(
"ERROR fitHelix ndf=%d\n",ndf);
437 if(mDebug>4) printf(
"fitHelix x0=%12.8f y0=%12.8f c=%12.8f dip=%12.8f phase=%12.8f f=%12.8f\n",
438 par[0],par[1],par[2],par[3],par[4],f);
442 double residHelix(
double *par){
446 int ifvtx=0, ifvtx2=0;
448 for(
int i=0; i<mHitAlg.nhit; i++){
453 double dx = mHitAlg.x[i] - x;
454 double dy = mHitAlg.y[i] - y;
455 int disc=mHitAlg.det[i]/4;
456 double ff=(dx*dx+dy*dy)/(mHitAlg.ex[i]*mHitAlg.ex[i]+mHitAlg.ey[i]*mHitAlg.ey[i]);
457 if(mResidMaskDisc & (1<<disc)) {
462 if(mHitMaskDisc & (1<<disc)) {
463 if(disc==6) ifvtx2=1;
467 if(mDebug>3) printf(
"residHelix %3d dx=%12.8f dy=%12.8f f=%12.8f\n",i,dx,dy,f);
469 double r=sqrt(x*x+y*y);
470 double phi=atan2(y,x);
471 double hx=mHitAlg.x[i];
472 double hy=mHitAlg.y[i];
473 double hr=mHitAlg.r[i];
474 double hp=mHitAlg.p[i];
478 while(dp>PI) dp-=2*PI;
479 while(dp<-PI) dp+=2*PI;
484 int quad=mHitAlg.det[i]%4;
485 if(disc<kFgtNumDiscs){
486 while(phi>StFgtGeom::phiQuadXaxis(2)) phi-=2*PI;
487 while(phi<StFgtGeom::phiQuadXaxis(1)) phi+=2*PI;
489 fillHist(disc,quad,dx,dy,dr,dp,x,y,r,phi);
492 if(ifvtx+ifvtx2<2 && mBeamLine==1){
493 double z,dca,eta,phi,opt;
494 getZvtxAndDcaFromHelix(par,dca,z,eta,phi,opt);
495 if(ifvtx==0) {f += dca*dca/mErrVTX/mErrVTX; ndf++; }
496 if(ifvtx2==0) {chi2 += dca*dca/mErrVTX/mErrVTX; ndf2++;}
499 if(ndf<=0) printf(
"ERROR resudHelix ndf=%d\n",ndf);
503 if(ndf2<=0) {printf(
"ERROR residHelix ndf2=%d\n",ndf2);}
504 else {chi2/=double(ndf2);}
505 double z,dca,eta,phi,opt;
506 getZvtxAndDcaFromHelix(par,dca,z,eta,phi,opt);
507 if(mDebug>0) printf(
"UPDATE Dca=%8.4f->%8.4f trkz=%8.4f->%8.4f chi2=%8.4f->%8.4f ndf=%d\n",mHitAlg.dca,dca,mHitAlg.trkz,z,mHitAlg.chi2,chi2,ndf2);
509 mHitAlg.dz=mHitAlg.dz-mHitAlg.trkz+z;
516 if(mFillHist>1 && mEventDisp) eventDisplay(par);
518 printf(
"residHelix x0=%12.8f y0=%12.8f c=%12.8f dip=%12.8f phase=%12.8f f=%12.8f\n",
519 par[0],par[1],par[2],par[3],par[4],f);
524 void fitTrackHelix(fgtAlignment_st* algpar,
int itrk,
double *par){
526 static double arg[10];
527 static TMinuit *m = 0;
531 arg[0] =-1; m->mnexcm(
"SET PRI", arg, 1,flag);
532 arg[0] =-1; m->mnexcm(
"SET NOWarning", arg, 0,flag);
533 arg[0] = 1; m->mnexcm(
"SET ERR", arg, 1,flag);
534 arg[0] = 500; arg[1] = 1.;
537 getAlign(itrk,algpar);
539 double dx = mHitAlg.x[1]-mHitAlg.x[0];
540 double dy = mHitAlg.y[1]-mHitAlg.y[0];
541 double dz = mHitAlg.z[1]-mHitAlg.z[0];
542 double dr = sqrt(dx*dx+dy*dy);
543 double dip = atan2(dz,dr);
544 double slp = atan2(dy,dx);
545 double x0= mHitAlg.x[0]-dx/dz*mHitAlg.z[0];
546 double y0= mHitAlg.y[0]-dy/dz*mHitAlg.z[0];
547 m->mnparm(0,
"x0" ,x0 ,0.1, 0, 0,flag);
548 m->mnparm(1,
"y0" ,y0 ,0.1, 0, 0,flag);
549 m->mnparm(2,
"curv",0.0001 ,1.0, 0, 0,flag);
550 m->mnparm(3,
"dip" ,dip ,0.1, 0, 0,flag);
551 m->mnparm(4,
"slp" ,slp ,0.1, 0, 0,flag);
553 m->mnexcm(
"MIGRAD", arg ,2, flag);
555 for(
int j=0; j<5; j++){ m->GetParameter(j,r,e); par[j]=r;}
559 void funcHelix(Int_t &npar, Double_t* gin, Double_t &f, Double_t *par, Int_t iflag){
560 if(mDebug>3) printf(
"funcHelix mQuad=%d mNtrk=%d\n",mQuad,mNtrk[mQuad]);
562 fgtAlignment_st* algpar= (fgtAlignment_st*)par;
564 for(
int itrk=0; itrk<mNtrk[mQuad]; itrk++){
565 if(mHit[mQuad][itrk].used==0)
continue;
566 fitTrackHelix(algpar,itrk,p);
569 memcpy(&mHit[mQuad][itrk],&mHitAlg,
sizeof(mHitAlg));
574 if(mDebug>3) printf(
"funcHelix f=%12.6f xoff=%12.8f yoff=%12.8f\n",f,algpar->xoff[8],algpar->xoff[8]);
575 static int ncall[4]={0,0,0,0};
577 if(ncall[mQuad]%100==0) printf(
"funcHelix quad=%d ncall=%d f=%12.6f\n",mQuad,ncall[mQuad],f);
581 void fitLine(Int_t &npar, Double_t* gin, Double_t &f, Double_t *par, Int_t iflag){
582 if(mDebug>4) printf(
"fitLine nhit=%d\n",mHitAlg.nhit);
586 for(
int i=0; i<mHitAlg.nhit; i++){
587 if(mHitAlg.use[i]==
false)
continue;
588 if(mHitAlg.det[i]/4==6) ifvtx=1;
589 double dx = par[0] + par[1] * mHitAlg.z[i] - mHitAlg.x[i];
590 double dy = par[2] + par[3] * mHitAlg.z[i] - mHitAlg.y[i];
591 f += (dx*dx+dy*dy)/(mHitAlg.ex[i]*mHitAlg.ex[i]+mHitAlg.ey[i]*mHitAlg.ey[i]);
593 if(mDebug>5) printf(
"dx=%8.4f dy=%8.4f dr=%8.4f\n",dx,dy,f);
595 if(ifvtx==0 && mBeamLine==1){
597 getZvtxAndDca(par,dca,z);
598 f += dca*dca/mErrVTX/mErrVTX;
602 if(ndf<=0) {printf(
"ERROR fitLine ndf=%d\n",ndf);}
603 else {f/=double(ndf);}
604 if(mDebug>4) printf(
"fitLine x0=%12.8f x1=%12.8f y0=%12.8f y1=%12.8f f=%12.8f\n",par[0],par[1],par[2],par[3],f);
608 double residLine(
double *par){
611 int ifvtx=0, ifvtx2=0;
613 for(
int i=0; i<mHitAlg.nhit; i++){
614 double x=par[0] + par[1] * mHitAlg.z[i];
615 double y=par[2] + par[3] * mHitAlg.z[i];
616 double dx = mHitAlg.x[i]-x;
617 double dy = mHitAlg.y[i]-y;
618 int disc=mHitAlg.det[i]/4;
619 if(mResidMaskDisc & (1<<disc)) {
620 f += (dx*dx+dy*dy)/(mHitAlg.ex[i]*mHitAlg.ex[i]+mHitAlg.ey[i]*mHitAlg.ey[i]);
623 if(mHitMaskDisc & (1<<disc)) {
624 chi2 += (dx*dx+dy*dy)/(mHitAlg.ex[i]*mHitAlg.ex[i]+mHitAlg.ey[i]*mHitAlg.ey[i]);
627 if(mDebug>5) printf(
"residLine %3d dx=%12.8f dy=%12.8f dr=%8.2f\n",i,dx,dy,dx*dx+dy*dy);
629 double r=sqrt(x*x+y*y);
630 double phi=atan2(y,x);
631 double hx=mHitAlg.x[i];
632 double hy=mHitAlg.y[i];
633 double hr=mHitAlg.r[i];
634 double hp=mHitAlg.p[i];
637 while(dp>PI) dp-=2*PI;
638 while(dp<-PI) dp+=2*PI;
643 int quad=mHitAlg.det[i]%4;
644 if(disc<kFgtNumDiscs){
645 while(phi>StFgtGeom::phiQuadXaxis(2)) phi-=2*PI;
646 while(phi<StFgtGeom::phiQuadXaxis(1)) phi+=2*PI;
648 fillHist(disc,quad,dx,dy,dr,dp,x,y,r,phi);
658 if(ifvtx+ifvtx2<2 && mBeamLine==1){
660 getZvtxAndDca(par,dca,z);
661 if(ifvtx==0) {f += dca*dca/mErrVTX/mErrVTX; ndf++; }
662 if(ifvtx2==0) {chi2 += dca*dca/mErrVTX/mErrVTX; ndf2++;}
665 if(ndf<=0) printf(
"ERROR residLine ndf=%d\n",ndf);
669 if(ndf2<=0) printf(
"ERROR residLine ndf2=%d\n",ndf2);
673 getZvtxAndDca(par,dca,z);
674 if(mDebug>0) printf(
"UPDATE Dca=%8.4f->%8.4f trkz=%8.4f->%8.4f chi2=%8.4f->%8.4f ndf=%d\n",mHitAlg.dca,dca,mHitAlg.trkz,z,mHitAlg.chi2,chi2,ndf2);
676 mHitAlg.dz=mHitAlg.dz-mHitAlg.trkz+z;
679 double theta=atan2(sqrt(par[1]*par[1]+par[3]*par[3]),1.0);
680 mHitAlg.eta=-log(tan(theta/2.0)) ;
681 mHitAlg.phi=atan2(par[3],par[1]);
684 if(mFillHist>1 && mEventDisp) eventDisplay(par);
685 if(mDebug>4) printf(
"residLine x0=%12.8f x1=%12.8f y0=%12.8f y1=%12.8f f=%12.8f\n",par[0],par[1],par[2],par[3],f);
690 void fitTrackLine(fgtAlignment_st* algpar,
int itrk,
double *par){
692 static double arg[10];
693 static TMinuit *m = 0;
697 arg[0] =-1; m->mnexcm(
"SET PRI", arg, 1,flag);
698 arg[0] =-1; m->mnexcm(
"SET NOWarning", arg, 0,flag);
699 arg[0] = 1; m->mnexcm(
"SET ERR", arg, 1,flag);
700 arg[0] = 500; arg[1] = 1.;
703 getAlign(itrk,algpar);
705 double x1 = (mHitAlg.x[1]-mHitAlg.x[0])/(mHitAlg.z[1]-mHitAlg.z[0]);
706 double y1 = (mHitAlg.y[1]-mHitAlg.y[0])/(mHitAlg.z[1]-mHitAlg.z[0]);
707 double x0 = mHitAlg.x[0] - x1*mHitAlg.z[0];
708 double y0 = mHitAlg.y[0] - y1*mHitAlg.z[0];
709 m->mnparm(0,
"x0",x0,0.1,0,0,flag);
710 m->mnparm(1,
"x1",x1,0.1,0,0,flag);
711 m->mnparm(2,
"y0",y0,0.1,0,0,flag);
712 m->mnparm(3,
"y1",y1,0.1,0,0,flag);
714 m->mnexcm(
"MIGRAD", arg ,2, flag);
716 for(
int j=0; j<4; j++){ m->GetParameter(j,r,e); par[j]=r;}
720 void funcLine(Int_t &npar, Double_t* gin, Double_t &f, Double_t *par, Int_t iflag){
722 if(mDebug>3) printf(
"funcLine mQuad=%d mNtrk=%d\n",mQuad,mNtrk[mQuad]);
724 fgtAlignment_st* algpar= (fgtAlignment_st*)par;
726 for(
int itrk=0; itrk<mNtrk[mQuad]; itrk++){
727 if(mHit[mQuad][itrk].used==0)
continue;
728 fitTrackLine(algpar,itrk,p);
731 memcpy(&mHit[mQuad][itrk],&mHitAlg,
sizeof(mHitAlg));
736 static int ncall[4]={0,0,0,0};
738 if(ncall[mQuad]%100==0) printf(
"funcLine quad=%d ncall=%d f=%12.6f\n",mQuad,ncall[mQuad],f);
743 StFgtAlignmentMaker::StFgtAlignmentMaker(
const Char_t *name) :
StMaker(name),mEventCounter(0),
744 mErrFgt(0.02), mErrVtx(0.02), mErrVtxZ(1.0),
745 mErrTpcI(0.6), mErrTpcO(0.12),mErrTpcZ(0.12),mErrPpt(0.1),mErrEmc(0.3),
746 mFakeNtrk(2000),mFakeEmin(40),mFakeEmax(40),mFakeEtamin(1.6),mFakeEtamax(1.6),
747 mFakePhimin(0),mFakePhimax(0),mFakeVtxSig(0),
749 mOutTreeFile(0),mInTreeFile(0),mReadParFile(0),
750 mRunNumber(0),mSeqNumber(0),mDay(0),mNStep(0){
751 memset(mDzCut ,0,
sizeof(mDzCut ));
752 memset(mDcaCut ,0,
sizeof(mDcaCut ));
753 memset(mFgtRCut,0,
sizeof(mFgtRCut));
754 memset(mFgtPCut,0,
sizeof(mFgtPCut));
755 memset(mTpcRCut,0,
sizeof(mTpcRCut));
756 memset(mTpcPCut,0,
sizeof(mTpcPCut));
757 memset(mEmcRCut,0,
sizeof(mEmcRCut));
758 memset(mEmcPCut,0,
sizeof(mEmcPCut));
761 Int_t StFgtAlignmentMaker::Init(){
762 memset(mNtrk,0,
sizeof(mNtrk));
763 memset(mHit,0,
sizeof(mHit));
768 Int_t StFgtAlignmentMaker::InitRun(Int_t runnum){
769 LOG_INFO <<
"StFgtAlignmentMaker::InitRun for " << runnum << endm;
773 LOG_FATAL <<
"StFgtDb not provided and error finding StFgtDbMaker" << endm;
776 mDb = fgtDbMkr->getDbTables();
778 LOG_FATAL <<
"StFgtDb not provided and error retrieving pointer from StFgtDbMaker '"
779 << fgtDbMkr->
GetName() << endm;
784 cout <<
"mDb="<<mDb<<endl;
785 orig_algpar=mDb->getAlignment();
787 readPar(orig_algpar);
792 static const int mMaxStep=100;
794 void StFgtAlignmentMaker::setStep(
int discmask,
int quadmask,
int parmask,
int hitmask_disc,
int residmask,
795 int trackType,
int minHit,
int minFgtHit,
int minVtx,
int minTpcHit,
int minPromptHit,
int minEemcHit,
796 float dzcut,
float dcacut,
float fgtrcut,
float fgtpcut,
float tpcrcut,
float tpcpcut,
float emcrcut,
float emcpcut){
797 if(mNStep>=mMaxStep) {printf(
"Reached MaxStep\n");
return; }
798 if(mNStep==0) { printf(
"Step0 is making before histo, and masks are set to 0\n"); discmask=0; quadmask=0; parmask=0; }
799 mDiscMask[mNStep]=discmask;
800 mQuadMask[mNStep]=quadmask;
801 mParMask[mNStep]=parmask;
802 mHitMask[mNStep]=hitmask_disc;
803 mResidMask[mNStep]=residmask;
804 mTrackType[mNStep]=trackType;
805 mMinHit[mNStep]=minHit;
806 mMinFgtHit[mNStep]=minFgtHit;
807 mMinVtx[mNStep]=minVtx;
808 mMinTpcHit[mNStep]=minTpcHit;
809 mMinPromptHit[mNStep]=minPromptHit;
810 mMinEemcHit[mNStep]=minEemcHit;
811 mDzCut[mNStep]=dzcut;
812 mDcaCut[mNStep]=dcacut;
813 mFgtRCut[mNStep]=fgtrcut;
814 mFgtPCut[mNStep]=fgtpcut;
815 mTpcRCut[mNStep]=tpcrcut;
816 mTpcPCut[mNStep]=tpcpcut;
817 mEmcRCut[mNStep]=emcrcut;
818 mEmcPCut[mNStep]=emcpcut;
819 printf(
"Adding step=%d with discMask=%x quadMask=%x parMask=%x hitMask=%x trkType=%d minHit=%d minFgt=%d minTpc=%d minPrompt=%d minEemc=%d\n",
820 mNStep,discmask,quadmask,parmask,hitmask_disc,trackType,minHit,minFgtHit,minTpcHit,minPromptHit,minEemcHit);
821 printf(
" Cuts dz=%8.3f dca=%8.3f fgtdr=%8.3f fgtdp=%8.3f tpcdr=%8.3f tpcdp=%8.3f emcdr=%8.3f emcdp=%8.3f\n",
822 mDzCut[mNStep],mDcaCut[mNStep],mFgtRCut[mNStep],mFgtPCut[mNStep],mTpcRCut[mNStep],mTpcPCut[mNStep],mEmcRCut[mNStep],mEmcPCut[mNStep]);
828 orig_algpar=mDb->getAlignment();
839 }
else if(mDataSource==1){
840 readFromStEventGlobal();
841 }
else if(mDataSource==2){
842 readFromStraightTrackMaker();
843 DispFromStraightTrackMaker();
844 }
else if(mDataSource==5){
845 calcETBalanceFromStEvent();
846 readFromStraightTrackAndStEvent();
847 }
else if(mDataSource==6){
848 readFromStraightTrackAndMudst();
854 gMessMgr->Info() <<
"StFgtAlignmentMaker::Finish()" << endm;
856 if(mDataSource==4) {fakeData();}
857 else if(mDataSource==3) {readFromTree();}
859 fgtAlignment_st result;
860 memcpy(&result,orig_algpar,
sizeof(fgtAlignment_st));
862 cout <<
"Doing Alignment with Number of steps = "<<mNStep<<endl;
863 for(
int s=0; s<mNStep; s++){
865 if(mDiscMask[s]+mParMask[s]>0) {mFillHist=0;}
866 else {mFillHist=1; resetHist(); printf(
"Saving hist for step=%d\n",mStep);}
867 for(
int quad=0; quad<kFgtNumQuads; quad++){
869 int quadmask= 1<<quad;
870 if( (mFillHist>0) || (quadmask & mQuadMask[s]) ){
871 cout << Form(
"Doing alignment for quad=%1d with Ntrk=%4d",quad,mNtrk[quad])<<endl;
873 printf(
"Quad=%d Step=%d with discMask=%x quadMask=%x parMask=%x hitMask=%x residMask=%x trkType=%d minHit=%d minFgt=%d vtx=%d minTpc=%d minPrompt=%d minEEmc=%d\n",
874 quad,s,mDiscMask[s],quadmask,mParMask[s],mHitMask[s],mResidMask[s],
875 mTrackType[s],mMinHit[s],mMinFgtHit[s],mMinVtx[s],mMinTpcHit[s],mMinPromptHit[s],mMinEemcHit[s]);
876 printf(
" Cuts dz=%8.3f dca=%8.3f fgtdr=%8.3f fgtdp=%8.3f tpcdr=%8.3f tpcdp=%8.3f emcdr=%8.3f emcdp=%8.3f\n",
877 mDzCut[s],mDcaCut[s],mFgtRCut[s],mFgtPCut[s],mTpcRCut[s],mTpcPCut[s],mEmcRCut[s],mEmcPCut[s]);
878 doAlignment(&result,mDiscMask[s],quadmask,mParMask[s],mHitMask[s],mResidMask[s],
879 mTrackType[s],mMinHit[s],mMinFgtHit[s],mMinVtx[s],mMinTpcHit[s],mMinPromptHit[s],mMinEemcHit[s],&result);
885 if(mOutTreeFile) writeTree();
892 void StFgtAlignmentMaker::fakeData() {
894 orig_algpar=
new fgtAlignment_st;
895 memset(orig_algpar,0,
sizeof(fgtAlignment_st));
898 memset(mHit,0,
sizeof(mHit));
901 for(
int itrk=0; itrk<1; itrk++){
902 mHit[quad][itrk].nhit=0;
903 for(
int d=0; d<10; d++){
905 mHit[quad][itrk].nhit++;
906 if (d==0) {mHit[quad][itrk].det[d]=24+quad; z=0;}
907 else if(d>6) {mHit[quad][itrk].det[d]=28+quad; z=200.0+d;}
909 mHit[quad][itrk].det[d]=(d-1)*4+quad;
910 z=StFgtGeom::getDiscZ(d-1);
912 mHit[quad][itrk].x[d]=20.0/67.399*(z-10); mHit[quad][itrk].ex[d]=0.1;
913 mHit[quad][itrk].y[d]=0.0; mHit[quad][itrk].ey[d]=0.1;
914 mHit[quad][itrk].z[d]=z; mHit[quad][itrk].ez[d]=0.1;
915 if(d==3) mHit[quad][itrk].x[d]+=0.2;
917 cout<<Form(
"Trk=%3d Hit=%3d Quad=%1d Det=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
918 itrk,d,quad,mHit[quad][itrk].det[d],
919 mHit[quad][itrk].x[d],mHit[quad][itrk].y[d],mHit[quad][itrk].z[d],
920 mHit[quad][itrk].ex[d],mHit[quad][itrk].ey[d],mHit[quad][itrk].ez[d])
930 int mFgt=1,mVtx=1,mTpc=0,mPpt=1,mEmc=1;
931 const double B = 0.5*tesla;
934 static const int NTPC=45;
936 for(
int ipad= 0;ipad< 8; ipad++){tpcr[ipad]=60.0 + 4.8*ipad;}
937 for(
int ipad= 8;ipad<13; ipad++){tpcr[ipad]=60.0 + 4.8*7 + 5.2*(ipad-8);}
938 for(
int ipad=13;ipad<45; ipad++){tpcr[ipad]=127.950 + 2.0*(ipad-13);}
942 for(
int itrk=0; itrk<mFakeNtrk; itrk++){
943 double ene=mFakeEmin;
944 double eta=mFakeEtamin;
945 double phi=mFakePhimin;
947 if(mFakeEmax>mFakeEmin) ene=rand.Uniform(mFakeEmin,mFakeEmax);
948 if(mFakeEtamax>mFakeEtamin) eta=rand.Uniform(mFakeEtamin,mFakeEtamax);
949 if(mFakePhimax>mFakePhimin) phi=rand.Uniform(mFakePhimin,mFakePhimax);
952 while (zz>60 || zz<-120) {zz=rand.Gaus(0,mFakeVtxSig);}
956 double theta=2*atan(exp(-eta));
957 double pt=ene*sin(theta);
958 double pz=ene*cos(theta);
959 double px=ene*sin(theta)*cos(phi);
960 double py=ene*sin(theta)*sin(phi);
965 printf(
"FAKE pt=%8.3f eta=%8.3f phi=%8.3f ene=%8.3f\n",pt,eta,phi,ene);
966 printf(
"FAKE pxyz=%8.3f %8.3f %8.3f\n",px,py,pz);
967 printf(
"FAKE vxyz=%8.3f %8.3f %8.3f\n",v.x(),v.y(),v.z());
969 for (
double z=0; z<=300; z+=20) {
971 double sp=pos.pathLength(zplane,zvec);
972 double sn=pos.pathLength(zplane,zvec);
975 printf(
"FAKE z=%8.3f pos=%8.3f %8.3f neg=%8.3f %8.3f\n",z,pxyz.x(),pxyz.y(),nxyz.x(),nxyz.y());
981 if(itrk%2==0) {trk=pos;}
988 mHit[mQuad][itrk].x[nhit]=xyz.x(); mHit[mQuad][itrk].y[nhit]=xyz.y(); mHit[mQuad][itrk].z[nhit]=xyz.z();
989 mHit[mQuad][itrk].ex[nhit]=mErrVtx; mHit[mQuad][itrk].ey[nhit]=mErrVtx; mHit[mQuad][itrk].ez[nhit]=mErrVtxZ;
990 mHit[mQuad][itrk].det[nhit]=4*6+mQuad;
992 if(itrk<5) printf(
"VTX %8.3f %8.3f %8.3f %8.4f %8.4f\n",xyz.x(),xyz.y(),xyz.z(),mErrVtx,mErrVtxZ);
994 mHit[mQuad][itrk].dz=0;
995 mHit[mQuad][itrk].trkz=v.z();
998 for(
int idisc=0; idisc<6; idisc++){
999 if(idisc==3)
continue;
1003 if(xyz.perp()>10.0 && xyz.perp()<38.3){
1004 mHit[mQuad][itrk].x[nhit]=xyz.x(); mHit[mQuad][itrk].y[nhit]=xyz.y(); mHit[mQuad][itrk].z[nhit]=xyz.z();
1005 mHit[mQuad][itrk].ex[nhit]=mErrFgt; mHit[mQuad][itrk].ey[nhit]=mErrFgt; mHit[mQuad][itrk].ez[nhit]=0.0;
1006 mHit[mQuad][itrk].det[nhit]=4*idisc+mQuad;
1009 if(itrk<5) printf(
"FGT%1d %8.3f %8.3f %8.3f %8.4f\n",idisc+1,xyz.x(),xyz.y(),xyz.z(),mErrFgt);
1012 if(nfgt<3) {
continue;}
1015 for(
int ipad=0; ipad<NTPC; ipad++){
1016 double r=tpcr[ipad];
1019 if(s<0) s=ss.second;
1023 mHit[mQuad][itrk].x[nhit]=xyz.x(); mHit[mQuad][itrk].y[nhit]=xyz.y(); mHit[mQuad][itrk].z[nhit]=xyz.z();
1024 if(ipad<13) {mHit[mQuad][itrk].ex[nhit]=mErrTpcI; mHit[mQuad][itrk].ey[nhit]=mErrTpcI;}
1025 else {mHit[mQuad][itrk].ex[nhit]=mErrTpcO; mHit[mQuad][itrk].ey[nhit]=mErrTpcO;}
1026 mHit[mQuad][itrk].ez[nhit]=mErrTpcZ;
1027 mHit[mQuad][itrk].det[nhit]=4*7+mQuad;
1029 if(itrk<5) printf(
"TPC %8.3f %8.3f %8.3f %8.4f %8.4f\n",xyz.x(),xyz.y(),xyz.z(),mHit[mQuad][itrk].ex[nhit],mErrTpcZ);
1037 if(xyz.perp()>tpcr[0] && xyz.perp()<tpcr[NTPC-1]){
1038 mHit[mQuad][itrk].x[nhit]=xyz.x(); mHit[mQuad][itrk].y[nhit]=xyz.y(); mHit[mQuad][itrk].z[nhit]=xyz.z();
1039 mHit[mQuad][itrk].ex[nhit]=mErrPpt; mHit[mQuad][itrk].ey[nhit]=mErrPpt; mHit[mQuad][itrk].ez[nhit]=0.0;
1040 mHit[mQuad][itrk].det[nhit]=4*8+mQuad;
1042 if(itrk<5) printf(
"PPT %8.3f %8.3f %8.3f %8.4f\n",xyz.x(),xyz.y(),xyz.z(),mErrPpt);
1049 if(xyz.perp()>tpcr[0] && xyz.perp()<tpcr[NTPC-1]){
1050 mHit[mQuad][itrk].x[nhit]=xyz.x(); mHit[mQuad][itrk].y[nhit]=xyz.y(); mHit[mQuad][itrk].z[nhit]=xyz.z();
1051 mHit[mQuad][itrk].ex[nhit]=mErrEmc; mHit[mQuad][itrk].ey[nhit]=mErrEmc; mHit[mQuad][itrk].ez[nhit]=0.0;
1052 mHit[mQuad][itrk].det[nhit]=4*11+mQuad;
1053 mHit[mQuad][itrk].tw[nhit]=float(ene);
1054 mHit[mQuad][itrk].nrl[nhit]=0;
1055 mHit[mQuad][itrk].su[nhit]=100.0;
1056 mHit[mQuad][itrk].sv[nhit]=100.0;
1058 if(itrk<5) printf(
"EMC %8.3f %8.3f %8.3f %8.4f\n",xyz.x(),xyz.y(),xyz.z(),mErrEmc);
1061 mHit[mQuad][itrk].nhit=nhit;
1062 mHit[mQuad][itrk].dca=0.0;
1063 mHit[mQuad][itrk].chi2=0.0;
1064 mHit[mQuad][itrk].riso=1.0;
1066 for(
int ii=0; ii<nhit; ii++){
1067 mHit[mQuad][itrk].x[ii]+= mHit[mQuad][itrk].ex[ii]*rand.Gaus();
1068 mHit[mQuad][itrk].y[ii]+= mHit[mQuad][itrk].ey[ii]*rand.Gaus();
1069 mHit[mQuad][itrk].z[ii]+= mHit[mQuad][itrk].ez[ii]*rand.Gaus();
1070 mHit[mQuad][itrk].r[ii]=sqrt(mHit[mQuad][itrk].x[ii]*mHit[mQuad][itrk].x[ii]+mHit[mQuad][itrk].y[ii]*mHit[mQuad][itrk].y[ii]);
1071 mHit[mQuad][itrk].p[ii]=atan2(mHit[mQuad][itrk].y[ii],mHit[mQuad][itrk].x[ii]);
1074 mNtrk[mQuad]=mFakeNtrk;
1078 void StFgtAlignmentMaker::readFromStraightTrackMaker(){
1089 int nPrimV=muDst->numberOfPrimaryVertices();
1092 vertex=V->position();
1093 vtxerr=V->posError();
1102 gMessMgr->Warning() <<
"StFgtAlignmentMaker::Make : No StFgtStraightTrackMaker" << endm;
1105 vector<AVTrack>& tracks=fgtSTracker->getTracks();
1106 for(vector<AVTrack>::iterator t=tracks.begin();t!=tracks.end();t++){
1107 if(mDebug>0) cout<<Form(
"Trk chi2=%8.3f dca=%8.3f",t->chi2,t->dca)<<endl;
1108 vector<AVPoint>* points=t->points;
1109 int quad=-1, nhit=0, ntrk=-1;
1110 for(vector<AVPoint>::iterator p=points->begin(); p!=points->end();p++){
1112 int quad2=p->quadID;
1113 if(quad==-1) quad=quad2;
1115 mHit[quad][ntrk].det[nhit]=disc*4+quad2;
1116 mHit[quad][ntrk].lr[nhit]=p->r;
1117 mHit[quad][ntrk].lp[nhit]=p->phi;
1118 mHit[quad][ntrk].z[nhit]=StFgtGeom::getDiscZ(disc);
1119 mHit[quad][ntrk].ex[nhit]=mErrFgt;
1120 mHit[quad][ntrk].ey[nhit]=mErrFgt;
1121 mHit[quad][ntrk].ez[nhit]=0;
1122 if(mDebug>0) cout<<Form(
"Trk=%3d Hit=%3d Quad=%1d Det=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
1123 ntrk,nhit,quad,mHit[quad][ntrk].det[nhit],
1124 mHit[quad][ntrk].x[nhit],mHit[quad][ntrk].y[nhit],mHit[quad][ntrk].z[nhit],
1125 mHit[quad][ntrk].ex[nhit],mHit[quad][ntrk].ey[nhit],mHit[quad][ntrk].ez[nhit])
1130 mHit[quad][ntrk].det[nhit]=24+quad;
1131 mHit[quad][ntrk].x[nhit]=vertex.x();
1132 mHit[quad][ntrk].y[nhit]=vertex.y();
1133 mHit[quad][ntrk].z[nhit]=vertex.z();
1134 mHit[quad][ntrk].ex[nhit]=vtxerr.x();
1135 mHit[quad][ntrk].ey[nhit]=vtxerr.y();
1136 mHit[quad][ntrk].ez[nhit]=vtxerr.z();
1137 if(mDebug>0) cout<<Form(
"Trk=%3d Hit=%3d Quad=%1d Det=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
1138 ntrk,nhit,quad,mHit[quad][ntrk].det[nhit],
1139 mHit[quad][ntrk].x[nhit],mHit[quad][ntrk].y[nhit],mHit[quad][ntrk].z[nhit],
1140 mHit[quad][ntrk].ex[nhit],mHit[quad][ntrk].ey[nhit],mHit[quad][ntrk].ez[nhit])
1144 mHit[quad][ntrk].nhit=nhit;
1145 mHit[quad][ntrk].dca =t->dca;
1146 mHit[quad][ntrk].chi2=t->chi2;
1149 if(mEventCounter%100==0) cout << Form(
"StFgtAlignmentMaker::readFromStraightTrackMaker EVT=%d NTRK=%d %d %d %d",
1150 mEventCounter,mNtrk[0],mNtrk[1],mNtrk[2],mNtrk[3])<<endl;
1153 void StFgtAlignmentMaker::readFromStraightTrackAndStEvent(){
1154 float MaxDrTpc=maxdtpc, MaxDpTpc=maxptpc;
1155 float MaxDrEemc=maxdemc, MaxDpEemc=maxpemc;
1156 float MaxDz=5.0, MaxDca=3.0, MaxChi2=50;
1163 event = (
StEvent *) GetInputDS(
"StEvent");
1165 gMessMgr->Warning() <<
"StFgtAlignmentMaker::Make : No StEvent" << endm;
1168 cout <<
"Event: Run "<<
event->runId() <<
" Event No: " <<
event->id() << endl;
1173 UInt_t NpVX =
event->numberOfPrimaryVertices();
1174 cout <<
"Number of Primary vertex="<<NpVX<<endl;
1177 cout <<
"Verrex :" << *vx << endl;
1178 vertex=vx->position();
1179 vtxerr=vx->positionError();
1182 vertex.set(0.0,0.0,-999.0);
1183 vtxerr.set(999.0,999.0,999.0);
1190 gMessMgr->Warning() <<
"StFgtAlignmentMaker::Make : No SyFgtStraightTrackMaker" << endm;
1193 vector<AVTrack>& tracks=fgtSTracker->getTracks();
1194 for(vector<AVTrack>::iterator t=tracks.begin();t!=tracks.end();t++){
1196 if(flagvtx){dz=t->trkZ - vertex.z();}
1197 if(mDebug>0) cout<<Form(
"Trk chi2=%8.3f dca=%8.3f zvtx=%8.3f dz=%8.3f",t->chi2,t->dca,t->trkZ,dz)<<endl;
1198 if(t->dca>MaxDca)
continue;
1199 if(t->chi2>MaxChi2)
continue;
1200 vector<AVPoint>* points=t->points;
1201 int quad=-1, nhit=0, ntrk=-1;
1203 for(vector<AVPoint>::iterator p=points->begin(); p!=points->end();p++){
1205 int quad2=p->quadID;
1206 if(quad==-1) {quad=quad2; mQuad=quad;}
1208 mHit[quad][ntrk].det[nhit]=disc*4+quad2;
1209 mHit[quad][ntrk].lr[nhit]=p->r;
1210 mHit[quad][ntrk].lp[nhit]=p->phi;
1211 mHit[quad][ntrk].z[nhit]=StFgtGeom::getDiscZ(disc);
1212 mHit[quad][ntrk].ex[nhit]=mErrFgt;
1213 mHit[quad][ntrk].ey[nhit]=mErrFgt;
1214 mHit[quad][ntrk].ez[nhit]=0;
1215 mHit[quad][ntrk].tw[nhit]=p->phiCharge;
1216 mHit[quad][ntrk].p1[nhit]=p->rCharge;
1217 mHit[quad][ntrk].p2[nhit]=(p->phiCharge-p->rCharge)/(p->phiCharge+p->rCharge);
1218 mHit[quad][ntrk].po[nhit]=p->fgtHitPhi->getEvenOddChargeAsy();
1219 mHit[quad][ntrk].use[nhit]=1;
1220 if(mDebug>0) cout<<Form(
"Trk=%3d Hit=%3d Quad=%1d Det=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
1221 ntrk,nhit,quad,mHit[quad][ntrk].det[nhit],
1222 mHit[quad][ntrk].x[nhit],mHit[quad][ntrk].y[nhit],mHit[quad][ntrk].z[nhit],
1223 mHit[quad][ntrk].ex[nhit],mHit[quad][ntrk].ey[nhit],mHit[quad][ntrk].ez[nhit])
1228 if(flagvtx==1 && fabs(dz)<MaxDz){
1229 mHit[quad][ntrk].det[nhit]=24+quad;
1230 mHit[quad][ntrk].x[nhit]=vertex.x();
1231 mHit[quad][ntrk].y[nhit]=vertex.y();
1232 mHit[quad][ntrk].z[nhit]=vertex.z();
1233 mHit[quad][ntrk].r[nhit]=sqrt(vertex.x()*vertex.x()+vertex.y()*vertex.y());
1234 mHit[quad][ntrk].p[nhit]=atan2(vertex.y(),vertex.x());
1235 mHit[quad][ntrk].ex[nhit]=vtxerr.x();
1236 mHit[quad][ntrk].ey[nhit]=vtxerr.y();
1237 mHit[quad][ntrk].ez[nhit]=vtxerr.z();
1238 mHit[quad][ntrk].use[nhit]=1;
1239 if(mDebug>0) cout<<Form(
"Trk=%3d Hit=%3d Quad=%1d Det=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
1240 ntrk,nhit,quad,mHit[quad][ntrk].det[nhit],
1241 mHit[quad][ntrk].x[nhit],mHit[quad][ntrk].y[nhit],mHit[quad][ntrk].z[nhit],
1242 mHit[quad][ntrk].ex[nhit],mHit[quad][ntrk].ey[nhit],mHit[quad][ntrk].ez[nhit])
1246 mHit[quad][ntrk].run=
event->runId();
1247 mHit[quad][ntrk].evt=
event->id();
1248 mHit[quad][ntrk].dca =t->dca;
1249 mHit[quad][ntrk].trkz =t->trkZ;
1250 mHit[quad][ntrk].dz =dz;
1251 mHit[quad][ntrk].chi2=t->chi2;
1252 mHit[quad][ntrk].nhit=nhit;
1258 fitTrackLine(orig_algpar,ntrk,p);
1260 printf(
"FGT ONLY TRA CK : %8.4f %8.4f %8.4f %8.4f\n",t->ax,t->mx,t->ay,t->my);
1261 printf(
"REFIT with VTX : %8.4f %8.4f %8.4f %8.4f\n",p[0],p[1],p[2],p[3]);
1263 }
else{ p[0]=t->ax; p[1]=t->mx; p[2]=t->ay; p[3]=t->my;}
1266 double ddr2=99999999;
1267 mHit[quad][ntrk].nhitEemc=0;
1270 StEEmcIUPointVec_t mPoints = mEEpoints->
points();
1271 for ( Int_t ipoint=0; ipoint<mEEpoints->
numberOfPoints(); ipoint++){
1276 float r=sqrt(x*x + y*y);
1277 float phi=atan2(y,x);
1278 float e[6];
int w[3];
1280 e[1]=point.
energy(1)*1000;
1281 e[2]=point.
energy(2)*1000;
1282 e[3]=point.
energy(3)*1000;
1283 e[4]=point.
cluster(0).energy()*1000;
1284 e[5]=point.
cluster(1).energy()*1000;
1286 w[1]=point.
cluster(0).numberOfStrips();
1287 w[2]=point.
cluster(1).numberOfStrips();
1292 double xx = p[0] + p[1]*z;
1293 double yy = p[2] + p[3]*z;
1294 double rr = sqrt(xx*xx+yy*yy);
1295 double pp = atan2(yy,xx);
1300 while(dp>PI) dp-=2*PI;
1301 while(dp<-PI) dp+=2*PI;
1302 if(mDebug>3) printf(
"EEMC %3d xyrp=%6.1f %6.1f %6.1f %6.2f e=%6.1f %6.1f %6.1f %6.1f %6.1f %6.1f dxyrp=%6.1f %6.1f %6.1f %6.2f\n",
1303 ipoint,x,y,r,phi,e[0],e[1],e[2],e[3],e[4],e[5],dx,dy,dr,dp);
1304 if(dr < 0.5*rr-25.0 &&
1305 fabs(dr)<MaxDrEemc && fabs(dp)<MaxDpEemc && e[1]>0.05 && e[2]>0.05){
1306 mHit[quad][ntrk].det[nhit]=36+quad;
1307 if(w[0]==0 && e[0]<1.5 && e[1]<4 && e[2]<4 && e[3]>0.05){
1308 mHit[quad][ntrk].det[nhit]=40+quad;
1310 if(e[0]>1 && e[1]>2 && e[2]>3 && e[2]>e[1] && (e[4]+e[5])/e[0]>10){
1311 mHit[quad][ntrk].det[nhit]=44+quad;
1313 if(mHit[quad][ntrk].nhitEemc>0 && (dx*dx+dy*dy)>ddr2)
continue;
1315 mHit[quad][ntrk].nhitEemc=1;
1316 mHit[quad][ntrk].x[nhit]=x;
1317 mHit[quad][ntrk].y[nhit]=y;
1318 mHit[quad][ntrk].z[nhit]=z;
1319 mHit[quad][ntrk].r[nhit]=sqrt(x*x+y*y);
1320 mHit[quad][ntrk].p[nhit]=atan2(y,x);
1321 mHit[quad][ntrk].ex[nhit]=0.3;
1322 mHit[quad][ntrk].ey[nhit]=0.3;
1323 mHit[quad][ntrk].ez[nhit]=0.3;
1324 mHit[quad][ntrk].tw[nhit]=e[0];
1325 mHit[quad][ntrk].p1[nhit]=e[1];
1326 mHit[quad][ntrk].p2[nhit]=e[2];
1327 mHit[quad][ntrk].po[nhit]=e[3];
1328 mHit[quad][ntrk].su[nhit]=e[4];
1329 mHit[quad][ntrk].sv[nhit]=e[5];
1330 mHit[quad][ntrk].nrl[nhit]=w[0];
1331 mHit[quad][ntrk].nsu[nhit]=w[1];
1332 mHit[quad][ntrk].nsv[nhit]=w[2];
1333 if(mDebug>0) cout<<Form(
"Trk=%3d Hit=%3d Quad=%1d Det=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
1334 ntrk,nhit,quad,mHit[quad][ntrk].det[nhit],
1335 mHit[quad][ntrk].x[nhit],mHit[quad][ntrk].y[nhit],mHit[quad][ntrk].z[nhit],
1336 mHit[quad][ntrk].ex[nhit],mHit[quad][ntrk].ey[nhit],mHit[quad][ntrk].ez[nhit])
1341 if(mHit[quad][ntrk].nhitEemc>0) nhit++;
1346 mHit[quad][ntrk].nhitPrompt=0;
1348 if(TpcHitCollection){
1350 UInt_t numberOfSectors = TpcHitCollection->numberOfSectors();
1351 for (UInt_t i = 0; i< numberOfSectors; i++) {
1353 if (!sectorCollection)
continue;
1355 Int_t numberOfPadrows = sectorCollection->numberOfPadrows();
1356 for (
int j = 0; j< numberOfPadrows; j++) {
1358 if (!rowCollection)
continue;
1360 StSPtrVecTpcHit &hits = rowCollection->hits();
1361 Long64_t NoHits = hits.size();
1364 for (Long64_t k = 0; k < NoHits; k++) {
1367 if(xyz.z()<0)
continue;
1368 if(xyz.z()<200.0)
continue;
1369 double xx = p[0] + p[1]*xyz.z();
1370 double yy = p[2] + p[3]*xyz.z();
1371 double rr = sqrt(xx*xx+yy*yy);
1372 double pp = atan2(yy,xx);
1373 double dx = xyz.x()-xx;
1374 double dy = xyz.y()-yy;
1375 double dr = xyz.perp()-rr;
1376 double dp = atan2(xyz.y(),xyz.x())-pp;
1377 while(dp> PI) dp-=2*PI;
1378 while(dp<-PI) dp+=2*PI;
1379 if(nhit>=MAXHIT){ printf(
"NOT ENOUGH SPACE FOR HIT!!!\n");
continue;}
1380 if(fabs(dr)<MaxDrTpc && fabs(dp)<MaxDpTpc && nhit<MAXHIT){
1381 mHit[quad][ntrk].det[nhit]=28+quad;
1382 if(xyz.z()>200) mHit[quad][ntrk].det[nhit]=32+quad;
1383 if(mHit[quad][ntrk].nhitPrompt>0 && (dx*dx+dy*dy)>ddr2)
continue;
1385 mHit[quad][ntrk].nhitPrompt=1;
1386 mHit[quad][ntrk].x[nhit]=xyz.x();
1387 mHit[quad][ntrk].y[nhit]=xyz.y();
1388 mHit[quad][ntrk].z[nhit]=xyz.z();
1389 mHit[quad][ntrk].r[nhit]=xyz.perp();
1390 mHit[quad][ntrk].p[nhit]=atan2(xyz.y(),xyz.x());
1391 mHit[quad][ntrk].ex[nhit]=0.2;
1392 mHit[quad][ntrk].ey[nhit]=0.2;
1393 mHit[quad][ntrk].ez[nhit]=0.2;
1394 if(mDebug>0) cout<<Form(
"Trk=%3d Hit=%3d Quad=%1d Det=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
1395 ntrk,nhit,quad,mHit[quad][ntrk].det[nhit],
1396 mHit[quad][ntrk].x[nhit],mHit[quad][ntrk].y[nhit],mHit[quad][ntrk].z[nhit],
1397 mHit[quad][ntrk].ex[nhit],mHit[quad][ntrk].ey[nhit],mHit[quad][ntrk].ez[nhit])
1404 if(mHit[quad][ntrk].nhitPrompt>0) nhit++;
1405 mHit[quad][ntrk].nhit=nhit;
1406 fillETBalance(ntrk);
1409 if(mEventCounter%100==0) cout << Form(
"StFgtAlignmentMaker::readFromStraightTrackMaker EVT=%d NTRK=%d %d %d %d",
1410 mEventCounter,mNtrk[0],mNtrk[1],mNtrk[2],mNtrk[3])<<endl;
1413 void StFgtAlignmentMaker::readFromStraightTrackAndMudst(){
1414 float MaxDrEemc=maxdemc, MaxDpEemc=maxpemc;
1415 float MaxDz=10.0, MaxDca=5.0, MaxChi2=50;
1423 gMessMgr->Warning() <<
"StFgtAlignmentMaker::Make : No MuDST" << endm;
1428 gMessMgr->Warning() <<
"StFgtAlignmentMaker::Make : No MuDST event" << endm;
1433 if(mDebug>0) cout <<
"Event: Run "<<
event->runId() <<
" Event No: " <<
event->eventId() << endl;
1438 int nPrimV=muDst->numberOfPrimaryVertices();
1439 if(mDebug>2) cout <<
"Number of Primary vertex="<<nPrimV<<endl;
1442 vertex=vx->position();
1443 vtxerr=vx->posError();
1444 if(mDebug>2) cout <<
"Vertex = " << vertex.z() << endl;
1453 gMessMgr->Warning() <<
"StFgtAlignmentMaker::Make : No SyFgtStraightTrackMaker" << endm;
1456 vector<AVTrack>& tracks=fgtSTracker->getTracks();
1457 for(vector<AVTrack>::iterator t=tracks.begin();t!=tracks.end();t++){
1458 float dz=t->trkZ - vertex.z();
1459 if(mDebug>0) cout<<Form(
"Trk chi2=%8.3f dca=%8.3f zvtx=%8.3f dz=%8.3f",t->chi2,t->dca,t->trkZ,dz)<<endl;
1460 if(t->dca>MaxDca)
continue;
1461 if(t->chi2>MaxChi2)
continue;
1463 if(fabs(dz)>MaxDz)
continue;
1464 vector<AVPoint>* points=t->points;
1465 int quad=-1, nhit=0, ntrk=-1;
1467 for(vector<AVPoint>::iterator p=points->begin(); p!=points->end();p++){
1469 int quad2=p->quadID;
1470 if(quad==-1) {quad=quad2; mQuad=quad;}
1472 mHit[quad][ntrk].run=
event->runId();
1473 mHit[quad][ntrk].evt=
event->eventId();
1474 mHit[quad][ntrk].det[nhit]=disc*4+quad2;
1475 mHit[quad][ntrk].lr[nhit]=p->r;
1476 mHit[quad][ntrk].lp[nhit]=p->phi;
1477 mHit[quad][ntrk].z[nhit]=StFgtGeom::getDiscZ(disc);
1478 mHit[quad][ntrk].ex[nhit]=mErrFgt;
1479 mHit[quad][ntrk].ey[nhit]=mErrFgt;
1480 mHit[quad][ntrk].ez[nhit]=0;
1481 mHit[quad][ntrk].tw[nhit]=p->phiCharge;
1482 mHit[quad][ntrk].p1[nhit]=p->rCharge;
1483 mHit[quad][ntrk].p2[nhit]=(p->phiCharge-p->rCharge)/(p->phiCharge+p->rCharge);
1484 mHit[quad][ntrk].po[nhit]=p->fgtHitPhi->getEvenOddChargeAsy();
1485 mHit[quad][ntrk].use[nhit]=1;
1486 if(mDebug>0) cout<<Form(
"Trk=%3d Hit=%3d Quad=%1d Disc=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
1487 ntrk,nhit,quad,mHit[quad][ntrk].det[nhit]/4,
1488 mHit[quad][ntrk].x[nhit],mHit[quad][ntrk].y[nhit],mHit[quad][ntrk].z[nhit],
1489 mHit[quad][ntrk].ex[nhit],mHit[quad][ntrk].ey[nhit],mHit[quad][ntrk].ez[nhit])
1495 mHit[quad][ntrk].det[nhit]=24+quad;
1496 mHit[quad][ntrk].x[nhit]=vertex.x();
1497 mHit[quad][ntrk].y[nhit]=vertex.y();
1498 mHit[quad][ntrk].z[nhit]=vertex.z();
1499 mHit[quad][ntrk].r[nhit]=sqrt(vertex.x()*vertex.x()+vertex.y()*vertex.y());
1500 mHit[quad][ntrk].p[nhit]=atan2(vertex.y(),vertex.x());
1501 mHit[quad][ntrk].ex[nhit]=vtxerr.x();
1502 mHit[quad][ntrk].ey[nhit]=vtxerr.y();
1503 mHit[quad][ntrk].ez[nhit]=vtxerr.z();
1504 mHit[quad][ntrk].use[nhit]=0;
1505 if(mDebug>-1) cout<<Form(
"Trk=%3d Hit=%3d Quad=%1d Disc=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
1506 ntrk,nhit,quad,mHit[quad][ntrk].det[nhit]/4,
1507 mHit[quad][ntrk].x[nhit],mHit[quad][ntrk].y[nhit],mHit[quad][ntrk].z[nhit],
1508 mHit[quad][ntrk].ex[nhit],mHit[quad][ntrk].ey[nhit],mHit[quad][ntrk].ez[nhit])
1512 mHit[quad][ntrk].dca =t->dca;
1513 mHit[quad][ntrk].trkz =t->trkZ;
1514 mHit[quad][ntrk].dz =dz;
1515 mHit[quad][ntrk].chi2=t->chi2;
1516 mHit[quad][ntrk].nhit=nhit;
1523 double arg[10],r, e;
1524 TMinuit *m =
new TMinuit(4);
1526 arg[0] =-1; m->mnexcm(
"SET PRI", arg, 1,flg);
1527 arg[0] = 1; m->mnexcm(
"SET ERR", arg, 1,flg);
1528 arg[0] = 500; arg[1] = 1.;
1530 getAlign(ntrk,orig_algpar);
1532 double x1 = (mHitAlg.x[mHitAlg.nhit-1]-mHitAlg.x[0])/(mHitAlg.z[mHitAlg.nhit-1]-mHitAlg.z[0]);
1533 double y1 = (mHitAlg.y[mHitAlg.nhit-1]-mHitAlg.y[0])/(mHitAlg.z[mHitAlg.nhit-1]-mHitAlg.z[0]);
1534 double x0 = mHitAlg.x[0] - x1*mHitAlg.z[0];
1535 double y0 = mHitAlg.y[0] - y1*mHitAlg.z[0];
1536 m->mnparm(0,
"x0",x0,0.1,0,0,flg);
1537 m->mnparm(1,
"x1",x1,0.1,0,0,flg);
1538 m->mnparm(2,
"y0",y0,0.1,0,0,flg);
1539 m->mnparm(3,
"y1",y1,0.1,0,0,flg);
1541 m->mnexcm(
"MIGRAD", arg ,2, flg);
1542 for(
int j=0; j<4; j++){ m->GetParameter(j,r,e); p[j]=r; }
1544 printf(
"FGT ONLY TRACK : %8.4f %8.4f %8.4f %8.4f\n",t->ax,t->mx,t->ay,t->my);
1545 printf(
"REFIT with VTX : %8.4f %8.4f %8.4f %8.4f\n",p[0],p[1],p[2],p[3]);
1548 p[0]=t->ax; p[1]=t->mx; p[2]=t->ay; p[3]=t->mx;
1552 mHit[quad][ntrk].nhitEemc=0;
1554 if(!mEEpoints) {printf(
"No EEMC Point\n");}
1556 StEEmcIUPointVec_t mPoints = mEEpoints->
points();
1557 for ( Int_t ipoint=0; ipoint<mEEpoints->
numberOfPoints(); ipoint++){
1562 float r=sqrt(x*x + y*y);
1563 float phi=atan2(y,x);
1564 float e[6];
int w[3];
1566 e[1]=point.
energy(1)*1000;
1567 e[2]=point.
energy(2)*1000;
1568 e[3]=point.
energy(3)*1000;
1569 e[4]=point.
cluster(0).energy()*1000;
1570 e[5]=point.
cluster(1).energy()*1000;
1572 w[1]=point.
cluster(0).numberOfStrips();
1573 w[2]=point.
cluster(1).numberOfStrips();
1576 double xx = p[0] + p[1]*z;
1577 double yy = p[2] + p[3]*z;
1578 double rr = sqrt(xx*xx + yy*yy);
1579 double pp = atan2(yy,xx);
1584 while(dp>PI) dp-=2*PI;
1585 while(dp<-PI) dp+=2*PI;
1586 if(mDebug>3) printf(
"EEMC %3d xyrp=%6.1f %6.1f %6.1f %6.2f e=%6.1f %6.1f %6.1f %6.1f %6.1f %6.1f dxyrp=%6.1f %6.1f %6.1f %6.2f\n",
1587 ipoint,x,y,r,phi,e[0],e[1],e[2],e[3],e[4],e[5],dx,dy,dr,dp);
1588 if(dr < 0.5*rr-25.0 &&
1589 fabs(dr)<MaxDrEemc && fabs(dp)<MaxDpEemc && e[1]>0.05 && e[2]>0.05){
1590 mHit[quad][ntrk].det[nhit]=36+quad;
1591 if(w[0]==0 && e[0]<1.5 && e[1]<4 && e[2]<4 && e[3]>0.05){
1592 mHit[quad][ntrk].det[nhit]=40+quad;
1594 if(e[0]>1 && e[1]>2 && e[2]>3 && e[2]>e[1] && (e[4]+e[5])/e[0]>10){
1595 mHit[quad][ntrk].det[nhit]=44+quad;
1597 mHit[quad][ntrk].nhitEemc++;
1598 mHit[quad][ntrk].x[nhit]=x;
1599 mHit[quad][ntrk].y[nhit]=y;
1600 mHit[quad][ntrk].z[nhit]=z;
1601 mHit[quad][ntrk].r[nhit]=sqrt(x*x+y*y);
1602 mHit[quad][ntrk].p[nhit]=atan2(y,x);
1603 mHit[quad][ntrk].ex[nhit]=0.5;
1604 mHit[quad][ntrk].ey[nhit]=0.5;
1605 mHit[quad][ntrk].ez[nhit]=0.5;
1606 mHit[quad][ntrk].tw[nhit]=e[0];
1607 mHit[quad][ntrk].p1[nhit]=e[1];
1608 mHit[quad][ntrk].p2[nhit]=e[2];
1609 mHit[quad][ntrk].po[nhit]=e[3];
1610 mHit[quad][ntrk].su[nhit]=e[4];
1611 mHit[quad][ntrk].sv[nhit]=e[5];
1612 mHit[quad][ntrk].nrl[nhit]=w[0];
1613 mHit[quad][ntrk].nsu[nhit]=w[1];
1614 mHit[quad][ntrk].nsv[nhit]=w[2];
1615 if(mDebug>0) cout<<Form(
"Trk=%3d EHit=%3d Quad=%1d Disc=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
1616 ntrk,nhit,quad,mHit[quad][ntrk].det[nhit]/4,
1617 mHit[quad][ntrk].x[nhit],mHit[quad][ntrk].y[nhit],mHit[quad][ntrk].z[nhit],
1618 mHit[quad][ntrk].ex[nhit],mHit[quad][ntrk].ey[nhit],mHit[quad][ntrk].ez[nhit])
1620 if(mDebug>0) printf(
"EEMC %3d q=%1d d=%1d trk=%6.2f %6.2f %6.2f %6.2f fgt=%6.1f %6.1f %6.1f %6.2f xyrp=%6.1f %6.1f %6.1f %6.2f dxyrp=%6.1f %6.1f %6.1f %6.2f\n",
1621 ntrk,quad,mHit[quad][ntrk].det[nhit]/4,p[0],p[1],p[2],p[3],xx,yy,rr,pp,x,y,r,phi,dx,dy,dr,dp);
1626 mHit[quad][ntrk].nhit=nhit;
1631 if(mEventCounter%100==0) cout << Form(
"StFgtAlignmentMaker::readFromStraightTrackMaker EVT=%d NTRK=%d %d %d %d",
1632 mEventCounter,mNtrk[0],mNtrk[1],mNtrk[2],mNtrk[3])<<endl;
1635 void StFgtAlignmentMaker::DispFromStraightTrackMaker(){
1637 float zmin=-50, zmin2=100;
1644 gMessMgr->Warning() <<
"StFgtAlignmentMaker::Make : No SyFgtStraightTrackMaker" << endm;
1647 vector<AVTrack>& tracks=fgtSTracker->getTracks();
1648 for(vector<AVTrack>::iterator t=tracks.begin();t!=tracks.end();t++){
1651 if(t->dca>maxDCA)
continue;
1652 if(t->trkZ<-200 || t->trkZ>200)
continue;
1653 cout<<Form(
"Trk chi2=%9.6f dca=%7.2f z=%7.2f mx=%7.2f ax=%7.2f my=%7.2f ay=%7.2f",
1654 t->chi2,t->dca,t->trkZ,t->mx,t->ax,t->my,t->ay)<<endl;
1655 TGraph *hitxz=
new TGraph(1); hitxz->SetMarkerStyle(21); hitxz->SetMarkerSize(0.8); hitxz->SetMarkerColor(kRed);
1656 TGraph *hityz=
new TGraph(1); hityz->SetMarkerStyle(21); hityz->SetMarkerSize(0.8); hityz->SetMarkerColor(kRed);
1657 TGraph *hitrz=
new TGraph(1); hitrz->SetMarkerStyle(21); hitrz->SetMarkerSize(0.8); hitrz->SetMarkerColor(kRed);
1658 TGraph *hitpz=
new TGraph(1); hitpz->SetMarkerStyle(21); hitpz->SetMarkerSize(0.8); hitpz->SetMarkerColor(kRed);
1659 TF1 *fxz =
new TF1(
"fxz",
"[0]+[1]*x",zmin,zmax); fxz->SetParameter(0,t->ax); fxz->SetParameter(1,t->mx);
1660 TF1 *fyz =
new TF1(
"fyz",
"[0]+[1]*x",zmin,zmax); fyz->SetParameter(0,t->ay); fyz->SetParameter(1,t->my);
1661 TF1 *frz =
new TF1(
"frz",
"sqrt(([0]+[1]*x)*([0]+[1]*x)+([2]+[3]*x)*([2]+[3]*x))",zmin,zmax);
1662 frz->SetParameter(0,t->ax); frz->SetParameter(1,t->mx); frz->SetParameter(2,t->ay); frz->SetParameter(3,t->my);
1663 TF1 *fpz =
new TF1(
"fpz",
"atan2([2]+[3]*x,[0]+[1]*x)",zmin,zmax);
1664 fpz->SetParameter(0,t->ax); fpz->SetParameter(1,t->mx); fpz->SetParameter(2,t->ay); fpz->SetParameter(3,t->my);
1665 vector<AVPoint>* points=t->points;
1668 for(vector<AVPoint>::iterator p=points->begin(); p!=points->end();p++){
1670 hitxz->SetPoint(i,p->z,p->x);
1671 hityz->SetPoint(i,p->z,p->y);
1672 hitrz->SetPoint(i,p->z,p->r);
1673 hitpz->SetPoint(i,p->z,p->phi);
1674 cout << Form(
" %2d quad=%d xyz=%8.3f %8.3f %8.3f",i,quad,p->x,p->y,p->z)<<endl;
1679 int ndisp=0, nprompt=0, neemc=0;
1680 TGraph *tpcxz=
new TGraph(1); tpcxz->SetMarkerStyle(21); tpcxz->SetMarkerSize(0.8); tpcxz->SetMarkerColor(kBlue);
1681 TGraph *tpcyz=
new TGraph(1); tpcyz->SetMarkerStyle(21); tpcyz->SetMarkerSize(0.8); tpcyz->SetMarkerColor(kBlue);
1682 TGraph *tpcrz=
new TGraph(1); tpcrz->SetMarkerStyle(21); tpcrz->SetMarkerSize(0.8); tpcrz->SetMarkerColor(kBlue);
1683 TGraph *tpcpz=
new TGraph(1); tpcpz->SetMarkerStyle(21); tpcpz->SetMarkerSize(0.8); tpcpz->SetMarkerColor(kBlue);
1684 TGraph *tpcdxz=
new TGraph(1); tpcdxz->SetMarkerStyle(21); tpcdxz->SetMarkerSize(0.8); tpcdxz->SetMarkerColor(kBlue);
1685 TGraph *tpcdyz=
new TGraph(1); tpcdyz->SetMarkerStyle(21); tpcdyz->SetMarkerSize(0.8); tpcdyz->SetMarkerColor(kBlue);
1686 TGraph *tpcdrz=
new TGraph(1); tpcdrz->SetMarkerStyle(21); tpcdrz->SetMarkerSize(0.8); tpcdrz->SetMarkerColor(kBlue);
1687 TGraph *tpcdpz=
new TGraph(1); tpcdpz->SetMarkerStyle(21); tpcdpz->SetMarkerSize(0.8); tpcdpz->SetMarkerColor(kBlue);
1689 event = (
StEvent *) GetInputDS(
"StEvent");
1693 if(TpcHitCollection){
1695 UInt_t numberOfSectors = TpcHitCollection->numberOfSectors();
1696 for (UInt_t i = 0; i< numberOfSectors; i++) {
1698 if (!sectorCollection)
continue;
1700 Int_t numberOfPadrows = sectorCollection->numberOfPadrows();
1701 for (
int j = 0; j< numberOfPadrows; j++) {
1703 if (!rowCollection)
continue;
1705 StSPtrVecTpcHit &hits = rowCollection->hits();
1706 Long64_t NoHits = hits.size();
1709 for (Long64_t k = 0; k < NoHits; k++) {
1712 if(xyz.z()<0)
continue;
1713 double xx = t->ax + t->mx*xyz.z();
1714 double yy = t->ay + t->my*xyz.z();
1715 double rr = sqrt(xx*xx+yy*yy);
1716 double pp = atan2(yy,xx);
1717 double dx = xyz.x()-xx;
1718 double dy = xyz.y()-yy;
1719 double dr = xyz.perp()-rr;
1720 double dp = atan2(xyz.y(),xyz.x())-pp;
1721 static const double PI=3.141592654;
1723 if(dp<-PI) dp+=2*PI;
1724 double dist = sqrt(dx*dx+dy*dy);
1726 tpcxz->SetPoint(ndisp,xyz.z(),xyz.x());
1727 tpcyz->SetPoint(ndisp,xyz.z(),xyz.y());
1728 tpcrz->SetPoint(ndisp,xyz.z(),xyz.perp());
1729 tpcpz->SetPoint(ndisp,xyz.z(),atan2(xyz.y(),xyz.x()));
1730 tpcdxz->SetPoint(ndisp,xyz.z(),dx);
1731 tpcdyz->SetPoint(ndisp,xyz.z(),dy);
1732 tpcdrz->SetPoint(ndisp,xyz.z(),dr);
1733 tpcdpz->SetPoint(ndisp,xyz.z(),dp);
1735 if(xyz.z()>200) nprompt++;
1736 fillHist(6,quad,dx,dy,dr,dp,xx,yy,rr,pp);
1743 cout <<
"Got TPC hits near fgt track="<<ndisp<<
" out of total="<<ntot<<endl;
1747 TGraph *emcxz=
new TGraph(1); emcxz->SetMarkerStyle(21); emcxz->SetMarkerSize(0.8); emcxz->SetMarkerColor(kRed);
1748 TGraph *emcyz=
new TGraph(1); emcyz->SetMarkerStyle(21); emcyz->SetMarkerSize(0.8); emcyz->SetMarkerColor(kRed);
1749 TGraph *emcrz=
new TGraph(1); emcrz->SetMarkerStyle(21); emcrz->SetMarkerSize(0.8); emcrz->SetMarkerColor(kRed);
1750 TGraph *emcpz=
new TGraph(1); emcpz->SetMarkerStyle(21); emcpz->SetMarkerSize(0.8); emcpz->SetMarkerColor(kRed);
1751 TGraph *emcdxz=
new TGraph(1); emcdxz->SetMarkerStyle(21); emcdxz->SetMarkerSize(0.8); emcdxz->SetMarkerColor(kRed);
1752 TGraph *emcdyz=
new TGraph(1); emcdyz->SetMarkerStyle(21); emcdyz->SetMarkerSize(0.8); emcdyz->SetMarkerColor(kRed);
1753 TGraph *emcdrz=
new TGraph(1); emcdrz->SetMarkerStyle(21); emcdrz->SetMarkerSize(0.8); emcdrz->SetMarkerColor(kRed);
1754 TGraph *emcdpz=
new TGraph(1); emcdpz->SetMarkerStyle(21); emcdpz->SetMarkerSize(0.8); emcdpz->SetMarkerColor(kRed);
1757 StEEmcIUPointVec_t mPoints = mEEpoints->
points();
1758 for ( Int_t ipoint=0; ipoint<mEEpoints->
numberOfPoints(); ipoint++){
1763 e[neemc][0]=point.
energy(0);
1764 e[neemc][1]=point.
energy(1)*1000;
1765 e[neemc][2]=point.
energy(2)*1000;
1766 e[neemc][3]=point.
energy(3)*1000;
1767 e[neemc][4]=point.
cluster(0).energy()*1000;
1768 e[neemc][5]=point.
cluster(1).energy()*1000;
1769 printf(
"EEMC %d xyz=%6.2f %6.2f %6.2f e=%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",
1770 ipoint,x,y,z,e[neemc][0],e[neemc][1],e[neemc][2],e[neemc][3],e[neemc][4],e[neemc][5]);
1771 double xx = t->ax + t->mx*z;
1772 double yy = t->ay + t->my*z;
1773 double rr = sqrt(xx*xx+yy*yy);
1774 double pp = atan2(yy,xx);
1777 double dr = sqrt(x*x+y*y)-rr;
1778 double dp = atan2(y,x)-pp;
1779 static const double PI=3.141592654;
1781 if(dp<-PI) dp+=2*PI;
1782 double dist = sqrt(dx*dx+dy*dy);
1783 if(dist<maxDist && e[neemc][1]>0.3 && e[neemc][2]>0.3){
1784 emcxz->SetPoint(ndisp,z,x);
1785 emcyz->SetPoint(ndisp,z,y);
1786 emcrz->SetPoint(ndisp,z,sqrt(x*x+y*y));
1787 emcpz->SetPoint(ndisp,z,atan2(y,x));
1788 emcdxz->SetPoint(ndisp,z,dx);
1789 emcdyz->SetPoint(ndisp,z,dy);
1790 emcdrz->SetPoint(ndisp,z,dr);
1791 emcdpz->SetPoint(ndisp,z,dp);
1794 fillHist(7,quad,dx,dy,dr,dp,xx,yy,rr,pp);
1799 if(ndisp==0)
continue;
1801 if(neemc==0)
continue;
1804 double xmin = (t->ax + t->mx*zmin2);
1805 double ymin = (t->ay + t->my*zmin2);
1806 double xmax = (t->ax + t->mx*zmax);
1807 double ymax = (t->ay + t->my*zmax);
1808 double rmin = sqrt(xmin*xmin+ymin*ymin);
1809 double rmax = sqrt(xmax*xmax+ymax*ymax);
1810 double pmax = atan2(ymax,xmax) + 0.3;
1811 double pmin = atan2(ymax,xmax) - 0.3;
1812 if(rmax<70)
continue;
1814 static TCanvas *c1=0, *c2=0;
1815 if(!c1) c1=
new TCanvas(
"EventDisp",
"Event Disp",50,50,800,800);
1816 if(!c2) c2=
new TCanvas(
"EventDisp2",
"Event Disp2",100,100,800,800);
1817 gStyle->SetOptStat(0);
1819 TH2F *xz =
new TH2F(
"xz",
"xz",1,zmin,zmax,1,-200,200);
1820 TH2F *yz =
new TH2F(
"yz",
"yz",1,zmin,zmax,1,-200,200);
1821 TH2F *rz =
new TH2F(
"rz",
"rz",1,zmin,zmax,1, -10,200);
1822 TH2F *pz =
new TH2F(
"pz",
"pz",1,zmin,zmax,1,-3.2,3.2);
1825 c1->cd(1); xz->Draw(); hitxz->Draw(
"P"); fxz->Draw(
"LSAME"); tpcxz->Draw(
"P"); emcxz->Draw(
"P");
1826 c1->cd(2); yz->Draw(); hityz->Draw(
"P"); fyz->Draw(
"LSAME"); tpcyz->Draw(
"P"); emcyz->Draw(
"P");
1827 c1->cd(3); rz->Draw(); hitrz->Draw(
"P"); frz->Draw(
"LSAME"); tpcrz->Draw(
"P"); emcrz->Draw(
"P");
1828 c1->cd(4); pz->Draw(); hitpz->Draw(
"P"); fpz->Draw(
"LSAME"); tpcpz->Draw(
"P"); emcpz->Draw(
"P");
1841 TH2F *xz2 =
new TH2F(
"dxz",
"dxz",1,zmin2,zmax,1,-12,12);
1842 TH2F *yz2 =
new TH2F(
"dyz",
"dyz",1,zmin2,zmax,1,-12,12);
1843 TH2F *rz2 =
new TH2F(
"drz",
"drz",1,zmin2,zmax,1,-12,12);
1844 TH2F *pz2 =
new TH2F(
"dpz",
"dpz",1,zmin2,zmax,1,-0.3,0.3);
1847 c2->cd(1); xz2->Draw(); tpcdxz->Draw(
"P"); emcdxz->Draw(
"P");
1848 c2->cd(2); yz2->Draw(); tpcdyz->Draw(
"P"); emcdyz->Draw(
"P");
1849 c2->cd(3); rz2->Draw(); tpcdrz->Draw(
"P"); emcdrz->Draw(
"P");
1850 c2->cd(4); pz2->Draw(); tpcdpz->Draw(
"P"); emcdpz->Draw(
"P");
1851 for(
int i=0; i<neemc; i++){
1853 sprintf(t,
"E=%4.1f P1=%4.2f P2=%4.2f T=%4.2f U=%4.2f V=%4.2f",e[i][0],e[i][1],e[i][2],e[i][3],e[i][4],e[i][5]);
1855 TText *tt =
new TText(0.1,0.9-0.07*i,t); tt->SetNDC(); tt->SetTextSize(0.04); tt->Draw();
1860 sprintf(tmp,
"disp/evdisp1_%d.png",nplot); c1->SaveAs(tmp);
1861 sprintf(tmp,
"disp/evdisp2_%d.png",nplot); c2->SaveAs(tmp);
1870 void StFgtAlignmentMaker::calcETBalanceFromStEvent() {
1872 event = (
StEvent *) GetInputDS(
"StEvent");
1874 gMessMgr->Warning() <<
"StFgtAlignmentMaker::Make : No StEvent" << endm;
1877 ele.set(0,0,0); tracks.set(0,0,0); bemcs.set(0,0,0); eemcs.set(0,0,0); tot.set(0,0,0); rec.set(0,0,0); iso.set(0,0,0);
1878 int nele=0,ntrack=0, nbemc=0, neemc=0, ntot=0, nrec=0, niso=0;
1879 UInt_t NpVX =
event->numberOfPrimaryVertices();
1882 for (UInt_t i = 0; i < NpVX; i++) {
1884 if(mDebug>2) cout << Form(
"Vertex: %3i ",i) << *vtx << endl;
1888 StEEmcIUPointVec_t mPoints = mEEpoints->
points();
1889 for ( Int_t ipoint=0; ipoint<mEEpoints->
numberOfPoints(); ipoint++){
1899 point.
cluster(0).energy()>0.02 &&
1900 point.
cluster(1).energy()>0.02){
1901 if(ee.perp() > ele.perp()) ele=ee;
1907 if(mEEpoints && nele>0){
1908 StEEmcIUPointVec_t mPoints = mEEpoints->
points();
1909 for ( Int_t ipoint=0; ipoint<mEEpoints->
numberOfPoints(); ipoint++){
1916 double deta = ele.pseudoRapidity() - d.pseudoRapidity();
1917 double dphi = ele.phi() - d.phi();
if(dphi>PI) {dphi-=2*PI;}
if(dphi<-PI) {dphi+=2*PI;}
1918 if(fabs(deta)<ISOCUT && fabs(dphi)<ISOCUT) {
StThreeVectorF ee=e*d; iso+=ee; niso++;}
1922 UInt_t nDaughters = vtx->numberOfDaughters();
1923 for (UInt_t j = 0; j < nDaughters; j++) {
1925 if (! pTrack)
continue;
1926 tracks+=pTrack->geometry()->momentum();
1928 double deta = ele.pseudoRapidity() - pTrack->geometry()->momentum().pseudoRapidity();
1929 double dphi = ele.phi() - pTrack->geometry()->momentum().phi();
if(dphi>PI) {dphi-=2*PI;}
if(dphi<-PI) {dphi+=2*PI;}
1930 if(fabs(deta)<ISOCUT && fabs(dphi)<ISOCUT) { iso+=pTrack->geometry()->momentum(); }
1933 StEmcDetector *btow=
event->emcCollection()->detector(kBarrelEmcTowerId);
1935 for(
int i=0; i<btow->numberOfModules(); i++){
1937 StSPtrVecEmcRawHit& hits = mod->hits();
1938 for(UInt_t k=0;k<hits.size();k++) {
1939 float e=hits[k]->energy();
1941 int mod=hits[k]->module();
1942 int eta=hits[k]->eta();
1943 int sub=hits[k]->sub();
1945 StEmcGeom::instance(
"bemc")->getXYZ(mod,eta,sub,x,y,z);
1951 double deta = ele.pseudoRapidity() - d.pseudoRapidity();
1952 double dphi = ele.phi() - d.phi();
if(dphi>PI) {dphi-=2*PI;}
if(dphi<-PI) {dphi+=2*PI;}
1953 if(fabs(deta)<ISOCUT && fabs(dphi)<ISOCUT) {
StThreeVectorF ee=e*d; iso+=ee; }
1958 tot=tracks+bemcs+eemcs; ntot=ntrack+nbemc+neemc;
1959 rec=tot-ele;
if(nele>0) {nrec=ntot-1;}
else {nrec=ntot;}
1960 float dphi=ele.phi() - tot.phi();
1961 ptbal = tot.perp()*cos(dphi);
1962 riso = ele.mag()/iso.mag();
1963 printf(
"NELE=%4d NTRK=%4d NBEMC=%4d NEEMC=%4d NTOT=%4d NREC=%4d NISO=%4d\n",nele,ntrack,nbemc,neemc,ntot,nrec,niso);
1964 printf(
"EELE=%6.1f ETRK=%6.1f EBEMC=%6.1f EEEMC=%6.1f ETOT=%6.1f EREC=%6.1f EISO=%6.1f\n",
1965 ele.mag(),tracks.mag(),bemcs.mag(),eemcs.mag(),tot.mag(),rec.mag(),iso.mag());
1966 printf(
"PELE=%6.1f PTRK=%6.1f PBEMC=%6.1f PEEMC=%6.1f PTOT=%6.1f PREC=%6.1f PISO=%6.1f\n",
1967 ele.perp(),tracks.perp(),bemcs.perp(),eemcs.perp(),tot.perp(),rec.perp(),iso.perp());
1968 printf(
"Dphi=%6.1f ETBal=%6.1f R(ele/iso)=%6.3f\n",dphi,ptbal,riso);
1971 void StFgtAlignmentMaker::fillETBalance(
int itrk){
1972 mHit[mQuad][itrk].ele[0]=ele.x();
1973 mHit[mQuad][itrk].ele[1]=ele.y();
1974 mHit[mQuad][itrk].ele[2]=ele.z();
1975 mHit[mQuad][itrk].ele[3]=ele.mag();
1976 mHit[mQuad][itrk].trk[0]=tracks.x();
1977 mHit[mQuad][itrk].trk[1]=tracks.y();
1978 mHit[mQuad][itrk].trk[2]=tracks.z();
1979 mHit[mQuad][itrk].trk[3]=tracks.mag();
1980 mHit[mQuad][itrk].bemc[0]=bemcs.x();
1981 mHit[mQuad][itrk].bemc[1]=bemcs.y();
1982 mHit[mQuad][itrk].bemc[2]=bemcs.z();
1983 mHit[mQuad][itrk].bemc[3]=bemcs.mag();
1984 mHit[mQuad][itrk].eemc[0]=eemcs.x();
1985 mHit[mQuad][itrk].eemc[1]=eemcs.y();
1986 mHit[mQuad][itrk].eemc[2]=eemcs.z();
1987 mHit[mQuad][itrk].eemc[3]=eemcs.mag();
1988 mHit[mQuad][itrk].tot[0]=tot.x();
1989 mHit[mQuad][itrk].tot[1]=tot.y();
1990 mHit[mQuad][itrk].tot[2]=tot.z();
1991 mHit[mQuad][itrk].tot[3]=tot.mag();
1992 mHit[mQuad][itrk].rec[0]=rec.x();
1993 mHit[mQuad][itrk].rec[1]=rec.y();
1994 mHit[mQuad][itrk].rec[2]=rec.z();
1995 mHit[mQuad][itrk].rec[3]=rec.mag();
1996 mHit[mQuad][itrk].iso[0]=iso.x();
1997 mHit[mQuad][itrk].iso[1]=iso.y();
1998 mHit[mQuad][itrk].iso[2]=iso.z();
1999 mHit[mQuad][itrk].iso[3]=iso.mag();
2000 mHit[mQuad][itrk].ptbal=ptbal;
2001 mHit[mQuad][itrk].riso=riso;
2004 void StFgtAlignmentMaker::readFromStEvent() {
2008 event = (
StEvent *) GetInputDS(
"StEvent");
2010 gMessMgr->Warning() <<
"StFgtAlignmentMaker::Make : No StEvent" << endm;
2013 cout <<
"Event: Run "<<
event->runId() <<
" Event No: " <<
event->id() << endl;
2015 if (event->fgtCollection()) {
2016 cout <<
"# of FGT hits: " <<
event->fgtCollection()->getNumHits() << endl;
2018 cout <<
"No FGT collection" << endl;
2021 UInt_t NpVX =
event->numberOfPrimaryVertices();
2022 if(mDebug>2) cout <<
"Number of Primary vertex="<<NpVX<<endl;
2025 for (UInt_t i = 0; i < NpVX; i++) {
2027 if(mDebug>2) cout << Form(
"Vertex: %3i ",i) << *vx << endl;
2028 UInt_t nDaughters = vx->numberOfDaughters();
2029 for (UInt_t j = 0; j < nDaughters; j++) {
2031 if (! pTrack)
continue;
2033 int nfgt=0, ntpc=0, nprompt=0, quad=-1;
2034 StPtrVecHit &hits=pTrack->detectorInfo()->hits();
2035 for (StPtrVecHitConstIterator iter=hits.begin(); iter != hits.end(); iter++){
2036 StDetectorId det=(*iter)->detector();
2037 if (det == kTpcId) {
2040 if(xyz.z()>200.0) {nprompt++;}
2041 }
else if (det == kFgtId) {
2044 quad=point->getQuad();
2047 cout << Form(
"Track: Tpc=%2d Pmp=%1d Fgt=%1d Quad=%1d ",ntpc,nprompt,nfgt,quad) << *pTrack << endl;
2048 if(nfgt==0)
continue;
2049 int itrk=mNtrk[quad];
2052 mHit[quad][itrk].det[ihit]=24+quad;
2054 mHit[quad][itrk].x[ihit]=vxyz.x();
2055 mHit[quad][itrk].y[ihit]=vxyz.y();
2056 mHit[quad][itrk].z[ihit]=vxyz.z();
2058 mHit[quad][itrk].ex[ihit]=evxyz.x();
2059 mHit[quad][itrk].ey[ihit]=evxyz.y();
2060 mHit[quad][itrk].ez[ihit]=evxyz.z();
2062 for (StPtrVecHitConstIterator iter=hits.begin(); iter != hits.end(); iter++){
2063 StDetectorId det=(*iter)->detector();
2065 mHit[quad][itrk].det[ihit]=28+quad;
2067 mHit[quad][itrk].x[ihit]=xyz.x();
2068 mHit[quad][itrk].y[ihit]=xyz.y();
2069 mHit[quad][itrk].z[ihit]=xyz.z();
2070 if(mHit[quad][itrk].z[ihit]>200.0){mHit[quad][itrk].det[ihit]=32+quad;}
2072 mHit[quad][itrk].ex[ihit]=exyz.x();
2073 mHit[quad][itrk].ey[ihit]=exyz.y();
2074 mHit[quad][itrk].ez[ihit]=exyz.z();
2075 }
else if (det == kFgtId){
2077 int disc=point->getDisc();
2078 int quad2=point->getQuad();
2079 mHit[quad][itrk].det[ihit]=disc*4+quad2;
2081 mHit[quad][itrk].lr[ihit]=point->getPositionR();
2082 mHit[quad][itrk].lp[ihit]=point->getPositionPhi();
2083 mHit[quad][itrk].z[ihit]=StFgtGeom::getDiscZ(disc);
2085 if(mErrFgt>=0.0) {mHit[quad][itrk].ex[ihit]=mErrFgt;}
else {mHit[quad][itrk].ex[ihit]=exyz.x();}
2086 if(mErrFgt>=0.0) {mHit[quad][itrk].ey[ihit]=mErrFgt;}
else {mHit[quad][itrk].ey[ihit]=exyz.y();}
2087 if(mErrFgt>=0.0) {mHit[quad][itrk].ez[ihit]=0.0;}
else {mHit[quad][itrk].ez[ihit]=exyz.z();}
2091 mHit[quad][itrk].nhit=ihit;
2092 for(
int i=0; i<mHit[quad][itrk].nhit; i++){
2093 cout<<Form(
"Trk=%3d Hit=%3d Quad=%1d Det=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
2094 itrk,i,quad,mHit[quad][itrk].det[i],
2095 mHit[quad][itrk].x[i],mHit[quad][itrk].y[i],mHit[quad][itrk].z[i],
2096 mHit[quad][itrk].ex[i],mHit[quad][itrk].ey[i],mHit[quad][itrk].ez[i])
2104 void StFgtAlignmentMaker::readFromStEventGlobal() {
2108 event = (
StEvent *) GetInputDS(
"StEvent");
2110 gMessMgr->Warning() <<
"StFgtAlignmentMaker::Make : No StEvent" << endm;
2113 cout <<
"Event: Run "<<
event->runId() <<
" Event No: " <<
event->id() << endl;
2115 if (event->fgtCollection()) {
2116 cout <<
"# of FGT point: " <<
event->fgtCollection()->getNumPoints() << endl;
2118 cout <<
"No FGT collection" << endl;
2121 StSPtrVecTrackNode& trackNode =
event->trackNodes();
2122 UInt_t nTracks = trackNode.size();
2124 cout <<
"# of tracks "<<nTracks<<endl;
2125 for (UInt_t i=0; i < nTracks; i++) {
2126 node = trackNode[i];
if (!node)
continue;
2128 int nfgt=0, ntpc=0, nprompt=0, quad=-1;
2129 StPtrVecHit &hits=gTrack->detectorInfo()->hits();
2130 for (StPtrVecHitConstIterator iter=hits.begin(); iter != hits.end(); iter++){
2131 StDetectorId det=(*iter)->detector();
2132 if (det == kTpcId) {
2135 if(xyz.z()>200.0) {nprompt++;}
2136 }
else if (det == kFgtId) {
2139 quad=point->getQuad();
2142 cout << Form(
"Track: Tpc=%2d Pmp=%1d Fgt=%1d Quad=%1d ",ntpc,nprompt,nfgt,quad) << *gTrack << endl;
2143 if(nfgt==0)
continue;
2144 int itrk=mNtrk[quad];
2146 for (StPtrVecHitConstIterator iter=hits.begin(); iter != hits.end(); iter++){
2147 StDetectorId det=(*iter)->detector();
2149 mHit[quad][itrk].det[ihit]=28+quad;
2151 mHit[quad][itrk].x[ihit]=xyz.x();
2152 mHit[quad][itrk].y[ihit]=xyz.y();
2153 mHit[quad][itrk].z[ihit]=xyz.z();
2154 if(mHit[quad][itrk].z[ihit]>200.0){mHit[quad][itrk].det[ihit]=32+quad;}
2156 mHit[quad][itrk].ex[ihit]=exyz.x();
2157 mHit[quad][itrk].ey[ihit]=exyz.y();
2158 mHit[quad][itrk].ez[ihit]=exyz.z();
2159 }
else if (det == kFgtId){
2161 int disc=point->getDisc();
2162 int quad2=point->getQuad();
2163 mHit[quad][itrk].det[ihit]=disc*4+quad2;
2165 mHit[quad][itrk].lr[ihit]=point->getPositionR();
2166 mHit[quad][itrk].lp[ihit]=point->getPositionPhi();
2167 mHit[quad][itrk].z[ihit]=StFgtGeom::getDiscZ(disc);
2169 if(mErrFgt>0.0) {mHit[quad][itrk].ex[ihit]=mErrFgt;}
else {mHit[quad][itrk].ex[ihit]=exyz.x();}
2170 if(mErrFgt>0.0) {mHit[quad][itrk].ey[ihit]=mErrFgt;}
else {mHit[quad][itrk].ey[ihit]=exyz.y();}
2171 if(mErrFgt>0.0) {mHit[quad][itrk].ez[ihit]=0;}
else {mHit[quad][itrk].ez[ihit]=exyz.z();}
2175 mHit[quad][itrk].nhit=ihit;
2176 for(
int i=0; i<mHit[quad][itrk].nhit; i++){
2177 cout<<Form(
"Trk=%3d Hit=%3d Quad=%1d Det=%2d XYZ=%8.4f %8.4f %8.4f err=%8.4f %8.4f %8.4f",
2178 itrk,i,quad,mHit[quad][itrk].det[i],
2179 mHit[quad][itrk].x[i],mHit[quad][itrk].y[i],mHit[quad][itrk].z[i],
2180 mHit[quad][itrk].ex[i],mHit[quad][itrk].ey[i],mHit[quad][itrk].ez[i])
2187 void StFgtAlignmentMaker::writeTree(){
2189 sprintf(fname,
"alignment_trkout_step%d.root",mStep+1);
2191 sprintf(fname,
"%d/alignment_trkout_step%d_day%d.root",mDay,mStep+1,mDay);
2192 }
else if(mRunNumber>0) {
2193 int yearday=mRunNumber/1000;
2194 sprintf(fname,
"%d/alignment_trkout_step%d.%d.root",yearday,mStep+1,mRunNumber);
2196 sprintf(fname,
"%d/alignment_trkout_step%d.%d.%d.root",yearday,mStep+1,mRunNumber,mSeqNumber);
2199 cout <<
"Creating "<<fname<<endl;
2200 TFile *f=
new TFile(fname,
"RECREATE",
"tracks");
2201 for(
int quad=0; quad<kFgtNumQuads; quad++){
2203 sprintf(c,
"q%1d",quad);
2204 TTree* t =
new TTree(c,c);
2205 t->Branch(
"run", &(mHitAlg.run),
"run/I");
2206 t->Branch(
"evt", &(mHitAlg.evt),
"evt/I");
2207 t->Branch(
"nhit",&(mHitAlg.nhit),
"nhit/I");
2208 t->Branch(
"nuse",&(mHitAlg.nhitUse),
"nuse/I");
2209 t->Branch(
"nfgt",&(mHitAlg.nhitFgt),
"nfgt/I");
2210 t->Branch(
"nvtx",&(mHitAlg.nhitVtx),
"nvtx/I");
2211 t->Branch(
"ntpc",&(mHitAlg.nhitTpc),
"ntpc/I");
2212 t->Branch(
"nppt",&(mHitAlg.nhitPrompt),
"nppt/I");
2213 t->Branch(
"nemc",&(mHitAlg.nhitEemc),
"nemc/I");
2214 t->Branch(
"used",&(mHitAlg.used),
"used/I");
2215 t->Branch(
"dca" ,&(mHitAlg.dca),
"dca/F");
2216 t->Branch(
"chi2",&(mHitAlg.chi2),
"chi2/F");
2217 t->Branch(
"trkz",&(mHitAlg.trkz),
"trkz/F");
2218 t->Branch(
"dz" , &(mHitAlg.dz),
"dz/F");
2219 t->Branch(
"eta", &(mHitAlg.eta),
"eta/F");
2220 t->Branch(
"phi", &(mHitAlg.phi),
"phi/F");
2221 t->Branch(
"opt", &(mHitAlg.opt),
"opt/F");
2222 t->Branch(
"det", mHitAlg.det,
"det[nhit]/I");
2223 t->Branch(
"x", mHitAlg.x,
"x[nhit]/F");
2224 t->Branch(
"y", mHitAlg.y,
"y[nhit]/F");
2225 t->Branch(
"z", mHitAlg.z,
"z[nhit]/F");
2226 t->Branch(
"ex", mHitAlg.ex,
"ex[nhit]/F");
2227 t->Branch(
"ey", mHitAlg.ey,
"ey[nhit]/F");
2228 t->Branch(
"ez", mHitAlg.ez,
"ez[nhit]/F");
2229 t->Branch(
"lr", mHitAlg.lr,
"lr[nhit]/F");
2230 t->Branch(
"lp", mHitAlg.lp,
"lp[nhit]/F");
2231 t->Branch(
"r", mHitAlg.r,
"r[nhit]/F");
2232 t->Branch(
"p", mHitAlg.p,
"p[nhit]/F");
2233 t->Branch(
"dx", mHitAlg.dx,
"dx[nhit]/F");
2234 t->Branch(
"dy", mHitAlg.dy,
"dy[nhit]/F");
2235 t->Branch(
"dr", mHitAlg.dr,
"dr[nhit]/F");
2236 t->Branch(
"dp", mHitAlg.dp,
"dp[nhit]/F");
2237 t->Branch(
"tw", mHitAlg.tw,
"tw[nhit]/F");
2238 t->Branch(
"p1", mHitAlg.p1,
"p1[nhit]/F");
2239 t->Branch(
"p2", mHitAlg.p2,
"p2[nhit]/F");
2240 t->Branch(
"po", mHitAlg.po,
"po[nhit]/F");
2241 t->Branch(
"su", mHitAlg.su,
"su[nhit]/F");
2242 t->Branch(
"sv", mHitAlg.sv,
"sv[nhit]/F");
2243 t->Branch(
"nrl", mHitAlg.nrl,
"nrl[nhit]/I");
2244 t->Branch(
"nsu", mHitAlg.nsu,
"nsu[nhit]/I");
2245 t->Branch(
"nsv", mHitAlg.nsv,
"nsv[nhit]/I");
2246 t->Branch(
"ele", mHitAlg.ele,
"ele[4]/F");
2247 t->Branch(
"trk", mHitAlg.trk,
"trk[4]/F");
2248 t->Branch(
"bemc",mHitAlg.bemc,
"bemc[4]/F");
2249 t->Branch(
"eemc",mHitAlg.eemc,
"eemc[4]/F");
2250 t->Branch(
"tot", mHitAlg.tot,
"tot[4]/F");
2251 t->Branch(
"rec", mHitAlg.rec,
"rec[4]/F");
2252 t->Branch(
"iso", mHitAlg.iso,
"iso[4]/F");
2253 t->Branch(
"ptbal",&(mHitAlg.ptbal),
"ptbal/F");
2254 t->Branch(
"riso", &(mHitAlg.riso),
"riso/F");
2255 t->Branch(
"use", mHitAlg.use,
"use[nhit]/O");
2258 for(itrk=0; itrk<mNtrk[quad]; itrk++){
2259 if(mHit[quad][itrk].used==0)
continue;
2260 memcpy(&mHitAlg,&mHit[quad][itrk],
sizeof(mHitAlg));
2265 cout<<Form(
" Wrote %6d/%6d tracks for quad=%1d",ntrk,itrk,quad)<<endl;
2271 void StFgtAlignmentMaker::readFromTree(){
2272 cout <<
"ReadFromTree mDb="<<mDb<<endl;
2275 cout<<
"StFgtAlignment: Please set input TTree file name using setReadTree()" << endl;
2278 cout <<
"Reading "<<mInTreeFile<<endl;
2279 TFile *f=
new TFile(mInTreeFile);
2280 for(
int quad=0; quad<kFgtNumQuads; quad++){
2282 sprintf(c,
"q%1d",quad);
2283 TTree *t = (TTree*) f->Get(c);
2284 t->SetBranchAddress(
"run", &(mHitAlg.run));
2285 t->SetBranchAddress(
"evt", &(mHitAlg.evt));
2286 t->SetBranchAddress(
"nhit",&(mHitAlg.nhit));
2287 t->SetBranchAddress(
"nuse",&(mHitAlg.nhitUse));
2288 t->SetBranchAddress(
"nfgt",&(mHitAlg.nhitFgt));
2289 t->SetBranchAddress(
"ntpc",&(mHitAlg.nhitTpc));
2290 t->SetBranchAddress(
"nppt",&(mHitAlg.nhitPrompt));
2291 t->SetBranchAddress(
"nemc",&(mHitAlg.nhitEemc));
2292 t->SetBranchAddress(
"used",&(mHitAlg.used));
2293 t->SetBranchAddress(
"dca" ,&(mHitAlg.dca));
2294 t->SetBranchAddress(
"chi2",&(mHitAlg.chi2));
2295 t->SetBranchAddress(
"trkz",&(mHitAlg.trkz));
2296 t->SetBranchAddress(
"dz" , &(mHitAlg.dz));
2297 t->SetBranchAddress(
"eta", &(mHitAlg.eta));
2298 t->SetBranchAddress(
"phi", &(mHitAlg.phi));
2299 t->SetBranchAddress(
"opt", &(mHitAlg.opt));
2300 t->SetBranchAddress(
"det", mHitAlg.det);
2301 t->SetBranchAddress(
"x", mHitAlg.x);
2302 t->SetBranchAddress(
"y", mHitAlg.y);
2303 t->SetBranchAddress(
"z", mHitAlg.z);
2304 t->SetBranchAddress(
"ex", mHitAlg.ex);
2305 t->SetBranchAddress(
"ey", mHitAlg.ey);
2306 t->SetBranchAddress(
"ez", mHitAlg.ez);
2307 t->SetBranchAddress(
"lr", mHitAlg.lr);
2308 t->SetBranchAddress(
"lp", mHitAlg.lp);
2309 t->SetBranchAddress(
"r", mHitAlg.r);
2310 t->SetBranchAddress(
"p", mHitAlg.p);
2311 t->SetBranchAddress(
"dx", mHitAlg.dx);
2312 t->SetBranchAddress(
"dy", mHitAlg.dy);
2313 t->SetBranchAddress(
"dr", mHitAlg.dr);
2314 t->SetBranchAddress(
"dp", mHitAlg.dp);
2315 t->SetBranchAddress(
"tw", mHitAlg.tw);
2316 t->SetBranchAddress(
"p1", mHitAlg.p1);
2317 t->SetBranchAddress(
"p2", mHitAlg.p2);
2318 t->SetBranchAddress(
"po", mHitAlg.po);
2319 t->SetBranchAddress(
"su", mHitAlg.su);
2320 t->SetBranchAddress(
"sv", mHitAlg.sv);
2321 t->SetBranchAddress(
"nrl", mHitAlg.nrl);
2322 t->SetBranchAddress(
"nsu", mHitAlg.nsu);
2323 t->SetBranchAddress(
"nsv", mHitAlg.nsv);
2324 t->SetBranchAddress(
"ele", mHitAlg.ele);
2325 t->SetBranchAddress(
"trk", mHitAlg.trk);
2326 t->SetBranchAddress(
"bemc",mHitAlg.bemc);
2327 t->SetBranchAddress(
"eemc",mHitAlg.eemc);
2328 t->SetBranchAddress(
"tot", mHitAlg.tot);
2329 t->SetBranchAddress(
"rec", mHitAlg.rec);
2330 t->SetBranchAddress(
"iso", mHitAlg.iso);
2331 t->SetBranchAddress(
"ptbal",&(mHitAlg.ptbal));
2332 t->SetBranchAddress(
"riso", &(mHitAlg.riso));
2333 t->SetBranchAddress(
"use", mHitAlg.use);
2334 mNtrk[quad]=t->GetEntries();
2336 for(itrk=0; itrk<mNtrk[quad]; itrk++){
2338 cout<<Form(
" MAXTRK=%d reached\n",MAXTRK)<<endl;
2343 memcpy(&mHit[quad][itrk],&mHitAlg,
sizeof(mHitAlg));
2346 cout<<Form(
" Read %6d tracks for quad=%1d",itrk,quad)<<endl;
2351 void StFgtAlignmentMaker::setPar(TMinuit* m, fgtAlignment_st* algpar,
int discmask,
int quadmask,
int parmask){
2355 double stp[2]={ 0.01, 0.1};
2356 double min[2]={-0.10,-5.0};
2357 double max[2]={ 0.10, 5.0};
2358 double zero[2]={0.00, 0.0};
2359 const char* name[6]={
"phi ",
"theta",
"psi ",
"xoff ",
"yoff ",
"zoff "};
2360 double *par = &(algpar->phi[0]);
2361 for(
int disc=0; disc<6; disc++){
2362 for(
int quad=0; quad<4; quad++){
2364 for(
int p=0; p<6; p++){
2366 if( (discmask & 1<<disc) && (quadmask & 1<<quad) && (parmask & 1<<p) ){st=stp; mn=min; mx=max;}
2367 else {st=zero; mn=zero; mx=zero;}
2368 sprintf(nam,
"D%1dQ%1d-%5s" ,disc,quad,name[p]);
2370 m->mnparm(j, nam, par[j], st[k], mn[k], mx[k], iflag);
2376 void StFgtAlignmentMaker::getPar(TMinuit* m, fgtAlignment_st* algpar){
2378 double *par= &(algpar->phi[0]);
2379 for(
int disc=0; disc<6; disc++){
2380 for(
int quad=0; quad<4; quad++){
2382 for(
int p=0; p<6; p++){
2384 m->GetParameter(j,r,e);
2391 void StFgtAlignmentMaker::writePar(fgtAlignment_st* algpar){
2392 char fname[100]=
"fgt_alignment.dat";
2393 int yearday=mRunNumber/1000;
2395 sprintf(fname,
"%d/fgt_alignment_%d.dat",yearday,mRunNumber);
2396 if(mSeqNumber>0) sprintf(fname,
"%d/fgt_alignment_%d.%07d.dat",yearday,mRunNumber,mSeqNumber);
2398 printf(
"Writing %s\n",fname);
2399 FILE *f=fopen(fname,
"w");
2400 for(
int disc=0; disc<6; disc++){
2401 for(
int quad=0; quad<4; quad++){
2403 printf(
"%1d %1d %3d %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n",
2405 algpar->phi[i], algpar->theta[i],algpar->psi[i],
2406 algpar->xoff[i],algpar->yoff[i],algpar->zoff[i]);
2407 fprintf(f,
"%1d %1d %3d %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n",
2409 algpar->phi[i], algpar->theta[i],algpar->psi[i],
2410 algpar->xoff[i],algpar->yoff[i],algpar->zoff[i]);
2416 void StFgtAlignmentMaker::readPar(fgtAlignment_st* algpar){
2417 algpar=orig_algpar=
new fgtAlignment_st;
2418 printf(
"Reading %s\n",mReadParFile);
2419 FILE *f=fopen(mReadParFile,
"r");
2420 if(f==0) {printf(
"Could not open %s\n",mReadParFile);
return;}
2421 for(
int disc=0; disc<6; disc++){
2422 for(
int quad=0; quad<4; quad++){
2423 int ii, i=disc*4+quad;
2424 fscanf(f,
"%d %d %d %lf %lf %lf %lf %lf %lf\n",
2426 &(algpar->phi[i]), &(algpar->theta[i]),&(algpar->psi[i]),
2427 &(algpar->xoff[i]),&(algpar->yoff[i]),&(algpar->zoff[i]));
2428 printf(
"%1d %1d %3d %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n",
2430 algpar->phi[i], algpar->theta[i],algpar->psi[i],
2431 algpar->xoff[i],algpar->yoff[i],algpar->zoff[i]);
2437 void StFgtAlignmentMaker::bookHist(){
2438 const float maxd[NAXIS][kFgtNumDiscs+6]={ {maxdfgt,maxdfgt,maxdfgt,maxdfgt,maxdfgt,maxdfgt,maxdvtx,maxdtpc,maxdtpc,maxdemc,maxdemc,maxdemc},
2439 {maxdfgt,maxdfgt,maxdfgt,maxdfgt,maxdfgt,maxdfgt,maxdvtx,maxdtpc,maxdtpc,maxdemc,maxdemc,maxdemc},
2440 {maxdfgt,maxdfgt,maxdfgt,maxdfgt,maxdfgt,maxdfgt,maxdvtx,maxdtpc,maxdtpc,maxdemc,maxdemc,maxdemc},
2441 {maxpfgt,maxpfgt,maxpfgt,maxpfgt,maxpfgt,maxpfgt,maxpvtx,maxptpc,maxptpc,maxpemc,maxpemc,maxpemc}};
2442 float xmin[4]={ 0,-10,-40,-40};
2443 float xmax[4]={ 40, 40, 0, 10};
2444 float ymin[4]={-10,-40,-40, 0};
2445 float ymax[4]={ 40, 0, 10, 40};
2446 float rmin=10.0, rmax=40.0;
2447 float phimin[4],phimax[4];
2448 phimin[0]=StFgtGeom::phiQuadXaxis(0); phimax[0]=StFgtGeom::phiQuadXaxis(3);
2449 phimin[1]=StFgtGeom::phiQuadXaxis(1); phimax[1]=StFgtGeom::phiQuadXaxis(0);
2450 phimin[2]=StFgtGeom::phiQuadXaxis(2); phimax[2]=StFgtGeom::phiQuadXaxis(1)+2*PI;
2451 phimin[3]=StFgtGeom::phiQuadXaxis(3); phimax[3]=StFgtGeom::phiQuadXaxis(2);
2454 const char* caxis1[NAXIS]={
"dx",
"dy",
"dr",
"dphi"};
2456 const char* caxis2[NAXIS*2]={
"dx.vs.x",
"dy.vs.x",
"dr.vs.r",
"dphi.vs.r",
2457 "dx.vs.y",
"dy.vs.y",
"dr.vs.phi",
"dphi.vs.phi"};
2458 const char* cquad[kFgtNumQuads]={
"A",
"B",
"C",
"D"};
2459 const char* cdisc[kFgtNumDiscs+6]={
"1",
"2",
"3",
"4",
"5",
"6",
"V",
"T",
"P",
"E",
"m",
"e"};
2461 for(
int disc=0; disc<kFgtNumDiscs+6; disc++){
2462 for(
int quad=0; quad<kFgtNumQuads; quad++){
2463 for(
int axis=0; axis<NAXIS; axis++){
2466 sprintf(c,
"%1s%1s-%s",cdisc[disc],cquad[quad],caxis1[axis]);
2467 hist1[disc][quad][axis]=
new TH1F(c,c,nbin,-maxd[axis][disc],maxd[axis][disc]);
2470 float xmin1,xmax1,xmin2,xmax2;
2472 xmin1=xmin[quad]; xmax1=xmax[quad]; xmin2=ymin[quad]; xmax2=ymax[quad];
2473 if(disc==kFgtNumDiscs){ xmin1=-10;xmax1=10; xmin2=-10; xmax2=10;}
2474 if(disc>kFgtNumDiscs) { xmin1=-160; xmax1=160; xmin2=-160; xmax2=160; }
2476 xmin1=rmin; xmax1=rmax; xmin2=phimin[quad]; xmax2=phimax[quad];
2477 if(disc==kFgtNumDiscs) { xmin1=0; xmax1=10; xmin2=-PI; xmax2=PI;}
2478 if(disc>kFgtNumDiscs) { xmin1*=4; xmax1*=4; xmin2=-PI; xmax2=PI;}
2480 sprintf(c,
"%1s%1s-%s",cdisc[disc],cquad[quad],caxis2[axis]);
2481 hist2[disc][quad][axis]=
new TH2F(c,c,nbin, xmin1,xmax1,nbin,-maxd[axis][disc],maxd[axis][disc]);
2482 sprintf(c,
"%1s%1s-%s",cdisc[disc],cquad[quad],caxis2[axis+NAXIS]);
2483 hist2[disc][quad][axis+NAXIS]=
new TH2F(c,c,nbin, xmin2,xmax2,nbin,-maxd[axis][disc],maxd[axis][disc]);
2487 histdz=
new TH1F(
"Zfgt-Ztpc",
"Zfgt-Ztpc",60,-30,30);
2490 void StFgtAlignmentMaker::resetHist(){
2491 for(
int disc=0; disc<kFgtNumDiscs+6; disc++){
2492 for(
int quad=0; quad<kFgtNumQuads; quad++){
2493 for(
int axis=0; axis<NAXIS; axis++){
2494 hist1[disc][quad][axis]->Reset(
"ICES");
2495 hist2[disc][quad][axis]->Reset(
"ICES");
2496 hist2[disc][quad][axis+NAXIS]->Reset(
"ICES");
2502 void StFgtAlignmentMaker::saveHist(){
2504 sprintf(fname,
"alignment_step%d.root",mStep+1);
2506 sprintf(fname,
"%d/alignment_step%d_day%d.root",mDay,mStep+1,mDay);
2507 }
else if(mRunNumber>0) {
2508 int yearday=mRunNumber/1000;
2509 sprintf(fname,
"%d/alignment_step%d.%d.root",yearday,mStep+1,mRunNumber);
2511 sprintf(fname,
"%d/alignment_step%d.%d.%d.root",yearday,mStep+1,mRunNumber,mSeqNumber);
2514 cout <<
"Writing " << fname << endl;
2515 TFile *hfile =
new TFile(fname,
"RECREATE");
2516 for(
int disc=0; disc<kFgtNumDiscs+6; disc++){
2517 for(
int quad=0; quad<kFgtNumQuads; quad++){
2518 for(
int axis=0; axis<NAXIS; axis++){
2519 hist1[disc][quad][axis]->Write();
2520 hist2[disc][quad][axis]->Write();
2521 hist2[disc][quad][axis+NAXIS]->Write();
2529 void StFgtAlignmentMaker::setHitMask(
int hitmask_disc){
2530 cout << Form(
"Alignment Step %d for Quad=%1d using Hits from=",mStep,mQuad);
2531 for(
int i=0; i<6; i++) {
if(hitmask_disc & (1<<i) ) {cout << Form(
"FgtD%1d ",i+1);}}
2532 if(hitmask_disc & 0x40) cout <<
"Vertex ";
2533 if(hitmask_disc & 0x80) cout <<
"TPC ";
2534 if(hitmask_disc & 0x100) cout <<
"Prompt ";
2535 if(hitmask_disc & 0x200) cout <<
"Eemc ";
2536 if(hitmask_disc & 0x400) cout <<
"Mip ";
2537 if(hitmask_disc & 0x800) cout <<
"Ele ";
2538 cout << Form(
"(hitmask_disc = %03x)",hitmask_disc);
2539 mHitMaskDisc=hitmask_disc;
2541 for(
int itrk=0; itrk<mNtrk[mQuad]; itrk++){
2542 mHit[mQuad][itrk].nhitUse=0;
2543 mHit[mQuad][itrk].nhitFgt=0;
2544 mHit[mQuad][itrk].nhitVtx=0;
2545 mHit[mQuad][itrk].nhitTpc=0;
2546 mHit[mQuad][itrk].nhitPrompt=0;
2547 mHit[mQuad][itrk].nhitEemc=0;
2548 mHit[mQuad][itrk].used=0;
2549 for(
int ihit=0; ihit<mHit[mQuad][itrk].nhit; ihit++){
2550 mHit[mQuad][itrk].use[ihit]=
false;
2551 int det=mHit[mQuad][itrk].det[ihit];
2553 if((hitmask_disc & (1<<disc)) ==0)
continue;
2555 if(mFgtRCut[mStep]>0 && fabs(mHit[mQuad][itrk].dr[ihit])>mFgtRCut[mStep])
continue;
2556 if(mFgtPCut[mStep]>0 && fabs(mHit[mQuad][itrk].dp[ihit])>mFgtPCut[mStep])
continue;
2557 mHit[mQuad][itrk].nhitFgt++;
2559 if(mDzCut[mStep]>0 && fabs(mHit[mQuad][itrk].dz )>mDzCut[mStep] )
continue;
2560 if(mDcaCut[mStep]>0 && fabs(mHit[mQuad][itrk].dca)>mDcaCut[mStep])
continue;
2561 mHit[mQuad][itrk].nhitVtx++;
2563 if(mTpcRCut[mStep]>0 && fabs(mHit[mQuad][itrk].dr[ihit])>mTpcRCut[mStep])
continue;
2564 if(mTpcPCut[mStep]>0 && fabs(mHit[mQuad][itrk].dp[ihit])>mTpcPCut[mStep])
continue;
2565 mHit[mQuad][itrk].nhitTpc++;
2567 if(mTpcRCut[mStep]>0 && fabs(mHit[mQuad][itrk].dr[ihit])>mTpcRCut[mStep])
continue;
2568 if(mTpcPCut[mStep]>0 && fabs(mHit[mQuad][itrk].dp[ihit])>mTpcPCut[mStep])
continue;
2569 mHit[mQuad][itrk].nhitTpc++;
2570 mHit[mQuad][itrk].nhitPrompt++;
2571 }
else if(disc==9 || disc==10 || disc==11) {
2572 if(mEmcRCut[mStep]>0 && fabs(mHit[mQuad][itrk].dr[ihit])>mEmcRCut[mStep])
continue;
2573 if(mEmcPCut[mStep]>0 && fabs(mHit[mQuad][itrk].dp[ihit])>mEmcPCut[mStep])
continue;
2574 mHit[mQuad][itrk].nhitEemc++;
2578 mHit[mQuad][itrk].use[ihit]=
true;
2579 mHit[mQuad][itrk].nhitUse++;
2582 if(mHit[mQuad][itrk].nhitUse>=mReqHit &&
2583 mHit[mQuad][itrk].nhitFgt>=mReqFgtHit &&
2584 mHit[mQuad][itrk].nhitVtx>=mReqVtx &&
2585 mHit[mQuad][itrk].nhitTpc>=mReqTpcHit &&
2586 mHit[mQuad][itrk].nhitPrompt>=mReqPromptHit &&
2587 mHit[mQuad][itrk].nhitEemc>=mReqEemcHit){
2588 mHit[mQuad][itrk].used=1;
2592 cout << Form(
" usable ntrack=%d with nhit>=%d nFgt>=%d vVtx>=%d nTpc>=%d nPrompt>=%d nEemc>=%d",
2593 mNtrkUse[mQuad],mReqHit,mReqFgtHit,mReqVtx,mReqTpcHit,mReqPromptHit,mReqEemcHit)<<endl;
2596 void StFgtAlignmentMaker::overWriteError(){
2597 printf(
"Over Writing Hit Errors\n");
2598 for(
int iquad=0; iquad<kFgtNumQuads; iquad++){
2599 printf(
" quad=%d ntrk=%d\n",iquad,mNtrk[iquad]);
2600 for(
int itrk=0; itrk<mNtrk[iquad]; itrk++){
2601 for(
int ihit=0; ihit<mHit[iquad][itrk].nhit; ihit++){
2603 if(ihit>100)
return;
2604 int det=mHit[iquad][itrk].det[ihit];
2607 mHit[iquad][itrk].ex[ihit]=mErrFgt;
2608 mHit[iquad][itrk].ey[ihit]=mErrFgt;
2609 mHit[iquad][itrk].ez[ihit]=0.0;
2611 mHit[iquad][itrk].ex[ihit]=mErrVtx;
2612 mHit[iquad][itrk].ey[ihit]=mErrVtx;
2613 mHit[iquad][itrk].ez[ihit]=mErrVtxZ;
2615 float x= mHit[iquad][itrk].x[ihit];
2616 float y= mHit[iquad][itrk].y[ihit];
2617 float r=sqrt(x*x+y*y);
2619 mHit[iquad][itrk].ex[ihit]=mErrTpcI;
2620 mHit[iquad][itrk].ey[ihit]=mErrTpcI;
2621 mHit[iquad][itrk].ez[ihit]=mErrTpcZ;
2623 mHit[iquad][itrk].ex[ihit]=mErrTpcO;
2624 mHit[iquad][itrk].ey[ihit]=mErrTpcO;
2625 mHit[iquad][itrk].ez[ihit]=mErrTpcZ;
2628 mHit[iquad][itrk].ex[ihit]=mErrPpt;
2629 mHit[iquad][itrk].ey[ihit]=mErrPpt;
2630 mHit[iquad][itrk].ez[ihit]=0;
2631 }
else if(disc==9 || disc==10 || disc==11) {
2632 mHit[iquad][itrk].ex[ihit]=mErrEmc;
2633 mHit[iquad][itrk].ey[ihit]=mErrEmc;
2634 mHit[iquad][itrk].ez[ihit]=0;
2641 void StFgtAlignmentMaker::doAlignment(fgtAlignment_st* input,
2642 int discmask,
int quadmask,
int parmask,
int hitmask_disc,
int residmask,
2643 int trackType,
int minHit,
int minFgtHit,
int minVtx,
int minTpcHit,
int minPromptHit,
int minEemcHit,
2644 fgtAlignment_st* result){
2648 TMinuit *m =
new TMinuit(NPAR);
2649 arg[0] =-1; m->mnexcm(
"SET PRI", arg ,1,iflag);
2650 arg[0] =-1; m->mnexcm(
"SET NOWarning", arg, 0,iflag);
2651 arg[0] = 1; m->mnexcm(
"SET ERR", arg ,1,iflag);
2652 if(trackType==0) { m->SetFCN(funcLine); min=2;}
2653 else if(trackType==1) { m->SetFCN(funcHelix); min=3;}
2655 if(mReqHit<min) mReqHit=min;
2656 mReqFgtHit=minFgtHit;
2658 mReqTpcHit=minTpcHit;
2659 mReqPromptHit=minPromptHit;
2660 mReqEemcHit=minEemcHit;
2661 mResidMaskDisc=residmask;
2663 setHitMask(hitmask_disc);
2664 if(mNtrkUse[mQuad]==0)
return;
2665 setPar(m,input,discmask,quadmask,parmask);
2668 arg[0] = 0; m->mnexcm(
"SET PRI", arg ,1,iflag);
2675 double *par = (
double *) input;
2676 if (trackType==0) { funcLine (np,gin,f,par,iflag);}
2677 else if(trackType==1) { funcHelix(np,gin,f,par,iflag);}
2679 arg[0] = 20000; arg[1] = 1.; m->mnexcm(
"MIGRAD", arg ,2, iflag);
2680 if(mFillHist==0) getPar(m,result);
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
double x(double s) const
coordinates of helix at point s
void energy(Float_t e, Int_t layer=0)
Set the energy of this point.
void position(TVector3 p)
Set the position of this point at the SMD plane.
StEEmcIUPointVec_t points()
Return a unique key assigned by the cluster maker.
Class for building points from smd clusters.
Int_t numberOfPoints()
Return number of points.
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
void cluster(StEEmcIUSmdCluster c, Int_t plane)
Add an smd cluster to this point.
A typical Analysis Class.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
StEEmcIUPoint point(Int_t ipoint)
Return a specified point.
virtual const char * GetName() const
special overload
Base class for representing EEMC points.
void numberOfRelatives(Int_t r)
Set the number of other points which share tower energy.
Represents a point in the FGT.