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p3 ] [ 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/hadrontherapy/src/HadrontherapyInteractionParameters.cc (Version 11.3.0) and /examples/advanced/hadrontherapy/src/HadrontherapyInteractionParameters.cc (Version 8.2)


  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 // Hadrontherapy advanced example for Geant4      
 27 // See more at: https://twiki.cern.ch/twiki/bi    
 28                                                   
 29 #include <fstream>                                
 30 #include <iostream>                               
 31 #include <sstream>                                
 32 #include <cmath>                                  
 33 #include <vector>                                 
 34                                                   
 35 #include "HadrontherapyInteractionParameters.h    
 36 #include "HadrontherapyParameterMessenger.hh"     
 37 #include "HadrontherapyDetectorConstruction.hh    
 38                                                   
 39 #include "globals.hh"                             
 40 #include "G4SystemOfUnits.hh"                     
 41 #include "G4UnitsTable.hh"                        
 42 #include "G4UImanager.hh"                         
 43 #include "G4RunManager.hh"                        
 44 #include "G4LossTableManager.hh"                  
 45 #include "G4Material.hh"                          
 46 #include "G4MaterialCutsCouple.hh"                
 47 #include "G4ParticleDefinition.hh"                
 48 #include "G4ParticleTable.hh"                     
 49 #include "G4NistManager.hh"                       
 50 #include "G4Element.hh"                           
 51 #include "G4StateManager.hh"                      
 52                                                   
 53 HadrontherapyInteractionParameters::Hadronther    
 54     nistEle(new G4NistElementBuilder(0)),         
 55     nistMat(new G4NistMaterialBuilder(nistEle,    
 56     data(G4cout.rdbuf()),                         
 57     pMessenger(0),                                
 58     beamFlag(false)                               
 59                                                   
 60 {                                                 
 61     if (wantMessenger) pMessenger = new Hadron    
 62 }                                                 
 63                                                   
 64 HadrontherapyInteractionParameters::~Hadronthe    
 65 {                                                 
 66     if (pMessenger) delete pMessenger;            
 67     delete nistMat;                               
 68     delete nistEle;                               
 69 }                                                 
 70                                                   
 71 G4double HadrontherapyInteractionParameters::G    
 72                                                   
 73                       const G4Material* pMat,     
 74                 G4double dens)                    
 75 {                                                 
 76     if (dens) return ComputeTotalDEDX(ene, pDe    
 77     return ComputeTotalDEDX(ene, pDef, pMat);     
 78 }                                                 
 79 bool HadrontherapyInteractionParameters::GetSt    
 80 {                                                 
 81   // Check arguments                              
 82   if ( !ParseArg(vararg)) return false;           
 83   // Clear previous energy & mass sp vectors      
 84         energy.clear();                           
 85         massDedx.clear();                         
 86   // log scale                                    
 87   if (kinEmin != kinEmax && npoints >1)           
 88   {                                               
 89       G4double logmin = std::log10(kinEmin);      
 90       G4double logmax = std::log10(kinEmax);      
 91       G4double en;                                
 92       // uniform log space                        
 93             for (G4double c = 0.; c < npoints;    
 94          {                                        
 95         en = std::pow(10., logmin + ( c*(logma    
 96         energy.push_back(en/MeV);                 
 97         dedxtot =  ComputeTotalDEDX (en, parti    
 98               massDedx.push_back ( (dedxtot /     
 99          }                                        
100   }                                               
101   else // one point only                          
102   {                                               
103       energy.push_back(kinEmin/MeV);              
104       dedxtot =  ComputeTotalDEDX (kinEmin, pa    
105       massDedx.push_back ( (dedxtot / density)    
106   }                                               
107                                                   
108     G4cout.precision(6);                          
109     data <<  "MeV             " << "MeV*cm2/g     
110       material << ", density = " << G4BestUnit    
111     data << G4endl;                               
112     data << std::left << std::setfill(' ');       
113     for (size_t i=0; i<energy.size(); i++){       
114     data << std::setw(16) << energy[i] << mass    
115   }                                               
116     outfile.close();                              
117     // This will plot                             
118                                                   
119 // Info to user                                   
120     G4String ofName = (filename == "") ? G4Str    
121     G4cout << "User choice:\n";                   
122     G4cout << "Kinetic energy lower limit= "<<    
123         ", Kinetic energy upper limit= " << G4    
124            ", npoints= "<< npoints << ", parti    
125      "\", material= \"" << material << "\", fi    
126      ofName << "\"" << G4endl;                    
127     return true;                                  
128 }                                                 
129 // Search for user material choice inside G4Ni    
130 G4Material* HadrontherapyInteractionParameters    
131 {                                                 
132     Pmaterial = G4NistManager::Instance()->Fin    
133     if (Pmaterial) density = Pmaterial -> GetD    
134     return Pmaterial;                             
135 }                                                 
136 // Parse arguments line                           
137 bool HadrontherapyInteractionParameters::Parse    
138 {                                                 
139   kinEmin = kinEmax = npoints = 0.;               
140   particle = material = filename = "";            
141   // set internal variables                       
142   std::istringstream strParam(vararg);            
143   // TODO here check for number and parameters    
144   strParam >> std::skipws >> material >> kinEm    
145   // npoints must be an integer!                  
146   npoints = std::floor(npoints);                  
147                                                   
148 // Check that  kinEmax >= kinEmin > 0 &&  npoi    
149 // TODO NIST points and linear scale              
150    if (kinEmax == 0. && kinEmin > 0. ) kinEmax    
151    if (kinEmax == 0. && kinEmin == 0. ) kinEma    
152    if (kinEmax < kinEmin)                         
153    {                                              
154      G4cout << "WARNING: kinEmin must not exce    
155      G4cout << "Usage: /parameter/command  mat    
156      return false;                                
157    }                                              
158   if (npoints < 1) npoints = 1;                   
159                                                   
160     // check if element/material is into datab    
161     if (!GetNistMaterial(material) )              
162      {                                            
163        G4cout << "WARNING: material \"" << mat    
164            " table [$G4INSTALL/source/material    
165        G4cout << "Use command \"/parameter/nis    
166        return false;                              
167      }                                            
168     // Check for particle                         
169     if (particle == "") particle = "proton"; /    
170     else if ( !FindParticle(particle) )           
171      {                                            
172     G4cout << "WARNING: Particle \"" << partic    
173     G4cout << "Try the command \"/particle/lis    
174     G4cout << "If you are interested in an ion    
175               "\nTry the commands:\n/gun/parti    
176         "\n/gun/ion <atomic number> <mass numb    
177     return false;                                 
178      }                                            
179     // start physics by forcing a G4RunManager    
180     BeamOn();                                     
181     // Set output file                            
182     if( filename != "" )                          
183        {                                          
184           outfile.open(filename,std::ios_base:    
185           data.rdbuf(outfile.rdbuf());            
186        }                                          
187     else data.rdbuf(G4cout.rdbuf());  // outpu    
188     return true;                                  
189 }                                                 
190 // Force physics tables build                     
191 void HadrontherapyInteractionParameters::BeamO    
192 {                                                 
193     // first check if RunManager is above G4St    
194     G4StateManager* mState = G4StateManager::G    
195     G4ApplicationState  aState = mState -> Get    
196     if ( aState <= G4State_Idle && beamFlag ==    
197    {                                              
198       G4cout << "Issuing a G4RunManager::beamO    
199       G4cout << "Current Run State is " << mSt    
200       G4RunManager::GetRunManager() -> BeamOn(    
201       beamFlag = true;                            
202    }                                              
203                                                   
204 }                                                 
205 // print a list of Nist elements and materials    
206 void HadrontherapyInteractionParameters::ListO    
207 {                                                 
208 /*                                                
209  $G4INSTALL/source/materials/src/G4NistElement    
210  You can also construct a new material by the     
211  see $G4INSTALL/source/materials/src/G4NistMat    
212 */                                                
213     // Get simplest full list                     
214      if (vararg =="list")                         
215     {                                             
216       const std::vector<G4String>& vec =  nist    
217       for (size_t i=0; i<vec.size(); i++)         
218        {                                          
219           G4cout << std::setw(12) << std::left    
220        }                                          
221       G4cout << G4endl;                           
222           }                                       
223     else if (vararg =="all" || vararg =="simpl    
224   {                                               
225     nistMat -> ListMaterials(vararg);             
226   }                                               
227 }                                                 
228                                                   
229                                                   
230