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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/gorad/src/GRGeomBiasMessenger.cc (Version 11.3.0) and /examples/advanced/gorad/src/GRGeomBiasMessenger.cc (Version 11.1.3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //  Gorad (Geant4 Open-source Radiation Analys     26 //  Gorad (Geant4 Open-source Radiation Analysis and Design)
 27 //                                                 27 //
 28 //  Author : Makoto Asai (SLAC National Accele     28 //  Author : Makoto Asai (SLAC National Accelerator Laboratory)
 29 //                                                 29 //
 30 //  Development of Gorad is funded by NASA Joh     30 //  Development of Gorad is funded by NASA Johnson Space Center (JSC)
 31 //  under the contract NNJ15HK11B.                 31 //  under the contract NNJ15HK11B.
 32 //                                                 32 //
 33 // *******************************************     33 // ********************************************************************
 34 //                                                 34 //
 35 // GRGeomBiasMessenger.cc                          35 // GRGeomBiasMessenger.cc
 36 //   A messenger class that handles the UI com     36 //   A messenger class that handles the UI commands for geometry
 37 //   imprtance biasing.                            37 //   imprtance biasing.
 38 //                                                 38 //
 39 // History                                         39 // History
 40 //   September 8th, 2020 : first implementatio     40 //   September 8th, 2020 : first implementation
 41 //                                                 41 //
 42 // *******************************************     42 // ********************************************************************
 43                                                    43 
 44 #include "GRGeomBiasMessenger.hh"                  44 #include "GRGeomBiasMessenger.hh"
 45                                                    45 
 46 #include "GRDetectorConstruction.hh"               46 #include "GRDetectorConstruction.hh"
 47 #include "GRPhysicsList.hh"                        47 #include "GRPhysicsList.hh"
 48 #include "G4UIdirectory.hh"                        48 #include "G4UIdirectory.hh"
 49 #include "G4UIcommand.hh"                          49 #include "G4UIcommand.hh"
 50 #include "G4UIcmdWith3VectorAndUnit.hh"            50 #include "G4UIcmdWith3VectorAndUnit.hh"
 51 #include "G4UIcmdWithADoubleAndUnit.hh"            51 #include "G4UIcmdWithADoubleAndUnit.hh"
 52 #include "G4UIcmdWithAnInteger.hh"                 52 #include "G4UIcmdWithAnInteger.hh"
 53 #include "G4UIcmdWithADouble.hh"                   53 #include "G4UIcmdWithADouble.hh"
 54 #include "G4UIparameter.hh"                        54 #include "G4UIparameter.hh"
 55 #include "G4Tokenizer.hh"                          55 #include "G4Tokenizer.hh"
 56 #include "G4UnitsTable.hh"                         56 #include "G4UnitsTable.hh"
 57                                                    57 
 58 GRGeomBiasMessenger::GRGeomBiasMessenger(          58 GRGeomBiasMessenger::GRGeomBiasMessenger(
 59   GRDetectorConstruction* det,GRPhysicsList* p     59   GRDetectorConstruction* det,GRPhysicsList* phys,G4int verboseLvl)
 60 : detector(det),physics(phys),verboseLevel(ver     60 : detector(det),physics(phys),verboseLevel(verboseLvl)
 61 {                                                  61 {
 62   G4UIparameter* param = nullptr;                  62   G4UIparameter* param = nullptr;
 63                                                    63 
 64   biasDir = new G4UIdirectory("/gorad/bias/");     64   biasDir = new G4UIdirectory("/gorad/bias/");
 65   biasDir->SetGuidance("Gorad biasing commands     65   biasDir->SetGuidance("Gorad biasing commands");
 66                                                    66 
 67   geoBiasCmd = new G4UIcommand("/gorad/bias/ge     67   geoBiasCmd = new G4UIcommand("/gorad/bias/geomImportance",this);
 68   geoBiasCmd->SetGuidance("Geometry importance     68   geoBiasCmd->SetGuidance("Geometry importance biasing");
 69   geoBiasCmd->SetGuidance("This command define     69   geoBiasCmd->SetGuidance("This command defines the number of layers and radius of the outermost sphere for geometry importance biasing.");
 70   geoBiasCmd->SetGuidance("If radius is set to     70   geoBiasCmd->SetGuidance("If radius is set to -1 (default), actual radius is set to 80% of the world volume");
 71   geoBiasCmd->SetGuidance("Note: There must be     71   geoBiasCmd->SetGuidance("Note: There must be at least two layers.");
 72   param = new G4UIparameter("nLayer",'i',false     72   param = new G4UIparameter("nLayer",'i',false);
 73   param->SetParameterRange("nLayer > 1");          73   param->SetParameterRange("nLayer > 1");
 74   geoBiasCmd->SetParameter(param);                 74   geoBiasCmd->SetParameter(param);
 75   param = new G4UIparameter("radius",'d',true)     75   param = new G4UIparameter("radius",'d',true);
 76   param->SetParameterRange("radius == -1.0 ||      76   param->SetParameterRange("radius == -1.0 || radius > 0.");
 77   param->SetDefaultValue(-1.0);                    77   param->SetDefaultValue(-1.0);
 78   geoBiasCmd->SetParameter(param);                 78   geoBiasCmd->SetParameter(param);
 79   param = new G4UIparameter("unit",'s',true);      79   param = new G4UIparameter("unit",'s',true);
 80   param->SetDefaultUnit("mm");                     80   param->SetDefaultUnit("mm");
 81   geoBiasCmd->SetParameter(param);                 81   geoBiasCmd->SetParameter(param);
 82   geoBiasCmd->SetToBeBroadcasted(false);           82   geoBiasCmd->SetToBeBroadcasted(false);
 83   geoBiasCmd->AvailableForStates(G4State_PreIn     83   geoBiasCmd->AvailableForStates(G4State_PreInit);
 84                                                    84 
 85   geoBiasLocCmd = new G4UIcmdWith3VectorAndUni     85   geoBiasLocCmd = new G4UIcmdWith3VectorAndUnit("/gorad/bias/geomImpLocate",this);
 86   geoBiasLocCmd->SetGuidance("Position of the      86   geoBiasLocCmd->SetGuidance("Position of the center of the outermost sphere.");
 87   geoBiasLocCmd->SetGuidance("By default, the      87   geoBiasLocCmd->SetGuidance("By default, the sphere is located at the origin of the world volume.");
 88   geoBiasLocCmd->SetGuidance("This command has     88   geoBiasLocCmd->SetGuidance("This command has to follow /gorad/bias/geomImportance command.");
 89   geoBiasLocCmd->SetParameterName("x0","y0","z     89   geoBiasLocCmd->SetParameterName("x0","y0","z0",false);
 90   geoBiasLocCmd->SetDefaultUnit("mm");             90   geoBiasLocCmd->SetDefaultUnit("mm");
 91   geoBiasLocCmd->SetToBeBroadcasted(false);        91   geoBiasLocCmd->SetToBeBroadcasted(false);
 92   geoBiasLocCmd->AvailableForStates(G4State_Pr     92   geoBiasLocCmd->AvailableForStates(G4State_PreInit);
 93                                                    93   
 94   geoBiasInRadCmd = new G4UIcmdWithADoubleAndU     94   geoBiasInRadCmd = new G4UIcmdWithADoubleAndUnit("/gorad/bias/geomImpInnerRadius",this);
 95   geoBiasInRadCmd->SetGuidance("Radius of the      95   geoBiasInRadCmd->SetGuidance("Radius of the innermost sphere.");
 96   geoBiasInRadCmd->SetGuidance("By default it      96   geoBiasInRadCmd->SetGuidance("By default it is defined as 1/n of radius of the outermost sphere.");
 97   geoBiasInRadCmd->SetParameterName("rT",false     97   geoBiasInRadCmd->SetParameterName("rT",false);
 98   geoBiasInRadCmd->SetDefaultUnit("mm");           98   geoBiasInRadCmd->SetDefaultUnit("mm");
 99   geoBiasInRadCmd->SetRange("rT > 0.");            99   geoBiasInRadCmd->SetRange("rT > 0.");
100   geoBiasInRadCmd->SetToBeBroadcasted(false);     100   geoBiasInRadCmd->SetToBeBroadcasted(false);
101   geoBiasInRadCmd->AvailableForStates(G4State_    101   geoBiasInRadCmd->AvailableForStates(G4State_PreInit);
102                                                   102   
103   geoBiasLocTgtCmd = new G4UIcmdWith3VectorAnd    103   geoBiasLocTgtCmd = new G4UIcmdWith3VectorAndUnit("/gorad/bias/geomImpLocTgt",this);
104   geoBiasLocTgtCmd->SetGuidance("Position of t    104   geoBiasLocTgtCmd->SetGuidance("Position of the center of the innermost sphere.");
105   geoBiasLocTgtCmd->SetGuidance("By default, i    105   geoBiasLocTgtCmd->SetGuidance("By default, it is located at the center of the outermost sphere.");
106   geoBiasLocTgtCmd->SetGuidance("This command     106   geoBiasLocTgtCmd->SetGuidance("This command has to follow /gorad/bias/geomImportance command.");
107   geoBiasLocTgtCmd->SetGuidance("Note: distanc    107   geoBiasLocTgtCmd->SetGuidance("Note: distance between (x0,y,0,z0) and (xT,yT,zT) must be smaller than r0*(nLayer-1)/nLayer.");
108   geoBiasLocTgtCmd->SetGuidance("          (sm    108   geoBiasLocTgtCmd->SetGuidance("          (smaller than r0-rT if radius of innermost sphere is set)");
109   geoBiasLocTgtCmd->SetParameterName("xT","yT"    109   geoBiasLocTgtCmd->SetParameterName("xT","yT","zT",false);
110   geoBiasLocTgtCmd->SetDefaultUnit("mm");         110   geoBiasLocTgtCmd->SetDefaultUnit("mm");
111   geoBiasLocTgtCmd->SetToBeBroadcasted(false);    111   geoBiasLocTgtCmd->SetToBeBroadcasted(false);
112   geoBiasLocTgtCmd->AvailableForStates(G4State    112   geoBiasLocTgtCmd->AvailableForStates(G4State_PreInit);
113                                                   113 
114   geoBiasFucCmd = new G4UIcmdWithAnInteger("/g    114   geoBiasFucCmd = new G4UIcmdWithAnInteger("/gorad/bias/geomImpFactor",this);
115   geoBiasFucCmd->SetGuidance("Alternate the ge    115   geoBiasFucCmd->SetGuidance("Alternate the geometry importance biasing factor.");
116   geoBiasFucCmd->SetGuidance("By default the f    116   geoBiasFucCmd->SetGuidance("By default the factor is set to 2. We do not recommend the factor to be much larger than 2.");
117   geoBiasFucCmd->SetGuidance("This command has    117   geoBiasFucCmd->SetGuidance("This command has to follow /gorad/bias/geomImportance command.");
118   geoBiasFucCmd->SetParameterName("factor",fal    118   geoBiasFucCmd->SetParameterName("factor",false);
119   geoBiasFucCmd->SetDefaultValue(2);              119   geoBiasFucCmd->SetDefaultValue(2);
120   geoBiasFucCmd->SetRange("factor > 0");          120   geoBiasFucCmd->SetRange("factor > 0");
121   geoBiasFucCmd->SetToBeBroadcasted(false);       121   geoBiasFucCmd->SetToBeBroadcasted(false);
122   geoBiasFucCmd->AvailableForStates(G4State_Pr    122   geoBiasFucCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
123                                                   123 
124   geoBiasProbCmd = new G4UIcmdWithADouble("/go    124   geoBiasProbCmd = new G4UIcmdWithADouble("/gorad/bias/geomImpProbability",this);
125   geoBiasProbCmd->SetGuidance("Reduce the prob    125   geoBiasProbCmd->SetGuidance("Reduce the probability of geometry importance biasing to avoid over biasing.");
126   geoBiasProbCmd->SetGuidance("By default the     126   geoBiasProbCmd->SetGuidance("By default the probability is set to 1.0 (i.e. 100%).");
127   geoBiasProbCmd->SetGuidance("This command ha    127   geoBiasProbCmd->SetGuidance("This command has to follow /gorad/bias/geomImportance command.");
128   geoBiasProbCmd->SetParameterName("prob",true    128   geoBiasProbCmd->SetParameterName("prob",true);
129   geoBiasProbCmd->SetDefaultValue(1.);            129   geoBiasProbCmd->SetDefaultValue(1.);
130   geoBiasProbCmd->SetRange("prob > 0. && prob     130   geoBiasProbCmd->SetRange("prob > 0. && prob <= 1.0");
131   geoBiasProbCmd->SetToBeBroadcasted(false);      131   geoBiasProbCmd->SetToBeBroadcasted(false);
132   geoBiasProbCmd->AvailableForStates(G4State_P    132   geoBiasProbCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
133                                                   133 
134   if(verboseLevel>0)                              134   if(verboseLevel>0) 
135   { G4cout << "UI commands /gorad/bias/ instan    135   { G4cout << "UI commands /gorad/bias/ instantiated." << G4endl; }
136 }                                                 136 }
137                                                   137 
138 GRGeomBiasMessenger::~GRGeomBiasMessenger()       138 GRGeomBiasMessenger::~GRGeomBiasMessenger()
139 {                                                 139 {
140   delete geoBiasProbCmd;                          140   delete geoBiasProbCmd;
141   delete geoBiasFucCmd;                           141   delete geoBiasFucCmd;
142   delete geoBiasLocTgtCmd;                        142   delete geoBiasLocTgtCmd;
143   delete geoBiasInRadCmd;                         143   delete geoBiasInRadCmd;
144   delete geoBiasLocCmd;                           144   delete geoBiasLocCmd;
145   delete geoBiasCmd;                              145   delete geoBiasCmd;
146   delete biasDir;                                 146   delete biasDir;
147 }                                                 147 }
148                                                   148 
149 void GRGeomBiasMessenger::SetNewValue(G4UIcomm    149 void GRGeomBiasMessenger::SetNewValue(G4UIcommand * command,G4String newVal)
150 {                                                 150 {
151   if(command==geoBiasCmd)                         151   if(command==geoBiasCmd)
152   {                                               152   {
153     G4Tokenizer next(newVal);                     153     G4Tokenizer next(newVal);
154     G4int nL = StoI(next());                      154     G4int nL = StoI(next());
155     G4String r = next() + " ";                    155     G4String r = next() + " ";
156     r += next();                                  156     r += next();
157     detector->GeomImp(nL,geoBiasCmd->ConvertTo    157     detector->GeomImp(nL,geoBiasCmd->ConvertToDimensionedDouble(r));
158     physics->ApplyGeomImpBias();                  158     physics->ApplyGeomImpBias();
159   }                                               159   }
160   else                                            160   else
161   { // following commands have to come after /    161   { // following commands have to come after /gorad/bias/geomImportance command.
162     G4bool applyGeomImpBias = detector->ApplyG    162     G4bool applyGeomImpBias = detector->ApplyGeomImpBias();
163     if(!applyGeomImpBias)                         163     if(!applyGeomImpBias)
164     {                                             164     {
165       G4ExceptionDescription ed;                  165       G4ExceptionDescription ed;
166       ed << "This command has to follow /gorad    166       ed << "This command has to follow /gorad/bias/geomImportance command. Command failed.";
167       command->CommandFailed(ed);                 167       command->CommandFailed(ed);
168     }                                             168     }
169     else if(command==geoBiasLocCmd)               169     else if(command==geoBiasLocCmd)
170     {                                             170     {
171       detector->GeomImpLocate(geoBiasLocCmd->G    171       detector->GeomImpLocate(geoBiasLocCmd->GetNew3VectorValue(newVal));
172     }                                             172     }
173     else if(command==geoBiasInRadCmd)             173     else if(command==geoBiasInRadCmd)
174     {                                             174     {
175       G4double rt = detector->GeomImpInnerRadi    175       G4double rt = detector->GeomImpInnerRadius(geoBiasInRadCmd->GetNewDoubleValue(newVal));
176       if(rt<0.)                                   176       if(rt<0.)
177       {                                           177       {
178         G4ExceptionDescription ed;                178         G4ExceptionDescription ed;
179         ed << "Specified radius is too large.     179         ed << "Specified radius is too large. It has to be smaller than the outermost sphere "
180            << -rt << " (mm)\n" << "command fai    180            << -rt << " (mm)\n" << "command failed.";
181         command->CommandFailed(ed);               181         command->CommandFailed(ed);
182       }                                           182       }
183     }                                             183     }
184     else if(command==geoBiasLocTgtCmd)            184     else if(command==geoBiasLocTgtCmd)
185     {                                             185     {
186       G4double dr = detector->GeomImpLocateTgt    186       G4double dr = detector->GeomImpLocateTgt(geoBiasLocTgtCmd->GetNew3VectorValue(newVal));
187       if(dr>0.)                                   187       if(dr>0.)
188       {                                           188       {
189         G4ExceptionDescription ed;                189         G4ExceptionDescription ed;
190         ed << "Distance between (x0,y,0,z0) an    190         ed << "Distance between (x0,y,0,z0) and (xT,yT,zT) must be smaller than radius*(nLayer-1)/nLayer, "
191            << dr << " (mm)\n" << "command fail    191            << dr << " (mm)\n" << "command failed."; 
192         command->CommandFailed(ed);               192         command->CommandFailed(ed);
193       }                                           193       }
194     }                                             194     }
195     else if(command==geoBiasFucCmd)               195     else if(command==geoBiasFucCmd)
196     {                                             196     {
197       detector->GeomImpFactor(StoI(newVal));      197       detector->GeomImpFactor(StoI(newVal));
198     }                                             198     }
199     else if(command==geoBiasProbCmd)              199     else if(command==geoBiasProbCmd)
200     {                                             200     {
201       detector->GeomImpProb(StoD(newVal));        201       detector->GeomImpProb(StoD(newVal));
202     }                                             202     }
203   }                                               203   }
204 }                                                 204 }
205                                                   205 
206 G4String GRGeomBiasMessenger::GetCurrentValue(    206 G4String GRGeomBiasMessenger::GetCurrentValue(G4UIcommand* /*command*/)
207 {                                                 207 {
208   G4String val;                                   208   G4String val;
209   return val;                                     209   return val;
210 }                                                 210 }
211                                                   211