9const int VertexFit::NTRKPAR = 6;
10const int VertexFit::NVTXPAR = 3;
11const int VertexFit::NCONSTR = 2;
17 if (m_pointer)
return m_pointer;
27VertexFit::VertexFit() {;}
43 m_vpar_origin.clear();
48 m_virtual_wtrk.clear();
53 m_TRA = HepMatrix(6, 7, 0);
60 m_TRB = HepMatrix(7, 6, 0);
78 m_vpar_origin.push_back(
vpar);
79 m_vpar_infit.push_back(
vpar);
80 if ((
unsigned int)number != m_vc.size() - 1)
81 std::cout <<
"wrong kinematic constraints index" << std::endl;
93 for (
unsigned int i = 0; i < tlis.size(); i++)
98 m_vpar_origin.push_back(n_vpar);
99 m_vpar_infit.push_back(n_vpar);
101 m_virtual_wtrk.push_back(vwtrk);
102 if ((
unsigned int)number != m_vc.size() - 1)
103 std::cout <<
"wrong kinematic constraints index" << std::endl;
127 std::vector<int> tlis =
AddList(
n1,
n2, n3, n4, n5);
133 std::vector<int> tlis =
AddList(
n1,
n2, n3, n4, n5, n6);
139 std::vector<int> tlis =
AddList(
n1,
n2, n3, n4, n5, n6, n7);
145 std::vector<int> tlis =
AddList(
n1,
n2, n3, n4, n5, n6, n7, n8);
149void VertexFit::AddVertex(
int number,
VertexParameter vpar,
int n1,
int n2,
int n3,
int n4,
int n5,
int n6,
int n7,
int n8,
int n9)
151 std::vector<int> tlis =
AddList(
n1,
n2, n3, n4, n5, n6, n7, n8, n9);
155void VertexFit::AddVertex(
int number,
VertexParameter vpar,
int n1,
int n2,
int n3,
int n4,
int n5,
int n6,
int n7,
int n8,
int n9,
int n10)
157 std::vector<int> tlis =
AddList(
n1,
n2, n3, n4, n5, n6, n7, n8, n9, n10);
161void VertexFit::AddVertex(
int number,
VertexParameter vpar,
int n1,
int n2,
int n3,
int n4,
int n5,
int n6,
int n7,
int n8,
int n9,
int n10,
int n11)
163 std::vector<int> tlis =
AddList(
n1,
n2, n3, n4, n5, n6, n7, n8, n9, n10, n11);
167void VertexFit::AddVertex(
int number,
VertexParameter vpar,
int n1,
int n2,
int n3,
int n4,
int n5,
int n6,
int n7,
int n8,
int n9,
int n10,
int n11,
int n12)
169 std::vector<int> tlis =
AddList(
n1,
n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12);
177 m_cpu = HepVector(10, 0);
178 if (
n < 0 || (
unsigned int)
n >= m_vc.size())
return okfit;
184 m_pOrigin = HepVector(m_nvtrk * NTRKPAR, 0);
185 m_pInfit = HepVector(m_nvtrk * NTRKPAR, 0);
186 m_pcovOrigin = HepSymMatrix(m_nvtrk * NTRKPAR, 0);
187 m_pcovInfit = HepSymMatrix(m_nvtrk * NTRKPAR, 0);
190 for(
unsigned int itk = 0; itk < ntrk; itk++)
196 m_pInfit = m_pOrigin;
198 m_xOrigin = HepVector(NVTXPAR, 0);
199 m_xInfit = HepVector(NVTXPAR, 0);
200 m_xcovOrigin = HepSymMatrix(NVTXPAR, 0);
201 m_xcovInfit = HepSymMatrix(NVTXPAR, 0);
202 m_xcovOriginInversed = HepSymMatrix(NVTXPAR, 0);
203 m_xcovInfitInversed = HepSymMatrix(NVTXPAR, 0);
205 m_xOrigin = m_vpar_origin[
n].Vx();
206 m_xcovOrigin = m_vpar_origin[
n].Evx();
207 m_xcovOriginInversed = m_xcovOrigin.inverse(ifail);
208 m_xInfit = m_xOrigin;
210 m_vpar_infit[
n] = m_vpar_origin[
n];
212 m_B = HepMatrix(NCONSTR*m_nvtrk, NVTXPAR, 0);
213 m_A = HepMatrix(NCONSTR*m_nvtrk, NTRKPAR*m_nvtrk, 0);
214 m_BT = HepMatrix(NVTXPAR,NCONSTR*m_nvtrk, 0);
215 m_AT = HepMatrix(NTRKPAR*m_nvtrk, NCONSTR*m_nvtrk, 0);
216 m_G = HepVector(NCONSTR*m_nvtrk, 0);
217 m_W = HepSymMatrix(NCONSTR*m_nvtrk, 0);
218 m_E = HepMatrix(NTRKPAR*m_nvtrk, NVTXPAR, 0);
221 m_cpu[0] += timer.CpuTime();
224 std::vector<double>
chisq;
226 for (
int it = 0; it < m_niter; it++)
229 UpdateConstraints(m_vc[
n]);
231 m_cpu[1] += timer.CpuTime();
235 m_cpu[2] += timer.CpuTime();
236 chisq.push_back(m_chisq[
n]);
240 if (fabs(delchi) < m_chiter)
break;
247 if (m_chisq[
n] >= m_chicut)
return okfit;
250 m_vpar_infit[
n].setVx(m_xInfit);
251 m_vpar_infit[
n].setEvx(m_xcovInfit);
260 if (
n < 0 || (
unsigned int)
n >= m_vc.size())
262 for (
unsigned int i = 0; i < (m_vc[
n].Ltrk()).size(); i++)
264 int itk = (m_vc[
n].Ltrk())[i];
267 m_vpar_infit[
n] = m_vpar_origin[
n];
270 std::vector<double>
chisq;
272 for (
int it = 0; it < m_niter; it++)
274 std::vector<WTrackParameter> wlis;
276 for (
unsigned int i = 0; i < (m_vc[
n].Ltrk()).size(); i++)
278 int itk = (m_vc[
n].Ltrk())[i];
282 m_vc[
n].UpdateConstraints(
vpar, wlis);
285 chisq.push_back(m_chisq[
n]);
289 if(fabs(delchi) < m_chiter)
293 if(m_chisq[
n]>=m_chicut)
return okfit;
303 for (
unsigned int n = 0;
n<(int)(m_vc.size());
n++)
306 if (m_chisq[
n] >= m_chicut)
return okfit;
308 mychi = mychi + m_chisq[
n];
315void VertexFit::fitVertex(
int n)
317 if (m_chisq.size() == 0)
319 for (
unsigned int i = 0; i < m_vc.size(); i++)
320 m_chisq.push_back(9999.0);
326 int NSIZE = (vc.
Ltrk()).size();
330 m_xcovInfitInversed = m_xcovOriginInversed;
332 for (
unsigned int i = 0; i < NSIZE; i++)
334 int itk = (vc.
Ltrk())[i];
335 m_xcovInfitInversed += vfW(itk).similarity(vfBT(itk));
337 m_xcovInfit = m_xcovInfitInversed.inverse(ifail);
340 m_KQ = HepMatrix(NVTXPAR, m_nvtrk * NCONSTR, 0);
341 m_E = HepMatrix(m_nvtrk*NTRKPAR, NVTXPAR, 0);
342 for (
unsigned int i = 0; i < NSIZE; i++)
344 int itk = (vc.
Ltrk())[i];
345 setKQ(itk, (m_xcovInfit * vfBT(itk) * vfW(itk)));
346 setE(itk, (-pcovOrigin(itk) * vfAT(itk) * vfKQ(itk).T()));
349 m_xInfit = m_xOrigin;
350 for (
unsigned int i = 0; i < NSIZE; i++)
352 int itk = (vc.
Ltrk())[i];
353 m_xInfit -= vfKQ(itk) * vfG(itk);
356 HepVector dq0q(NVTXPAR, 0);
357 dq0q = m_xcovInfitInversed * (m_xOrigin - m_xInfit);
358 for (
unsigned int i = 0; i < NSIZE; i++)
360 int itk = (vc.
Ltrk())[i];
361 HepVector
alpha(NTRKPAR, 0);
362 alpha = pOrigin(itk) - pcovOrigin(itk) * vfAT(itk) * (vfW(itk)*vfG(itk) - vfKQ(itk).T()*dq0q);
363 setPInfit(itk,
alpha);
366 m_chisq[
n] = (m_W.similarity(m_G.T())- m_xcovInfitInversed.similarity((m_xInfit-m_xOrigin).T()))[0][0];
369void VertexFit::vertexCovMatrix(
int n)
376 unsigned int NSIZE = vc.
Ltrk().size();
378 m_pcovInfit = HepSymMatrix(NTRKPAR*m_nvtrk, 0);
379 for (
unsigned int i = 0; i < NSIZE; i++)
381 int itk = vc.
Ltrk()[i];
382 setPCovInfit(itk, pcovOrigin(itk) - vfW(itk).similarity(pcovOrigin(itk) * vfAT(itk)));
384 m_pcovInfit = m_pcovInfit + m_xcovInfitInversed.similarity(m_E);
387 m_cpu[3] += timer.CpuTime();
390void VertexFit::swimVertex(
int n)
407 unsigned int NSIZE = vc.
Ltrk().size();
409 HepMatrix
A(6, 6, 0);
413 HepMatrix
B(6, 3, 0);
419 HepSymMatrix
Ew(7, 0);
420 HepMatrix ew1(6, 6, 0);
421 HepMatrix ew2(7, 7, 0);
423 for (
unsigned int i = 0; i < NSIZE; i++)
425 int itk = vc.
Ltrk()[i];
433 w1 =
A * pInfit(itk) +
B * m_xInfit;
434 ew1 = pcovInfit(itk).similarity(A) + m_xcovInfit.similarity(B) +
A*vfE(itk)*
B.T() +
B*(vfE(itk).T())*
A.T();
440 m_TRB[3][0] = w2[0] / w2[3];
441 m_TRB[3][1] = w2[1] / w2[3];
442 m_TRB[3][2] = w2[2] / w2[3];
444 ew2 = m_TRB * ew1 * m_TRB.T();
451 m_cpu[4] += timer.CpuTime();
456 assert(p.num_row() == 5);
462 HepSymMatrix ew1(6, 0);
463 HepSymMatrix ew2(7, 0);
466 ew1 = pcovInfit(itk);
467 w2 = Convert67(wtrk0.
mass(), w1);
468 m_TRB[3][0] = w2[0] / w2[3];
469 m_TRB[3][1] = w2[1] / w2[3];
470 m_TRB[3][2] = w2[2] / w2[3];
471 ew2 = ew1.similarity(m_TRB);
478 for (
int i = 0; i < 5; i++)
480 double del = htrk0.
eHel()[i][i] - htrk1.
eHel()[i][i];
485 p[i] = (htrk0.
helix()[i] - htrk1.
helix()[i]) / sqrt(
abs(del));
490void VertexFit::fitBeam(
int n)
552void VertexFit::swimBeam(
int n)
623 HepMatrix A(NTRKPAR, NTRKPAR * m_nvtrk, 0);
624 HepMatrix B(NTRKPAR, NVTXPAR, 0);
626 unsigned int NSIZE = vc.
Ltrk().size();
629 HepMatrix Ai(6, 6, 0);
633 HepMatrix Bi(6, 3, 0);
639 HepSymMatrix
Ew(7, 0);
640 HepMatrix ew1(6, 6, 0);
641 HepMatrix ew2(7, 7, 0);
644 for(
unsigned int i = 0; i < NSIZE; i++)
646 int itk = vc.
Ltrk()[i];
656 A.sub(1, NTRKPAR*itk + 1, Ai);
663 w1 = A * m_pInfit + B * m_xInfit;
664 ew1 = m_pcovInfit.similarity(A) + m_xcovInfit.similarity(B) + A*m_E*B.T()+B*(m_E.T())*A.T();
675 m_TRB[3][0] = w1[0] / totalE;
676 m_TRB[3][1] = w1[1] / totalE;
677 m_TRB[3][2] = w1[2] / totalE;
678 ew2 = m_TRB * ew1 * m_TRB.T();
685 m_virtual_wtrk[
n] = vwtrk;
687 m_cpu[5] += timer.CpuTime();
692 int ntrk = (vc.
Ltrk()).size();
693 int type = vc.
type();
698 for (
unsigned int i = 0; i < ntrk; i++)
700 int itk = (vc.
Ltrk())[i];
701 HepVector
alpha(6, 0);
718 double J = a * (delx.x()*p.px() + delx.y()*p.py()) / p.perp2();
719 J = std::min(J, 1-1e-4);
720 J = std::max(J, -1+1e-4);
721 double Rx = delx.x() - 2 * p.px() * (delx.x()*p.px() + delx.y()*p.py()) / p.perp2();
722 double Ry = delx.y() - 2 * p.py() * (delx.x()*p.px() + delx.y()*p.py()) / p.perp2();
723 double S = 1.0 / sqrt(1-J*J) / p.perp2();
726 dc[0] = delx.y()*p.px() - delx.x()*p.py() - 0.5*a*(delx.x()*delx.x() + delx.y()*delx.y());
727 dc[1] = delx.z() - p.pz()/a*asin(J);
730 HepMatrix Ec(2, 3, 0);
733 HepMatrix Dc(2, 6, 0);
735 Dc[0][1] = -delx.x();
737 Dc[0][3] = p.py() + a * delx.x();
738 Dc[0][4] = -p.px() + a * delx.y();
740 Dc[1][0] = -p.pz() * S * Rx;
741 Dc[1][1] = -p.pz() * S * Ry;
742 Dc[1][2] = - asin(J) / a;
743 Dc[1][3] = p.px() * p.pz() * S;
744 Dc[1][4] = p.py() * p.pz() * S;
749 HepSymMatrix vd(2, 0);
751 vd = pcovOrigin(itk).similarity(Dc);
760 for (
unsigned int i = 0; i < ntrk; i++)
762 int itk = (vc.
Ltrk())[i];
763 HepVector
alpha(6, 0);
783 dc[0] = p.pz()*delx.x() - p.px()*delx.z();
784 dc[1] = p.pz()*delx.y() - p.py()*delx.z();
786 HepMatrix Ec(2, 3, 0);
796 HepMatrix Dc(2, 6, 0);
797 Dc[0][0] = -delx.z();
804 Dc[1][1] = -delx.z();
813 HepSymMatrix vd(2, 0);
816 vd = pcovOrigin(itk).similarity(Dc);
822 gc = Dc*(pOrigin(itk)-pInfit(itk)) + Ec*(m_xOrigin-m_xInfit) +
dc;
830 double J = a * (delx.x()*p.px() + delx.y()*p.py())/p.perp2();
831 J = std::min(J, 1-1e-4);
832 J = std::max(J, -1+1e-4);
833 double Rx = delx.x() - 2*p.px()*(delx.x()*p.px() + delx.y()*p.py())/p.perp2();
834 double Ry = delx.y() - 2*p.py()*(delx.x()*p.px() + delx.y()*p.py())/p.perp2();
835 double S = 1.0 / sqrt(1-J*J) / p.perp2();
839 dc[0] = delx.y() * p.px() - delx.x() * p.py() - 0.5 * a * (delx.x() * delx.x() + delx.y() * delx.y());
840 dc[1] = delx.z() - p.pz() / a*asin(J);
842 HepMatrix Ec(2, 3, 0);
843 Ec[0][0] = -p.py()- a * delx.x();
844 Ec[0][1] = p.px() - a * delx.y();
846 Ec[1][0] = -p.px() * p.pz() * S ;
847 Ec[1][1] = -p.py() * p.pz() * S ;
855 Dc[0][1] = -delx.x();
857 Dc[0][3] = p.py() + a*delx.x();
858 Dc[0][4] = -p.px() + a*delx.y();
861 Dc[1][0] = -p.pz()*S*Rx;
862 Dc[1][1] = -p.pz()*S*Ry;
863 Dc[1][2] = -asin(J)/a;
864 Dc[1][3] = p.px()*p.pz()*S;
865 Dc[1][4] = p.py()*p.pz()*S;
870 HepSymMatrix vd(2, 0);
872 vd = pcovOrigin(itk).similarity(Dc);
877 gc = Dc * (pOrigin(itk) - pInfit(itk)) + Ec *(m_xOrigin - m_xInfit) +
dc;
886HepVector VertexFit::Convert67(
const double &
mass,
const HepVector &p)
890 m.sub(1, p.sub(1, 3));
891 m.sub(5, p.sub(4, 6));
892 m[3] = sqrt(
mass*
mass + p[0]*p[0] + p[1]*p[1] + p[2]*p[2]);
896HepVector VertexFit::Convert76(
const HepVector &p)
900 m.sub(1, p.sub(1, 3));
901 m.sub(4, p.sub(5, 7));
double abs(const EvtComplex &c)
HepGeom::Point3D< double > HepPoint3D
HepSymMatrix eHel() const
std::vector< int > AddList(int n1)
std::vector< WTrackParameter > wTrackInfit() const
void clearGammaShapeList()
std::vector< WTrackParameter > wTrackOrigin() const
void setWTrackInfit(const int n, const WTrackParameter wtrk)
std::vector< int > Ltrk() const
void FixedVertexConstraints(std::vector< int > tlis)
void CommonVertexConstraints(std::vector< int > tlis)
double getCBz(const HepVector &vtx, const HepVector &trackPosition)
static VertexFitBField * instance()
WTrackParameter wtrk(int n) const
HepSymMatrix Ew(int n) const
void AddBeamFit(int number, VertexParameter vpar, int n)
void AddVertex(int number, VertexParameter vpar, std::vector< int > lis)
bool pull(int n, int itk, HepVector &p)
HepPoint3D vx(int n) const
static VertexFit * instance()
VertexParameter vpar(int n) const
void BuildVirtualParticle(int number)
void setVx(const HepPoint3D &vx)
void setEw(const HepSymMatrix &Ew)
void setCharge(const int charge)
void setW(const HepVector &w)