G4tgbRotationMatrix.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4tgbRotationMatrix.cc 69803 2013-05-15 15:24:50Z gcosmo $
00028 //
00029 //
00030 // class G4tgbRotationMatrix
00031 
00032 // History:
00033 // - Created.                                 P.Arce, CIEMAT (November 2007)
00034 // -------------------------------------------------------------------------
00035 
00036 #include "G4tgbRotationMatrix.hh"
00037 #include "G4RotationMatrix.hh"
00038 #include "G4tgrMessenger.hh"
00039 #include "G4tgrUtils.hh"
00040 #include "G4UIcommand.hh"
00041 
00042 // -------------------------------------------------------------------------
00043 G4tgbRotationMatrix::G4tgbRotationMatrix()
00044   : theTgrRM(0)
00045 {
00046 }
00047 
00048 
00049 // -------------------------------------------------------------------------
00050 G4tgbRotationMatrix::~G4tgbRotationMatrix()
00051 {
00052 }
00053 
00054 
00055 // -------------------------------------------------------------------------
00056 G4tgbRotationMatrix::G4tgbRotationMatrix( G4tgrRotationMatrix* tgr )
00057   : theTgrRM(tgr)
00058 {
00059 }
00060 
00061 
00062 // -------------------------------------------------------------------------
00063 G4RotationMatrix* G4tgbRotationMatrix::BuildG4RotMatrix()
00064 {
00065   std::vector<G4double> values = theTgrRM->GetValues();
00066 
00067   if( values.size() == 3 ) {
00068     return BuildG4RotMatrixFrom3( values );
00069   } else if( values.size() == 6 ) {
00070     return BuildG4RotMatrixFrom6( values );
00071   } else if( values.size() == 9 ) {
00072     return BuildG4RotMatrixFrom9( values );
00073   }
00074   else
00075   {
00076     G4String ErrMessage = "Number of values is: "
00077                         + G4UIcommand::ConvertToString(G4int(values.size()))
00078                         + G4String(". It should be 3, 6, or 9 !");
00079     G4Exception("G4tgbRotationMatrix::BuildG4RotMatrix()",
00080                 "InvalidData", FatalException, ErrMessage);
00081   }
00082   return 0;
00083 }
00084 
00085 
00086 // -------------------------------------------------------------------------
00087 G4RotationMatrix*
00088 G4tgbRotationMatrix::BuildG4RotMatrixFrom3( std::vector<G4double>& values )
00089 {
00090   G4RotationMatrix* rotMat = new G4RotationMatrix();
00091 
00092   rotMat->rotateX( values[0] );
00093   rotMat->rotateY( values[1] );
00094   rotMat->rotateZ( values[2] );
00095 
00096 #ifdef G4VERBOSE
00097   if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00098   {
00099     G4cout << " Constructing new G4RotationMatrix from 3 numbers "
00100            <<  GetName() << " : " << *rotMat << G4endl;
00101   }
00102 #endif
00103 
00104   return rotMat;
00105 }
00106 
00107 
00108 // -------------------------------------------------------------------------
00109 G4RotationMatrix*
00110 G4tgbRotationMatrix::BuildG4RotMatrixFrom6( std::vector<G4double>& values )
00111 {
00112   G4double thetaX = values[0];
00113   G4double phiX = values[1];
00114   G4double thetaY = values[2];
00115   G4double phiY = values[3];
00116   G4double thetaZ = values[4];
00117   G4double phiZ = values[5];
00118 
00119   // build the 3 axis from the values
00120   G4ThreeVector colx(std::sin(thetaX)*std::cos(phiX),
00121                      std::sin(thetaX)*std::sin(phiX),std::cos(thetaX));
00122   G4ThreeVector coly(std::sin(thetaY)*std::cos(phiY),
00123                      std::sin(thetaY)*std::sin(phiY),std::cos(thetaY));
00124   G4ThreeVector colz(std::sin(thetaZ)*std::cos(phiZ),
00125                      std::sin(thetaZ)*std::sin(phiZ),std::cos(thetaZ));
00126 
00127   // Now create a G4RotationMatrix (HepRotation), which can be left handed. 
00128   // This is not foreseen in CLHEP, but can be achieved using the
00129   // constructor which does not check its input arguments!   
00130 
00131   G4Rep3x3 rottemp(colx.x(),coly.x(),colz.x(), // matrix representation
00132                    colx.y(),coly.y(),colz.y(), // (inverted)
00133                    colx.z(),coly.z(),colz.z());
00134   
00135   G4RotationMatrix* rotMat = new G4RotationMatrix(rottemp);
00136 
00137 #ifdef G4VERBOSE
00138   if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00139   {
00140     G4cout << " Constructing new G4RotationMatrix from 6 numbers "
00141            <<  GetName() << " : " << *rotMat << G4endl;
00142   }
00143 #endif
00144 
00145   return rotMat;
00146 }
00147 
00148 // -------------------------------------------------------------------------
00149 G4RotationMatrix*
00150 G4tgbRotationMatrix::BuildG4RotMatrixFrom9( std::vector<G4double>& values )
00151 {
00152   // build the 3 axis from the values
00153   G4ThreeVector colx(values[0],values[1],values[2]);
00154   G4ThreeVector coly(values[3],values[4],values[5]);
00155   G4ThreeVector colz(values[6],values[7],values[8]);
00156 
00157   // Now create a G4RotationMatrix (HepRotation), which can be left handed. 
00158   // This is not foreseen in CLHEP, but can be achieved using the
00159   // constructor which does not check its input arguments!
00160 
00161   G4Rep3x3 rottemp(colx.x(),coly.x(),colz.x(),  // matrix representation
00162                    colx.y(),coly.y(),colz.y(),  // (inverted)
00163                    colx.z(),coly.z(),colz.z());
00164   
00165   G4RotationMatrix* rotMat = new G4RotationMatrix(rottemp);
00166 
00167 #ifdef G4VERBOSE
00168   if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00169   {
00170     G4cout << " Constructing new G4RotationMatrix from 9 numbers "
00171            <<  GetName() << " : " << *rotMat << G4endl;
00172   }
00173 #endif
00174 
00175   return rotMat;
00176 }

Generated on Mon May 27 17:49:58 2013 for Geant4 by  doxygen 1.4.7