00001
00002 #include <math.h>
00003 #include <assert.h>
00004 #include <TVector3.h>
00005 #include <TH1.h>
00006
00007 #include "UtilBeamLine3D.h"
00008 const float detEpsilon=1e-4;
00009
00010
00011 int twoLineDca3D(double& lambda,double& kappa,TVector3& V, TVector3& U, TVector3& R,TVector3& P){
00012
00013
00014 double a= P*U;
00015 double det=1-a*a;
00016 if(util.fcnMon1) {
00017 util.hA[20]->Fill(det);
00018 }
00019 if(det<detEpsilon) return -1;
00020
00021 TVector3 VmR=V-R;
00022 double b= VmR*P;
00023 double c = VmR*U;
00024 lambda = (b-a*c)/det;
00025 kappa = (a*b-c)/det;
00026 if(util.fcnMon1&0x2) {
00027 printf("\nbm V=%.1f %.1f %.1f, U=%.3f %.3f %.3f\n",V.x(),V.y(),V.z(),U.x(),U.y(),U.z());
00028
00029 printf(" tr R=%.1f %.1f %.1f, P=%.3f %.3f %.3f\n",R.x(),R.y(),R.z(),P.x(),P.y(),P.z());
00030 printf(" lam=%f kap=%f det=%f a=%f b=%f c=%f\n",lambda,kappa, det,a,b,c);
00031 }
00032 return 0;
00033 }
00034
00035
00036
00037
00038 void beamLineLike3D(int &npar,double *grad,double &fcnval, double *inpPar,int iflag){
00039 double dmax2=util.cut_Dmax*util.cut_Dmax;
00040
00041
00042
00043 fcnval=9999;
00044 assert (util.track.size()>10);
00045 TVector3 V;TVector3 U;
00046 V.SetXYZ(inpPar[0],inpPar[1],0.);
00047 U.SetXYZ(inpPar[2],inpPar[3],1.);
00048 U=U.Unit();
00049
00050 assert(fabs(1.-U.Mag2())<1.e-6);
00051 if(util.fcnMon1) {
00052 char txt[1000];
00053 sprintf(txt,"FCN: 3D dca, beamLine X=%.2f Y=%.2f",V.x(),V.y());
00054 printf("monitor %s\n",txt);
00055 util.hA[21]->SetTitle(txt);
00056 }
00057
00058 double chi2 = 0;
00059 int nBadDet=0;
00060
00061 vector<TrackStump>::iterator it;
00062 for (it=util.track.begin() ; it < util.track.end(); it++) {
00063 TrackStump *t= &(*it);
00064 if (t->bad) continue;
00065 double lambda=0, kappa=0;
00066 TVector3 r(t->r),p(t->p);
00067 if( twoLineDca3D(lambda,kappa,V,U,r,p)) {
00068 nBadDet++; continue;
00069 }
00070 if(util.fcnMon1&0x2) {
00071 TVector3 r1=r+lambda*p;
00072 TVector3 r2=V+kappa*U;
00073 TVector3 D=r1-r2;
00074 printf(" dca T=%.1f %.1f %.1f B=%.1f %.1f %.1f dca=%.1f\n",r1.x(),r1.y(),r1.z(),r2.x(),r2.y(),r2.z(),D.Mag());
00075 }
00076
00077 TVector3 D=((r-V)+(lambda*p-kappa*U));
00078 if(util.fcnMon1) {
00079 util.hA[21]->Fill(D.Mag());
00080 TVector3 r1=r+lambda*p;
00081 util.hA[22]->Fill(r1.z(),D.Mag());
00082 if (D.Mag()<dmax2) {
00083 util.hA[23]->Fill(r.z());
00084 util.hA[0]->Fill(10);
00085 }
00086 }
00087 double dT2=D.Perp2();
00088 double dZ2=D.z()*D.z();
00089
00090 if (dT2<dmax2) chi2+=dT2/t->ery2;
00091 else chi2+=dmax2/t->ery2;
00092 if (dZ2<dmax2) chi2+=dZ2/t->erz2;
00093 else chi2+=dmax2/t->erz2;
00094 }
00095
00096 fcnval = chi2;
00097 util.fcnMon1=0;
00098 if(util.fcnCount<0) return;
00099 if(util.fcnCount%10==0)printf("nCall=%d fcn=%.1f position:V=%.2f,%.2f tilt(Z=100cm):U=%.2f,%.2f\n",util.fcnCount,chi2,V.x(),V.y(),U.x()*100.,U.y()*100.);
00100 util.fcnCount++;
00101 }