16# if defined(__EXTENSIONS__)
19# define __EXTENSIONS__
23#elif defined(__GNUC__)
24# if defined(_XOPEN_SOURCE)
33#define HEP_SHORT_NAMES
34#include "CLHEP/String/Strings.h"
35#include "CLHEP/Matrix/Vector.h"
36#include "CLHEP/Matrix/SymMatrix.h"
37#include "CLHEP/Matrix/DiagMatrix.h"
38#include "CLHEP/Matrix/Matrix.h"
58#include "CLHEP/Matrix/Matrix.h"
59#include "GaudiKernel/StatusCode.h"
60#include "GaudiKernel/IInterface.h"
61#include "GaudiKernel/Kernel.h"
62#include "GaudiKernel/Service.h"
63#include "GaudiKernel/ISvcLocator.h"
64#include "GaudiKernel/SvcFactory.h"
65#include "GaudiKernel/IDataProviderSvc.h"
66#include "GaudiKernel/Bootstrap.h"
67#include "GaudiKernel/MsgStream.h"
68#include "GaudiKernel/SmartDataPtr.h"
69#include "GaudiKernel/IMessageSvc.h"
73using CLHEP::HepVector;
74using CLHEP::HepSymMatrix;
75using CLHEP::HepDiagMatrix;
76using CLHEP::HepMatrix;
79TTrack::_fitter =
THelixFitter(
"TTrack Default Helix Fitter");
94 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
95 if(scmgn!=StatusCode::SUCCESS) {
96 std::cout<< __FILE__<<
" "<<__LINE__<<
" Unable to open Magnetic field service"<<std::endl;
102 fitter(& TTrack::_fitter);
106 a[1] = fmod(atan2(_charge * (c.
center().y() -
ORIGIN.y()),
113 a[2] = 333.564095/ (c.
radius() * Bz);
120 unsigned n =
_links.length();
121 for (
unsigned i = 0; i < n; i++)
138 _segments(a._segments),
139 _helix(new
Helix(* a._helix)),
142 _name(
"copy of " + a._name),
147 _daughter(a._daughter) {
149 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
150 if(scmgn!=StatusCode::SUCCESS) {
151 std::cout<< __FILE__<<
" "<<__LINE__<<
" Unable to open Magnetic field service"<<std::endl;
170 _helix(new
Helix( a.helix())),
178 if(_helix->
kappa() > 0.)_charge = 1.;
183 _helix(new
Helix(h)),
193 fitter(& TTrack::_fitter);
195 if(_helix->
kappa() > 0.)_charge = 1.;
201 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
202 if(scmgn!=StatusCode::SUCCESS) {
203 std::cout<< __FILE__<<
" "<<__LINE__<<
" Unable to open Magnetic field service"<<std::endl;
213 _name(
"empty track"),
218 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
219 if(scmgn!=StatusCode::SUCCESS) {
220 std::cout<< __FILE__<<
" "<<__LINE__<<
" Unable to open Magnetic field service"<<std::endl;
231 if (msg ==
"") def =
true;
232 std::string pre = pre0;
234 for (
unsigned i = 0; i < pre.length(); i++)
236 if (def || msg.find(
"track") != std::string::npos || msg.find(
"detail") != std::string::npos) {
238 <<
p() <<
"(pt=" <<
pt() <<
")" << std::endl
240 <<
"links=" <<
_links.length()
242 <<
"),chrg=" << _charge
248 if (msg.find(
"helix") != std::string::npos || msg.find(
"detail") != std::string::npos) {
250 <<
"pivot=" << _helix->
pivot()
251 <<
",center=" << _helix->
center() << std::endl
253 <<
"helix=(" << _helix->
a()[0] <<
"," << _helix->
a()[1]<<
","
254 << _helix->
a()[2] <<
"," << _helix->
a()[3] <<
","
255 << _helix->
a()[4] <<
")" << std::endl;
263 unsigned n =
_links.length();
265 std::cout <<
"TTrack::movePivot !!! can't move a pivot"
266 <<
" because of no link";
267 std::cout << std::endl;
277 unsigned innerMost = 0;
278 unsigned innerMostLayer = (* links)[0]->wire()->layerId();
280 for (
unsigned i = 1; i < n; i++) {
281 TMLink * l = (* links)[i];
289 HepPoint3D newPivot = (* links)[innerMost]->positionOnWire();
292 _helix->
pivot(newPivot);
302 unsigned n =
_links.length();
304 for (
unsigned i = 0; i < n; ++i) {
305 if (
_links[i]->pull() > maxSigma) bad.append(
_links[i]);
347 if (
int(_charge) == 0 ) {
348 std::cout <<
"HelCyl gets a straight line !!" << std::endl;
356 double rTrk = fabs( _helix->
radius() );
358 double rPivot = fabs( _helix->
pivot().perp() );
360 double phi0 = _helix->
a()[1];
361 double tanl = _helix->
a()[4];
372 if (
intersection( CenterTrk,_charge * rTrk ,CenterCyl,rCyl,
377 double phiCyl = atan2( _charge * ( CenterTrk.y() - Cross1.y() ),
378 _charge * ( CenterTrk.x() - Cross1.x() ) );
379 phiCyl = ( phiCyl > 0. ) ? phiCyl : phiCyl + 2. *
M_PI;
381 dPhi = phiCyl - phi0;
387 double PhiYobun = 1./ fabs( _helix->
radius() );
388 double zero = 0.00001;
391 if( dPhi > PhiYobun ) dPhi -= 2. *
M_PI;
392 if( -2. *
M_PI -
zero <= dPhi <= ( -2.*
M_PI + PhiYobun ) )
397 if( dPhi < -PhiYobun ) dPhi += 2. *
M_PI;
398 if( 2. *
M_PI +
zero >= dPhi >= ( 2. *
M_PI - PhiYobun ) )
402 if( dPhi < -
M_PI ) dPhi += 2. *
M_PI;
403 if( dPhi >=
M_PI ) dPhi -= 2. *
M_PI;
409 xp.setX( Cross1.x() );
410 xp.setY( Cross1.y() );
411 xp.setZ( _helix->
x(dPhi).z() );
414 if ( xp.z() > zb && xp.z() < zf ) {
427 if ( fabs(tanl) < 0.1 ) {
444 dPhi = _charge * ( _helix->
x(0.).z() - zee )/rTrk/tanl;
449 if ( fabs(dPhi) > 2. *
M_PI ) {
457 xp.setX( _helix->
x(dPhi).x() );
458 xp.setY( _helix->
x(dPhi).y() );
461 double test = xp.perp2() - rhole*rhole ;
789TTrack::dxda(
const TMLink & link,
804 double rho = 333.564095/(kappa * Bz);
805 double tanLambda = a[4];
807 double sinPhi0 =
sin(phi0);
808 double cosPhi0 =
cos(phi0);
809 double sinPhi0dPhi =
sin(phi0 + dPhi);
810 double cosPhi0dPhi =
cos(phi0 + dPhi);
833 c =
HepPoint3D(
w.backwardPosition() - (
v *
w.backwardPosition()) *
v);
839 dxdphi[0] = rho * sinPhi0dPhi;
840 dxdphi[1] = - rho * cosPhi0dPhi;
841 dxdphi[2] = - rho * tanLambda;
844 d2xdphi2[0] = rho * cosPhi0dPhi;
845 d2xdphi2[1] = rho * sinPhi0dPhi;
848 double dxdphi_dot_v = dxdphi[0]*
v.x() + dxdphi[1]*
v.y() + dxdphi[2]*
v.z();
849 double x_dot_v =
x[0]*
v.x() +
x[1]*
v.y() +
x[2]*
v.z();
851 double dfdphi = - (dxdphi[0] - dxdphi_dot_v*
v.x()) * dxdphi[0]
852 - (dxdphi[1] - dxdphi_dot_v*
v.y()) * dxdphi[1]
853 - (dxdphi[2] - dxdphi_dot_v*
v.z()) * dxdphi[2]
854 - (x[0] - c[0] - x_dot_v*
v.x()) * d2xdphi2[0]
855 - (x[1] - c[1] - x_dot_v*
v.y()) * d2xdphi2[1];
861 dxda_phi[0] = cosPhi0;
862 dxda_phi[1] = -(dRho + rho)*sinPhi0 + rho*sinPhi0dPhi;
863 dxda_phi[2] = -(rho/kappa)*( cosPhi0 - cosPhi0dPhi );
868 dyda_phi[0] = sinPhi0;
869 dyda_phi[1] = (dRho + rho)*cosPhi0 - rho*cosPhi0dPhi;
870 dyda_phi[2] = -(rho/kappa)*( sinPhi0 - sinPhi0dPhi );
877 dzda_phi[2] = (rho/kappa)*tanLambda*dPhi;
879 dzda_phi[4] = -rho*dPhi;
883 d2xdphida[1] = rho*cosPhi0dPhi;
884 d2xdphida[2] = -(rho/kappa)*sinPhi0dPhi;
890 d2ydphida[1] = rho*sinPhi0dPhi;
891 d2ydphida[2] = (rho/kappa)*cosPhi0dPhi;
898 d2zdphida[2] = (rho/kappa)*tanLambda;
903 for(
int i = 0; i < 5; i++ ){
904 double d_dot_v =
v.x()*dxda_phi[i]
907 dfda[i] = - (dxda_phi[i] - d_dot_v*
v.x()) * dxdphi[0]
908 - (dyda_phi[i] - d_dot_v*
v.y()) * dxdphi[1]
909 - (dzda_phi[i] - d_dot_v*
v.z()) * dxdphi[2]
910 - (x[0] - c[0] - x_dot_v*
v.x()) * d2xdphida[i]
911 - (x[1] - c[1] - x_dot_v*
v.y()) * d2ydphida[i]
912 - (x[2] - c[2] - x_dot_v*
v.z()) * d2zdphida[i];
913 dphida[i] = - dfda[i] /dfdphi;
917 dxda[0] = cosPhi0 + rho * sinPhi0dPhi * dphida[0];
918 dxda[1] = - (dRho + rho) * sinPhi0 + rho * sinPhi0dPhi * (1. + dphida[1]);
919 dxda[2] = - rho / kappa * (cosPhi0 - cosPhi0dPhi)
920 + rho * sinPhi0dPhi * dphida[2];
921 dxda[3] = rho * sinPhi0dPhi * dphida[3];
922 dxda[4] = rho * sinPhi0dPhi * dphida[4];
924 dyda[0] = sinPhi0 - rho * cosPhi0dPhi * dphida[0];
925 dyda[1] = (dRho + rho) * cosPhi0 - rho * cosPhi0dPhi * (1. + dphida[1]);
926 dyda[2] = - rho / kappa * (sinPhi0 - sinPhi0dPhi)
927 - rho * cosPhi0dPhi * dphida[2];
928 dyda[3] = - rho * cosPhi0dPhi * dphida[3];
929 dyda[4] = - rho * cosPhi0dPhi * dphida[4];
931 dzda[0] = - rho * tanLambda * dphida[0];
932 dzda[1] = - rho * tanLambda * dphida[1];
933 dzda[2] = rho / kappa * tanLambda * dPhi - rho * tanLambda * dphida[2];
934 dzda[3] = 1. - rho * tanLambda * dphida[3];
935 dzda[4] = - rho * dPhi - rho * tanLambda * dphida[4];
944#ifdef TRKRECO_DEBUG_DETAIL
945 std::cout <<
" TTrack::fit2D(r-phi) ..." << std::endl;
950 if (
_links.length() < 4)
return -1;
955 Vector da(5), dxda(5), dyda(5), dzda(5);
956 Vector dDda(5), dchi2da(5);
959 double chi2Old = 1.0e+99;
960 const double convergence = 1.0e-5;
967 while (nTrial < 100) {
968#ifdef TRKRECO_DEBUG_DETAIL
969 if(a[3] != 0. || a[4] != 0.)cerr <<
"Error in 2D functions of TTrack : a = " << a << std::endl;
973 for (
unsigned j = 0; j < 5; ++j) dchi2da[j] = 0.;
983 double dPhi = l->dPhi();
984 const HepPoint3D & onTrack = l->positionOnTrack();
985 const HepPoint3D & onWire = l->positionOnWire();
986#ifdef TRKRECO_DEBUG_DETAIL
987 if(onTrack.z() != 0.)cerr <<
"Error in 2D functions of TTrack : onTrack = " << onTrack << std::endl;
988 if(onWire.z() != 0.)cerr <<
"Error in 2D functions of TTrack : onWire = " << onWire << std::endl;
990 HepPoint3D onTrack2(onTrack.x(),onTrack.y(),0.);
995 if (onWire2.cross(onTrack2).z() < 0.) leftRight =
WireHitLeft;
996 double distance = h.distance(leftRight);
997 double eDistance = h.dDistance(leftRight);
998 double eDistance2 = eDistance * eDistance;
1002 double vmag =
v.mag();
1003 double dDistance = vmag -
distance;
1006 this->dxda2D(* l, dPhi, dxda, dyda, dzda);
1012 v.y() * dyda ) / vmag
1026 std::cout <<
" in fit2D " << onTrack <<
", " << onWire;
1029 dchi2da += (dDistance / eDistance2) * dDda;
1030 d2chi2d2a += vT_times_v(dDda) / eDistance2;
1031 double pChi2 = dDistance * dDistance / eDistance2;
1035 l->update(onTrack2, onWire2, leftRight, pChi2);
1039 double change = chi2Old -
chi2;
1040 if (fabs(change) < convergence)
break;
1042#ifdef TRKRECO_DEBUG_DETAIL
1043 std::cout <<
"chi2Old, chi2=" << chi2Old <<
" "<<
chi2 << std::endl;
1050 for (
unsigned j = 0; j < 5; ++j) dchi2da[j] = 0.;
1060 double dPhi = l->dPhi();
1061 const HepPoint3D & onTrack = l->positionOnTrack();
1062 const HepPoint3D & onWire = l->positionOnWire();
1063 HepPoint3D onTrack2(onTrack.x(),onTrack.y(),0.);
1064 HepPoint3D onWire2(onWire.x(),onWire.y(),0.);
1068 if (onWire2.cross(onTrack2).z() < 0.) leftRight =
WireHitLeft;
1069 double distance = h.distance(leftRight);
1070 double eDistance = h.dDistance(leftRight);
1071 double eDistance2 = eDistance * eDistance;
1075 double vmag =
v.mag();
1076 double dDistance = vmag -
distance;
1079 this->dxda2D(* l, dPhi, dxda, dyda, dzda);
1084 v.y() * dyda ) / vmag
1087 std::cout <<
" in fit2D " << onTrack <<
", " << onWire;
1090 dchi2da += (dDistance / eDistance2) * dDda;
1091 d2chi2d2a += vT_times_v(dDda) / eDistance2;
1092 double pChi2 = dDistance * dDistance / eDistance2;
1096 l->update(onTrack2, onWire2, leftRight, pChi2);
1100#ifdef TRKRECO_DEBUG_DETAIL
1101 std::cout <<
"factor = " << factor << std::endl;
1102 std::cout <<
"chi2 = " <<
chi2 << std::endl;
1104 if(factor < 0.01)
break;
1110 f = dchi2da.sub(1, 3);
1111 e = d2chi2d2a.sub(1, 3);
1133 Ea[0][0] = Ec[0][0];
1134 Ea[0][1] = Ec[0][1];
1135 Ea[0][2] = Ec[0][2];
1136 Ea[1][1] = Ec[1][1];
1137 Ea[1][2] = Ec[1][2];
1138 Ea[2][2] = Ec[2][2];
1146 _ndf =
_links.length() - dim;
1568 double vmag2 =
v.mag2();
1569 double vmag = sqrt(vmag2);
1572 arcZList.removeAll();
1579 double r = _helix->
curv();
1584 double wv =
w.dot(
v);
1586 d2[0] = vmag2*
R[0]*
R[0] + (wv*wv - vmag2*
w.mag2());
1587 d2[1] = vmag2*
R[1]*
R[1] + (wv*wv - vmag2*
w.mag2());
1590 if (d2[0] < 0. && d2[1] < 0.) {
1594 bool ok_inner, ok_outer;
1617 l[0][0] = (- wv + d[0]) / vmag2;
1618 l[1][0] = (- wv - d[0]) / vmag2;
1619 z[0][0] = X.z() + l[0][0]*V.z();
1620 z[1][0] = X.z() + l[1][0]*V.z();
1624 l[0][1] = (- wv + d[1]) / vmag2;
1625 l[1][1] = (- wv - d[1]) / vmag2;
1626 z[0][1] = X.z() + l[0][1]*V.z();
1627 z[1][1] = X.z() + l[1][1]*V.z();
1633 p[0][0] =
x + l[0][0] *
v;
1634 p[1][0] =
x + l[1][0] *
v;
1637 p[0][0] -= drift/
pc0.mag()*
pc0;
1640 p[1][0] -= drift/pc1.mag()*pc1;
1643 p[0][1] =
x + l[0][1] *
v;
1644 p[1][1] =
x + l[1][1] *
v;
1647 p[0][1] += drift/
pc0.mag()*
pc0;
1650 p[1][1] += drift/pc1.mag()*pc1;
1659 ok_xy[0][0] =
false;
1660 ok_xy[1][0] =
false;
1666 ok_xy[0][1] =
false;
1667 ok_xy[1][1] =
false;
1671 ok_xy[0][0] =
false;
1673 ok_xy[1][0] =
false;
1677 ok_xy[0][1] =
false;
1679 ok_xy[1][1] =
false;
1681 if(!ok_inner && ok_outer && (!ok_xy[0][0]) && (!ok_xy[1][0])){
1684 if(ok_inner && !ok_outer && (!ok_xy[0][1]) && (!ok_xy[1][1])){
1689 std::cout <<
"Drift Dist. = " << h.distance(
WireHitLeft) << std::endl;
1690 std::cout <<
"outer ok? = " << ok_outer << std::endl;
1691 std::cout <<
"Z cand = " << z[0][0] <<
", " << z[1][0] << std::endl;
1692 std::cout <<
"inner ok? = " << ok_inner << std::endl;
1693 std::cout <<
"Z cand = " << z[0][1] <<
", " << z[1][1] << std::endl;
1713 if ((!ok_xy[0][0]) && (!ok_xy[1][0]) &&
1714 (!ok_xy[0][1]) && (!ok_xy[1][1])){
1718 double cosdPhi, dPhi;
1723 if(fabs(cosdPhi) < 1.0){
1724 dPhi = acos(cosdPhi);
1725 }
else if(cosdPhi >= 1.0){
1733 arcZ->setY(z[0][0]);
1734 arcZList.append(arcZ);
1739 if(fabs(cosdPhi) < 1.0){
1740 dPhi = acos(cosdPhi);
1741 }
else if(cosdPhi >= 1.0){
1749 arcZ->setY(z[1][0]);
1750 arcZList.append(arcZ);
1755 if(cosdPhi>1.0) cosdPhi = 1.0;
1756 if(cosdPhi<-1.0) cosdPhi = -1.0;
1758 if(fabs(cosdPhi) < 1.0){
1759 dPhi = acos(cosdPhi);
1760 }
else if(cosdPhi >= 1.0){
1768 arcZ->setY(z[0][1]);
1769 arcZList.append(arcZ);
1774 if(cosdPhi>1.0) cosdPhi = 1.0;
1775 if(cosdPhi<-1.0) cosdPhi = -1.0;
1776 if(fabs(cosdPhi) < 1.0){
1777 dPhi = acos(cosdPhi);
1778 }
else if(cosdPhi >= 1.0){
1786 arcZ->setY(z[1][1]);
1787 arcZList.append(arcZ);
1790 if(arcZList.length() == 1 ||
1791 arcZList.length() == 2){
1802 double minZ = 9999999.;
1809 int n1 = arcZList1.length();
1810 int n2 = arcZList2.length();
1811 for(
int i=0;i<
n1;i++){
1812 for(
int j=0;j<
n2;j++){
1813 if(fabs(arcZList1[i]->
y()-arcZList2[j]->
y()) < minZ){
1814 minZ = fabs(arcZList1[i]->
y()-arcZList2[j]->
y());
1823 if(minZ == 9999999.){
1839#if defined(__GNUG__)
1843 if( (*a)->x() < (*b)->x() ){
1845 }
else if( (*a)->x() == (*b)->x() ){
1853TArcOrder(
const void *av,
const void *bv )
1857 if( (*a)->x() < (*b)->x() ){
1859 }
else if( (*a)->x() == (*b)->x() ){
1876 int flag1, flag2, flag3;
1877 double minZ1 = 9999999.;
1878 double minZ2 = 9999999.;
1879 double minZ01 = 9999999.;
1880 double minZ12 = 9999999.;
1889 if((ok1 != 0 && ok2 != 0 && ok3 != 0) ||
1890 (ok1 == 0 && ok2 != 0 && ok3 != 0) ||
1891 (ok1 != 0 && ok2 == 0 && ok3 != 0) ||
1892 (ok1 != 0 && ok2 != 0 && ok3 == 0) ||
1893 (ok1 == 0 && ok2 != 0 && ok3 == 0)){
1899 if(ok1 == 0 && ok2 == 0 && ok3 == 0){
1902 int n1 = arcZList1.length();
1903 int n2 = arcZList2.length();
1904 int n3 = arcZList3.length();
1905 for(
int i=0;i<
n1;i++){
1906 for(
int j=0;j<
n2;j++){
1907 for(
int k=0;k<n3;k++){
1909 arcZ.append(*arcZList1[i]);
1910 arcZ.append(*arcZList2[j]);
1911 arcZ.append(*arcZList3[k]);
1912 arcZ.sort(TArcOrder);
1913 double z01 = fabs(arcZ[0]->
y()-arcZ[1]->
y());
1914 double z12 = fabs(arcZ[1]->
y()-arcZ[2]->
y());
1915 if(z01 <= minZ1 && z12 <= minZ2){
1925 if(minZ1 == 9999999.||
1939 }
else if(ok1 == 0 && ok2 == 0 && ok3 != 0){
1940 int n1 = arcZList1.length();
1941 int n2 = arcZList2.length();
1942 for(
int i=0;i<
n1;i++){
1943 for(
int j=0;j<
n2;j++){
1944 if(fabs(arcZList1[i]->
y()-arcZList2[j]->
y()) < minZ01){
1945 minZ01 = fabs(arcZList1[i]->
y()-arcZList2[j]->
y());
1951 if(minZ01 == 9999999.){
1962 }
else if(ok1 != 0 && ok2 == 0 && ok3 == 0){
1963 int n2 = arcZList2.length();
1964 int n3 = arcZList3.length();
1965 for(
int i=0;i<
n2;i++){
1966 for(
int j=0;j<n3;j++){
1967 if(fabs(arcZList2[i]->
y()-arcZList3[j]->
y()) < minZ12){
1968 minZ12 = fabs(arcZList2[i]->
y()-arcZList3[j]->
y());
1974 if(minZ12 == 9999999.){
1994 HepAListDeleteAll(l1);
1995 HepAListDeleteAll(l2);
2002 HepAListDeleteAll(l1);
2003 HepAListDeleteAll(l2);
2004 HepAListDeleteAll(l3);
2011 if(list.length() == 0)
return -1;
2015 double r = fabs(_helix->
curv());
2016 for(
unsigned i = 0, size = list.length(); i < size; ++i){
2024 double vmag2 =
v.mag2();
2025 double vmag = sqrt(vmag2);
2027 for(
unsigned j = 0; j < 4; ++j)
2028 list[i]->arcZ(tmp,j);
2031 if (vmag == 0.)
continue;
2034 double R[2] = {r + drift, r - drift};
2035 double wv =
w.dot(
v);
2037 d2[0] = vmag2*R[0]*R[0] + (wv*wv - vmag2*
w.mag2());
2038 d2[1] = vmag2*R[1]*R[1] + (wv*wv - vmag2*
w.mag2());
2041 if (d2[0] < 0. && d2[1] < 0.)
continue;
2043 bool ok_inner(
true);
2044 bool ok_outer(
true);
2045 double d[2] = {-1., -1.};
2063 l[0][0] = (- wv + d[0]) / vmag2;
2064 l[1][0] = (- wv - d[0]) / vmag2;
2065 z[0][0] = X.z() + l[0][0]*V.z();
2066 z[1][0] = X.z() + l[1][0]*V.z();
2070 l[0][1] = (- wv + d[1]) / vmag2;
2071 l[1][1] = (- wv - d[1]) / vmag2;
2072 z[0][1] = X.z() + l[0][1]*V.z();
2073 z[1][1] = X.z() + l[1][1]*V.z();
2082 p[0][0] =
x + l[0][0] *
v;
2083 p[1][0] =
x + l[1][0] *
v;
2090 p[0][0] -= drift/
pc0.mag()*
pc0;
2093 p[1][0] -= drift/pc1.mag()*pc1;
2097 p[0][1] =
x + l[0][1] *
v;
2098 p[1][1] =
x + l[1][1] *
v;
2105 p[0][1] += drift/
pc0.mag()*
pc0;
2108 p[1][1] += drift/pc1.mag()*pc1;
2117 ok_xy[0][0] =
false;
2118 ok_xy[1][0] =
false;
2124 ok_xy[0][1] =
false;
2125 ok_xy[1][1] =
false;
2129 ok_xy[0][0] =
false;
2131 ok_xy[1][0] =
false;
2135 ok_xy[0][1] =
false;
2137 ok_xy[1][1] =
false;
2139 if(!ok_inner && ok_outer && (!ok_xy[0][0]) && (!ok_xy[1][0])){
2142 if(ok_inner && !ok_outer && (!ok_xy[0][1]) && (!ok_xy[1][1])){
2163 if ((!ok_xy[0][0]) && (!ok_xy[1][0]) &&
2164 (!ok_xy[0][1]) && (!ok_xy[1][1])){
2167 double cosdPhi, dPhi;
2173 if(fabs(cosdPhi) < 1.0){
2174 dPhi = acos(cosdPhi);
2175 }
else if(cosdPhi >= 1.0){
2180 list[i]->arcZ(
HepPoint3D(r*dPhi, z[0][0], 0.), index);
2187 if(fabs(cosdPhi) < 1.0){
2188 dPhi = acos(cosdPhi);
2189 }
else if(cosdPhi >= 1.0){
2194 list[i]->arcZ(
HepPoint3D(r*dPhi, z[1][0], 0.), index);
2201 if(fabs(cosdPhi) < 1.0){
2202 dPhi = acos(cosdPhi);
2203 }
else if(cosdPhi >= 1.0){
2208 list[i]->arcZ(
HepPoint3D(r*dPhi, z[0][1], 0.), index);
2215 if(fabs(cosdPhi) < 1.0){
2216 dPhi = acos(cosdPhi);
2217 }
else if(cosdPhi >= 1.0){
2222 list[i]->arcZ(
HepPoint3D(r*dPhi, z[1][1], 0.), index);
2228 double gmaxX = -9999. ,gminX = 9999.;
2229 double gmaxY = -9999. ,gminY = 9999.;
2230 FILE *gnuplot, *data;
2232 double dStep = 2.*
M_PI/step;
2233 if((data = fopen(
"dat1",
"w")) != NULL){
2235 for(
int ii=0;ii<step;++ii){
2236 double X = tp[0][0].x() + drift*
cos(dStep*
static_cast<double>(ii));
2237 double Y = tp[0][0].y() + drift*
sin(dStep*
static_cast<double>(ii));
2238 fprintf(data,
"%lf, %lf\n",X,Y);
2239 if(gmaxX < X)gmaxX = X;
2240 if(gminX > X)gminX = X;
2241 if(gmaxY < Y)gmaxY = Y;
2242 if(gminY > Y)gminY = Y;
2247 if((data = fopen(
"dat2",
"w")) != NULL){
2249 for(
int ii=0;ii<step;++ii){
2250 double X = tp[1][0].x() + drift*
cos(dStep*
static_cast<double>(ii));
2251 double Y = tp[1][0].y() + drift*
sin(dStep*
static_cast<double>(ii));
2252 fprintf(data,
"%lf, %lf\n",X,Y);
2253 if(gmaxX < X)gmaxX = X;
2254 if(gminX > X)gminX = X;
2255 if(gmaxY < Y)gmaxY = Y;
2256 if(gminY > Y)gminY = Y;
2261 if((data = fopen(
"dat3",
"w")) != NULL){
2263 for(
int ii=0;ii<step;++ii){
2264 double X = tp[0][1].x() + drift*
cos(dStep*
static_cast<double>(ii));
2265 double Y = tp[0][1].y() + drift*
sin(dStep*
static_cast<double>(ii));
2266 fprintf(data,
"%lf, %lf\n",X,Y);
2267 if(gmaxX < X)gmaxX = X;
2268 if(gminX > X)gminX = X;
2269 if(gmaxY < Y)gmaxY = Y;
2270 if(gminY > Y)gminY = Y;
2275 if((data = fopen(
"dat4",
"w")) != NULL){
2277 for(
int ii=0;ii<step;++ii){
2278 double X = tp[1][1].x() + drift*
cos(dStep*
static_cast<double>(ii));
2279 double Y = tp[1][1].y() + drift*
sin(dStep*
static_cast<double>(ii));
2280 fprintf(data,
"%lf, %lf\n",X,Y);
2281 if(gmaxX < X)gmaxX = X;
2282 if(gminX > X)gminX = X;
2283 if(gmaxY < Y)gmaxY = Y;
2284 if(gminY > Y)gminY = Y;
2291 double tD = tDist.mag();
2292 double vvvM = 1./
v.mag();
2296 if((data = fopen(
"dat5",
"w")) != NULL){
2297 for(
int ii=0;ii<step+1;++ii){
2300 fprintf(data,
"%lf, %lf\n",X,Y);
2301 if(gmaxX < X)gmaxX = X;
2302 if(gminX > X)gminX = X;
2303 if(gmaxY < Y)gmaxY = Y;
2304 if(gminY > Y)gminY = Y;
2308 if((data = fopen(
"dat6",
"w")) != NULL){
2311 fprintf(data,
"%lf, %lf\n",X,Y);
2312 if(gmaxX < X)gmaxX = X;
2313 if(gminX > X)gminX = X;
2314 if(gmaxY < Y)gmaxY = Y;
2315 if(gminY > Y)gminY = Y;
2318 if((data = fopen(
"dat7",
"w")) != NULL){
2321 fprintf(data,
"%lf, %lf\n",X,Y);
2322 if(gmaxX < X)gmaxX = X;
2323 if(gminX > X)gminX = X;
2324 if(gmaxY < Y)gmaxY = Y;
2325 if(gminY > Y)gminY = Y;
2329 dStep = 2.*
M_PI/step;
2330 if((data = fopen(
"dat8",
"w")) != NULL){
2331 for(
int ii=0;ii<step;++ii){
2332 double X =
center.
x() + r*
cos(dStep*
static_cast<double>(ii));
2333 double Y =
center.
y() + r*
sin(dStep*
static_cast<double>(ii));
2334 fprintf(data,
"%lf, %lf\n",X,Y);
2338 if((data = fopen(
"dat9",
"w")) != NULL){
2340 double X =
p[0][0].x();
2341 double Y =
p[0][0].y();
2342 fprintf(data,
"%lf, %lf\n",X,Y);
2346 if((data = fopen(
"dat10",
"w")) != NULL){
2348 double X =
p[1][0].x();
2349 double Y =
p[1][0].y();
2350 fprintf(data,
"%lf, %lf\n",X,Y);
2354 if((data = fopen(
"dat11",
"w")) != NULL){
2356 double X =
p[0][1].x();
2357 double Y =
p[0][1].y();
2358 fprintf(data,
"%lf, %lf\n",X,Y);
2362 if((data = fopen(
"dat12",
"w")) != NULL){
2364 double X =
p[1][1].x();
2365 double Y =
p[1][1].y();
2366 fprintf(data,
"%lf, %lf\n",X,Y);
2370 std::cout <<
"Drift Distance = " << drift <<
", xy1cm -> z" << V.z()/
v.mag() <<
"cm, xyDist(cm) = " << tD << std::endl;
2371 if(tX.z()<0.)std::cout <<
"ERROR : F < B" << std::endl;
2372 if((gnuplot = popen(
"gnuplot",
"w")) != NULL){
2373 fprintf(gnuplot,
"set size 0.721,1.0 \n");
2374 fprintf(gnuplot,
"set xrange [%f:%f] \n",gminX,gmaxX);
2375 fprintf(gnuplot,
"set yrange [%f:%f] \n",gminY,gmaxY);
2376 fprintf(gnuplot,
"plot \"dat1\" with line, \"dat2\" with line, \"dat3\" with line, \"dat4\" with line, \"dat5\" with line, \"dat6\", \"dat7\", \"dat8\" with line, \"dat9\", \"dat10\", \"dat11\", \"dat12\" \n");
2394 double kappa = a[2];
2406 double vCrs = v0.x() * v1.y() - v0.y() * v1.x();
2407 double vDot = v0.x() * v1.x() + v0.y() * v1.y();
2408 double dPhi = atan2(vCrs, vDot);
2431TTrack::dxda2D(
const TMLink & link,
2442 double kappa = a[2];
2446 double rho = 333.564095/(kappa * Bz);
2450 double sinPhi0 =
sin(phi0);
2451 double cosPhi0 =
cos(phi0);
2452 double sinPhi0dPhi =
sin(phi0 + dPhi);
2453 double cosPhi0dPhi =
cos(phi0 + dPhi);
2457 double dmag2 = d.mag2();
2459 dphida[0] = (sinPhi0 * d.x() - cosPhi0 * d.y()) / dmag2;
2460 dphida[1] = (dRho + rho) * (cosPhi0 * d.x() + sinPhi0 * d.y())
2462 dphida[2] = (- rho / kappa) * (sinPhi0 * d.x() - cosPhi0 * d.y())
2467 dxda[0] = cosPhi0 + rho * sinPhi0dPhi * dphida[0];
2468 dxda[1] = - (dRho + rho) * sinPhi0 + rho * sinPhi0dPhi * (1. + dphida[1]);
2469 dxda[2] = - rho / kappa * (cosPhi0 - cosPhi0dPhi)
2470 + rho * sinPhi0dPhi * dphida[2];
2471 dxda[3] = rho * sinPhi0dPhi * dphida[3];
2472 dxda[4] = rho * sinPhi0dPhi * dphida[4];
2474 dyda[0] = sinPhi0 - rho * cosPhi0dPhi * dphida[0];
2475 dyda[1] = (dRho + rho) * cosPhi0 - rho * cosPhi0dPhi * (1. + dphida[1]);
2476 dyda[2] = - rho / kappa * (sinPhi0 - sinPhi0dPhi)
2477 - rho * cosPhi0dPhi * dphida[2];
2478 dyda[3] = - rho * cosPhi0dPhi * dphida[3];
2479 dyda[4] = - rho * cosPhi0dPhi * dphida[4];
2485 dzda[4] = - rho * dPhi;
2500 double r = fabs(_helix->
curv());
2502 for(
unsigned i = 0, size = svdList.length(); i < size; ++i){
2506 if(fabs(cosdPhi) < 1.0){
2507 dPhi = acos(cosdPhi);
2508 }
else if(cosdPhi >= 1.0){
2514 svdList[i]->arcZ(tmp);
2520#if defined(__GNUG__)
2523 if ((* a)->pt() < (* b)->pt())
return 1;
2525 ((* a)->pt() == (* b)->pt())
return 0;
2533 if ((* a)->pt() < (* b)->pt())
return 1;
2535 ((* a)->pt() == (* b)->pt())
return 0;
2543#ifdef TRKRECO_DEBUG_DETAIL
2544 std::cout <<
" TTrack::fit2D(r-phi) ..." << std::endl;
2555 double chi2Old = 1.0e+99;
2558 Vector da(5), dxda(3), dyda(3);
2560 const double convergence = 1.0e-5;
2563 double factor = 1.0;
2564 unsigned usedWireNumber = 0;
2567 while(nTrial < 100){
2570 for (
unsigned j=0;j<3;++j) dchi2da[j] = 0.;
2577 if(l->
fit2D() == 0)
continue;
2582 double dPhi = l->
dPhi();
2585 HepPoint3D onTrack2(onTrack.x(),onTrack.y(),0.);
2586 HepPoint3D onWire2(onWire.x(),onWire.y(),0.);
2590 if (onWire2.cross(onTrack2).z() < 0.) leftRight =
WireHitLeft;
2592 double eDistance = h.
dDrift(leftRight);
2593 double eDistance2 = eDistance * eDistance;
2594 if(eDistance == 0.){
2595 std::cout <<
"Error(?) : Drift Distance Error = 0 in fit2D of TrkReco." << std::endl;
2601 double vmag =
v.mag();
2602 double dDistance = vmag -
distance;
2605 if(this->dxda2D(*l, dPhi, dxda, dyda) != 0)
continue;
2610 ? (
v.x()*dxda+
v.y()*dyda)/vmag
2613 std::cout <<
" in fit2D " << onTrack <<
", " << onWire;
2617 dchi2da += (dDistance/eDistance2)*dDda;
2618 d2chi2d2a += vT_times_v(dDda)/eDistance2;
2619 double pChi2 = dDistance*dDistance/eDistance2;
2623 l->
update(onTrack2, onWire2, leftRight, pChi2);
2627 double kappa = _helix->
a()[2];
2628 double phi0 = _helix->
a()[1];
2634 double vCrs = v0.x() * v1.y() - v0.y() * v1.x();
2635 double vDot = v0.x() * v1.x() + v0.y() * v1.y();
2636 double dPhi = atan2(vCrs, vDot);
2637 HepPoint3D onTrack(_helix->
x(dPhi).x(),_helix->
x(dPhi).y(),0.);
2639 double eDistance = ipError;
2640 double eDistance2 = eDistance * eDistance;
2643 double vmag =
v.mag();
2644 double dDistance = vmag -
distance;
2646 if(this->dxda2D(dPhi, dxda, dyda) != 0)
goto ipOff;
2649 ? (
v.x()*dxda+
v.y()*dyda)/vmag
2654 dchi2da += (dDistance/eDistance2)*dDda;
2655 d2chi2d2a += vT_times_v(dDda)/eDistance2;
2656 double pChi2 = dDistance*dDistance/eDistance2;
2662 if(usedWireNumber < 4){
2668 double change = chi2Old -
chi2;
2669 if(fabs(change) < convergence)
break;
2671#ifdef TRKRECO_DEBUG_DETAIL
2672 std::cout <<
"chi2Old, chi2=" << chi2Old <<
" "<<
chi2 << std::endl;
2679 for (
unsigned j=0;j<3;++j) dchi2da[j] = 0.;
2686 if(l->
fit2D() == 0)
continue;
2691 double dPhi = l->
dPhi();
2694 HepPoint3D onTrack2(onTrack.x(),onTrack.y(),0.);
2695 HepPoint3D onWire2(onWire.x(),onWire.y(),0.);
2699 if (onWire2.cross(onTrack2).z() < 0.) leftRight =
WireHitLeft;
2701 double eDistance = h.
dDrift(leftRight);
2702 double eDistance2 = eDistance * eDistance;
2706 double vmag =
v.mag();
2707 double dDistance = vmag -
distance;
2710 if(this->dxda2D(*l, dPhi, dxda, dyda) != 0)
continue;
2714 ? (
v.x()*dxda +
v.y()*dyda)/vmag
2717 std::cout <<
" in fit2D " << onTrack <<
", " << onWire;
2721 dchi2da += (dDistance/eDistance2)*dDda;
2722 d2chi2d2a += vT_times_v(dDda)/eDistance2;
2723 double pChi2 = dDistance*dDistance/eDistance2;
2727 l->
update(onTrack2, onWire2, leftRight, pChi2);
2731 double kappa = _helix->
a()[2];
2732 double phi0 = _helix->
a()[1];
2738 double vCrs = v0.x() * v1.y() - v0.y() * v1.x();
2739 double vDot = v0.x() * v1.x() + v0.y() * v1.y();
2740 double dPhi = atan2(vCrs, vDot);
2741 HepPoint3D onTrack(_helix->
x(dPhi).x(),_helix->
x(dPhi).y(),0.);
2743 double eDistance = ipError;
2744 double eDistance2 = eDistance * eDistance;
2747 double vmag =
v.mag();
2748 double dDistance = vmag -
distance;
2750 if(this->dxda2D(dPhi, dxda, dyda) != 0)
goto ipOff2;
2753 ? (
v.x()*dxda+
v.y()*dyda)/vmag
2758 dchi2da += (dDistance/eDistance2)*dDda;
2759 d2chi2d2a += vT_times_v(dDda)/eDistance2;
2760 double pChi2 = dDistance*dDistance/eDistance2;
2766 if(usedWireNumber < 4){
2772#ifdef TRKRECO_DEBUG_DETAIL
2773 std::cout <<
"factor = " << factor << std::endl;
2774 std::cout <<
"chi2 = " <<
chi2 << std::endl;
2776 if(factor < 0.01)
break;
2782 f = solve(d2chi2d2a, dchi2da);
2802 Ea[0][0] = Ec[0][0];
2803 Ea[0][1] = Ec[0][1];
2804 Ea[0][2] = Ec[0][2];
2805 Ea[1][1] = Ec[1][1];
2806 Ea[1][2] = Ec[1][2];
2807 Ea[2][2] = Ec[2][2];
2817 _ndf = usedWireNumber-dim;
2824 double gmaxX = -9999. ,gminX = 9999.;
2825 double gmaxY = -9999. ,gminY = 9999.;
2826 FILE *gnuplot, *data;
2828 double dStep = 2.*
M_PI/step;
2829 for(
int i=0,size =
_links.length();i<size;++i){
2831 double drift = l->
hit()->distance(0);
2832 char name[100] =
"dat";
2833 char counter[10] =
"";
2835 strcat(
name,counter);
2836 if((data = fopen(
name,
"w")) != NULL){
2837 for(
int ii=0;ii<step;++ii){
2838 double X = l->
wire()->
xyPosition().x() + drift*
cos(dStep*
static_cast<double>(ii));
2839 double Y = l->
wire()->
xyPosition().y() + drift*
sin(dStep*
static_cast<double>(ii));
2840 fprintf(data,
"%lf, %lf\n",X,Y);
2841 if(gmaxX < X)gmaxX = X;
2842 if(gminX > X)gminX = X;
2843 if(gmaxY < Y)gmaxY = Y;
2844 if(gminY > Y)gminY = Y;
2850 dStep = 2.*
M_PI/step;
2851 if((data = fopen(
"datc",
"w")) != NULL){
2852 for(
int ii=0;ii<step;++ii){
2853 double X = _helix->
center().x() + _helix->
radius()*
cos(dStep*
static_cast<double>(ii));
2854 double Y = _helix->
center().y() + _helix->
radius()*
sin(dStep*
static_cast<double>(ii));
2855 fprintf(data,
"%lf, %lf\n",X,Y);
2859 if((gnuplot = popen(
"gnuplot",
"w")) != NULL){
2860 fprintf(gnuplot,
"set size 0.721,1.0 \n");
2861 fprintf(gnuplot,
"set xrange [%f:%f] \n",gminX,gmaxX);
2862 fprintf(gnuplot,
"set yrange [%f:%f] \n",gminY,gmaxY);
2863 if(
_links.length() == 4){
2864 fprintf(gnuplot,
"plot \"datc\" with line, \"dat00\" with line, \"dat01\" with line, \"dat02\" with line, \"dat03\" with line \n");
2865 }
else if(
_links.length() == 5){
2866 fprintf(gnuplot,
"plot \"datc\" with line, \"dat00\" with line, \"dat01\" with line, \"dat02\" with line, \"dat03\" with line, \"dat04\" with line \n");
2867 }
else if(
_links.length() == 6){
2868 fprintf(gnuplot,
"plot \"datc\" with line, \"dat00\" with line, \"dat01\" with line, \"dat02\" with line, \"dat03\" with line, \"dat04\" with line, \"dat05\" with line \n");
2869 }
else if(
_links.length() == 7){
2870 fprintf(gnuplot,
"plot \"datc\" with line, \"dat00\" with line, \"dat01\" with line, \"dat02\" with line, \"dat03\" with line, \"dat04\" with line, \"dat05\" with line, \"dat06\" with line \n");
2871 }
else if(
_links.length() == 8){
2872 fprintf(gnuplot,
"plot \"datc\" with line, \"dat00\" with line, \"dat01\" with line, \"dat02\" with line, \"dat03\" with line, \"dat04\" with line, \"dat05\" with line, \"dat06\" with line, \"dat07\" with line \n");
2873 }
else if(
_links.length() == 9){
2874 fprintf(gnuplot,
"plot \"datc\" with line, \"dat00\" with line, \"dat01\" with line, \"dat02\" with line, \"dat03\" with line, \"dat04\" with line, \"dat05\" with line, \"dat06\" with line, \"dat07\" with line, \"dat08\" with line \n");
2875 }
else if(
_links.length() == 10){
2876 fprintf(gnuplot,
"plot \"datc\" with line, \"dat00\" with line, \"dat01\" with line, \"dat02\" with line, \"dat03\" with line, \"dat04\" with line, \"dat05\" with line, \"dat06\" with line, \"dat07\" with line, \"dat08\" with line, \"dat09\" with line \n");
2877 }
else if(
_links.length() >= 11){
2878 fprintf(gnuplot,
"plot \"datc\" with line, \"dat00\" with line, \"dat01\" with line, \"dat02\" with line, \"dat03\" with line, \"dat04\" with line, \"dat05\" with line, \"dat06\" with line, \"dat07\" with line, \"dat08\" with line, \"dat09\" with line, \"dat10\" with line \n");
2894 double kappa = _helix->
a()[2];
2895 double phi0 = _helix->
a()[1];
2902 double vCrs = v0.x() * v1.y() - v0.y() * v1.x();
2903 double vDot = v0.x() * v1.x() + v0.y() * v1.y();
2904 double dPhi = atan2(vCrs, vDot);
2906 xt = _helix->
x(dPhi);
2916TTrack::dxda2D(
const TMLink & link,
2922 double kappa = (_helix->
a())[2];
2924 std::cout <<
"Error(?) : kappa == 0 in dxda2D of TrkReco." << std::endl;
2928 double dRho = (_helix->
a())[0];
2929 double phi0 = (_helix->
a())[1];
2933 double rho = 333.564095/(kappa * Bz);
2935 double sinPhi0 =
sin(phi0);
2936 double cosPhi0 =
cos(phi0);
2937 double sinPhi0dPhi =
sin(phi0 + dPhi);
2938 double cosPhi0dPhi =
cos(phi0 + dPhi);
2943 double dmag2 = d.mag2();
2946 std::cout <<
"Error(?) : Distance(center-xyPosition) == 0 in dxda2D of TrkReco." << std::endl;
2950 dphida[0] = (sinPhi0*d.x()-cosPhi0*d.y())/dmag2;
2951 dphida[1] = (dRho+rho)*(cosPhi0*d.x()+sinPhi0 * d.y())/dmag2 - 1.;
2952 dphida[2] = (-rho/kappa)*(sinPhi0*d.x()-cosPhi0*d.y())/dmag2;
2954 dxda[0] = cosPhi0+rho*sinPhi0dPhi*dphida[0];
2955 dxda[1] = -(dRho+rho)*sinPhi0+rho*sinPhi0dPhi*(1.+dphida[1]);
2956 dxda[2] = -rho/kappa*(cosPhi0-cosPhi0dPhi)+rho*sinPhi0dPhi*dphida[2];
2958 dyda[0] = sinPhi0-rho*cosPhi0dPhi*dphida[0];
2959 dyda[1] = (dRho+rho)*cosPhi0-rho*cosPhi0dPhi*(1.+dphida[1]);
2960 dyda[2] = -rho/kappa*(sinPhi0-sinPhi0dPhi)-rho*cosPhi0dPhi*dphida[2];
2966TTrack::dxda2D(
double dPhi,
2971 double kappa = (_helix->
a())[2];
2973 std::cout <<
"Error(?) : kappa == 0 in dxda2D of TrkReco." << std::endl;
2976 double dRho = (_helix->
a())[0];
2977 double phi0 = (_helix->
a())[1];
2981 double rho = 333.564095/(kappa * Bz);
2983 double sinPhi0 =
sin(phi0);
2984 double cosPhi0 =
cos(phi0);
2985 double sinPhi0dPhi =
sin(phi0 + dPhi);
2986 double cosPhi0dPhi =
cos(phi0 + dPhi);
2991 double dmag2 = d.mag2();
2994 std::cout <<
"Error(?) : Distance(center-xyPosition) == 0 in dxda2D of TrkReco." << std::endl;
2998 dphida[0] = (sinPhi0*d.x()-cosPhi0*d.y())/dmag2;
2999 dphida[1] = (dRho+rho)*(cosPhi0*d.x()+sinPhi0 * d.y())/dmag2 - 1.;
3000 dphida[2] = (-rho/kappa)*(sinPhi0*d.x()-cosPhi0*d.y())/dmag2;
3002 dxda[0] = cosPhi0+rho*sinPhi0dPhi*dphida[0];
3003 dxda[1] = -(dRho+rho)*sinPhi0+rho*sinPhi0dPhi*(1.+dphida[1]);
3004 dxda[2] = -rho/kappa*(cosPhi0-cosPhi0dPhi)+rho*sinPhi0dPhi*dphida[2];
3006 dyda[0] = sinPhi0-rho*cosPhi0dPhi*dphida[0];
3007 dyda[1] = (dRho+rho)*cosPhi0-rho*cosPhi0dPhi*(1.+dphida[1]);
3008 dyda[2] = -rho/kappa*(sinPhi0-sinPhi0dPhi)-rho*cosPhi0dPhi*dphida[2];
3015TTrack::defineType(
void)
const {
3017 if (
pt() < 0.2) highPt =
false;
3019 if (fabs(
impact()) > 8.3) fromIP =
false;
3022 else if (fromIP && (! highPt))
return _type =
TrackTypeCurl;
3033 return std::string(
"undefined");
3035 return std::string(
"normal");
3037 return std::string(
"curl ");
3039 return std::string(
"circle");
3041 return std::string(
"cosmic");
3043 return std::string(
"unknown ");
3047#define t_dot(a,b) (a[0]*b[0]+a[1]*b[1]+a[2]*b[2])
3048#define t_dot2(a,b) (a[0]*b[0]+a[1]*b[1])
3049#define t_print(a,b) std::cout << b << " = " << a[0] << " " << a[1] << " " << a[2] << std::endl;
3062 double wp[3];
w.xyPosition(wp);
3063 double wb[3];
w.backwardPosition(wb);
3065 v[0] =
w.direction().x();
3066 v[1] =
w.direction().y();
3067 v[2] =
w.direction().z();
3069 if (doSagCorrection) {
3072 HepPoint3D wireBackwardPosition(wb[0], wb[1], wb[2]);
3075 wireBackwardPosition,
3083 wb[0] = wireBackwardPosition.x();
3084 wb[1] = wireBackwardPosition.y();
3085 wb[2] = wireBackwardPosition.z();
3089 double xt[3]; _helix->
x(0., xt);
3090 double x0 = - xc.x();
3091 double y0 = - xc.y();
3092 double x1 = wp[0] + x0;
3093 double y1 = wp[1] + y0;
3096 double dPhi = atan2(x0 * y1 - y0 * x1, x0 * x1 + y0 * y1);
3098 double kappa = _helix->
kappa();
3099 double phi0 = _helix->
phi0();
3111 double firstdfdphi = 0.;
3112 static bool first =
true;
3126 Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
3127 if(m_pmgnIMF==NULL) {
3128 std::cout<< __FILE__<<
" "<<__LINE__<<
" Unable to open Magnetic field service"<<std::endl;
3131 double rho = 333.564095/(kappa * Bz);
3133 double tanLambda = _helix->
tanl();
3137 const double convergence = 1.0e-5;
3139 unsigned nTrial = 0;
3140 while (nTrial < 100) {
3147 l =
v[0] * t_x[0] +
v[1] * t_x[1] +
v[2] * t_x[2]
3148 -
v[0] * wb[0] -
v[1] * wb[1] -
v[2] * wb[2];
3150 double rcosPhi = rho *
cos(phi0 + dPhi);
3151 double rsinPhi = rho *
sin(phi0 + dPhi);
3152 t_dXdPhi[0] = rsinPhi;
3153 t_dXdPhi[1] = - rcosPhi;
3154 t_dXdPhi[2] = - rho * tanLambda;
3157 double t_d2Xd2Phi[2];
3158 t_d2Xd2Phi[0] = rcosPhi;
3159 t_d2Xd2Phi[1] = rsinPhi;
3163 n[0] = t_x[0] - wb[0];
3164 n[1] = t_x[1] - wb[1];
3165 n[2] = t_x[2] - wb[2];
3168 a[0] = n[0] - l *
v[0];
3169 a[1] = n[1] - l *
v[1];
3170 a[2] = n[2] - l *
v[2];
3171 double dfdphi = a[0] * t_dXdPhi[0]
3172 + a[1] * t_dXdPhi[1]
3173 + a[2] * t_dXdPhi[2];
3178 firstdfdphi = dfdphi;
3183 std::cout <<
"TTrack::approach ... " <<
w.name() <<
" "
3184 <<
"dfdphi(0)=" << firstdfdphi
3185 <<
",(" << nTrial <<
")=" << dfdphi << endl;
3190 if (fabs(dfdphi) < convergence)
3193 double dv =
v[0] * t_dXdPhi[0]
3194 +
v[1] * t_dXdPhi[1]
3195 +
v[2] * t_dXdPhi[2];
3196 double t0 = t_dXdPhi[0] * t_dXdPhi[0]
3197 + t_dXdPhi[1] * t_dXdPhi[1]
3198 + t_dXdPhi[2] * t_dXdPhi[2];
3199 double d2fd2phi = t0 - dv * dv
3200 + a[0] * t_d2Xd2Phi[0]
3201 + a[1] * t_d2Xd2Phi[1];
3204 dPhi -= dfdphi / d2fd2phi;
3385 double wwmag2 = ww.mag2();
3386 double wwmag = sqrt(wwmag2);
3391#ifdef TRKRECO_DEBUG_DETAIL
3392 std::cout<<
"old lr "<<lr<<endl;
3393 std::cout<<
"old X "<<X<<endl;
3394 std::cout<<
"link.leftRight "<<link.
leftRight()<<endl;
3406#ifdef TRKRECO_DEBUG_DETAIL
3407 std::cout<<
"charge "<<_charge<<
" Bz "<<Bz<<endl;
3409 if (_charge*Bz > 0){
3434 double vmag2 =
v.mag2();
3435 double vmag = sqrt(vmag2);
3437 double r = _helix->
curv();
3438 double wv =
w.dot(
v);
3441 double d2 = wv * wv - vmag2 * (
w.mag2() - r * r);
3442#ifdef TRKRECO_DEBUG_DETAIL
3443 std::cout<<
"lr "<<lr<<endl;
3446 std::cout<<
"X "<<X<<endl;
3447 std::cout<<
"center "<<
center<<endl;
3448 std::cout<<
"xx "<<xx<<endl;
3449 std::cout<<
"ww "<<ww<<endl;
3450 std::cout<<
"TTrack::wire direction:"<<h.
wire()->
direction()<<endl;
3451 std::cout<<
"x "<<
x<<endl;
3452 std::cout<<
"w "<<
w<<endl;
3453 std::cout<<
"sz,Track::vmag:"<<vmag<<
", helix_r:"<<r<<
", wv:"<<wv<<
", d:"<<sqrt(d2)<<endl;
3462 std::cout <<
"TTrack !!! stereo: 0. > d2 = " << d2 <<
" "
3467 double d = sqrt(d2);
3471 l[0] = (- wv + d) / vmag2;
3472 l[1] = (- wv - d) / vmag2;
3479 z[0] = X.z() + l[0] * V.z();
3480 z[1] = X.z() + l[1] * V.z();
3481#ifdef TRKRECO_DEBUG_DETAIL
3482 std::cout<<
"X.z():"<<X.z()<<endl;
3483 std::cout<<
"szPosition::z(0) "<<z[0]<<
" z(1)"<<z[1]<<
" leftRight "<<link.
leftRight()<<endl;
3485 std::cout <<
" l0, l1 = " << l[0] <<
", " << l[1] << std::endl;
3486 std::cout <<
" z0, z1 = " << z[0] <<
", " << z[1] << std::endl;
3524 if ((! ok[0]) && (! ok[1])) {
3532 p[0] =
x + l[0] *
v;
3533 p[1] =
x + l[1] *
v;
3548 if (ok[1]) best = 1;
3553 if(fabs(cosdPhi)<=1.0) {
3554 dPhi = acos(cosdPhi);
3555 }
else if (cosdPhi>1.0) {
3574 unsigned n =
links.length();
3581 float minDist =
links[0]->drift();
3582#ifdef TRKRECO_DEBUG_DETAIL
3583 std::cout<<
"minDist szPosition TTrack:"<<minDist<<endl;
3585 for (
unsigned i = 1; i < n; i++) {
3586 if (
links[i]->hit()->drift() < minDist) {
3587 minDist =
links[i]->drift();
3588#ifdef TRKRECO_DEBUG_DETAIL
3589 std::cout<<
"minDist szPosition TTrack:"<<minDist<<endl;
3600#ifdef TRKRECO_DEBUG_DETAIL
3601 std::cout<<
"err of szPosition TTrack:"<<err<<endl;
3616 if (fabs(cosdPhi) <= 1.0) {
3617 dPhi = acos(cosdPhi);
3619 else if (cosdPhi > 1.0) {
3627 sz.setX(_helix->
curv() * dPhi);
3638 unsigned n =
_links.length();
3639 for (
unsigned i = 0; i < n; i++) {
3644 std::cout <<
"TTrack::assign !!! hit(" << h->
wire()->
name();
3645 std::cout <<
") already assigned" << std::endl;
3658 Hep3Vector p(
t.pivot[0],
t.pivot[1],
t.pivot[2]);
3659 HepSymMatrix er(5,0);
3665 er(1,1) =
t.error[0];
3666 er(2,1) =
t.error[1];
3667 er(2,2) =
t.error[2];
3668 er(3,1) =
t.error[3];
3669 er(3,2) =
t.error[4];
3670 er(3,3) =
t.error[5];
3671 er(4,1) =
t.error[6];
3672 er(4,2) =
t.error[7];
3673 er(4,3) =
t.error[8];
3674 er(4,4) =
t.error[9];
3675 er(5,1) =
t.error[10];
3676 er(5,2) =
t.error[11];
3677 er(5,3) =
t.error[12];
3678 er(5,4) =
t.error[13];
3679 er(5,5) =
t.error[14];
3680 return Helix(p, a, er);
3686 Hep3Vector p(
t.pivot[0],
t.pivot[1],
t.pivot[2]);
3687 HepSymMatrix er(5,0);
3693 er(1,1) =
t.error[0];
3694 er(2,1) =
t.error[1];
3695 er(2,2) =
t.error[2];
3696 er(3,1) =
t.error[3];
3697 er(3,2) =
t.error[4];
3698 er(3,3) =
t.error[5];
3699 er(4,1) =
t.error[6];
3700 er(4,2) =
t.error[7];
3701 er(4,3) =
t.error[8];
3702 er(4,4) =
t.error[9];
3703 er(5,1) =
t.error[10];
3704 er(5,2) =
t.error[11];
3705 er(5,3) =
t.error[12];
3706 er(5,4) =
t.error[13];
3707 er(5,5) =
t.error[14];
3708 return Helix(p, a, er);
3714 Hep3Vector p(
t.pivot_x,
t.pivot_y,
t.pivot_z);
3715 HepSymMatrix er(5,0);
3721 er(1,1) =
t.error[0];
3722 er(2,1) =
t.error[1];
3723 er(2,2) =
t.error[2];
3724 er(3,1) =
t.error[3];
3725 er(3,2) =
t.error[4];
3726 er(3,3) =
t.error[5];
3727 er(4,1) =
t.error[6];
3728 er(4,2) =
t.error[7];
3729 er(4,3) =
t.error[8];
3730 er(4,4) =
t.error[9];
3731 er(5,1) =
t.error[10];
3732 er(5,2) =
t.error[11];
3733 er(5,3) =
t.error[12];
3734 er(5,4) =
t.error[13];
3735 er(5,5) =
t.error[14];
3736 return Helix(p, a, er);
3745 float chrg = hIp.
a()[2] / fabs(hIp.
a()[2]);
3747 if (chrg > 0.)
s =
"+";
3751 x[0] = fabs(hIp.
a()[0]);
3753 x[2] = 1. / fabs(hIp.
a()[2]);
3754 x[3] = (1. / fabs(hIp.
a()[2])) * hIp.
a()[4];
3756 if ((
x[0] < 2.) && (fabs(
x[1]) < 4.))
s +=
"i ";
3759 for (
unsigned i = 0; i < 4; i++) {
3762 if (
x[i] < 0.)
s +=
"-";
3765 int y = int(fabs(
x[i]));
3766 s += itostring(
y) +
".";
3767 float z = fabs(
x[i]);
3768 for (
unsigned j = 0; j < 3; j++) {
3819 if (
f ==
"")
f =
"?";
3829 if (k ==
"") k =
"?";
3836 if (
b ==
"")
b =
"ok";
3843 if (
s ==
"")
s =
"?";
3851 std::string p =
" ";
3852 return f + p + k + p +
b + p +
s + p + itostring(m) + p + itostring(d);
3858 unsigned n = cores.length();
3860 unsigned nA = n - nS;
3883 s +=
"a" + itostring(
int(nA));
3884 s +=
" s" + itostring(
int(nS));
3885 s +=
" n" + itostring(
int(n));
3889 if (
x < 0.)
s +=
" -";
3892 int y = int(fabs(
x));
3893 s += itostring(
y) +
".";
3895 for (
unsigned j = 0; j < 1; j++) {
3909 for (
unsigned i = 0; i < 11; i++) {
3910 nh += itostring(n[i]);
3911 if (i % 2) nh +=
"-";
3912 else if (i < 10) nh +=
",";
3924 bool positive =
true;
3925 if (e[0][0] <= 0.) positive =
false;
3926 else if (e2.determinant() <= 0.) positive =
false;
3927 else if (e3.determinant() <= 0.) positive =
false;
3928 else if (e4.determinant() <= 0.) positive =
false;
3929 else if (e.determinant() <= 0.) positive =
false;
3936 for (
unsigned i = 0; i < 5; i++)
3940 for (
unsigned i = 0; i < 5; i++)
3941 for (
unsigned j = 0; j <= i; j++)
3942 if (isnan(Ea[i][j]))
3950 if (
t.idhep == 11)
charge = -1;
3951 else if (
t.idhep == -11)
charge = 1;
3952 else if (
t.idhep == 13)
charge = -1;
3953 else if (
t.idhep == -13)
charge = 1;
3954 else if (
t.idhep == 211)
charge = 1;
3955 else if (
t.idhep == -211)
charge = -1;
3956 else if (
t.idhep == 321)
charge = 1;
3957 else if (
t.idhep == -321)
charge = -1;
3958 else if (
t.idhep == 2212)
charge = 1;
3959 else if (
t.idhep == -2212)
charge = -1;
3961 std::cout <<
"Track2Helix(gen_hepevt) !!! charge of id=";
3962 std::cout <<
t.idhep <<
" is unknown" << std::endl;
3965 Hep3Vector mom(
t.P[0],
t.P[1],
t.P[2]);
3966 Hep3Vector pos(
t.V[0] / 10.,
t.V[1] / 10.,
t.V[2] / 10.);
HepGeom::Vector3D< double > HepVector3D
double sin(const BesAngle a)
double cos(const BesAngle a)
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per saves r n generator level $ !Flag for chat level in !Latex Output unit
**********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
CLHEP::HepSymMatrix SymMatrix
int intersection(const HepPoint3D &c1, double r1, const HepPoint3D &c2, double r2, double eps, HepPoint3D &x1, HepPoint3D &x2)
Circle utilities.
const HepPoint3D ORIGIN
Constants.
void NHitsSuperLayer(const AList< TMLink > &links, unsigned nHits[11])
returns # of hits per super layer.
unsigned NStereoHits(const AList< TMLink > &links)
returns # of stereo hits.
Helix Track2Helix(const MdcTrk_localz &t)
int SortByPt(const void *av, const void *bv)
Utility functions.
std::string TrackInformation(const TTrack &t)
std::string TrackStatus(const TTrack &t)
returns string of track status.
std::string TrackLayerUsage(const TTrack &t)
bool PositiveDefinite(const Helix &h)
Error matrix validity.
std::string TrackKinematics(const Helix &h)
bool HelixHasNan(const Helix &h)
Helix parameter validity.
#define TrackFitCdcKalman
#define TrackFitSvdCdcKalman
HepGeom::Point3D< double > HepPoint3D
#define TrackQualityAfterKink
#define TrackQualityCosmic
#define TrackTypeUndefined
#define TrackTrackManager
#define TrackTypeIncomingCosmic
#define TrackOldConformalFinder
#define TrackQualityOutsideCurler
#define TrackTypeOutgoingCosmic
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
const HepSymMatrix & Ea(void) const
returns error matrix.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
double radius(void) const
returns radious of helix.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
virtual double getReferField()=0
A class to represent a circle in tracking.
double radius(void) const
returns radius.
const HepPoint3D & center(void) const
returns position of center.
A class to fit a TTrackBase object to a helix.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
unsigned state(void) const
returns state.
const TTrack *const track(void) const
assigns a pointer to a TTrack.
float dDrift(unsigned) const
returns drift distance error.
float drift(unsigned) const
returns drift distance.
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
A class to represent a wire in MDC.
unsigned layerId(void) const
returns layer id.
const HepVector3D & direction(void) const
returns direction vector of the wire.
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
const HepPoint3D & forwardPosition(void) const
returns position in forward endplate.
const HepPoint3D & backwardPosition(void) const
returns position in backward endplate.
std::string name(void) const
returns name.
A class to relate TMDCWireHit and TTrack objects.
const HepPoint3D & positionOnWire(void) const
returns the closest point on wire to a track.
const HepPoint3D & positionOnTrack(void) const
returns the closest point on track to wire.
unsigned leftRight(void) const
returns left-right. 0:left, 1:right, 2:wire
const TMDCWireHit * hit(void) const
returns a pointer to a hit.
const unsigned fit2D(const unsigned &)
void update(const HepPoint3D &onTrack, const HepPoint3D &onWire, unsigned leftRight, double pull)
sets results of fitting.
double dPhi(void) const
returns dPhi to the closest point.
const HepPoint3D & position(void) const
returns position.
const TMDCWire *const wire(void) const
returns a pointer to a wire.
double dot(const TPoint2D &) const
A class to represent a track in tracking.
A class to relate TMDCWireHit and TTrack objects.
A virtual class for a track class in tracking.
virtual double distance(const TMLink &) const
returns distance to a position of TMLink in TMLink space.
virtual void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
const AList< TMLink > & links(unsigned mask=0) const
returns a list of masked TMLinks assigned to this track. 'mask' will be applied if mask is not 0.
const TMFitter *const fitter(void) const
returns a pointer to a default fitter.
unsigned nCores(unsigned mask=0) const
returns # of masked TMLinks for fit. 'mask' will be applied if mask is not 0.
const AList< TMLink > & cores(unsigned mask=0) const
returns a list of masked TMLinks for fit. 'mask' will be applied if mask is not 0.
A class to represent a track in tracking.
void assign(unsigned maskForWireHit)
assigns wire hits to this track.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
int stereoHitForCurl(TMLink &link, AList< HepPoint3D > &arcZList) const
const std::string & name(void) const
returns/sets name.
TPoint2D center(void) const
returns position of helix center.
unsigned quality(void) const
sets/returns quality.
TTrack()
Default constructor.
int fit2D(unsigned=0, double=0.1, double=0.015)
fits itself. Error was happened if return value is not zero.
double radius(void) const
returns signed radius.
int HelCyl(double rhole, double rcyl, double zb, double zf, double epsl, double &phi, HepPoint3D &xp) const
returns a cathode hit list.
double impact(void) const
returns signed impact parameter to the origin.
double pt(void) const
returns Pt.
int approach(TMLink &) const
calculates the closest approach to a wire in real space. Results are stored in TMLink....
void refine2D(AList< TMLink > &list, float maxSigma)
fits itself with cathode hits.
int approach2D(TMLink &) const
void movePivot(void)
moves pivot to the inner most hit.
double chi2(void) const
returns chi2.
int szPosition(TMLink &link) const
calculates arc length and z for a stereo hit.
virtual ~TTrack()
Destructor.
void deleteListForCurl(AList< HepPoint3D > &l1, AList< HepPoint3D > &l2) const
Hep3Vector p(void) const
returns momentum.
double complex pa0 double complex pb0ij double complex pc0
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
complex_t R(double Q2, double M2, double G, double Mp2, double Mm2)