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"
27 ifstream fin(alignFile.c_str());
29 fin.getline(strtmp,1000);
32 for (
int layer=0; layer<6; layer++){
33 fin >> str[layer] >> m_dx[layer] >> m_dy[layer] >> m_dz[layer]
34 >> m_rx[layer] >> m_ry[layer] >> m_rz[layer];
36 m_dxOrig[layer] = m_dx[layer];
37 m_dyOrig[layer] = m_dy[layer];
38 m_dzOrig[layer] = m_dz[layer];
39 m_rxOrig[layer] = m_rx[layer];
40 m_ryOrig[layer] = m_ry[layer];
41 m_rzOrig[layer] = m_rz[layer];
47 for (
int layer=0; layer<6; layer++){
48 m_dx[layer] = m_dxOrig[layer];
49 m_dy[layer] = m_dyOrig[layer];
50 m_dz[layer] = m_dzOrig[layer];
51 m_rx[layer] = m_rxOrig[layer];
52 m_ry[layer] = m_ryOrig[layer];
53 m_rz[layer] = m_rzOrig[layer];
61 int layer_geo = int(layer_vir/2);
66 double dist = p1.distance2(p2);
67 if(fabs(dist) < 0.001){
68 double s1 = lineOriginal.
sAtR(m_r[layer_geo], -1);
69 double s2 = lineOriginal.
sAtR(m_r[layer_geo], 1);
71 p1 = lineOriginal.
x(s1);
72 p2 = lineOriginal.
x(s2);
111 double drho = lineOriginal[0];
112 double phi0 = lineOriginal[1];
113 double dz = lineOriginal[2];
114 double tgl = lineOriginal[3];
122 int flg_parallel_x = 0;
123 int flg_parallel_y = 0;
125 if(phi0 == TMath::Pi()/2. || phi0 == -1.*TMath::Pi()/2.) flg_parallel_x = 1;
126 if(phi0 == 0 || phi0 == TMath::Pi()) flg_parallel_y = 1;
128 double a, b, x0, x1, x2, y0, y1, y2, s1, s2, z1, z2;
132 if(flg_parallel_x == 0 && flg_parallel_y == 0){
133 a =
tan(TMath::Pi()/2.+phi0);
134 b = drho /
cos(phi0);
137 y1 = drho /
cos(phi0);
138 s1 = sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
139 z1 = -1.*tgl*s1 + dz;
143 s2 = sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0));
144 z2 = -1.*tgl*s2 + dz;
145 if(x1==x2 || y1==y2 || z1==z2){
148 s2 = sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0));
149 z2 = -1.*tgl*s2 + dz;
152 else if(flg_parallel_x == 1){
153 x1 = drho; y1 = 0; s1 = sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)); z1 = -1.*tgl*s1 + dz;
154 x2 = drho; y2 = 1; s2 = sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0)); z2 = -1.*tgl*s2 + dz;
156 else if(flg_parallel_y == 1){
157 x1 = 0; y1 = drho; s1 = sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)); z1 = -1.*tgl*s1 + dz;
158 x2 = 1; y2 = drho; s2 = sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0)); z2 = -1.*tgl*s2 + dz;
163 double shift_x = m_dx[layer_vir];
164 double shift_y = m_dy[layer_vir];
165 double shift_z = m_dz[layer_vir];
166 double rotation_z = m_rz[layer_vir];
205 if(x1!=x2 && y1!=y2){
206 new_a = (y1-y2)/(x1-x2);
208 new_phi0 = atan(new_a)+TMath::Pi()/2.;
209 new_drho = new_b*
cos(phi0);
210 new_tgl = (z1-z2)/(-1.*(sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))-sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0))));
211 new_dz = z1 + new_tgl*sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
216 new_tgl = (z1-z2)/(-1.*(sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))-sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0))));
217 new_dz = z1 + new_tgl*sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
220 new_phi0 = TMath::Pi()/2.;
222 new_tgl = (z1-z2)/(-1.*(sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))-sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0))));
223 new_dz = z1 + new_tgl*sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
226 lineConverted[0] = new_drho;
227 lineConverted[1] = new_phi0;
228 lineConverted[2] = new_dz;
229 lineConverted[3] = new_tgl;
244 double x_shift = pos.x() - m_dx[layer_vir];
245 double y_shift = pos.y() - m_dy[layer_vir];
246 double z_shift = pos.z() - m_dz[layer_vir];
248 Hep3Vector InputVector(x_shift,y_shift,z_shift);
250 InputVector.rotateZ(-m_rz[layer_vir]);
251 InputVector.rotateY(-m_ry[layer_vir]);
252 InputVector.rotateX(-m_rx[layer_vir]);
254 double x = InputVector.x();
255 double y = InputVector.y();
256 double z = InputVector.z();
265 int layer_vir = layer_geo*2+sheet_geo;
267 double x_shift = pos.x() - m_dx[layer_vir];
268 double y_shift = pos.y() - m_dy[layer_vir];
269 double z_shift = pos.z() - m_dz[layer_vir];
271 Hep3Vector InputVector(x_shift,y_shift,z_shift);
273 InputVector.rotateZ(-m_rz[layer_vir]);
274 InputVector.rotateY(-m_ry[layer_vir]);
275 InputVector.rotateX(-m_rx[layer_vir]);
277 double x = InputVector.x();
278 double y = InputVector.y();
279 double z = InputVector.z();
287 double shift_y,
double shift_z,
double rotation_z){
289 double x_shift =
x - shift_x;
290 double y_shift = y - shift_y;
291 double z_shift = z - shift_z;
293 x = x_shift*
cos(rotation_z) + y_shift*
sin(rotation_z);
294 y = -1.*x_shift*
sin(rotation_z) + y_shift*
cos(rotation_z);
329 Hep3Vector InputVector(xp,yp,zp);
331 InputVector.rotateX(m_rx[layer_vir]);
332 InputVector.rotateY(m_ry[layer_vir]);
333 InputVector.rotateZ(m_rz[layer_vir]);
335 Hep3Vector OO(m_dx[layer_vir],m_dy[layer_vir],m_dz[layer_vir]);
336 Hep3Vector InputVector_t1 = InputVector+OO;
338 double x = InputVector_t1.x();
339 double y = InputVector_t1.y();
340 double z = InputVector_t1.z();
348 int layer_vir = layer_geo*2+sheet_geo;
355 Hep3Vector InputVector(xp,yp,zp);
357 InputVector.rotateX(m_rx[layer_vir]);
358 InputVector.rotateY(m_ry[layer_vir]);
359 InputVector.rotateZ(m_rz[layer_vir]);
361 Hep3Vector OO(m_dx[layer_vir],m_dy[layer_vir],m_dz[layer_vir]);
362 Hep3Vector InputVector_t1 = InputVector+OO;
364 double x = InputVector_t1.x();
365 double y = InputVector_t1.y();
366 double z = InputVector_t1.z();
383 Hep3Vector OO(m_dx[layer_vir],m_dy[layer_vir],m_dz[layer_vir]);
384 Hep3Vector LVposUp = GposUp - OO;
385 Hep3Vector LVposDown = GposDown - OO;
389 LVposUp.rotateZ(-m_rz[layer_vir]);
390 LVposUp.rotateY(-m_ry[layer_vir]);
391 LVposUp.rotateX(-m_rx[layer_vir]);
393 LVposDown.rotateZ(-m_rz[layer_vir]);
395 LVposDown.rotateY(-m_ry[layer_vir]);
396 LVposDown.rotateX(-m_rx[layer_vir]);
398 LposUp.setX(LVposUp.x());
399 LposUp.setY(LVposUp.y());
400 LposUp.setZ(LVposUp.z());
402 LposDown.setX(LVposDown.x());
403 LposDown.setY(LVposDown.y());
404 LposDown.setZ(LVposDown.z());
412 Hep3Vector OO(m_dx[layer_vir],m_dy[layer_vir],m_dz[layer_vir]);
413 Hep3Vector LVpos = Gpos - OO;
417 LVpos.rotateZ(-m_rz[layer_vir]);
418 LVpos.rotateY(-m_ry[layer_vir]);
419 LVpos.rotateX(-m_rx[layer_vir]);
421 Lpos.setX(LVpos.x());
422 Lpos.setY(LVpos.y());
423 Lpos.setZ(LVpos.z());
432 int layer_vir = int(layer_geo*2+sheet_geo);
433 Hep3Vector OO(m_dx[layer_vir],m_dy[layer_vir],m_dz[layer_vir]);
434 Hep3Vector LVposUp = GposUp - OO;
435 Hep3Vector LVposDown = GposDown - OO;
439 LVposUp.rotateZ(-m_rz[layer_vir]);
440 LVposUp.rotateY(-m_ry[layer_vir]);
441 LVposUp.rotateX(-m_rx[layer_vir]);
443 LVposDown.rotateZ(-m_rz[layer_vir]);
445 LVposDown.rotateY(-m_ry[layer_vir]);
446 LVposDown.rotateX(-m_rx[layer_vir]);
448 LposUp.setX(LVposUp.x());
449 LposUp.setY(LVposUp.y());
450 LposUp.setZ(LVposUp.z());
452 LposDown.setX(LVposDown.x());
453 LposDown.setY(LVposDown.y());
454 LposDown.setZ(LVposDown.z());
463 int layer_vir = int(layer_geo*2+sheet_geo);
464 Hep3Vector OO(m_dx[layer_vir],m_dy[layer_vir],m_dz[layer_vir]);
465 Hep3Vector LVpos = Gpos - OO;
469 LVpos.rotateZ(-m_rz[layer_vir]);
470 LVpos.rotateY(-m_ry[layer_vir]);
471 LVpos.rotateX(-m_rx[layer_vir]);
473 Lpos.setX(LVpos.x());
474 Lpos.setY(LVpos.y());
475 Lpos.setZ(LVpos.z());
482 int layer_geo = int(layer_vir/2);
484 ToyCgem ACgem(layer_vir,m_r[layer_geo], m_dx[layer_vir], m_dy[layer_vir], m_dz[layer_vir], m_rx[layer_vir], m_ry[layer_vir], m_rz[layer_vir]);
487 Hep3Vector N = LV.unit();
489 Hep3Vector A = ACgem.
getdir();
491 double R = ACgem.
GetR();
493 if (N.cross(A).mag()==0)
499 if (((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))<0)
505 double D1 = (((N.cross(A)).dot((B-O).cross(A)))+sqrt(((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))))/((N.cross(A)).dot(N.cross(A)));
506 double D2 = (((N.cross(A)).dot((B-O).cross(A)))-sqrt(((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))))/((N.cross(A)).dot(N.cross(A)));
509 double z1 = A.dot(N*D1-B+O);
510 double z2 = A.dot(N*D2-B+O);
513 Hep3Vector Inter1 = D1*N + O;
514 Hep3Vector Inter2 = D2*N + O;
519 posUp = (Inter1.phi()>Inter2.phi())? Inter1:Inter2;
520 posDown = (Inter1.phi()>Inter2.phi())? Inter2:Inter1;
531 int layer_geo = int(layer_vir/2);
533 ToyCgem ACgem(layer_vir,m_r[layer_geo], m_dx[layer_vir], m_dy[layer_vir], m_dz[layer_vir], m_rx[layer_vir], m_ry[layer_vir], m_rz[layer_vir]);
536 Hep3Vector N = LV.unit();
538 Hep3Vector A = ACgem.
getdir();
540 double R = ACgem.
GetR();
542 if (N.cross(A).mag()==0)
548 if (((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))<0)
554 double D1 = (((N.cross(A)).dot((B-O).cross(A)))+sqrt(((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))))/((N.cross(A)).dot(N.cross(A)));
555 double D2 = (((N.cross(A)).dot((B-O).cross(A)))-sqrt(((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))))/((N.cross(A)).dot(N.cross(A)));
558 double z1 = A.dot(N*D1-B+O);
559 double z2 = A.dot(N*D2-B+O);
562 Hep3Vector Inter1 = D1*N + O;
563 Hep3Vector Inter2 = D2*N + O;
568 Hep3Vector posUp = (Inter1.phi()>Inter2.phi())? Inter1:Inter2;
569 Hep3Vector posDown = (Inter1.phi()>Inter2.phi())? Inter2:Inter1;
571 pos = (layer_vir%2==0)? posDown:posUp;
585 int layer_vir = int(layer_geo*2+sheet_geo);
587 ToyCgem ACgem(layer_vir,m_r[layer_geo], m_dx[layer_vir], m_dy[layer_vir], m_dz[layer_vir], m_rx[layer_vir], m_ry[layer_vir], m_rz[layer_vir]);
590 Hep3Vector N = LV.unit();
592 Hep3Vector A = ACgem.
getdir();
594 double R = ACgem.
GetR();
596 if (N.cross(A).mag()==0)
601 if (((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))<0)
607 double D1 = (((N.cross(A)).dot((B-O).cross(A)))+sqrt(((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))))/((N.cross(A)).dot(N.cross(A)));
608 double D2 = (((N.cross(A)).dot((B-O).cross(A)))-sqrt(((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))))/((N.cross(A)).dot(N.cross(A)));
611 double z1 = A.dot(N*D1-B+O);
612 double z2 = A.dot(N*D2-B+O);
615 Hep3Vector Inter1 = D1*N + O;
616 Hep3Vector Inter2 = D2*N + O;
621 posUp = (Inter1.phi()>Inter2.phi())? Inter1:Inter2;
622 posDown = (Inter1.phi()>Inter2.phi())? Inter2:Inter1;
633 int layer_vir = int(layer_geo*2+sheet_geo);
635 ToyCgem ACgem(layer_vir,m_r[layer_geo], m_dx[layer_vir], m_dy[layer_vir], m_dz[layer_vir], m_rx[layer_vir], m_ry[layer_vir], m_rz[layer_vir]);
638 Hep3Vector N = LV.unit();
640 Hep3Vector A = ACgem.
getdir();
642 double R = ACgem.
GetR();
644 if (N.cross(A).mag()==0)
649 if (((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))<0)
655 double D1 = (((N.cross(A)).dot((B-O).cross(A)))+sqrt(((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))))/((N.cross(A)).dot(N.cross(A)));
656 double D2 = (((N.cross(A)).dot((B-O).cross(A)))-sqrt(((N.cross(A)).dot(N.cross(A)))*R*R-(A.dot(A)*((B-O).dot(N.cross(A)))*((B-O).dot(N.cross(A))))))/((N.cross(A)).dot(N.cross(A)));
659 double z1 = A.dot(N*D1-B+O);
660 double z2 = A.dot(N*D2-B+O);
663 Hep3Vector Inter1 = D1*N + O;
664 Hep3Vector Inter2 = D2*N + O;
669 Hep3Vector posUp = (Inter1.phi()>Inter2.phi())? Inter1:Inter2;
670 Hep3Vector posDown = (Inter1.phi()>Inter2.phi())? Inter2:Inter1;
672 pos = (layer_vir%2==0)? posDown:posUp;
693ToyCgem::ToyCgem(
int layer_vir,
double r,
double x0,
double y0,
double z0,
double rx,
double ry,
double rz)
696 int layer_geo = int(layer_vir/2.);
710 Hep3Vector orin(0,0,1);
729 Hep3Vector LV(
cos(Phi-TMath::Pi()/2.),
sin(Phi-TMath::Pi()/2.),TanL);
double tan(const BesAngle a)
double sin(const BesAngle a)
double cos(const BesAngle a)
HepGeom::Point3D< double > HepPoint3D
void StraightLineConversion_v1(int layer_vir, double lineOriginal[], double lineConverted[])
StraightLine StraightLineConversion(int layer_vir, StraightLine lineOriginal)
void GetLocPos(int layer_vir, Hep3Vector GposUp, Hep3Vector GposDown, HepPoint3D &LposUp, HepPoint3D &LposDown)
HepPoint3D point_invTransform(int layer_vir, HepPoint3D pos)
void initAlignPar(std::string alignFile)
void HelixConversion(int layer_vir, double helixOriginal[], double helixConverted[])
bool getinter(ToyRay ARay, int layer_vir, Hep3Vector &posUp, Hep3Vector &posDown)
HepPoint3D point_transform(int layer_vir, HepPoint3D pos)
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
ToyCgem(int layer_vir, double r, double x0, double y0, double z0, double rx, double ry, double rz)
ToyRay(double dr, double phi, double dz, double tanl)