MCPcopy Create free account
hub / github.com/christopherpoole/CADMesh / DetectorConstruction

Class DetectorConstruction

examples/basic/basic.cc:48–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46
47
48class DetectorConstruction : public G4VUserDetectorConstruction
49{
50 public:
51 G4VPhysicalVolume* Construct()
52 {
53 // Materials //
54 G4NistManager * nist_manager = G4NistManager::Instance();
55 G4Material * air = nist_manager->FindOrBuildMaterial("G4_AIR");
56 G4Material * water = nist_manager->FindOrBuildMaterial("G4_WATER");
57
58 // World //
59 auto world_solid = new G4Box("world_solid", 2000*mm, 200*cm, 2*m);
60
61 auto world_logical = new G4LogicalVolume( world_solid
62 , air
63 , "world_logical"
64 , 0, 0, 0
65 );
66
67 world_logical->SetVisAttributes(G4VisAttributes::GetInvisible());
68
69 auto world_physical = new G4PVPlacement( 0
70 , G4ThreeVector()
71 , world_logical
72 , "world_physical"
73 , 0, false, 0
74 );
75
76 ////////////////////
77 // CADMesh :: PLY //
78 ////////////////////
79
80 // Read your file. PLY and OBJ can also be loaded using the built-in
81 // reader (no external software dependencies). Look at the other
82 // examples for using external readers.
83 auto sphere_mesh = CADMesh::TessellatedMesh::FromPLY("./sphere.ply");
84
85 // Optionally set the mesh scale and offset. These values are applied
86 // directly to the mesh vertices before generating the solid. The scale
87 // is applied before the offset inside CADMesh.
88 sphere_mesh->SetScale(400);
89 sphere_mesh->SetOffset(G4ThreeVector(500, 500, 750));
90
91 // Get the G4VSolid*. Use this like you would any other solid in Geant4.
92 auto sphere_solid = sphere_mesh->GetSolid();
93
94 auto sphere_logical = new G4LogicalVolume( sphere_solid
95 , water
96 , "logical"
97 , 0, 0, 0
98 );
99
100 auto rotation = new G4RotationMatrix();
101 rotation->rotateX(90*deg);
102
103 new G4PVPlacement( rotation
104 , G4ThreeVector()
105 , sphere_logical

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected