StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
likeFuncBeamLine3D.cxx
1 // C-style global function call by Minuit
2 #include <math.h>
3 #include <assert.h>
4 #include <TVector3.h>
5 #include <TH1.h>
6 
7 #include "UtilBeamLine3D.h"
8 const float detEpsilon=1e-4; // tolernace for paralell lines for DCA computation.
9 
10 //==========================================================
11 int twoLineDca3D(double& lambda,double& kappa,TVector3& V, TVector3& U, TVector3& R,TVector3& P){ // returns non-zero error code
12  /* find lambda and kappa which define the two points on
13  each vector that are on either end of the DCA. */
14  double a= P*U;
15  double det=1-a*a;
16  if(util.fcnMon1) {
17  util.hA[20]->Fill(det);
18  }
19  if(det<detEpsilon) return -1; // abort processing of this track
20 
21  TVector3 VmR=V-R; // will be faster
22  double b= VmR*P;
23  double c = VmR*U;
24  lambda = (b-a*c)/det;
25  kappa = (a*b-c)/det;
26  if(util.fcnMon1&0x2) {
27  printf("\nbm V=%.1f %.1f %.1f, U=%.3f %.3f %.3f\n",V.x(),V.y(),V.z(),U.x(),U.y(),U.z());
28 
29  printf(" tr R=%.1f %.1f %.1f, P=%.3f %.3f %.3f\n",R.x(),R.y(),R.z(),P.x(),P.y(),P.z());
30  printf(" lam=%f kap=%f det=%f a=%f b=%f c=%f\n",lambda,kappa, det,a,b,c);
31  }
32  return 0;
33 }
34 
35 //===========================================================
36 // Function computes total likelohood for Minuit, returns : fcnval
37 //===========================================================
38 void beamLineLike3D(int &npar,double *grad,double &fcnval, double *inpPar,int iflag){
39  double dmax2=util.cut_Dmax*util.cut_Dmax; // to speed up
40 
41 
42 
43  fcnval=9999; // make default large
44  assert (util.track.size()>10); // will prevent on running w/o tracks
45  TVector3 V;TVector3 U;
46  V.SetXYZ(inpPar[0],inpPar[1],0.);
47  U.SetXYZ(inpPar[2],inpPar[3],1.); // direction, needs normalization
48  U=U.Unit();
49  // printf("U=%f %f %f %f\n",U.x(),U.y(),U.z(),U.Mag2());
50  assert(fabs(1.-U.Mag2())<1.e-6);
51  if(util.fcnMon1) {
52  char txt[1000];
53  sprintf(txt,"FCN: 3D dca, beamLine X=%.2f Y=%.2f",V.x(),V.y());
54  printf("monitor %s\n",txt);
55  util.hA[21]->SetTitle(txt);
56  }
57 
58  double chi2 = 0;
59  int nBadDet=0;
60 
61  vector<TrackStump>::iterator it;
62  for (it=util.track.begin() ; it < util.track.end(); it++) {
63  TrackStump *t= &(*it);
64  if (t->bad) continue;
65  double lambda=0, kappa=0;
66  TVector3 r(t->r),p(t->p);
67  if( twoLineDca3D(lambda,kappa,V,U,r,p)) {
68  nBadDet++; continue;
69  }
70  if(util.fcnMon1&0x2) {
71  TVector3 r1=r+lambda*p; // track
72  TVector3 r2=V+kappa*U; // vertex
73  TVector3 D=r1-r2;
74  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());
75  }
76 
77  TVector3 D=((r-V)+(lambda*p-kappa*U));
78  if(util.fcnMon1) {
79  util.hA[21]->Fill(D.Mag());
80  TVector3 r1=r+lambda*p;
81  util.hA[22]->Fill(r1.z(),D.Mag());
82  if (D.Mag()<dmax2) {
83  util.hA[23]->Fill(r.z());
84  util.hA[0]->Fill(10);
85  }
86  }
87  double dT2=D.Perp2(); // compute distance only once
88  double dZ2=D.z()*D.z();
89 
90  if (dT2<dmax2) chi2+=dT2/t->ery2;
91  else chi2+=dmax2/t->ery2;
92  if (dZ2<dmax2) chi2+=dZ2/t->erz2;
93  else chi2+=dmax2/t->erz2;
94  }
95  //printf(" nBadDet=%d\n",nBadDet);
96  fcnval = chi2;
97  util.fcnMon1=0; // clear this flag so only one set is monitored
98  if(util.fcnCount<0) return; // skip if in scanning mode
99  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.);
100  util.fcnCount++;
101 }