Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-23 09:11:43

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 // G4ScaleTransform inline implementation.
0027 // Based on implementation provided in Root
0028 //
0029 // Author: Gabriele Cosmo (CERN), 18.02.2016 - Initial version
0030 //         Evgueni Tcherniaev (CERN), 11.03.2016 - Added normals transforms
0031 // --------------------------------------------------------------------
0032 
0033 inline G4ScaleTransform::G4ScaleTransform()
0034   : fScale(1.,1.,1.), fIScale(1.,1.,1.)
0035 {
0036 }
0037 
0038 inline G4ScaleTransform::G4ScaleTransform(G4double sx, G4double sy, G4double sz)
0039   : fScale(sx,sy,sz), fIScale()
0040 {
0041   Init();
0042 }  
0043 
0044 inline G4ScaleTransform::G4ScaleTransform(const G4ThreeVector& scale)
0045   : fScale(scale), fIScale()
0046 {
0047   Init();
0048 }
0049         
0050 inline G4ScaleTransform::G4ScaleTransform(const G4Scale3D& scale)
0051   : fScale(scale.xx(), scale.yy(), scale.zz()), fIScale()
0052 {
0053   Init();
0054 }
0055 
0056 inline G4ScaleTransform::G4ScaleTransform(const G4ScaleTransform& right)
0057   : fScale(right.fScale), fIScale(right.fIScale),
0058     flFactor(right.flFactor), fgFactor(right.fgFactor)
0059 {
0060 }
0061   
0062 inline G4ScaleTransform&
0063 G4ScaleTransform::operator=(const G4ScaleTransform& right)
0064 {
0065   fScale = right.fScale;
0066   fIScale = right.fIScale;
0067   flFactor = right.flFactor;
0068   fgFactor = right.fgFactor;
0069   return *this;
0070 }
0071           
0072 inline void G4ScaleTransform::Init()
0073 {
0074   if (!((fScale.x()>0) && (fScale.y()>0) && (fScale.z()>0)))
0075   {
0076      G4Exception("G4ScaleTransform::Init()", "GeomMgt0001",
0077                  FatalException, "Scale transformation must be positive!");
0078   }
0079   fIScale.set(1./fScale.x(), 1./fScale.y(), 1./fScale.z());
0080   flFactor = std::min(std::min(fIScale.x(), fIScale.y()), fIScale.z());
0081   fgFactor = std::min(std::min(fScale.x(), fScale.y()), fScale.z());
0082 }
0083 
0084 inline const G4ThreeVector& G4ScaleTransform::GetScale() const
0085 {
0086   return fScale;
0087 }
0088 
0089 inline const G4ThreeVector& G4ScaleTransform::GetInvScale() const
0090 {
0091   return fIScale;
0092 }
0093 
0094 inline void G4ScaleTransform::SetScale(const G4ThreeVector& scale)
0095 {
0096   fScale = scale;
0097   Init();
0098 }
0099 
0100 inline void G4ScaleTransform::SetScale(const G4Scale3D& scale)
0101 {
0102   fScale.set(scale.xx(), scale.yy(), scale.zz());
0103   Init();
0104 }
0105  
0106 inline void G4ScaleTransform::SetScale(G4double sx, G4double sy, G4double sz)
0107 {
0108   fScale.set(sx,sy,sz);
0109   Init();
0110 }
0111 
0112 inline void G4ScaleTransform::Transform(const G4ThreeVector& global,
0113                                               G4ThreeVector& local) const
0114 {
0115   local.set(global.x()*fIScale.x(),
0116             global.y()*fIScale.y(),
0117             global.z()*fIScale.z());      
0118 }
0119   
0120 inline G4ThreeVector
0121 G4ScaleTransform::Transform(const G4ThreeVector& global) const
0122 {
0123   G4ThreeVector local(global.x()*fIScale.x(),
0124                       global.y()*fIScale.y(),
0125                       global.z()*fIScale.z());
0126   return local;
0127 }     
0128     
0129 inline void
0130 G4ScaleTransform::InverseTransform(const G4ThreeVector& local, 
0131                                          G4ThreeVector& global) const
0132 {
0133   global.set(local.x()*fScale.x(),
0134              local.y()*fScale.y(),
0135              local.z()*fScale.z());
0136 }
0137 
0138 inline G4ThreeVector
0139 G4ScaleTransform::InverseTransform(const G4ThreeVector& local) const
0140 {
0141   G4ThreeVector global(local.x()*fScale.x(),
0142                        local.y()*fScale.y(),
0143                        local.z()*fScale.z());
0144   return global;
0145 }
0146 
0147 inline void
0148 G4ScaleTransform::TransformNormal(const G4ThreeVector& global,
0149                                         G4ThreeVector& local) const
0150 {
0151   local.set(global.x()*fIScale.y()*fIScale.z(),
0152             global.y()*fIScale.z()*fIScale.x(),
0153             global.z()*fIScale.x()*fIScale.y());      
0154 }
0155   
0156 inline G4ThreeVector
0157 G4ScaleTransform::TransformNormal(const G4ThreeVector& global) const
0158 {
0159   G4ThreeVector local(global.x()*fIScale.y()*fIScale.z(),
0160                       global.y()*fIScale.z()*fIScale.x(),
0161                       global.z()*fIScale.x()*fIScale.y());
0162   return local;
0163 }     
0164     
0165 inline void
0166 G4ScaleTransform::InverseTransformNormal(const G4ThreeVector& local, 
0167                                                G4ThreeVector& global) const
0168 {
0169   global.set(local.x()*fScale.y()*fScale.z(),
0170              local.y()*fScale.z()*fScale.x(),
0171              local.z()*fScale.x()*fScale.y());
0172 }
0173 
0174 inline G4ThreeVector
0175 G4ScaleTransform::InverseTransformNormal(const G4ThreeVector& local) const
0176 {
0177   G4ThreeVector global(local.x()*fScale.y()*fScale.z(),
0178                        local.y()*fScale.z()*fScale.x(),
0179                        local.z()*fScale.x()*fScale.y());
0180   return global;
0181 }
0182 
0183 inline G4double
0184 G4ScaleTransform::TransformDistance(G4double dist,
0185                                     const G4ThreeVector& dir) const
0186 {
0187   G4ThreeVector v(dir.x()*fIScale.x(),
0188                   dir.y()*fIScale.y(),
0189                   dir.z()*fIScale.z());
0190   G4double scale = std::sqrt(v.dot(v));
0191   return ( scale*dist );
0192 }
0193 
0194 inline G4double G4ScaleTransform::TransformDistance(G4double safety) const
0195 {
0196   return ( safety*flFactor );
0197 }
0198     
0199 inline G4double
0200 G4ScaleTransform::InverseTransformDistance(G4double dist,
0201                                            const G4ThreeVector& dir) const
0202 {
0203   G4ThreeVector v(dir.x()*fScale.x(),
0204                   dir.y()*fScale.y(),
0205                   dir.z()*fScale.z());
0206   G4double scale = std::sqrt(v.dot(v));
0207   return ( scale*dist );
0208 }
0209 
0210 inline G4double
0211 G4ScaleTransform::InverseTransformDistance(G4double safety) const
0212 {
0213   return ( safety*fgFactor );
0214 }
0215 
0216 inline
0217 std::ostream& operator << (std::ostream& os, const G4ScaleTransform& transf)
0218 {
0219   std::streamsize oldPrec = os.precision(6); 
0220 
0221   os << "  Scale Transformation: " << G4endl
0222      << "    x,y,z: "
0223        << transf.GetScale().x()  << " "
0224        << transf.GetScale().y()  << " "
0225        << transf.GetScale().z()  << G4endl
0226      << "    Inverse x,y,z: "
0227        << transf.GetInvScale().x() << " "
0228        << transf.GetInvScale().y() << " "
0229        << transf.GetInvScale().z() << G4endl;
0230   
0231   os.precision(oldPrec); 
0232 
0233   return os; 
0234 }