1#include "CgemSegmentFitAlg/CgemSegmentFun.h"
3#include "CLHEP/Units/PhysicalConstants.h"
5#include "CLHEP/Matrix/Vector.h"
6#include "CLHEP/Matrix/SymMatrix.h"
7#include "CLHEP/Geometry/Point3D.h"
8#include "KalFitAlg/helix/Helix.h"
11#include "CLHEP/Matrix/Matrix.h"
30 HepMatrix delta_Par(2,1);
31 HepSymMatrix ParErr(2);
33 HepSymMatrix HitErr(2);
38 for(
int i = 0; i < 3; i++){
41 double tmp_phi = atan2(tmp_y , tmp_x );
43 if(dphi[i] < -
M_PI) dphi[i] += 2*
M_PI;
44 if(dphi[i] >=
M_PI) dphi[i] -= 2*
M_PI;
49 delta_Par(1,1) = dphi[i]; delta_Par(2,1) = dz[i];
56 HitErr(1,1) = (pow(S(2,2),2)*ParErr(2,2)+pow(S(2,1),2)*ParErr(1,1))/(pow(S(2,2)*S(1,1),2)*ParErr(2,2)*ParErr(1,1));
57 HitErr(1,2) = -S(2,1)/(S(1,1)*ParErr(2,2)*pow(S(2,2),2));
58 HitErr(2,1) = -S(2,1)/(S(1,1)*ParErr(2,2)*pow(S(2,2),2));
59 HitErr(2,2) = 1./(ParErr(2,2)*pow(S(2,2),2));
61 chisq += (HitErr.similarityT(delta_Par)).determinant();
80 HepMatrix J_dmdx(2,3,0), J_dxda(3,5,0), J(2,5,0), A(6,5,0);
81 HepSymMatrix U(5, 0), W(6,0),
C(2,0);
82 HepVector a_new(5), dm(6), da(5);
85 for(
int i = 0; i < 3; i++) {
92 double tmp_phi = atan2(y,
x);
94 if(dphi[i] < -
M_PI) dphi[i] += 2*
M_PI;
95 if(dphi[i] >=
M_PI) dphi[i] -= 2*
M_PI;
97 dm[i*2]=dphi[i]*
rl[i];
101 J_dmdx(1,1)=-y/
rl[i];
102 J_dmdx(1,2)=
x/
rl[i];
104 J_dxda=cgem_helix_0.
delXDelA(d_phi);
111 cout<<
"iLayer = "<<i<<endl;
112 cout<<
"dm: "<<dm<<endl;
113 cout<<
"J_dmdx: "<<J_dmdx<<endl;
114 cout<<
"J_dxda: "<<J_dxda<<endl;
115 cout<<
"J: "<<J<<endl;
116 cout<<
"A: "<<A<<endl;
117 cout<<
"C: "<<
C<<endl;
118 cout<<
"W: "<<W<<endl;
122 cout<<
"U = "<<U<<endl;
123 cout<<
"U.det() = "<<U.determinant()<<endl;
126 HepSymMatrix U_inv = U;
128 cout<<
"U_inv = "<<U_inv<<endl;
129 cout<<
"I = "<<U*U_inv<<endl;
137 cout<<
"U1 = "<<U1<<endl;
138 U1.invertCholesky5(ifail);
139 cout<<
"ifail = "<<ifail<<endl;
140 cout<<
"U1^-1 = "<<U1<<endl;
141 cout<<
"I1="<<U*U1<<endl;
144 cout<<
"U2 = "<<U2<<endl;
145 U2.invertHaywood5(ifail);
146 cout<<
"ifail = "<<ifail<<endl;
147 cout<<
"U2^-1 = "<<U2<<endl;
148 cout<<
"I2="<<U*U2<<endl;
151 cout<<
"U3 = "<<U3<<endl;
152 U3.invertBunchKaufman(ifail);
153 cout<<
"ifail = "<<ifail<<endl;
154 cout<<
"U3^-1 = "<<U3<<endl;
155 cout<<
"I3="<<U*U3<<endl;
164 cout<<
"ifail = "<<ifail<<endl;
165 cout<<
"U^-1 = "<<U<<endl;
166 cout<<
"I="<<U*U0<<endl;
170 cout<<
"del_a="<<da<<endl;
172 cout<<
"a_new="<<a_new<<endl;
178 double dphi[3],dv[3];
181 for(
int i = 0; i < 3; i++){
185 double tmp_phi = atan2(tmp_y , tmp_x );
186 while(tmp_phi<0) tmp_phi += 2*
M_PI;
187 dphi[i] = tmp_phi -
vec_phi[i];
188 if(dphi[i] < -
M_PI) dphi[i] += 2*
M_PI;
189 if(dphi[i] >=
M_PI) dphi[i] -= 2*
M_PI;
192 dv[i] = tmp_v -
vec_v[i];
201 chisq = -1.*log(total);
209 for(
int i = 0; i < 5; i++){
217 if(fabs(
x)>delta_phi)
return 0.;
218 else return 0.5/delta_phi;
222 return 1./sqrt(2*
M_PI)/sigma*
exp(-1.*pow((
x-mean)/sigma,2)/2);
226 double m_rad = helix.
radius();
227 double l = helix.
center().perp();
229 double cosPhi = (m_rad * m_rad + l * l - r * r) / (2 * m_rad * l);
231 if(cosPhi < -1 || cosPhi > 1)
return 0;
233 double dPhi = helix.
center().phi() - acos(cosPhi) - helix.
phi0();
242 double x[3]={0.};
double y[3]= {0.};
243 for(
int i = 0; i < 3; i++){
248 x0 = ((pow(
x[2],2)+pow(y[2],2))*(y[1]-y[0])+(pow(
x[1],2)+pow(y[1],2))*(y[0]-y[2])+(pow(
x[0],2)+pow(y[0],2))*(y[2]-y[1]))/(2.*((
x[2] -
x[0])*(y[1] - y[0]) - (
x[1] -
x[0])*(y[2] - y[0])));
249 y0 = ((pow(
x[2],2)+pow(y[2],2))*(
x[1]-
x[0])+(pow(
x[1],2)+pow(y[1],2))*(
x[0]-
x[2])+(pow(
x[0],2)+pow(y[0],2))*(
x[2]-
x[1]))/(2.*((y[2] - y[0])*(
x[1] -
x[0]) - (y[1] -y[0])*(
x[2] -
x[0])));
250 r = sqrt(pow(
x[1]-x0, 2) + pow(y[1]-y0,2));
252 return 333.564*charge/r;
257 double x[3]={0.};
double y[3]= {0.};
258 for(
int i = 0; i < 3; i++){
263 x0 = ((pow(
x[2],2)+pow(y[2],2))*(y[1]-y[0])+(pow(
x[1],2)+pow(y[1],2))*(y[0]-y[2])+(pow(
x[0],2)+pow(y[0],2))*(y[2]-y[1]))/(2.*((
x[2] -
x[0])*(y[1] - y[0]) - (
x[1] -
x[0])*(y[2] - y[0])));
264 y0 = ((pow(
x[2],2)+pow(y[2],2))*(
x[1]-
x[0])+(pow(
x[1],2)+pow(y[1],2))*(
x[0]-
x[2])+(pow(
x[0],2)+pow(y[0],2))*(
x[2]-
x[1]))/(2.*((y[2] - y[0])*(
x[1] -
x[0]) - (y[1] -y[0])*(
x[2] -
x[0])));
267 r = sqrt(pow(
x[1]-x0, 2) + pow(y[1]-y0,2));
270 d0 = sqrt(x0*x0 + y0*y0) - r;
271 if(d0 >= 0) d0 = charge*d0;
272 else d0 = -charge*d0;
274 phi0 = atan2(-y0*charge,-x0*charge);
277 if(phi0 < 0)phi0 += 2.*
M_PI;
279 double pt_temp= r/333.564*charge;
280 a_kappa = 1./pt_temp;
282 TGraph* Zz =
new TGraph(3);
283 TF1*
f1 =
new TF1(
"f1",
"[0]+[1]*x",-1000.,1000.);
285 for(
int i = 0; i < 3; i++){
286 s[i] = r*acos(((x0 -
x[i])*x0 + (y0 - y[i])*y0)/r/sqrt(x0*x0 + y0*y0));
287 Zz->SetPoint(i,
s[i],
vec_z[i]);
291 z0 =
f1->GetParameter(0);
292 tanl =
f1->GetParameter(1);
306 double temp[10][10]={0.0};
314 temp[j][k] = arcs[j+1][(k>=i)?k+1:k];
318 double t =
detA(temp,
n-1);
335 int nrow=m.num_row();
336 int ncol=m.num_col();
337 if(nrow!=ncol||nrow<=0||ncol<=0)
return false;
341 for(
int i=0; i<
n; i++)
342 for(
int j=0; j<
n; j++)
343 arcs[i][j]=m(i+1,j+1);
350 double flag=
detA(src,
n);
363 des[i][j]=
t[i][j]/flag;
391 temp[k][
t] = arcs[k>=i?k+1:k][
t>=j?
t+1:
t];
396 ans[j][i] =
detA(temp,
n-1);
399 ans[j][i] = - ans[j][i];
408 int n = mm.num_row();
410 for(
int i=0; i<
n; i++)
411 for(
int j=0; j<
n; j++)
412 arcs[i][j]=mm(i+1,j+1);
416 for(
int i=0; i<
n; i++)
417 for(
int j=0; j<=i; j++)
418 m_inv(i+1,j+1)=des[i][j];
EvtComplex exp(const EvtComplex &c)
double tan(const BesAngle a)
double sin(const BesAngle a)
double cos(const BesAngle a)
***************************************************************************************Pseudo Class RRes *****************************************************************************************Parameters and physical constants **Maarten sept ************************************************************************DOUBLE PRECISION xsmu **************************************************************************PARTICLE DATA all others are from PDG *Only resonances with known widths into electron pairs are sept ************************************************************************C Declarations C
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
HepMatrix delXDelA(double phi) const
double radius(void) const
returns radious of helix.
void getAStart(double arcs[10][10], int n, double ans[10][10])
bool DetSquareMatrix(HepMatrix m, double &det)
void GetHelixVarBeforeFit(int charge, double &d0, double &phi0, double &omega, double &z0, double &tanl)
HepSymMatrix InvC(int iLayer)
bool InverseSymMatrix(HepSymMatrix m, HepSymMatrix &m_inv)
double fLadder(double x, double delta_phi)
double GetKappaAfterFit(int charge, double *rec_phi)
double fGauss(double x, double mean, double sigma)
bool GetMatrixInverse(double src[10][10], int n, double des[10][10])
double detA(double arcs[10][10], int n)
void GetLikelihoodF(CLHEP::HepVector trkpar, HepPoint3D pivot, double &chisq)
HepVector CalculateHelix(CLHEP::HepVector trkpar, HepPoint3D pivot)
void fcnTrk(int &npar, double *gin, double &f, double *par, int iflag)
void GetChisqF(CLHEP::HepVector trkpar, HepPoint3D pivot, double &chisq)
double IntersectCylinder(double r, KalmanFit::Helix helix)