BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSMagnetOuterFactoryBase.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSAppropriateTubs.hh"
20#include "BDSColours.hh"
21#include "BDSDebug.hh"
22#include "BDSExtent.hh"
23#include "BDSGeometryComponent.hh"
24#include "BDSGlobalConstants.hh"
25#include "BDSMagnetOuterFactoryBase.hh"
26#include "BDSMaterials.hh"
27
28#include "globals.hh" // geant4 types / globals
29
30#include "G4Colour.hh"
31#include "G4CutTubs.hh"
32#include "G4LogicalVolume.hh"
33#include "G4Tubs.hh"
34#include "G4VisAttributes.hh"
35
36#include <set>
37
38BDSMagnetOuterFactoryBase::BDSMagnetOuterFactoryBase()
39{
40 sensitiveOuter = BDSGlobalConstants::Instance()->SensitiveOuter();
41
42 // initialise variables and pointers that'll be used by the factory
44}
45
47{
49}
50
52{
54 poleSolid = nullptr;
55 yokeSolid = nullptr;
56 containerSolid = nullptr;
57 magnetContainerSolid = nullptr;
58 poleLV = nullptr;
59 yokeLV = nullptr;
60 containerLV = nullptr;
61 magnetContainerLV = nullptr;
62 yokePV = nullptr;
63 outerVisAttributes = nullptr;
64
65 magnetContainer = nullptr;
66
67 inputFaceNormal = G4ThreeVector(0,0,-1);
68 outputFaceNormal = G4ThreeVector(0,0, 1);
69}
70
72 G4Colour* colour,
73 G4Material* outerMaterial)
74{
75 if (poleSolid)
76 {
77 poleLV = new G4LogicalVolume(poleSolid,
78 outerMaterial,
79 name + "_pole_lv");
80 }
81
82 yokeLV = new G4LogicalVolume(yokeSolid,
83 outerMaterial,
84 name + "_yoke_lv");
85
86 // the container is filled with the world material as it may not tightly fit the yoke - e.g. square container
87 // for a C-shaped yoke -> there's a gap that should be filled with (e.g.) air
88 G4Material* worldMaterial = BDSMaterials::Instance()->GetMaterial(BDSGlobalConstants::Instance()->WorldMaterial());
89 containerLV = new G4LogicalVolume(containerSolid,
90 worldMaterial,
91 name + "_outer_container_lv");
92
93 magnetContainerLV = new G4LogicalVolume(magnetContainerSolid,
94 worldMaterial,
95 name + "_container_lv");
96
97 // VISUAL ATTRIBUTES
98 G4VisAttributes* outerVisAttr;
99 if (colour)
100 {outerVisAttr = new G4VisAttributes(*colour);}
101 else
102 {outerVisAttr = new G4VisAttributes(*BDSColours::Instance()->GetColour("default"));}
103 outerVisAttr->SetVisibility(true);
104 outerVisAttr->SetForceLineSegmentsPerCircle(nSegmentsPerCircle);
105 allVisAttributes.insert(outerVisAttr);
106 if (poleLV)
107 {poleLV->SetVisAttributes(outerVisAttr);}
108 yokeLV->SetVisAttributes(outerVisAttr);
109 // container
110 containerLV->SetVisAttributes(containerVisAttr);
111 magnetContainerLV->SetVisAttributes(containerVisAttr);
112}
113
115{
116 if (poleLV)
117 {poleLV->SetUserLimits(defaultUserLimits);}
118 yokeLV->SetUserLimits(defaultUserLimits);
119 containerLV->SetUserLimits(defaultUserLimits);
120 magnetContainerLV->SetUserLimits(defaultUserLimits);
121
122 for (auto& lv : allLogicalVolumes)
123 {lv->SetUserLimits(defaultUserLimits);}
124}
125
127 G4double magnetContainerLength,
128 G4double magnetContainerRadius,
129 G4bool flatFaces)
130{
131 magnetContainerRadius += lengthSafetyLarge; // extra margin
132 magnetContainerSolid = BDS::AppropriateTubs(name + "_container_solid", // name
133 0, // inner radius
134 magnetContainerRadius, // outer radius
135 magnetContainerLength * 0.5, // z half length
136 0, // starting angle
137 CLHEP::twopi, // sweep angle
138 inputFaceNormal, // input face normal vector
139 outputFaceNormal, // output face normal vector
140 flatFaces);
141
142 magContExtent = BDSExtent(magnetContainerRadius, magnetContainerRadius, magnetContainerLength*0.5);
143}
144
146 G4double magnetContainerLength,
147 G4double magnetContainerRadius)
148{
149 magnetContainerRadius += lengthSafetyLarge; // extra margin
150 magnetContainerSolid = new G4Tubs(name + "_container_solid", // name
151 0, // inner radius
152 magnetContainerRadius, // outer radius
153 magnetContainerLength * 0.5, // z half length
154 0, // starting angle
155 CLHEP::twopi); // sweep angle
156
157 magContExtent = BDSExtent(magnetContainerRadius, magnetContainerRadius, magnetContainerLength*0.5);
158}
159
160void BDSMagnetOuterFactoryBase::CreateMagnetContainerComponent()
161{
162 magnetContainer = new BDSGeometryComponent(magnetContainerSolid,
163 magnetContainerLV,
164 magContExtent);
165}
166
167
169{
170 outer->SetInputFaceNormal(inputFaceNormal);
171 outer->SetOutputFaceNormal(outputFaceNormal);
172}
173
static BDSColours * Instance()
singleton pattern
Definition: BDSColours.cc:33
Holder for +- extents in 3 dimensions.
Definition: BDSExtent.hh:39
G4double nSegmentsPerCircle
Cache of global constants variable.
G4VisAttributes * containerVisAttr
Cache of global constants variable.
G4double lengthSafetyLarge
Cache of global constants variable.
G4UserLimits * defaultUserLimits
Cache of global constants variable.
virtual void FactoryBaseCleanUp()
Empty containers for next use - factories are never deleted so can't rely on scope.
A generic geometry component for a bdsim model.
static BDSGlobalConstants * Instance()
Access method.
virtual void CleanUp()
Empty containers for next use - factories are never deleted so can't rely on scope.
virtual void CreateLogicalVolumes(const G4String &name, G4Colour *colour, G4Material *outerMaterial)
void SetFaceNormals(BDSMagnetOuter *outer)
Copy face normals from members to an instance of outer.
void CleanUpBase()
Non-virtual clean up that can be used in the constructor.
G4VSolid * poleSolid
Solid for an individual pole that will be placed multiple times.
virtual void SetUserLimits()
Attach default user limits to all logical volumes.
G4bool sensitiveOuter
Cache of global constants variable.
G4VSolid * yokeSolid
Solid for outer part that connects all poles.
void BuildMagnetContainerSolidStraight(const G4String &name, G4double magnetContainerLength, G4double magnetContainerRadius)
void BuildMagnetContainerSolidAngled(const G4String &name, G4double magnetContainerLength, G4double magnetContainerRadius, G4bool flatFaces=false)
An object for both the returned magnet outer body but also a tight fitting container for the whole ma...
void SetInputFaceNormal(const G4ThreeVector &input)
Setter for face normals.
void SetOutputFaceNormal(const G4ThreeVector &output)
Setter for face normals.
static BDSMaterials * Instance()
Singleton pattern access.
Definition: BDSMaterials.cc:38
G4Material * GetMaterial(G4String material) const
Get material by name.