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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 10.0.p2)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 //  Gorad (Geant4 Open-source Radiation Analys    
 27 //                                                
 28 //  Author : Makoto Asai (SLAC National Accele    
 29 //                                                
 30 //  Development of Gorad is funded by NASA Joh    
 31 //  under the contract NNJ15HK11B.                
 32 //                                                
 33 // *******************************************    
 34 //                                                
 35 // GRPrimGenActionMessenger.hh                    
 36 //   Header file of a messenger that handles p    
 37 //   Input radiation spectrum file should be i    
 38 //   row should have low-end kinetic energy an    
 39 //   separated by a space.                        
 40 //                                                
 41 // History                                        
 42 //   September 8th, 2020 : first implementatio    
 43 //                                                
 44 // *******************************************    
 45                                                   
 46 #include "GRPrimGenActionMessenger.hh"            
 47                                                   
 48 #include "G4UIdirectory.hh"                       
 49 #include "G4UIcommand.hh"                         
 50 #include "G4UIparameter.hh"                       
 51                                                   
 52 GRPrimGenActionMessenger::GRPrimGenActionMesse    
 53 : verboseLevel(verboseLvl)                        
 54 {                                                 
 55   G4UIparameter* param = nullptr;                 
 56                                                   
 57   srcDir = new G4UIdirectory("/gorad/source/")    
 58   srcDir->SetGuidance("Define primary particle    
 59                                                   
 60   defCmd = new G4UIcommand("/gorad/source/defi    
 61   defCmd->SetGuidance("Define primary particle    
 62   defCmd->SetGuidance("[usage] /gorad/source/d    
 63   defCmd->SetGuidance("  pName : Particle name    
 64   defCmd->SetGuidance("  fName : File name of     
 65   defCmd->SetGuidance("  srcType : defines how    
 66   defCmd->SetGuidance("            Arb : Gener    
 67   defCmd->SetGuidance("            LW  : Gener    
 68   defCmd->SetGuidance("  radius : Radius of th    
 69   defCmd->SetGuidance("  unit : Unit of radius    
 70   defCmd->SetGuidance("  x0,y0,z0 : (Optional)    
 71   defCmd->SetGuidance("             By default    
 72   defCmd->SetGuidance("[note] This command is     
 73   particlePara = new G4UIparameter("pName",'s'    
 74   defCmd->SetParameter(particlePara);             
 75   param = new G4UIparameter("fName",'s',false)    
 76   defCmd->SetParameter(param);                    
 77   param = new G4UIparameter("srcType",'s',fals    
 78   param->SetParameterCandidates("Arb LW");        
 79   defCmd->SetParameter(param);                    
 80   param = new G4UIparameter("radius",'d',true)    
 81   param->SetParameterRange("radius == -1. || r    
 82   param->SetDefaultValue(-1.);                    
 83   defCmd->SetParameter(param);                    
 84   param = new G4UIparameter("unit",'s',true);     
 85   param->SetDefaultUnit("m");                     
 86   defCmd->SetParameter(param);                    
 87   param = new G4UIparameter("x0",'d',true);       
 88   param->SetDefaultValue(0.);                     
 89   defCmd->SetParameter(param);                    
 90   param = new G4UIparameter("y0",'d',true);       
 91   param->SetDefaultValue(0.);                     
 92   defCmd->SetParameter(param);                    
 93   param = new G4UIparameter("z0",'d',true);       
 94   param->SetDefaultValue(0.);                     
 95   defCmd->SetParameter(param);                    
 96   defCmd->AvailableForStates(G4State_Idle);       
 97   defCmd->SetToBeBroadcasted(false);              
 98 }                                                 
 99                                                   
100 GRPrimGenActionMessenger::~GRPrimGenActionMess    
101 {                                                 
102   delete defCmd;                                  
103   delete srcDir;                                  
104 }                                                 
105                                                   
106 #include "G4UImanager.hh"                         
107 #include "G4Threading.hh"                         
108 #include "G4Tokenizer.hh"                         
109 #include "G4UnitsTable.hh"                        
110 #include <fstream>                                
111 #include "GRDetectorConstruction.hh"              
112                                                   
113 void GRPrimGenActionMessenger::SetNewValue(G4U    
114 {                                                 
115   auto UI = G4UImanager::GetUIpointer();          
116   if(verboseLevel>0) G4cout << newVal << G4end    
117                                                   
118   G4Tokenizer next(newVal);                       
119   G4String pName = next();                        
120   G4String fName = next();                        
121   std::ifstream specFile;                         
122   specFile.open(fName,std::ios::in);              
123   if(specFile.fail())                             
124   {                                               
125     G4ExceptionDescription ed;                    
126     ed << "ERROR : File <" << fName << "> is n    
127     command->CommandFailed(ed);                   
128     return;                                       
129   }                                               
130                                                   
131   G4String srcType = next();                      
132   G4String radius = next();                       
133   G4String unit = next();                         
134   G4double r = StoD(radius);                      
135   if(r<0.)                                        
136   {                                               
137     r = GRDetectorConstruction::GetWorldSize()    
138     radius = DtoS(r);                             
139     unit = "mm";                                  
140     G4cout<<"################ Radius of the GP    
141   }                                               
142   G4String pos = next() + " " + next() + " " +    
143                                                   
144   G4String cmd;                                   
145   G4int ec = 0;                                   
146   ec = std::max(UI->ApplyCommand("/gps/pos/sha    
147   cmd = "/gps/pos/centre " + pos + " " + unit;    
148   ec = std::max(UI->ApplyCommand(cmd),ec);        
149   cmd = "/gps/pos/radius " + radius + " " + un    
150   ec = std::max(UI->ApplyCommand(cmd),ec);        
151   ec = std::max(UI->ApplyCommand("/gps/pos/typ    
152   ec = std::max(UI->ApplyCommand("/gps/number     
153   cmd = "/gps/particle " + pName;                 
154   ec = std::max(UI->ApplyCommand(cmd),ec);        
155   ec = std::max(UI->ApplyCommand("/gps/ang/typ    
156   ec = std::max(UI->ApplyCommand("/gps/ang/max    
157   ec = std::max(UI->ApplyCommand("/gps/ang/min    
158   cmd = "/gps/ene/type " + srcType;               
159   ec = std::max(UI->ApplyCommand(cmd),ec);        
160   ec = std::max(UI->ApplyCommand("/gps/hist/ty    
161                                                   
162   enum { bufsize = 128 };                         
163   static char* line = new char[bufsize];          
164   while(specFile.good())                          
165   {                                               
166     specFile.getline(line,bufsize);               
167     if(line[(size_t)0]=='#') continue;            
168     G4String valStr = line;                       
169     G4StrUtil::strip(valStr);                     
170     G4StrUtil::rstrip(valStr, 0x0d);              
171     if(valStr.size()==0) continue;                
172     cmd = "/gps/hist/point " + valStr;            
173     ec = std::max(UI->ApplyCommand(cmd),ec);      
174     if(specFile.eof()) break;                     
175   }                                               
176   ec = std::max(UI->ApplyCommand("/gps/hist/in    
177                                                   
178   if(ec>0)                                        
179   {                                               
180     G4ExceptionDescription ed;                    
181     ed << "ERROR : Internal error while proces    
182     command->CommandFailed(ec,ed);                
183   }                                               
184 }                                                 
185                                                   
186 G4String GRPrimGenActionMessenger::GetCurrentV    
187 {                                                 
188   G4String val;                                   
189   return val;                                     
190 }                                                 
191                                                   
192 #include "G4ParticleTable.hh"                     
193 void GRPrimGenActionMessenger::UpdateParticleL    
194 {                                                 
195   auto particleTable = G4ParticleTable::GetPar    
196   G4String candList;                              
197   for(G4int i=0;i<particleTable->entries();i++    
198   { candList += particleTable->GetParticleName    
199   candList += "ion";                              
200   particlePara->SetParameterCandidates(candLis    
201 }                                                 
202                                                   
203