From d81373bcbc573082cbf3788d12d4380968b461c5 Mon Sep 17 00:00:00 2001 From: Nam Tran Date: Fri, 15 Jan 2021 18:38:28 -0600 Subject: [PATCH] add messenger --- include/DetectorConstructionMessenger.hh | 36 +++++++++++++ src/DetectorConstructionMessenger.cc | 67 ++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 include/DetectorConstructionMessenger.hh create mode 100644 src/DetectorConstructionMessenger.cc diff --git a/include/DetectorConstructionMessenger.hh b/include/DetectorConstructionMessenger.hh new file mode 100644 index 0000000..e69d32d --- /dev/null +++ b/include/DetectorConstructionMessenger.hh @@ -0,0 +1,36 @@ +#ifndef DetectorConstructionMessenger_h +#define DetectorConstructionMessenger_h 1 + +class DetectorConstruction; +class G4UIdirectory; +class G4UIcmdWithADoubleAndUnit; +class G4UIcmdWithAIntAndUnit; +class G4UIcmdWith3VectorAndUnit; +class G4UIcmdWith3Vector; +class G4UIcmdWithABool; +class G4UIcmdWithAString; +class G4UIcmdWithADouble; + +#include "G4UImessenger.hh" +#include "globals.hh" + +class DetectorConstructionMessenger: public G4UImessenger +{ + public: + DetectorConstructionMessenger(DetectorConstruction *detCon); + ~DetectorConstructionMessenger(); + + virtual void SetNewValue(G4UIcommand *command, G4String newValues); + virtual G4String GetCurrentValue(G4UIcommand * command); + + private: + DetectorConstruction *fDetCon; + + G4UIdirectory *fMuTomoDirectory; + + G4UIcmdWithAString *fTargetMaterialCmd; + G4UIcmdWith3VectorAndUnit *fTargetSizeCmd; + G4UIcmdWith3VectorAndUnit *fTargetLocationCmd; +}; + +#endif diff --git a/src/DetectorConstructionMessenger.cc b/src/DetectorConstructionMessenger.cc new file mode 100644 index 0000000..8657474 --- /dev/null +++ b/src/DetectorConstructionMessenger.cc @@ -0,0 +1,67 @@ +#include "DetectorConstructionMessenger.hh" +#include "DetectorConstruction.hh" +#include "G4UIdirectory.hh" +#include "G4UIcmdWithADoubleAndUnit.hh" +#include "G4UIcmdWithABool.hh" +#include "G4UIcmdWithAString.hh" +#include "G4UIcmdWith3VectorAndUnit.hh" +#include "G4UIcmdWith3Vector.hh" +#include "G4UIcmdWithADouble.hh" +#include "G4RunManager.hh" + +#include "G4ios.hh" + +DetectorConstructionMessenger::DetectorConstructionMessenger( + DetectorConstruction *detCon) + : fDetCon(detCon) { + fMuTomoDirectory = new G4UIdirectory("/muTomo/"); + fMuTomoDirectory->SetGuidance("Customize muon tomography geometry commands."); + + fTargetMaterialCmd = + new G4UIcmdWithAString("/muTomo/setTargetMaterial", this); + fTargetMaterialCmd->SetGuidance("Set target material."); + fTargetMaterialCmd->SetParameterName("targetMaterial", true); + fTargetMaterialCmd->SetDefaultValue("G4_Pb"); + + fTargetSizeCmd = new G4UIcmdWith3VectorAndUnit("/muTomo/setTargetSize", this); + fTargetSizeCmd->SetGuidance("Set target size."); + fTargetSizeCmd->SetParameterName("muTomoSizeX", "muTomoSizeY", "muTomoSizeZ", + true); + fTargetSizeCmd->SetDefaultValue(G4ThreeVector(6., 2., 6.)); + fTargetSizeCmd->SetDefaultUnit("mm"); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... + +DetectorConstructionMessenger::~DetectorConstructionMessenger() { + delete fTargetMaterialCmd; + delete fTargetSizeCmd; +} + +//....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)); + // } +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... + +G4String DetectorConstructionMessenger::GetCurrentValue(G4UIcommand *command) { + G4String cv; + + // if (command == fTargetMaterialCmd) { + // cv = fDetCon->GetMaterial(); + // } + // if (command == fTargetSizeCmd) { + // cv = fTargetSizeCmd->ConvertToString(fDetCon->GetSizes(), "mm"); + // } + return cv; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....