21#include "MdcTrkRecon/MdcSegInfoSterO.h"
22#include "MdcGeom/MdcSuperLayer.h"
23#include "TrkBase/TrkRecoTrk.h"
24#include "MdcGeom/BesAngle.h"
25#include "MdcTrkRecon/MdcSegWorks.h"
26#include "MdcTrkRecon/MdcSeg.h"
27#include "CLHEP/Alist/AList.h"
28#include "MdcTrkRecon/mdcTwoInv.h"
29#include "MdcGeom/MdcDetector.h"
30#include "TrkBase/TrkExchangePar.h"
31#include "TrkBase/TrkHelixUtils.h"
32#include "TrkBase/TrkFit.h"
33#include "MdcTrkRecon/MdcLine.h"
34#include "MdcData/MdcHit.h"
35#include "MdcData/MdcHitUse.h"
36#include "CLHEP/Geometry/Point3D.h"
37#include "CLHEP/Geometry/Vector3D.h"
39#include "BField/BField.h"
40#include "MdcGeom/Constants.h"
42#ifndef ENABLE_BACKWARDS_COMPATIBILITY
49 assert (i >= 0 && i < 2);
57 if (tkFit == 0)
return 1;
71 double kap = 0.5 *
par.omega();
75 double radius = slayer->
rEnd();
79 std::cout <<
"delPhi "<<slayer->
delPhi()
82 <<
" zEnd() "<<slayer->
zEnd()
83 <<
" phiAx "<<segStuff.
phiAx
85 <<
" phiDiff "<<phiSeg - segStuff.
phiAx<< std::endl;
87 bool lStraight =
false;
88 if (fabs(kap)<1.e-9) lStraight =
true;
91 double zApprox = phiDiff.
rad() * -dPhiZ;
93 std::cout<<
"zApp "<<zApprox<<std::endl;
95 double delRad = slayer->
stDip() *
96 (1. - zApprox * zApprox * segStuff.
wirLen2inv);
100 delPhiArg = delRad * d0 / (radius*radius);
102 delPhiArg = -delRad * kap;
109 bool szFaild =
false;
112 for (
int ihit = 0; ihit < parentSeg->
nHit(); ihit++){
120 span.
sigma[hitFit] = 1;
121 arcTemp += span.
x[hitFit];
127 std::cout<<
"MdcSegInfoSterO hit "<<ihit<<
" z calc faild"<<std::endl;
131 if (hitFit >0) span.
fit(hitFit);
135 segStuff.
phiAx += delPhiArg +
137 phiDiff = phiSeg - segStuff.
phiAx;
138 double z = phiDiff.
rad() * -dPhiZ;
140 std::cout<<
"z "<<z<<std::endl;
145 double arg = radius*radius - d0*d0;
146 if (
arg <= 0.0)
return 1;
147 double rD0Root = sqrt(
arg);
148 double rD0Rinv = 1. / rD0Root;
149 double rinv = 1./radius;
151 double slope = parentSeg->
slope();
152 ct = dPhiZ * (rD0Root * slope + d0 * rinv) * rinv;
155 if (
arc == 0.0)
return 1;
159 std::cout <<
"in MdcSegInfoSterO : z0 "<<
z0 <<
" "<<
_errmat[0]
165 double dctdm = dPhiZ * rD0Root * rinv;
166 double dctdD = -dPhiZ * rinv * (slope * d0 * rD0Rinv - rinv);
167 double dzdm = -
arc * dPhiZ * rD0Root * rinv;
168 double dzdphi = dPhiZ;
169 double dzdphi0 = -dPhiZ;
170 double dzdD = -dPhiZ +
ct * d0 * rD0Rinv -
arc * dctdD;
172 const double *inErr = parentSeg->
errmat();
174 const HepMatrix trackErr =
par.covariance();
175 _errmat[0] = dzdm * dzdm * inErr[2] +
176 2 * dzdm * dzdphi * inErr[1] +
177 dzdphi * dzdphi * inErr[0] +
178 dzdD * dzdD * trackErr(1,1) +
179 dzdphi0 * dzdphi0 * trackErr(2,2) +
180 2 * dzdD * dzdphi0 * trackErr(1,2);
184 _errmat[2] = dctdm * dctdm * inErr[2] +
185 dctdD * dctdD * trackErr(1,1);
189 _errmat[1] = dzdm * dctdm * inErr[2] +
190 dzdphi * dctdm * inErr[1] +
191 dzdD * dctdD * trackErr(1,1) +
192 dzdphi0 * dctdD * trackErr(1,2);
197 double arg = 1. - kap*kap * radius*radius;
198 if (
arg < 0.0)
return 1;
199 double rKapRoot = sqrt(
arg);
200 double rKapRinv = 1. / rKapRoot;
201 double ctFactor = -rKapRoot * -dPhiZ;
202 double slopeAx = kap * rKapRinv;
203 double slope = parentSeg->
slope();
213 ct = (slopeAx - slope) * ctFactor;
215 if (
arc == 0.0)
return 1;
220 arc = arcTemp/hitFit;
230 std::cout<<
"--slayer NO. "<<slayer->
index()<<std::endl;
231 std::cout<<
"ori ct "<<(slopeAx - slope) * ctFactor
235 <<
" arc "<<arcTemp/hitFit<<std::endl;
236 std::cout<<
"-------- "<<std::endl;
239 double dctdm = dPhiZ * rKapRoot;
240 double dctdkap = -dPhiZ * ( 1 + radius * radius * kap * rKapRinv * slope);
241 double dzdm =
arc * -dPhiZ * rKapRoot;
242 double dzdphi = dPhiZ;
243 double dzdkap = dPhiZ * radius * rKapRinv -
arc * dctdkap -
244 ct * ( radius * rKapRinv / kap -
arc / kap);
245 double dzdphi0 = -dPhiZ ;
247 const double *inErr = parentSeg->
errmat();
249 const HepMatrix trackErr =
par.covariance();
250 _errmat[0] = dzdm * dzdm * inErr[2] +
251 2 * dzdm * dzdphi * inErr[1] +
252 dzdphi * dzdphi * inErr[0] +
253 dzdkap * dzdkap * trackErr(3,3) +
254 dzdphi0 * dzdphi0 * trackErr(2,2) +
255 2 * dzdkap * dzdphi0 * trackErr(2,3);
272 _errmat[2] = dctdm * dctdm * inErr[2] +
273 dctdkap * dctdkap * trackErr(3,3);
277 _errmat[1] = dzdm * dctdm * inErr[2] +
278 dzdphi * dctdm * inErr[1] +
279 dzdkap * dctdkap * trackErr(3,3) +
280 dzdphi0 * dctdkap * trackErr(2,3);
292 std::cout <<
" ErrMsg(warning)" <<
"Failed to invert matrix -- MdcSegInfo::calcStereo" <<
312 std::cout<<
"---------- "<<std::endl;
315 std::cout<<
"fp rp "<<fp<<
" "<<rp<<std::endl;
316 std::cout<<
"Xmid "<<X<<std::endl;
322 double d0 = -
par.d0();
323 double phi0 = (
par.phi0()-
pi/2);
325 if((-1)*
par.omega()/Bz > 0) _charge = 1;
329 else r = 1/
par.omega();
331 double xc =
sin(
par.phi0()) *(-d0+r) * -1.;
332 double yc = -1.*
cos(
par.phi0()) *(-d0+r) * -1;
337 double wwmag2 = ww.mag2();
338 double wwmag = sqrt(wwmag2);
339 int ambig = hitUse.
ambig();
341 double driftdist = fabs( h.
driftDist(t0,ambig) );
343 driftdist/wwmag * ww.y(), 0.);
345 std::cout<<
"xc "<<xc <<
" yc "<<yc<<
" drfitdist "<<driftdist<<std::endl;
346 std::cout<<
"r1 "<<r <<
" d0 "<<d0 <<
" phi0 "<<phi0<<std::endl;
347 std::cout<<
"lr "<<lr<<
" hit ambig "<<hitUse.
ambig()<<
" ambig "<<ambig
349 <<
" right "<<h.
driftDist(0,-1)<<std::endl;
357 if (ambig == 0) lr =
ORIGIN;
377 double vmag2 =
v.mag2();
381 double wv =
w.dot(
v);
383 double d2 = wv * wv - vmag2 * (
w.mag2() - r * r);
385 std::cout<<
"X_fix "<<X<<
" center "<<center<<std::endl;
386 std::cout<<
"V "<<V<<std::endl;
387 std::cout<<
"w "<<
w<<
" v "<<
v<<std::endl;
394 std::cout <<
"in MdcSegInfoSterO !!! stereo: 0. > d2 = " << d2 <<
" "
395 << hitUse.
ambig() << std::endl;
404 std::cout<<
"wv "<<wv<<
" d "<<d<<
" vmag2 "<<vmag2<<std::endl;
406 l[0] = (- wv + d) / vmag2;
407 l[1] = (- wv - d) / vmag2;
414 z[0] = X.z() + l[0] * V.z();
415 z[1] = X.z() + l[1] * V.z();
417 std::cout <<
"X.z "<<X.z()<<
" V.z "<<V.z()<<std::endl;
418 std::cout <<
"l0, l1 = " << l[0] <<
", " << l[1] << std::endl;
419 std::cout <<
"rpz " << rp.z() <<
" fpz " << fp.z() << std::endl;
420 std::cout <<
"z0 " << z[0] <<
" z1 " << z[1] << std::endl;
423 if (hitUse.
ambig() == 0) {
424 if(debug>0)std::cout<<
" ambig = 0 " <<std::endl;
425 if (z[0] > rp.z()+20. || z[0] < fp.z()-20.) {
428 if (z[1] > rp.z()+20. || z[1] < fp.z()-20.) {
432 if(debug>0)std::cout<<
" ambig != 0 " <<std::endl;
434 if (fabs(z[0]/rp.z())>1.05 ) { ok[0] =
false; }
436 if (fabs(z[1]/rp.z())>1.05 ) { ok[1] =
false; }
438 if ((! ok[0]) && (! ok[1])) {
439 if(debug>0&&(hitUse.
ambig()!=0)&&fabs(z[1]/rp.z())>1.05)std::cout<<
" z[1] bad " << std::endl;
440 if(debug>0&&(hitUse.
ambig()!=0)&&fabs(z[0]/rp.z())>1.05)std::cout<<
" z[0] bad " << std::endl;
443 std::cout<<
" z[1] bad " <<
"rpz " << rp.z() <<
" fpz " << fp.z()
444 <<
"z0 " << z[0] <<
" z1 " << z[1] << std::endl;
445 std::cout<<
" !ok[0] && !ok[1] return -2" <<std::endl;
456 std::cout<<__FILE__<<
" "<<__LINE__<<
" p0 "<<p[0].x()<<
" "<<p[0].y()<< std::endl;
457 std::cout<<__FILE__<<
" "<<__LINE__<<
" p1 "<<p[1].x()<<
" "<<p[1].y()<< std::endl;
458 std::cout<<__FILE__<<
" "<<__LINE__<<
" c "<<center.x()<<
" "<<center.y()<<
" "<<_charge<< std::endl;
459 std::cout<<__FILE__<<
" "<<__LINE__<<
" p0 centerx*y "<<center.x() * p[0].y()<<
" centery*x"<<center.y() * p[0].x()<< std::endl;
460 std::cout<<__FILE__<<
" "<<__LINE__<<
" p1 centerx*y "<<center.x() * p[1].y()<<
" centery*x"<<center.y() * p[1].x()<< std::endl;
481 double cosdPhi = - center.dot((p[best] - center).unit()) / center.mag();
483 if(fabs(cosdPhi)<=1.0) {
484 dPhi = acos(cosdPhi);
485 }
else if (cosdPhi>1.0) {
492 tmp.setX(
abs(r * dPhi));
497 span->
y[hitFit] = z[best];
501 span->
x[hitFit] =
abs(r * dPhi);
502 if (hitUse.
ambig()<0) driftdist *= -1.;
506 std::cout<<
"("<<h.
layernumber()<<
","<<h.
wirenumber()<<
") s "<<span->
x[hitFit]<<
" z "<<span->
y[hitFit]<<std::endl;
HepGeom::Vector3D< double > HepVector3D
double arg(const EvtComplex &c)
double sin(const BesAngle a)
double cos(const BesAngle a)
int mdcTwoInv(double matrix[3], double invmat[3])
const HepPoint3D ORIGIN
Constants.
**********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
HepGeom::Vector3D< double > HepVector3D
HepGeom::Point3D< double > HepPoint3D
static const double epsilon
const MdcHit * mdcHit() const
unsigned layernumber() const
unsigned wirenumber() const
void print(std::ostream &o) const
double sigma(double, int, double, double, double) const
double driftDist(double, int, double, double, double) const
const MdcSWire * wire() const
const Hep3Vector & zAxis(void) const
const HepPoint3D * getWestPoint(void) const
const HepPoint3D * getEastPoint(void) const
int zPosition(MdcHitUse &hitUse, const TrkRecoTrk &track, MdcLine *span, int hitFit, double t0) const
bool parIsAngle(int i) const
int calcStereo(MdcSeg *parentSeg, const TrkRecoTrk &track, MdcSegWorks &segStuff)
const MdcSuperLayer * superlayer() const
const double * errmat() const
MdcHitUse * hit(int i) const
double delPhiinv(void) const
double delPhi(void) const
virtual TrkExchangePar helix(double fltL) const =0
static double fltToRad(const TrkExchangePar &hel, double rad)
const BField & bField() const
const TrkFit * fitResult() const