BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Ext_errmx.cxx
Go to the documentation of this file.
1// File: Ext_errmx.cc
2//
3// Description: Handle error matrix( x, y, z, px, py, pz ).
4// The used coordinate system is the cartesian
5// BESIII coordinate system.The error matrix is
6// now calculated in the Track Coordinate System( TCS )
7// instead of the BESIII Coordinate System( BCS )
8// in the previous version.
9//
10// Modified from BELLE:
11// Creation: 08-Jan-1998
12// Version: 05-Mar-1999
13// by Wang Liangliang
14//
15// Date: 2005.3.30
16//
17
18#include <iostream>
19
20#include "TrkExtAlg/Ext_errmx.h"
21
22extern bool Ext_err_valid( bool msg, const HepSymMatrix &error,
23 const int dimension );
24static const double Eps(1.0e-12); // Infinitesimal number.
25static const double Infinite(1.0e+12); // Infinite number.
26
27// Default constructor
28
29Ext_errmx::Ext_errmx() : m_err(Ndim_err,0), m_err3(3,0), m_R(3,3,0),
30 m_err2(2), m_valid(0) {}
31
32// Copy constructor
33
34Ext_errmx::Ext_errmx( const Ext_errmx &err ) : m_err(err.m_err),
35 m_err3(err.m_err3), m_R(err.m_R), m_err2(err.m_err2),
36 m_valid(err.m_valid) {}
37
38Ext_errmx::Ext_errmx( const HepSymMatrix &err ) : m_err(err),
39 m_err3(3,0), m_R(3,3,0), m_err2(2), m_valid(1) {}
40
41/*
42 Put the error matrix.
43*/
44
45void Ext_errmx::put_err( const double error[] )
46{
47 int ne = 0;
48
49 for( int i = 1; i <= m_err.num_col(); i++ ){
50 for( int j = 1; j <= i; j++ ){
51 m_err.fast( i, j ) = error[ ne++ ];
52 }
53 }
54 m_valid = 1;
55}
56
57/*
58 Setup m_err3 and m_R for get_plane_err(s).
59*/
60void Ext_errmx::set_plane_errs( const Hep3Vector &nx, const Hep3Vector &ny,
61 const Hep3Vector &nz ) const
62{
63// Setup the rotation matrix.
64
65 m_R( 1, 1 ) = nx.x();
66 m_R( 1, 2 ) = nx.y();
67 m_R( 1, 3 ) = nx.z();
68 m_R( 2, 1 ) = ny.x();
69 m_R( 2, 2 ) = ny.y();
70 m_R( 2, 3 ) = ny.z();
71 m_R( 3, 1 ) = nz.x();
72 m_R( 3, 2 ) = nz.y();
73 m_R( 3, 3 ) = nz.z();
74
75// Get the 3x3 sub matrix and Rotate the error matrix.
76
77 m_err3 = (m_err.sub( 1, 3 )).similarity( m_R );
78
79}
80
81/*
82 Get the projection of error on the plane along the readout direction.
83*/
84
85double Ext_errmx::get_plane_err( const Hep3Vector &np, const Hep3Vector &nr )
86 const
87// ( Inputs )
88// np -- Unit vector to the direction of the track.
89// nr -- Readout direction unit vector on the plane.
90//
91// ( Outputs )
92// HepVector[0] = Error( sigma ) along the readout direction.
93// HepVector[1] = Error( sigma ) along the direction perp. to
94// the readout direction.
95{
96
97// Check the validity of the error matrix.
98
99 if( !(*this).valid( 0 ) ){
100 //std::cout << "%WARNING at Ext_get_plane_err: You are trying to calculate"
101// << " error \n using an invalid error matrix." << std::endl;
102 }
103
104// Construct 3 TCS axes.
105
106// x: nx --- unit vector which is perp to np and on the plane of nr and np.
107// y: nz x nx
108// z: nz( = np ) --- direction of the track.
109
110 double nr_np( nr*np );
111 double denom( 1.0 - nr_np*nr_np );
112 double error( 0.0 );
113
114 if( denom > Eps ){ // Track is not parallel to the readout direction.
115
116 double fac( 1.0 / sqrt( denom ) );
117 Hep3Vector nx( ( nr - nr_np * np ) * fac );
118 Hep3Vector ny( np.cross( nx ) );
119
120 (*this).set_plane_errs( nx, ny, np );
121
122 double sigma2( m_err3( 1, 1 ) ); // Error along nx.
123 if( sigma2 > 0 ){
124 error = sqrt( sigma2 ) * fac; // Error projection.
125 }
126
127 } else { // Track is parallel to the readout direction.
128
129 error = Infinite;
130
131 }
132 return( error );
133}
134
135/*
136 Get a projection of error on the plane along the readout direction
137 and its perpendicular direction on the readout plane.
138*/
139
140const HepVector &Ext_errmx::get_plane_errs( const Hep3Vector &np,
141 const Hep3Vector &nr, const Hep3Vector &nt ) const
142// ( Inputs )
143// np -- Unit vector to the direction of the track.
144// nr -- Readout direction unit vector on the plane.
145// nt -- Unit vector that is perp. to nr on the readout plane.
146//
147// ( Outputs )
148// HepVector[0] = Error( sigma ) along the readout direction.
149// HepVector[1] = Error( sigma ) along the direction perp. to
150// the readout direction.
151{
152
153// Check the validity of the error matrix.
154
155 if( !(*this).valid( 1 ) ){
156// std::cout << "%WARNING at Ext_get_plane_errs: You are trying to calculate"
157// << " error \n using an invalid error matrix." << std::endl;
158 }
159
160 double nr_np( nr*np );
161 double denom_r( 1.0 - nr_np*nr_np );
162
163 if( denom_r > Eps ){ // nr is not parallel to the track direction: np.
164
165 double nt_np( nt*np );
166 double denom_t( 1.0 - nt_np*nt_np );
167 double fac_r( 1.0 / sqrt( denom_r ) );
168 Hep3Vector nx( ( nr - nr_np * np ) * fac_r );
169 Hep3Vector ny( np.cross( nx ) );
170
171 (*this).set_plane_errs( nx, ny, np );
172
173 double sigma2( m_err3( 1, 1 ) ); // Error along nx.
174 if( sigma2 > 0 ){
175 m_err2( 1 ) = sqrt( sigma2 ) * fac_r; // Error projection.
176 } else {
177 m_err2( 1 ) = 0.0;
178 }
179
180 if( denom_t > Eps ){ // nt is not parallel to the track direction: np.
181 double fac_t( 1.0 / sqrt( denom_t ) );
182 sigma2 = m_err3( 2, 2 );
183 if( sigma2 > 0 ){
184 m_err2( 2 ) = sqrt( sigma2 ) * fac_t; // Error projection.
185 } else {
186 m_err2( 2 ) = 0.0;
187 }
188 } else { // nt is parallel to the track direction: np.
189 m_err2( 2 ) = (*this).get_plane_err( np, nt );
190 }
191 } else { // nr is parallel to the track direction: np.
192 m_err2( 1 ) = (*this).get_plane_err( np, nr );
193 m_err2( 2 ) = (*this).get_plane_err( np, nt );
194 }
195 return( m_err2 );
196}
197
198/*
199 Get the 2D projected track error perpendicular to a given vector at the
200 current point. pv: momentum vector, for example.
201 view=1. Hep3Vector(1)= error(sigma) along the direction
202 which is perpendicular to pv on the xy plane.
203 Hep3Vector(2)= error(sigma) along the direction
204 which is (pv) x (Hep3Vector(1) direction).
205 view=2. Hep3Vector(1)= error(sigma) along the direction
206 which is perpendicular to pv on the zy plane.
207 Hep3Vector(2)= error(sigma) along the direction
208 which is (pv) x (Hep3Vector(1) direction).
209 view=3. Hep3Vector(1)= error(sigma) along the direction
210 which is perpendicular to pv on the zx plane.
211 Hep3Vector(2)= error(sigma) along the direction
212 which is (pv) x (Hep3Vector(1) direction).
213*/
214
215const Hep3Vector * Ext_errmx::get_tvs( const int view,
216 const Hep3Vector &pv ) const
217// ( Inputs )
218// view -- 2D projection view. = 1 xy, =2 zy, =3 zx.
219// pv -- A vector for which the perpendicular error will be calculated,
220// for example, momentum of the track.
221{
222
223 Hep3Vector np( pv.unit() );
224 Hep3Vector nr;
225
226 switch( view ){
227
228 case 1: // xy view
229
230 if( np.x() != 0 || np.y() != 0 ){
231 nr.setX( np.y() );
232 nr.setY( -np.x() );
233 nr = nr.unit();
234 } else { // Pointing to z-direction.
235 nr.setX( 1 );
236 }
237 break;
238
239 case 2: // zy view
240
241 if( np.y() != 0 || np.z() != 0 ){
242 nr.setY( -np.z() );
243 nr.setZ( np.y() );
244 nr = nr.unit();
245 } else { // Pointing to x-direction.
246 nr.setZ( 1 );
247 }
248 break;
249
250 case 3: // zx view
251
252 if( np.z() != 0 || np.x() != 0 ){
253 nr.setX( -np.z() );
254 nr.setZ( np.x() );
255 nr = nr.unit();
256 } else { // Pointing to z-direction.
257 nr.setZ( 1 );
258 }
259 break;
260 } /* End of switch */
261
262 Hep3Vector nt( np.cross( nr ) );
263 const HepVector & err_v = (*this).get_plane_errs( np, nr, nt );
264 *m_nv = err_v[0]*nr;
265 *(m_nv+1) = err_v[1]*nt;
266 return( m_nv );
267}
268
269/*
270 Get the 2D projected track error perpendicular to a given vector at the
271 current point. pv: momentum vector, for example.
272 Hep3Vector(1)= error(sigma) along the direction which is
273 perpendicular to pv on the plane formed by pv and z-axis.
274 Hep3Vector(2)= error(sigma) along the direction which is
275 (pv) x (Hep3Vector(1) direction).
276*/
277
278const Hep3Vector * Ext_errmx::get_tvs( const Hep3Vector &pv ) const
279// ( Inputs )
280// pv -- A vector for which the perpendicular error will be calculated,
281// for example, momentum of the track.
282{
283
284 Hep3Vector np( pv.unit() );
285 Hep3Vector nz( 0.0, 0.0, 1.0 );
286 Hep3Vector nt( (nz.cross(np)).unit() );
287 Hep3Vector nr( nt.cross(np) );
288
289 const HepVector & err_v = (*this).get_plane_errs( np, nr, nt );
290 *m_nv = err_v[0]*nr;
291 *(m_nv+1) = err_v[1]*nt;
292 return( m_nv );
293
294}
295
296/*
297 valid( msg ). Check the validity of the diagonal elements.
298*/
299
300bool Ext_errmx::valid( bool msg ) const
301{
302 if( m_valid ){
303 if( Ext_err_valid( msg, m_err, 6 ) ){
304 return 1;
305 } else {
306 m_valid = 0;
307 return 0;
308 }
309 } else {
310 return 0;
311 }
312}
313
314// Assign "=" operator
315
317{
318 if( this != &err ){
319 m_err = err.m_err;
320 m_err3 = err.m_err3;
321 m_err2 = err.m_err2;
322 m_R = err.m_R;
323 m_valid = err.m_valid;
324 *m_nv = *err.m_nv;
325 *(m_nv+1) = *(err.m_nv+1);
326 }
327 return *this;
328}
329
330/*
331 ostream "<<" operator
332*/
333std::ostream &operator<<( std::ostream &s, const Ext_errmx &err )
334{
335 s << " m_valid: " << err.m_valid << '\n'
336 << "m_err: " << err.m_err << " m_err3: " << err.m_err3
337 << " m_R: " << err.m_R << " m_err2: " << err.m_err2
338 << " *m_nv: " << *err.m_nv
339 << " *(m_nv+1): " << *(err.m_nv+1)
340 << std::endl;
341 return s;
342}
bool Ext_err_valid(bool msg, HepSymMatrix &error, const int dimension)
bool Ext_err_valid(bool msg, const HepSymMatrix &error, const int dimension)
std::ostream & operator<<(std::ostream &s, const Ext_errmx &err)
Definition: Ext_errmx.cxx:333
XmlRpcServer s
Definition: HelloServer.cpp:11
HepSymMatrix m_err
Definition: Ext_errmx.h:133
void put_err(const double error[])
Definition: Ext_errmx.cxx:45
bool valid(bool msg) const
Definition: Ext_errmx.cxx:300
Ext_errmx & operator=(const Ext_errmx &errmx)
Definition: Ext_errmx.cxx:316
const Hep3Vector * get_tvs(const int view, const Hep3Vector &pv) const
Definition: Ext_errmx.cxx:215
void set_plane_errs(const Hep3Vector &nx, const Hep3Vector &ny, const Hep3Vector &nz) const
Definition: Ext_errmx.cxx:60
const HepVector & get_plane_errs(const Hep3Vector &np, const Hep3Vector &nr, const Hep3Vector &nt) const
Definition: Ext_errmx.cxx:140
double get_plane_err(const Hep3Vector &np, const Hep3Vector &nr) const
Definition: Ext_errmx.cxx:85