[1035] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: G4tgbRotationMatrix.cc,v 1.8 2008/12/18 12:59:38 gunter Exp $ |
---|
| 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
| 29 | // |
---|
| 30 | // |
---|
| 31 | // class G4tgbRotationMatrix |
---|
| 32 | |
---|
| 33 | // History: |
---|
| 34 | // - Created. P.Arce, CIEMAT (November 2007) |
---|
| 35 | // ------------------------------------------------------------------------- |
---|
| 36 | |
---|
| 37 | #include "G4tgbRotationMatrix.hh" |
---|
| 38 | #include "G4RotationMatrix.hh" |
---|
| 39 | #include "G4tgrMessenger.hh" |
---|
| 40 | #include "G4tgrUtils.hh" |
---|
| 41 | #include "G4UIcommand.hh" |
---|
| 42 | |
---|
| 43 | // ------------------------------------------------------------------------- |
---|
| 44 | G4tgbRotationMatrix::G4tgbRotationMatrix() |
---|
| 45 | { |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | // ------------------------------------------------------------------------- |
---|
| 50 | G4tgbRotationMatrix::~G4tgbRotationMatrix() |
---|
| 51 | { |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | // ------------------------------------------------------------------------- |
---|
| 56 | G4tgbRotationMatrix::G4tgbRotationMatrix( G4tgrRotationMatrix* tgr ) |
---|
| 57 | { |
---|
| 58 | theTgrRM = tgr; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | // ------------------------------------------------------------------------- |
---|
| 63 | G4RotationMatrix* G4tgbRotationMatrix::BuildG4RotMatrix() |
---|
| 64 | { |
---|
| 65 | std::vector<G4double> values = theTgrRM->GetValues(); |
---|
| 66 | |
---|
| 67 | if( values.size() == 3 ) { |
---|
| 68 | return BuildG4RotMatrixFrom3( values ); |
---|
| 69 | } else if( values.size() == 6 ) { |
---|
| 70 | return BuildG4RotMatrixFrom6( values ); |
---|
| 71 | } else if( values.size() == 9 ) { |
---|
| 72 | return BuildG4RotMatrixFrom9( values ); |
---|
| 73 | } |
---|
| 74 | else |
---|
| 75 | { |
---|
| 76 | G4String ErrMessage = "Number of values is: " |
---|
| 77 | + G4UIcommand::ConvertToString(G4int(values.size())) |
---|
| 78 | + G4String(". It should be 3, 6, or 9 !"); |
---|
| 79 | G4Exception("G4tgbRotationMatrix::BuildG4RotMatrix()", |
---|
| 80 | "InvalidData", FatalException, ErrMessage); |
---|
| 81 | } |
---|
| 82 | return 0; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | // ------------------------------------------------------------------------- |
---|
| 87 | G4RotationMatrix* |
---|
| 88 | G4tgbRotationMatrix::BuildG4RotMatrixFrom3( std::vector<G4double>& values ) |
---|
| 89 | { |
---|
| 90 | G4RotationMatrix* rotMat = new G4RotationMatrix(); |
---|
| 91 | |
---|
| 92 | rotMat->rotateX( values[0] ); |
---|
| 93 | rotMat->rotateY( values[1] ); |
---|
| 94 | rotMat->rotateZ( values[2] ); |
---|
| 95 | |
---|
| 96 | #ifdef G4VERBOSE |
---|
| 97 | if( G4tgrMessenger::GetVerboseLevel() >= 1 ) |
---|
| 98 | { |
---|
| 99 | G4cout << " Constructing new G4RotationMatrix from 3 numbers " |
---|
| 100 | << GetName() << " : " << *rotMat << G4endl; |
---|
| 101 | } |
---|
| 102 | #endif |
---|
| 103 | |
---|
| 104 | return rotMat; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | // ------------------------------------------------------------------------- |
---|
| 109 | G4RotationMatrix* |
---|
| 110 | G4tgbRotationMatrix::BuildG4RotMatrixFrom6( std::vector<G4double>& values ) |
---|
| 111 | { |
---|
| 112 | G4double thetaX = values[0]; |
---|
| 113 | G4double phiX = values[1]; |
---|
| 114 | G4double thetaY = values[2]; |
---|
| 115 | G4double phiY = values[3]; |
---|
| 116 | G4double thetaZ = values[4]; |
---|
| 117 | G4double phiZ = values[5]; |
---|
| 118 | |
---|
| 119 | // build the 3 axis from the values |
---|
| 120 | CLHEP::Hep3Vector colx(std::sin(thetaX)*std::cos(phiX), |
---|
| 121 | std::sin(thetaX)*std::sin(phiX),std::cos(thetaX)); |
---|
| 122 | CLHEP::Hep3Vector coly(std::sin(thetaY)*std::cos(phiY), |
---|
| 123 | std::sin(thetaY)*std::sin(phiY),std::cos(thetaY)); |
---|
| 124 | CLHEP::Hep3Vector colz(std::sin(thetaZ)*std::cos(phiZ), |
---|
| 125 | std::sin(thetaZ)*std::sin(phiZ),std::cos(thetaZ)); |
---|
| 126 | |
---|
| 127 | // Now create a G4RotationMatrix (HepRotation), which can be left handed. |
---|
| 128 | // This is not foreseen in CLHEP, but can be achieved using the |
---|
| 129 | // constructor which does not check its input arguments! |
---|
| 130 | |
---|
| 131 | CLHEP::HepRep3x3 rottemp(colx.x(),coly.x(),colz.x(), // matrix representation |
---|
| 132 | colx.y(),coly.y(),colz.y(), // (inverted) |
---|
| 133 | colx.z(),coly.z(),colz.z()); |
---|
| 134 | |
---|
| 135 | G4RotationMatrix* rotMat = new G4RotationMatrix(rottemp); |
---|
| 136 | |
---|
| 137 | #ifdef G4VERBOSE |
---|
| 138 | if( G4tgrMessenger::GetVerboseLevel() >= 1 ) |
---|
| 139 | { |
---|
| 140 | G4cout << " Constructing new G4RotationMatrix from 6 numbers " |
---|
| 141 | << GetName() << " : " << *rotMat << G4endl; |
---|
| 142 | } |
---|
| 143 | #endif |
---|
| 144 | |
---|
| 145 | return rotMat; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | // ------------------------------------------------------------------------- |
---|
| 149 | G4RotationMatrix* |
---|
| 150 | G4tgbRotationMatrix::BuildG4RotMatrixFrom9( std::vector<G4double>& values ) |
---|
| 151 | { |
---|
| 152 | // build the 3 axis from the values |
---|
| 153 | CLHEP::Hep3Vector colx(values[0],values[1],values[2]); |
---|
| 154 | CLHEP::Hep3Vector coly(values[3],values[4],values[5]); |
---|
| 155 | CLHEP::Hep3Vector colz(values[6],values[7],values[8]); |
---|
| 156 | |
---|
| 157 | // Now create a G4RotationMatrix (HepRotation), which can be left handed. |
---|
| 158 | // This is not foreseen in CLHEP, but can be achieved using the |
---|
| 159 | // constructor which does not check its input arguments! |
---|
| 160 | |
---|
| 161 | CLHEP::HepRep3x3 rottemp(colx.x(),coly.x(),colz.x(), // matrix representation |
---|
| 162 | colx.y(),coly.y(),colz.y(), // (inverted) |
---|
| 163 | colx.z(),coly.z(),colz.z()); |
---|
| 164 | |
---|
| 165 | G4RotationMatrix* rotMat = new G4RotationMatrix(rottemp); |
---|
| 166 | |
---|
| 167 | #ifdef G4VERBOSE |
---|
| 168 | if( G4tgrMessenger::GetVerboseLevel() >= 1 ) |
---|
| 169 | { |
---|
| 170 | G4cout << " Constructing new G4RotationMatrix from 9 numbers " |
---|
| 171 | << GetName() << " : " << *rotMat << G4endl; |
---|
| 172 | } |
---|
| 173 | #endif |
---|
| 174 | |
---|
| 175 | return rotMat; |
---|
| 176 | } |
---|