19 #include <CLHEP/Units/SystemOfUnits.h>
22 #include <TGeoMatrix.h>
25 static constexpr
const double CM_2_MM = (CLHEP::centimeter/dd4hep::centimeter);
28 struct MyTransform3D :
public G4Transform3D {
30 MyTransform3D(
double XX,
double XY,
double XZ,
double DX,
31 double YX,
double YY,
double YZ,
double DY,
32 double ZX,
double ZY,
double ZZ,
double DZ)
33 : G4Transform3D(XX, XY, XZ, DX, YX, YY, YZ, DY, ZX, ZY, ZZ, DZ) {
36 MyTransform3D(
const double* t,
const double* r)
37 : G4Transform3D(r[0],r[1],r[2],t[0]*
CM_2_MM,r[3],r[4],r[5],t[1]*
CM_2_MM,r[6],r[7],r[8],t[2]*
CM_2_MM) {
39 MyTransform3D(
const double* t)
40 : G4Transform3D(1.0, 0.0, 0.0, t[0]*
CM_2_MM, 0.0, 1.0, 0.0, t[1]*
CM_2_MM, 0.0, 0.0, 1.0, t[2]*
CM_2_MM) {
45 class MyG4RotationMatrix :
public G4RotationMatrix {
47 MyG4RotationMatrix() : G4RotationMatrix() {}
48 MyG4RotationMatrix(
const double* r) : G4RotationMatrix(r[0],r[1],r[2],r[3],r[4],r[5],r[6],r[7],r[8]) {
54 return matrix->IsRotation() ? MyG4RotationMatrix(matrix->GetRotationMatrix()) : MyG4RotationMatrix();
62 return matrix->IsRotation() ? MyG4RotationMatrix(matrix->GetRotationMatrix()) : MyG4RotationMatrix();
71 rot.GetComponents(r, r+9);
72 return MyG4RotationMatrix(r);
80 return MyTransform3D(translation);
84 return MyTransform3D(translation, rotation);
88 transform = MyTransform3D(translation);
92 transform = MyTransform3D(translation, rotation);
100 return matrix->IsRotation()
101 ?
g4Transform(matrix->GetTranslation(), matrix->GetRotationMatrix())
107 ?
g4Transform(matrix->GetTranslation(), matrix->GetRotationMatrix(), transform)
108 :
g4Transform(matrix->GetTranslation(), transform);
120 return rotation->IsRotation()
121 ?
g4Transform(translation->GetTranslation(), rotation->GetRotationMatrix())
126 double r[9], t[3] = {pos.X(), pos.Y(), pos.Z()};
127 rot.GetComponents(r, r+9);
132 double r[9], t[3] = {pos.X(), pos.Y(), pos.Z()};
133 rot.GetComponents(r, r+9);
144 matrix.GetDecomposition(rot, pos);
151 matrix.GetDecomposition(rot, pos);
158 const G4Transform3D&
delta,
160 const std::function<
void(
const G4Transform3D&
delta)>& callback)
162 G4Transform3D transform(start);
163 for( std::size_t i = 0; i < count; ++i ) {
165 transform = transform *
delta;
173 const G4Transform3D& delta1,
175 const G4Transform3D& delta2,
177 const std::function<
void(
const G4Transform3D&
delta)>& callback)
179 G4Transform3D transform2 = start;
180 for(std::size_t j = 0; j < count2; ++j) {
181 G4Transform3D transform1 = transform2;
183 transform2 = transform2 * delta2;
191 const G4Transform3D& delta1,
193 const G4Transform3D& delta2,
195 const G4Transform3D& delta3,
197 const std::function<
void(
const G4Transform3D&
delta)>& callback)
199 G4Transform3D transform3 = start;
200 for(std::size_t k = 0; k < count3; ++k) {
201 G4Transform3D transform2 = transform3;
203 transform3 = transform3 * delta3;
209 constexpr
double eps = 2e-14;
211 if ( fabs(tr.xx()) > (1e0-eps) &&
212 fabs(tr.yy()) > (1e0-eps) &&
213 fabs(tr.zz()) > (1e0-eps) ) {
214 if ( fabs(tr.dx()) > eps )
215 return { tr.dx(), kYAxis };
216 else if ( fabs(tr.dy()) > eps )
217 return { tr.dy(), kYAxis };
218 else if ( fabs(tr.dz()) > eps )
219 return { tr.dz(), kZAxis };
221 else if ( tr.getTranslation().mag() > eps && fabs(tr.dz()) < eps ) {
222 return { tr.getTranslation().rho(), kRho };
224 else if ( fabs(tr.dz()) < eps ) {
225 return { tr.getRotation().phi(), kPhi };
227 except(
"Geant4Converter",
"Invalid volume parametrization matrix. Unknown Axis!");
228 return { 0e0, kUndefined };