DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
ConstructAssembly.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::ConstructAssembly() {
17 static bool firstcall = true;
18 if (!firstcall) {
19 // only run once
20 return;
21 }
22 firstcall = false;
23 //@formatter:on
24
25 DLG4::VolumeBuilders::SetGlobalDefaultUnit(CLHEP::mm); // 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 auto shape = VB::CreatePolyhedraBuilder("part", 3)
32 //@formatter:off
33 ->AddPlane(p.IR = 40 , p.OR = 50 , p.z = 0 )
34 ->AddPlane(p.IR , p.OR , p.z -= 100 );
35 //@formatter:on
36
37 auto assembly = VB::CreateAssembly("example_assembly");
38 auto temp = shape;
39 for (int i = 0; i < 3; i++) {
40 temp->ForkAndReset("part_" + std::to_string(i))
41 ->SetPhysOffset({0, 250. * (i), 0.})
42 ->AddTo(assembly);
43 }
44
45 assembly->SetMother(world_phys)
46 ->SetMaterial(_copper)
47 ->SetColor(0, 1, 0) // We can pre-configure the logical-volume!
48 ->ForceSolid(true)
49 ->SetPhysOffset({0, 0, -200})
50 ->PlaceAndFork()
51 ->SetColor(1, 0, 0) // but the fork still shares logical volume so they are now ALL red.
52 ->StackPhysRotation(G4RotationMatrix().rotateY(-90.0 * deg))
53 ->MakePlacement()
54 // but we can clone only the Final solid, and rebuild LV with new color:
55 ->ForkForLogicalVolume("blue")
56 ->SetColor(0, 0, 1)
57 ->StackPhysRotation(G4RotationMatrix().rotateY(-90.0 * deg))
58 ->MakePlacement();
59}
RZBuilder CreatePolyhedraBuilder(const G4String &name, int sides, G4double phi_start, G4double phi_tot)
Create a builder for associated IR,OR,Z defined object.
Assembly CreateAssembly(G4String name)
Assembly of strucures, ie builders and/or other assemblies.
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.