Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:19:14

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 // $Id: PHG4GDMLWriteDefine.cc 68053 2013-03-13 14:39:51Z gcosmo $
0028 //
0029 // class PHG4GDMLWriteDefine Implementation
0030 //
0031 // Original author: Zoltan Torzsok, November 2007
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();   // Rectify matrix from possible roundoff errors
0056 
0057    // Direction of rotation given by left-hand rule; clockwise rotation
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 }