source: trunk/source/persistency/ascii/src/G4tgbPlaceParamCircle.cc @ 1347

Last change on this file since 1347 was 1347, checked in by garnier, 13 years ago

geant4 tag 9.4

File size: 5.7 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: G4tgbPlaceParamCircle.cc,v 1.6 2010/10/13 07:56:55 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
29//
30//
31// class G4tgbPlaceParamCircle
32
33// History:
34// - Created.                                 P.Arce, CIEMAT (November 2007)
35// -------------------------------------------------------------------------
36
37#include "G4tgbPlaceParamCircle.hh"
38#include "G4tgrPlaceParameterisation.hh"
39#include "G4ThreeVector.hh"
40#include "G4RotationMatrix.hh"
41#include "G4VPhysicalVolume.hh"
42#include "G4tgrUtils.hh"
43#include "G4tgrMessenger.hh"
44
45// -------------------------------------------------------------------------
46G4tgbPlaceParamCircle::~G4tgbPlaceParamCircle()
47{
48}
49
50
51// -------------------------------------------------------------------------
52G4tgbPlaceParamCircle::
53G4tgbPlaceParamCircle( G4tgrPlaceParameterisation* tgrParam )
54  : G4tgbPlaceParameterisation(tgrParam)
55{
56  //---- Get translation and rotation
57  if( tgrParam->GetParamType() == "CIRCLE" )
58  {
59    CheckNExtraData( tgrParam, 7, WLSIZE_EQ, "G4tgbPlaceParamCircle:");
60    theCircleAxis = G4ThreeVector( tgrParam->GetExtraData()[4],
61                                   tgrParam->GetExtraData()[5],
62                                   tgrParam->GetExtraData()[6] );
63
64    G4ThreeVector zaxis(0.,0.,-1.);
65    if( zaxis.cross(theCircleAxis).mag() > 1.E-6 )
66    {
67      theDirInPlane = zaxis.cross(theCircleAxis);
68    }
69    else
70    { 
71      theDirInPlane = theCircleAxis.cross(G4ThreeVector(0.,-1.,0.));
72    }
73    theAxis = kZAxis;
74  }
75  else
76  {
77    CheckNExtraData( tgrParam, 4, WLSIZE_EQ, "G4tgbPlaceParamCircle:");
78    if( tgrParam->GetParamType() == "CIRCLE_XY" ) {
79      theCircleAxis = G4ThreeVector(0.,0.,1.);
80      theDirInPlane = G4ThreeVector(1.,0.,0.);
81      theAxis = kZAxis;
82    } else if( tgrParam->GetParamType() == "CIRCLE_XZ" ) {
83      theCircleAxis = G4ThreeVector(0.,1.,0.);
84      theDirInPlane = G4ThreeVector(1.,0.,0.);
85      theAxis = kYAxis;
86    } else if( tgrParam->GetParamType() == "CIRCLE_YZ" ) {
87      theCircleAxis = G4ThreeVector(1.,0.,0.);
88      theDirInPlane = G4ThreeVector(0.,1.,0.);
89      theAxis = kXAxis;
90    }
91  }
92
93  if( theCircleAxis.mag() == 0. )
94  {
95    G4Exception("G4tgbPlaceParamCircle::G4tgbPlaceParamCircle()",
96                "InvalidSetup", FatalException, "Circle axis is zero !");
97  }
98  theCircleAxis /= theCircleAxis.mag();
99
100  theAxis = kZAxis;
101
102  theNCopies = G4int(tgrParam->GetExtraData()[0]);
103  theStep = tgrParam->GetExtraData()[1];
104  theOffset = tgrParam->GetExtraData()[2];
105  theRadius = tgrParam->GetExtraData()[3];
106
107#ifdef G4VERBOSE
108  if( G4tgrMessenger::GetVerboseLevel() >= 2 )
109  {
110    G4cout << " G4tgbPlaceParamCircle::G4tgbPlaceParamCircle():" << G4endl
111           << " param type " << tgrParam->GetParamType() << G4endl
112           << "   no copies - " << theNCopies << G4endl
113           << "   step - " << theStep << G4endl
114           << "   offset - " << theOffset << G4endl
115           << "   radius - " << theRadius << G4endl
116           << "   circle axis - " << theCircleAxis << G4endl
117           << "   dir in plane - " << theDirInPlane << G4endl;
118  }
119#endif
120}
121
122
123// -------------------------------------------------------------------------
124void G4tgbPlaceParamCircle::
125ComputeTransformation(const G4int copyNo, G4VPhysicalVolume *physVol) const
126{ 
127  G4double posi = theOffset + copyNo*theStep;
128  G4ThreeVector origin = theDirInPlane * theRadius;
129  origin.rotate( posi, theCircleAxis );
130
131  //----- Calculate rotation matrix (so that all volumes point to the centre)
132  G4RotationMatrix rm;
133  rm.rotate( -posi, theCircleAxis );
134
135  //----- Set translation and rotation
136  physVol->SetTranslation(origin);
137  G4RotationMatrix* pvRm = physVol->GetRotation();
138  if( pvRm == 0 )
139  {
140    pvRm = new G4RotationMatrix;
141  }
142  *pvRm  = *theRotationMatrix * rm;
143  physVol->SetRotation(pvRm);
144  physVol->SetCopyNo( copyNo );
145
146#ifdef G4VERBOSE
147  if( G4tgrMessenger::GetVerboseLevel() >= 3 )
148  {
149    G4cout << " G4tgbPlaceParamCircle::ComputeTransformation():" 
150           << physVol->GetName() << G4endl
151           << "   no copies - " << theNCopies  << G4endl
152           << "   centre - " << origin << G4endl
153           << "   rotation-matrix - " << *pvRm << G4endl;
154  }
155#endif
156}
Note: See TracBrowser for help on using the repository browser.