File indexing completed on 2025-08-06 08:19:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #include "PHG4GDMLWriteDefine.hh"
0036 #include <Geant4/G4SystemOfUnits.hh>
0037
0038 const G4double PHG4GDMLWriteDefine::kRelativePrecision = DBL_EPSILON;
0039 const G4double PHG4GDMLWriteDefine::kAngularPrecision = DBL_EPSILON;
0040 const G4double PHG4GDMLWriteDefine::kLinearPrecision = DBL_EPSILON;
0041
0042 PHG4GDMLWriteDefine::PHG4GDMLWriteDefine()
0043 : PHG4GDMLWrite(), defineElement(0)
0044 {
0045 }
0046
0047 PHG4GDMLWriteDefine::~PHG4GDMLWriteDefine()
0048 {
0049 }
0050
0051 G4ThreeVector PHG4GDMLWriteDefine::GetAngles(const G4RotationMatrix& mtx)
0052 {
0053 G4double x,y,z;
0054 G4RotationMatrix mat = mtx;
0055 mat.rectify();
0056
0057
0058
0059 static const G4double kMatrixPrecision = 10E-10;
0060 const G4double cosb = std::sqrt(mtx.xx()*mtx.xx()+mtx.yx()*mtx.yx());
0061
0062 if (cosb > kMatrixPrecision)
0063 {
0064 x = std::atan2(mtx.zy(),mtx.zz());
0065 y = std::atan2(-mtx.zx(),cosb);
0066 z = std::atan2(mtx.yx(),mtx.xx());
0067 }
0068 else
0069 {
0070 x = std::atan2(-mtx.yz(),mtx.yy());
0071 y = std::atan2(-mtx.zx(),cosb);
0072 z = 0.0;
0073 }
0074
0075 return G4ThreeVector(x,y,z);
0076 }
0077
0078 void PHG4GDMLWriteDefine::
0079 Scale_vectorWrite(xercesc::DOMElement* element, const G4String& tag,
0080 const G4String& name, const G4ThreeVector& scl)
0081 {
0082 const G4double x = (std::fabs(scl.x()-1.0) < kRelativePrecision)
0083 ? 1.0 : scl.x();
0084 const G4double y = (std::fabs(scl.y()-1.0) < kRelativePrecision)
0085 ? 1.0 : scl.y();
0086 const G4double z = (std::fabs(scl.z()-1.0) < kRelativePrecision)
0087 ? 1.0 : scl.z();
0088
0089 xercesc::DOMElement* scaleElement = NewElement(tag);
0090 scaleElement->setAttributeNode(NewAttribute("name",name));
0091 scaleElement->setAttributeNode(NewAttribute("x",x));
0092 scaleElement->setAttributeNode(NewAttribute("y",y));
0093 scaleElement->setAttributeNode(NewAttribute("z",z));
0094 element->appendChild(scaleElement);
0095 }
0096
0097 void PHG4GDMLWriteDefine::
0098 Rotation_vectorWrite(xercesc::DOMElement* element, const G4String& tag,
0099 const G4String& name, const G4ThreeVector& rot)
0100 {
0101 const G4double x = (std::fabs(rot.x()) < kAngularPrecision) ? 0.0 : rot.x();
0102 const G4double y = (std::fabs(rot.y()) < kAngularPrecision) ? 0.0 : rot.y();
0103 const G4double z = (std::fabs(rot.z()) < kAngularPrecision) ? 0.0 : rot.z();
0104
0105 xercesc::DOMElement* rotationElement = NewElement(tag);
0106 rotationElement->setAttributeNode(NewAttribute("name",name));
0107 rotationElement->setAttributeNode(NewAttribute("x",x/degree));
0108 rotationElement->setAttributeNode(NewAttribute("y",y/degree));
0109 rotationElement->setAttributeNode(NewAttribute("z",z/degree));
0110 rotationElement->setAttributeNode(NewAttribute("unit","deg"));
0111 element->appendChild(rotationElement);
0112 }
0113
0114 void PHG4GDMLWriteDefine::
0115 Position_vectorWrite(xercesc::DOMElement* element, const G4String& tag,
0116 const G4String& name, const G4ThreeVector& pos)
0117 {
0118 const G4double x = (std::fabs(pos.x()) < kLinearPrecision) ? 0.0 : pos.x();
0119 const G4double y = (std::fabs(pos.y()) < kLinearPrecision) ? 0.0 : pos.y();
0120 const G4double z = (std::fabs(pos.z()) < kLinearPrecision) ? 0.0 : pos.z();
0121
0122 xercesc::DOMElement* positionElement = NewElement(tag);
0123 positionElement->setAttributeNode(NewAttribute("name",name));
0124 positionElement->setAttributeNode(NewAttribute("x",x/mm));
0125 positionElement->setAttributeNode(NewAttribute("y",y/mm));
0126 positionElement->setAttributeNode(NewAttribute("z",z/mm));
0127 positionElement->setAttributeNode(NewAttribute("unit","mm"));
0128 element->appendChild(positionElement);
0129 }
0130
0131 void PHG4GDMLWriteDefine::DefineWrite(xercesc::DOMElement* element)
0132 {
0133 std::cout << "PHG4GDML: Writing definitions..." << std::endl;
0134
0135 defineElement = NewElement("define");
0136 element->appendChild(defineElement);
0137 }