10#include <klm/modules/KLMTracking/KLMTrackFitter.h>
13#include <klm/bklm/geometry/Module.h>
14#include <klm/bklm/geometry/GeometryPar.h>
15#include <klm/eklm/geometry/GeometryData.h>
19#include <framework/logging/Logger.h>
20#include <framework/utilities/MathHelpers.h>
23#include <CLHEP/Matrix/DiagMatrix.h>
24#include <CLHEP/Matrix/Matrix.h>
31using namespace Belle2::KLM;
34enum { VX = 0, VY = 1, VZ = 2 };
37enum { AY = 0, BY = 1, AZ = 2, BZ = 3 };
40enum { MY = 0, MZ = 1 };
64 if (listHitSector.size() < 2) {
71 HepSymMatrix error(2, 0);
72 HepVector gloEta(2, 0);
73 HepSymMatrix gloError(2, 0);
77 HepVector globalPar(4, 0);
78 HepSymMatrix globalErr(4, 0);
81 globalPar.sub(1, eta);
82 globalErr.sub(1, error);
86 globalPar.sub(3, eta);
87 globalErr.sub(3, error);
126 double x_pre, y_pre, z_pre, dx, dy, dz;
130 HepMatrix errors(2, 2, 0);
131 HepMatrix A(2, 4, 0);
135 double hit_xErr;
double hit_yErr;
double hit_zErr;
136 HepMatrix globalHitErr(3, 3, 0);
140 A[ MY ][ BY ] = x_mea;
142 A[ MZ ][ BZ ] = x_mea;
164 double dn = nStrips - 1.5;
165 double factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.60;
166 hit_localPhiErr = hit_localPhiErr *
sqrt(factor);
170 factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.55;
171 hit_localZErr = hit_localZErr *
sqrt(factor);
175 double sinphi = globalOrigin[1] / globalOrigin.mag();
176 double cosphi = globalOrigin[0] / globalOrigin.mag();
178 hit_xErr = hit_localPhiErr * sinphi;
179 hit_yErr = hit_localPhiErr * cosphi;
180 hit_zErr = hit_localZErr;
183 globalHitErr[0][0] =
square(hit_xErr);
184 globalHitErr[0][1] = (hit_xErr) * (hit_yErr);
185 globalHitErr[0][2] = 0;
186 globalHitErr[1][1] =
square(hit_yErr);;
187 globalHitErr[1][0] = (hit_xErr) * (hit_yErr);
188 globalHitErr[1][2] = 0;
189 globalHitErr[2][2] =
square(hit_zErr);
190 globalHitErr[2][0] = 0;
191 globalHitErr[2][1] = 0;
213 globalHitErr[0][0] =
square(hit_xErr);
214 globalHitErr[0][1] = 0.;
215 globalHitErr[0][2] = 0.;
216 globalHitErr[1][1] =
square(hit_yErr);
217 globalHitErr[1][0] = 0.;
218 globalHitErr[1][2] = 0.;
219 globalHitErr[2][2] =
square(hit_zErr);;
220 globalHitErr[2][0] = 0.;
221 globalHitErr[2][1] = 0.;
227 B2FATAL(
"In KLMTrackFitter globalDistanceToHit, hit is neither from E/B-KLM.");
232 double distance =
sqrt(dx * dx + dy * dy + dz * dz);
235 error =
sqrt(errors[ MY ][ MY ] +
244 sigma = distance / error;
257 int depDir,
int indDir)
262 HepMatrix globalHitErr(3, 3, 0);
268 int noPoints = hitList.size();
271 HepMatrix A(noPoints, 2, 0);
274 HepVector y(noPoints, 0);
278 HepDiagMatrix V_y_inverse(noPoints, 0);
281 HepSymMatrix V_A, V_A_inverse;
285 for (std::list< KLMHit2d* >::iterator iHit = hitList.begin(); iHit != hitList.end(); ++iHit) {
302 double dn = nStrips - 1.5;
303 double factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.60;
304 hit_localPhiErr = hit_localPhiErr *
sqrt(factor);
308 factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.55;
309 hit_localZErr = hit_localZErr *
sqrt(factor);
313 double sinphi = globalOrigin[1] / globalOrigin.mag();
314 double cosphi = globalOrigin[0] / globalOrigin.mag();
316 globalHitErr[0][0] =
square(hit_localPhiErr * sinphi);
317 globalHitErr[0][1] = (hit_localPhiErr * sinphi) * (hit_localPhiErr * cosphi);
318 globalHitErr[0][2] = 0.;
319 globalHitErr[1][1] =
square(hit_localPhiErr * cosphi);
320 globalHitErr[1][0] = (hit_localPhiErr * sinphi) * (hit_localPhiErr * cosphi);
321 globalHitErr[1][2] = 0.;
322 globalHitErr[2][2] =
square(hit_localZErr);
323 globalHitErr[2][0] = 0.;
324 globalHitErr[2][1] = 0.;
329 indPos = globalPos.x();
333 indPos = globalPos.y();
337 indPos = globalPos.z();
341 B2DEBUG(20,
"error in bklm in-TrackFit: illegal direction");
348 depPos = globalPos.x();
352 depPos = globalPos.y();
356 depPos = globalPos.z();
360 B2DEBUG(20,
"error in bklm dep-TrackFit: illegal direction");
376 12) <<
" Vec_y: " << hit_yErr *
sqrt(12));
378 globalHitErr[0][0] =
square(hit_xErr);
379 globalHitErr[0][1] = 0.;
380 globalHitErr[0][2] = 0.;
381 globalHitErr[1][1] =
square(hit_yErr);
382 globalHitErr[1][0] = 0.;
383 globalHitErr[1][2] = 0.;
384 globalHitErr[2][2] =
square(hit_zErr);
385 globalHitErr[2][0] = 0.;
386 globalHitErr[2][1] = 0.;
393 indPos = globalPos.x();
397 indPos = globalPos.y();
401 indPos = globalPos.z();
405 B2DEBUG(20,
"error in EKLM in-TrackFit: illegal direction");
412 depPos = globalPos.x();
416 depPos = globalPos.y();
420 depPos = globalPos.z();
424 B2DEBUG(20,
"error in EKLM dep-TrackFit: illegal direction");
430 A[ n ][ 1 ] = indPos;
434 double error_raw = globalHitErr[indDir][indDir] + globalHitErr[depDir][depDir];
435 double weight = error_raw;
437 V_y_inverse[ n ][ n ] = 1.0 / weight;
439 V_y_inverse[ n ][ n ] = DBL_MAX;
445 V_A_inverse = V_y_inverse.similarityT(A);
448 V_A = V_A_inverse.inverse(ierr);
450 eta = V_A * A.T() * V_y_inverse * y;
454 HepMatrix residual = y - A * eta;
455 HepMatrix chisqr = residual.T() * V_y_inverse * residual;
457 return (chisqr.trace());
double getWidth() const
Get width.
const StripGeometry * getStripGeometry() const
Get strip geometry data.
bool inRPC() const
Determine whether this 2D hit is in RPC or scintillator.
int getSubdetector() const
Get subdetector number.
int getYStripMin() const
Get first strip number for EKLM hit in the y-measuring plane.
int getLayer() const
Get layer number.
int getZStripMax() const
Get last strip number for z plane.
int getSection() const
Get section number.
float getPositionZ() const
Get hit global position z coordinate.
int getSector() const
Get sector number.
float getPositionX() const
Get hit global position x coordinate.
int getPhiStripMin() const
Get strip number for phi plane.
int getZStripMin() const
Get strip number for z plane.
int getXStripMax() const
Get last strip number for EKLM hit in the x-measuring plane.
int getPhiStripMax() const
Get last strip number for phi plane.
float getPositionY() const
Get hit global position y coordinate.
int getYStripMax() const
Get last strip number for EKLM hit in the y-measuring plane.
int getXStripMin() const
Get first strip number for EKLM hit in the x-measuring plane.
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
~KLMTrackFitter()
Destructor.
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.
Belle2::KLM::KLMGeometryPar * m_GeoPar
pointer to GeometryPar singleton
CLHEP::HepSymMatrix m_GlobalErr
track params errors in global system
CLHEP::HepVector m_GlobalPar
track params in global system
bool m_Valid
Is fit valid.
KLMTrackFitter()
Default constructor.
static const double cm
Standard units with the value = 1.
Provides BKLM geometry parameters for simulation, reconstruction etc (from Gearbox or DataBase)
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.
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.
double getZStripWidth() const
Get z-strip width.
constexpr T square(const T &x)
Calculate the square of the input.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.