BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSCollimatorJawTip.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 "BDSAcceleratorModel.hh"
19#include "BDSCollimatorJawTip.hh"
20#include "BDSColourFromMaterial.hh"
21#include "BDSBeamPipeInfo.hh"
22#include "BDSCollimatorJaw.hh"
23#include "BDSColours.hh"
24#include "BDSDebug.hh"
25#include "BDSException.hh"
26#include "BDSSDType.hh"
27
28#include "G4Box.hh"
29#include "G4Para.hh"
30#include "G4LogicalVolume.hh"
31#include "G4PVPlacement.hh"
32#include "G4VisAttributes.hh"
33
34#include <cmath>
35#include <set>
36
37BDSCollimatorJawTip::BDSCollimatorJawTip(const G4String& nameIn,
38 G4double lengthIn,
39 G4double horizontalWidthIn,
40 G4double xHalfGapIn,
41 G4double yHalfHeightIn,
42 G4double xSizeLeftIn,
43 G4double xSizeRightIn,
44 G4double leftJawTiltIn,
45 G4double rightJawTiltIn,
46 G4double tipThicknessIn,
47 G4bool buildLeftJawIn,
48 G4bool buildRightJawIn,
49 G4Material* collimatorMaterialIn,
50 G4Material* collimatorTipMaterialIn,
51 G4Material* vacuumMaterialIn,
52 G4Colour* colourIn,
53 G4Colour* tipColourIn):
54BDSCollimatorJaw(nameIn, lengthIn, horizontalWidthIn, xHalfGapIn, yHalfHeightIn, xSizeLeftIn, xSizeRightIn,
55 leftJawTiltIn, rightJawTiltIn, buildLeftJawIn, buildRightJawIn, collimatorMaterialIn,
56 vacuumMaterialIn, colourIn, "jcoltip"),
57 tipColour(tipColourIn),
58 tipThickness(tipThicknessIn),
59 collimatorTipMaterial(collimatorTipMaterialIn)
60{
61 if (!tipColour)
62 {
63 G4Colour* defaultTipColour = BDSColours::Instance()->GetColour("collimatorTip");
64 tipColour = BDSColourFromMaterial::Instance()->GetColourWithDefault(collimatorTipMaterialIn, defaultTipColour);
65 }
66 UpdateCalculations();
67}
68
69BDSCollimatorJawTip::~BDSCollimatorJawTip()
70{;}
71
73{
75
76 // shrink the bulk jaws from the aperture side to make space for the tips, so the
77 // centre of each jaw moves outwards by half the space taken
78 G4double tipSpace = tipThickness + 2*lengthSafety;
79 leftJawWidth -= tipSpace;
80 leftJawPos += G4ThreeVector(0.5*tipSpace, 0, 0);
81 rightJawWidth -= tipSpace;
82 rightJawPos -= G4ThreeVector(0.5*tipSpace, 0, 0);
83
84 leftJawTipPos = G4ThreeVector(leftJawHalfGap + 0.5*tipThickness, 0, 0);
85 rightJawTipPos = G4ThreeVector(-(rightJawHalfGap + 0.5*tipThickness), 0, 0);
86}
87
89{
90 // the remaining checks only apply to the jaw and vacuum geometry
91 if (!buildAperture)
92 {
93 if (tipThickness > (0.5*horizontalWidth-4*lengthSafety))
94 {throw BDSException(__METHOD_NAME__, "2x tipThickness is greater than the horizontal width for zero opening jcoltip \"" + name + "\"");}
95 return;
96 }
97
98 // tip solids have a half width of tipThickness/2 - lengthSafety
99 if (tipThickness * 0.5 - lengthSafety < 1e-3) // 1um minimum, could also be negative
100 {throw BDSException(__METHOD_NAME__, "insufficient tipThickness for jcoltip \"" + name + "\"");}
101
102 // bulk jaw solids have a half width of (jawWidth - tipThickness)/2 - lengthSafety
103 if (buildLeftJaw && ((0.5 * horizontalWidth - leftJawHalfGap - tipThickness) * 0.5 - lengthSafety < 1e-3))
104 {throw BDSException(__METHOD_NAME__, "left jaw of jcoltip \"" + name + "\" too thin given horizontalWidth, aperture and tipThickness");}
105 if (buildRightJaw && ((0.5 * horizontalWidth - rightJawHalfGap - tipThickness) * 0.5 - lengthSafety < 1e-3))
106 {throw BDSException(__METHOD_NAME__, "right jaw of jcoltip \"" + name + "\" too thin given horizontalWidth, aperture and tipThickness");}
107}
108
110{
113 BuildTips();
114}
115
116void BDSCollimatorJawTip::BuildTips()
117{
118 G4VisAttributes* tipVisAttr = new G4VisAttributes(*tipColour);
119 RegisterVisAttributes(tipVisAttr);
120
121 G4UserLimits* tipCollUserLimits = CollimatorUserLimits();
122
123 // If not aperture, then the base class just fills the container with one material. Now,
124 // place a tip material block inside that block.
125 if (!buildAperture && tipThickness > 1e-3)
126 {
127 G4VSolid* tipSolid = new G4Box(name + "_tip_solid",
128 tipThickness,
130 chordLength * 0.5 - 2*lengthSafety);
131 // the containerLV is of length chordLength * 0.5 - lengthSafety
132 RegisterSolid(tipSolid);
133
134 G4LogicalVolume* collimatorTipLV = new G4LogicalVolume(tipSolid, collimatorTipMaterial, name + "_tip_lv");
135 collimatorTipLV->SetVisAttributes(tipVisAttr);
136 collimatorTipLV->SetUserLimits(tipCollUserLimits);
137
138 // register with base class (BDSGeometryComponent)
139 RegisterLogicalVolume(collimatorTipLV);
140 BDSAcceleratorModel::Instance()->VolumeSet("collimators")->insert(collimatorTipLV);
141 if (sensitiveOuter)
142 {RegisterSensitiveVolume(collimatorTipLV, BDSSDType::collimatorcomplete);}
143
144 // place the jaw
145 G4PVPlacement* collimatorTipPV = new G4PVPlacement(nullptr, // rotation
146 (G4ThreeVector) 0, // position
147 collimatorTipLV, // its logical volume
148 name + "_tip_pv", // its name
149 collimatorLV, // its mother volume
150 false, // no boolean operation
151 0, // copy number
153 RegisterPhysicalVolume(collimatorTipPV);
154 return;
155 }
156
157 G4VSolid* leftJawTipSolid = nullptr;
159 {
160 if (jawTiltLeft != 0)
161 {
162 G4double leftHalfLength = chordLength * 0.5 * std::cos(jawTiltLeft);
163 leftJawTipSolid = new G4Para(name + "_leftjawtip_solid",
164 tipThickness * 0.5 - lengthSafety,
166 leftHalfLength - lengthSafety,
167 0, jawTiltLeft, 0);
168 }
169 else
170 {
171 leftJawTipSolid = new G4Box(name + "_leftjawtip_solid",
172 tipThickness * 0.5 - lengthSafety,
174 chordLength * 0.5 - lengthSafety);
175 }
176 RegisterSolid(leftJawTipSolid);
177
178 G4LogicalVolume* leftJawTipLV = new G4LogicalVolume(leftJawTipSolid, collimatorTipMaterial, name + "_leftjawtip_lv");
179 leftJawTipLV->SetVisAttributes(tipVisAttr);
180 leftJawTipLV->SetUserLimits(tipCollUserLimits);
181 RegisterLogicalVolume(leftJawTipLV);
182 BDSAcceleratorModel::Instance()->VolumeSet("collimators")->insert(leftJawTipLV);
183 if (sensitiveOuter)
184 {RegisterSensitiveVolume(leftJawTipLV, BDSSDType::collimatorcomplete);}
185
186 // place the tip
187 G4PVPlacement* leftJawTipPV = new G4PVPlacement(nullptr,
188 leftJawTipPos,
189 leftJawTipLV,
190 name + "_leftjawtip_pv",
191 containerLogicalVolume,
192 false, // no boolean operation
193 0, // copy number
195 RegisterPhysicalVolume(leftJawTipPV);
196 }
197
198 G4VSolid* rightJawTipSolid = nullptr;
200 {
201 if (jawTiltRight != 0)
202 {
203 G4double rightHalfLength = chordLength * 0.5 * std::cos(jawTiltRight);
204 rightJawTipSolid = new G4Para(name + "_rightjawtip_solid",
205 tipThickness * 0.5 - lengthSafety,
207 rightHalfLength - lengthSafety,
208 0, jawTiltRight, 0);
209 }
210 else
211 {
212 rightJawTipSolid = new G4Box(name + "_rightjawtip_solid",
213 tipThickness * 0.5 - lengthSafety,
215 chordLength * 0.5 - lengthSafety);
216 }
217 RegisterSolid(rightJawTipSolid);
218
219 G4LogicalVolume* rightJawTipLV = new G4LogicalVolume(rightJawTipSolid, collimatorTipMaterial, name + "_rightjawtip_lv");
220 rightJawTipLV->SetVisAttributes(tipVisAttr);
221 rightJawTipLV->SetUserLimits(tipCollUserLimits);
222 RegisterLogicalVolume(rightJawTipLV);
223 BDSAcceleratorModel::Instance()->VolumeSet("collimators")->insert(rightJawTipLV);
224 if (sensitiveOuter)
225 {RegisterSensitiveVolume(rightJawTipLV, BDSSDType::collimatorcomplete);}
226
227 // place the tip
228 G4PVPlacement* rightJawTipPV = new G4PVPlacement(nullptr,
229 rightJawTipPos,
230 rightJawTipLV,
231 name + "_rightjawtip_pv",
232 containerLogicalVolume,
233 false, // no boolean operation
234 0, // copy number
236 RegisterPhysicalVolume(rightJawTipPV);
237 }
238}
const G4String name
Const protected member variable that may not be changed by derived classes.
static G4bool sensitiveOuter
Useful variable often used in construction.
static G4double lengthSafety
Useful variable often used in construction.
static G4bool checkOverlaps
Useful variable often used in construction.
G4double chordLength
Protected member variable that can be modified by derived classes.
std::set< G4LogicalVolume * > * VolumeSet(const G4String &name)
Returns pointer to a set of logical volumes. If no set by that name exits, create it.
virtual void Build() override
Override function in BDSCollimator for totally different construction.
void UpdateCalculations()
Adjust the calculated values to include the space for the tips that are separate placements.
Collimator with only two jaw and no top bit.
G4bool buildAperture
Build aperture or not.
virtual void Build() override
Override function in BDSCollimator for totally different construction.
G4double jawTiltLeft
Tilt of jaw 1 (angle in x-z plane)
G4double jawTiltRight
Tilt of jaw 2 (angle in x-z plane)
void Calculations()
Calculate offsets and sizes.
G4double yHalfHeight
Half height of each jaw.
G4bool buildRightJaw
Build right jaw or not.
G4bool buildLeftJaw
Build left jaw or not.
G4LogicalVolume * collimatorLV
In case of no aperture, cache this volume for derived classes to place inside.
G4UserLimits * CollimatorUserLimits()
Return either default user limits or custom ones based on optional minimumKineticEnergy.
G4double horizontalWidth
Horizontal width.
static BDSColourFromMaterial * Instance()
Singleton pattern.
G4Colour * GetColourWithDefault(const G4Material *material, G4Colour *defaultIn) const
Get colour from name - if not found return the supplied default.
G4Colour * GetColour(G4double red, G4double green, G4double blue, G4double alpha=1)
Get a cached anonymous colour by values.
static BDSColours * Instance()
singleton pattern
Definition BDSColours.cc:32
General exception with possible name of object and message.
void RegisterLogicalVolume(G4LogicalVolume *logicalVolume)
void RegisterPhysicalVolume(G4VPhysicalVolume *physicalVolume)
void RegisterVisAttributes(G4VisAttributes *visAttribute)
void RegisterSolid(G4VSolid *solid)
void RegisterSensitiveVolume(G4LogicalVolume *sensitiveVolume, BDSSDType sensitivityType)