8 #include "CLHEP/GenericFunctions/CumulativeChiSquare.hh"
17 declareInterface<CascadeTools>(
this);
27 if(particleMom.size() == 0)
return -999999.;
28 TLorentzVector totalMom;
29 unsigned int NTrk = particleMom.size();
30 for(
unsigned int it=0;
it<NTrk;
it++) totalMom += particleMom[
it];
36 if(particleMom2.size() == 0)
return -999999.;
37 TLorentzVector totalMom;
38 unsigned int NTrk = particleMom2.size();
39 if (
masses.size() != NTrk) {
40 ATH_MSG_DEBUG(
"The provided number of masses does not match the number of tracks in the vertex");
44 for(
unsigned int it=0;
it<NTrk;
it++) {
45 double esq = particleMom2[
it].Px()*particleMom2[
it].Px() + particleMom2[
it].Py()*particleMom2[
it].Py() +
47 double e = (esq>0.) ? sqrt(esq) : 0.;
49 temp.SetPxPyPzE(particleMom2[
it].Px(),particleMom2[
it].Py(),particleMom2[
it].Pz(),
e);
57 if(particleMom.size() == 0)
return -999999.;
58 unsigned int NTrk = particleMom.size();
59 TLorentzVector totalMom;
60 for(
unsigned int it=0;
it<NTrk;
it++) totalMom += particleMom[
it];
63 for(
unsigned int it=0;
it<NTrk;
it++) {
64 D_vec(3*
it+3) = 2.*(totalMom.E()*particleMom[
it].Px()/particleMom[
it].E()-totalMom.Px());
65 D_vec(3*
it+4) = 2.*(totalMom.E()*particleMom[
it].Py()/particleMom[
it].E()-totalMom.Py());
66 D_vec(3*
it+5) = 2.*(totalMom.E()*particleMom[
it].Pz()/particleMom[
it].E()-totalMom.Pz());
69 double massVarsq = merr(0,0);
70 if (massVarsq <= 0.)
ATH_MSG_DEBUG(
"massError: negative sqrt massVarsq " << massVarsq);
71 double massVar = (massVarsq>0.) ? sqrt(massVarsq) : 0.;
72 double massErr = massVar/(2.*totalMom.M());
78 if(particleMom2.size() == 0)
return -999999.;
79 unsigned int NTrk = particleMom2.size();
80 if (
masses.size() != NTrk) {
81 ATH_MSG_DEBUG(
"The provided number of masses does not match the number of tracks in the vertex");
84 std::vector<TLorentzVector> particleMom(NTrk);
85 for(
unsigned int it=0;
it<NTrk;
it++) {
86 double esq = particleMom2[
it].Px()*particleMom2[
it].Px() + particleMom2[
it].Py()*particleMom2[
it].Py() +
88 double e = (esq>0.) ? sqrt(esq) : 0.;
89 particleMom[
it].SetPxPyPzE(particleMom2[
it].Px(),particleMom2[
it].Py(),particleMom2[
it].Pz(),
e);
91 TLorentzVector totalMom;
92 for(
unsigned int it=0;
it<NTrk;
it++) totalMom += particleMom[
it];
94 std::vector<double>dm2dpx(NTrk), dm2dpy(NTrk), dm2dpz(NTrk);
95 for(
unsigned int it=0;
it<NTrk;
it++) {
96 dm2dpx[
it] = 2.*(totalMom.E()*particleMom[
it].Px()/particleMom[
it].E()-totalMom.Px());
97 dm2dpy[
it] = 2.*(totalMom.E()*particleMom[
it].Py()/particleMom[
it].E()-totalMom.Py());
98 dm2dpz[
it] = 2.*(totalMom.E()*particleMom[
it].Pz()/particleMom[
it].E()-totalMom.Pz());
101 for(
unsigned int it=0;
it<NTrk;
it++) {
102 D_vec(3*
it+3) = dm2dpx[
it];
103 D_vec(3*
it+4) = dm2dpy[
it];
104 D_vec(3*
it+5) = dm2dpz[
it];
107 double massVarsq = merr(0,0);
108 if (massVarsq <= 0.)
ATH_MSG_DEBUG(
"massError: negative sqrt massVarsq " << massVarsq);
109 double massVar = (massVarsq>0.) ? sqrt(massVarsq) : 0.;
110 double massErr = massVar/(2.*totalMom.M());
116 if(particleMom.size() == 0)
return -999999.;
123 if(particleMom.size() == 0)
return -999999.;
127 double PT =
P.perp();
129 unsigned int NTrk = particleMom.size();
131 for(
unsigned int it=0;
it<NTrk;
it++) {
132 D_vec(3*
it+3) = Px/
PT;
133 D_vec(3*
it+4) = Py/
PT;
137 double PtErrsq = PtErrSq(0,0);
138 if (PtErrsq <= 0.)
ATH_MSG_DEBUG(
"ptError: negative sqrt PtErrsq " << PtErrsq);
139 return (PtErrsq>0.) ? sqrt(PtErrsq) : 0.;
144 if(particleMom.size() == 0)
return -999999.;
146 double dx = vert.x();
147 double dy = vert.y();
149 double dxy = (
P.x()*
dx +
P.y()*
dy)/
P.perp();
155 if(particleMom.size() == 0)
return -999999.;
157 double dx = vert.x();
158 double dy = vert.y();
162 double PT =
P.perp();
163 double LXYoverPT = (Px*
dx+Py*
dy)/(
PT*
PT);
165 unsigned int NTrk = particleMom.size();
167 double dLxydx = Px/
PT;
168 double dLxydy = Py/
PT;
169 double dLxydx0 = -dLxydx;
170 double dLxydy0 = -dLxydy;
176 for(
unsigned int it=0;
it<NTrk;
it++) {
177 D_vec(3*
it+3) = (
dx - LXYoverPT*Px)/
PT;
178 D_vec(3*
it+4) = (
dy - LXYoverPT*Py)/
PT;
181 D_vec(3*NTrk+3) = dLxydx0;
182 D_vec(3*NTrk+4) = dLxydy0;
183 D_vec(3*NTrk+5) = 0.;
185 unsigned int ndim = 3*NTrk+3;
187 W_mat.block(0,0,ndim,ndim) =
cov;
188 W_mat.block(3*NTrk+3,3*NTrk+3,3,3) = PV->covariancePosition();
191 double LxyErrsq = V_err(0,0);
192 if (LxyErrsq <= 0.)
ATH_MSG_DEBUG(
"lxyError: negative sqrt LxyErrsq " << LxyErrsq);
193 return (LxyErrsq>0.) ? sqrt(LxyErrsq) : 0.;
198 if(particleMom.size() == 0)
return -999999.;
200 double LXY =
lxy(particleMom,SV,PV);
201 double PT =
pT(particleMom);
207 if(particleMom.size() == 0)
return -999999.;
210 double dx = vert.x();
211 double dy = vert.y();
215 double PT =
P.perp();
216 double LXY = Px*
dx+Py*
dy;
218 unsigned int NTrk = particleMom.size();
219 TLorentzVector totalMom;
220 for(
unsigned int it=0;
it<NTrk;
it++) totalMom += particleMom[
it];
222 double dTaudx = (M*Px)/(
PT*
PT);
223 double dTaudy = (M*Py)/(
PT*
PT);
224 double dTaudx0 = -dTaudx;
225 double dTaudy0 = -dTaudy;
231 for(
unsigned int it=0;
it<NTrk;
it++) {
232 D_vec(3*
it+3) = (((totalMom.E()*particleMom[
it].Px()*LXY)/(M*particleMom[
it].
E()))-Px*LXY/M+M*
dx)/(
PT*
PT) - 2.*M*LXY*Px/(
PT*
PT*
PT*
PT);
233 D_vec(3*
it+4) = (((totalMom.E()*particleMom[
it].Py()*LXY)/(M*particleMom[
it].
E()))-Py*LXY/M+M*
dy)/(
PT*
PT) - 2.*M*LXY*Py/(
PT*
PT*
PT*
PT);
236 D_vec(3*NTrk+3) = dTaudx0;
237 D_vec(3*NTrk+4) = dTaudy0;
238 D_vec(3*NTrk+5) = 0.;
240 unsigned int ndim = 3*NTrk+3;
242 W_mat.block(0,0,ndim,ndim) =
cov;
243 W_mat.block(3*NTrk+3,3*NTrk+3,3,3) = PV->covariancePosition();
246 double tauErrsq = V_err(0,0);
247 if (tauErrsq <= 0.)
ATH_MSG_DEBUG(
"tauError: negative sqrt tauErrsq " << tauErrsq);
248 double tauErr = (tauErrsq>0.) ? sqrt(tauErrsq) : 0.;
254 if(particleMom.size() == 0)
return -999999.;
255 double LXY =
lxy(particleMom,SV,PV);
256 double PT =
pT(particleMom);
262 if(particleMom.size() == 0)
return -999999.;
264 double dx = vert.x();
265 double dy = vert.y();
269 double PT =
P.perp();
270 double LXY = Px*
dx+Py*
dy;
272 unsigned int NTrk = particleMom.size();
273 TLorentzVector totalMom;
274 for(
unsigned int it=0;
it<NTrk;
it++) totalMom += particleMom[
it];
276 double dTaudx = (M*Px)/(
PT*
PT);
277 double dTaudy = (M*Py)/(
PT*
PT);
278 double dTaudx0 = -dTaudx;
279 double dTaudy0 = -dTaudy;
285 for(
unsigned int it=0;
it<NTrk;
it++) {
290 D_vec(3*NTrk+3) = dTaudx0;
291 D_vec(3*NTrk+4) = dTaudy0;
292 D_vec(3*NTrk+5) = 0.;
294 unsigned int ndim = 3*NTrk+3;
296 W_mat.block(0,0,ndim,ndim) =
cov;
297 W_mat.block(3*NTrk+3,3*NTrk+3,3,3) = PV->covariancePosition();
300 double tauErrsq = V_err(0,0);
301 if (tauErrsq <= 0.)
ATH_MSG_DEBUG(
"tauError: negative sqrt tauErrsq " << tauErrsq);
302 double tauErr = (tauErrsq>0.) ? sqrt(tauErrsq) : 0.;
308 if(particleMom.size() == 0) {
315 double p2 =
P.mag2();
316 double pdr =
P.dot((
sv -
pv));
317 return sv -
P*pdr/
p2;
322 if(particleMom.size() == 0)
return -999999.;
326 return (
P.dot(vtx))/(
P.mag()*vtx.mag());
331 if(particleMom.size() == 0)
return -999999.;
335 double pT =
P.perp();
336 return (
P.x()*vtx.x()+
P.y()*vtx.y())/(
pT*vtx.perp());
341 if(particleMom.size() == 0)
return -999999.;
350 if(particleMom.size() == 0)
return -999999.;
352 double dx = vert.x();
353 double dy = vert.y();
354 double dz = vert.z();
359 double P2 =
P.mag2();
360 double L = Px*
dx+Py*
dy+Pz*dz;
362 unsigned int NTrk = particleMom.size();
365 double da0zdx = (Px*Pz)/P2;
366 double da0zdy = (Py*Pz)/P2;
367 double da0zdz = (Pz*Pz)/P2 - 1.;
368 double da0zdx0 = -da0zdx;
369 double da0zdy0 = -da0zdy;
370 double da0zdz0 = -da0zdz;
376 for(
unsigned int it=0;
it<NTrk;
it++) {
377 D_vec(3*
it+3) = (Pz*(P2*
dx-2.*L*Px))/(P2*P2);
378 D_vec(3*
it+4) = (Pz*(P2*
dy-2.*L*Py))/(P2*P2);
379 D_vec(3*
it+5) = (Pz*(P2*dz-2.*L*Pz))/(P2*P2)+L/P2;
381 D_vec(3*NTrk+3) = da0zdx0;
382 D_vec(3*NTrk+4) = da0zdy0;
383 D_vec(3*NTrk+5) = da0zdz0;
385 unsigned int ndim = 3*NTrk+3;
387 W_mat.block(0,0,ndim,ndim) =
cov;
388 W_mat.block(3*NTrk+3,3*NTrk+3,3,3) = PV->covariancePosition();
391 double a0zErrsq = V_err(0,0);
392 if (a0zErrsq <= 0.)
ATH_MSG_DEBUG(
"a0zError: negative sqrt a0zErrsq " << a0zErrsq);
393 return (a0zErrsq>0.) ? sqrt(a0zErrsq) : 0.;
398 if(particleMom.size() == 0)
return -999999.;
399 double cosineTheta_xy =
cosTheta_xy(particleMom,SV,PV);
400 double sinTheta_xy = ((1.-cosineTheta_xy*cosineTheta_xy)>0.) ? sqrt((1.-cosineTheta_xy*cosineTheta_xy)) : 0.;
406 if(particleMom.size() == 0)
return -999999.;
408 double dx = vert.x();
409 double dy = vert.y();
413 double P2 =
P.perp()*
P.perp();
414 double L = Px*
dx+Py*
dy;
415 double dR2 = vert.perp()*vert.perp();
416 double d = sqrt((P2*dR2-L*L)/P2);
418 unsigned int NTrk = particleMom.size();
420 double da0dx = (P2*
dx-L*Px)/(P2*
d);
421 double da0dy = (P2*
dy-L*Py)/(P2*
d);
422 double da0dx0 = -da0dx;
423 double da0dy0 = -da0dy;
429 for(
unsigned int it=0;
it<NTrk;
it++) {
430 D_vec(3*
it+3) = (L*(L*Px-P2*
dx))/(P2*P2*
d);
431 D_vec(3*
it+4) = (L*(L*Py-P2*
dy))/(P2*P2*
d);
434 D_vec(3*NTrk+3) = da0dx0;
435 D_vec(3*NTrk+4) = da0dy0;
436 D_vec(3*NTrk+5) = 0.;
438 unsigned int ndim = 3*NTrk+3;
440 W_mat.block(0,0,ndim,ndim) =
cov;
441 W_mat.block(3*NTrk+3,3*NTrk+3,3,3) = PV->covariancePosition();
444 double a0xyErrsq = V_err(0,0);
445 if (a0xyErrsq <= 0.)
ATH_MSG_DEBUG(
"a0xyError: negative sqrt a0xyErrsq " << a0xyErrsq);
446 return (a0xyErrsq>0.) ? sqrt(a0xyErrsq) : 0.;
451 if(particleMom.size() == 0)
return -999999.;
452 double cosineTheta =
cosTheta(particleMom,SV,PV);
453 double sinTheta = ((1.-cosineTheta*cosineTheta)>0.) ? sqrt((1.-cosineTheta*cosineTheta)) : 0.;
459 if(particleMom.size() == 0)
return -999999.;
461 double dx = vert.x();
462 double dy = vert.y();
463 double dz = vert.z();
468 double P2 =
P.mag2();
469 double L = Px*
dx+Py*
dy+Pz*dz;
470 double dR2 = vert.mag2();
471 double d = sqrt((P2*dR2-L*L)/P2);
473 unsigned int NTrk = particleMom.size();
475 double da0dx = (P2*
dx-L*Px)/(P2*
d);
476 double da0dy = (P2*
dy-L*Py)/(P2*
d);
477 double da0dz = (P2*dz-L*Pz)/(P2*
d);
478 double da0dx0 = -da0dx;
479 double da0dy0 = -da0dy;
480 double da0dz0 = -da0dz;
486 for(
unsigned int it=0;
it<NTrk;
it++) {
487 D_vec(3*
it+3) = (L*(L*Px-P2*
dx))/(P2*P2*
d);
488 D_vec(3*
it+4) = (L*(L*Py-P2*
dy))/(P2*P2*
d);
489 D_vec(3*
it+5) = (L*(L*Pz-P2*dz))/(P2*P2*
d);
491 D_vec(3*NTrk+3) = da0dx0;
492 D_vec(3*NTrk+4) = da0dy0;
493 D_vec(3*NTrk+5) = da0dz0;
495 unsigned int ndim = 3*NTrk+3;
497 W_mat.block(0,0,ndim,ndim) =
cov;
498 W_mat.block(3*NTrk+3,3*NTrk+3,3,3) = PV->covariancePosition();
501 double a0Errsq = V_err(0,0);
502 if (a0Errsq <= 0.)
ATH_MSG_DEBUG(
"a0Error: negative sqrt a0Errsq " << a0Errsq);
503 return (a0Errsq>0.) ? sqrt(a0Errsq) : 0.;
508 if(particleMom.size() == 0) {
512 TLorentzVector totalMom;
513 unsigned int NTrk = particleMom.size();
514 for(
unsigned int it=0;
it<NTrk;
it++) totalMom += particleMom[
it];
515 TVector3 P3 = totalMom.Vect();
523 double chi2 = (V0Mass -
mass)*(V0Mass -
mass)/(massErr*massErr);
525 Genfun::CumulativeChiSquare myCumulativeChiSquare(
ndf);
527 double achi2prob = 1.-myCumulativeChiSquare(
chi2);
541 Genfun::CumulativeChiSquare myCumulativeChiSquare(
ndf);
543 double chi2prob = 1.-myCumulativeChiSquare(
chi2);
563 if (
matrix.size() == (3*NTrk+3)*(3*NTrk+3+1)/2) {
565 }
else if (
matrix.size() == (5*NTrk+3)*(5*NTrk+3+1)/2) {
574 for (
int i=1;
i<= ndim;
i++) {
575 for (
int j=1; j<=
i; j++){
579 (*mtx).fillSymmetric(
i-1,j-1,
matrix[ij]);
596 for(
int i=0;
i<(3+3*NTrk);
i++){
597 for(
int j=0; j<=
i; j++){