CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
CgemGeoAlign.cxx
Go to the documentation of this file.
1#include "CgemGeomSvc/CgemGeoAlign.h"
2
3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/IMessageSvc.h"
5#include "GaudiKernel/StatusCode.h"
6#include "GaudiKernel/ISvcLocator.h"
7#include "GaudiKernel/Bootstrap.h"
8#include "GaudiKernel/SmartDataPtr.h"
9#include "GaudiKernel/IDataProviderSvc.h"
10#include "GaudiKernel/PropertyMgr.h"
11
12#include "TMath.h"
13
14#include <iostream>
15#include <fstream>
16#include <iomanip>
17
18using namespace std;
19
21 m_r[0] = 87.915;
22 m_r[1] = 130.415;
23 m_r[2] = 172.915;
24}
25
26void CgemGeoAlign::initAlignPar(string alignFile){
27 ifstream fin(alignFile.c_str());
28 char strtmp[200];
29 fin.getline(strtmp,1000);
30 string str[3];
31 for (int layer=0; layer<3; layer++){
32 fin >> str[layer] >> m_dx[layer] >> m_dy[layer] >> m_dz[layer]
33 >> m_rx[layer] >> m_ry[layer] >> m_rz[layer];
34
35 m_dxOrig[layer] = m_dx[layer];
36 m_dyOrig[layer] = m_dy[layer];
37 m_dzOrig[layer] = m_dz[layer];
38 m_rxOrig[layer] = m_rx[layer];
39 m_ryOrig[layer] = m_ry[layer];
40 m_rzOrig[layer] = m_rz[layer];
41 }
42 fin.close();
43}
44
46 for (int layer=0; layer<3; layer++){
47 m_dx[layer] = m_dxOrig[layer];
48 m_dy[layer] = m_dyOrig[layer];
49 m_dz[layer] = m_dzOrig[layer];
50 m_rx[layer] = m_rxOrig[layer];
51 m_ry[layer] = m_ryOrig[layer];
52 m_rz[layer] = m_rzOrig[layer];
53 }
54}
55
57 // 1. Get 2 points on straight line:
58 HepPoint3D p1 = lineOriginal.xAtR(m_r[layer], -1);
59 HepPoint3D p2 = lineOriginal.xAtR(m_r[layer], 1);
60
61 double dist = p1.distance2(p2);
62 if(fabs(dist) < 0.001){
63 double s1 = lineOriginal.sAtR(m_r[layer], -1);
64 double s2 = lineOriginal.sAtR(m_r[layer], 1);
65
66 p1 = lineOriginal.x(s1);
67 p2 = lineOriginal.x(s2);
68 }
69
70 // 2. Transformation
71 // cout << "alignment par: " << setw(15) << m_dx[layer] << setw(15) << m_dy[layer]
72 // << setw(15) << m_dz[layer] << setw(15) << m_rz[layer] << endl;
73
74 // cout << "2 points before transform: "
75 // << setw(15) << p1.x() << setw(15) << p1.y() << setw(15) << p1.z()
76 // << setw(15) << p2.x() << setw(15) << p2.y() << setw(15) << p2.z() << endl;
77
78 HepPoint3D newP1 = point_transform(layer, p1);
79 HepPoint3D newP2 = point_transform(layer, p2);
80
81 // cout << "2 points after transform: "
82 // << setw(15) << newP1.x() << setw(15) << newP1.y() << setw(15) << newP1.z()
83 // << setw(15) << newP2.x() << setw(15) << newP2.y() << setw(15) << newP2.z() << endl;
84
85 // 3. New line parameters
86 StraightLine newLine(newP1, newP2);
87
88 // cout << "use StraightLine" << endl;
89 // cout << "track before transform: " << setw(15) << lineOriginal.dr() << setw(15) << lineOriginal.phi0()
90 // << setw(15) << lineOriginal.dz() << setw(15) << lineOriginal.tanl() << endl;
91 // cout << "track after transform: " << setw(15) << newLine.dr() << setw(15) << newLine.phi0()
92 // << setw(15) << newLine.dz() << setw(15) << newLine.tanl() << endl << endl;
93
94 return newLine;
95}
96
97void CgemGeoAlign::StraightLineConversion_v1(int layer, double lineOriginal[], double lineConverted[]){
98
99 // m_dx[0] = 1;
100 // m_dy[0] = 1;
101 // m_dz[0] = 1;
102 // m_rz[0] = 0; //TMath::Pi()/2.;
103
104 // 0. Get original straight line parameters:
105
106 double drho = lineOriginal[0];
107 double phi0 = lineOriginal[1];
108 double dz = lineOriginal[2];
109 double tgl = lineOriginal[3];
110
111 // 1. Get 2 points on straight line:
112
113 //--- Line on x-y plane: y = ax + b
114 //--- Line on s-z plane: z = -1.*tgl*s + dz;
115 // s = sqrt((x-x0)^2+(y-y0)^2)
116
117 int flg_parallel_x = 0;
118 int flg_parallel_y = 0;
119
120 if(phi0 == TMath::Pi()/2. || phi0 == -1.*TMath::Pi()/2.) flg_parallel_x = 1;
121 if(phi0 == 0 || phi0 == TMath::Pi()) flg_parallel_y = 1;
122
123 double a, b, x0, x1, x2, y0, y1, y2, s1, s2, z1, z2;
124 x0 = drho*cos(phi0);
125 y0 = drho*sin(phi0);
126
127 if(flg_parallel_x == 0 && flg_parallel_y == 0){
128 a = tan(TMath::Pi()/2.+phi0);
129 b = drho / cos(phi0);
130
131 x1 = 0;
132 y1 = drho / cos(phi0);
133 s1 = sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
134 z1 = -1.*tgl*s1 + dz;
135
136 x2 = -1.*b/a;
137 y2 = 0;
138 s2 = sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0));
139 z2 = -1.*tgl*s2 + dz;
140 if(x1==x2 || y1==y2 || z1==z2){
141 x2 = (1.-b)/a;
142 y2 = 1;
143 s2 = sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0));
144 z2 = -1.*tgl*s2 + dz;
145 }
146 }
147 else if(flg_parallel_x == 1){
148 x1 = drho; y1 = 0; s1 = sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)); z1 = -1.*tgl*s1 + dz;
149 x2 = drho; y2 = 1; s2 = sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0)); z2 = -1.*tgl*s2 + dz;
150 }
151 else if(flg_parallel_y == 1){
152 x1 = 0; y1 = drho; s1 = sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)); z1 = -1.*tgl*s1 + dz;
153 x2 = 1; y2 = drho; s2 = sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0)); z2 = -1.*tgl*s2 + dz;
154 }
155
156 // 2. Transformation
157
158 double shift_x = m_dx[layer];
159 double shift_y = m_dy[layer];
160 double shift_z = m_dz[layer];
161 double rotation_z = m_rz[layer];
162
163 // cout << "alignment par: " << setw(15) << shift_x << setw(15) << shift_y
164 // << setw(15) << shift_z << setw(15) << rotation_z << endl;
165
166 // cout << "2 points before transform: "
167 // << setw(15) << x1 << setw(15) << y1 << setw(15) << z1
168 // << setw(15) << x2 << setw(15) << y2 << setw(15) << z2 << endl;
169
170 point_transform(x1, y1, z1, shift_x, shift_y, shift_z, rotation_z);
171 point_transform(x2, y2, z2, shift_x, shift_y, shift_z, rotation_z);
172
173 // cout << "2 points after transform: "
174 // << setw(15) << x1 << setw(15) << y1 << setw(15) << z1
175 // << setw(15) << x2 << setw(15) << y2 << setw(15) << z2 << endl;
176
177 // 3. New line parameters
178
179 //--- Line on x-y plane: y = ax + b
180 // y1 = ax1 + b
181 // y2 = ax2 + b
182 // a = (y1-y2)/(x1-x2) = -tan(TMath::Pi()/2.-phi0) = tan(phi0-TMath::Pi()/2.);
183 // b = y1-a*x1 = drho / cos(phi0);
184 // phi0 = atan(a)+TMath::Pi()/2.;
185 // drho = b*cos(phi0);
186 //--- Line on s-z plane: z = -1.*tgl*s + dz;
187 // s = sqrt((x-x0)^2+(y-y0)^2)
188 // z1 = -1.*tgl*sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))+dz
189 // z2 = -1.*tgl*sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0))+dz
190 // tgl = (z1-z2)/(-1.*(sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))-sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0))));
191 // dz = z1 + tgl*sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
192
193 double new_a;
194 double new_b;
195 double new_phi0;
196 double new_drho;
197 double new_tgl;
198 double new_dz;
199
200 if(x1!=x2 && y1!=y2){
201 new_a = (y1-y2)/(x1-x2);
202 new_b = y1-new_a*x1;
203 new_phi0 = atan(new_a)+TMath::Pi()/2.;
204 new_drho = new_b*cos(phi0);
205 new_tgl = (z1-z2)/(-1.*(sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))-sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0))));
206 new_dz = z1 + new_tgl*sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
207 }
208 else if(x1==x2){
209 new_phi0 = 0;
210 new_drho = x1;
211 new_tgl = (z1-z2)/(-1.*(sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))-sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0))));
212 new_dz = z1 + new_tgl*sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
213 }
214 else if(y1==y2){
215 new_phi0 = TMath::Pi()/2.;
216 new_drho = y1;
217 new_tgl = (z1-z2)/(-1.*(sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))-sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0))));
218 new_dz = z1 + new_tgl*sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
219 }
220
221 lineConverted[0] = new_drho;
222 lineConverted[1] = new_phi0;
223 lineConverted[2] = new_dz;
224 lineConverted[3] = new_tgl;
225
226 // cout << "track before transform: " << setw(15) << lineOriginal[0] << setw(15) << lineOriginal[1]
227 // << setw(15) << lineOriginal[2] << setw(15) << lineOriginal[3] << endl;
228 // cout << "track after transform: " << setw(15) << lineConverted[0] << setw(15) << lineConverted[1]
229 // << setw(15) << lineConverted[2] << setw(15) << lineConverted[3] << endl << endl;
230
231}
232
233void CgemGeoAlign::HelixConversion(int layer, double helixOriginal[], double helixConverted[]){
234}
235
237 double x_shift = pos.x() - m_dx[layer];
238 double y_shift = pos.y() - m_dy[layer];
239 double z_shift = pos.z() - m_dz[layer];
240
241 double x = x_shift*cos(m_rz[layer]) + y_shift*sin(m_rz[layer]);
242 double y = -1.*x_shift*sin(m_rz[layer]) + y_shift*cos(m_rz[layer]);
243 double z = z_shift;
244
245 return HepPoint3D(x,y,z);
246}
247
248void CgemGeoAlign::point_transform(double& x, double& y, double& z, double shift_x,
249 double shift_y, double shift_z, double rotation_z){
250 // double x_origin = x;
251 // double y_origin = y;
252 // double z_origin = z;
253
254 // double x_rotate = x_origin*cos(rotation_z) + y_origin*sin(rotation_z);
255 // double y_rotate = -1.*x_origin*sin(rotation_z) + y_origin*cos(rotation_z);
256 // double z_rotate = z_origin;
257
258 // double x_shift = x_rotate + shift_x;
259 // double y_shift = y_rotate + shift_y;
260 // double z_shift = z_rotate + shift_z;
261
262 // x = x_shift;
263 // y = y_shift;
264 // z = z_shift;
265
266 double x_shift = x - shift_x;
267 double y_shift = y - shift_y;
268 double z_shift = z - shift_z;
269
270 x = x_shift*cos(rotation_z) + y_shift*sin(rotation_z);
271 y = -1.*x_shift*sin(rotation_z) + y_shift*cos(rotation_z);
272 z = z_shift;
273}
274
276 double xp = pos.x();
277 double yp = pos.y();
278 double zp = pos.z();
279
280 double rz = -1.*m_rz[layer];
281 double xrot = xp*cos(rz) + yp*sin(rz);
282 double yrot = -1.*xp*sin(rz) + yp*cos(rz);
283
284 double x = xrot + m_dx[layer];
285 double y = yrot + m_dy[layer];
286 double z = zp + m_dz[layer];
287
288 // cout << "before invTransform: " << setw(15) << xp<< setw(15) << yp << setw(15) << zp << endl;
289 // cout << " after invTransform: " << setw(15) << xp<< setw(15) << yp << setw(15) << zp << endl;
290
291 return HepPoint3D(x, y, z);
292}
Double_t x[10]
HepGeom::Point3D< double > HepPoint3D
Definition: Gam4pikp.cxx:37
double tan(const BesAngle a)
double sin(const BesAngle a)
double cos(const BesAngle a)
void StraightLineConversion_v1(int layer, double lineOriginal[], double lineConverted[])
StraightLine StraightLineConversion(int layer, StraightLine lineOriginal)
void initAlignPar(std::string alignFile)
HepPoint3D point_transform(int layer, HepPoint3D pos)
void resetAlignPar()
HepPoint3D point_invTransform(int layer, HepPoint3D pos)
void HelixConversion(int layer, double helixOriginal[], double helixConverted[])
HepPoint3D x(double s=0.) const
returns position after moving s in downwoards
HepPoint3D xAtR(double R, int direction=1) const
double sAtR(double R, int direction=1) const