10 #include <klm/bklm/modules/bklmTracking/BKLMTrackFitter.h>
13 #include <klm/bklm/geometry/GeometryPar.h>
14 #include <klm/bklm/geometry/Module.h>
17 #include <framework/logging/Logger.h>
20 #include <CLHEP/Matrix/DiagMatrix.h>
21 #include <CLHEP/Matrix/Matrix.h>
26 using namespace CLHEP;
28 using namespace Belle2::bklm;
31 enum { VX = 0, VY = 1, VZ = 2 };
34 enum { AY = 0, BY = 1, AZ = 2, BZ = 3 };
37 enum { MY = 0, MZ = 1 };
40 BKLMTrackFitter::BKLMTrackFitter():
64 if (listHitSector.size() < 2) {
71 HepSymMatrix error(2, 0);
72 HepVector gloEta(2, 0);
73 HepSymMatrix gloError(2, 0);
77 HepVector sectorPar(4, 0);
78 HepSymMatrix sectorErr(4, 0);
79 HepVector globalPar(4, 0);
80 HepSymMatrix globalErr(4, 0);
84 globalPar.sub(1, eta);
85 globalErr.sub(1, error);
88 sectorPar.sub(1, eta);
89 sectorErr.sub(1, error);
94 globalPar.sub(3, eta);
95 globalErr.sub(3, error);
98 sectorPar.sub(3, eta);
99 sectorErr.sub(3, error);
105 (*listHitSector.begin())->getSector(), 1);
107 Hep3Vector p1(0, 0, 0); Hep3Vector p2(0, 0, 0);
110 double y1 = sectorPar[0] + sectorPar[1] * x1;
111 double y2 = sectorPar[0] + sectorPar[1] * x2;
112 double z1 = sectorPar[2] + sectorPar[3] * x1;
113 double z2 = sectorPar[2] + sectorPar[3] * x2;
114 p1.setX(x1); p1.setY(y1); p1.setZ(z1);
115 p2.setX(x2); p2.setY(y2); p2.setZ(z2);
120 if (gl2[0] != gl1[0]) {
121 globalPar[1] = (gl2[1] - gl1[1]) / (gl2[0] - gl1[0]);
122 globalPar[0] = gl1[1] - globalPar[1] * gl1[0];
123 globalPar[3] = (gl2[2] - gl1[2]) / (gl2[0] - gl1[0]);
124 globalPar[2] = gl1[2] - globalPar[3] * gl1[0];
125 globalErr = sectorErr;
127 globalPar[1] = DBL_MAX;
128 globalPar[0] = DBL_MAX;
129 globalPar[3] = DBL_MAX;
130 globalPar[2] = DBL_MAX;
131 globalErr = sectorErr;
160 double x, y, z, dy, dz;
172 CLHEP::Hep3Vector globalPos(hit->getPositionX(), hit->getPositionY(), hit->getPositionZ());
185 double distance =
sqrt(dy * dy + dz * dz);
191 HepMatrix errors(2, 2, 0);
192 HepMatrix A(2, 4, 0);
207 int nStrips = hit->getPhiStripMax() - hit->getPhiStripMin() + 1;
208 double dn = nStrips - 1.5;
209 double factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.60;
210 hit_localPhiErr = hit_localPhiErr *
sqrt(factor);
212 nStrips = hit->getZStripMax() - hit->getZStripMin() + 1;
214 factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.55;
215 hit_localZErr = hit_localZErr *
sqrt(factor);
218 error =
sqrt(errors[ MY ][ MY ] +
220 pow(hit_localPhiErr, 2) +
221 pow(hit_localZErr, 2));
224 sigma = distance / error;
245 double x_mea = hit->getPositionX();
246 double y_mea = hit->getPositionY();
247 double z_mea = hit->getPositionZ();
252 double dx = x_pre - x_mea;
253 double dz = z_pre - z_mea;
255 double distance =
sqrt(dx * dx + dz * dz);
259 HepMatrix errors(2, 2, 0);
260 HepMatrix A(2, 4, 0);
278 int nStrips = hit->getPhiStripMax() - hit->getPhiStripMin() + 1;
279 double dn = nStrips - 1.5;
280 double factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.60;
281 hit_localPhiErr = hit_localPhiErr *
sqrt(factor);
283 nStrips = hit->getZStripMax() - hit->getZStripMin() + 1;
285 factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.55;
286 hit_localZErr = hit_localZErr *
sqrt(factor);
290 double sinphi = globalOrigin[1] / globalOrigin.mag();
291 double cosphi = globalOrigin[0] / globalOrigin.mag();
293 HepMatrix globalHitErr(3, 3, 0);
294 globalHitErr[0][0] = pow(hit_localPhiErr * sinphi, 2);
295 globalHitErr[0][1] = (hit_localPhiErr * sinphi) * (hit_localPhiErr * cosphi);
296 globalHitErr[0][2] = 0;
297 globalHitErr[1][1] = pow(hit_localPhiErr * cosphi, 2);;
298 globalHitErr[1][0] = (hit_localPhiErr * sinphi) * (hit_localPhiErr * cosphi);
299 globalHitErr[1][2] = 0;
300 globalHitErr[2][2] = pow(hit_localZErr, 2);
301 globalHitErr[2][0] = 0;
302 globalHitErr[2][1] = 0;
312 HepMatrix error_mea(2, 2, 0);
313 error =
sqrt(errors[ MY ][ MY ] +
321 sigma = distance / error;
334 int depDir,
int indDir)
339 std::list< KLMHit2d* >::iterator iHit;
341 Hep3Vector localHitPos;
342 HepMatrix localHitErr(3, 3, 0);
349 int noPoints = hitList.size();
352 HepMatrix A(noPoints, 2, 0);
355 HepVector y(noPoints, 0);
359 HepDiagMatrix V_y_inverse(noPoints, 0);
363 HepSymMatrix V_A, V_A_inverse;
365 iHit = hitList.begin();
367 int section = hit->getSection();
368 int sector = hit->getSector();
374 for (iHit = hitList.begin(); iHit != hitList.end(); ++iHit) {
377 if (hit->getSection() != section || hit->getSector() != sector) {
385 CLHEP::Hep3Vector globalPos;
386 globalPos[0] = hit->getPositionX();
387 globalPos[1] = hit->getPositionY();
388 globalPos[2] = hit->getPositionZ();
396 int nStrips = hit->getPhiStripMax() - hit->getPhiStripMin() + 1;
397 double dn = nStrips - 1.5;
398 double factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.60;
399 hit_localPhiErr = hit_localPhiErr *
sqrt(factor);
401 nStrips = hit->getZStripMax() - hit->getZStripMin() + 1;
403 factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.55;
404 hit_localZErr = hit_localZErr *
sqrt(factor);
407 localHitErr[0][0] = 0.0;
408 localHitErr[0][1] = 0;
409 localHitErr[0][2] = 0;
410 localHitErr[1][1] = hit_localPhiErr;
411 localHitErr[1][0] = 0;
412 localHitErr[1][2] = 0;
413 localHitErr[2][2] = hit_localZErr;
414 localHitErr[2][0] = 0;
415 localHitErr[2][1] = 0;
420 indPos = localHitPos.x();
424 indPos = localHitPos.y();
428 indPos = localHitPos.z();
432 B2DEBUG(20,
"error in klm_trackSectorFit: illegal direction");
439 depPos = localHitPos.x();
443 depPos = localHitPos.y();
447 depPos = localHitPos.z();
451 B2DEBUG(20,
"error in klm_trackSectorFit: illegal direction");
457 A[ n ][ 1 ] = indPos;
461 if (localHitErr[ depDir ][ depDir ] > 0.0) {
462 V_y_inverse[ n ][ n ] = 1.0 / localHitErr[ depDir ][ depDir ];
464 V_y_inverse[ n ][ n ] = DBL_MAX;
469 V_A_inverse = V_y_inverse.similarityT(A);
472 V_A = V_A_inverse.inverse(ierr);
474 eta = V_A * A.T() * V_y_inverse * y;
478 HepMatrix residual = y - A * eta;
479 HepMatrix chisqr = residual.T() * V_y_inverse * residual;
481 return (chisqr.trace());
489 int depDir,
int indDir)
494 HepMatrix globalHitErr(3, 3, 0);
500 int noPoints = hitList.size();
503 HepMatrix A(noPoints, 2, 0);
506 HepVector y(noPoints, 0);
510 HepDiagMatrix V_y_inverse(noPoints, 0);
513 HepSymMatrix V_A, V_A_inverse;
519 for (std::list< KLMHit2d* >::iterator iHit = hitList.begin(); iHit != hitList.end(); ++iHit) {
527 CLHEP::Hep3Vector globalPos;
528 globalPos[0] = hit->getPositionX();
529 globalPos[1] = hit->getPositionY();
530 globalPos[2] = hit->getPositionZ();
538 int nStrips = hit->getPhiStripMax() - hit->getPhiStripMin() + 1;
539 double dn = nStrips - 1.5;
540 double factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.60;
541 hit_localPhiErr = hit_localPhiErr *
sqrt(factor);
543 nStrips = hit->getZStripMax() - hit->getZStripMin() + 1;
545 factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.55;
546 hit_localZErr = hit_localZErr *
sqrt(factor);
550 double sinphi = globalOrigin[1] / globalOrigin.mag();
551 double cosphi = globalOrigin[0] / globalOrigin.mag();
553 globalHitErr[0][0] = pow(hit_localPhiErr * sinphi, 2);
554 globalHitErr[0][1] = (hit_localPhiErr * sinphi) * (hit_localPhiErr * cosphi);
555 globalHitErr[0][2] = 0;
556 globalHitErr[1][1] = pow(hit_localPhiErr * cosphi, 2);;
557 globalHitErr[1][0] = (hit_localPhiErr * sinphi) * (hit_localPhiErr * cosphi);
558 globalHitErr[1][2] = 0;
559 globalHitErr[2][2] = pow(hit_localZErr, 2);;
560 globalHitErr[2][0] = 0;
561 globalHitErr[2][1] = 0;
566 indPos = globalPos.x();
570 indPos = globalPos.y();
574 indPos = globalPos.z();
578 B2DEBUG(20,
"error in bklm trackFit: illegal direction");
585 depPos = globalPos.x();
589 depPos = globalPos.y();
593 depPos = globalPos.z();
597 B2DEBUG(20,
"error in bklm trackFit: illegal direction");
603 A[ n ][ 1 ] = indPos;
607 double error_raw = globalHitErr[indDir][indDir] + globalHitErr[depDir][depDir];
610 double weight = error_raw;
612 V_y_inverse[ n ][ n ] = 1.0 / weight;
614 V_y_inverse[ n ][ n ] = DBL_MAX;
622 V_A_inverse = V_y_inverse.similarityT(A);
625 V_A = V_A_inverse.inverse(ierr);
627 eta = V_A * A.T() * V_y_inverse * y;
631 HepMatrix residual = y - A * eta;
632 HepMatrix chisqr = residual.T() * V_y_inverse * residual;
634 return (chisqr.trace());
double fit(std::list< KLMHit2d * > &listTrackPoint)
do fit and returns chi square of the fit.
float m_Chi2
Chi square of fit.
double fit1dTrack(std::list< KLMHit2d * > hitList, CLHEP::HepVector &eta, CLHEP::HepSymMatrix &error, int depDir, int indDir)
do fit in the global system
int m_NumHit
the number of hits on this track
double globalDistanceToHit(KLMHit2d *hit, double &error, double &sigma)
Distance from track to a hit in the global system.
double distanceToHit(KLMHit2d *hit, double &error, double &sigma)
Distance from track to a hit in the plane of the module.
CLHEP::HepSymMatrix m_GlobalErr
track params errors in global system
CLHEP::HepVector m_GlobalPar
track params in global system
bklm::GeometryPar * m_GeoPar
pointer to GeometryPar singleton
double fit1dSectorTrack(std::list< KLMHit2d * > hitList, CLHEP::HepVector &eta, CLHEP::HepSymMatrix &error, int depDir, int indDir)
do fit in the y-x plane or z-x plane
CLHEP::HepVector m_SectorPar
track params in the sector local system
CLHEP::HepSymMatrix m_SectorErr
track params errors in the sector local system
bool m_Valid
Is fit valid.
bool m_globalFit
do fit in the local system or global system false: local sys; true: global sys.
~BKLMTrackFitter()
Destructor.
const Module * findModule(int section, int sector, int layer) const
Get the pointer to the definition of a module.
Define the geometry of a BKLM module Each sector [octant] contains Modules.
const CLHEP::Hep3Vector globalToLocal(const CLHEP::Hep3Vector &v, bool reco=false) const
Transform space-point within this module from global to local coordinates.
double getPhiStripWidth() const
Get phi-strip width.
const CLHEP::Hep3Vector getGlobalOrigin() const
Return the position (in global coordinates) of this module's sensitive-volume origin.
const CLHEP::Hep3Vector localToGlobal(const CLHEP::Hep3Vector &v, bool reco=false) const
Transform space-point within this module from local to global coordinates.
double getZStripWidth() const
Get z-strip width.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.