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
33#include "VolumeBuilderTypes.hh"
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 class RZBuilder;
66 template <typename T>
67 class VolumeBuilder;
69 // See other Derived classes, or better yet the Factories "Topic" in the Doxygen html manual,
70 // For Factories for other types of shapes or sources.
71
72 // Parameters after name are only needed for polyhedra or angular information:
88 const G4String &name, int sides, G4double phi_start = 0., G4double phi_tot = 360);
89
92 const G4String &name, G4double phi_start = 0., G4double phi_tot = 360);
93
105 RZBuilderPtr CreateCylinderBuilder(G4double unit, const G4String &name,
106 G4double endz, G4double height, G4double OR, G4double IR = 0);
107
118 RZBuilderPtr CreateCylinderBuilder(const G4String &name,
119 G4double endz, G4double height, G4double OR, G4double IR = 0);
132 class RZBuilder final: public VolumeBuilder<RZBuilder> {
134 public:
136 friend class VolumeBuilder<RZBuilder>; // shouldn't be needed, maybe isn't now.
137 template <typename T>
138 friend class i_shared_ptr; // needed in principle, but maybe not for this class.
139
140 // Friend all the factories. Keeping them external is easier for users, but more boilerplate.
142 const G4String &name, int sides, G4double phi_start, G4double phi_tot);
143 friend RZBuilderPtr CreatePolyconeBuilder(const G4String &name, G4double phi_start,
144 G4double phi_tot);
145 friend RZBuilderPtr CreateCylinderBuilder(G4double unit, const G4String &name,
146 G4double endz, G4double height, G4double OR, G4double IR);
147 friend RZBuilderPtr CreateCylinderBuilder(const G4String &name,
148 G4double endz, G4double height, G4double OR, G4double IR);
149
158 virtual RZBuilderPtr SetNumSides(G4double N);
159
164 RZBuilderPtr AddPlane(const RZPlane &plane);
172 RZBuilderPtr AddPlane(G4double IR, G4double OR, G4double z);
173
182 RZBuilderPtr AddPlane(G4double unit, G4double IR, G4double OR, G4double z);
183
184
189 RZBuilderPtr AddPlanes(const std::vector<RZPlane> &planes);
195 RZBuilderPtr AddPlanes(const std::vector<RZPlaneUnitless> &planes);
202 RZBuilderPtr AddPlanes(G4double unit, const std::vector<RZPlaneUnitless> &planes);
203
231
246
247
250 protected:
252 G4VSolid *SolidConstructor(const G4String &name) override {
253 return (this->*MakeSolidFunctionPtr_)(name);
254 }
255
256 private:
257 explicit RZBuilder(const G4String &name, G4double init_phi_start = 0.,
258 G4double init_phi_tot = 360, int init_sides = 4);
259
260 //These will become public as MakeSolid() in derived classes.
261 //RZBuilder(const RZBuilder &other, const G4String &new_name);
262 G4VSolid *MakePolycone(const G4String &name);
263
264 G4VSolid *MakePolyhedra(const G4String &name);
265
266 //There is no MakeCylinder() because it's a special case of Polycone'
267
268 RZBuilder(const RZBuilder &other);
269
270
271 G4int sides_{4}; // only for polyhedra
272 // private raw copy ctor
273 // values and checks...
274 G4double phi_start_deg_{0};
275 G4double phi_tot_deg{360};
276
277 G4VSolid * (RZBuilder::*MakeSolidFunctionPtr_)(const G4String &name) = nullptr;
278
279 // plane data:
280 int num_planes_{0};
281 std::vector<G4double> z_;
282 std::vector<G4double> IR_;
283 std::vector<G4double> OR_;
284
285 RZBuilder() = default;
286 RZBuilder(RZBuilder &&) noexcept = delete;
287
288 // RZBuilderPtr Clone() const override {
289 // return RZBuilderPtr(new RZBuilder(*this));
290 // }
291 };
292}
293
294// technical notes
295// You cannot have polymorphic clone in C++ with reference return, so we need a pointer return.
296// Then the copies use -> where originals use . (dot) which is annoying. So we use Create() factory methods to
297// Create the originals always as pointers too.
298// But then we make ctors private, to simplify the interface. And might as well use smart pointers while we're at it.
299// Seems this is a common pattern, but that's C++ :P
300//
301// * return from a base class Clone() returns a base class type and slices derived class members.
302// It's actually possible to have a simple Clone(): Derived(Base) {} in Derived, especially if derived has no data
303// to reconstruct, but smart pointer return and factories are the "usual" way.
304//
305// In C# all of this would be simple.
Builder class for RZ mult-plane defined solids.
Definition RZBuilder.hh:132
friend RZBuilderPtr CreatePolyhedraBuilder(const G4String &name, int sides, G4double phi_start, G4double phi_tot)
Create a builder for associated IR,OR,Z defined object.
Definition RZBuilder.cc:36
G4VSolid * SolidConstructor(const G4String &name) override
The polymorphic Solid constructor.
Definition RZBuilder.hh:252
friend RZBuilderPtr CreateCylinderBuilder(G4double unit, const G4String &name, G4double endz, G4double height, G4double OR, G4double IR)
Create a simple cylinder builder.
Definition RZBuilder.cc:44
friend RZBuilderPtr CreatePolyconeBuilder(const G4String &name, G4double phi_start, G4double phi_tot)
Create a builder for associated IR,OR,Z defined object.
Definition RZBuilder.cc:26
A polymorphic, type-erased builder referencing any specialized builder.
VolumeBuilder: Common functionality for volume builder classes.
A wrapper for std::shared_ptr that allows and facilitates many implicit(i) type conversions.
RZPlane(G4double u, G4double ir, G4double or_, G4double z_)
Definition RZBuilder.hh:51
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:36
RZBuilderPtr CreateCylinderBuilder(G4double unit, const G4String &name, G4double endz, G4double height, G4double OR, G4double IR=0)
Create a simple cylinder builder.
Definition RZBuilder.cc:44
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:26
RZBuilderPtr ReflectZSolidConfig()
Flip Solid Configuration.
Definition RZBuilder.cc:102
virtual RZBuilderPtr SetNumSides(G4double N)
Set number of sides.
Definition RZBuilder.cc:115
RZBuilderPtr AddPlane(const RZPlane &plane)
Adds a plane defining one IR,OR,Z triplet in the volume design.
Definition RZBuilder.cc:130
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:156
RZBuilderPtr FillSolidConfig()
Modifies a Solid CONFIGURATION to set all inner diameters (IDs) to 0.
Definition RZBuilder.cc:87
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