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