Import Geant4 11.3.0.beta source tree
This commit is contained in:
@@ -5,6 +5,12 @@ which **must** added in reverse chronological order (newest at the top). It must
|
||||
be used as a substitute for writing good git commit messages!
|
||||
|
||||
|
||||
## 2024-01-30 John Allison (exam-ext-vis-standalone-V11-02-00)
|
||||
- A smarter way of getting extent of geometry that ignores invisible volumes.
|
||||
Thus, if the world is marked invisible, it ignores it.
|
||||
- DrawGeometryVisAction.cc:
|
||||
- Use G4PhysicalVolumeModel to determine extent.
|
||||
|
||||
## 2023-11-15 I. Hrivnacova, John Allison (exam-ext-vis-standalone-V11-01-01)
|
||||
- Updated standalone.mac:
|
||||
- Changed "/vis/open XYZ [600x600-0+0]" to "/vis/open" to allow run-time choices
|
||||
|
||||
@@ -55,7 +55,7 @@ class DetectorConstruction : public G4VUserDetectorConstruction
|
||||
G4LogicalVolume* fScoringVolume = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace B1
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
@@ -33,25 +33,27 @@
|
||||
|
||||
#include "G4VUserVisAction.hh"
|
||||
|
||||
namespace B1 { // Taken from example/basic/B1
|
||||
class DetectorConstruction;
|
||||
namespace B1
|
||||
{ // Taken from example/basic/B1
|
||||
class DetectorConstruction;
|
||||
}
|
||||
class G4VPhysicalVolume;
|
||||
#include "G4Transform3D.hh"
|
||||
#include "G4VisExtent.hh"
|
||||
|
||||
class DrawGeometryVisAction: public G4VUserVisAction {
|
||||
public:
|
||||
DrawGeometryVisAction();
|
||||
~DrawGeometryVisAction();
|
||||
void Draw() override;
|
||||
const G4VisExtent& GetVisxtent() const {return fExtent;}
|
||||
private:
|
||||
B1::DetectorConstruction* fDetectorConstruction;
|
||||
G4VPhysicalVolume* fPhysicalVolume;
|
||||
G4Transform3D fTransform;
|
||||
G4VisExtent fExtent;
|
||||
class DrawGeometryVisAction : public G4VUserVisAction
|
||||
{
|
||||
public:
|
||||
DrawGeometryVisAction();
|
||||
~DrawGeometryVisAction();
|
||||
void Draw() override;
|
||||
const G4VisExtent& GetVisxtent() const { return fExtent; }
|
||||
|
||||
private:
|
||||
B1::DetectorConstruction* fDetectorConstruction;
|
||||
G4VPhysicalVolume* fPhysicalVolume;
|
||||
G4Transform3D fTransform;
|
||||
G4VisExtent fExtent;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,14 +35,15 @@
|
||||
|
||||
class G4Polyhedron;
|
||||
|
||||
class StandaloneVisAction: public G4VUserVisAction {
|
||||
public:
|
||||
StandaloneVisAction();
|
||||
~StandaloneVisAction();
|
||||
void Draw() override;
|
||||
private:
|
||||
G4Polyhedron* fpSubtractedPolyhedron;
|
||||
class StandaloneVisAction : public G4VUserVisAction
|
||||
{
|
||||
public:
|
||||
StandaloneVisAction();
|
||||
~StandaloneVisAction();
|
||||
void Draw() override;
|
||||
|
||||
private:
|
||||
G4Polyhedron* fpSubtractedPolyhedron;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -29,16 +29,16 @@
|
||||
|
||||
#include "DetectorConstruction.hh"
|
||||
|
||||
#include "G4RunManager.hh"
|
||||
#include "G4NistManager.hh"
|
||||
#include "G4Box.hh"
|
||||
#include "G4Cons.hh"
|
||||
#include "G4Orb.hh"
|
||||
#include "G4Sphere.hh"
|
||||
#include "G4Trd.hh"
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4NistManager.hh"
|
||||
#include "G4Orb.hh"
|
||||
#include "G4PVPlacement.hh"
|
||||
#include "G4RunManager.hh"
|
||||
#include "G4Sphere.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "G4Trd.hh"
|
||||
|
||||
namespace B1
|
||||
{
|
||||
@@ -52,7 +52,7 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
|
||||
|
||||
// Envelope parameters
|
||||
//
|
||||
G4double env_sizeXY = 20*cm, env_sizeZ = 30*cm;
|
||||
G4double env_sizeXY = 20 * cm, env_sizeZ = 30 * cm;
|
||||
G4Material* env_mat = nist->FindOrBuildMaterial("G4_WATER");
|
||||
|
||||
// Option to switch on/off checking of volumes overlaps
|
||||
@@ -62,109 +62,111 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
|
||||
//
|
||||
// World
|
||||
//
|
||||
G4double world_sizeXY = 1.2*env_sizeXY;
|
||||
G4double world_sizeZ = 1.2*env_sizeZ;
|
||||
G4double world_sizeXY = 1.2 * env_sizeXY;
|
||||
G4double world_sizeZ = 1.2 * env_sizeZ;
|
||||
G4Material* world_mat = nist->FindOrBuildMaterial("G4_AIR");
|
||||
|
||||
auto solidWorld = new G4Box("World", // its name
|
||||
0.5 * world_sizeXY, 0.5 * world_sizeXY, 0.5 * world_sizeZ); // its size
|
||||
auto solidWorld =
|
||||
new G4Box("World", // its name
|
||||
0.5 * world_sizeXY, 0.5 * world_sizeXY, 0.5 * world_sizeZ); // its size
|
||||
|
||||
auto logicWorld = new G4LogicalVolume(solidWorld, // its solid
|
||||
world_mat, // its material
|
||||
"World"); // its name
|
||||
world_mat, // its material
|
||||
"World"); // its name
|
||||
|
||||
auto physWorld = new G4PVPlacement(nullptr, // no rotation
|
||||
G4ThreeVector(), // at (0,0,0)
|
||||
logicWorld, // its logical volume
|
||||
"World", // its name
|
||||
nullptr, // its mother volume
|
||||
false, // no boolean operation
|
||||
0, // copy number
|
||||
checkOverlaps); // overlaps checking
|
||||
G4ThreeVector(), // at (0,0,0)
|
||||
logicWorld, // its logical volume
|
||||
"World", // its name
|
||||
nullptr, // its mother volume
|
||||
false, // no boolean operation
|
||||
0, // copy number
|
||||
checkOverlaps); // overlaps checking
|
||||
|
||||
//
|
||||
// Envelope
|
||||
//
|
||||
auto solidEnv = new G4Box("Envelope", // its name
|
||||
0.5 * env_sizeXY, 0.5 * env_sizeXY, 0.5 * env_sizeZ); // its size
|
||||
auto solidEnv = new G4Box("Envelope", // its name
|
||||
0.5 * env_sizeXY, 0.5 * env_sizeXY, 0.5 * env_sizeZ); // its size
|
||||
|
||||
auto logicEnv = new G4LogicalVolume(solidEnv, // its solid
|
||||
env_mat, // its material
|
||||
"Envelope"); // its name
|
||||
env_mat, // its material
|
||||
"Envelope"); // its name
|
||||
|
||||
new G4PVPlacement(nullptr, // no rotation
|
||||
G4ThreeVector(), // at (0,0,0)
|
||||
logicEnv, // its logical volume
|
||||
"Envelope", // its name
|
||||
logicWorld, // its mother volume
|
||||
false, // no boolean operation
|
||||
0, // copy number
|
||||
checkOverlaps); // overlaps checking
|
||||
G4ThreeVector(), // at (0,0,0)
|
||||
logicEnv, // its logical volume
|
||||
"Envelope", // its name
|
||||
logicWorld, // its mother volume
|
||||
false, // no boolean operation
|
||||
0, // copy number
|
||||
checkOverlaps); // overlaps checking
|
||||
|
||||
//
|
||||
// Shape 1
|
||||
//
|
||||
G4Material* shape1_mat = nist->FindOrBuildMaterial("G4_A-150_TISSUE");
|
||||
G4ThreeVector pos1 = G4ThreeVector(0, 2*cm, -7*cm);
|
||||
G4ThreeVector pos1 = G4ThreeVector(0, 2 * cm, -7 * cm);
|
||||
|
||||
// Conical section shape
|
||||
G4double shape1_rmina = 0.*cm, shape1_rmaxa = 2.*cm;
|
||||
G4double shape1_rminb = 0.*cm, shape1_rmaxb = 4.*cm;
|
||||
G4double shape1_hz = 3.*cm;
|
||||
G4double shape1_phimin = 0.*deg, shape1_phimax = 360.*deg;
|
||||
G4double shape1_rmina = 0. * cm, shape1_rmaxa = 2. * cm;
|
||||
G4double shape1_rminb = 0. * cm, shape1_rmaxb = 4. * cm;
|
||||
G4double shape1_hz = 3. * cm;
|
||||
G4double shape1_phimin = 0. * deg, shape1_phimax = 360. * deg;
|
||||
auto solidShape1 = new G4Cons("Shape1", shape1_rmina, shape1_rmaxa, shape1_rminb, shape1_rmaxb,
|
||||
shape1_hz, shape1_phimin, shape1_phimax);
|
||||
shape1_hz, shape1_phimin, shape1_phimax);
|
||||
|
||||
auto logicShape1 = new G4LogicalVolume(solidShape1, // its solid
|
||||
shape1_mat, // its material
|
||||
"Shape1"); // its name
|
||||
shape1_mat, // its material
|
||||
"Shape1"); // its name
|
||||
|
||||
new G4PVPlacement(nullptr, // no rotation
|
||||
pos1, // at position
|
||||
logicShape1, // its logical volume
|
||||
"Shape1", // its name
|
||||
logicEnv, // its mother volume
|
||||
false, // no boolean operation
|
||||
0, // copy number
|
||||
checkOverlaps); // overlaps checking
|
||||
pos1, // at position
|
||||
logicShape1, // its logical volume
|
||||
"Shape1", // its name
|
||||
logicEnv, // its mother volume
|
||||
false, // no boolean operation
|
||||
0, // copy number
|
||||
checkOverlaps); // overlaps checking
|
||||
|
||||
//
|
||||
// Shape 2
|
||||
//
|
||||
G4Material* shape2_mat = nist->FindOrBuildMaterial("G4_BONE_COMPACT_ICRU");
|
||||
G4ThreeVector pos2 = G4ThreeVector(0, -1*cm, 7*cm);
|
||||
G4ThreeVector pos2 = G4ThreeVector(0, -1 * cm, 7 * cm);
|
||||
|
||||
// Trapezoid shape
|
||||
G4double shape2_dxa = 12*cm, shape2_dxb = 12*cm;
|
||||
G4double shape2_dya = 10*cm, shape2_dyb = 16*cm;
|
||||
G4double shape2_dz = 6*cm;
|
||||
auto solidShape2 = new G4Trd("Shape2", // its name
|
||||
0.5 * shape2_dxa, 0.5 * shape2_dxb, 0.5 * shape2_dya, 0.5 * shape2_dyb,
|
||||
0.5 * shape2_dz); // its size
|
||||
G4double shape2_dxa = 12 * cm, shape2_dxb = 12 * cm;
|
||||
G4double shape2_dya = 10 * cm, shape2_dyb = 16 * cm;
|
||||
G4double shape2_dz = 6 * cm;
|
||||
auto solidShape2 =
|
||||
new G4Trd("Shape2", // its name
|
||||
0.5 * shape2_dxa, 0.5 * shape2_dxb, 0.5 * shape2_dya, 0.5 * shape2_dyb,
|
||||
0.5 * shape2_dz); // its size
|
||||
|
||||
auto logicShape2 = new G4LogicalVolume(solidShape2, // its solid
|
||||
shape2_mat, // its material
|
||||
"Shape2"); // its name
|
||||
shape2_mat, // its material
|
||||
"Shape2"); // its name
|
||||
|
||||
new G4PVPlacement(nullptr, // no rotation
|
||||
pos2, // at position
|
||||
logicShape2, // its logical volume
|
||||
"Shape2", // its name
|
||||
logicEnv, // its mother volume
|
||||
false, // no boolean operation
|
||||
0, // copy number
|
||||
checkOverlaps); // overlaps checking
|
||||
pos2, // at position
|
||||
logicShape2, // its logical volume
|
||||
"Shape2", // its name
|
||||
logicEnv, // its mother volume
|
||||
false, // no boolean operation
|
||||
0, // copy number
|
||||
checkOverlaps); // overlaps checking
|
||||
|
||||
// Set Shape2 as scoring volume
|
||||
//
|
||||
fScoringVolume = logicShape2;
|
||||
|
||||
//
|
||||
//always return the physical World
|
||||
// always return the physical World
|
||||
//
|
||||
return physWorld;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
}
|
||||
} // namespace B1
|
||||
|
||||
@@ -30,38 +30,46 @@
|
||||
|
||||
#include "DrawGeometryVisAction.hh"
|
||||
|
||||
#include "G4VVisManager.hh"
|
||||
#include "DetectorConstruction.hh"
|
||||
#include "G4VPhysicalVolume.hh"
|
||||
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4VSolid.hh"
|
||||
#include "G4PhysicalVolumeModel.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "G4VPhysicalVolume.hh"
|
||||
#include "G4VSolid.hh"
|
||||
#include "G4VVisManager.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
DrawGeometryVisAction::DrawGeometryVisAction() {
|
||||
DrawGeometryVisAction::DrawGeometryVisAction()
|
||||
{
|
||||
// Get a physical volume from your detector construction
|
||||
fDetectorConstruction = new B1::DetectorConstruction();
|
||||
// (I think, properly, we should delete this in the destructor.)
|
||||
fPhysicalVolume = fDetectorConstruction->Construct();
|
||||
// (I think the deletion of constructed volumes is handled by the volume stores.)
|
||||
// Give this an overall transform to avoid clash with other vis action(s)
|
||||
fTransform = G4Translate3D(-20*cm,20*cm,0);
|
||||
fExtent = fPhysicalVolume->GetLogicalVolume()->GetSolid()->GetExtent().Transform(fTransform);
|
||||
// Give this an overall transform to avoid clash with other vis action(s) in this case
|
||||
fTransform = G4Translate3D(-20 * cm, 20 * cm, 0);
|
||||
// Get extent and transform if required
|
||||
G4PhysicalVolumeModel pvModel(fPhysicalVolume);
|
||||
fExtent = pvModel.GetExtent();
|
||||
fExtent.Transform(fTransform);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
DrawGeometryVisAction::~DrawGeometryVisAction() {
|
||||
DrawGeometryVisAction::~DrawGeometryVisAction()
|
||||
{
|
||||
delete fDetectorConstruction;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void DrawGeometryVisAction::Draw() {
|
||||
void DrawGeometryVisAction::Draw()
|
||||
{
|
||||
G4VVisManager* pVisManager = G4VVisManager::GetConcreteInstance();
|
||||
if (pVisManager) {
|
||||
pVisManager->DrawGeometry(fPhysicalVolume,fTransform);
|
||||
pVisManager->DrawGeometry(fPhysicalVolume, fTransform);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,21 +30,22 @@
|
||||
|
||||
#include "StandaloneVisAction.hh"
|
||||
|
||||
#include "G4VVisManager.hh"
|
||||
#include "G4VisAttributes.hh"
|
||||
#include "G4Polyhedron.hh"
|
||||
#include "G4Box.hh"
|
||||
#include "G4Polyhedron.hh"
|
||||
#include "G4SubtractionSolid.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "G4VVisManager.hh"
|
||||
#include "G4VisAttributes.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
StandaloneVisAction::StandaloneVisAction() {
|
||||
auto pA = G4Box("boxA",3*cm,3*cm,3*cm).CreatePolyhedron();
|
||||
auto pB = G4Box("boxB",1*cm,1*cm,1*cm).CreatePolyhedron();
|
||||
pB->Transform(G4Translate3D(3*cm,3*cm,3*cm));
|
||||
StandaloneVisAction::StandaloneVisAction()
|
||||
{
|
||||
auto pA = G4Box("boxA", 3 * cm, 3 * cm, 3 * cm).CreatePolyhedron();
|
||||
auto pB = G4Box("boxB", 1 * cm, 1 * cm, 1 * cm).CreatePolyhedron();
|
||||
pB->Transform(G4Translate3D(3 * cm, 3 * cm, 3 * cm));
|
||||
fpSubtractedPolyhedron = new G4Polyhedron(pA->subtract(*pB));
|
||||
G4VisAttributes subVisAtts(G4Colour(0,1,1));
|
||||
G4VisAttributes subVisAtts(G4Colour(0, 1, 1));
|
||||
fpSubtractedPolyhedron->SetVisAttributes(subVisAtts);
|
||||
delete pA;
|
||||
delete pB;
|
||||
@@ -52,32 +53,31 @@ StandaloneVisAction::StandaloneVisAction() {
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
StandaloneVisAction::~StandaloneVisAction() {
|
||||
StandaloneVisAction::~StandaloneVisAction()
|
||||
{
|
||||
delete fpSubtractedPolyhedron;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void StandaloneVisAction::Draw() {
|
||||
void StandaloneVisAction::Draw()
|
||||
{
|
||||
G4VVisManager* pVisManager = G4VVisManager::GetConcreteInstance();
|
||||
if (pVisManager) {
|
||||
|
||||
// Simple box...
|
||||
pVisManager->Draw(G4Box("box",2*cm,2*cm,2*cm),
|
||||
G4VisAttributes(G4Colour(1,1,0)));
|
||||
pVisManager->Draw(G4Box("box", 2 * cm, 2 * cm, 2 * cm), G4VisAttributes(G4Colour(1, 1, 0)));
|
||||
|
||||
// Boolean solid...
|
||||
G4Box boxA("boxA",3*cm,3*cm,3*cm);
|
||||
G4Box boxB("boxB",1*cm,1*cm,1*cm);
|
||||
G4SubtractionSolid subtracted("subtracted_boxes",&boxA,&boxB,
|
||||
G4Translate3D(3*cm,3*cm,3*cm));
|
||||
pVisManager->Draw(subtracted,
|
||||
G4VisAttributes(G4Colour(0,1,1)),
|
||||
G4Translate3D(-6*cm,-6*cm,-6*cm));
|
||||
G4Box boxA("boxA", 3 * cm, 3 * cm, 3 * cm);
|
||||
G4Box boxB("boxB", 1 * cm, 1 * cm, 1 * cm);
|
||||
G4SubtractionSolid subtracted("subtracted_boxes", &boxA, &boxB,
|
||||
G4Translate3D(3 * cm, 3 * cm, 3 * cm));
|
||||
pVisManager->Draw(subtracted, G4VisAttributes(G4Colour(0, 1, 1)),
|
||||
G4Translate3D(-6 * cm, -6 * cm, -6 * cm));
|
||||
|
||||
// Same, but explicit polyhedron...
|
||||
// The heavy work is done in the constructor
|
||||
pVisManager->Draw(*fpSubtractedPolyhedron,G4Translate3D(6*cm,6*cm,6*cm));
|
||||
pVisManager->Draw(*fpSubtractedPolyhedron, G4Translate3D(6 * cm, 6 * cm, 6 * cm));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,38 +32,35 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#include "globals.hh"
|
||||
#include "DrawGeometryVisAction.hh"
|
||||
#include "StandaloneVisAction.hh"
|
||||
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "G4UIExecutive.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4VisExecutive.hh"
|
||||
#include "G4VisExtent.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIExecutive.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
|
||||
#include "StandaloneVisAction.hh"
|
||||
#include "DrawGeometryVisAction.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
int main(int argc,char** argv) {
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
G4UIExecutive* ui = new G4UIExecutive(argc, argv);
|
||||
|
||||
G4VisManager* visManager = new G4VisExecutive;
|
||||
visManager->Initialize ();
|
||||
visManager->Initialize();
|
||||
|
||||
auto standaloneVisAction = new StandaloneVisAction;
|
||||
visManager->RegisterRunDurationUserVisAction
|
||||
("A standalone example - 3 boxes, 2 with boolean subtracted cutout",
|
||||
standaloneVisAction,
|
||||
G4VisExtent(-10*cm,10*cm,-10*cm,10*cm,-10*cm,10*cm));
|
||||
visManager->RegisterRunDurationUserVisAction(
|
||||
"A standalone example - 3 boxes, 2 with boolean subtracted cutout", standaloneVisAction,
|
||||
G4VisExtent(-10 * cm, 10 * cm, -10 * cm, 10 * cm, -10 * cm, 10 * cm));
|
||||
|
||||
auto geometryVisAction = new DrawGeometryVisAction;
|
||||
visManager->RegisterRunDurationUserVisAction
|
||||
("A detector geometry",
|
||||
geometryVisAction,
|
||||
geometryVisAction->GetVisxtent());
|
||||
visManager->RegisterRunDurationUserVisAction("A detector geometry", geometryVisAction,
|
||||
geometryVisAction->GetVisxtent());
|
||||
|
||||
G4UImanager::GetUIpointer()->ApplyCommand ("/control/execute standalone.mac");
|
||||
G4UImanager::GetUIpointer()->ApplyCommand("/control/execute standalone.mac");
|
||||
ui->SessionStart();
|
||||
|
||||
delete geometryVisAction;
|
||||
@@ -73,4 +70,3 @@ int main(int argc,char** argv) {
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
Reference in New Issue
Block a user