BOSS 8.0.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 "Ext_errmx.h"
21
22extern bool Ext_err_valid( bool msg, const HepSymMatrix& error, const int dimension );
23static const double Eps( 1.0e-12 ); // Infinitesimal number.
24static const double Infinite( 1.0e+12 ); // Infinite number.
25
26// Default constructor
27
29 : m_err( Ndim_err, 0 ), m_err3( 3, 0 ), m_R( 3, 3, 0 ), m_err2( 2 ), m_valid( 0 ) {}
30
31// Copy constructor
32
34 : m_err( err.m_err )
35 , m_err3( err.m_err3 )
36 , m_R( err.m_R )
37 , m_err2( err.m_err2 )
38 , m_valid( err.m_valid ) {}
39
40Ext_errmx::Ext_errmx( const HepSymMatrix& err )
41 : m_err( err ), m_err3( 3, 0 ), m_R( 3, 3, 0 ), m_err2( 2 ), m_valid( 1 ) {}
42
43/*
44 Put the error matrix.
45*/
46
47void Ext_errmx::put_err( const double error[] ) {
48 int ne = 0;
49
50 for ( int i = 1; i <= m_err.num_col(); i++ )
51 {
52 for ( int j = 1; j <= i; j++ ) { m_err.fast( i, j ) = error[ne++]; }
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 // Setup the rotation matrix.
63
64 m_R( 1, 1 ) = nx.x();
65 m_R( 1, 2 ) = nx.y();
66 m_R( 1, 3 ) = nx.z();
67 m_R( 2, 1 ) = ny.x();
68 m_R( 2, 2 ) = ny.y();
69 m_R( 2, 3 ) = ny.z();
70 m_R( 3, 1 ) = nz.x();
71 m_R( 3, 2 ) = nz.y();
72 m_R( 3, 3 ) = nz.z();
73
74 // Get the 3x3 sub matrix and Rotate the error matrix.
75
76 m_err3 = ( m_err.sub( 1, 3 ) ).similarity( m_R );
77}
78
79/*
80 Get the projection of error on the plane along the readout direction.
81*/
82
83double Ext_errmx::get_plane_err( const Hep3Vector& np, const Hep3Vector& nr ) const
84// ( Inputs )
85// np -- Unit vector to the direction of the track.
86// nr -- Readout direction unit vector on the plane.
87//
88// ( Outputs )
89// HepVector[0] = Error( sigma ) along the readout direction.
90// HepVector[1] = Error( sigma ) along the direction perp. to
91// the readout direction.
92{
93
94 // Check the validity of the error matrix.
95
96 if ( !( *this ).valid( 0 ) )
97 {
98 // std::cout << "%WARNING at Ext_get_plane_err: You are trying to calculate"
99 // << " error \n using an invalid error matrix." << std::endl;
100 }
101
102 // Construct 3 TCS axes.
103
104 // x: nx --- unit vector which is perp to np and on the plane of nr and np.
105 // y: nz x nx
106 // z: nz( = np ) --- direction of the track.
107
108 double nr_np( nr * np );
109 double denom( 1.0 - nr_np * nr_np );
110 double error( 0.0 );
111
112 if ( denom > Eps )
113 { // Track is not parallel to the readout direction.
114
115 double fac( 1.0 / sqrt( denom ) );
116 Hep3Vector nx( ( nr - nr_np * np ) * fac );
117 Hep3Vector ny( np.cross( nx ) );
118
119 ( *this ).set_plane_errs( nx, ny, np );
120
121 double sigma2( m_err3( 1, 1 ) ); // Error along nx.
122 if ( sigma2 > 0 )
123 {
124 error = sqrt( sigma2 ) * fac; // Error projection.
125 }
126 }
127 else
128 { // Track is parallel to the readout direction.
129
130 error = Infinite;
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, const Hep3Vector& nr,
141 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 {
157 // std::cout << "%WARNING at Ext_get_plane_errs: You are trying to calculate"
158 // << " error \n using an invalid error matrix." << std::endl;
159 }
160
161 double nr_np( nr * np );
162 double denom_r( 1.0 - nr_np * nr_np );
163
164 if ( denom_r > Eps )
165 { // nr is not parallel to the track direction: np.
166
167 double nt_np( nt * np );
168 double denom_t( 1.0 - nt_np * nt_np );
169 double fac_r( 1.0 / sqrt( denom_r ) );
170 Hep3Vector nx( ( nr - nr_np * np ) * fac_r );
171 Hep3Vector ny( np.cross( nx ) );
172
173 ( *this ).set_plane_errs( nx, ny, np );
174
175 double sigma2( m_err3( 1, 1 ) ); // Error along nx.
176 if ( sigma2 > 0 )
177 {
178 m_err2( 1 ) = sqrt( sigma2 ) * fac_r; // Error projection.
179 }
180 else { m_err2( 1 ) = 0.0; }
181
182 if ( denom_t > Eps )
183 { // nt is not parallel to the track direction: np.
184 double fac_t( 1.0 / sqrt( denom_t ) );
185 sigma2 = m_err3( 2, 2 );
186 if ( sigma2 > 0 )
187 {
188 m_err2( 2 ) = sqrt( sigma2 ) * fac_t; // Error projection.
189 }
190 else { m_err2( 2 ) = 0.0; }
191 }
192 else
193 { // nt is parallel to the track direction: np.
194 m_err2( 2 ) = ( *this ).get_plane_err( np, nt );
195 }
196 }
197 else
198 { // nr is parallel to the track direction: np.
199 m_err2( 1 ) = ( *this ).get_plane_err( np, nr );
200 m_err2( 2 ) = ( *this ).get_plane_err( np, nt );
201 }
202 return ( m_err2 );
203}
204
205/*
206 Get the 2D projected track error perpendicular to a given vector at the
207 current point. pv: momentum vector, for example.
208 view=1. Hep3Vector(1)= error(sigma) along the direction
209 which is perpendicular to pv on the xy plane.
210 Hep3Vector(2)= error(sigma) along the direction
211 which is (pv) x (Hep3Vector(1) direction).
212 view=2. Hep3Vector(1)= error(sigma) along the direction
213 which is perpendicular to pv on the zy plane.
214 Hep3Vector(2)= error(sigma) along the direction
215 which is (pv) x (Hep3Vector(1) direction).
216 view=3. Hep3Vector(1)= error(sigma) along the direction
217 which is perpendicular to pv on the zx plane.
218 Hep3Vector(2)= error(sigma) along the direction
219 which is (pv) x (Hep3Vector(1) direction).
220*/
221
222const Hep3Vector* Ext_errmx::get_tvs( const int view, const Hep3Vector& pv ) const
223// ( Inputs )
224// view -- 2D projection view. = 1 xy, =2 zy, =3 zx.
225// pv -- A vector for which the perpendicular error will be calculated,
226// for example, momentum of the track.
227{
228
229 Hep3Vector np( pv.unit() );
230 Hep3Vector nr;
231
232 switch ( view )
233 {
234
235 case 1: // xy view
236
237 if ( np.x() != 0 || np.y() != 0 )
238 {
239 nr.setX( np.y() );
240 nr.setY( -np.x() );
241 nr = nr.unit();
242 }
243 else
244 { // Pointing to z-direction.
245 nr.setX( 1 );
246 }
247 break;
248
249 case 2: // zy view
250
251 if ( np.y() != 0 || np.z() != 0 )
252 {
253 nr.setY( -np.z() );
254 nr.setZ( np.y() );
255 nr = nr.unit();
256 }
257 else
258 { // Pointing to x-direction.
259 nr.setZ( 1 );
260 }
261 break;
262
263 case 3: // zx view
264
265 if ( np.z() != 0 || np.x() != 0 )
266 {
267 nr.setX( -np.z() );
268 nr.setZ( np.x() );
269 nr = nr.unit();
270 }
271 else
272 { // Pointing to z-direction.
273 nr.setZ( 1 );
274 }
275 break;
276 } /* End of switch */
277
278 Hep3Vector nt( np.cross( nr ) );
279 const HepVector& err_v = ( *this ).get_plane_errs( np, nr, nt );
280 *m_nv = err_v[0] * nr;
281 *( m_nv + 1 ) = err_v[1] * nt;
282 return ( m_nv );
283}
284
285/*
286 Get the 2D projected track error perpendicular to a given vector at the
287 current point. pv: momentum vector, for example.
288 Hep3Vector(1)= error(sigma) along the direction which is
289 perpendicular to pv on the plane formed by pv and z-axis.
290 Hep3Vector(2)= error(sigma) along the direction which is
291 (pv) x (Hep3Vector(1) direction).
292*/
293
294const Hep3Vector* Ext_errmx::get_tvs( const Hep3Vector& pv ) const
295// ( Inputs )
296// pv -- A vector for which the perpendicular error will be calculated,
297// for example, momentum of the track.
298{
299
300 Hep3Vector np( pv.unit() );
301 Hep3Vector nz( 0.0, 0.0, 1.0 );
302 Hep3Vector nt( ( nz.cross( np ) ).unit() );
303 Hep3Vector nr( nt.cross( np ) );
304
305 const HepVector& err_v = ( *this ).get_plane_errs( np, nr, nt );
306 *m_nv = err_v[0] * nr;
307 *( m_nv + 1 ) = err_v[1] * nt;
308 return ( m_nv );
309}
310
311/*
312 valid( msg ). Check the validity of the diagonal elements.
313*/
314
315bool Ext_errmx::valid( bool msg ) const {
316 if ( m_valid )
317 {
318 if ( Ext_err_valid( msg, m_err, 6 ) ) { return 1; }
319 else
320 {
321 m_valid = 0;
322 return 0;
323 }
324 }
325 else { return 0; }
326}
327
328// Assign "=" operator
329
331 if ( this != &err )
332 {
333 m_err = err.m_err;
334 m_err3 = err.m_err3;
335 m_err2 = err.m_err2;
336 m_R = err.m_R;
337 m_valid = err.m_valid;
338 *m_nv = *err.m_nv;
339 *( m_nv + 1 ) = *( err.m_nv + 1 );
340 }
341 return *this;
342}
343
344/*
345 ostream "<<" operator
346*/
347std::ostream& operator<<( std::ostream& s, const Ext_errmx& err ) {
348 s << " m_valid: " << err.m_valid << '\n'
349 << "m_err: " << err.m_err << " m_err3: " << err.m_err3 << " m_R: " << err.m_R
350 << " m_err2: " << err.m_err2 << " *m_nv: " << *err.m_nv
351 << " *(m_nv+1): " << *( err.m_nv + 1 ) << std::endl;
352 return s;
353}
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)
XmlRpcServer s
HepSymMatrix m_err
Definition Ext_errmx.h:128
void put_err(const double error[])
Definition Ext_errmx.cxx:47
bool valid(bool msg) const
Ext_errmx & operator=(const Ext_errmx &errmx)
const Hep3Vector * get_tvs(const int view, const Hep3Vector &pv) const
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
double get_plane_err(const Hep3Vector &np, const Hep3Vector &nr) const
Definition Ext_errmx.cxx:83