diff --git a/include/DetectorConstruction.hh b/include/DetectorConstruction.hh index 0be4e3f..ef5c6e3 100644 --- a/include/DetectorConstruction.hh +++ b/include/DetectorConstruction.hh @@ -7,6 +7,7 @@ class G4VPhysicalVolume; class G4LogicalVolume; +class DetectorConstructionMessenger; /// Detector construction class to define materials and geometry. @@ -19,12 +20,9 @@ class DetectorConstruction : public G4VUserDetectorConstruction virtual G4VPhysicalVolume* Construct(); virtual void ConstructSDandField(); - const G4String GetTargetMaterial() { return fTargetMaterial; } - void SetTargetMaterial(const G4String mat) { fTargetMaterial = mat; } + void ComputeGeometry(); - protected: - // void DefineMaterials(); - G4bool fCheckOverlaps; + // public fields to avoid all getters and setters G4double scSizeX; G4double scSizeY; G4double scSizeZ; @@ -47,11 +45,19 @@ class DetectorConstruction : public G4VUserDetectorConstruction G4double targetX; G4double targetY; G4double targetZ; - G4String fTargetMaterial; + G4double targetLocationX; + G4double targetLocationY; + G4double targetLocationZ; + G4String targetMaterialStr; G4double worldSizeX; G4double worldSizeY; G4double worldSizeZ; + + protected: + // void DefineMaterials(); + G4bool fCheckOverlaps; + DetectorConstructionMessenger *fDetConMessenger; }; //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/src/DetectorConstruction.cc b/src/DetectorConstruction.cc index fac507f..d411c47 100644 --- a/src/DetectorConstruction.cc +++ b/src/DetectorConstruction.cc @@ -1,5 +1,6 @@ #include "DetectorConstruction.hh" +#include "DetectorConstructionMessenger.hh" #include "G4Box.hh" #include "G4LogicalVolume.hh" #include "G4MultiFunctionalDetector.hh" @@ -21,10 +22,11 @@ DetectorConstruction::DetectorConstruction() : G4VUserDetectorConstruction(), fCheckOverlaps(true) { + fDetConMessenger = new DetectorConstructionMessenger(this); // DefineMaterials(); } -DetectorConstruction::~DetectorConstruction() {} +DetectorConstruction::~DetectorConstruction() { delete fDetConMessenger; } G4VPhysicalVolume *DetectorConstruction::Construct() { G4NistManager *nist = G4NistManager::Instance(); @@ -34,35 +36,8 @@ G4VPhysicalVolume *DetectorConstruction::Construct() { G4Material *scMaterial = nist->FindOrBuildMaterial("G4_PLASTIC_SC_VINYLTOLUENE"); - // World and crystals - scSizeX = 5.0 * cm; - scSizeY = 50.0 * cm; - scSizeZ = 1. * cm; - scGapX = 0.2 * cm; - scGapZ = 0.2 * cm; - nScBar = 10; - nLayerTop = 2; - nLayerBottom = 2; - - layerGapZ = 1 * cm; - topBotGap = 50 * cm; - - layerSizeX = nScBar * scSizeX + nScBar * scGapX; - layerSizeY = nScBar * scSizeX + nScBar * scGapX; - layerSizeZ = scSizeZ + scGapZ; - - concreteX = 30 * cm; - concreteY = 30 * cm; - concreteZ = 30 * cm; - targetX = 10 * cm; - targetY = 10 * cm; - targetZ = 5 * cm; - - worldSizeX = 1.2 * layerSizeX; - worldSizeY = 1.2 * layerSizeY; - worldSizeZ = - 1.2 * ((nLayerBottom + nLayerTop) * (layerSizeZ + layerGapZ) + topBotGap); - + // ComputeGeometry first + ComputeGeometry(); // world volume G4Box *solidWorld = new G4Box("World", 0.5 * worldSizeX, 0.5 * worldSizeY, 0.5 * worldSizeZ); @@ -90,8 +65,9 @@ G4VPhysicalVolume *DetectorConstruction::Construct() { new G4Box("target", targetX / 2, targetY / 2, targetZ / 2); G4LogicalVolume *logTarget = new G4LogicalVolume(solidTarget, targetMaterial, "target"); - new G4PVPlacement(0, G4ThreeVector(), logTarget, "target", logConcrete, false, - 0, fCheckOverlaps); + new G4PVPlacement( + 0, G4ThreeVector(targetLocationX, targetLocationY, targetLocationZ), + logTarget, "target", logConcrete, false, 0, fCheckOverlaps); // scintillators G4Box *solidScX = @@ -177,3 +153,33 @@ void DetectorConstruction::ConstructSDandField() { mfDetY->RegisterPrimitive(primitiv2); SetSensitiveDetector("logicScY", mfDetY); } + +void DetectorConstruction::ComputeGeometry() { + scSizeX = 5.0 * cm; + scSizeY = 50.0 * cm; + scSizeZ = 1. * cm; + scGapX = 0.2 * cm; + scGapZ = 0.2 * cm; + nScBar = 10; + nLayerTop = 2; + nLayerBottom = 2; + + layerGapZ = 1 * cm; + topBotGap = 50 * cm; + + layerSizeX = nScBar * scSizeX + nScBar * scGapX; + layerSizeY = nScBar * scSizeX + nScBar * scGapX; + layerSizeZ = scSizeZ + scGapZ; + + concreteX = 30 * cm; + concreteY = 30 * cm; + concreteZ = 30 * cm; + targetX = 10 * cm; + targetY = 10 * cm; + targetZ = 5 * cm; + + worldSizeX = 1.2 * layerSizeX; + worldSizeY = 1.2 * layerSizeY; + worldSizeZ = + 1.2 * ((nLayerBottom + nLayerTop) * (layerSizeZ + layerGapZ) + topBotGap); +} diff --git a/src/DetectorConstructionMessenger.cc b/src/DetectorConstructionMessenger.cc index 8657474..593809f 100644 --- a/src/DetectorConstructionMessenger.cc +++ b/src/DetectorConstructionMessenger.cc @@ -17,18 +17,25 @@ DetectorConstructionMessenger::DetectorConstructionMessenger( fMuTomoDirectory = new G4UIdirectory("/muTomo/"); fMuTomoDirectory->SetGuidance("Customize muon tomography geometry commands."); - fTargetMaterialCmd = - new G4UIcmdWithAString("/muTomo/setTargetMaterial", this); + fTargetMaterialCmd = new G4UIcmdWithAString("/muTomo/targetMaterial", this); fTargetMaterialCmd->SetGuidance("Set target material."); fTargetMaterialCmd->SetParameterName("targetMaterial", true); fTargetMaterialCmd->SetDefaultValue("G4_Pb"); - fTargetSizeCmd = new G4UIcmdWith3VectorAndUnit("/muTomo/setTargetSize", this); + fTargetSizeCmd = new G4UIcmdWith3VectorAndUnit("/muTomo/targetSize", this); fTargetSizeCmd->SetGuidance("Set target size."); - fTargetSizeCmd->SetParameterName("muTomoSizeX", "muTomoSizeY", "muTomoSizeZ", + fTargetSizeCmd->SetParameterName("targetSizeX", "targetSizeY", "targetSizeZ", true); fTargetSizeCmd->SetDefaultValue(G4ThreeVector(6., 2., 6.)); fTargetSizeCmd->SetDefaultUnit("mm"); + + fTargetLocationCmd = + new G4UIcmdWith3VectorAndUnit("/muTomo/targetLocation", this); + fTargetLocationCmd->SetGuidance("Set target location."); + fTargetLocationCmd->SetParameterName("targetLocationX", "targetLocationY", + "targetLocationZ", true); + fTargetLocationCmd->SetDefaultValue(G4ThreeVector(0., 0., 0.)); + fTargetLocationCmd->SetDefaultUnit("mm"); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... @@ -36,18 +43,28 @@ DetectorConstructionMessenger::DetectorConstructionMessenger( DetectorConstructionMessenger::~DetectorConstructionMessenger() { delete fTargetMaterialCmd; delete fTargetSizeCmd; + delete fTargetLocationCmd; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... void DetectorConstructionMessenger::SetNewValue(G4UIcommand *command, G4String newValue) { - // if (command == fTargetMaterialCmd) { - // fDetCon->SetMaterial(newValue); - // } - // if (command == fTargetSizeCmd) { - // fDetCon->SetSizes(fTargetSizeCmd->GetNew3VectorValue(newValue)); - // } + if (command == fTargetMaterialCmd) { + fDetCon->targetMaterialStr = newValue; + } + if (command == fTargetSizeCmd) { + G4ThreeVector newPos = fTargetSizeCmd->GetNew3VectorValue(newValue); + fDetCon->targetX = newPos.x(); + fDetCon->targetY = newPos.y(); + fDetCon->targetZ = newPos.z(); + } + if (command == fTargetLocationCmd) { + G4ThreeVector newLoc = fTargetLocationCmd->GetNew3VectorValue(newValue); + fDetCon->targetLocationX = newLoc.x(); + fDetCon->targetLocationY = newLoc.y(); + fDetCon->targetLocationZ = newLoc.z(); + } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... @@ -55,12 +72,19 @@ void DetectorConstructionMessenger::SetNewValue(G4UIcommand *command, G4String DetectorConstructionMessenger::GetCurrentValue(G4UIcommand *command) { G4String cv; - // if (command == fTargetMaterialCmd) { - // cv = fDetCon->GetMaterial(); - // } - // if (command == fTargetSizeCmd) { - // cv = fTargetSizeCmd->ConvertToString(fDetCon->GetSizes(), "mm"); - // } + if (command == fTargetMaterialCmd) { + cv = fDetCon->targetMaterialStr; + } + if (command == fTargetSizeCmd) { + cv = fTargetSizeCmd->ConvertToString( + G4ThreeVector(fDetCon->targetX, fDetCon->targetY, fDetCon->targetZ)); + } + if (command == fTargetLocationCmd) { + cv = fTargetLocationCmd->ConvertToString( + G4ThreeVector(fDetCon->targetLocationX, fDetCon->targetLocationY, + fDetCon->targetLocationZ)); + } + return cv; }