DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
RZBuilder.hh
Go to the documentation of this file.
1#pragma once
2
3/*
4 * RZBuilder.hh
5 *
6 * Created on: Jun 19, 2024
7 * Author: D. S. Leonard
8 *
9 * The main user class is presently RZBuilder
10 * Which creates polycones and polyhedrals From z plane definitions.
11 * VolumeMaker which it inherits from provides more generic extended functionality (syntax helpers) to it.
12 * Such as logical volume creation, unions/subtractions, and vis attribute settings.
13 * Features/Benefits
14 * -Unit is separate and remembered for cleaner/simpler dimensioning
15 * (no * mm everwhere, no double unit application, no forgotten unit).
16 * -z=0 point can be outside of object, allowing many objects to reference from a single z.
17 * -Much simpler than using unions for multi-plane objects
18 * - No overlap/z-shift/half-height/sign confusions for every union part.
19 * -no half height math everywhere (or doubled or forgotten application of it).
20 * -Simplified union syntax when still needed.
21 * -Simplified vis_att syntax
22 * -Simplified logical volume construction.
23 * -Polymorphic methods could help in automation in principle.
24 *
25 *
26 */
27
34#include "VolumeBuilder.hh"
36// ReSharper disable once CppUnusedIncludeDirective
37#include <memory>
38
39namespace DLG4::VolumeBuilders {
44 struct RZPlane {
45 G4double unit; // unit
46 G4double IR; // inner radius
47 G4double OR; // outer radius
48 G4double z;
49 RZPlane() = default;
50
51 RZPlane(G4double u, G4double ir, G4double or_, G4double z_)
52 : unit(u), IR(ir), OR(or_), z(z_) {
53 }
54 };
55
60 G4double IR{0}; // inner radius
61 G4double OR{0}; // outer radius
62 G4double z{0};
63 };
64
65 // See other Derived classes, or better yet the Factories "Topic" in the Doxygen html manual,
66 // For Factories for other types of shapes or sources.
67
68 // Parameters after name are only needed for polyhedra or angular information:
83 RZBuilderPtr CreatePolyhedraBuilder(
84 const G4String &name, int sides, G4double phi_start = 0., G4double phi_tot = 360);
85
87 RZBuilderPtr CreatePolyconeBuilder(
88 const G4String &name, G4double phi_start = 0., G4double phi_tot = 360);
89
101 RZBuilderPtr CreateCylinderBuilder(G4double unit, const G4String &name,
102 G4double endz, G4double height, G4double OR, G4double IR = 0);
103
114 RZBuilderPtr CreateCylinderBuilder(const G4String &name,
115 G4double endz, G4double height, G4double OR, G4double IR = 0);
118}
119
131 class RZBuilder final: public VolumeBuilder<RZBuilder> {
133 public:
135 friend class VolumeBuilder<RZBuilder>; // shouldn't be needed, maybe isn't now.
136 template <typename T>
137 friend class i_shared_ptr; // needed in principle, but maybe not for this class.
138
139 // Friend all the factories. Keeping them external is easier for users, but more boilerplate.
141 const G4String &name, int sides, G4double phi_start, G4double phi_tot);
142 friend RZBuilderPtr VB::CreatePolyconeBuilder(const G4String &name, G4double phi_start,
143 G4double phi_tot);
144 friend RZBuilderPtr VB::CreateCylinderBuilder(G4double unit, const G4String &name,
145 G4double endz, G4double height, G4double OR, G4double IR);
146 friend RZBuilderPtr VB::CreateCylinderBuilder(const G4String &name,
147 G4double endz, G4double height, G4double OR, G4double IR);
148
157 virtual RZBuilderPtr SetNumSides(G4double N);
158
163 RZBuilderPtr AddPlane(const RZPlane &plane);
171 RZBuilderPtr AddPlane(G4double IR, G4double OR, G4double z);
172
181 RZBuilderPtr AddPlane(G4double unit, G4double IR, G4double OR, G4double z);
182
183
188 RZBuilderPtr AddPlanes(const std::vector<RZPlane> &planes);
194 RZBuilderPtr AddPlanes(const std::vector<RZPlaneUnitless> &planes);
201 RZBuilderPtr AddPlanes(G4double unit, const std::vector<RZPlaneUnitless> &planes);
202
230
245
246
249 protected:
251 G4VSolid *SolidConstructor(const G4String &name) override {
252 return (this->*MakeSolidFunctionPtr_)(name);
253 }
254
255 private:
256 explicit RZBuilder(const G4String &name, G4double init_phi_start = 0.,
257 G4double init_phi_tot = 360, int init_sides = 4);
258
259 //These will become public as MakeSolid() in derived classes.
260 //RZBuilder(const RZBuilder &other, const G4String &new_name);
261 G4VSolid *MakePolycone(const G4String &name);
262
263 G4VSolid *MakePolyhedra(const G4String &name);
264
265 //There is no MakeCylinder() because it's a special case of Polycone'
266
267 RZBuilder(const RZBuilder &other);
268
269
270 G4int sides_{4}; // only for polyhedra
271 // private raw copy ctor
272 // values and checks...
273 G4double phi_start_deg_{0};
274 G4double phi_tot_deg{360};
275
276 G4VSolid * (RZBuilder::*MakeSolidFunctionPtr_)(const G4String &name) = nullptr;
277
278 // plane data:
279 int num_planes_{0};
280 std::vector<G4double> z_;
281 std::vector<G4double> IR_;
282 std::vector<G4double> OR_;
283
284 RZBuilder() = default;
285 RZBuilder(RZBuilder &&) noexcept = delete;
286
287 // RZBuilderPtr Clone() const override {
288 // return RZBuilderPtr(new RZBuilder(*this));
289 // }
290 };
291}
292
293// technical notes
294// You cannot have polymorphic clone in C++ with reference return, so we need a pointer return.
295// Then the copies use -> where originals use . (dot) which is annoying. So we use Create() factory methods to
296// Create the originals always as pointers too.
297// But then we make ctors private, to simplify the interface. And might as well use smart pointers while we're at it.
298// Seems this is a common pattern, but that's C++ :P
299//
300// * return from a base class Clone() returns a base class type and slices derived class members.
301// It's actually possible to have a simple Clone(): Derived(Base) {} in Derived, especially if derived has no data
302// to reconstruct, but smart pointer return and factories are the "usual" way.
303//
304// In C# all of this would be simple.
Builder class for RZ mult-plane defined solids.
Definition RZBuilder.hh:131
G4VSolid * SolidConstructor(const G4String &name) override
The polymorphic Solid constructor.
Definition RZBuilder.hh:251
A polymorphic, type-erased builder referencing any specialized builder.
VolumeBuilder: Common functionality for volume builder classes.
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.
Definition RZBuilder.cc:38
RZBuilderPtr CreateCylinderBuilder(G4double unit, const G4String &name, G4double endz, G4double height, G4double OR, G4double IR=0)
Create a simple cylinder builder.
Definition RZBuilder.cc:46
RZBuilderPtr CreatePolyconeBuilder(const G4String &name, G4double phi_start=0., G4double phi_tot=360)
Create a builder for associated IR,OR,Z defined object.
Definition RZBuilder.cc:28
RZBuilderPtr ReflectZSolidConfig()
Flip Solid Configuration.
Definition RZBuilder.cc:106
virtual RZBuilderPtr SetNumSides(G4double N)
Set number of sides.
Definition RZBuilder.cc:119
RZBuilderPtr AddPlane(const RZPlane &plane)
Adds a plane defining one IR,OR,Z triplet in the volume design.
Definition RZBuilder.cc:134
RZBuilderPtr AddPlanes(const std::vector< RZPlane > &planes)
Adds multiple RZ planes each defining one unit,IR,OR,Z set in the volume design.
Definition RZBuilder.cc:160
RZBuilderPtr FillSolidConfig()
Modifies a Solid CONFIGURATION to set all inner diameters (IDs) to 0.
Definition RZBuilder.cc:91
RZPlane for use with global or preset units.
Definition RZBuilder.hh:59
Struct for adding planes to GeantMultiPlane –DSLeonard 2024 Overloads make this not strictly needed.
Definition RZBuilder.hh:44
RZPlane(G4double u, G4double ir, G4double or_, G4double z_)
Definition RZBuilder.hh:51