source: trunk/source/g3tog4/src/G4gsrotm.cc @ 1202

Last change on this file since 1202 was 965, checked in by garnier, 15 years ago

update g3tog4

File size: 4.0 KB
Line 
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: G4gsrotm.cc,v 1.12 2006/06/29 18:14:55 gunter Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30#include "G3toG4.hh"
31#include "G3RotTable.hh"
32#include "G4ThreeVector.hh"
33#include "G3toG4RotationMatrix.hh"
34
35void PG4gsrotm(G4String tokens[])
36{
37    // fill the parameter containers
38    G3fillParams(tokens,PTgsrotm);
39
40    // interpret the parameters
41    G4int irot = Ipar[0];
42   
43    // the angles in Geant are in degrees
44    G4double theta1 = Rpar[0];
45    G4double phi1   = Rpar[1];
46    G4double theta2 = Rpar[2];
47    G4double phi2   = Rpar[3];
48    G4double theta3 = Rpar[4];
49    G4double phi3   = Rpar[5];
50
51    G4gsrotm(irot, theta1,phi1, theta2,phi2, theta3,phi3);
52}
53
54void G4gsrotm(G4int irot, G4double theta1, G4double phi1,
55              G4double theta2, G4double phi2, G4double theta3, G4double phi3)
56{
57    G4double degrad = pi/180;
58   
59    G4double th1r = theta1*degrad;
60    G4double th2r = theta2*degrad;
61    G4double th3r = theta3*degrad;
62   
63    G4double phi1r = phi1*degrad;
64    G4double phi2r = phi2*degrad;
65    G4double phi3r = phi3*degrad;
66   
67        // Construct unit vectors
68   
69    G4ThreeVector x(std::sin(th1r)*std::cos(phi1r), std::sin(th1r)*std::sin(phi1r), std::cos(th1r));
70    G4ThreeVector y(std::sin(th2r)*std::cos(phi2r), std::sin(th2r)*std::sin(phi2r), std::cos(th2r));
71    G4ThreeVector z(std::sin(th3r)*std::cos(phi3r), std::sin(th3r)*std::sin(phi3r), std::cos(th3r));
72
73        // check for orthonormality and left-handedness
74
75    G4double check = (x.cross(y))*z;
76    G4double tol = 1.0e-3;
77       
78    if (1-std::abs(check)>tol) {
79        G4cerr << "Coordinate axes forming rotation matrix "
80               << irot << " are not orthonormal.(" << 1-std::abs(check) << ")" 
81         << G4endl;
82        G4cerr << " theta1=" << theta1;
83        G4cerr << " phi1=" << phi1;
84        G4cerr << " theta2=" << theta2;
85        G4cerr << " phi2=" << phi2;
86        G4cerr << " theta3=" << theta3;
87        G4cerr << " phi3=" << phi3;
88        G4cerr << G4endl;
89        G4Exception("G4gsrotm error");
90    }
91    //else if (1+check<=tol) {
92    //    G4cerr << "G4gsrotm warning: coordinate axes forming rotation "
93    //           << "matrix " << irot << " are left-handed" << G4endl;
94    //}
95   
96    G3toG4RotationMatrix* rotp = new G3toG4RotationMatrix;
97
98    rotp->SetRotationMatrixByRow(x, y, z);
99   
100        // add it to the List
101
102    G3Rot.Put(irot, rotp);
103}
Note: See TracBrowser for help on using the repository browser.