QwGeant4
src/QweakSimTrap.cc
Go to the documentation of this file.
1 #include "QweakSimTrap.hh"
2 #include "G4SystemOfUnits.hh"
3 
4 G4double QweakSimTrap::FixPlane(G4ThreeVector pt[8], G4int iface[4])
5 {
6  G4ThreeVector& p1 = pt[iface[0]];
7  G4ThreeVector& p2 = pt[iface[1]];
8  G4ThreeVector& p3 = pt[iface[2]];
9  G4ThreeVector& p4 = pt[iface[3]];
10 
11  struct TrapSidePlane
12  {
13  G4double a,b,c,d; // Normal unit vector (a,b,c) and offset (d)
14  } plane;
15 
16  G4ThreeVector normal = ((p4 - p2).cross(p3 - p1)).unit();
17  if (std::abs(normal.x()) < DBL_EPSILON) normal.setX(0);
18  if (std::abs(normal.y()) < DBL_EPSILON) normal.setY(0);
19  if (std::abs(normal.z()) < DBL_EPSILON) normal.setZ(0);
20  normal = normal.unit();
21 
22  G4ThreeVector centre = (p1 + p2 + p3 + p4)*0.25;
23  plane.a = normal.x();
24  plane.b = normal.y();
25  plane.c = normal.z();
26  plane.d = -normal.dot(centre);
27 
28  // compute distances and check planarity
29  G4double sd1 = (normal.dot(p1) + plane.d);
30  G4double sd2 = (normal.dot(p2) + plane.d);
31  G4double sd3 = (normal.dot(p3) + plane.d);
32  G4double sd4 = (normal.dot(p4) + plane.d);
33  if (std::sqrt(sd1*sd1+sd2*sd2+sd3*sd3+sd4*sd4)/4.0 > 1*mm) {
34  G4cerr << "Warning! Not even QweakSimTrap is going to help here." << G4endl;
35  G4cerr << "There is something wrong with your QweakSimTrap parameters." << G4endl;
36  }
37 
38  // fix along xhat
39  G4ThreeVector xhat(1.0,0.0,0.0);
40  G4double xd = (normal.dot(centre + xhat) + plane.d);
41  p1 -= sd1/xd * xhat;
42  p2 -= sd2/xd * xhat;
43  p3 -= sd3/xd * xhat;
44  p4 -= sd4/xd * xhat;
45 
46  // compute distances and check planarity
47  G4double sd1c = (normal.dot(p1) + plane.d);
48  G4double sd2c = (normal.dot(p2) + plane.d);
49  G4double sd3c = (normal.dot(p3) + plane.d);
50  G4double sd4c = (normal.dot(p4) + plane.d);
51 
52  return std::sqrt(sd1c*sd1c+sd2c*sd2c+sd3c*sd3c+sd4c*sd4c)/4.0;
53 }
54 
55 QweakSimTrap::QweakSimTrap(const G4String& pName,
56  G4double pDz, G4double pTheta, G4double pPhi,
57  G4double pDy1, G4double pDx1, G4double pDx2, G4double pAlp1,
58  G4double pDy2, G4double pDx3, G4double pDx4, G4double pAlp2)
59 : G4Trap(pName)
60 {
61  G4cout << "You are using a QweakSim trapezoid." << G4endl;
62 
63  G4double fDz = pDz;
64  G4double fTthetaCphi = std::tan(pTheta)*std::cos(pPhi);
65  G4double fTthetaSphi = std::tan(pTheta)*std::sin(pPhi);
66 
67  G4double fDy1, fDx1, fDx2, fTalpha1;
68  G4double fDy2, fDx3, fDx4, fTalpha2;
69  fDy1 = pDy1; fDx1 = pDx1; fDx2 = pDx2; fTalpha1 = std::tan(pAlp1);
70  fDy2 = pDy2; fDx3 = pDx3; fDx4 = pDx4; fTalpha2 = std::tan(pAlp2);
71 
72  G4double DzTthetaCphi = fDz*fTthetaCphi;
73  G4double DzTthetaSphi = fDz*fTthetaSphi;
74  G4double Dy1Talpha1 = fDy1*fTalpha1;
75  G4double Dy2Talpha2 = fDy2*fTalpha2;
76 
77  G4ThreeVector pt[8] =
78  {
79  G4ThreeVector(-DzTthetaCphi-Dy1Talpha1-fDx1,-DzTthetaSphi-fDy1,-fDz),
80  G4ThreeVector(-DzTthetaCphi-Dy1Talpha1+fDx1,-DzTthetaSphi-fDy1,-fDz),
81  G4ThreeVector(-DzTthetaCphi+Dy1Talpha1-fDx2,-DzTthetaSphi+fDy1,-fDz),
82  G4ThreeVector(-DzTthetaCphi+Dy1Talpha1+fDx2,-DzTthetaSphi+fDy1,-fDz),
83  G4ThreeVector( DzTthetaCphi-Dy2Talpha2-fDx3, DzTthetaSphi-fDy2, fDz),
84  G4ThreeVector( DzTthetaCphi-Dy2Talpha2+fDx3, DzTthetaSphi-fDy2, fDz),
85  G4ThreeVector( DzTthetaCphi+Dy2Talpha2-fDx4, DzTthetaSphi+fDy2, fDz),
86  G4ThreeVector( DzTthetaCphi+Dy2Talpha2+fDx4, DzTthetaSphi+fDy2, fDz)
87  };
88 
89  G4int iface[2][4] = { {0,2,6,4}, {1,3,5,7} }; // ~-X, ~+X
90  for (G4int i=0; i<2; ++i)
91  {
92  G4double d = FixPlane(pt,iface[i]);
93  }
94 
95  fDx1 = 0.5*(pt[1]-pt[0]).x();
96  fDx2 = 0.5*(pt[3]-pt[2]).x();
97  fDx3 = 0.5*(pt[5]-pt[4]).x();
98  fDx4 = 0.5*(pt[7]-pt[6]).x();
99 
100  // Pass to G4Trap
101  SetAllParameters(pDz, pTheta, pPhi, pDy1, fDx1, fDx2, pAlp1, pDy2, fDx3, fDx4, pAlp2);
102 }
QweakSimTrap(const G4String &pName, G4double pDz, G4double pTheta, G4double pPhi, G4double pDy1, G4double pDx1, G4double pDx2, G4double pAlp1, G4double pDy2, G4double pDx3, G4double pDx4, G4double pAlp2)
G4double FixPlane(G4ThreeVector pt[8], G4int iface[4])