File indexing completed on 2025-02-25 09:22:34
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
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #include "GRGeomBiasMessenger.hh"
0045
0046 #include "GRDetectorConstruction.hh"
0047 #include "GRPhysicsList.hh"
0048 #include "G4UIdirectory.hh"
0049 #include "G4UIcommand.hh"
0050 #include "G4UIcmdWith3VectorAndUnit.hh"
0051 #include "G4UIcmdWithADoubleAndUnit.hh"
0052 #include "G4UIcmdWithAnInteger.hh"
0053 #include "G4UIcmdWithADouble.hh"
0054 #include "G4UIparameter.hh"
0055 #include "G4Tokenizer.hh"
0056 #include "G4UnitsTable.hh"
0057
0058 GRGeomBiasMessenger::GRGeomBiasMessenger(
0059 GRDetectorConstruction* det,GRPhysicsList* phys,G4int verboseLvl)
0060 : detector(det),physics(phys),verboseLevel(verboseLvl)
0061 {
0062 G4UIparameter* param = nullptr;
0063
0064 biasDir = new G4UIdirectory("/gorad/bias/");
0065 biasDir->SetGuidance("Gorad biasing commands");
0066
0067 geoBiasCmd = new G4UIcommand("/gorad/bias/geomImportance",this);
0068 geoBiasCmd->SetGuidance("Geometry importance biasing");
0069 geoBiasCmd->SetGuidance("This command defines the number of layers and radius of the outermost sphere for geometry importance biasing.");
0070 geoBiasCmd->SetGuidance("If radius is set to -1 (default), actual radius is set to 80% of the world volume");
0071 geoBiasCmd->SetGuidance("Note: There must be at least two layers.");
0072 param = new G4UIparameter("nLayer",'i',false);
0073 param->SetParameterRange("nLayer > 1");
0074 geoBiasCmd->SetParameter(param);
0075 param = new G4UIparameter("radius",'d',true);
0076 param->SetParameterRange("radius == -1.0 || radius > 0.");
0077 param->SetDefaultValue(-1.0);
0078 geoBiasCmd->SetParameter(param);
0079 param = new G4UIparameter("unit",'s',true);
0080 param->SetDefaultUnit("mm");
0081 geoBiasCmd->SetParameter(param);
0082 geoBiasCmd->SetToBeBroadcasted(false);
0083 geoBiasCmd->AvailableForStates(G4State_PreInit);
0084
0085 geoBiasLocCmd = new G4UIcmdWith3VectorAndUnit("/gorad/bias/geomImpLocate",this);
0086 geoBiasLocCmd->SetGuidance("Position of the center of the outermost sphere.");
0087 geoBiasLocCmd->SetGuidance("By default, the sphere is located at the origin of the world volume.");
0088 geoBiasLocCmd->SetGuidance("This command has to follow /gorad/bias/geomImportance command.");
0089 geoBiasLocCmd->SetParameterName("x0","y0","z0",false);
0090 geoBiasLocCmd->SetDefaultUnit("mm");
0091 geoBiasLocCmd->SetToBeBroadcasted(false);
0092 geoBiasLocCmd->AvailableForStates(G4State_PreInit);
0093
0094 geoBiasInRadCmd = new G4UIcmdWithADoubleAndUnit("/gorad/bias/geomImpInnerRadius",this);
0095 geoBiasInRadCmd->SetGuidance("Radius of the innermost sphere.");
0096 geoBiasInRadCmd->SetGuidance("By default it is defined as 1/n of radius of the outermost sphere.");
0097 geoBiasInRadCmd->SetParameterName("rT",false);
0098 geoBiasInRadCmd->SetDefaultUnit("mm");
0099 geoBiasInRadCmd->SetRange("rT > 0.");
0100 geoBiasInRadCmd->SetToBeBroadcasted(false);
0101 geoBiasInRadCmd->AvailableForStates(G4State_PreInit);
0102
0103 geoBiasLocTgtCmd = new G4UIcmdWith3VectorAndUnit("/gorad/bias/geomImpLocTgt",this);
0104 geoBiasLocTgtCmd->SetGuidance("Position of the center of the innermost sphere.");
0105 geoBiasLocTgtCmd->SetGuidance("By default, it is located at the center of the outermost sphere.");
0106 geoBiasLocTgtCmd->SetGuidance("This command has to follow /gorad/bias/geomImportance command.");
0107 geoBiasLocTgtCmd->SetGuidance("Note: distance between (x0,y,0,z0) and (xT,yT,zT) must be smaller than r0*(nLayer-1)/nLayer.");
0108 geoBiasLocTgtCmd->SetGuidance(" (smaller than r0-rT if radius of innermost sphere is set)");
0109 geoBiasLocTgtCmd->SetParameterName("xT","yT","zT",false);
0110 geoBiasLocTgtCmd->SetDefaultUnit("mm");
0111 geoBiasLocTgtCmd->SetToBeBroadcasted(false);
0112 geoBiasLocTgtCmd->AvailableForStates(G4State_PreInit);
0113
0114 geoBiasFucCmd = new G4UIcmdWithAnInteger("/gorad/bias/geomImpFactor",this);
0115 geoBiasFucCmd->SetGuidance("Alternate the geometry importance biasing factor.");
0116 geoBiasFucCmd->SetGuidance("By default the factor is set to 2. We do not recommend the factor to be much larger than 2.");
0117 geoBiasFucCmd->SetGuidance("This command has to follow /gorad/bias/geomImportance command.");
0118 geoBiasFucCmd->SetParameterName("factor",false);
0119 geoBiasFucCmd->SetDefaultValue(2);
0120 geoBiasFucCmd->SetRange("factor > 0");
0121 geoBiasFucCmd->SetToBeBroadcasted(false);
0122 geoBiasFucCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
0123
0124 geoBiasProbCmd = new G4UIcmdWithADouble("/gorad/bias/geomImpProbability",this);
0125 geoBiasProbCmd->SetGuidance("Reduce the probability of geometry importance biasing to avoid over biasing.");
0126 geoBiasProbCmd->SetGuidance("By default the probability is set to 1.0 (i.e. 100%).");
0127 geoBiasProbCmd->SetGuidance("This command has to follow /gorad/bias/geomImportance command.");
0128 geoBiasProbCmd->SetParameterName("prob",true);
0129 geoBiasProbCmd->SetDefaultValue(1.);
0130 geoBiasProbCmd->SetRange("prob > 0. && prob <= 1.0");
0131 geoBiasProbCmd->SetToBeBroadcasted(false);
0132 geoBiasProbCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
0133
0134 if(verboseLevel>0)
0135 { G4cout << "UI commands /gorad/bias/ instantiated." << G4endl; }
0136 }
0137
0138 GRGeomBiasMessenger::~GRGeomBiasMessenger()
0139 {
0140 delete geoBiasProbCmd;
0141 delete geoBiasFucCmd;
0142 delete geoBiasLocTgtCmd;
0143 delete geoBiasInRadCmd;
0144 delete geoBiasLocCmd;
0145 delete geoBiasCmd;
0146 delete biasDir;
0147 }
0148
0149 void GRGeomBiasMessenger::SetNewValue(G4UIcommand * command,G4String newVal)
0150 {
0151 if(command==geoBiasCmd)
0152 {
0153 G4Tokenizer next(newVal);
0154 G4int nL = StoI(next());
0155 G4String r = next() + " ";
0156 r += next();
0157 detector->GeomImp(nL,geoBiasCmd->ConvertToDimensionedDouble(r));
0158 physics->ApplyGeomImpBias();
0159 }
0160 else
0161 {
0162 G4bool applyGeomImpBias = detector->ApplyGeomImpBias();
0163 if(!applyGeomImpBias)
0164 {
0165 G4ExceptionDescription ed;
0166 ed << "This command has to follow /gorad/bias/geomImportance command. Command failed.";
0167 command->CommandFailed(ed);
0168 }
0169 else if(command==geoBiasLocCmd)
0170 {
0171 detector->GeomImpLocate(geoBiasLocCmd->GetNew3VectorValue(newVal));
0172 }
0173 else if(command==geoBiasInRadCmd)
0174 {
0175 G4double rt = detector->GeomImpInnerRadius(geoBiasInRadCmd->GetNewDoubleValue(newVal));
0176 if(rt<0.)
0177 {
0178 G4ExceptionDescription ed;
0179 ed << "Specified radius is too large. It has to be smaller than the outermost sphere "
0180 << -rt << " (mm)\n" << "command failed.";
0181 command->CommandFailed(ed);
0182 }
0183 }
0184 else if(command==geoBiasLocTgtCmd)
0185 {
0186 G4double dr = detector->GeomImpLocateTgt(geoBiasLocTgtCmd->GetNew3VectorValue(newVal));
0187 if(dr>0.)
0188 {
0189 G4ExceptionDescription ed;
0190 ed << "Distance between (x0,y,0,z0) and (xT,yT,zT) must be smaller than radius*(nLayer-1)/nLayer, "
0191 << dr << " (mm)\n" << "command failed.";
0192 command->CommandFailed(ed);
0193 }
0194 }
0195 else if(command==geoBiasFucCmd)
0196 {
0197 detector->GeomImpFactor(StoI(newVal));
0198 }
0199 else if(command==geoBiasProbCmd)
0200 {
0201 detector->GeomImpProb(StoD(newVal));
0202 }
0203 }
0204 }
0205
0206 G4String GRGeomBiasMessenger::GetCurrentValue(G4UIcommand* )
0207 {
0208 G4String val;
0209 return val;
0210 }