BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSCavityFactoryBase.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 "BDSCavity.hh"
20#include "BDSCavityFactoryBase.hh"
21#include "BDSCavityInfo.hh"
22#include "BDSColours.hh"
23#include "BDSExtent.hh"
24#include "BDSGlobalConstants.hh"
25#include "BDSMaterials.hh"
26#include "BDSSDType.hh"
27#include "BDSUtilities.hh"
28
29#include "globals.hh"
30#include "G4LogicalVolume.hh"
31#include "G4RotationMatrix.hh"
32#include "G4PVPlacement.hh"
33#include "G4ThreeVector.hh"
34#include "G4Tubs.hh"
35#include "G4VisAttributes.hh"
36#include "G4VPhysicalVolume.hh"
37
38#include "CLHEP/Units/SystemOfUnits.h"
39
40#include <map>
41#include <set>
42
43class G4UserLimits;
44
45BDSCavityFactoryBase::BDSCavityFactoryBase()
46{
48 sensitiveBeamPipe = BDSGlobalConstants::Instance()->SensitiveBeamPipe();
49 sensitiveVacuum = BDSGlobalConstants::Instance()->StoreELossVacuum();
50
51 CleanUpBase(); // initialise variables
52}
53
55 G4double totalChordLength,
56 const BDSCavityInfo* info,
57 G4Material* vacuumMaterial)
58{
59 CleanUp();
60 G4double containerRadius = CreateSolids(name, totalChordLength, info);
61 CreateLogicalVolumes(name, info, vacuumMaterial);
62 SetUserLimits(totalChordLength);
64 PlaceComponents(name);
65
66 BDSExtent ext = BDSExtent(containerRadius, containerRadius, totalChordLength*0.5);
68
69 return result;
70}
71
76
78{
80
81 vacuumSolid = nullptr;
82 cavitySolid = nullptr;
83 containerSolid = nullptr;
84 vacuumLV = nullptr;
85 cavityLV = nullptr;
86 containerLV = nullptr;
87}
88
90 const BDSCavityInfo* info,
91 G4Material* vacuumMaterial)
92{
93 cavityLV = new G4LogicalVolume(cavitySolid, // solid
94 info->material, // material
95 name + "_cavity_lv"); // name
96 allLogicalVolumes.insert(cavityLV);
97 sensitiveVolumes[cavityLV] = BDSSDType::energydep;
98
99 vacuumLV = new G4LogicalVolume(vacuumSolid, // solid
100 vacuumMaterial, // material
101 name + "_vacuum_lv"); // name
102 if (sensitiveVacuum)
103 {sensitiveVolumes[vacuumLV] = BDSSDType::energydepvacuum;}
104 allLogicalVolumes.insert(vacuumLV);
105
106 containerLV = new G4LogicalVolume(containerSolid,
108 name + "_container_lv");
109}
110
112{
113 auto defaultUL = BDSGlobalConstants::Instance()->DefaultUserLimits();
114 //copy the default and update with the length of the object rather than the default 1m
115 G4UserLimits* ul = BDS::CreateUserLimits(defaultUL, length);
116
117 if (ul != defaultUL) // if it's not the default register it
118 {allUserLimits.insert(ul);}
119
120 for (auto lv : allLogicalVolumes)
121 {lv->SetUserLimits(ul);}
122}
123
124void BDSCavityFactoryBase::SetVisAttributes(const G4String& colourName)
125{
126 // visualisation attributes
127 auto col = BDSColours::Instance()->GetColour(colourName);
128 G4VisAttributes* cavityVis = new G4VisAttributes(*col);
129 cavityVis->SetVisibility(true);
130 cavityVis->SetForceLineSegmentsPerCircle(nSegmentsPerCircle);
131 cavityLV->SetVisAttributes(cavityVis);
132 allVisAttributes.insert(cavityVis);
133
134 // vacuum
135 vacuumLV->SetVisAttributes(BDSGlobalConstants::Instance()->ContainerVisAttr());
136 // container
137 containerLV->SetVisAttributes(BDSGlobalConstants::Instance()->ContainerVisAttr());
138}
139
141{
142 G4PVPlacement* vacuumPV = new G4PVPlacement(nullptr, // rotation
143 G4ThreeVector(), // position
144 vacuumLV, // logical Volume to be placed
145 name + "_vacuum_pv", // placement name
146 containerLV, // mother volume
147 false, // pMany unused
148 0, // copy number
149 checkOverlaps); // check overlaps
150 allPhysicalVolumes.insert(vacuumPV);
151
152 G4PVPlacement* cavityPV = new G4PVPlacement(nullptr, // rotation
153 G4ThreeVector(), // position
154 cavityLV, // logical Volume to be placed
155 name + "_cavity_pv", // placement name
156 containerLV, // mother volume
157 false, // pMany unused
158 0, // copy number
159 checkOverlaps); // check overlaps
160 allPhysicalVolumes.insert(cavityPV);
161}
162
164{
166 extent, vacuumLV);
167
168 // register objects
169 cavity->RegisterSolid(allSolids);
170 cavity->RegisterLogicalVolume(allLogicalVolumes); //using geometry component base class method
173 cavity->RegisterPhysicalVolume(allPhysicalVolumes);
174 cavity->RegisterRotationMatrix(allRotationMatrices);
175 cavity->RegisterUserLimits(allUserLimits);
176 cavity->RegisterVisAttributes(allVisAttributes);
177
178 return cavity;
179}
G4bool sensitiveBeamPipe
Whether the beam pipe will record energy deposition.
G4bool sensitiveVacuum
Whether the vacuum will record energy deposition.
virtual BDSCavity * BuildCavityAndRegisterObjects(const BDSExtent &extent)
Construct output object and register all temporary objects from vectors.
virtual void SetVisAttributes(const G4String &colourName="rfcavity")
Set vis attributes for cavityLV, vacuumLV and containerLV.
G4LogicalVolume * vacuumLV
Cache of particular solid or lv for common functionality in this class.
virtual void SetUserLimits(G4double length)
BDSCavity * CreateCavity(const G4String &name, G4double totalChordLength, const BDSCavityInfo *info, G4Material *vacuumMaterial)
virtual G4double CreateSolids(const G4String &name, G4double totalChordLength, const BDSCavityInfo *info)=0
Create vacuumSolid and cavitySolid. Must return the container radius.
G4LogicalVolume * containerLV
Cache of particular solid or lv for common functionality in this class.
void CleanUpBase()
Non-virtual clean up that can be used in the constructor safely.
G4LogicalVolume * cavityLV
Cache of particular solid or lv for common functionality in this class.
virtual void PlaceComponents(const G4String &name)
Place the vacuum and cavity centrally in the container logical volume.
G4Material * emptyMaterial
Cache of variable from BDSGlobalConstants.
std::map< G4LogicalVolume *, BDSSDType > sensitiveVolumes
Map to sensitivity for volumes.
G4VSolid * vacuumSolid
Cache of particular solid or lv for common functionality in this class.
virtual void CleanUp()
Ensure all internal members are reset before reuse. Calls CleanUpBase.
G4VSolid * containerSolid
Cache of particular solid or lv for common functionality in this class.
virtual void CreateLogicalVolumes(const G4String &name, const BDSCavityInfo *info, G4Material *vacuumMaterial)
Create vacuumLV, cavityLV and containerLV.
G4VSolid * cavitySolid
Cache of particular solid or lv for common functionality in this class.
Holder for all Geometrical information required to create an RF cavity.
G4Material * material
Material.
A holder class for an RF cavity piece of geometry.
Definition BDSCavity.hh:39
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
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:39
G4bool checkOverlaps
Cache of global constants variable.
G4int nSegmentsPerCircle
Cache of global constants variable.
virtual void FactoryBaseCleanUp()
Empty containers for next use - factories are never deleted so can't rely on scope.
void RegisterRotationMatrix(G4RotationMatrix *rotationMatrix)
void RegisterLogicalVolume(G4LogicalVolume *logicalVolume)
void RegisterPhysicalVolume(G4VPhysicalVolume *physicalVolume)
void RegisterUserLimits(G4UserLimits *userLimit)
void RegisterVisAttributes(G4VisAttributes *visAttribute)
void RegisterSolid(G4VSolid *solid)
void RegisterSensitiveVolume(G4LogicalVolume *sensitiveVolume, BDSSDType sensitivityType)
static BDSGlobalConstants * Instance()
Access method.
static BDSMaterials * Instance()
Singleton pattern access.
G4Material * GetMaterial(G4String material) const
Get material by name.
G4UserLimits * CreateUserLimits(G4UserLimits *defaultUL, G4double length, G4double fraction=1.6)