BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBeamPipeFactoryCircularVacuum.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 "BDSBeamPipeFactoryCircularVacuum.hh"
19#include "BDSBeamPipe.hh"
20#include "BDSExtent.hh"
21#include "BDSGlobalConstants.hh"
22#include "BDSUtilities.hh"
23
24#include "globals.hh" // geant4 globals / types
25#include "G4CutTubs.hh"
26#include "G4LogicalVolume.hh"
27#include "G4ThreeVector.hh"
28#include "G4Tubs.hh"
29#include "G4UserLimits.hh"
30#include "G4VSolid.hh"
31
32#include <cmath>
33#include <set>
34#include <utility>
35
36class G4Material;
37
38BDSBeamPipeFactoryCircularVacuum::BDSBeamPipeFactoryCircularVacuum()
39{;}
40
42 G4double lengthIn,
43 G4double aper1In,
44 G4double /*aper2In*/,
45 G4double /*aper3In*/,
46 G4double /*aper4In*/,
47 G4Material* vacuumMaterialIn,
48 G4double /*beamPipeThicknessIn*/,
49 G4Material* /*beamPipeMaterialIn*/,
50 const G4String& /*pointsFileIn*/,
51 const G4String& /*pointsUnitIn*/)
52{
53 // clean up after last usage
54 CleanUp();
55
56 containerSolid = new G4Tubs(nameIn + "_container_solid", // name
57 0, // inner radius
58 aper1In, // outer radius
59 lengthIn*0.5, // half length
60 0, // rotation start angle
61 CLHEP::twopi); // rotation finish angle
62
63 G4double containerRadius = aper1In + lengthSafetyLarge;
64
65 return CommonFinalConstruction(nameIn, vacuumMaterialIn, lengthIn, containerRadius);
66}
67
69 G4double lengthIn,
70 const G4ThreeVector& inputFaceNormalIn,
71 const G4ThreeVector& outputFaceNormalIn,
72 G4double aper1In,
73 G4double /*aper2In*/,
74 G4double /*aper3In*/,
75 G4double /*aper4In */,
76 G4Material* vacuumMaterialIn,
77 G4double /*beamPipeThicknessIn*/,
78 G4Material* /*beamPipeMaterialIn*/,
79 const G4String& /*pointsFileIn*/,
80 const G4String& /*pointsUnitIn*/)
81{
82 // clean up after last usage
83 CleanUp();
84 inputFaceNormal = inputFaceNormalIn;
85 outputFaceNormal = outputFaceNormalIn;
86
87 // check faces of angled container volume don't intersect - if it can be built, remaining angled volumes can be built
89
90 containerSolid = new G4CutTubs(nameIn + "_container_solid", // name
91 0, // inner radius
92 aper1In, // outer radius
93 lengthIn*0.5, // half length
94 0, // rotation start angle
95 CLHEP::twopi, // rotation finish angle
96 inputFaceNormal, // input face normal
97 outputFaceNormal); // rotation finish angle
98
99 G4double containerRadius = aper1In + lengthSafetyLarge;
100
101 return CommonFinalConstruction(nameIn, vacuumMaterialIn, lengthIn, containerRadius);
102}
103
107 G4Material* vacuumMaterialIn,
108 G4double lengthIn,
109 G4double containerRadiusIn)
110{
111 // prepare a longer container subtraction solid
112 // doesn't have to be angled as it's only used for transverse subtraction
113 containerSubtractionSolid = new G4Tubs(nameIn + "_container_sub_solid",// name
114 0, // inner radius
115 containerRadiusIn, // outer radius
116 lengthIn*4, // full length for unambiguous subtraction
117 0, // rotation start angle
118 CLHEP::twopi); // rotation finish angle
119
120 // We don't use BDSBeamPipeFactoryBase::CommonConstruction as this factory doesn't
121 // produce a beam pipe solid etc - only vacuum so it wouldn't work.
122
123 containerLV = new G4LogicalVolume(containerSolid,
124 vacuumMaterialIn,
125 nameIn + "_container_lv");
126
127 containerLV->SetVisAttributes(BDSGlobalConstants::Instance()->ContainerVisAttr());
128 vacuumLV = containerLV; // copy pointer for referencing in BuildBeamPipeAndRegisterVolumes.
129
130 // user limits
131 auto defaultUL = BDSGlobalConstants::Instance()->DefaultUserLimits();
132 //copy the default and update with the length of the object rather than the default 1m
133 G4UserLimits* ul = BDS::CreateUserLimits(defaultUL, lengthIn);
134 if (ul != defaultUL) // if it's not the default register it
135 {allUserLimits.insert(ul);}
136 containerLV->SetUserLimits(ul);
137 vacuumLV->SetUserLimits(ul);
138
139 // record extents
140 BDSExtent ext = BDSExtent(containerRadiusIn, containerRadiusIn, lengthIn*0.5);
141
142 return BDSBeamPipeFactoryBase::BuildBeamPipeAndRegisterVolumes(ext, containerRadiusIn);
143}
G4ThreeVector outputFaceNormal
For recording the face normals in the finished pipe component.
G4ThreeVector inputFaceNormal
For recording the face normals in the finished pipe component.
BDSBeamPipe * BuildBeamPipeAndRegisterVolumes(BDSExtent extent, G4double containerRadius, G4bool containerIsCircular=false)
build beampipe and register logical volumes
static void CheckAngledVolumeCanBeBuilt(G4double length, const G4ThreeVector &inputfaceAngle, const G4ThreeVector &outputfaceAngle, G4double horizontalWidth, const G4String &name)
check if a beam pipe volume with angled faces can be constructed
G4VSolid * containerSubtractionSolid
Longer (in length) version of container solid for unambiguous subtraction.
virtual BDSBeamPipe * CreateBeamPipe(const G4String &nameIn, G4double lengthIn, G4double aper1=0, G4double aper2=0, G4double aper3=0, G4double aper4=0, G4Material *vacuumMaterialIn=nullptr, G4double beamPipeThicknessIn=0, G4Material *beamPipeMaterialIn=nullptr, const G4String &pointsFileIn="", const G4String &pointsUnitIn="")
create a flat ended beampipe
BDSBeamPipe * CommonFinalConstruction(const G4String &nameIn, G4Material *vacuumMaterialIn, G4double lengthIn, G4double containerRadiusIn)
A holder class for a piece of beam pipe geometry.
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:38
G4double lengthSafetyLarge
Cache of global constants variable.
static BDSGlobalConstants * Instance()
Access method.
G4UserLimits * CreateUserLimits(G4UserLimits *defaultUL, G4double length, G4double fraction=1.6)