DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
ConstructExample1.cc
Go to the documentation of this file.
1
10#include "DetectorConstruction_includes.hh" // common includes
11#include <VolumeBuilders.hh>
12
13using namespace CLHEP;
14namespace VB = DLG4::VolumeBuilders; // Geometry builder helpers
15
16void DetectorConstruction::ConstructExample1() {
17 static bool firstcall = true;
18 if (!firstcall) {
19 // only run once
20 return;
21 }
22 firstcall = false;
23 //@formatter:on
24
25 VB::SetGlobalDefaultUnit(CLHEP::cm); // set a global unit
26 G4Color coppertone(0.72, 0.45, .2);
28 p.unit = mm; // see prior note.
29 G4double some_reference;
30
31 // some shape to union onto our main shape:
32 auto another_builder_or_geant_solid = VB::CreatePolyconeBuilder("union")
33 //@formatter:off
34 ->AddPlane(p.IR = 90 , p.OR = 100*2.0/sqrt(3.) , p.z = -10 )
35 ->AddPlane(p.IR , p.OR , p.z -= 15 );
36
37 // just a descriptively named variable for the documented README example:
38 G4VPhysicalVolume *another_builder_or_geant_physical_volume = world_phys;
39
40 auto ring_part = VB::CreatePolyhedraBuilder("ring_part", 6)
41 // can set configurations in any order mostly, but can be nice to set many things up front before geometry details:
42 ->SetMaterial(_copper)
43 ->SetColor(coppertone) // We can pre-configure the logical-volume!
44 ->ForceSolid(true)
45 ->AddUnion(another_builder_or_geant_solid, {0, 0, 0}) // with relative z, may not need to provide offset.
46 // can predefine this. If a builder, it will auto build if needed!:
47 ->SetMother(another_builder_or_geant_physical_volume)
48 ->SetDefaultUnit(CLHEP::cm)
49 // You can skip things to default them. Less Noise!!
50 // ->SetPhysOffset(something) // z referencing defined below may be enough!!
51 // ->SetPhysRotation(zero_rot)
52 // clang-format-off
53 ->AddPlane(p.IR = 50, p.OR = 100, p.z = -10)
54 ->AddPlane(p.IR, p.OR, p.z -= 40)
55 ->AddPlane(p.IR = 90, p.OR, p.z)
56 ->AddPlane(p.IR, p.OR, some_reference = p.z -= 40) // set a reference for later.
57 ->MakePlacement();
58 // clang-format-on
59
60 // Logcial volume was auto-named "ring_part_L"
61 // Physical volume was auto-maned "ring_part_P" and can get auto copy_no(default) or auto name-numbering.
62}
63
64//
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.
void SetGlobalDefaultUnit(G4double unit)
Set the default unit for all VolumeBuilder methods.
Struct for adding planes to GeantMultiPlane –DSLeonard 2024 Overloads make this not strictly needed.