DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
ConstructBoxExample.cc
Go to the documentation of this file.
1
10// ReSharper disable CppExpressionWithoutSideEffects
11#include "DetectorConstruction_includes.hh" // common includes
12#include <VolumeBuilders.hh>
13
14using namespace CLHEP;
15namespace VB = DLG4::VolumeBuilders; // Geometry builder helpers.
16
17void DetectorConstruction::ConstructBoxExample() {
18 static bool firstcall = true;
19 if (!firstcall) {
20 // only run once
21 return;
22 }
23 firstcall = false;
24 //@formatter:on
25
26 DLG4::VolumeBuilders::SetGlobalDefaultUnit(CLHEP::mm); // set a global unit
27 VB::BuilderViewList builder_list;
28 // a small box to mark the world center
29 auto box_part = VB::CreateZDeltaBoxBuilder(
30 "box_part", // name
31 10, // x total size
32 10, // y total size
33 -5, // z start
34 10) // z change
35 ->SetColor(1, 0, 0) // red
36 ->SetPhysOffset({0, 0, 0})
37 ->AddTo(builder_list);
38
39 // multiple boxes arranged in y with a z-edged referenced to 0:
40 VB::CreateZDeltaBoxBuilder("box_part2", 100, 100, 0, 200)->SetColor(0, 1, 0) // green
41 ->AddTo(builder_list);
42 VB::CreateZDeltaBoxBuilder("box_part3", 100, 100, 0, 100)->SetColor(0, .5, .5) // blue-green
43 ->AddTo(builder_list);
44 VB::CreateZDeltaBoxBuilder("box_part4", 100, 100, 0, 50)->SetColor(0.5, 0.7, 1) // blue
45 ->AddTo(builder_list);
46 VB::CreateZDeltaBoxBuilder("box_part4", 100, 100, 50, 100)
47 ->SetColor(150. / 255, 0, 175. / 255) // purple
48 ->AddTo(builder_list);
49 // a box rotated around y with its own origin still at the z=0 edge, ie rotated off-center:
50 VB::CreateZDeltaBoxBuilder("box_part4", 100, 100, 0, 200)
51 // can set configurations in any order mostly, but can be nice to set many things up front before geometry details:
52 ->SetColor(255. / 255, 165. / 255, 0) // orange
53 ->SetPhysRotation(G4RotationMatrix().rotateY(-90.0 * deg))
54 ->AddTo(builder_list);
55 // arrange all boxes in y and set common properties:
56 double y = 0;
57 for (auto &builder : builder_list) {
58 builder->SetMother(world_phys)
59 ->SetMaterial(_copper)
60 ->ForceSolid(true)
61 ->SetPhysOffset({mm, 0, y, 0}) // distribute in y
62 ->MakePlacement();
63 y += 100;
64 }
65}
66
67//
BoxBuilder CreateZDeltaBoxBuilder(const G4double unit, const G4String &name, const G4double x_full_size, const G4double y_full_size, const G4double edge_z, const G4double z_delta)
Create a Box solid.
void SetGlobalDefaultUnit(G4double unit)
Set the default unit for all VolumeBuilder methods.
_internals_::BuilderViewList BuilderViewList
a user type to hold many builders