13#include <G4Polycone.hh>
14#include <G4Polyhedra.hh>
34 object->MakeSolidFunctionPtr_ = &RZBuilder::MakePolycone;
41 auto object =
new RZBuilder(name, phi_start, phi_tot, sides);
42 object->MakeSolidFunctionPtr_ = &RZBuilder::MakePolyhedra;
47 G4double unit,
const G4String &name, G4double endz, G4double h, G4double OR, G4double IR) {
50 object->MakeSolidFunctionPtr_ = &RZBuilder::MakePolycone;
56 object->AddPlane(plane);
58 object->AddPlane(plane);
69 RZBuilder::RZBuilder(
const G4String &name, G4double init_phi_start, G4double init_phi_tot,
72 phi_tot_deg(init_phi_tot) {
73 set_shared_from_this_enabled(
false);
75 set_shared_from_this_enabled(
true);
80 RZBuilder::RZBuilder(
const RZBuilder &other) :
82 sides_(other.sides_), phi_start_deg_(other.phi_start_deg_), phi_tot_deg(other.phi_tot_deg),
83 num_planes_(other.num_planes_), z_(other.z_), IR_(other.IR_), OR_(other.OR_),
84 MakeSolidFunctionPtr_(other.MakeSolidFunctionPtr_) {
85 set_shared_from_this_enabled(
false);
87 set_shared_from_this_enabled(
true);
93 throw std::runtime_error(
"Error in RZBuilder::FillSolidConfig\"\n"
94 "Cannot fill a solid builder CONFIGURATION, when the solid is already built from it."
95 "Use ForkAndReset(\"new_name\") first to get an unbuilt copy.\n\n");
99 for (
int i = 0; i < num_planes_; i++) {
102 return this->shared_from_this();
108 throw std::runtime_error(
"Error in RZBuilder::ReflectZSolidConfig\"\n"
109 "Cannot flip a solid builder CONFIGURATION, when the solid is already built from it.\n"
110 "Use ReflectZFinalSolidCopy(\"new_name\") instead to copy and flip the solid.\n\n");
113 for (
int i = 0; i < num_planes_; i++) {
114 this->z_[i] = -this->z_[i];
116 return this->shared_from_this();
120 if (MakeSolidFunctionPtr_ == &RZBuilder::MakePolyhedra) {
124 "Warning in RZBuilder: Calling SetNumSides() on a builder that makes round things"
125 <<
" might be as clever as giving a balloon to a hedgehog. \n Ignoring call." <<
128 return shared_from_this();
135 if (plane.
IR < 0 || plane.
OR < 0) {
136 throw std::runtime_error(
"Error in RZBuilder::AddPlane()"
137 " for builder " + GetBuilderName() +
".\n"
138 "IR and OR must be non-negative.");
140 IR_.push_back(plane.
IR * plane.
unit);
141 OR_.push_back(plane.
OR * plane.
unit);
142 z_.push_back(plane.
z * plane.
unit);
144 return shared_from_this();
148 auto plane =
RZPlane{unit, IR, OR, z};
149 return AddPlane(plane);
154 auto plane =
RZPlane{GetEffectiveDefaultUnit(), IR, OR, z};
155 return AddPlane(plane);
161 for (
const auto &plane : planes) {
164 return shared_from_this();
169 for (
const auto &plane : planes) {
170 G4double unit = this->GetEffectiveDefaultUnit();
171 auto rzplane =
RZPlane{unit, plane.
IR, plane.OR, plane.z};
174 return shared_from_this();
179 for (
const auto &plane : planes) {
180 auto rzplane =
RZPlane{unit, plane.
IR, plane.OR, plane.z};
183 return shared_from_this();
187 G4VSolid *RZBuilder::MakePolycone(
const G4String &name) {
188 if (this->solid_ptr_.get() !=
nullptr) {
189 std::string error =
"Error in MakePolycone: A solid was already built\n"
190 "You can copy and rename the builder to reset it and build again.";
191 throw std::runtime_error(error);
194 G4cout <<
"New Polycone:" << GetBuilderName() <<
" phi_start: " << phi_start_deg_ <<
195 " degrees, phi_tot: " << phi_tot_deg
196 <<
" degrees" << G4endl;
197 for (
int i = 0; i < z_.size(); i++) {
198 G4cout <<
"z: " << z_[i] <<
" IR: " << IR_[i] <<
" OR: " << OR_[i] << G4endl;
200 auto retval =
new G4Polycone(
201 name, phi_start_deg_ * CLHEP::deg, phi_tot_deg * CLHEP::deg, num_planes_, z_.data(),
207 G4VSolid *RZBuilder::MakePolyhedra(
const G4String &name) {
208 if (this->solid_ptr_.get() !=
nullptr) {
209 std::string error =
"Error in MakePolyhedra: A solid was already built\n"
210 "You can copy and rename the builder to reset it and build again.";
211 throw std::runtime_error(error);
214 G4cout <<
"New Polyhedra:" << GetBuilderName() <<
" with " << sides_ <<
" sides, "
215 <<
" phi_start: " << phi_start_deg_ <<
" degrees, phi_tot: " << phi_tot_deg <<
216 " degrees" << G4endl;
217 for (
int i = 0; i < z_.size(); i++) {
218 G4cout <<
"z: " << z_[i] <<
" IR: " << IR_[i] <<
" OR: " << OR_[i] << G4endl;
220 auto retval =
new G4Polyhedra(
221 name, phi_start_deg_ * CLHEP::deg, phi_tot_deg * CLHEP::deg, sides_, num_planes_,
223 IR_.data(), OR_.data());
Builder class for RZ mult-plane defined solids.
VolumeBuilder: Common functionality for volume builder classes.
G4String GetBuilderName() const
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.
SharedPtr< RZBuilder > RZBuilderPtr
Struct for adding planes to GeantMultiPlane –DSLeonard 2024 Overloads make this not strictly needed.
static G4double global_default_unit