10#include "VertexFit/KalmanVertexFit.h"
11#include "VertexFit/HTrackParameter.h"
12#include "VertexFit/WTrackParameter.h"
20 if(m_pointer)
return m_pointer;
27KalmanVertexFit::KalmanVertexFit() {;}
30 m_x = HepVector(3, 0);
31 m_C0 = HepSymMatrix(3, 0);
32 m_C = HepSymMatrix(3, 0);
53 m_chisqCutforTrack = 50;
54 m_maxVertexIteration = 3;
55 m_maxTrackIteration = 5;
56 m_chisqCutforTrackIteration = 0.1;
71 std::vector<int> trackid;
72 v.setEvx(m_C.inverse(ifail));
78 return m_C.inverse(ifail);
90 m_chiF.push_back(999.);
98 m_hTrkOrigin.push_back(htrk);
101 m_hTrkInfit.push_back(htrk);
108 HepSymMatrix W(3, 0);
109 HepSymMatrix GB(5, 0);
120 for(
int k = 0; k < m_hTrkOrigin.size(); k++)
121 if(m_flag[k] == 0)
num =
num +1;
127 std::vector<int> trackid;
128 for(
int k = 0; k < m_hTrkOrigin.size(); k++)
129 if(m_flag[k] == 0) trackid.push_back(
trackID(k));
143 HepSymMatrix CP(3, 0);
152 updateMatrices(k, pp, xp);
156 HepSymMatrix CK(3, 0);
157 CK = CP + (m_GB[k].similarity(m_A[k].T()));
163 x = CK.inverse(ifail) * (CP * xp + m_A[k].T() * m_GB[k] *
164 (m_hTrkOrigin[k].hel() - m_c[k]));
165 p = m_W[k] * m_B[k].T() * m_G[k] *(m_hTrkOrigin[k].hel()- m_c[k]-
168 HepSymMatrix chif(1, 0);
169 chif = CP.similarity((
x-xp).T()) +
170 m_G[k].similarity((m_hTrkOrigin[k].hel()-
171 m_c[k]- m_A[k]*
x - m_B[k]*p).T());
182 m_chiF[k] = chif[0][0];
186 if(fabs(delchi) < m_chisqCutforTrackIteration)
break;
190 if(m_chiF[k] > m_chisqCutforTrack) {
211 HepSymMatrix
C(3, 0);
212 C = m_C - m_GB[k].similarity(m_A[k].T());
213 x =
C.inverse(ifail)*(m_C*m_x-m_A[k].T() * m_GB[k] *
214 (m_hTrkOrigin[k].hel()-m_c[k]));
223 for(
int iter = 0;
iter < m_maxVertexIteration;
iter++) {
233 for(
int k = 0; k < m_hTrkOrigin.size(); k++) {
234 if(m_flag[k]==1)
continue;
245 for(
int k = 0; k < m_hTrkOrigin.size(); k++) {
246 if(m_flag[k]==1)
continue;
247 double chi2 =
chiS(k);
253 if(chi2 > m_chisqCutforTrack) {
264 if(m_flag[k]==1)
return 999;
268 HepSymMatrix
C(3, 0);
269 C = m_C - m_GB[k].similarity(m_A[k].T());
270 x =
C.inverse(ifail)*(m_C*m_x-m_A[k].T() * m_GB[k] *
271 (m_hTrkOrigin[k].hel()-m_c[k]));
272 p = m_W[k]* m_B[k].T()*m_G[k]*
273 (m_hTrkOrigin[k].hel()-m_c[k]-m_A[k]*m_x);
274 HepSymMatrix chis(1, 0);
275 chis =
C.similarity((
x-m_x).T())+
276 m_G[k].similarity((m_hTrkOrigin[k].hel()-m_c[k]-
277 m_A[k]*m_x-m_B[k]*p).T());
286 if(m_flag[k] == 1)
return;
291 HepSymMatrix CP(3, 0);
296 updateMatrices(k, pp, xp);
297 pp = m_W[k] * m_B[k].T() * m_G[k] * (m_hTrkOrigin[k].hel() - m_c[k] - m_A[k] * xp);
299 updateMatrices(k, pp, xp);
301 HepVector helix(5, 0);
302 helix = m_c[k] + m_A[k] * xp + m_B[k] * pp;
303 HepMatrix E(3, 3, 0);
304 E = -CP.inverse(ifail) * m_A[k].T() * m_G[k] * m_B[k] * m_W[k];
305 HepSymMatrix D(3, 0);
306 D = m_W[k] + CP.similarity(E.T());
308 HepMatrix middle(5, 5, 0);
309 HepSymMatrix error(5, 0);
310 middle = (CP.inverse(ifail)).similarity(m_A[k]) + m_A[k] * E * m_B[k].T() +
311 (m_A[k] * E * m_B[k].T()).T() + D.similarity(m_B[k]);
312 error.assign(middle);
314 m_hTrkInfit[k].setHel(helix);
315 m_hTrkInfit[k].setEHel(error);
372 if(m_flag[k]==1)
return;
385 return m_hTrkInfit[k];
389 if(m_flag[k] == 1)
return m_hTrkOrigin[k].wTrack();
394 HepSymMatrix CP(3, 0);
400 double Energy = sqrt(pp[0]*pp[0] + pp[1]*pp[1] + pp[2]*pp[2] +
mass *
mass);
402 HepMatrix Awtrk(7, 3, 0), Bwtrk(7, 3, 0);
403 Awtrk[4][0] = Awtrk[5][1] = Awtrk[6][2] = 1;
404 Bwtrk[0][0] = Bwtrk[1][1] = Bwtrk[2][2] = 1;
405 Bwtrk[3][0] = pp[0] / Energy;
406 Bwtrk[3][1] = pp[1] / Energy;
407 Bwtrk[3][2] = pp[2] / Energy;
410 HepSymMatrix Ew(7, 0);
411 w[0] = pp[0];
w[1] = pp[1];
w[2] = pp[2];
w[3] = Energy;
412 w[4] = xp[0];
w[5] = xp[1];
w[6] = xp[2];
414 HepSymMatrix Gwtrk(7, 0);
415 Gwtrk = m_hTrkOrigin[k].wTrack().Ew().inverse(ifail);
416 HepSymMatrix Wwtrk(3, 0);
417 Wwtrk = Gwtrk.similarity(Bwtrk.T()).inverse(ifail);
419 HepMatrix Ewtrk(3, 3, 0);
420 Ewtrk = -CP.inverse(ifail) * Awtrk.T() * Gwtrk * Bwtrk * Wwtrk;
421 HepSymMatrix Dwtrk(3, 0);
422 Dwtrk = Wwtrk + CP.similarity(Ewtrk.T());
424 HepMatrix Ewmiddle(7, 7, 0);
425 Ewmiddle = (CP.inverse(ifail)).similarity(Awtrk) + Awtrk * Ewtrk * Bwtrk.T() +
426 (Awtrk * Ewtrk * Bwtrk.T()).T() + Dwtrk.similarity(Bwtrk);
429 wtrk.
setCharge(m_hTrkOrigin[k].charge());
439void KalmanVertexFit::updateMatrices(
const int k,
const HepVector p,
const HepVector x) {
449 m_A[k] = he.dHdx(p,
x);
450 m_B[k] = he.dHdp(p,
x);
453 m_W[k] = (m_G[k].similarity(m_B[k].T())).
inverse(ifail);
454 m_GB[k] = m_G[k] - (m_W[k].similarity(m_B[k])).similarity(m_G[k]);
455 m_c[k] = he.hel() - m_A[k] *
x - m_B[k] * p;
458void KalmanVertexFit::updateMatrices(
const int k) {
465 updateMatrices(k, p,
x);
469 HepVector n_pull(5, 0);
470 n_pull[0] = n_pull[1] = n_pull[2] = n_pull[3] = n_pull[4] = 999.;
471 if(m_flag[k] == 1)
return n_pull;
472 for (
int i = 0 ; i < 5; i++) {
473 double cov = m_hTrkOrigin[k].eHel()[i][i] - m_hTrkInfit[k].eHel()[i][i];
474 if (cov == 0.)
continue;
475 n_pull[i] = (m_hTrkOrigin[k].hel()[i] - m_hTrkInfit[k].hel()[i]) / sqrt(cov);
482 if(m_flag[k] == 1)
return pull;
484 double kappa_origin = m_hTrkOrigin[k].kappa();
485 double kappa_infit = m_hTrkInfit[k].kappa();
486 double lamb_origin = m_hTrkOrigin[k].lambda();
487 double lamb_infit = m_hTrkInfit[k].lambda();
489 double Vkappa_origin = m_hTrkOrigin[k].eHel()[2][2];
490 double Vkappa_infit = m_hTrkInfit[k].eHel()[2][2];
491 double Vlamb_origin = m_hTrkOrigin[k].eHel()[4][4];
492 double Vlamb_infit = m_hTrkInfit[k].eHel()[4][4];
493 double V_kappa_lamb_origin = m_hTrkOrigin[k].eHel()[4][2];
494 double V_kappa_lamb_infit = m_hTrkInfit[k].eHel()[4][2];
496 double P_origin = calculationP(kappa_origin, lamb_origin);
502 double P_infit = calculationP(kappa_infit, lamb_infit);
504 double SigmaP_origin = calculationSigmaP(kappa_origin, lamb_origin, Vkappa_origin,
505 Vlamb_origin, V_kappa_lamb_origin);
506 double SigmaP_infit = calculationSigmaP(kappa_infit, lamb_infit, Vkappa_infit,
507 Vlamb_infit, V_kappa_lamb_infit);
508 if ((SigmaP_origin - SigmaP_infit) <= 0.)
return pull;
509 pull = (P_origin - P_infit) / sqrt (SigmaP_origin - SigmaP_infit);
515double KalmanVertexFit::calculationP(
const double kappa,
const double lamb) {
517 P = sqrt(1 + lamb * lamb) / kappa;
522double KalmanVertexFit::calculationSigmaP(
const double kappa,
const double lamb,
523 const double Vkappa,
const double Vlamb,
524 const double Vkappa_lamb) {
526 double dp_dkappa = -sqrt(1 + lamb*lamb) /kappa/kappa;
527 double dp_dlamb = lamb / kappa / sqrt(1 + lamb*lamb);
528 SigmaP = dp_dkappa * dp_dkappa * Vkappa + dp_dlamb * dp_dlamb * Vlamb
529 + 2 * dp_dkappa * dp_dlamb * Vkappa_lamb;
double P(RecMdcKalTrack *trk)
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
***************************************************************************************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
HepSymMatrix eHel() const
double pullmomentum(const int k)
void addTrack(const HTrackParameter)
int trackID(const int k) const
HTrackParameter hTrack(const int k) const
WTrackParameter wTrack(const int k, const double mass) const
VertexParameter vtx() const
std::vector< int > trackIDList() const
double chiS(const int k) const
void initVertex(const VertexParameter vtx)
HepVector pull(const int k)
static KalmanVertexFit * instance()
void inverse(const int k)
void setEw(const HepSymMatrix &Ew)
void setCharge(const int charge)
void setW(const HepVector &w)