Geant4  10.01.p02
G4NeutronHPJENDLHEData.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 // Class Description
27 // Cross-section data set for a high precision (based on JENDL_HE evaluated data
28 // libraries) description of elastic scattering 20 MeV ~ 3 GeV;
29 // Class Description - End
30 
31 // 15-Nov-06 First Implementation is done by T. Koi (SLAC/SCCS)
32 
34 #include "G4SystemOfUnits.hh"
35 #include "G4LPhysicsFreeVector.hh"
36 #include "G4ElementTable.hh"
37 #include "G4NeutronHPData.hh"
38 
40 {
41 
42  G4bool result = true;
43  G4double eKin = aP->GetKineticEnergy();
44  //if(eKin>20*MeV||aP->GetDefinition()!=G4Neutron::Neutron()) result = false;
45  if ( eKin < 20*MeV || 3*GeV < eKin || aP->GetDefinition()!=G4Neutron::Neutron() )
46  {
47  result = false;
48  }
49 // Element Check
50  else if ( !(vElement[ anE->GetIndex() ]) ) result = false;
51 
52  return result;
53 
54 }
55 
56 
57 
59 {
60  ;
61 }
62 
63 
64 
66 :G4VCrossSectionDataSet( "JENDLHE"+reaction+"CrossSection" )
67 {
68  reactionName = reaction;
69  BuildPhysicsTable( *pd );
70 }
71 
72 
73 
75 {
76  for ( std::map< G4int , std::map< G4int , G4PhysicsVector* >* >::iterator itZ = mIsotope.begin();
77  itZ != mIsotope.end(); ++itZ ) {
78  std::map< G4int , G4PhysicsVector* >* pointer_map = itZ->second;
79  if ( pointer_map ) {
80  for ( std::map< G4int , G4PhysicsVector* >::iterator itA = pointer_map->begin();
81  itA != pointer_map->end() ; ++itA ) {
82  G4PhysicsVector* pointerPhysicsVector = itA->second;
83  if ( pointerPhysicsVector ) {
84  delete pointerPhysicsVector;
85  itA->second = 0;
86  }
87  }
88  delete pointer_map;
89  itZ->second = 0;
90  }
91  }
92  mIsotope.clear();
93 }
94 
95 
96 
98 {
99 
100 // if ( &aP != G4Neutron::Neutron() )
101 // throw G4HadronicException(__FILE__, __LINE__, "Attempt to use NeutronHP data for particles other than neutrons!!!");
103 
104  G4String baseName = getenv( "G4NEUTRONHPDATA" );
105  G4String dirName = baseName+"/JENDL_HE/"+particleName+"/"+reactionName ;
106  G4String aFSType = "/CrossSection/";
107  G4NeutronHPNames theNames;
108 
109  G4String filename;
110 
111 // Create JENDL_HE data
112 // Create map element or isotope
113 
114  size_t numberOfElements = G4Element::GetNumberOfElements();
115  //theCrossSections = new G4PhysicsTable( numberOfElements );
116 
117  // make a PhysicsVector for each element
118 
119  static G4ThreadLocal G4ElementTable *theElementTable = 0 ; if (!theElementTable) theElementTable= G4Element::GetElementTable();
120  vElement.clear();
121  vElement.resize( numberOfElements );
122  for ( size_t i = 0; i < numberOfElements; ++i )
123  {
124 
125  G4Element* theElement = (*theElementTable)[i];
126  vElement[i] = false;
127 
128  // isotope
129  G4int nIso = (*theElementTable)[i]->GetNumberOfIsotopes();
130  G4int Z = static_cast<G4int> ((*theElementTable)[i]->GetZ());
131  if ( nIso!=0 )
132  {
133  G4bool found_at_least_one = false;
134  for ( G4int i1 = 0; i1 < nIso; i1++ )
135  {
136  G4int A = theElement->GetIsotope(i1)->GetN();
137 
138  if ( isThisNewIsotope( Z , A ) )
139  {
140 
141  std::stringstream ss;
142  ss << dirName << aFSType << Z << "_" << A << "_" << theNames.GetName( Z-1 );
143  filename = ss.str();
144  std::fstream file;
145  file.open ( filename , std::fstream::in );
146  G4int dummy;
147  file >> dummy;
148  if ( file.good() )
149  {
150 
151  //G4cout << "Found file for Z=" << Z << ", A=" << A << ", as " << filename << G4endl;
152  found_at_least_one = true;
153 
154  // read the file
155  G4PhysicsVector* aPhysVec = readAFile ( &file );
156 
157  //Regist
158 
159  registAPhysicsVector( Z , A , aPhysVec );
160 
161  }
162  else
163  {
164  //G4cout << "No file for "<< reactionType << " Z=" << Z << ", A=" << A << G4endl;
165  }
166 
167  file.close();
168 
169  }
170  else
171  {
172  found_at_least_one = TRUE;
173  }
174  }
175 
176  if ( found_at_least_one ) vElement[i] = true;
177 
178  }
179  else
180  {
181  G4StableIsotopes theStableOnes;
182  G4int first = theStableOnes.GetFirstIsotope( Z );
183  G4bool found_at_least_one = FALSE;
184  for ( G4int i1 = 0; i1 < theStableOnes.GetNumberOfIsotopes( static_cast<G4int>(theElement->GetZ() ) ); i1++)
185  {
186  G4int A = theStableOnes.GetIsotopeNucleonCount( first+i1 );
187 
188  if ( isThisNewIsotope( Z , A ) )
189  {
190 
191  std::stringstream ss;
192  ss << dirName << aFSType << Z << "_" << A << "_" << theNames.GetName( Z-1 );
193  filename = ss.str();
194 
195  std::fstream file;
196  file.open ( filename , std::fstream::in );
197  G4int dummy;
198  file >> dummy;
199  if ( file.good() )
200  {
201  //G4cout << "Found file for Z=" << Z << ", A=" << A << ", as " << filename << G4endl;
202  found_at_least_one = TRUE;
203  //Read the file
204 
205  G4PhysicsVector* aPhysVec = readAFile ( &file );
206 
207  //Regist the PhysicsVector
208  registAPhysicsVector( Z , A , aPhysVec );
209 
210  }
211  else
212  {
213  //G4cout << "No file for "<< reactionType << " Z=" << Z << ", A=" << A << G4endl;
214  }
215 
216  file.close();
217  }
218  else
219  {
220  found_at_least_one = TRUE;
221  }
222  }
223 
224  if ( found_at_least_one ) vElement[i] = true;
225 
226  }
227 
228  }
229 
230 }
231 
232 
233 
235 {
236  if(&aP!=G4Neutron::Neutron())
237  throw G4HadronicException(__FILE__, __LINE__, "Attempt to use NeutronHP data for particles other than neutrons!!!");
238 // G4cout << "G4NeutronHPJENDLHEData::DumpPhysicsTable still to be implemented"<<G4endl;
239 }
240 
241 
242 
245 // aTemp
246 {
247 
248  // Primary energy >20MeV
249  // Thus
250  // Not take account of Doppler broadening
251  // also
252  // Not take account of Target thermal motions
253 
254  G4double result = 0;
255 
256  G4double ek = aP->GetKineticEnergy();
257 
258  G4int nIso = anE->GetNumberOfIsotopes();
259  G4int Z = static_cast<G4int> ( anE->GetZ() );
260  if ( nIso!=0 )
261  {
262  for ( G4int i1 = 0; i1 < nIso; i1++ )
263  {
264 
265  G4int A = anE->GetIsotope(i1)->GetN();
266  G4double frac = anE->GetRelativeAbundanceVector()[ i1 ]; // This case do NOT request "*perCent".
267 
268  result += frac * getXSfromThisIsotope( Z , A , ek );
269  //G4cout << reactionType << " XS in barn " << Z << " " << A << " " << frac << " " << getXSfromThisIsotope( Z , A , ek )/barn << G4endl;
270 
271  }
272  }
273  else
274  {
275 
276  G4StableIsotopes theStableOnes;
277  G4int first = theStableOnes.GetFirstIsotope( Z );
278  for ( G4int i1 = 0; i1 < theStableOnes.GetNumberOfIsotopes( static_cast<G4int>(anE->GetZ() ) ); i1++)
279  {
280 
281  G4int A = theStableOnes.GetIsotopeNucleonCount( first+i1 );
282  G4double frac = theStableOnes.GetAbundance( first+i1 )*perCent; // This case request "*perCent".
283 
284  result += frac * getXSfromThisIsotope( Z , A , ek );
285  //G4cout << reactionType << " XS in barn " << Z << " " << A << " " << frac << " " << getXSfromThisIsotope( Z , A , ek )/barn << G4endl;
286 
287  }
288  }
289  return result;
290 
291 }
292 
293 
294 
296 {
297 
298  G4int dummy;
299  G4int len;
300  *file >> dummy;
301  *file >> len;
302 
303  std::vector< G4double > v_e;
304  std::vector< G4double > v_xs;
305 
306  for ( G4int i = 0 ; i < len ; i++ )
307  {
308  G4double e;
309  G4double xs;
310 
311  *file >> e;
312  *file >> xs;
313  // data are written in eV and barn.
314  v_e.push_back( e*eV );
315  v_xs.push_back( xs*barn );
316  }
317 
318  G4LPhysicsFreeVector* aPhysVec = new G4LPhysicsFreeVector( static_cast< size_t >( len ) , v_e.front() , v_e.back() );
319 
320  for ( G4int i = 0 ; i < len ; i++ )
321  {
322  aPhysVec->PutValues( static_cast< size_t >( i ) , v_e[ i ] , v_xs[ i ] );
323  }
324 
325  return aPhysVec;
326 }
327 
328 
329 
331 {
332  if ( mIsotope.find ( z ) == mIsotope.end() ) return false;
333  if ( mIsotope.find ( z ) -> second->find ( a ) == mIsotope.find ( z ) -> second->end() ) return false;
334  return true;
335 }
336 
337 
338 
340 {
341 
342  std::pair< G4int , G4PhysicsVector* > aPair = std::pair < G4int , G4PhysicsVector* > ( A , aPhysVec );
343 
344  std::map < G4int , std::map< G4int , G4PhysicsVector* >* >::iterator itm;
345  itm = mIsotope.find ( Z );
346  if ( itm != mIsotope.end() )
347  {
348  itm->second->insert ( aPair );
349  }
350  else
351  {
352  std::map< G4int , G4PhysicsVector* >* aMap = new std::map< G4int , G4PhysicsVector* >;
353  aMap->insert ( aPair );
354  mIsotope.insert( std::pair< G4int , std::map< G4int , G4PhysicsVector* >* > ( Z , aMap ) );
355  }
356 
357 }
358 
359 
360 
362 {
363 
364  G4double aXSection = 0.0;
365  G4bool outOfRange;
366 
367  G4PhysicsVector* aPhysVec;
368  if ( mIsotope.find ( Z )->second->find ( A ) != mIsotope.find ( Z )->second->end() )
369  {
370 
371  aPhysVec = mIsotope.find ( Z )->second->find ( A )->second;
372  aXSection = aPhysVec->GetValue( ek , outOfRange );
373 
374  }
375  else
376  {
377 
378  //Select closest one in the same Z
379  std::map < G4int , G4PhysicsVector* >::iterator it;
380  G4int delta0 = 99; // no mean for 99
381  for ( it = mIsotope.find ( Z )->second->begin() ; it != mIsotope.find ( Z )->second->end() ; it++ )
382  {
383  G4int delta = std::abs( A - it->first );
384  if ( delta < delta0 ) delta0 = delta;
385  }
386 
387  // Randomize of selection larger or smaller than A
388  if ( G4UniformRand() < 0.5 ) delta0 *= -1;
389  G4int A1 = A + delta0;
390  if ( mIsotope.find ( Z )->second->find ( A1 ) != mIsotope.find ( Z )->second->end() )
391  {
392  aPhysVec = mIsotope.find ( Z )->second->find ( A1 )->second;
393  }
394  else
395  {
396  A1 = A - delta0;
397  aPhysVec = mIsotope.find ( Z )->second->find ( A1 )->second;
398  }
399 
400  aXSection = aPhysVec->GetValue( ek , outOfRange );
401  // X^(2/3) factor
402  aXSection *= std::pow ( 1.0*A/ A1 , 2.0 / 3.0 );
403 
404  }
405 
406  return aXSection;
407 }
size_t GetNumberOfIsotopes() const
Definition: G4Element.hh:158
void PutValues(size_t binNumber, G4double binValue, G4double dataValue)
static const double MeV
Definition: G4SIunits.hh:193
void registAPhysicsVector(G4int, G4int, G4PhysicsVector *)
G4bool isThisInMap(G4int, G4int)
G4double GetValue(G4double theEnergy, G4bool &isOutRange) const
G4double GetKineticEnergy() const
G4double z
Definition: TRTMaterials.hh:39
G4int GetFirstIsotope(G4int Z)
G4double GetZ() const
Definition: G4Element.hh:131
G4double getXSfromThisIsotope(G4int, G4int, G4double)
G4double a
Definition: TRTMaterials.hh:39
#define G4ThreadLocal
Definition: tls.hh:89
G4NeutronHPDataUsed GetName(G4int A, G4int Z, G4String base, G4String rest, G4bool &active)
int G4int
Definition: G4Types.hh:78
G4double GetCrossSection(const G4DynamicParticle *, const G4Element *, G4double aT)
G4bool isThisNewIsotope(G4int z, G4int a)
const G4String & GetParticleName() const
void DumpPhysicsTable(const G4ParticleDefinition &)
G4int GetN() const
Definition: G4Isotope.hh:94
#define G4UniformRand()
Definition: Randomize.hh:93
static size_t GetNumberOfElements()
Definition: G4Element.cc:410
bool G4bool
Definition: G4Types.hh:79
#define FALSE
Definition: globals.hh:52
G4PhysicsVector * readAFile(std::fstream *)
G4double * GetRelativeAbundanceVector() const
Definition: G4Element.hh:166
size_t GetIndex() const
Definition: G4Element.hh:181
static const double second
Definition: G4SIunits.hh:138
#define TRUE
Definition: globals.hh:55
static const double perCent
Definition: G4SIunits.hh:296
static G4Neutron * Neutron()
Definition: G4Neutron.cc:104
static const G4double A[nN]
G4int GetNumberOfIsotopes(G4int Z)
static const double eV
Definition: G4SIunits.hh:194
G4int GetIsotopeNucleonCount(G4int number)
G4bool IsApplicable(const G4DynamicParticle *, const G4Element *)
const G4Isotope * GetIsotope(G4int iso) const
Definition: G4Element.hh:169
G4double GetAbundance(G4int number)
static const double barn
Definition: G4SIunits.hh:95
std::vector< G4Element * > G4ElementTable
std::vector< G4bool > vElement
double G4double
Definition: G4Types.hh:76
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:403
std::map< G4int, std::map< G4int, G4PhysicsVector * > * > mIsotope
void BuildPhysicsTable(const G4ParticleDefinition &)