source: trunk/source/processes/hadronic/cross_sections/src/G4NeutronCaptureXS.cc @ 1340

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

update ti head

File size: 5.3 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: G4NeutronCaptureXS.cc,v 1.5 2010/10/15 22:36:13 dennis Exp $
27// GEANT4 tag $Name: hadr-cross-V09-03-12 $
28//
29// -------------------------------------------------------------------
30//
31// GEANT4 Class file
32//
33//
34// File name:    G4NeutronCaptureXS
35//
36// Author  Ivantchenko, Geant4, 3-Aug-09
37//
38// Modifications:
39//
40
41#include "G4NeutronCaptureXS.hh"
42#include "G4Element.hh"
43#include "G4ElementTable.hh"
44#include "G4PhysicsLogVector.hh"
45#include "G4PhysicsVector.hh"
46
47#include <iostream>
48#include <fstream>
49#include <sstream>
50
51using namespace std;
52
53G4NeutronCaptureXS::G4NeutronCaptureXS() 
54  : emax(20*MeV),maxZ(92)
55{
56  //  verboseLevel = 0;
57  if(verboseLevel > 0){
58    G4cout  << "G4NeutronCaptureXS::G4NeutronCaptureXS: Initialise for Z < "
59            << maxZ + 1 << G4endl;
60  }
61  data.resize(maxZ+1, 0);
62  isInitialized = false;
63}
64
65G4NeutronCaptureXS::~G4NeutronCaptureXS()
66{
67  for(G4int i=0; i<=maxZ; ++i) {
68    delete data[i];
69  }
70}
71
72G4bool
73G4NeutronCaptureXS::IsApplicable(const G4DynamicParticle*, 
74                                    const G4Element*)
75{
76  return true;
77}
78
79G4bool
80G4NeutronCaptureXS::IsIsoApplicable(const G4DynamicParticle*,
81                                    G4int /*ZZ*/, G4int /*AA*/)
82{
83  return false;
84}
85
86
87G4double
88G4NeutronCaptureXS::GetCrossSection(const G4DynamicParticle* aParticle,
89                                    const G4Element* elm,
90                                    G4double)
91{
92  G4double xs = 0.0;
93  G4double ekin = aParticle->GetKineticEnergy();
94  if(ekin > emax) { return xs; }
95
96  G4int Z = G4int(elm->GetZ());
97  G4PhysicsVector* pv = data[Z];
98
99  // element was not initialised
100  if(!pv) {
101    Initialise(Z);
102    pv = data[Z];
103    if(!pv) { return xs; }
104  }
105
106  G4int n = pv->GetVectorLength() - 1;
107  G4double e1 = pv->Energy(0);
108  G4double e2 = pv->Energy(n);
109  if(ekin < e1)       { xs = (*pv)[0]*std::sqrt(e1/ekin); }
110  else if(ekin <= e2) { xs = pv->Value(ekin); }
111
112  if(verboseLevel > 0){
113    G4cout  << "ekin= " << ekin << ",  xs= " << xs << G4endl;
114  }
115  return xs;
116}
117
118
119void 
120G4NeutronCaptureXS::BuildPhysicsTable(const G4ParticleDefinition& p)
121{
122  if(verboseLevel > 0){
123    G4cout << "G4NeutronCaptureXS::BuildPhysicsTable for " 
124           << p.GetParticleName() << G4endl;
125  }
126  if(isInitialized || p.GetParticleName() != "neutron") { return; }
127  isInitialized = true;
128
129
130  // check environment variable
131  // Build the complete string identifying the file with the data set
132  char* path = getenv("G4NEUTRONXSDATA");
133  if (!path){
134    G4cout << "G4NEUTRONXSDATA environment variable not set" << G4endl;
135  }
136
137  // Access to elements
138  const G4ElementTable* theElmTable = G4Element::GetElementTable();
139  size_t numOfElm = G4Element::GetNumberOfElements();
140  if(numOfElm > 0) {
141    for(size_t i=0; i<numOfElm; ++i) {
142      G4int Z = G4int(((*theElmTable)[i])->GetZ());
143      if(Z < 1)         { Z = 1; }
144      else if(Z > maxZ) { Z = maxZ; }
145      //G4cout << "Z= " << Z << G4endl;
146      // Initialisation
147      if(!data[Z]) { Initialise(Z, path); }
148    }
149  }
150}
151
152void 
153G4NeutronCaptureXS::DumpPhysicsTable(const G4ParticleDefinition&)
154{}
155
156
157void 
158G4NeutronCaptureXS::Initialise(G4int Z, const char* p)
159{
160  if(data[Z]) { return; }
161  const char* path = p;
162  if(!p) {
163  // check environment variable
164  // Build the complete string identifying the file with the data set
165    path = getenv("G4NEUTRONXSDATA");
166    if (!path) {
167      if(verboseLevel > 1) {
168        G4cout << "G4NEUTRONXSDATA environment variable not set" << G4endl;
169      }
170      return;
171    }
172  }
173
174  // upload data from file
175  data[Z] = new G4PhysicsLogVector();
176
177  std::ostringstream ost;
178  ost << path << "/cap" << Z ;
179  std::ifstream filein(ost.str().c_str());
180  if (!(filein)) {
181    G4cout << " file " << ost << "  is not opened" << G4endl;
182  }else{
183    if(verboseLevel > 1) {
184      G4cout << ost << " is opened" << G4endl;
185    }
186    // retrieve data from DB
187    data[Z]->Retrieve(filein, true);
188  } 
189}
Note: See TracBrowser for help on using the repository browser.