Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4GPSModel.cc
이 파일의 문서화 페이지로 가기
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: G4GPSModel.cc 100959 2016-11-03 14:13:37Z allison $
28 //
29 //
30 // John Allison 26th April 2017.
31 // Model for a representation of the General Paricle Source.
32 
33 #include "G4GPSModel.hh"
34 
35 #include "G4VGraphicsScene.hh"
37 #include "G4VisAttributes.hh"
38 #include "G4GeometryTolerance.hh"
39 #include "G4PhysicalConstants.hh"
40 #include "G4Transform3D.hh"
41 #include "G4Point3D.hh"
42 #include "G4Circle.hh"
43 #include "G4Tubs.hh"
44 #include "G4Box.hh"
45 #include "G4EllipticalTube.hh"
46 #include "G4Orb.hh"
47 #include "G4Ellipsoid.hh"
48 #include "G4Para.hh"
49 
50 #include <sstream>
51 
53 : fColour(colour)
54 {
55  fType = "G4GPSModel";
56  std::ostringstream oss;
57  oss << "G4GPSModel for General Particle Source " << fColour;
58  fGlobalTag = oss.str();
60 }
61 
63 
65 {
66 return "";
67 }
68 
70 {
71  return "G4GPSModel " + GetCurrentTag ();
72 }
73 
75 // The main task of a model is to describe itself to the graphics scene
76 // handler (a object which inherits G4VSceneHandler, which inherits
77 // G4VGraphicsScene).
78 {
80  // Note: As far as I can see, if this is the first time Instance has been
81  // called, it will, nevertheless, instantiate a default source, Type:"Point",
82  // Shaep: "NULL", which will be drawn as a small circle at the origin of
83  // coordinates whether you have set up GPS or not. Sorry, can't think of a
84  // way to avoid that. Mostly, of course, you will only invoke this function,
85  // if you have - or are about to - set up GPS, in which case all will be well.
86  if (!pGPSData) return;
87 
88  G4int nSources = pGPSData->GetSourceVectorSize();
89  for (G4int iSource = 0; iSource < nSources; ++iSource) {
90 
91  const G4SingleParticleSource* pCurrentSingleSource = pGPSData->GetCurrentSource(iSource);
92  if (!pCurrentSingleSource) return;
93 
94  const G4SPSPosDistribution* pSPSPosDistribution = pCurrentSingleSource->GetPosDist();
95  if (!pSPSPosDistribution) return;
96 
97  G4String Type = pSPSPosDistribution->GetPosDisType();
98  G4String Shape = pSPSPosDistribution->GetPosDisShape();
99  // Type can be: Point, Plane, Surface or Volume
100  // Shape can be: Square, Circle, Ellipse, Rectangle,
101  // Sphere, Ellipsoid, Cylinder, Parallelepiped
102 // G4cout
103 // << "G4GPSModel::DescribeYourselfTo"
104 // << ": PosDisType: " << Type
105 // << ", Shape: " << Shape
106 // << G4endl;
107 
108  const G4double& halfx = pSPSPosDistribution->GetHalfX();
109  const G4double& halfy = pSPSPosDistribution->GetHalfY();
110  const G4double& halfz = pSPSPosDistribution->GetHalfZ();
111  const G4double& Radius = pSPSPosDistribution->GetRadius();
112  const G4double& Radius0 = pSPSPosDistribution->GetRadius0();
113  const G4double& ParAlpha = pSPSPosDistribution->GetParAlpha();
114  const G4double& ParTheta = pSPSPosDistribution->GetParTheta();
115  const G4double& ParPhi = pSPSPosDistribution->GetParPhi();
116 
117  const G4ThreeVector& Rotx = pSPSPosDistribution->GetRotx();
118  const G4ThreeVector& Roty = pSPSPosDistribution->GetRoty();
119  const G4ThreeVector& Rotz = pSPSPosDistribution->GetRotz();
120 
121  const G4ThreeVector& position = pSPSPosDistribution->GetCentreCoords();
122  G4Transform3D transform(CLHEP::HepXHat,CLHEP::HepYHat,CLHEP::HepZHat,Rotx,Roty,Rotz);
123  transform = G4Translate3D(position) * transform;
124 
126  G4double smallHalfThickness = 10.*surfaceTolerance;
127 
128  G4VisAttributes gpsAtts;
129  gpsAtts.SetColour(fColour);
130  gpsAtts.SetForceSolid();
131 
132  if (Type == "Point") {
133 
134  G4Circle circle;
135  circle.SetPosition(position);
136  circle.SetScreenDiameter(10.);
137  circle.SetVisAttributes(gpsAtts);
138  sceneHandler.BeginPrimitives(transform);
139  sceneHandler.AddPrimitive(circle);
140  sceneHandler.EndPrimitives();
141 
142  } else if (Type == "Plane") {
143 
144  // Code based on G4SPSPosDistribution::GeneratePointsInPlane.
145  sceneHandler.PreAddSolid(transform,gpsAtts);
146  if (Shape == "Circle") {
147  sceneHandler.AddSolid
148  (G4Tubs("GPS_Circle",0.,Radius,smallHalfThickness,0.,twopi));
149  } else if (Shape == "Annulus") {
150  sceneHandler.AddSolid
151  (G4Tubs("GPS_Annulus",Radius0,Radius,smallHalfThickness,0.,twopi));
152  } else if (Shape == "Ellipse") {
153  sceneHandler.AddSolid
154  (G4EllipticalTube("GPS_Ellipse",halfx,halfy,smallHalfThickness));
155  } else if (Shape == "Square") {
156  sceneHandler.AddSolid
157  (G4Box("GPS_Ellipse",halfx,halfx,smallHalfThickness));
158  } else if (Shape == "Rectangle") {
159  sceneHandler.AddSolid
160  (G4Box("GPS_Rectangle",halfx,halfy,smallHalfThickness));
161  }
162  sceneHandler.PostAddSolid();
163 
164  } else if (Type == "Surface" || Type == "Volume") {
165 
166  // Code based on G4SPSPosDistribution::GeneratePointsOnSurface.
167  // and G4SPSPosDistribution::GeneratePointsInVolume.
168  sceneHandler.PreAddSolid(transform,gpsAtts);
169  if (Shape == "Sphere") {
170  sceneHandler.AddSolid
171  (G4Orb("GPS_Sphere",Radius));
172  } else if (Shape == "Ellipsoid") {
173  sceneHandler.AddSolid
174  (G4Ellipsoid("GPS_Ellipsoid",halfx,halfy,halfz));
175  } else if (Shape == "Cylinder") {
176  sceneHandler.AddSolid
177  (G4Tubs("GPS_Cylinder",0.,Radius, halfz, 0., twopi));
178  } else if (Shape == "Para") {
179  sceneHandler.AddSolid
180  (G4Para("GPS_Para",halfx,halfy,halfz,ParAlpha,ParTheta,ParPhi));
181  }
182  sceneHandler.PostAddSolid();
183 
184  }
185  }
186 }
void SetPosition(const G4Point3D &)
G4ThreeVector GetCentreCoords() const
virtual void AddSolid(const G4Box &)=0
HepGeom::Translate3D G4Translate3D
Definition: G4Tubs.hh:85
virtual void EndPrimitives()=0
G4SingleParticleSource * GetCurrentSource(G4int idx)
G4String fGlobalTag
Definition: G4VModel.hh:109
G4String GetCurrentDescription() const
Definition: G4GPSModel.cc:69
static G4GeneralParticleSourceData * Instance()
virtual ~G4GPSModel()
Definition: G4GPSModel.cc:62
G4GPSModel(const G4Colour &colour=G4Colour(1., 0., 0., 0.3))
Definition: G4GPSModel.cc:52
G4SPSPosDistribution * GetPosDist() const
G4Colour fColour
Definition: G4GPSModel.hh:68
const G4ThreeVector & GetRotz() const
G4double GetParTheta() const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())=0
G4double GetParPhi() const
G4String GetPosDisShape() const
G4String fGlobalDescription
Definition: G4VModel.hh:110
double G4double
Definition: G4Types.hh:76
G4String GetPosDisType() const
G4double GetRadius0() const
void DescribeYourselfTo(G4VGraphicsScene &)
Definition: G4GPSModel.cc:74
Definition: G4Box.hh:64
static constexpr double twopi
Definition: G4SIunits.hh:76
G4String fType
Definition: G4VModel.hh:108
Definition: G4Orb.hh:62
G4double GetHalfZ() const
G4double GetParAlpha() const
G4String GetCurrentTag() const
Definition: G4GPSModel.cc:64
virtual void AddPrimitive(const G4Polyline &)=0
void SetForceSolid(G4bool=true)
DLL_API const Hep3Vector HepXHat
int G4int
Definition: G4Types.hh:78
DLL_API const Hep3Vector HepYHat
const G4ThreeVector & GetRotx() const
virtual void PostAddSolid()=0
const G4ThreeVector & GetRoty() const
DLL_API const Hep3Vector HepZHat
void SetColour(const G4Colour &)
static G4GeometryTolerance * GetInstance()
G4double GetHalfY() const
void SetScreenDiameter(G4double)
G4double GetHalfX() const
Definition: G4Para.hh:86
G4double GetSurfaceTolerance() const
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:80
G4double GetRadius() const
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &visAttribs)=0