BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtmyEulerAngles.cc
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2//
3// Environment:
4// This software is part of models developed at BES collaboration
5// based on the EvtGen framework. If you use all or part
6// of it, please give an appropriate acknowledgement.
7//
8// Copyright Information: See EvtGen/BesCopyright
9// Copyright (A) 2006 Ping Rong-Gang @IHEP
10//
11// Module: EvtDIY.cc
12//
13// Description: Class to calculate the Euler angles to rotate a system
14//
15// Modification history:
16//
17// Ping R.-G. December, 2007 Module created
18//
19//------------------------------------------------------------------------
20//
21#include "EvtmyEulerAngles.hh"
22#include "EvtPatches.hh"
23#include "EvtReport.hh"
24#include <cstdlib>
25#include <fstream>
26#include <iostream>
27#include <math.h>
28#include <stdio.h>
29using namespace std; //::endl;
30
33 _Yaxis = Yaxis;
34 _Zaxis = Zaxis;
36}
37
39 EvtVector4R z0( 0, 0, 0, 1 );
40 Zcm = z0;
41 _x = h1;
42 _X = h2;
43 yy = Zcm.cross( _x );
44 zz = h1;
45 xx = yy.cross( zz );
46
47 YY = Zcm.cross( _X );
48 ZZ = _X;
49 XX = YY.cross( ZZ );
50 _N = zz.cross( ZZ );
51}
52
54 EvtVector4R y2, std::string axisTag ) {
55
56 EvtVector4R z0( 0, 0, 0, 1 );
57 if ( axisTag == "xy" )
58 {
59 xx = x1;
60 yy = y1;
61 zz = xx.cross( yy );
62
63 XX = x2;
64 YY = y2;
65 ZZ = XX.cross( YY );
66 }
67 else if ( axisTag == "yz" )
68 {
69 yy = x1;
70 zz = y1;
71 xx = yy.cross( zz );
72
73 YY = x2;
74 ZZ = y2;
75 XX = YY.cross( ZZ );
76 }
77 else
78 {
79 std::cout << "EvtmyEulerAngles::EvtmyEulerAngles bad axisTag option" << std::endl;
80 abort();
81 }
82
83 _N = zz.cross( ZZ );
84 // std::cout<<" _N "<<zz<<ZZ<<_N<<yy<<std::endl;
85}
86
88 double cp = yy.dot( _N ) / yy.d3mag() / _N.d3mag();
89 if ( fabs( cp - 1 ) < 0.00001 ) return 0;
90 double acoscp = acos( cp );
91 double xyz = zz.dot( yy.cross( _N ) );
92 if ( xyz >= 0 ) { return acoscp; }
93 else { return 2 * 3.1415926 - acoscp; }
94}
95
97 double cp = zz.dot( ZZ ) / zz.d3mag() / ZZ.d3mag();
98 return acos( cp );
99}
100
102 double cp = YY.dot( _N ) / YY.d3mag() / _N.d3mag();
103 if ( fabs( cp - 1 ) < 0.00001 ) return 0;
104 double xyz = ZZ.dot( _N.cross( YY ) );
105 if ( xyz >= 0 ) { return acos( cp ); }
106 else { return 2 * 3.1415926 - acos( cp ); }
107}
108
110 for ( int i = 1; i < 4; i++ )
111 {
112 _Yaxis.set( i - 1, Pyaxis.get( i ) );
113 _Zaxis.set( i - 1, Pzaxis.get( i ) );
114 }
115 EulerAngles();
116}
117
119
120double EvtmyEulerAngles::getAlpha() { return _alpha; }
121
122double EvtmyEulerAngles::getBeta() { return _beta; }
123
124double EvtmyEulerAngles::getGamma() { return _gamma; }
125
127 // to calculate Euler angles with y-convention, i.e. R=R(Z, alpha).R(Y,beta).R(Z,gamma)
128 double pi = 3.1415926;
129 _ry = _Yaxis.d3mag();
130 _rz = _Zaxis.d3mag();
131
132 if ( _ry == 0 || _rz == 0 )
133 {
134 report( ERROR, "" ) << "Euler angle calculation specified by zero modules of the axis!"
135 << endl;
136 report( ERROR, "EvtGen" ) << "Will terminate execution!" << endl;
137 ::abort();
138 }
139 double tolerance = 1e-10;
140 bool Y1is0 = fabs( _Yaxis.get( 0 ) ) < tolerance;
141 bool Y2is0 = fabs( _Yaxis.get( 1 ) ) < tolerance;
142 bool Y3is0 = fabs( _Yaxis.get( 2 ) ) < tolerance;
143 bool Z1is0 = fabs( _Zaxis.get( 0 ) ) < tolerance;
144 bool Z2is0 = fabs( _Zaxis.get( 1 ) ) < tolerance;
145 bool Z3is0 = fabs( _Zaxis.get( 2 ) ) < tolerance;
146
147 if ( Y1is0 && Y3is0 && Z1is0 && Z2is0 )
148 {
149 _alpha = 0;
150 _beta = 0;
151 _gamma = 0;
152 return;
153 }
154
155 if ( Z1is0 && Z2is0 && !Y2is0 )
156 {
157 _alpha = 0;
158 _beta = 0;
159 _gamma = acos( _Yaxis.get( 0 ) / _ry );
160 if ( _Yaxis.get( 1 ) < 0 ) _gamma = 2 * pi - _gamma;
161 return;
162 }
163
164 // For general case to calculate Euler angles
165 // to calculate beta
166
167 if ( Z1is0 && Z2is0 ) { _beta = 0; }
168 else { _beta = acos( _Zaxis.get( 2 ) / _rz ); }
169
170 // to calculate alpha
171
172 if ( _beta == 0 ) { _alpha = 0.0; }
173 else
174 {
175 double cosalpha = _Zaxis.get( 0 ) / _rz / sin( _beta );
176 if ( fabs( cosalpha ) > 1.0 ) cosalpha = cosalpha / fabs( cosalpha );
177 _alpha = acos( cosalpha );
178 if ( _Zaxis.get( 1 ) < 0.0 ) _alpha = 2 * pi - _alpha;
179 }
180
181 // to calculate gamma, alpha=0 and beta=0 case has been calculated, so only alpha !=0 and
182 // beta !=0 case left
183
184 double singamma = _Yaxis.get( 2 ) / _ry / sin( _beta );
185 double cosgamma =
186 ( -_Yaxis.get( 0 ) / _ry - cos( _alpha ) * cos( _beta ) * singamma ) / sin( _alpha );
187 if ( fabs( singamma ) > 1.0 ) singamma = singamma / fabs( singamma );
188 _gamma = asin( singamma );
189 if ( singamma > 0 && cosgamma < 0 ) _gamma = pi - _gamma; // _gamma>0
190 if ( singamma < 0 && cosgamma < 0 ) _gamma = pi - _gamma; //_gamma<0
191 if ( singamma < 0 && cosgamma > 0 ) _gamma = 2 * pi + _gamma; //_gamma<0
192}
double pi
ostream & report(Severity severity, const char *facility)
Definition EvtReport.cc:34
@ ERROR
Definition EvtReport.hh:49
double get(int i) const
EvtVector4R cross(const EvtVector4R &v2)
virtual ~EvtmyEulerAngles()