source: trunk/source/processes/hadronic/cross_sections/src/G4NeutronInelasticXS.cc

Last change on this file was 1340, checked in by garnier, 14 years ago

update ti head

File size: 7.0 KB
Line 
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// $Id: G4NeutronInelasticXS.cc,v 1.6 2010/10/15 22:35:32 dennis Exp $
27// GEANT4 tag $Name: hadr-cross-V09-03-12 $
28//
29// -------------------------------------------------------------------
30//
31// GEANT4 Class file
32//
33//
34// File name:    G4NeutronInelasticXS
35//
36// Author  Ivantchenko, Geant4, 3-Aug-09
37//
38// Modifications:
39//
40
41#include "G4NeutronInelasticXS.hh"
42#include "G4Neutron.hh"
43#include "G4DynamicParticle.hh"
44#include "G4Element.hh"
45#include "G4ElementTable.hh"
46#include "G4PhysicsLogVector.hh"
47#include "G4PhysicsVector.hh"
48#include "G4GlauberGribovCrossSection.hh"
49#include "G4HadronNucleonXsc.hh"
50#include "G4NistManager.hh"
51#include "G4Proton.hh"
52
53#include <iostream>
54#include <fstream>
55#include <sstream>
56
57using namespace std;
58
59G4NeutronInelasticXS::G4NeutronInelasticXS() 
60  : proton(G4Proton::Proton()), maxZ(92)
61{
62  //  verboseLevel = 0;
63  if(verboseLevel > 0){
64    G4cout  << "G4NeutronInelasticXS::G4NeutronInelasticXS Initialise for Z < " 
65            << maxZ + 1 << G4endl;
66  }
67  data.resize(maxZ+1, 0);
68  coeff.resize(maxZ+1, 1.0);
69  ggXsection = new G4GlauberGribovCrossSection();
70  fNucleon = new G4HadronNucleonXsc();
71  isInitialized = false;
72}
73
74G4NeutronInelasticXS::~G4NeutronInelasticXS()
75{
76  for(G4int i=0; i<=maxZ; ++i) {
77    delete data[i];
78  }
79}
80
81G4bool
82G4NeutronInelasticXS::IsApplicable(const G4DynamicParticle*, 
83                                   const G4Element*)
84{
85  return true;
86}
87
88G4bool
89G4NeutronInelasticXS::IsIsoApplicable(const G4DynamicParticle*,
90                                      G4int /*ZZ*/, G4int /*AA*/)
91{
92  return false;
93}
94
95
96G4double
97G4NeutronInelasticXS::GetCrossSection(const G4DynamicParticle* aParticle,
98                                      const G4Element* elm,
99                                      G4double)
100{
101  G4double xs = 0.0;
102  G4double ekin = aParticle->GetKineticEnergy();
103
104  G4int Z = G4int(elm->GetZ());
105  if(Z < 1 || Z > maxZ) { return xs; }
106  G4PhysicsVector* pv = data[Z];
107  //  G4cout  << "G4NeutronInelasticXS::GetCrossSection e= " << ekin << " Z= " << Z << G4endl;
108
109  // element was not initialised
110  if(!pv) {
111    Initialise(Z);
112    pv = data[Z];
113    if(!pv) { return xs; }
114  }
115
116  G4double e1 = pv->Energy(0);
117  if(ekin <= e1) { return xs; }
118
119  G4int n = pv->GetVectorLength() - 1;
120  G4double e2 = pv->Energy(n);
121  if(ekin <= e2) { 
122    xs = pv->Value(ekin); 
123  } else if(1 == Z) { 
124    fNucleon->GetHadronNucleonXscPDG(aParticle, proton);
125    xs = coeff[1]*fNucleon->GetInelasticHadronNucleonXsc();
126  } else {         
127    ggXsection->GetCrossSection(aParticle, elm);
128    xs = coeff[Z]*ggXsection->GetInelasticGlauberGribovXsc();
129  }
130
131  if(verboseLevel > 0) {
132    G4cout  << "ekin= " << ekin << ",  XSinel= " << xs << G4endl;
133  }
134  return xs;
135}
136
137
138void 
139G4NeutronInelasticXS::BuildPhysicsTable(const G4ParticleDefinition& p)
140{
141  if(verboseLevel > 0){
142    G4cout << "G4NeutronInelasticXS::BuildPhysicsTable for " 
143           << p.GetParticleName() << G4endl;
144  }
145  if(isInitialized || p.GetParticleName() != "neutron") { return; }
146  isInitialized = true;
147
148  // check environment variable
149  // Build the complete string identifying the file with the data set
150  char* path = getenv("G4NEUTRONXSDATA");
151  if (!path){
152    G4cout << "G4NEUTRONXSDATA environment variable not set" << G4endl;
153  }
154
155  G4DynamicParticle* dynParticle = 
156    new G4DynamicParticle(G4Neutron::Neutron(),G4ThreeVector(1,0,0),1);
157
158  // Access to elements
159  const G4ElementTable* theElmTable = G4Element::GetElementTable();
160  size_t numOfElm = G4Element::GetNumberOfElements();
161  if(numOfElm > 0) {
162    for(size_t i=0; i<numOfElm; ++i) {
163      G4int Z = G4int(((*theElmTable)[i])->GetZ());
164      if(Z < 1)         { Z = 1; }
165      else if(Z > maxZ) { Z = maxZ; }
166      //G4cout << "Z= " << Z << G4endl;
167      // Initialisation
168      if(!data[Z]) { Initialise(Z, dynParticle, path); }
169    }
170  }
171  delete dynParticle;
172}
173
174void 
175G4NeutronInelasticXS::DumpPhysicsTable(const G4ParticleDefinition&)
176{
177}
178
179void 
180G4NeutronInelasticXS::Initialise(G4int Z, G4DynamicParticle* dp, 
181                                 const char* p)
182{
183  if(data[Z]) { return; }
184  const char* path = p;
185  if(!p) {
186  // check environment variable
187  // Build the complete string identifying the file with the data set
188    path = getenv("G4NEUTRONXSDATA");
189    if (!path) {
190      if(verboseLevel > 1) {
191        G4cout << "G4NEUTRONXSDATA environment variable not set" << G4endl;
192      }
193      return;
194    }
195  }
196  G4DynamicParticle* dynParticle = dp;
197  if(!dp) {
198    dynParticle = 
199      new G4DynamicParticle(G4Neutron::Neutron(),G4ThreeVector(1,0,0),1);
200  }
201
202  const G4Element* Elem = 
203    G4NistManager::Instance()->FindOrBuildElement(Z, true);
204
205  // upload data from file
206  data[Z] = new G4PhysicsLogVector();
207
208  std::ostringstream ost;
209  ost << path << "/inelast" << Z ;
210  std::ifstream filein(ost.str().c_str());
211  if (!(filein)) {
212    G4cout << " file " << ost << "  is not opened" << G4endl;
213  }else{
214    if(verboseLevel > 1) {
215      G4cout << ost << " is opened" << G4endl;
216    }
217    // retrieve data from DB
218    data[Z]->Retrieve(filein, true);
219
220    // smooth transition
221    size_t n      = data[Z]->GetVectorLength() - 1;
222    G4double emax = data[Z]->Energy(n);
223    G4double sig1 = (*data[Z])[n];
224    dynParticle->SetKineticEnergy(emax);
225    G4double sig2 = 0.0;
226    if(1 == Z) {
227      fNucleon->GetHadronNucleonXscPDG(dynParticle, proton);
228      sig2 = fNucleon->GetInelasticHadronNucleonXsc();
229    } else {
230      ggXsection->GetCrossSection(dynParticle, Elem);
231      sig2 = ggXsection->GetInelasticGlauberGribovXsc();
232    }
233    if(sig2 > 0.) { coeff[Z] = sig1/sig2; }
234  } 
235  if(!dp) { delete dynParticle; }
236}
Note: See TracBrowser for help on using the repository browser.