Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IORTInteractionParameters.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // This is the *BASIC* version of IORT, a Geant4-based application
27 //
28 // Main Authors: G.Russo(a,b), C.Casarino*(c), G.C. Candiano(c), G.A.P. Cirrone(d), F.Romano(d)
29 // Contributor Authors: S.Guatelli(e)
30 // Past Authors: G.Arnetta(c), S.E.Mazzaglia(d)
31 //
32 // (a) Fondazione Istituto San Raffaele G.Giglio, Cefalù, Italy
33 // (b) IBFM-CNR , Segrate (Milano), Italy
34 // (c) LATO (Laboratorio di Tecnologie Oncologiche), Cefalù, Italy
35 // (d) Laboratori Nazionali del Sud of the INFN, Catania, Italy
36 // (e) University of Wallongong, Australia
37 //
38 // *Corresponding author, email to carlo.casarino@polooncologicocefalu.it
40 
41 #include <fstream>
42 #include <iostream>
43 #include <sstream>
44 #include <cmath>
45 #include <vector>
46 
50 
51 #include "globals.hh"
52 #include "G4SystemOfUnits.hh"
53 #include "G4UnitsTable.hh"
54 #include "G4UImanager.hh"
55 #include "G4RunManager.hh"
56 #include "G4LossTableManager.hh"
57 #include "G4Material.hh"
58 #include "G4MaterialCutsCouple.hh"
59 #include "G4ParticleDefinition.hh"
60 #include "G4ParticleTable.hh"
61 #include "G4NistManager.hh"
62 #include "G4Element.hh"
63 #include "G4StateManager.hh"
64 
66  nistEle(new G4NistElementBuilder(0)),
67  nistMat(new G4NistMaterialBuilder(nistEle, 0)),
68  data(G4cout.rdbuf()),
69  pMessenger(0),
70  beamFlag(false)
71 #ifdef G4ANALYSIS_USE_ROOT
72  ,theRootCanvas(0),
73  theRootGraph(0)
74 #endif
75 {
76  if (wantMessenger) pMessenger = new IORTParameterMessenger(this);
77 }
78 
80 {
81  if (pMessenger) delete pMessenger;
82  delete nistMat;
83  delete nistEle;
84 }
85 
87  const G4ParticleDefinition* pDef,
88  const G4Material* pMat,
89  G4double dens)
90 {
91  if (dens) return ComputeTotalDEDX(ene, pDef, pMat)/dens;
92  return ComputeTotalDEDX(ene, pDef, pMat);
93 }
95 {
96  // Check arguments
97  if ( !ParseArg(vararg)) return false;
98  // Clear previous energy & mass sp vectors
99  energy.clear();
100  massDedx.clear();
101  // log scale
102  if (kinEmin != kinEmax && npoints >1)
103  {
104  G4double logmin = std::log10(kinEmin);
105  G4double logmax = std::log10(kinEmax);
106  G4double en;
107  // uniform log space
108  for (G4double c = 0.; c < npoints; c++)
109  {
110  en = std::pow(10., logmin + ( c*(logmax-logmin) / (npoints - 1.)) );
111  energy.push_back(en/MeV);
112  dedxtot = ComputeTotalDEDX (en, particle, material);
113  massDedx.push_back ( (dedxtot / density)/(MeV*cm2/g) );
114  }
115  }
116  else // one point only
117  {
118  energy.push_back(kinEmin/MeV);
119  dedxtot = ComputeTotalDEDX (kinEmin, particle, material);
120  massDedx.push_back ( (dedxtot / density)/(MeV*cm2/g) );
121  }
122 
123  G4cout.precision(6);
124  data << "MeV " << "MeV*cm2/g " << particle << " (into " <<
125  material << ", density = " << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
126  data << G4endl;
127  data << std::left << std::setfill(' ');
128  for (size_t i=0; i<energy.size(); i++){
129  data << std::setw(16) << energy[i] << massDedx[i] << G4endl;
130  }
131  outfile.close();
132  // This will plot
133 #ifdef G4ANALYSIS_USE_ROOT
134  PlotStopping("pdf");
135 #endif
136 
137  // Info to user
138  G4String ofName = (filename == "") ? "User terminal": filename;
139  G4cout << "User choice:\n";
140  G4cout << "Kinetic energy lower limit= "<< G4BestUnit(kinEmin,"Energy") <<
141  ", Kinetic energy upper limit= " << G4BestUnit(kinEmax,"Energy") <<
142  ", npoints= "<< npoints << ", particle= \"" << particle <<
143  "\", material= \"" << material << "\", filename= \""<<
144  ofName << "\"" << G4endl;
145  return true;
146 }
148 // Save Plot
149 #ifdef G4ANALYSIS_USE_ROOT
150 void IORTInteractionParameters::PlotStopping(const G4String& filetype)
151 {
152  if (!theRootCanvas)
153  {
154  gROOT->Reset();
155  gROOT->SetStyle("Plain");
156  theRootCanvas = new TCanvas("theRootCanvas","Interaction Parameters",200, 10, 600,400);
157  theRootCanvas -> SetFillColor(20);
158  theRootCanvas -> SetBorderMode(1);
159  theRootCanvas -> SetBorderSize(1);
160  theRootCanvas -> SetFrameBorderMode(0);
161  theRootCanvas -> SetGrid();
162  // Use global pad: root manual pgg 109,...
163  }
164 
165  if (theRootGraph) delete theRootGraph;
166  theRootGraph = new TGraph(energy.size(), &energy[0], &massDedx[0]);
167  //theRootGraph = new TGraph();
168  axisX = theRootGraph -> GetXaxis(),
169  axisY = theRootGraph -> GetYaxis();
170  axisX -> SetTitle("MeV");
171  axisY -> SetTitle("Stopping Power (MeV cm2/g)");
172  //axisX -> SetNdivisions(500,kTRUE);
173  //axisX -> SetTickLength(0.03);
174  //axisX -> SetLabelOffset(2.005);
175  axisX -> SetAxisColor(2);
176  axisY -> SetAxisColor(2);
177  gPad -> SetLogx(1);
178  gPad -> SetLogy(1);
179  theRootGraph -> SetMarkerColor(4);
180  theRootGraph -> SetMarkerStyle(20);// circle
181  theRootGraph -> SetMarkerSize(.5);
182 
183  G4String gName = particle.substr(0, particle.find("[") ); // cut excitation energy
184  gName = gName + "_" + material;
185  G4String fName = "./referenceData/interaction/" + gName + "." + filetype;
186  theRootGraph -> SetTitle(gName);
187  theRootGraph -> Draw("AP");
188  //theRootCanvas -> Update();
189  //theRootCanvas -> Draw();
190  theRootCanvas -> SaveAs(fName);
191 }
192 #endif
193 
194 // Search for user material choice inside G4NistManager database
195 G4Material* IORTInteractionParameters::GetNistMaterial(G4String mat)
196 {
197  Pmaterial = G4NistManager::Instance()->FindOrBuildMaterial(mat);
198  if (Pmaterial) density = Pmaterial -> GetDensity();
199  return Pmaterial;
200 }
201 // Parse arguments line
203 {
204  kinEmin = kinEmax = npoints = 0.;
205  particle = material = filename = "";
206  // set internal variables
207  std::istringstream strParam(vararg);
208  // TODO here check for number and parameters consistency
209  strParam >> std::skipws >> material >> kinEmin >> kinEmax >> npoints >> particle >> filename;
210  // npoints must be an integer!
211  npoints = std::floor(npoints);
212 
213 // Check that kinEmax >= kinEmin > 0 && npoints >= 1
214 // TODO NIST points and linear scale
215  if (kinEmax == 0. && kinEmin > 0. ) kinEmax = kinEmin;
216  if (kinEmax == 0. && kinEmin == 0. ) kinEmax = kinEmin = 1.*MeV;
217  if (kinEmax < kinEmin)
218  {
219  G4cout << "WARNING: kinEmin must not exceed kinEmax!" << G4endl;
220  G4cout << "Usage: /parameter/command material kinetic Emin kinetic Emax nPoints [particle] [output filename]" << G4endl;
221  return false;
222  }
223  if (npoints < 1) npoints = 1;
224 
225  // check if element/material is into database
226  if (!GetNistMaterial(material) )
227  {
228  G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials"
229  " table [$G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl;
230  G4cout << "Use command \"/parameter/nist\" to see full materials list" << G4endl;
231  return false;
232  }
233  // Check for particle
234  if (particle == "") particle = "proton"; // default to "proton"
235  else if ( !FindParticle(particle) )
236  {
237  G4cout << "WARNING: Particle \"" << particle << "\" isn't supported." << G4endl;
238  G4cout << "Try the command \"/particle/list\" to get full supported particles list." << G4endl;
239  G4cout << "If you are interested in an ion that isn't in this list you must give it to the particle gun."
240  "\nTry the commands:\n/gun/particle ion"
241  "\n/gun/ion <atomic number> <mass number> <[charge]>" << G4endl << G4endl;
242  return false;
243  }
244  // start physics by forcing a G4RunManager::BeamOn():
245  BeamOn();
246  // Set output file
247  if( filename != "" )
248  {
249  outfile.open(filename,std::ios_base::trunc); // overwrite existing file
250  data.rdbuf(outfile.rdbuf());
251  }
252  else data.rdbuf(G4cout.rdbuf()); // output is G4cout!
253  return true;
254 }
255 // Force physics tables build
257 {
258  // first check if RunManager is above G4State_Idle
260  G4ApplicationState aState = mState -> GetCurrentState();
261  if ( aState <= G4State_Idle && beamFlag == false)
262  {
263  G4cout << "Issuing a G4RunManager::beamOn()... ";
264  G4cout << "Current Run State is " << mState -> GetStateString( aState ) << G4endl;
266  beamFlag = true;
267  }
268 
269 }
270 // print a list of Nist elements and materials
272 {
273 /*
274  $G4INSTALL/source/materials/src/G4NistElementBuilder.cc
275  You can also construct a new material by the ConstructNewMaterial method:
276  see $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc
277 */
278  // Get simplest full list
279  if (vararg =="list")
280  {
281  const std::vector<G4String>& vec = nistMat -> GetMaterialNames();
282  for (size_t i=0; i<vec.size(); i++)
283  {
284  G4cout << std::setw(12) << std::left << i+1 << vec[i] << G4endl;
285  }
286  G4cout << G4endl;
287  }
288  else if (vararg =="all" || vararg =="simple" ||
289  vararg =="compound" || vararg =="hep" )
290  {
291  nistMat -> ListMaterials(vararg);
292  }
293 }
294 
295 
void ListOfNistMaterials(const G4String &vararg)
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
G4String fName
Definition: G4AttUtils.hh:55
static constexpr double cm2
Definition: G4SIunits.hh:120
G4double ComputeTotalDEDX(G4double kinEnergy, const G4ParticleDefinition *, const G4Material *, G4double cut=DBL_MAX)
G4double GetStopping(G4double energy, const G4ParticleDefinition *, const G4Material *, G4double density=0.)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
bool ParseArg(const G4String &vararg)
static G4NistManager * Instance()
const XML_Char const XML_Char * data
Definition: expat.h:268
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
static G4StateManager * GetStateManager()
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
G4bool SetTitle(G4ToolsBaseHisto &baseHisto, const G4String &title)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
const G4ParticleDefinition * FindParticle(const G4String &)
G4bool GetStoppingTable(const G4String &vararg)
#define G4endl
Definition: G4ios.hh:61
static constexpr double MeV
Definition: G4SIunits.hh:214
double G4double
Definition: G4Types.hh:76
tuple c
Definition: test.py:13
G4ApplicationState