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