source: trunk/source/processes/hadronic/cross_sections/src/G4NeutronElasticXS.cc @ 1355

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