BmnRoot
Loading...
Searching...
No Matches
BmnVSPTransform.cxx
Go to the documentation of this file.
1#include "BmnVSPTransform.h"
2
3#include "Math/RotationX.h"
4#include "Math/RotationY.h"
5#include "Math/RotationZ.h"
6
7#include "TMath.h"
8
11
14
15//print test information ----------- -------------------------------------------
17{
18 for(size_t iStation = 0; iStation < transform_stack.size(); ++iStation)
19 {
20 cout << " iStation[" << iStation << "]:\n";
21
22 for(size_t iModule = 0; iModule < transform_stack[iStation].size(); ++iModule) {
23 cout << " iModule[" << iModule << "]:\n";
24
25 for(size_t iTransform = 0; iTransform < transform_stack[iStation][iModule].size(); ++iTransform) {
26 cout << " iTransform[" << iTransform << "]:\n";
27
28 Transform3D transform = transform_stack[iStation][iModule][iTransform];
29
30 Rotation3D rotation = transform.Rotation();
31 Translation3D translation = transform.Translation();
32
33 Double_t xx, xy, xz, yx, yy, yz, zx, zy, zz;
34 Double_t dx, dy, dz;
35
36 rotation.GetComponents(xx, xy, xz, yx, yy, yz, zx, zy, zz);
37 translation.GetComponents(dx, dy, dz);
38
39 cout << " xx = " << xx << "\n";
40 cout << " xy = " << xy << "\n";
41 cout << " xz = " << xz << "\n";
42 cout << "\n";
43 cout << " yx = " << yx << "\n";
44 cout << " yy = " << yy << "\n";
45 cout << " yz = " << yz << "\n";
46 cout << "\n";
47 cout << " zx = " << zx << "\n";
48 cout << " zy = " << zy << "\n";
49 cout << " zz = " << zz << "\n";
50 cout << "\n";
51 cout << " dx = " << dx << "\n";
52 cout << " dy = " << dy << "\n";
53 cout << " dz = " << dz << "\n";
54
55 Double_t traceR = xx + yy + zz;
56
57 Double_t theta = TMath::ACos((traceR-1)*0.5)*TMath::RadToDeg();
58
59 cout << "theta = " << theta << "\n";
60
61 Double_t cosToX = xx/TMath::Sqrt(xx*xx + yx*yx + zx*zx);
62 Double_t angleXdeg = TMath::ACos(cosToX)*TMath::RadToDeg();
63 cout << "angleXdeg = " << angleXdeg << "\n";
64
65 Double_t cosToY = yy/TMath::Sqrt(xy*xy + yy*yy + zy*zy);
66 Double_t angleYdeg = TMath::ACos(cosToY)*TMath::RadToDeg();
67 cout << "angleYdeg = " << angleYdeg << "\n";
68
69 Double_t cosToZ = zz/TMath::Sqrt(xz*xz + yz*yz + zz*zz);
70 Double_t angleZdeg = TMath::ACos(cosToZ)*TMath::RadToDeg();
71 cout << "angleZdeg = " << angleZdeg << "\n";
72
73
74 Plane3D::Vector vec1(xx, yx, zx);
75 Plane3D::Vector vec2(xy, yy, zy);
76 Plane3D::Vector vec3(xz, yz, zz);
77
78 cout << "vec1.Theta() = " << vec1.Theta()*TMath::RadToDeg() << "\n";
79 cout << "vec2.Theta() = " << vec2.Theta()*TMath::RadToDeg() << "\n";
80 cout << "vec3.Theta() = " << vec3.Theta()*TMath::RadToDeg() << "\n";
81
82 cout << "vec1.Mag2() = " << vec1.Mag2() << "\n";
83 cout << "vec2.Mag2() = " << vec2.Mag2() << "\n";
84 cout << "vec3.Mag2() = " << vec3.Mag2() << "\n";
85 }
86 }
87 }
88}
89//------------------------------------------------------------------------------
90
92 transform_stack.clear();
93}
94
95Bool_t BmnVSPTransform::LoadFromXMLFile(TString xml_config_file) {
96
97 Bool_t testVerboseOut = false;
98
99 //clear all previous transformations before loading new
100 Reset();
101
102 TDOMParser *parser = new TDOMParser();
103 parser->SetValidate(false);
104
105 Int_t parse_status = parser->ParseFile(xml_config_file);
106 if(parse_status != 0) {
107 std::cerr << "Error: An error occured when parsing the file! (in BmnVSPTransform)\n";
108 return false;
109 }
110
111 TXMLNode *stationSet_node = parser->GetXMLDocument()->GetRootNode();
112
113 if( strcmp(stationSet_node->GetNodeName(), "StationSet") != 0 ) {
114 std::cerr << "Error: Incorrect name of the root element! (in BmnVSPStationSet)\n";
115 return false;
116 }
117
118 TXMLNode *station_node = stationSet_node->GetChildren();
119
120 Int_t station_cnt = 0;
121 while(station_node) {
122 if( strcmp(station_node->GetNodeName(), "Station") == 0 ) {
123 transform_stack.push_back(vector<vector<Transform3D>>());
124 TXMLNode *module_node = station_node->GetChildren();
125
126 Int_t module_cnt = 0;
127 while(module_node) {
128 if( strcmp(module_node->GetNodeName(), "Module") == 0 ) {
129 transform_stack[station_cnt].push_back(vector<Transform3D>());
130 TXMLNode *transform_node = module_node->GetChildren();
131
132 Int_t transform_cnt = 0;
133 while(transform_node) {
134 if( strcmp(transform_node->GetNodeName(), "Transform") == 0 ) {
135 TString rotationOrder = "ZYX"; //default order
136 Double_t xRotationDeg = 0.0;
137 Double_t yRotationDeg = 0.0;
138 Double_t zRotationDeg = 0.0;
139 Double_t xTranslation = 0.0;
140 Double_t yTranslation = 0.0;
141 Double_t zTranslation = 0.0;
142
143 //getting information from the current transform
144 if( transform_node->HasAttributes() ) {
145 TList *attrList = transform_node->GetAttributes();
146 TXMLAttr *attr = 0;
147 TIter next(attrList);
148
149 while ((attr = (TXMLAttr*)next()) != nullptr)
150 {
151 if( strcmp(attr->GetName(), "rotOrder") == 0 ) {
152 rotationOrder = attr->GetValue();
153 }
154 if( strcmp(attr->GetName(), "xRotationDeg") == 0 ) {
155 xRotationDeg = atof(attr->GetValue());
156 }
157 if( strcmp(attr->GetName(), "yRotationDeg") == 0 ) {
158 yRotationDeg = atof(attr->GetValue());
159 }
160 if( strcmp(attr->GetName(), "zRotationDeg") == 0 ) {
161 zRotationDeg = atof(attr->GetValue());
162 }
163 if( strcmp(attr->GetName(), "xTranslation") == 0 ) {
164 xTranslation = atof(attr->GetValue());
165 }
166 if( strcmp(attr->GetName(), "yTranslation") == 0 ) {
167 yTranslation = atof(attr->GetValue());
168 }
169 if( strcmp(attr->GetName(), "zTranslation") == 0 ) {
170 zTranslation = atof(attr->GetValue());
171 }
172 }
173 }
174
175 if(testVerboseOut) {
176 cout << "current_station = " << station_cnt << "\n";
177 cout << " current_module = " << module_cnt << "\n";
178 cout << " current_transform = " << transform_cnt << "\n";
179 cout << " rotationOrder = " << rotationOrder << "\n";
180 cout << " xRotationDeg = " << xRotationDeg << "\n";
181 cout << " yRotationDeg = " << yRotationDeg << "\n";
182 cout << " zRotationDeg = " << zRotationDeg << "\n";
183 cout << " xTranslation = " << xTranslation << "\n";
184 cout << " yTranslation = " << yTranslation << "\n";
185 cout << " zTranslation = " << zTranslation << "\n";
186 cout << "\n";
187 }
188
189 RotationX rotX(xRotationDeg*TMath::DegToRad());
190 RotationY rotY(yRotationDeg*TMath::DegToRad());
191 RotationZ rotZ(zRotationDeg*TMath::DegToRad());
192 Rotation3D rotation;
193 //rotation = rotX*rotY*rotZ;
194
195 for(Int_t iaxis = 0; iaxis < rotationOrder.Sizeof(); ++iaxis) {
196 if(rotationOrder[iaxis] == 'X' || rotationOrder[iaxis] == 'x') rotation *= rotX;
197 if(rotationOrder[iaxis] == 'Y' || rotationOrder[iaxis] == 'y') rotation *= rotY;
198 if(rotationOrder[iaxis] == 'Z' || rotationOrder[iaxis] == 'z') rotation *= rotZ;
199 }
200
201
202 Translation3D translation(xTranslation, yTranslation, zTranslation);
203 Transform3D transform(rotation, translation);
204
205 //adding the current transform into the vector
206 transform_stack[station_cnt][module_cnt].push_back(transform);
207
208 transform_cnt++;
209 }
210 transform_node = transform_node->GetNextNode();
211 }
212 module_cnt++;
213 }
214 module_node = module_node->GetNextNode();
215 }
216 station_cnt++;
217 }
218 station_node = station_node->GetNextNode();
219 }
220 delete parser;
221
222 return true;
223}
224
225Plane3D::Point BmnVSPTransform::ApplyTransforms(Plane3D::Point point, Int_t station, Int_t module) {
226 Plane3D::Point tpoint = point; //transformed point
227
228 for(auto it = transform_stack.at(station).at(module).cbegin(); it != transform_stack.at(station).at(module).cend(); it++) {
229 tpoint = (*it)(tpoint);
230 }
231 return tpoint;
232}
233
234Plane3D::Point BmnVSPTransform::ApplyInverseTransforms(Plane3D::Point point, Int_t station, Int_t module) {
235 Plane3D::Point tpoint = point; //transformed point
236
237 for(auto it = transform_stack.at(station).at(module).crbegin(); it != transform_stack.at(station).at(module).crend(); it++) {
238 tpoint = (*it).Inverse()(tpoint);
239 }
240 return tpoint;
241}
Bool_t LoadFromXMLFile(TString xml_config_file)
Plane3D::Point ApplyTransforms(Plane3D::Point point, Int_t station, Int_t module)
virtual ~BmnVSPTransform()
Plane3D::Point ApplyInverseTransforms(Plane3D::Point point, Int_t station, Int_t module)