File indexing completed on 2026-04-10 07:50:32
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "G4RotationMatrix.hh"
0015 #include <iomanip>
0016 #include <cstring>
0017
0018
0019 struct U4RotationMatrix : public G4RotationMatrix
0020 {
0021 enum {
0022 X = 0x1 << 0 ,
0023 Y = 0x1 << 1 ,
0024 Z = 0x1 << 2
0025 };
0026
0027 static std::string Desc(const G4RotationMatrix* rot );
0028 static U4RotationMatrix* ZZ( double angle );
0029 static U4RotationMatrix* Flip(unsigned mask) ;
0030 static U4RotationMatrix* Flip(const char* axes) ;
0031 static unsigned FlipMask(const char* axes);
0032
0033 U4RotationMatrix(const double* src, bool flip);
0034
0035 U4RotationMatrix(
0036 double xx, double xy, double xz,
0037 double yx, double yy, double yz,
0038 double zx, double zy, double zz
0039 );
0040 };
0041
0042 inline std::string U4RotationMatrix::Desc(const G4RotationMatrix* rot )
0043 {
0044 int wid = 10 ;
0045 int prc = 3 ;
0046
0047 std::stringstream ss ;
0048
0049 ss << "U4RotationMatrix::Desc"
0050 << ( rot ? "" : " null" )
0051 << std::endl
0052 ;
0053
0054 if(rot) ss
0055 << " " << std::fixed << std::setw(wid) << std::setprecision(prc) << rot->xx()
0056 << " " << std::fixed << std::setw(wid) << std::setprecision(prc) << rot->xy()
0057 << " " << std::fixed << std::setw(wid) << std::setprecision(prc) << rot->xz()
0058 << std::endl
0059 << " " << std::fixed << std::setw(wid) << std::setprecision(prc) << rot->yx()
0060 << " " << std::fixed << std::setw(wid) << std::setprecision(prc) << rot->yy()
0061 << " " << std::fixed << std::setw(wid) << std::setprecision(prc) << rot->yz()
0062 << std::endl
0063 << " " << std::fixed << std::setw(wid) << std::setprecision(prc) << rot->zx()
0064 << " " << std::fixed << std::setw(wid) << std::setprecision(prc) << rot->zy()
0065 << " " << std::fixed << std::setw(wid) << std::setprecision(prc) << rot->zz()
0066 << std::endl
0067 ;
0068
0069 std::string s = ss.str();
0070 return s ;
0071 }
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 inline U4RotationMatrix::U4RotationMatrix(const double* a16, bool f )
0098 :
0099 G4RotationMatrix( a16[0], a16[f?4:1], a16[f?8:2],
0100 a16[f?1:4], a16[5], a16[f?9:6],
0101 a16[f?2:8], a16[f?6:9], a16[10] )
0102 {}
0103
0104
0105 inline U4RotationMatrix::U4RotationMatrix(
0106 double xx, double xy, double xz,
0107 double yx, double yy, double yz,
0108 double zx, double zy, double zz
0109 )
0110 :
0111 G4RotationMatrix( xx, xy, xz ,
0112 yx, yy, yz ,
0113 zx, zy, zz )
0114 {}
0115
0116
0117 inline U4RotationMatrix* U4RotationMatrix::ZZ( double phi )
0118 {
0119 return new U4RotationMatrix( cos(phi), sin(phi), 0.,
0120 -sin(phi), cos(phi), 0.,
0121 0., 0., 1. );
0122 }
0123
0124
0125 inline U4RotationMatrix* U4RotationMatrix::Flip(unsigned mask )
0126 {
0127 double XX = (mask & X) ? -1. : 1. ;
0128 double YY = (mask & Y) ? -1. : 1. ;
0129 double ZZ = (mask & Z) ? -1. : 1. ;
0130
0131 return new U4RotationMatrix( XX, 0., 0.,
0132 0., YY, 0.,
0133 0., 0., ZZ );
0134 }
0135 inline unsigned U4RotationMatrix::FlipMask(const char* axes)
0136 {
0137 unsigned mask = 0 ;
0138 if(axes && strstr(axes, "X")) mask |= X ;
0139 if(axes && strstr(axes, "Y")) mask |= Y ;
0140 if(axes && strstr(axes, "Z")) mask |= Z ;
0141 return mask ;
0142 }
0143 inline U4RotationMatrix* U4RotationMatrix::Flip(const char* axes)
0144 {
0145 return Flip(FlipMask(axes));
0146 }
0147
0148