BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSTipCollimator.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2024.
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 "BDSAcceleratorModel.hh"
20#include "BDSBeamPipeInfo.hh"
21#include "BDSTipCollimator.hh"
22#include "BDSColours.hh"
23#include "BDSDebug.hh"
24#include "BDSException.hh"
25#include "BDSGlobalConstants.hh"
26#include "BDSMaterials.hh"
27#include "BDSSDType.hh"
28#include "BDSUtilities.hh"
29#include "BDSWarning.hh"
30
31#include "globals.hh"
32#include "G4Box.hh"
33#include "G4LogicalVolume.hh"
34#include "G4PVPlacement.hh"
35#include "G4SubtractionSolid.hh"
36#include "G4Tubs.hh"
37#include "G4UserLimits.hh"
38#include "G4VisAttributes.hh"
39
40#include <map>
41
42BDSTipCollimator::BDSTipCollimator(const G4String& nameIn,
43 G4double lengthIn,
44 G4double horizontalWidthIn,
45 const G4String& typeIn,
46 G4Material* collimatorMaterialIn,
47 G4Material* collimatorTipMaterialIn,
48 G4Material* vacuumMaterialIn,
49 G4double xApertureIn,
50 G4double yApertureIn,
51 G4double xApertureOutIn,
52 G4double yApertureOutIn,
53 G4Colour* colourIn,
54 G4Colour* tipColourIn,
55 G4double tipThicknessIn,
56 G4bool circularOuterIn):
57 BDSAcceleratorComponent(nameIn, lengthIn, 0, typeIn),
58 collimatorSolid(nullptr),
59 innerSolid(nullptr),
60 vacuumSolid(nullptr),
61 horizontalWidth(horizontalWidthIn),
62 collimatorMaterial(collimatorMaterialIn),
63 collimatorTipMaterial(collimatorTipMaterialIn),
64 vacuumMaterial(vacuumMaterialIn),
65 xAperture(xApertureIn),
66 yAperture(yApertureIn),
67 xApertureOut(xApertureOutIn),
68 yApertureOut(yApertureOutIn),
69 tapered(false),
70 colour(colourIn),
71 tipColour(tipColourIn),
72 tipThickness(tipThicknessIn),
73 minKineticEnergy(0),
74 circularOuter(circularOuterIn)
75{;}
76
77BDSTipCollimator::~BDSTipCollimator()
78{;}
79
81{
82 if ((xAperture > 0.5 * horizontalWidth) || (yAperture > 0.5 * horizontalWidth))
83 {
84 G4cerr << __METHOD_NAME__ << "half aperture bigger than width or height!" << G4endl;
85 G4cerr << "Full horizontal width is " << horizontalWidth << " mm for component named: \""
86 << name << "\"" << G4endl;
87 G4cerr << "x (half) aperture " << xAperture << " mm, y (half) aperture " << yAperture << " mm" << G4endl;
88 throw BDSException(__METHOD_NAME__, "Error in collimator");
89 }
90
92 {
93 G4cerr << __METHOD_NAME__ << "half aperture exit bigger than width or height!" << G4endl;
94 G4cerr << "Full horizontal width is " << horizontalWidth << " mm for component named: \""
95 << name << "\"" << G4endl;
96 G4cerr << "x (half) aperture " << xApertureOut << " mm, y (half) aperture " << yApertureOut << " mm" << G4endl;
97 throw BDSException(__METHOD_NAME__, "Error in collimator");
98 }
99
100 if (BDS::IsFinite(xApertureOut) && (xAperture <= 0))
101 {BDS::Warning(__METHOD_NAME__, "element: \"" + name + "\": no entrance aperture set for collimator - exit aperture parameters will be ignored");}
102
104 if (!tapered)
105 {// copy for consistency in output and aperture prediction
108 }
109
110 if (!colour)
111 {colour = BDSColours::Instance()->GetColour("collimator");}
112 if (!tipColour)
113 {tipColour = BDSColours::Instance()->GetColour("collimatorTip");}
114}
115
117{
119 {return collimatorMaterial->GetName();}
120 else
121 {return "none";}
122}
123
125{
126 if (circularOuter)
127 {
128 containerSolid = new G4Tubs(name + "_solid",
129 0,
130 0.5*horizontalWidth,
131 0.5*chordLength,
132 0,
133 CLHEP::twopi);
134 }
135 else
136 {
137 containerSolid = new G4Box(name + "_container_solid",
138 horizontalWidth*0.5,
139 horizontalWidth*0.5,
140 chordLength*0.5);
141 }
142
143 containerLogicalVolume = new G4LogicalVolume(containerSolid,
145 name + "_container_lv");
147 chordLength * 0.5);
148 SetExtent(ext);
149}
150
152{
154 BDSAcceleratorComponent::Build(); // calls BuildContainer and sets limits and vis for container
155
156 // Swap variables around if exit size is larger than entrance size
157 // Rotation for tapered collimator (needed for tapered elliptical collimator)
158 G4bool isOutLarger = ((xApertureOut > xAperture) && (yApertureOut > yAperture));
159 G4RotationMatrix* colRotate;
160 if (tapered && isOutLarger)
161 {
162 std::swap(xAperture,xApertureOut);
163 std::swap(yAperture,yApertureOut);
164 colRotate = new G4RotationMatrix;
165 colRotate->rotateX(CLHEP::pi);
166 RegisterRotationMatrix(colRotate);
167 }
168 else
169 {colRotate = nullptr;}
170
171 G4VSolid* outerSolid;
172 if (circularOuter)
173 {
174 outerSolid = new G4Tubs(name + "_outer_solid",
175 0,
178 0,
179 CLHEP::twopi);
180 }
181 else
182 {
183 outerSolid = new G4Box(name + "_outer_solid",
186 chordLength * 0.5 - lengthSafety);
187 }
188 RegisterSolid(outerSolid);
189
190 G4bool buildVacuumAndAperture = (BDS::IsFinite(xAperture) && BDS::IsFinite(yAperture));
191
192 // only do subtraction if aperture actually set
193 if (buildVacuumAndAperture)
194 {
196
197 collimatorSolid = new G4SubtractionSolid(name + "_collimator_solid", // name
198 outerSolid, // solid 1
199 innerSolid); // minus solid 2
201 }
202 else
203 {collimatorSolid = outerSolid;}
204
205 G4LogicalVolume* collimatorLV = new G4LogicalVolume(collimatorSolid, // solid
206 collimatorMaterial, // material
207 name + "_collimator_lv"); // name
208
209 // register it in a set of collimator logical volumes
210 BDSAcceleratorModel::Instance()->VolumeSet("collimators")->insert(collimatorLV);
211
212 G4VisAttributes* collimatorVisAttr = new G4VisAttributes(*colour);
213 collimatorLV->SetVisAttributes(collimatorVisAttr);
214 RegisterVisAttributes(collimatorVisAttr);
215
216 collimatorLV->SetUserLimits(CollimatorUserLimits());
217
218 // register with base class (BDSGeometryComponent)
219 RegisterLogicalVolume(collimatorLV);
220 if (sensitiveOuter)
221 {RegisterSensitiveVolume(collimatorLV, BDSSDType::collimatorcomplete);}
222
223 G4PVPlacement* collPV = new G4PVPlacement(colRotate, // rotation
224 G4ThreeVector(), // position
225 collimatorLV, // its logical volume
226 name + "_collimator_pv", // its name
227 containerLogicalVolume, // its mother volume
228 false, // no boolean operation
229 0, // copy number
231
233
234 if (buildVacuumAndAperture)
235 {
236 G4LogicalVolume* vacuumLV = new G4LogicalVolume(vacuumSolid, // solid
237 vacuumMaterial, // material
238 name + "_vacuum_lv"); // name
239
240 vacuumLV->SetVisAttributes(containerVisAttr);
241 // user limits - provided by BDSAcceleratorComponent
242 vacuumLV->SetUserLimits(userLimits);
244 RegisterLogicalVolume(vacuumLV);
245 if (sensitiveVacuum)
246 {RegisterSensitiveVolume(vacuumLV, BDSSDType::energydepvacuum);}
247
248 G4PVPlacement* vacPV = new G4PVPlacement(colRotate, // rotation
249 (G4ThreeVector) 0, // position
250 vacuumLV, // its logical volume
251 name + "_vacuum_pv", // its name
252 containerLogicalVolume, // its mother volume
253 false, // no boolean operation
254 0, // copy number
256
258 }
259}
260
262{
264 {
265 // copy default ones with correct length and global time etc provided
266 // by BDSAcceleratorComponent
267 G4UserLimits* collUserLimits = new G4UserLimits(*userLimits);
268 collUserLimits->SetUserMinEkine(minKineticEnergy);
269 RegisterUserLimits(collUserLimits);
270 return collUserLimits;
271 }
272 else // user limits - provided by BDSAcceleratorComponent
273 {return userLimits;}
274}
Abstract class that represents a component of an accelerator.
G4UserLimits * userLimits
Cache of user limits.
void SetAcceleratorVacuumLogicalVolume(G4LogicalVolume *accVacLVIn)
const G4String name
Const protected member variable that may not be changed by derived classes.
static G4Material * emptyMaterial
Useful variable often used in construction.
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.
static G4VisAttributes * containerVisAttr
Useful variable often used in construction.
static G4bool sensitiveVacuum
Useful variable often used in construction.
std::set< G4LogicalVolume * > * VolumeSet(const G4String &name)
Returns pointer to a set of logical volumes. If no set by that name exits, create it.
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:33
General exception with possible name of object and message.
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:39
void RegisterRotationMatrix(G4RotationMatrix *rotationMatrix)
void RegisterLogicalVolume(G4LogicalVolume *logicalVolume)
void RegisterPhysicalVolume(G4VPhysicalVolume *physicalVolume)
void RegisterUserLimits(G4UserLimits *userLimit)
void SetExtent(const BDSExtent &extIn)
Set extent.
void RegisterVisAttributes(G4VisAttributes *visAttribute)
void RegisterSolid(G4VSolid *solid)
void RegisterSensitiveVolume(G4LogicalVolume *sensitiveVolume, BDSSDType sensitivityType)
G4double xApertureOut
Aperture at exit in x dimension.
G4double yAperture
Aperture at entrance in y dimension.
virtual void CheckParameters()
G4VSolid * innerSolid
Geometrical objects:
G4double minKineticEnergy
Optional minimum kinetic energy for collimator materials.
G4double horizontalWidth
Horizontal width.
G4Colour * tipColour
Colour of collimator tip.
G4VSolid * collimatorSolid
Geometrical objects:
virtual void Build()
virtual G4String Material() const
Accessor.
G4double yApertureOut
Aperture at exit in y dimension.
G4Material * vacuumMaterial
Vacuum material.
G4Colour * colour
Colour of collimator.
G4Material * collimatorMaterial
Material.
BDSTipCollimator()=delete
Private default constructor to force the use of the supplied one.
virtual void BuildContainerLogicalVolume()
G4UserLimits * CollimatorUserLimits()
Return either default user limits or custom ones based on optional minimumKineticEnergy.
G4double xAperture
Aperture at entrance in x dimension.
virtual void BuildInnerCollimator()=0
G4bool tapered
Flag for tapered collimator.
G4VSolid * vacuumSolid
Geometrical objects:
G4bool circularOuter
Aperture type of the collimator.
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())