BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TrkBmSpotOnTrk.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: TrkBmSpotOnTrk.cxx,v 1.3 2006/03/28 01:03:35 zhangy Exp $
4//
5// Description:
6// Implementation of class to add beam spot to track fit.
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Authors: Steve Schaffner
12//------------------------------------------------------------------------
13#include "CLHEP/Geometry/Point3D.h"
14#include "CLHEP/Vector/ThreeVector.h"
15#include <math.h>
16#ifndef ENABLE_BACKWARDS_COMPATIBILITY
17typedef HepGeom::Point3D<double> HepPoint3D;
18#endif
19#include "TrkBase/TrkDifPoca.h"
20#include "TrkBase/TrkDifTraj.h"
21#include "TrkBase/TrkPoca.h"
22#include "TrkBase/TrkRep.h"
23#include "TrkFitter/TrkBmSpotOnTrk.h"
24using CLHEP::Hep3Vector;
25
26static HepPoint3D dum1( 0, 0, 0 ), dum2( 0, 0, 1 );
27
28TrkBmSpotOnTrk::TrkBmSpotOnTrk( const HepPoint3D& ip, const HepSymMatrix& size )
29 : TrkHitOnTrk( 0, 0.5e-4 )
30 , _beamTraj( FindBeamTrajectory( ip, size ) )
31 , _ip( ip )
32 , _size( size ) {}
33
34// Effectively a copy constructor
36 const TrkDifTraj* trkTraj )
37 : TrkHitOnTrk( hot, newRep, trkTraj )
38 , _beamTraj( hot._beamTraj )
39 , _ip( hot.ip() )
40 , _size( hot._size ) {}
41
43
45 return new TrkBmSpotOnTrk( *this, rep, trkTraj );
46}
47
49 TrkErrCode status = updatePoca( traj, x );
50 if ( status.success() )
51 {
52 assert( _poca != 0 );
53 setHitResid( _poca->doca() );
54 setHitRms( GetRms() );
55 }
56 else
57 {
58#ifdef MDCPATREC_WARNING
59 std::cout << "ErrMsg(warning) TrkBmSpotOnTrk::updateMeasurement failed" << std::endl;
60#endif
61 setHitResid( 9999.9 );
62 setHitRms( 9999.9 );
63 }
64 return status;
65}
66
68
69const Trajectory* TrkBmSpotOnTrk::hitTraj() const { return &_beamTraj; }
70
71const HepPoint3D& TrkBmSpotOnTrk::ip() const { return _ip; }
72
73//
74// GetRms
75//
76// Calculate RMS (hit width or resolution) based on local track
77// trajectory.
78//
79// We have to deal with the error ellipse carefully. To do
80// this, find the point along the linear trajectory in x and y
81// that minimizes the chi-squared, and then use doca/sqrt(chi2)
82// as the RMS.
83//
85 //
86 // Get direction
87 //
88 const TrkDifTraj& trkTraj = getParentRep()->traj();
89 Hep3Vector trkDir = trkTraj.direction( fltLen() );
90
91 //
92 // Get errors (assume no correlation)
93 //
94 double Mxx = 1.0 / _size.fast( 1, 1 );
95 double Myy = 1.0 / _size.fast( 2, 2 );
96
97 //
98 // Normalized track directions in x/y
99 //
100 double vx = trkDir[0];
101 double vy = trkDir[1];
102 double normxy = ( vx * vx + vy * vy );
103 if ( normxy <= 0 ) return 999.9;
104 normxy = sqrt( normxy );
105
106 vx /= normxy;
107 vy /= normxy;
108
109 //
110 // Solve for point of least chi2
111 //
112 double s = vx * vy * ( Mxx - Myy ) / ( vx * vx * Mxx + vy * vy * Myy );
113
114 double dx = ( -vy + s * vx );
115 double dy = ( +vx + s * vy );
116
117 double chi2 = dx * dx * Mxx + dy * dy * Myy;
118
119 return chi2 <= 0 ? 0.0 : ( 1.0 / sqrt( chi2 ) );
120}
121
122//
123// FindBeamTrajectory
124//
125// Calculate a linear trajectory that corresponds to the
126// beam spot and error matrix
127//
128// The simplest way I have to understand this calculation
129// is to consider which (x,y) point is required to minimize
130// the chi2 at +/- one unit in z.
131//
132// The following simple calculation assumes x and y are uncorrelated.
133// This is to save CPU. It is straight forward to extend the
134// calculation to finite x/y correlation.
135//
137 const HepSymMatrix& error ) {
138 int ifail;
139 HepSymMatrix cover( error.inverse( ifail ) );
140
141 if ( ifail )
142 {
143#ifdef MDCPATREC_FATAL
144 std::cout << "ErrMsg(fatal) TrkLineTraj: "
145 << "Error inverting beamspot error matrix" << std::endl;
146#endif
147 }
148 double dx = -cover.fast( 3, 1 ) / cover.fast( 1, 1 );
149 double dy = -cover.fast( 3, 2 ) / cover.fast( 2, 2 );
150
151 HepPoint3D p1 = point + Hep3Vector( -dx, -dy, -1 );
152 HepPoint3D p2 = point + Hep3Vector( +dx, +dy, +1 );
153
154 return TrkLineTraj( p1, p2 );
155}
double p2[4]
double p1[4]
HepGeom::Point3D< double > HepPoint3D
XmlRpcServer s
static HepPoint3D dum2(0, 0, 1)
virtual const TrkDifTraj & traj() const =0
TrkBmSpotOnTrk * clone(TrkRep *, const TrkDifTraj *t=0) const
const HepPoint3D & ip() const
static const TrkLineTraj FindBeamTrajectory(const HepPoint3D &point, const HepSymMatrix &error)
virtual TrkEnums::TrkViewInfo whatView() const
const Trajectory * hitTraj() const
TrkBmSpotOnTrk(const HepPoint3D &ip, const HepSymMatrix &size)
TrkErrCode updatePoca(const TrkDifTraj *trkTraj, bool maintainAmbiguity)
TrkHitOnTrk(const TrkFundHit *, double tolerance)