DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
RZBuilderCore.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 "VolumeBuilderBase.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:
84 const G4String &name, int sides, G4double phi_start = 0., G4double phi_tot = 360);
85
88 const G4String &name, G4double phi_start = 0., G4double phi_tot = 360);
89
101 RZBuilder CreateCylinderBuilder(G4double unit, const G4String &name,
102 G4double endz, G4double height, G4double OR, G4double IR = 0);
103
114 RZBuilder CreateCylinderBuilder(const G4String &name,
115 G4double endz, G4double height, G4double OR, G4double IR = 0);
118}
119
131 class RZBuilderCore final: public VolumeBuilderBase<RZBuilderCore> {
133 public:
134 friend class VolumeBuilderCore;
135 friend class VolumeBuilderBase<RZBuilderCore>; // 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 RZBuilder VB::CreatePolyconeBuilder(const G4String &name, G4double phi_start,
143 G4double phi_tot);
144 friend RZBuilder VB::CreateCylinderBuilder(G4double unit, const G4String &name,
145 G4double endz, G4double height, G4double OR, G4double IR);
146 friend RZBuilder VB::CreateCylinderBuilder(const G4String &name,
147 G4double endz, G4double height, G4double OR, G4double IR);
148
157 virtual RZBuilder SetNumSides(G4double N);
158
163 RZBuilder AddPlane(const RZPlane &plane);
171 RZBuilder AddPlane(G4double IR, G4double OR, G4double z);
172
181 RZBuilder AddPlane(G4double unit, G4double IR, G4double OR, G4double z);
182
183
188 RZBuilder AddPlanes(const std::vector<RZPlane> &planes);
194 RZBuilder AddPlanes(const std::vector<RZPlaneUnitless> &planes);
201 RZBuilder 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 RZBuilderCore(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 RZBuilderCore(const RZBuilderCore &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 * (RZBuilderCore::*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 RZBuilderCore() = default;
285 RZBuilderCore(RZBuilderCore &&) noexcept = delete;
286
287 // RZBuilder Clone() const override {
288 // return RZBuilder(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.
G4VSolid * SolidConstructor(const G4String &name) override
The polymorphic Solid constructor.
VolumeBuilder: Common functionality for volume builder classes.
A polymorphic, type-erased "view" of any specialized builder.
RZBuilder CreateCylinderBuilder(G4double unit, const G4String &name, G4double endz, G4double h, G4double OR, G4double IR)
Create a simple cylinder builder.
RZBuilder CreatePolyconeBuilder(const G4String &name, G4double phi_start, G4double phi_tot)
Create a builder for associated IR,OR,Z defined object.
RZBuilder CreatePolyhedraBuilder(const G4String &name, int sides, G4double phi_start, G4double phi_tot)
Create a builder for associated IR,OR,Z defined object.
RZBuilder ReflectZSolidConfig()
Flip Solid Configuration.
virtual RZBuilder SetNumSides(G4double N)
Set number of sides.
RZBuilder AddPlanes(const std::vector< RZPlane > &planes)
Adds multiple RZ planes each defining one unit,IR,OR,Z set in the volume design.
RZBuilder FillSolidConfig()
Modifies a Solid CONFIGURATION to set all inner diameters (IDs) to 0.
RZBuilder AddPlane(const RZPlane &plane)
Adds a plane defining one IR,OR,Z triplet in the volume design.
_internals_::RZBuilder RZBuilder
Shared pointer to _internals_::RZBuilderCore.
RZPlane for use with global or preset units.
Struct for adding planes to GeantMultiPlane –DSLeonard 2024 Overloads make this not strictly needed.
RZPlane(G4double u, G4double ir, G4double or_, G4double z_)