Warning, file /geant4/examples/advanced/hadrontherapy/src/HadrontherapyInteractionParameters.cc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 #include <fstream>
0030 #include <iostream>
0031 #include <sstream>
0032 #include <cmath>
0033 #include <vector>
0034
0035 #include "HadrontherapyInteractionParameters.hh"
0036 #include "HadrontherapyParameterMessenger.hh"
0037 #include "HadrontherapyDetectorConstruction.hh"
0038
0039 #include "globals.hh"
0040 #include "G4SystemOfUnits.hh"
0041 #include "G4UnitsTable.hh"
0042 #include "G4UImanager.hh"
0043 #include "G4RunManager.hh"
0044 #include "G4LossTableManager.hh"
0045 #include "G4Material.hh"
0046 #include "G4MaterialCutsCouple.hh"
0047 #include "G4ParticleDefinition.hh"
0048 #include "G4ParticleTable.hh"
0049 #include "G4NistManager.hh"
0050 #include "G4Element.hh"
0051 #include "G4StateManager.hh"
0052
0053 HadrontherapyInteractionParameters::HadrontherapyInteractionParameters(G4bool wantMessenger):
0054 nistEle(new G4NistElementBuilder(0)),
0055 nistMat(new G4NistMaterialBuilder(nistEle, 0)),
0056 data(G4cout.rdbuf()),
0057 pMessenger(0),
0058 beamFlag(false)
0059
0060 {
0061 if (wantMessenger) pMessenger = new HadrontherapyParameterMessenger(this);
0062 }
0063
0064 HadrontherapyInteractionParameters::~HadrontherapyInteractionParameters()
0065 {
0066 if (pMessenger) delete pMessenger;
0067 delete nistMat;
0068 delete nistEle;
0069 }
0070
0071 G4double HadrontherapyInteractionParameters::GetStopping (G4double ene,
0072 const G4ParticleDefinition* pDef,
0073 const G4Material* pMat,
0074 G4double dens)
0075 {
0076 if (dens) return ComputeTotalDEDX(ene, pDef, pMat)/dens;
0077 return ComputeTotalDEDX(ene, pDef, pMat);
0078 }
0079 bool HadrontherapyInteractionParameters::GetStoppingTable(const G4String& vararg)
0080 {
0081
0082 if ( !ParseArg(vararg)) return false;
0083
0084 energy.clear();
0085 massDedx.clear();
0086
0087 if (kinEmin != kinEmax && npoints >1)
0088 {
0089 G4double logmin = std::log10(kinEmin);
0090 G4double logmax = std::log10(kinEmax);
0091 G4double en;
0092
0093 for (G4double c = 0.; c < npoints; c++)
0094 {
0095 en = std::pow(10., logmin + ( c*(logmax-logmin) / (npoints - 1.)) );
0096 energy.push_back(en/MeV);
0097 dedxtot = ComputeTotalDEDX (en, particle, material);
0098 massDedx.push_back ( (dedxtot / density)/(MeV*cm2/g) );
0099 }
0100 }
0101 else
0102 {
0103 energy.push_back(kinEmin/MeV);
0104 dedxtot = ComputeTotalDEDX (kinEmin, particle, material);
0105 massDedx.push_back ( (dedxtot / density)/(MeV*cm2/g) );
0106 }
0107
0108 G4cout.precision(6);
0109 data << "MeV " << "MeV*cm2/g " << particle << " (into " <<
0110 material << ", density = " << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
0111 data << G4endl;
0112 data << std::left << std::setfill(' ');
0113 for (size_t i=0; i<energy.size(); i++){
0114 data << std::setw(16) << energy[i] << massDedx[i] << G4endl;
0115 }
0116 outfile.close();
0117
0118
0119
0120 G4String ofName = (filename == "") ? G4String("User terminal"): filename;
0121 G4cout << "User choice:\n";
0122 G4cout << "Kinetic energy lower limit= "<< G4BestUnit(kinEmin,"Energy") <<
0123 ", Kinetic energy upper limit= " << G4BestUnit(kinEmax,"Energy") <<
0124 ", npoints= "<< npoints << ", particle= \"" << particle <<
0125 "\", material= \"" << material << "\", filename= \""<<
0126 ofName << "\"" << G4endl;
0127 return true;
0128 }
0129
0130 G4Material* HadrontherapyInteractionParameters::GetNistMaterial(G4String mat)
0131 {
0132 Pmaterial = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0133 if (Pmaterial) density = Pmaterial -> GetDensity();
0134 return Pmaterial;
0135 }
0136
0137 bool HadrontherapyInteractionParameters::ParseArg(const G4String& vararg)
0138 {
0139 kinEmin = kinEmax = npoints = 0.;
0140 particle = material = filename = "";
0141
0142 std::istringstream strParam(vararg);
0143
0144 strParam >> std::skipws >> material >> kinEmin >> kinEmax >> npoints >> particle >> filename;
0145
0146 npoints = std::floor(npoints);
0147
0148
0149
0150 if (kinEmax == 0. && kinEmin > 0. ) kinEmax = kinEmin;
0151 if (kinEmax == 0. && kinEmin == 0. ) kinEmax = kinEmin = 1.*MeV;
0152 if (kinEmax < kinEmin)
0153 {
0154 G4cout << "WARNING: kinEmin must not exceed kinEmax!" << G4endl;
0155 G4cout << "Usage: /parameter/command material EkinMin EKinMax nPoints [particle] [output filename]" << G4endl;
0156 return false;
0157 }
0158 if (npoints < 1) npoints = 1;
0159
0160
0161 if (!GetNistMaterial(material) )
0162 {
0163 G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
0164 " table [$G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl;
0165 G4cout << "Use command \"/parameter/nist\" to see full materials list" << G4endl;
0166 return false;
0167 }
0168
0169 if (particle == "") particle = "proton";
0170 else if ( !FindParticle(particle) )
0171 {
0172 G4cout << "WARNING: Particle \"" << particle << "\" isn't supported." << G4endl;
0173 G4cout << "Try the command \"/particle/list\" to get full supported particles list." << G4endl;
0174 G4cout << "If you are interested in an ion that isn't in this list you must give it to the particle gun."
0175 "\nTry the commands:\n/gun/particle ion"
0176 "\n/gun/ion <atomic number> <mass number> <[charge]>" << G4endl << G4endl;
0177 return false;
0178 }
0179
0180 BeamOn();
0181
0182 if( filename != "" )
0183 {
0184 outfile.open(filename,std::ios_base::trunc);
0185 data.rdbuf(outfile.rdbuf());
0186 }
0187 else data.rdbuf(G4cout.rdbuf());
0188 return true;
0189 }
0190
0191 void HadrontherapyInteractionParameters::BeamOn()
0192 {
0193
0194 G4StateManager* mState = G4StateManager::GetStateManager();
0195 G4ApplicationState aState = mState -> GetCurrentState();
0196 if ( aState <= G4State_Idle && beamFlag == false)
0197 {
0198 G4cout << "Issuing a G4RunManager::beamOn()... ";
0199 G4cout << "Current Run State is " << mState -> GetStateString( aState ) << G4endl;
0200 G4RunManager::GetRunManager() -> BeamOn(0);
0201 beamFlag = true;
0202 }
0203
0204 }
0205
0206 void HadrontherapyInteractionParameters::ListOfNistMaterials(const G4String& vararg)
0207 {
0208
0209
0210
0211
0212
0213
0214 if (vararg =="list")
0215 {
0216 const std::vector<G4String>& vec = nistMat -> GetMaterialNames();
0217 for (size_t i=0; i<vec.size(); i++)
0218 {
0219 G4cout << std::setw(12) << std::left << i+1 << vec[i] << G4endl;
0220 }
0221 G4cout << G4endl;
0222 }
0223 else if (vararg =="all" || vararg =="simple" || vararg =="compound" || vararg =="hep" )
0224 {
0225 nistMat -> ListMaterials(vararg);
0226 }
0227 }
0228
0229