13#include <G4Polycone.hh>
14#include <G4Polyhedra.hh>
32 object->MakeSolidFunctionPtr_ = &RZBuilder::MakePolycone;
39 auto object =
new RZBuilder(name, phi_start, phi_tot, sides);
40 object->MakeSolidFunctionPtr_ = &RZBuilder::MakePolyhedra;
45 G4double unit,
const G4String &name, G4double endz, G4double h, G4double OR, G4double IR) {
48 object->MakeSolidFunctionPtr_ = &RZBuilder::MakePolycone;
54 object->AddPlane(plane);
56 object->AddPlane(plane);
65 RZBuilder::RZBuilder(
const G4String &name, G4double init_phi_start, G4double init_phi_tot,
68 phi_tot_deg(init_phi_tot) {
76 RZBuilder::RZBuilder(
const RZBuilder &other) :
77 VolumeBuilder<RZBuilder>(other),
78 sides_(other.sides_), phi_start_deg_(other.phi_start_deg_), phi_tot_deg(other.phi_tot_deg),
79 num_planes_(other.num_planes_), z_(other.z_), IR_(other.IR_), OR_(other.OR_),
80 MakeSolidFunctionPtr_(other.MakeSolidFunctionPtr_) {
82 SetName(other.GetBuilderName());
89 throw std::runtime_error(
"Error in RZBuilder::FillSolidConfig\"\n"
90 "Cannot fill a solid builder CONFIGURATION, when the solid is already built from it."
91 "Use ForkAndReset(\"new_name\") first to get an unbuilt copy.\n\n");
95 for (
int i = 0; i < num_planes_; i++) {
104 throw std::runtime_error(
"Error in RZBuilder::ReflectZSolidConfig\"\n"
105 "Cannot flip a solid builder CONFIGURATION, when the solid is already built from it.\n"
106 "Use ReflectZFinalSolidCopy(\"new_name\") instead to copy and flip the solid.\n\n");
109 for (
int i = 0; i < num_planes_; i++) {
110 this->z_[i] = -this->z_[i];
116 if (MakeSolidFunctionPtr_ == &RZBuilder::MakePolyhedra) {
120 "Warning in RZBuilder: Calling SetNumSides() on a builder that makes round things"
121 <<
" might be as clever as giving a balloon to a hedgehog. \n Ignoring call." <<
131 if (plane.
IR < 0 || plane.
OR < 0) {
132 throw std::runtime_error(
"Error in RZBuilder::AddPlane()"
134 "IR and OR must be non-negative.");
136 IR_.push_back(plane.
IR * plane.
unit);
137 OR_.push_back(plane.
OR * plane.
unit);
138 z_.push_back(plane.
z * plane.
unit);
144 auto plane =
RZPlane{unit, IR, OR, z};
157 for (
const auto &plane : planes) {
165 for (
const auto &plane : planes) {
167 auto rzplane =
RZPlane{unit, plane.
IR, plane.OR, plane.z};
175 for (
const auto &plane : planes) {
176 auto rzplane =
RZPlane{unit, plane.
IR, plane.OR, plane.z};
183 G4VSolid *RZBuilder::MakePolycone(
const G4String &name) {
184 if (this->solid_ptr_.get() !=
nullptr) {
185 std::string error =
"Error in MakePolycone: A solid was already built\n"
186 "You can copy and rename the builder to reset it and build again.";
187 throw std::runtime_error(error);
190 G4cout <<
"New Polycone:" <<
GetBuilderName() <<
" phi_start: " << phi_start_deg_ <<
191 " degrees, phi_tot: " << phi_tot_deg
192 <<
" degrees" << G4endl;
193 for (
int i = 0; i < z_.size(); i++) {
194 G4cout <<
"z: " << z_[i] <<
" IR: " << IR_[i] <<
" OR: " << OR_[i] << G4endl;
196 auto retval =
new G4Polycone(
197 name, phi_start_deg_ * CLHEP::deg, phi_tot_deg * CLHEP::deg, num_planes_, z_.data(),
203 G4VSolid *RZBuilder::MakePolyhedra(
const G4String &name) {
204 if (this->solid_ptr_.get() !=
nullptr) {
205 std::string error =
"Error in MakePolyhedra: A solid was already built\n"
206 "You can copy and rename the builder to reset it and build again.";
207 throw std::runtime_error(error);
210 G4cout <<
"New Polyhedra:" <<
GetBuilderName() <<
" with " << sides_ <<
" sides, "
211 <<
" phi_start: " << phi_start_deg_ <<
" degrees, phi_tot: " << phi_tot_deg <<
212 " degrees" << G4endl;
213 for (
int i = 0; i < z_.size(); i++) {
214 G4cout <<
"z: " << z_[i] <<
" IR: " << IR_[i] <<
" OR: " << OR_[i] << G4endl;
216 auto retval =
new G4Polyhedra(
217 name, phi_start_deg_ * CLHEP::deg, phi_tot_deg * CLHEP::deg, sides_, num_planes_,
219 IR_.data(), OR_.data());
std::shared_ptr< T > shared_from_this()
void set_shared_from_this_enabled(bool enabled)
Builder class for RZ mult-plane defined solids.
VolumeBuilder: Common functionality for volume builder classes.
DerivedPtr SetName(const G4String &name)
SetName Sets name used for solid and derived product names.
G4String GetBuilderName() const
A wrapper for std::shared_ptr that allows and facilitates many implicit(i) type conversions.
RZBuilderPtr CreatePolyhedraBuilder(const G4String &name, int sides, G4double phi_start=0., G4double phi_tot=360)
Create a builder for associated IR,OR,Z defined object.
RZBuilderPtr CreateCylinderBuilder(G4double unit, const G4String &name, G4double endz, G4double height, G4double OR, G4double IR=0)
Create a simple cylinder builder.
RZBuilderPtr CreatePolyconeBuilder(const G4String &name, G4double phi_start=0., G4double phi_tot=360)
Create a builder for associated IR,OR,Z defined object.
RZBuilderPtr ReflectZSolidConfig()
Flip Solid Configuration.
virtual RZBuilderPtr SetNumSides(G4double N)
Set number of sides.
RZBuilderPtr AddPlane(const RZPlane &plane)
Adds a plane defining one IR,OR,Z triplet in the volume design.
RZBuilderPtr AddPlanes(const std::vector< RZPlane > &planes)
Adds multiple RZ planes each defining one unit,IR,OR,Z set in the volume design.
RZBuilderPtr FillSolidConfig()
Modifies a Solid CONFIGURATION to set all inner diameters (IDs) to 0.
G4double GetEffectiveDefaultUnit() const
Get the builder default unit or global if not set.
SharedPtr< RZBuilder > RZBuilderPtr
static G4double global_default_unit
Struct for adding planes to GeantMultiPlane –DSLeonard 2024 Overloads make this not strictly needed.