File indexing completed on 2026-09-18 08:32:53
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 #include "Par04DetectorMessenger.hh"
0030
0031 #include "Par04DetectorConstruction.hh" // for Par04DetectorConstruction
0032
0033 #include "G4UIcmdWithADoubleAndUnit.hh" // for G4UIcmdWithADoubleAndUnit
0034 #include "G4UIcmdWithAnInteger.hh" // for G4UIcmdWithAnInteger
0035 #include "G4UIcmdWithoutParameter.hh" // for G4UIcmdWithoutParameter
0036 #include "G4UIdirectory.hh" // for G4UIdirectory
0037
0038 #include <CLHEP/Units/SystemOfUnits.h> // for pi
0039 #include <G4ApplicationState.hh> // for G4State_PreInit, G4State_Idle
0040 #include <G4ThreeVector.hh> // for G4ThreeVector
0041 #include <G4Types.hh> // for G4bool, G4double, G4int
0042 #include <G4UIcommand.hh> // for G4UIcommand
0043 #include <G4UImessenger.hh> // for G4UImessenger
0044 #include <G4UIparameter.hh> // for G4UIparameter
0045 #include <istream> // for basic_istream, basic_istream...
0046 #include <string> // for operator>>
0047
0048
0049
0050 Par04DetectorMessenger::Par04DetectorMessenger(Par04DetectorConstruction* aDetector)
0051 : G4UImessenger(), fDetector(aDetector)
0052 {
0053 fExampleDir = new G4UIdirectory("/Par04/");
0054 fExampleDir->SetGuidance("UI commands specific to this example");
0055
0056 fDetectorDir = new G4UIdirectory("/Par04/detector/");
0057 fDetectorDir->SetGuidance("Detector construction UI commands");
0058
0059 fPrintCmd = new G4UIcmdWithoutParameter("/Par04/detector/print", this);
0060 fPrintCmd->SetGuidance("Print current settings.");
0061
0062 fDetectorInnerRadiusCmd =
0063 new G4UIcmdWithADoubleAndUnit("/Par04/detector/setDetectorInnerRadius", this);
0064 fDetectorInnerRadiusCmd->SetGuidance("Set cylindrical detector inner radius");
0065 fDetectorInnerRadiusCmd->SetParameterName("Size", false);
0066 fDetectorInnerRadiusCmd->SetRange("Size>0.");
0067 fDetectorInnerRadiusCmd->SetUnitCategory("Length");
0068 fDetectorInnerRadiusCmd->AvailableForStates(G4State_PreInit);
0069 fDetectorInnerRadiusCmd->SetToBeBroadcasted(false);
0070
0071 fDetectorLengthCmd = new G4UIcmdWithADoubleAndUnit("/Par04/detector/setDetectorLength", this);
0072 fDetectorLengthCmd->SetGuidance("Set length of the detector (cylinder length)");
0073 fDetectorLengthCmd->SetParameterName("Size", false);
0074 fDetectorLengthCmd->SetRange("Size>0.");
0075 fDetectorLengthCmd->SetUnitCategory("Length");
0076 fDetectorLengthCmd->AvailableForStates(G4State_PreInit);
0077 fDetectorLengthCmd->SetToBeBroadcasted(false);
0078
0079 fNbLayersCmd = new G4UIcmdWithAnInteger("/Par04/detector/setNbOfLayers", this);
0080 fNbLayersCmd->SetGuidance("Set number of layers.");
0081 fNbLayersCmd->SetParameterName("NbLayers", false);
0082 fNbLayersCmd->SetRange("NbLayers>0");
0083 fNbLayersCmd->AvailableForStates(G4State_PreInit);
0084 fNbLayersCmd->SetToBeBroadcasted(false);
0085
0086 fAbsorCmd = new G4UIcommand("/Par04/detector/setAbsorber", this);
0087 fAbsorCmd->SetGuidance("Set the absorber id, the material, the thickness.");
0088 fAbsorCmd->SetGuidance(" absorber number : from 0 to 1");
0089 fAbsorCmd->SetGuidance(" material name");
0090 fAbsorCmd->SetGuidance(" thickness (with unit) : t>0");
0091 fAbsorCmd->SetGuidance(" if sensitive : true/false.");
0092 auto absNbPrm = new G4UIparameter("AbsorNb", 'i', false);
0093 absNbPrm->SetGuidance("absor number : from 0 to 1");
0094 absNbPrm->SetParameterRange("AbsorNb>-1&AbsoNb<2");
0095 fAbsorCmd->SetParameter(absNbPrm);
0096 auto matPrm = new G4UIparameter("material", 's', false);
0097 matPrm->SetGuidance("material name");
0098 fAbsorCmd->SetParameter(matPrm);
0099 auto thickPrm = new G4UIparameter("thickness", 'd', false);
0100 thickPrm->SetGuidance("thickness of absorber");
0101 thickPrm->SetParameterRange("thickness>0.");
0102 fAbsorCmd->SetParameter(thickPrm);
0103 auto unitPrm = new G4UIparameter("unit", 's', false);
0104 unitPrm->SetGuidance("unit of thickness");
0105 G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("mm"));
0106 unitPrm->SetParameterCandidates(unitList);
0107 fAbsorCmd->SetParameter(unitPrm);
0108 auto sensitivePrm = new G4UIparameter("sensitive", 'b', false);
0109 sensitivePrm->SetGuidance("if absorber is sensitive (registers energy deposits)");
0110 fAbsorCmd->SetParameter(sensitivePrm);
0111
0112 fAbsorCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0113 fAbsorCmd->SetToBeBroadcasted(false);
0114
0115 fMeshDir = new G4UIdirectory("/Par04/mesh/");
0116 fMeshDir->SetGuidance("Mesh UI commands");
0117
0118 fMeshNbRhoCellsCmd = new G4UIcmdWithAnInteger("/Par04/mesh/setNbOfRhoCells", this);
0119 fMeshNbRhoCellsCmd->SetGuidance("Set number of rho cells in the cylindrical mesh readout.");
0120 fMeshNbRhoCellsCmd->SetParameterName("NbRhoCells", false);
0121 fMeshNbRhoCellsCmd->SetRange("NbRhoCells>0");
0122 fMeshNbRhoCellsCmd->AvailableForStates(G4State_PreInit);
0123 fMeshNbRhoCellsCmd->SetToBeBroadcasted(false);
0124
0125 fMeshNbPhiCellsCmd = new G4UIcmdWithAnInteger("/Par04/mesh/setNbOfPhiCells", this);
0126 fMeshNbPhiCellsCmd->SetGuidance("Set number of phi cells in the cylindrical mesh readout.");
0127 fMeshNbPhiCellsCmd->SetParameterName("NbPhiCells", false);
0128 fMeshNbPhiCellsCmd->SetRange("NbPhiCells>0");
0129 fMeshNbPhiCellsCmd->AvailableForStates(G4State_PreInit);
0130 fMeshNbPhiCellsCmd->SetToBeBroadcasted(false);
0131
0132 fMeshNbZCellsCmd = new G4UIcmdWithAnInteger("/Par04/mesh/setNbOfZCells", this);
0133 fMeshNbZCellsCmd->SetGuidance("Set number of z cells in the cylindrical mesh readout.");
0134 fMeshNbZCellsCmd->SetParameterName("NbZCells", false);
0135 fMeshNbZCellsCmd->SetRange("NbZCells>0");
0136 fMeshNbZCellsCmd->AvailableForStates(G4State_PreInit);
0137 fMeshNbZCellsCmd->SetToBeBroadcasted(false);
0138
0139 fMeshSizeRhoCellsCmd = new G4UIcmdWithADoubleAndUnit("/Par04/mesh/setSizeOfRhoCells", this);
0140 fMeshSizeRhoCellsCmd->SetGuidance("Set size of rho cells in the cylindrical readout mesh");
0141 fMeshSizeRhoCellsCmd->SetParameterName("Size", false);
0142 fMeshSizeRhoCellsCmd->SetRange("Size>0.");
0143 fMeshSizeRhoCellsCmd->SetUnitCategory("Length");
0144 fMeshSizeRhoCellsCmd->AvailableForStates(G4State_PreInit);
0145 fMeshSizeRhoCellsCmd->SetToBeBroadcasted(false);
0146
0147 fMeshSizeZCellsCmd = new G4UIcmdWithADoubleAndUnit("/Par04/mesh/setSizeOfZCells", this);
0148 fMeshSizeZCellsCmd->SetGuidance("Set size of z cells in the cylindrical readout mesh");
0149 fMeshSizeZCellsCmd->SetParameterName("Size", false);
0150 fMeshSizeZCellsCmd->SetRange("Size>0.");
0151 fMeshSizeZCellsCmd->SetUnitCategory("Length");
0152 fMeshSizeZCellsCmd->AvailableForStates(G4State_PreInit);
0153 fMeshSizeZCellsCmd->SetToBeBroadcasted(false);
0154 }
0155
0156
0157
0158 Par04DetectorMessenger::~Par04DetectorMessenger()
0159 {
0160 delete fPrintCmd;
0161 delete fDetectorInnerRadiusCmd;
0162 delete fDetectorLengthCmd;
0163 delete fNbLayersCmd;
0164 delete fAbsorCmd;
0165 delete fDetectorDir;
0166 delete fMeshNbRhoCellsCmd;
0167 delete fMeshNbPhiCellsCmd;
0168 delete fMeshNbZCellsCmd;
0169 delete fMeshSizeRhoCellsCmd;
0170 delete fMeshSizeZCellsCmd;
0171 delete fMeshDir;
0172 delete fExampleDir;
0173 }
0174
0175
0176
0177 void Par04DetectorMessenger::SetNewValue(G4UIcommand* aCommand, G4String aNewValue)
0178 {
0179 if (aCommand == fPrintCmd) {
0180 fDetector->Print();
0181 }
0182 else if (aCommand == fDetectorInnerRadiusCmd) {
0183 fDetector->SetInnerRadius(fDetectorInnerRadiusCmd->GetNewDoubleValue(aNewValue));
0184 }
0185 else if (aCommand == fDetectorLengthCmd) {
0186 fDetector->SetLength(fDetectorInnerRadiusCmd->GetNewDoubleValue(aNewValue));
0187 }
0188 else if (aCommand == fNbLayersCmd) {
0189 fDetector->SetNbOfLayers(fNbLayersCmd->GetNewIntValue(aNewValue));
0190 }
0191 else if (aCommand == fAbsorCmd) {
0192 G4int num;
0193 G4double thick;
0194 G4String unt, mat;
0195 G4bool sensitive;
0196 std::istringstream is(aNewValue);
0197 is >> num >> mat >> thick >> unt >> std::boolalpha >> sensitive;
0198 G4String material = mat;
0199 thick *= G4UIcommand::ValueOf(unt);
0200 fDetector->SetAbsorberMaterial(num, material);
0201 fDetector->SetAbsorberThickness(num, thick);
0202 fDetector->SetAbsorberSensitivity(num, sensitive);
0203 }
0204 else if (aCommand == fMeshNbRhoCellsCmd) {
0205 fDetector->SetMeshNbOfCells(0, fMeshNbRhoCellsCmd->GetNewIntValue(aNewValue));
0206 }
0207 else if (aCommand == fMeshNbPhiCellsCmd) {
0208 fDetector->SetMeshNbOfCells(1, fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue));
0209 fDetector->SetMeshSizeOfCells(1,
0210 2. * CLHEP::pi / fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue));
0211 }
0212 else if (aCommand == fMeshNbZCellsCmd) {
0213 fDetector->SetMeshNbOfCells(2, fMeshNbZCellsCmd->GetNewIntValue(aNewValue));
0214 }
0215 else if (aCommand == fMeshSizeRhoCellsCmd) {
0216 fDetector->SetMeshSizeOfCells(0, fMeshSizeRhoCellsCmd->GetNewDoubleValue(aNewValue));
0217 }
0218 else if (aCommand == fMeshSizeZCellsCmd) {
0219 fDetector->SetMeshSizeOfCells(2, fMeshSizeZCellsCmd->GetNewDoubleValue(aNewValue));
0220 }
0221 }
0222
0223
0224
0225 G4String Par04DetectorMessenger::GetCurrentValue(G4UIcommand* aCommand)
0226 {
0227 G4String cv;
0228
0229 if (aCommand == fDetectorInnerRadiusCmd) {
0230 cv = fDetectorInnerRadiusCmd->ConvertToString(fDetector->GetInnerRadius(), "mm");
0231 }
0232 else if (aCommand == fDetectorLengthCmd) {
0233 cv = fDetectorLengthCmd->ConvertToString(fDetector->GetLength(), "mm");
0234 }
0235 else if (aCommand == fNbLayersCmd) {
0236 cv = fNbLayersCmd->ConvertToString(fDetector->GetNbOfLayers());
0237 }
0238 else if (aCommand == fMeshNbRhoCellsCmd) {
0239 cv = fMeshNbRhoCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[0]);
0240 }
0241 else if (aCommand == fMeshNbPhiCellsCmd) {
0242 cv = fMeshNbPhiCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[1]);
0243 }
0244 else if (aCommand == fMeshNbZCellsCmd) {
0245 cv = fMeshNbZCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[2]);
0246 }
0247 else if (aCommand == fMeshSizeRhoCellsCmd) {
0248 cv = fMeshSizeRhoCellsCmd->ConvertToString(fDetector->GetMeshSizeOfCells()[0]);
0249 }
0250 else if (aCommand == fMeshSizeZCellsCmd) {
0251 cv = fMeshSizeZCellsCmd->ConvertToString(fDetector->GetMeshSizeOfCells()[2]);
0252 }
0253 return cv;
0254 }