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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/GRPrimGenActionMessenger.cc (Version 11.3.0) and /examples/advanced/gorad/src/GRPrimGenActionMessenger.cc (Version 11.2)


  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 // GRPrimGenActionMessenger.hh                     35 // GRPrimGenActionMessenger.hh
 36 //   Header file of a messenger that handles p     36 //   Header file of a messenger that handles primary generator action.
 37 //   Input radiation spectrum file should be i     37 //   Input radiation spectrum file should be in ASCII format and each
 38 //   row should have low-end kinetic energy an     38 //   row should have low-end kinetic energy and differential flux
 39 //   separated by a space.                         39 //   separated by a space.
 40 //                                                 40 //
 41 // History                                         41 // History
 42 //   September 8th, 2020 : first implementatio     42 //   September 8th, 2020 : first implementation
 43 //                                                 43 //
 44 // *******************************************     44 // ********************************************************************
 45                                                    45 
 46 #include "GRPrimGenActionMessenger.hh"             46 #include "GRPrimGenActionMessenger.hh"
 47                                                    47 
 48 #include "G4UIdirectory.hh"                        48 #include "G4UIdirectory.hh"
 49 #include "G4UIcommand.hh"                          49 #include "G4UIcommand.hh"
 50 #include "G4UIparameter.hh"                        50 #include "G4UIparameter.hh"
 51                                                    51 
 52 GRPrimGenActionMessenger::GRPrimGenActionMesse     52 GRPrimGenActionMessenger::GRPrimGenActionMessenger(G4int verboseLvl)
 53 : verboseLevel(verboseLvl)                         53 : verboseLevel(verboseLvl)
 54 {                                                  54 {
 55   G4UIparameter* param = nullptr;                  55   G4UIparameter* param = nullptr;
 56                                                    56 
 57   srcDir = new G4UIdirectory("/gorad/source/")     57   srcDir = new G4UIdirectory("/gorad/source/");
 58   srcDir->SetGuidance("Define primary particle     58   srcDir->SetGuidance("Define primary particle spectrum.");
 59                                                    59 
 60   defCmd = new G4UIcommand("/gorad/source/defi     60   defCmd = new G4UIcommand("/gorad/source/define",this);
 61   defCmd->SetGuidance("Define primary particle     61   defCmd->SetGuidance("Define primary particle spectrum.");
 62   defCmd->SetGuidance("[usage] /gorad/source/d     62   defCmd->SetGuidance("[usage] /gorad/source/define pName fName srcType radius unit (x0 y0 z0)");
 63   defCmd->SetGuidance("  pName : Particle name     63   defCmd->SetGuidance("  pName : Particle name.");
 64   defCmd->SetGuidance("  fName : File name of      64   defCmd->SetGuidance("  fName : File name of the spectrum. Directory may be preceded to the file name.");
 65   defCmd->SetGuidance("  srcType : defines how     65   defCmd->SetGuidance("  srcType : defines how the primaries are generated.");
 66   defCmd->SetGuidance("            Arb : Gener     66   defCmd->SetGuidance("            Arb : Generate primaries along with the defined spectrum.");
 67   defCmd->SetGuidance("            LW  : Gener     67   defCmd->SetGuidance("            LW  : Generate primaries in flat ditribution with track weight representing the spectrum.");
 68   defCmd->SetGuidance("  radius : Radius of th     68   defCmd->SetGuidance("  radius : Radius of the source sphere. If it is set to -1 (default), radius is set to 98% of the world volume.");
 69   defCmd->SetGuidance("  unit : Unit of radius     69   defCmd->SetGuidance("  unit : Unit of radius value.");
 70   defCmd->SetGuidance("  x0,y0,z0 : (Optional)     70   defCmd->SetGuidance("  x0,y0,z0 : (Optional) location of the center of the sphere (same unit is applied as radius).");
 71   defCmd->SetGuidance("             By default     71   defCmd->SetGuidance("             By default the sphere is located at the center of the world volume.");
 72   defCmd->SetGuidance("[note] This command is      72   defCmd->SetGuidance("[note] This command is not mandatory but dwialternatively granular /gps/ commands can be used for defining primary particles.");
 73   particlePara = new G4UIparameter("pName",'s'     73   particlePara = new G4UIparameter("pName",'s',false);
 74   defCmd->SetParameter(particlePara);              74   defCmd->SetParameter(particlePara);
 75   param = new G4UIparameter("fName",'s',false)     75   param = new G4UIparameter("fName",'s',false);
 76   defCmd->SetParameter(param);                     76   defCmd->SetParameter(param);
 77   param = new G4UIparameter("srcType",'s',fals     77   param = new G4UIparameter("srcType",'s',false);
 78   param->SetParameterCandidates("Arb LW");         78   param->SetParameterCandidates("Arb LW");
 79   defCmd->SetParameter(param);                     79   defCmd->SetParameter(param);
 80   param = new G4UIparameter("radius",'d',true)     80   param = new G4UIparameter("radius",'d',true);
 81   param->SetParameterRange("radius == -1. || r     81   param->SetParameterRange("radius == -1. || radius>0.");
 82   param->SetDefaultValue(-1.);                     82   param->SetDefaultValue(-1.);
 83   defCmd->SetParameter(param);                     83   defCmd->SetParameter(param);
 84   param = new G4UIparameter("unit",'s',true);      84   param = new G4UIparameter("unit",'s',true);
 85   param->SetDefaultUnit("m");                      85   param->SetDefaultUnit("m");
 86   defCmd->SetParameter(param);                     86   defCmd->SetParameter(param);
 87   param = new G4UIparameter("x0",'d',true);        87   param = new G4UIparameter("x0",'d',true);
 88   param->SetDefaultValue(0.);                      88   param->SetDefaultValue(0.);
 89   defCmd->SetParameter(param);                     89   defCmd->SetParameter(param);
 90   param = new G4UIparameter("y0",'d',true);        90   param = new G4UIparameter("y0",'d',true);
 91   param->SetDefaultValue(0.);                      91   param->SetDefaultValue(0.);
 92   defCmd->SetParameter(param);                     92   defCmd->SetParameter(param);
 93   param = new G4UIparameter("z0",'d',true);        93   param = new G4UIparameter("z0",'d',true);
 94   param->SetDefaultValue(0.);                      94   param->SetDefaultValue(0.);
 95   defCmd->SetParameter(param);                     95   defCmd->SetParameter(param);
 96   defCmd->AvailableForStates(G4State_Idle);        96   defCmd->AvailableForStates(G4State_Idle);
 97   defCmd->SetToBeBroadcasted(false);               97   defCmd->SetToBeBroadcasted(false);
 98 }                                                  98 }
 99                                                    99 
100 GRPrimGenActionMessenger::~GRPrimGenActionMess    100 GRPrimGenActionMessenger::~GRPrimGenActionMessenger()
101 {                                                 101 {
102   delete defCmd;                                  102   delete defCmd;
103   delete srcDir;                                  103   delete srcDir;
104 }                                                 104 }
105                                                   105 
106 #include "G4UImanager.hh"                         106 #include "G4UImanager.hh"
107 #include "G4Threading.hh"                         107 #include "G4Threading.hh"
108 #include "G4Tokenizer.hh"                         108 #include "G4Tokenizer.hh"
109 #include "G4UnitsTable.hh"                        109 #include "G4UnitsTable.hh"
110 #include <fstream>                                110 #include <fstream>
111 #include "GRDetectorConstruction.hh"              111 #include "GRDetectorConstruction.hh"
112                                                   112 
113 void GRPrimGenActionMessenger::SetNewValue(G4U    113 void GRPrimGenActionMessenger::SetNewValue(G4UIcommand * command,G4String newVal)
114 {                                                 114 {
115   auto UI = G4UImanager::GetUIpointer();          115   auto UI = G4UImanager::GetUIpointer();
116   if(verboseLevel>0) G4cout << newVal << G4end    116   if(verboseLevel>0) G4cout << newVal << G4endl;
117                                                   117 
118   G4Tokenizer next(newVal);                       118   G4Tokenizer next(newVal);
119   G4String pName = next();                        119   G4String pName = next();
120   G4String fName = next();                        120   G4String fName = next();
121   std::ifstream specFile;                         121   std::ifstream specFile;
122   specFile.open(fName,std::ios::in);              122   specFile.open(fName,std::ios::in);
123   if(specFile.fail())                             123   if(specFile.fail())
124   {                                               124   {
125     G4ExceptionDescription ed;                    125     G4ExceptionDescription ed;
126     ed << "ERROR : File <" << fName << "> is n    126     ed << "ERROR : File <" << fName << "> is not found.";
127     command->CommandFailed(ed);                   127     command->CommandFailed(ed);
128     return;                                       128     return;
129   }                                               129   }
130                                                   130 
131   G4String srcType = next();                      131   G4String srcType = next();
132   G4String radius = next();                       132   G4String radius = next();
133   G4String unit = next();                         133   G4String unit = next();
134   G4double r = StoD(radius);                      134   G4double r = StoD(radius);
135   if(r<0.)                                        135   if(r<0.)
136   {                                               136   {
137     r = GRDetectorConstruction::GetWorldSize()    137     r = GRDetectorConstruction::GetWorldSize() * 0.98;
138     radius = DtoS(r);                             138     radius = DtoS(r);
139     unit = "mm";                                  139     unit = "mm";
140     G4cout<<"################ Radius of the GP    140     G4cout<<"################ Radius of the GPS sphere is set to "<<r<<" (mm)"<<G4endl;
141   }                                               141   }
142   G4String pos = next() + " " + next() + " " +    142   G4String pos = next() + " " + next() + " " + next();
143                                                   143 
144   G4String cmd;                                   144   G4String cmd;
145   G4int ec = 0;                                   145   G4int ec = 0;
146   ec = std::max(UI->ApplyCommand("/gps/pos/sha    146   ec = std::max(UI->ApplyCommand("/gps/pos/shape Sphere"),ec);
147   cmd = "/gps/pos/centre " + pos + " " + unit;    147   cmd = "/gps/pos/centre " + pos + " " + unit;
148   ec = std::max(UI->ApplyCommand(cmd),ec);        148   ec = std::max(UI->ApplyCommand(cmd),ec);
149   cmd = "/gps/pos/radius " + radius + " " + un    149   cmd = "/gps/pos/radius " + radius + " " + unit;
150   ec = std::max(UI->ApplyCommand(cmd),ec);        150   ec = std::max(UI->ApplyCommand(cmd),ec);
151   ec = std::max(UI->ApplyCommand("/gps/pos/typ    151   ec = std::max(UI->ApplyCommand("/gps/pos/type Surface"),ec);
152   ec = std::max(UI->ApplyCommand("/gps/number     152   ec = std::max(UI->ApplyCommand("/gps/number 1"),ec);
153   cmd = "/gps/particle " + pName;                 153   cmd = "/gps/particle " + pName;
154   ec = std::max(UI->ApplyCommand(cmd),ec);        154   ec = std::max(UI->ApplyCommand(cmd),ec);
155   ec = std::max(UI->ApplyCommand("/gps/ang/typ    155   ec = std::max(UI->ApplyCommand("/gps/ang/type cos"),ec);
156   ec = std::max(UI->ApplyCommand("/gps/ang/max    156   ec = std::max(UI->ApplyCommand("/gps/ang/maxtheta 90.0 deg"),ec);
157   ec = std::max(UI->ApplyCommand("/gps/ang/min    157   ec = std::max(UI->ApplyCommand("/gps/ang/mintheta 0.0 deg"),ec);
158   cmd = "/gps/ene/type " + srcType;               158   cmd = "/gps/ene/type " + srcType;
159   ec = std::max(UI->ApplyCommand(cmd),ec);        159   ec = std::max(UI->ApplyCommand(cmd),ec);
160   ec = std::max(UI->ApplyCommand("/gps/hist/ty    160   ec = std::max(UI->ApplyCommand("/gps/hist/type arb"),ec);
161                                                   161 
162   enum { bufsize = 128 };                         162   enum { bufsize = 128 };
163   static char* line = new char[bufsize];          163   static char* line = new char[bufsize];
164   while(specFile.good())                          164   while(specFile.good())
165   {                                               165   {
166     specFile.getline(line,bufsize);               166     specFile.getline(line,bufsize);
167     if(line[(size_t)0]=='#') continue;            167     if(line[(size_t)0]=='#') continue;
168     G4String valStr = line;                       168     G4String valStr = line;
169     G4StrUtil::strip(valStr);                     169     G4StrUtil::strip(valStr);
170     G4StrUtil::rstrip(valStr, 0x0d);              170     G4StrUtil::rstrip(valStr, 0x0d);
171     if(valStr.size()==0) continue;                171     if(valStr.size()==0) continue;
172     cmd = "/gps/hist/point " + valStr;            172     cmd = "/gps/hist/point " + valStr;
173     ec = std::max(UI->ApplyCommand(cmd),ec);      173     ec = std::max(UI->ApplyCommand(cmd),ec);
174     if(specFile.eof()) break;                     174     if(specFile.eof()) break;
175   }                                               175   }
176   ec = std::max(UI->ApplyCommand("/gps/hist/in    176   ec = std::max(UI->ApplyCommand("/gps/hist/inter Lin"),ec);
177                                                   177 
178   if(ec>0)                                        178   if(ec>0)
179   {                                               179   {
180     G4ExceptionDescription ed;                    180     G4ExceptionDescription ed;
181     ed << "ERROR : Internal error while proces    181     ed << "ERROR : Internal error while processing /gorad/source/define command.";
182     command->CommandFailed(ec,ed);                182     command->CommandFailed(ec,ed);
183   }                                               183   }
184 }                                                 184 }
185                                                   185 
186 G4String GRPrimGenActionMessenger::GetCurrentV    186 G4String GRPrimGenActionMessenger::GetCurrentValue(G4UIcommand* /*command*/)
187 {                                                 187 {
188   G4String val;                                   188   G4String val;
189   return val;                                     189   return val;
190 }                                                 190 }
191                                                   191 
192 #include "G4ParticleTable.hh"                     192 #include "G4ParticleTable.hh"
193 void GRPrimGenActionMessenger::UpdateParticleL    193 void GRPrimGenActionMessenger::UpdateParticleList()
194 {                                                 194 {
195   auto particleTable = G4ParticleTable::GetPar    195   auto particleTable = G4ParticleTable::GetParticleTable();
196   G4String candList;                              196   G4String candList;
197   for(G4int i=0;i<particleTable->entries();i++    197   for(G4int i=0;i<particleTable->entries();i++)
198   { candList += particleTable->GetParticleName    198   { candList += particleTable->GetParticleName(i) + " "; }
199   candList += "ion";                              199   candList += "ion";
200   particlePara->SetParameterCandidates(candLis    200   particlePara->SetParameterCandidates(candList);
201 }                                                 201 }
202                                                   202 
203                                                   203