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) 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 "BDSCavity.hh"
19#include "BDSCavityFactoryBase.hh"
20#include "BDSCavityInfo.hh"
21#include "BDSColours.hh"
22#include "BDSExtent.hh"
23#include "BDSGlobalConstants.hh"
24#include "BDSMaterials.hh"
25#include "BDSSDType.hh"
26#include "BDSUtilities.hh"
27
28#include "globals.hh"
29#include "G4LogicalVolume.hh"
30#include "G4RotationMatrix.hh"
31#include "G4PVPlacement.hh"
32#include "G4ThreeVector.hh"
33#include "G4Tubs.hh"
34#include "G4VisAttributes.hh"
35#include "G4VPhysicalVolume.hh"
36
37#include "CLHEP/Units/SystemOfUnits.h"
38
39#include <map>
40#include <set>
41
42class G4UserLimits;
43
44BDSCavityFactoryBase::BDSCavityFactoryBase()
45{
47 sensitiveBeamPipe = BDSGlobalConstants::Instance()->SensitiveBeamPipe();
48 sensitiveVacuum = BDSGlobalConstants::Instance()->StoreELossVacuum();
49
50 CleanUpBase(); // initialise variables
51}
52
54 G4double totalChordLength,
55 const BDSCavityInfo* info,
56 G4Material* vacuumMaterial)
57{
58 CleanUp();
59 G4double containerRadius = CreateSolids(name, totalChordLength, info);
60 CreateLogicalVolumes(name, info, vacuumMaterial);
61 SetUserLimits(totalChordLength);
63 PlaceComponents(name);
64
65 BDSExtent ext = BDSExtent(containerRadius, containerRadius, totalChordLength*0.5);
67
68 return result;
69}
70
75
77{
79
80 vacuumSolid = nullptr;
81 cavitySolid = nullptr;
82 containerSolid = nullptr;
83 vacuumLV = nullptr;
84 cavityLV = nullptr;
85 containerLV = nullptr;
86}
87
89 const BDSCavityInfo* info,
90 G4Material* vacuumMaterial)
91{
92 cavityLV = new G4LogicalVolume(cavitySolid, // solid
93 info->material, // material
94 name + "_cavity_lv"); // name
95 allLogicalVolumes.insert(cavityLV);
96 sensitiveVolumes[cavityLV] = BDSSDType::energydep;
97
98 vacuumLV = new G4LogicalVolume(vacuumSolid, // solid
99 vacuumMaterial, // material
100 name + "_vacuum_lv"); // name
101 if (sensitiveVacuum)
102 {sensitiveVolumes[vacuumLV] = BDSSDType::energydepvacuum;}
103 allLogicalVolumes.insert(vacuumLV);
104
105 containerLV = new G4LogicalVolume(containerSolid,
107 name + "_container_lv");
108}
109
111{
112 auto defaultUL = BDSGlobalConstants::Instance()->DefaultUserLimits();
113 //copy the default and update with the length of the object rather than the default 1m
114 G4UserLimits* ul = BDS::CreateUserLimits(defaultUL, length);
115
116 if (ul != defaultUL) // if it's not the default register it
117 {allUserLimits.insert(ul);}
118
119 for (auto lv : allLogicalVolumes)
120 {lv->SetUserLimits(ul);}
121}
122
123void BDSCavityFactoryBase::SetVisAttributes(const G4String& colourName)
124{
125 // visualisation attributes
126 auto col = BDSColours::Instance()->GetColour(colourName);
127 G4VisAttributes* cavityVis = new G4VisAttributes(*col);
128 cavityVis->SetVisibility(true);
129 cavityVis->SetForceLineSegmentsPerCircle(nSegmentsPerCircle);
130 cavityLV->SetVisAttributes(cavityVis);
131 allVisAttributes.insert(cavityVis);
132
133 // vacuum
134 vacuumLV->SetVisAttributes(BDSGlobalConstants::Instance()->ContainerVisAttr());
135 // container
136 containerLV->SetVisAttributes(BDSGlobalConstants::Instance()->ContainerVisAttr());
137}
138
140{
141 G4PVPlacement* vacuumPV = new G4PVPlacement(nullptr, // rotation
142 G4ThreeVector(), // position
143 vacuumLV, // logical Volume to be placed
144 name + "_vacuum_pv", // placement name
145 containerLV, // mother volume
146 false, // pMany unused
147 0, // copy number
148 checkOverlaps); // check overlaps
149 allPhysicalVolumes.insert(vacuumPV);
150
151 G4PVPlacement* cavityPV = new G4PVPlacement(nullptr, // rotation
152 G4ThreeVector(), // position
153 cavityLV, // logical Volume to be placed
154 name + "_cavity_pv", // placement name
155 containerLV, // mother volume
156 false, // pMany unused
157 0, // copy number
158 checkOverlaps); // check overlaps
159 allPhysicalVolumes.insert(cavityPV);
160}
161
163{
165 extent, vacuumLV);
166
167 // register objects
168 cavity->RegisterSolid(allSolids);
169 cavity->RegisterLogicalVolume(allLogicalVolumes); //using geometry component base class method
172 cavity->RegisterPhysicalVolume(allPhysicalVolumes);
173 cavity->RegisterRotationMatrix(allRotationMatrices);
174 cavity->RegisterUserLimits(allUserLimits);
175 cavity->RegisterVisAttributes(allVisAttributes);
176
177 return cavity;
178}
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:38
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
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:38
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)