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