File indexing completed on 2025-01-31 09:22:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #include "DetectorMessenger.hh"
0032 #include "G4UIdirectory.hh"
0033 #include "G4UIcmdWithADoubleAndUnit.hh"
0034 #include "G4UIcmdWithAString.hh"
0035 #include "G4UIcmdWithABool.hh"
0036 #include "G4UIcmdWithoutParameter.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "DetectorConstruction.hh"
0039 #include "G4RunManager.hh"
0040
0041 DetectorMessenger::DetectorMessenger(AnalysisManager* analysis_manager)
0042 : geometryHasChanged(false)
0043 {
0044 changeTheGeometryDir = new G4UIdirectory("/geometrySetup/");
0045 changeTheGeometryDir -> SetGuidance("Geometry setup");
0046
0047 changeTheDetectorCmd = new G4UIcmdWithAString("/geometrySetup/selectDetector",this);
0048 changeTheDetectorCmd -> SetGuidance("Select the type of detector you wish to use");
0049 changeTheDetectorCmd -> SetParameterName("Material",false);
0050 changeTheDetectorCmd -> AvailableForStates(G4State_PreInit);
0051
0052 changeDetectorDimensionDir = new G4UIdirectory("/geometrySetup/detectorDimension/");
0053 changeDetectorDimensionDir -> SetGuidance("Modify the dimensions of the detector");
0054
0055 changeDetectorSizeWidthCmd = new G4UIcmdWithADoubleAndUnit("/geometrySetup/detectorDimension/setWidth", this);
0056 changeDetectorSizeWidthCmd -> SetGuidance("Set the width of the detector");
0057 changeDetectorSizeWidthCmd -> SetParameterName("Width", false);
0058 changeDetectorSizeWidthCmd -> SetRange("Width >= 0.1 && Width <= 150.");
0059 changeDetectorSizeWidthCmd -> SetUnitCategory("Length");
0060 changeDetectorSizeWidthCmd -> SetDefaultUnit("um");
0061 changeDetectorSizeWidthCmd -> AvailableForStates(G4State_PreInit);
0062
0063 changeDetectorSizeThicknessCmd = new G4UIcmdWithADoubleAndUnit("/geometrySetup/detectorDimension/setThickness", this);
0064 changeDetectorSizeThicknessCmd -> SetGuidance("Set the thickness of the detector");
0065 changeDetectorSizeThicknessCmd -> SetParameterName("Thickness", false);
0066 changeDetectorSizeThicknessCmd -> SetRange("Thickness >= 0.1 && Thickness <= 50.");
0067 changeDetectorSizeThicknessCmd -> SetUnitCategory("Length");
0068 changeDetectorSizeThicknessCmd -> SetDefaultUnit("um");
0069 changeDetectorSizeThicknessCmd -> AvailableForStates(G4State_PreInit);
0070
0071 changeSecondStageDimensionDir = new G4UIdirectory("/geometrySetup/detectorDimension/secondStage/");
0072 changeSecondStageDimensionDir -> SetGuidance("Modify the dimensions of the E stage for the telescope detector");
0073
0074 changeSecondStageSizeWidthCmd = new G4UIcmdWithADoubleAndUnit("/geometrySetup/detectorDimension/secondStage/setWidth", this);
0075 changeSecondStageSizeWidthCmd -> SetGuidance("Set the width of the E-stage for telescope detector");
0076 changeSecondStageSizeWidthCmd -> SetParameterName("Width", false);
0077 changeSecondStageSizeWidthCmd -> SetRange("Width >= 10 && Width <= 1000.");
0078 changeSecondStageSizeWidthCmd -> SetUnitCategory("Length");
0079 changeSecondStageSizeWidthCmd -> SetDefaultUnit("um");
0080 changeSecondStageSizeWidthCmd -> AvailableForStates(G4State_PreInit);
0081
0082 changeSecondStageSizeThicknessCmd = new G4UIcmdWithADoubleAndUnit("/geometrySetup/detectorDimension/secondStage/setThickness", this);
0083 changeSecondStageSizeThicknessCmd -> SetGuidance("Set the thickness of the E-stage for telescope detector");
0084 changeSecondStageSizeThicknessCmd -> SetParameterName("Thickness", false);
0085 changeSecondStageSizeThicknessCmd -> SetRange("Thickness >= 10 && Thickness <= 1000.");
0086 changeSecondStageSizeThicknessCmd -> SetUnitCategory("Length");
0087 changeSecondStageSizeThicknessCmd -> SetDefaultUnit("um");
0088 changeSecondStageSizeThicknessCmd -> AvailableForStates(G4State_PreInit);
0089
0090 enableWaterPhantomCmd = new G4UIcmdWithABool("/geometrySetup/enableWaterPhantom", this);
0091 enableWaterPhantomCmd -> SetGuidance("If true, the detector is placed inside a water phantom");
0092 enableWaterPhantomCmd -> SetParameterName("Phantom", false);
0093 enableWaterPhantomCmd -> AvailableForStates(G4State_PreInit);
0094
0095 changeDetectorPositionDir = new G4UIdirectory("/geometrySetup/detectorPosition/");
0096 changeDetectorPositionDir -> SetGuidance("Modify the placement of the detector");
0097
0098 changeDetectorPositionDepthCmd = new G4UIcmdWithADoubleAndUnit("/geometrySetup/detectorPosition/setDepth", this);
0099 changeDetectorPositionDepthCmd -> SetGuidance("Set the detector depth inside the water phantom");
0100 changeDetectorPositionDepthCmd -> SetParameterName("Depth", false);
0101 changeDetectorPositionDepthCmd -> SetRange("Depth >= 1. && Depth <= 250.");
0102 changeDetectorPositionDepthCmd -> SetUnitCategory("Length");
0103 changeDetectorPositionDepthCmd -> SetDefaultUnit("mm");
0104 changeDetectorPositionDepthCmd -> AvailableForStates(G4State_PreInit);
0105
0106 applyChangesToGeometryCmd = new G4UIcmdWithoutParameter("/geometrySetup/applyChanges",this);
0107 applyChangesToGeometryCmd -> SetGuidance("Apply selected changes to the geometry");
0108 applyChangesToGeometryCmd -> AvailableForStates(G4State_PreInit);
0109
0110
0111 detectorType = "Diamond";
0112 detectorWidth = 30.*um;
0113 detectorThickness = 10.*um;
0114 phantomEnabled = false;
0115 detectorDepth = 50*mm;
0116 secondStageWidth = 800.*um;
0117 secondStageThickness = 500.*um;
0118
0119 analysis = analysis_manager;
0120 }
0121
0122 DetectorMessenger::~DetectorMessenger()
0123 {
0124 delete changeTheDetectorCmd;
0125 delete changeDetectorSizeWidthCmd;
0126 delete changeDetectorSizeThicknessCmd;
0127 delete changeSecondStageSizeWidthCmd;
0128 delete changeSecondStageSizeThicknessCmd;
0129 delete enableWaterPhantomCmd;
0130 delete changeDetectorPositionDepthCmd;
0131
0132 delete applyChangesToGeometryCmd;
0133
0134 delete changeSecondStageDimensionDir;
0135 delete changeDetectorDimensionDir;
0136 delete changeDetectorPositionDir;
0137 delete changeTheGeometryDir;
0138 }
0139
0140 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String commandContent)
0141 {
0142
0143 if( command == changeTheDetectorCmd )
0144 {
0145 if( commandContent == "Diamond" || commandContent == "MicroDiamond" || commandContent == "Silicon" || commandContent == "SiliconBridge" || commandContent == "DiamondTelescope")
0146 {
0147 detectorType = commandContent;
0148 geometryHasChanged = true;
0149
0150 G4cout << "Detector type changed to " << commandContent << G4endl;
0151 G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
0152 }
0153
0154 else
0155 {
0156 G4cout <<"Unknown detector type: " << commandContent << ". Geometry not changed." << G4endl;
0157 }
0158 }
0159
0160 else if( command == changeDetectorSizeWidthCmd )
0161 {
0162 detectorWidth = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(commandContent);
0163 geometryHasChanged = true;
0164
0165 G4cout << "Detector width changed to " << commandContent << G4endl;
0166 G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
0167 }
0168
0169 else if( command == changeDetectorSizeThicknessCmd )
0170 {
0171 detectorThickness = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(commandContent);
0172 geometryHasChanged = true;
0173
0174 G4cout << "Detector thickness changed to " << commandContent << G4endl;
0175 G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
0176 }
0177
0178 else if( command == changeSecondStageSizeWidthCmd )
0179 {
0180 secondStageWidth = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(commandContent);
0181 geometryHasChanged = true;
0182
0183 G4cout << "Telescope E-stage width changed to " << commandContent << G4endl;
0184 if ( detectorType != "DiamondTelescope" )
0185 {
0186 G4cout << "However this setting only takes effect when using the telescope detector.";
0187 G4cout << "Select it with '/geometrySetup/selectDetector DiamondTelescope' or this command will be ignored" << G4endl;
0188 }
0189 else G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
0190 }
0191
0192 else if( command == changeSecondStageSizeThicknessCmd )
0193 {
0194 secondStageThickness = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(commandContent);
0195 geometryHasChanged = true;
0196
0197 G4cout << "Telescope E-stage thickness changed to " << commandContent << G4endl;
0198 if ( detectorType != "DiamondTelescope" )
0199 {
0200 G4cout << "However this setting only takes effect when using the telescope detector.";
0201 G4cout << "Select it with '/geometrySetup/selectDetector DiamondTelescope' or this command will be ignored" << G4endl;
0202 }
0203 else G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
0204 }
0205
0206 else if( command == enableWaterPhantomCmd )
0207 {
0208 phantomEnabled = G4UIcmdWithABool::GetNewBoolValue(commandContent);
0209 geometryHasChanged = true;
0210
0211 if( phantomEnabled == true ) G4cout << "Water phantom enabled" << G4endl;
0212 else G4cout << "Water phantom disabled" << G4endl;
0213 G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
0214 }
0215
0216 else if( command == changeDetectorPositionDepthCmd )
0217 {
0218 detectorDepth = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(commandContent);
0219 geometryHasChanged = true;
0220
0221 G4cout << "Detector depth in water changed to " << commandContent << G4endl;
0222 if( phantomEnabled == false )
0223 {
0224 G4cout << "However the water phantom is not enabled.";
0225 G4cout << "Enable it with '/geometrySetup/enableWaterPhantom true' or this command will be ignored" << G4endl;
0226 }
0227 else G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
0228 }
0229
0230 else if( command == applyChangesToGeometryCmd )
0231 {
0232 if( geometryHasChanged == true )
0233 {
0234 G4RunManager* runManager = G4RunManager::GetRunManager();
0235
0236 DetectorConstruction* newDetector = new DetectorConstruction(analysis, this);
0237
0238 runManager -> SetUserInitialization(newDetector);
0239 runManager -> GeometryHasBeenModified();
0240
0241 geometryHasChanged = false;
0242
0243 G4cout << "All pending changes to geometry have been applied" << G4endl;
0244 }
0245
0246 else
0247 {
0248 G4cout << "No pending changes to geometry. This command will be ignored" << G4endl;
0249 }
0250 }
0251 }