BOSS 7.0.5
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//
22#include <iostream>
23#include <math.h>
24#include <fstream>
25#include <stdio.h>
26#include <cstdlib>
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}
53
55
56 EvtVector4R z0(0,0,0,1);
57 if(axisTag=="xy"){
58 xx = x1;
59 yy = y1;
60 zz=xx.cross(yy);
61
62 XX = x2;
63 YY = y2;
64 ZZ=XX.cross(YY);
65 }else if(axisTag=="yz"){
66 yy=x1;
67 zz=y1;
68 xx=yy.cross(zz);
69
70 YY=x2;
71 ZZ=y2;
72 XX=YY.cross(ZZ);
73 }else{
74 std::cout<<"EvtmyEulerAngles::EvtmyEulerAngles bad axisTag option"<<std::endl;
75 abort();
76 }
77
78 _N=zz.cross(ZZ);
79 //std::cout<<" _N "<<zz<<ZZ<<_N<<yy<<std::endl;
80
81}
82
84 double cp=yy.dot(_N)/yy.d3mag()/_N.d3mag();
85 if(fabs(cp-1)<0.00001) return 0;
86 double acoscp = acos(cp);
87 double xyz=zz.dot(yy.cross(_N));
88 if(xyz>=0){return acoscp;}else{ return 2*3.1415926-acoscp;}
89
90}
91
93 double cp=zz.dot(ZZ)/zz.d3mag()/ZZ.d3mag();
94 return acos(cp);
95}
96
97
99 double cp=YY.dot(_N)/YY.d3mag()/_N.d3mag();
100 if(fabs(cp-1)<0.00001) return 0;
101 double xyz=ZZ.dot(_N.cross(YY));
102 if(xyz>=0){return acos(cp);}else{ return 2*3.1415926-acos(cp);}
103}
104
106 for (int i=1;i<4;i++){
107 _Yaxis.set(i-1,Pyaxis.get(i));
108 _Zaxis.set(i-1,Pzaxis.get(i));
109 }
110 EulerAngles();
111}
112
114}
115
117 return _alpha;
118}
119
121 return _beta;
122}
123
125 return _gamma;
126}
127
129 // to calculate Euler angles with y-convention, i.e. R=R(Z, alpha).R(Y,beta).R(Z,gamma)
130 double pi=3.1415926;
131 _ry=_Yaxis.d3mag();
132 _rz=_Zaxis.d3mag();
133
134 if(_ry==0 ||_rz==0) {
135 report(ERROR,"") << "Euler angle calculation specified by zero modules of the axis!"<<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 _alpha=0; _beta=0; _gamma=0;
149 return;
150 }
151
152 if( Z1is0 && Z2is0 && !Y2is0){
153 _alpha=0; _beta=0;
154 _gamma=acos(_Yaxis.get(0)/_ry);
155 if(_Yaxis.get(1)<0) _gamma=2*pi - _gamma;
156 return;
157 }
158
159 // For general case to calculate Euler angles
160 // to calculate beta
161
162 if(Z1is0 && Z2is0) {
163 _beta=0;
164 } else{ _beta =acos(_Zaxis.get(2)/_rz);}
165
166 //to calculate alpha
167
168 if(_beta==0){
169 _alpha=0.0;
170 }else {
171 double cosalpha=_Zaxis.get(0)/_rz/sin(_beta);
172 if(fabs(cosalpha)>1.0) cosalpha=cosalpha/fabs(cosalpha);
173 _alpha=acos(cosalpha);
174 if(_Zaxis.get(1)<0.0) _alpha=2*pi - _alpha;
175 }
176
177 //to calculate gamma, alpha=0 and beta=0 case has been calculated, so only alpha !=0 and beta !=0 case left
178
179 double singamma=_Yaxis.get(2)/_ry/sin(_beta);
180 double cosgamma=(-_Yaxis.get(0)/_ry-cos(_alpha)*cos(_beta)*singamma)/sin(_alpha);
181 if(fabs(singamma)>1.0) singamma=singamma/fabs(singamma);
182 _gamma=asin(singamma);
183 if(singamma>0 && cosgamma<0 ) _gamma=pi - _gamma; // _gamma>0
184 if(singamma<0 && cosgamma<0 ) _gamma=pi - _gamma; //_gamma<0
185 if(singamma<0 && cosgamma>0 ) _gamma=2*pi + _gamma; //_gamma<0
186
187
188}
ostream & report(Severity severity, const char *facility)
Definition: EvtReport.cc:36
@ ERROR
Definition: EvtReport.hh:49
double sin(const BesAngle a)
double cos(const BesAngle a)
double get(int i) const
Definition: EvtVector3R.hh:126
double d3mag() const
Definition: EvtVector3R.cc:95
void set(int i, double d)
Definition: EvtVector3R.hh:130
double dot(const EvtVector4R &v2) const
Definition: EvtVector4R.cc:199
double get(int i) const
Definition: EvtVector4R.hh:179
EvtVector4R cross(const EvtVector4R &v2)
Definition: EvtVector4R.cc:171
double d3mag() const
Definition: EvtVector4R.cc:186
virtual ~EvtmyEulerAngles()