BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSMagnetOuterFactoryBase.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSAppropriateTubs.hh"
19#include "BDSColours.hh"
20#include "BDSDebug.hh"
21#include "BDSExtent.hh"
22#include "BDSGeometryComponent.hh"
23#include "BDSGlobalConstants.hh"
24#include "BDSMagnetOuterFactoryBase.hh"
25#include "BDSMaterials.hh"
26
27#include "globals.hh" // geant4 types / globals
28
29#include "G4Colour.hh"
30#include "G4CutTubs.hh"
31#include "G4LogicalVolume.hh"
32#include "G4Tubs.hh"
33#include "G4VisAttributes.hh"
34
35#include <set>
36
37BDSMagnetOuterFactoryBase::BDSMagnetOuterFactoryBase()
38{
39 sensitiveOuter = BDSGlobalConstants::Instance()->SensitiveOuter();
40
41 // initialise variables and pointers that'll be used by the factory
43}
44
49
51{
53 poleSolid = nullptr;
54 yokeSolid = nullptr;
55 containerSolid = nullptr;
56 magnetContainerSolid = nullptr;
57 poleLV = nullptr;
58 yokeLV = nullptr;
59 containerLV = nullptr;
60 magnetContainerLV = nullptr;
61 yokePV = nullptr;
62 outerVisAttributes = nullptr;
63
64 magnetContainer = nullptr;
65
66 inputFaceNormal = G4ThreeVector(0,0,-1);
67 outputFaceNormal = G4ThreeVector(0,0, 1);
68}
69
71 G4Colour* colour,
72 G4Material* outerMaterial)
73{
74 if (poleSolid)
75 {
76 poleLV = new G4LogicalVolume(poleSolid,
77 outerMaterial,
78 name + "_pole_lv");
79 }
80
81 yokeLV = new G4LogicalVolume(yokeSolid,
82 outerMaterial,
83 name + "_yoke_lv");
84
85 // the container is filled with the world material as it may not tightly fit the yoke - e.g. square container
86 // for a C-shaped yoke -> there's a gap that should be filled with (e.g.) air
87 G4Material* worldMaterial = BDSMaterials::Instance()->GetMaterial(BDSGlobalConstants::Instance()->WorldMaterial());
88 containerLV = new G4LogicalVolume(containerSolid,
89 worldMaterial,
90 name + "_outer_container_lv");
91
92 magnetContainerLV = new G4LogicalVolume(magnetContainerSolid,
93 worldMaterial,
94 name + "_container_lv");
95
96 // VISUAL ATTRIBUTES
97 G4VisAttributes* outerVisAttr;
98 if (colour)
99 {outerVisAttr = new G4VisAttributes(*colour);}
100 else
101 {outerVisAttr = new G4VisAttributes(*BDSColours::Instance()->GetColour("default"));}
102 outerVisAttr->SetVisibility(true);
103 outerVisAttr->SetForceLineSegmentsPerCircle(nSegmentsPerCircle);
104 allVisAttributes.insert(outerVisAttr);
105 if (poleLV)
106 {poleLV->SetVisAttributes(outerVisAttr);}
107 yokeLV->SetVisAttributes(outerVisAttr);
108 // container
109 containerLV->SetVisAttributes(containerVisAttr);
110 magnetContainerLV->SetVisAttributes(containerVisAttr);
111}
112
114{
115 if (poleLV)
116 {poleLV->SetUserLimits(defaultUserLimits);}
117 yokeLV->SetUserLimits(defaultUserLimits);
118 containerLV->SetUserLimits(defaultUserLimits);
119 magnetContainerLV->SetUserLimits(defaultUserLimits);
120
121 for (auto& lv : allLogicalVolumes)
122 {lv->SetUserLimits(defaultUserLimits);}
123}
124
126 G4double magnetContainerLength,
127 G4double magnetContainerRadius,
128 G4bool flatFaces)
129{
130 magnetContainerRadius += lengthSafetyLarge; // extra margin
131 magnetContainerSolid = BDS::AppropriateTubs(name + "_container_solid", // name
132 0, // inner radius
133 magnetContainerRadius, // outer radius
134 magnetContainerLength * 0.5, // z half length
135 0, // starting angle
136 CLHEP::twopi, // sweep angle
137 inputFaceNormal, // input face normal vector
138 outputFaceNormal, // output face normal vector
139 flatFaces);
140
141 magContExtent = BDSExtent(magnetContainerRadius, magnetContainerRadius, magnetContainerLength*0.5);
142}
143
145 G4double magnetContainerLength,
146 G4double magnetContainerRadius)
147{
148 magnetContainerRadius += lengthSafetyLarge; // extra margin
149 magnetContainerSolid = new G4Tubs(name + "_container_solid", // name
150 0, // inner radius
151 magnetContainerRadius, // outer radius
152 magnetContainerLength * 0.5, // z half length
153 0, // starting angle
154 CLHEP::twopi); // sweep angle
155
156 magContExtent = BDSExtent(magnetContainerRadius, magnetContainerRadius, magnetContainerLength*0.5);
157}
158
159void BDSMagnetOuterFactoryBase::CreateMagnetContainerComponent()
160{
161 magnetContainer = new BDSGeometryComponent(magnetContainerSolid,
162 magnetContainerLV,
163 magContExtent);
164}
165
166
168{
169 outer->SetInputFaceNormal(inputFaceNormal);
170 outer->SetOutputFaceNormal(outputFaceNormal);
171}
172
static BDSColours * Instance()
singleton pattern
Definition BDSColours.cc:32
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:38
G4VisAttributes * containerVisAttr
Cache of global constants variable.
G4double lengthSafetyLarge
Cache of global constants variable.
G4int nSegmentsPerCircle
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.
G4Material * GetMaterial(G4String material) const
Get material by name.