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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/modeling/src/G4GPSModel.cc (Version 11.3.0) and /visualization/modeling/src/G4GPSModel.cc (Version 10.7.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 //                                                 27 //
 28 //                                                 28 //
 29 // John Allison  26th April 2017.                  29 // John Allison  26th April 2017.
 30 // Model for a representation of the General P     30 // Model for a representation of the General Paricle Source.
 31                                                    31 
 32 #include "G4GPSModel.hh"                           32 #include "G4GPSModel.hh"
 33                                                    33 
 34 #include "G4VGraphicsScene.hh"                     34 #include "G4VGraphicsScene.hh"
 35 #include "G4GeneralParticleSourceData.hh"          35 #include "G4GeneralParticleSourceData.hh"
 36 #include "G4VisAttributes.hh"                      36 #include "G4VisAttributes.hh"
 37 #include "G4GeometryTolerance.hh"                  37 #include "G4GeometryTolerance.hh"
 38 #include "G4PhysicalConstants.hh"                  38 #include "G4PhysicalConstants.hh"
 39 #include "G4Transform3D.hh"                        39 #include "G4Transform3D.hh"
 40 #include "G4Point3D.hh"                            40 #include "G4Point3D.hh"
 41 #include "G4Circle.hh"                             41 #include "G4Circle.hh"
 42 #include "G4Tubs.hh"                               42 #include "G4Tubs.hh"
 43 #include "G4Box.hh"                                43 #include "G4Box.hh"
 44 #include "G4EllipticalTube.hh"                     44 #include "G4EllipticalTube.hh"
 45 #include "G4Orb.hh"                                45 #include "G4Orb.hh"
 46 #include "G4Ellipsoid.hh"                          46 #include "G4Ellipsoid.hh"
 47 #include "G4Para.hh"                               47 #include "G4Para.hh"
 48                                                    48 
 49 #include <sstream>                                 49 #include <sstream>
 50                                                    50 
 51 G4GPSModel::G4GPSModel (const G4Colour& colour     51 G4GPSModel::G4GPSModel (const G4Colour& colour)
 52 : fColour(colour)                                  52 : fColour(colour)
 53 {                                                  53 {
 54   fType = "G4GPSModel";                            54   fType = "G4GPSModel";
 55   std::ostringstream oss;                          55   std::ostringstream oss;
 56   oss << "G4GPSModel for General Particle Sour     56   oss << "G4GPSModel for General Particle Source " << fColour;
 57   fGlobalTag = oss.str();                          57   fGlobalTag = oss.str();
 58   fGlobalDescription = fGlobalTag;                 58   fGlobalDescription = fGlobalTag;
 59 }                                                  59 }
 60                                                    60 
 61 G4GPSModel::~G4GPSModel () {}                      61 G4GPSModel::~G4GPSModel () {}
 62                                                    62 
 63 G4String G4GPSModel::GetCurrentTag () const        63 G4String G4GPSModel::GetCurrentTag () const
 64 {                                                  64 {
 65 return "";                                         65 return "";
 66 }                                                  66 }
 67                                                    67 
 68 G4String G4GPSModel::GetCurrentDescription ()      68 G4String G4GPSModel::GetCurrentDescription () const
 69 {                                                  69 {
 70   return "G4GPSModel " + GetCurrentTag ();         70   return "G4GPSModel " + GetCurrentTag ();
 71 }                                                  71 }
 72                                                    72 
 73 void G4GPSModel::DescribeYourselfTo (G4VGraphi     73 void G4GPSModel::DescribeYourselfTo (G4VGraphicsScene& sceneHandler)
 74 // The main task of a model is to describe its     74 // The main task of a model is to describe itself to the graphics scene
 75 // handler (a object which inherits G4VSceneHa     75 // handler (a object which inherits G4VSceneHandler, which inherits
 76 // G4VGraphicsScene).                              76 // G4VGraphicsScene).
 77 {                                                  77 {
 78   G4GeneralParticleSourceData* pGPSData = G4Ge     78   G4GeneralParticleSourceData* pGPSData = G4GeneralParticleSourceData::Instance();
 79   // Note: As far as I can see, if this is the     79   // Note: As far as I can see, if this is the first time Instance has been
 80   // called, it will, nevertheless, instantiat     80   // called, it will, nevertheless, instantiate a default source, Type:"Point",
 81   // Shaep: "NULL", which will be drawn as a s     81   // Shaep: "NULL", which will be drawn as a small circle at the origin of
 82   // coordinates whether you have set up GPS o     82   // coordinates whether you have set up GPS or not.  Sorry, can't think of a
 83   // way to avoid that.  Mostly, of course, yo     83   // way to avoid that.  Mostly, of course, you will only invoke this function,
 84   // if you have - or are about to - set up GP     84   // if you have - or are about to - set up GPS, in which case all will be well.
 85   if (!pGPSData) return;                           85   if (!pGPSData) return;
 86                                                    86 
 87   G4int nSources = pGPSData->GetSourceVectorSi     87   G4int nSources = pGPSData->GetSourceVectorSize();
 88   for (G4int iSource = 0; iSource < nSources;      88   for (G4int iSource = 0; iSource < nSources; ++iSource) {
 89                                                    89 
 90     const G4SingleParticleSource* pCurrentSing     90     const G4SingleParticleSource* pCurrentSingleSource = pGPSData->GetCurrentSource(iSource);
 91     if (!pCurrentSingleSource) return;             91     if (!pCurrentSingleSource) return;
 92                                                    92 
 93     const G4SPSPosDistribution* pSPSPosDistrib     93     const G4SPSPosDistribution* pSPSPosDistribution = pCurrentSingleSource->GetPosDist();
 94     if (!pSPSPosDistribution) return;              94     if (!pSPSPosDistribution) return;
 95                                                    95 
 96     G4String Type = pSPSPosDistribution->GetPo     96     G4String Type = pSPSPosDistribution->GetPosDisType();
 97     G4String Shape = pSPSPosDistribution->GetP     97     G4String Shape = pSPSPosDistribution->GetPosDisShape();
 98     // Type can be: Point, Plane, Surface or V     98     // Type can be: Point, Plane, Surface or Volume
 99     // Shape can be: Square, Circle, Ellipse,      99     // Shape can be: Square, Circle, Ellipse, Rectangle,
100     //    Sphere, Ellipsoid, Cylinder, Paralle    100     //    Sphere, Ellipsoid, Cylinder, Parallelepiped
101 //    G4cout                                      101 //    G4cout
102 //    << "G4GPSModel::DescribeYourselfTo"         102 //    << "G4GPSModel::DescribeYourselfTo"
103 //    << ": PosDisType: " << Type                 103 //    << ": PosDisType: " << Type
104 //    << ", Shape: " << Shape                     104 //    << ", Shape: " << Shape
105 //    << G4endl;                                  105 //    << G4endl;
106                                                   106 
107     const G4double& halfx = pSPSPosDistributio    107     const G4double& halfx = pSPSPosDistribution->GetHalfX();
108     const G4double& halfy = pSPSPosDistributio    108     const G4double& halfy = pSPSPosDistribution->GetHalfY();
109     const G4double& halfz = pSPSPosDistributio    109     const G4double& halfz = pSPSPosDistribution->GetHalfZ();
110     const G4double& Radius  = pSPSPosDistribut    110     const G4double& Radius  = pSPSPosDistribution->GetRadius();
111     const G4double& Radius0 = pSPSPosDistribut    111     const G4double& Radius0 = pSPSPosDistribution->GetRadius0();
112     const G4double& ParAlpha = pSPSPosDistribu    112     const G4double& ParAlpha = pSPSPosDistribution->GetParAlpha();
113     const G4double& ParTheta = pSPSPosDistribu    113     const G4double& ParTheta = pSPSPosDistribution->GetParTheta();
114     const G4double& ParPhi   = pSPSPosDistribu    114     const G4double& ParPhi   = pSPSPosDistribution->GetParPhi();
115                                                   115 
116     const G4ThreeVector& Rotx = pSPSPosDistrib    116     const G4ThreeVector& Rotx = pSPSPosDistribution->GetRotx();
117     const G4ThreeVector& Roty = pSPSPosDistrib    117     const G4ThreeVector& Roty = pSPSPosDistribution->GetRoty();
118     const G4ThreeVector& Rotz = pSPSPosDistrib    118     const G4ThreeVector& Rotz = pSPSPosDistribution->GetRotz();
119                                                   119 
120     const G4ThreeVector& position = pSPSPosDis    120     const G4ThreeVector& position = pSPSPosDistribution->GetCentreCoords();
121     G4Transform3D transform(CLHEP::HepXHat,CLH    121     G4Transform3D transform(CLHEP::HepXHat,CLHEP::HepYHat,CLHEP::HepZHat,Rotx,Roty,Rotz);
122     transform = G4Translate3D(position) * tran    122     transform = G4Translate3D(position) * transform;
123                                                   123 
124     G4double surfaceTolerance = G4GeometryTole    124     G4double surfaceTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
125     G4double smallHalfThickness = 10.*surfaceT    125     G4double smallHalfThickness = 10.*surfaceTolerance;
126                                                   126 
127     G4VisAttributes gpsAtts;                      127     G4VisAttributes gpsAtts;
128     gpsAtts.SetColour(fColour);                   128     gpsAtts.SetColour(fColour);
129     gpsAtts.SetForceSolid();                      129     gpsAtts.SetForceSolid();
130                                                   130     
131     if (Type == "Point") {                        131     if (Type == "Point") {
132                                                   132 
133       G4Circle circle;                            133       G4Circle circle;
134       circle.SetPosition(position);               134       circle.SetPosition(position);
135       circle.SetScreenDiameter(10.);              135       circle.SetScreenDiameter(10.);
136       circle.SetVisAttributes(gpsAtts);           136       circle.SetVisAttributes(gpsAtts);
137       sceneHandler.BeginPrimitives(transform);    137       sceneHandler.BeginPrimitives(transform);
138       sceneHandler.AddPrimitive(circle);          138       sceneHandler.AddPrimitive(circle);
139       sceneHandler.EndPrimitives();               139       sceneHandler.EndPrimitives();
140                                                   140 
141     } else if (Type == "Plane") {                 141     } else if (Type == "Plane") {
142                                                   142 
143       // Code based on G4SPSPosDistribution::G    143       // Code based on G4SPSPosDistribution::GeneratePointsInPlane.
144       sceneHandler.PreAddSolid(transform,gpsAt    144       sceneHandler.PreAddSolid(transform,gpsAtts);
145       if (Shape == "Circle") {                    145       if (Shape == "Circle") {
146         sceneHandler.AddSolid                     146         sceneHandler.AddSolid
147         (G4Tubs("GPS_Circle",0.,Radius,smallHa    147         (G4Tubs("GPS_Circle",0.,Radius,smallHalfThickness,0.,twopi));
148       } else if (Shape == "Annulus") {            148       } else if (Shape == "Annulus") {
149         sceneHandler.AddSolid                     149         sceneHandler.AddSolid
150         (G4Tubs("GPS_Annulus",Radius0,Radius,s    150         (G4Tubs("GPS_Annulus",Radius0,Radius,smallHalfThickness,0.,twopi));
151       } else if (Shape == "Ellipse") {            151       } else if (Shape == "Ellipse") {
152         sceneHandler.AddSolid                     152         sceneHandler.AddSolid
153         (G4EllipticalTube("GPS_Ellipse",halfx,    153         (G4EllipticalTube("GPS_Ellipse",halfx,halfy,smallHalfThickness));
154       } else if (Shape == "Square") {             154       } else if (Shape == "Square") {
155         sceneHandler.AddSolid                     155         sceneHandler.AddSolid
156         (G4Box("GPS_Ellipse",halfx,halfx,small    156         (G4Box("GPS_Ellipse",halfx,halfx,smallHalfThickness));
157       } else if (Shape == "Rectangle") {          157       } else if (Shape == "Rectangle") {
158         sceneHandler.AddSolid                     158         sceneHandler.AddSolid
159         (G4Box("GPS_Rectangle",halfx,halfy,sma    159         (G4Box("GPS_Rectangle",halfx,halfy,smallHalfThickness));
160       }                                           160       }
161       sceneHandler.PostAddSolid();                161       sceneHandler.PostAddSolid();
162                                                   162 
163     } else if (Type == "Surface" || Type == "V    163     } else if (Type == "Surface" || Type == "Volume") {
164                                                   164       
165       // Code based on G4SPSPosDistribution::G    165       // Code based on G4SPSPosDistribution::GeneratePointsOnSurface.
166       // and           G4SPSPosDistribution::G    166       // and           G4SPSPosDistribution::GeneratePointsInVolume.
167       sceneHandler.PreAddSolid(transform,gpsAt    167       sceneHandler.PreAddSolid(transform,gpsAtts);
168       if (Shape == "Sphere") {                    168       if (Shape == "Sphere") {
169         sceneHandler.AddSolid                     169         sceneHandler.AddSolid
170         (G4Orb("GPS_Sphere",Radius));             170         (G4Orb("GPS_Sphere",Radius));
171       } else if (Shape == "Ellipsoid") {          171       } else if (Shape == "Ellipsoid") {
172         sceneHandler.AddSolid                     172         sceneHandler.AddSolid
173         (G4Ellipsoid("GPS_Ellipsoid",halfx,hal    173         (G4Ellipsoid("GPS_Ellipsoid",halfx,halfy,halfz));
174       } else if (Shape == "Cylinder") {           174       } else if (Shape == "Cylinder") {
175         sceneHandler.AddSolid                     175         sceneHandler.AddSolid
176         (G4Tubs("GPS_Cylinder",0.,Radius, half    176         (G4Tubs("GPS_Cylinder",0.,Radius, halfz, 0., twopi));
177       } else if (Shape == "Para") {               177       } else if (Shape == "Para") {
178         sceneHandler.AddSolid                     178         sceneHandler.AddSolid
179         (G4Para("GPS_Para",halfx,halfy,halfz,P    179         (G4Para("GPS_Para",halfx,halfy,halfz,ParAlpha,ParTheta,ParPhi));
180       }                                           180       }
181       sceneHandler.PostAddSolid();                181       sceneHandler.PostAddSolid();
182                                                   182 
183     }                                             183     }
184   }                                               184   }
185 }                                                 185 }
186                                                   186