From 5f8e2a8698077854c3928e6f14dc8d9f4a437d35 Mon Sep 17 00:00:00 2001 From: Gitea Date: Tue, 3 Apr 2018 10:40:26 +0200 Subject: [PATCH] Added a new box. You can set the inner box size with command line arguments. --- include/MedtechDetectorConstruction.hh | 2 ++ include/Parameters.hh | 5 +++++ medtech.cc | 5 +++++ src/MedtechDetectorConstruction.cc | 22 +++++++++++++++++++--- src/Parameters.cc | 12 +++++++++++- 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/include/MedtechDetectorConstruction.hh b/include/MedtechDetectorConstruction.hh index f360cb3..8397876 100644 --- a/include/MedtechDetectorConstruction.hh +++ b/include/MedtechDetectorConstruction.hh @@ -18,6 +18,8 @@ #include "G4ThreeVector.hh" #include "G4NistManager.hh" #include "G4Material.hh" +#include "G4SubtractionSolid.hh" +#include "Parameters.hh" class MedtechDetectorConstruction : public G4VUserDetectorConstruction { diff --git a/include/Parameters.hh b/include/Parameters.hh index 818914a..7fd57f7 100644 --- a/include/Parameters.hh +++ b/include/Parameters.hh @@ -23,6 +23,8 @@ private: int hdegree; int vdegree; + double box_size; + public: /* Static access method. */ static Parameters* getInstance(); @@ -37,6 +39,9 @@ public: void SetParticleEnergy(int); void SetHDegree(int); void SetVDegree(int); + + void SetBoxSize(double); + double GetBoxSize(); }; #endif /* Parameters_hh */ diff --git a/medtech.cc b/medtech.cc index 650453d..e73d641 100644 --- a/medtech.cc +++ b/medtech.cc @@ -47,6 +47,11 @@ int main(int argc,char** argv) { param -> SetVDegree(atoi(argv[i+1])); } + + else if(!strcmp("-s", argv[i])) + { + param -> SetBoxSize(atof(argv[i+1])); + } } //parameters from command line diff --git a/src/MedtechDetectorConstruction.cc b/src/MedtechDetectorConstruction.cc index 645aae3..7a8e81f 100644 --- a/src/MedtechDetectorConstruction.cc +++ b/src/MedtechDetectorConstruction.cc @@ -19,11 +19,14 @@ MedtechDetectorConstruction::~MedtechDetectorConstruction() G4VPhysicalVolume* MedtechDetectorConstruction::Construct() { + Parameters *parameter = Parameters::getInstance(); + //Material Section G4NistManager *manager = G4NistManager::Instance(); G4Material *air = manager -> FindOrBuildMaterial("G4_AIR"); G4Material *targetMaterial = manager -> FindOrBuildMaterial("G4_Pb"); G4Material *collMaterial = manager -> FindOrBuildMaterial("G4_W"); + G4Material *boxMaterial = manager -> FindOrBuildMaterial("G4_W"); //End of Material Section //Physical world @@ -47,7 +50,7 @@ G4VPhysicalVolume* MedtechDetectorConstruction::Construct() G4LogicalVolume *logicTarget = new G4LogicalVolume(solidTarget, targetMaterial, "Collimator", 0, 0, 0); G4PVPlacement *physicalTarget = new G4PVPlacement(0, //no rotation - G4ThreeVector(0, 0, 4*m), //at (0,0,0) + G4ThreeVector(0, 0, 1.1*m), //at (0,0,0) logicTarget, //it's logical volume "Target", //it's name logicWorld, //it's mother volume @@ -59,7 +62,7 @@ G4VPhysicalVolume* MedtechDetectorConstruction::Construct() G4Box *solidColl = new G4Box("Collimator 1", 0.25*m, 0.25*m, 0.1*cm); G4LogicalVolume *logicColl = new G4LogicalVolume(solidColl, collMaterial, "Collimator 1", 0, 0, 0); G4PVPlacement *physicalColl = new G4PVPlacement(0, //no rotation - G4ThreeVector(0.5*m, 0, 2*m), //at (0,0,0) + G4ThreeVector(0.5*m, 0, 10*cm), //at (0,0,0) logicColl, //it's logical volume "Collimator 1", //it's name logicWorld, //it's mother volume @@ -68,12 +71,25 @@ G4VPhysicalVolume* MedtechDetectorConstruction::Construct() G4LogicalVolume *logicColl2 = new G4LogicalVolume(solidColl, collMaterial, "Collimator 2", 0, 0, 0); G4PVPlacement *physicalColl2 = new G4PVPlacement(0, //no rotation - G4ThreeVector(-0.5*m, 0, 2*m), //at (0,0,0) + G4ThreeVector(-0.5*m, 0, 10*cm), //at (0,0,0) logicColl2, //it's logical volume "Collimator 2", //it's name logicWorld, //it's mother volume false, //no boolean operations 0); //no particular field + G4double box_size = parameter -> GetBoxSize(); + G4Box *solidB1 = new G4Box("B1", 25*cm, 25*cm, 1*cm); + G4Box *solidB2 = new G4Box("B2", box_size*cm, box_size*cm, 1.5*cm); + + G4SubtractionSolid *Box = new G4SubtractionSolid("Box", solidB1, solidB2); + G4LogicalVolume *logicBox = new G4LogicalVolume(Box, boxMaterial, "Box", 0, 0, 0); + G4PVPlacement *physicalBox = new G4PVPlacement(0, //no rotation + G4ThreeVector(0, 0, 5*cm), + logicBox, + "Box", + logicWorld, + false, + 0); return physicalWorld; } diff --git a/src/Parameters.cc b/src/Parameters.cc index 3e4abcb..c5e9779 100644 --- a/src/Parameters.cc +++ b/src/Parameters.cc @@ -17,7 +17,7 @@ Parameters* Parameters::getInstance() return instance; } -Parameters::Parameters() : ParticleEnergy(6), hdegree(0), vdegree(0) +Parameters::Parameters() : ParticleEnergy(6), hdegree(0), vdegree(0), box_size(10) { } @@ -64,3 +64,13 @@ void Parameters::SetParticleEnergy(int p) { ParticleEnergy = p; } + +void Parameters::SetBoxSize(double s) +{ + box_size = s; +} + +double Parameters::GetBoxSize() +{ + return box_size; +}