Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/hadronic/models/particle_hp/src/G4ParticleHPThermalScatteringData.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/hadronic/models/particle_hp/src/G4ParticleHPThermalScatteringData.cc (Version 11.3.0) and /processes/hadronic/models/particle_hp/src/G4ParticleHPThermalScatteringData.cc (Version 11.1.1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4ParticleHPThermalScatteringData           <<  26 // Thermal Neutron Scattering
                                                   >>  27 // Koi, Tatsumi (SCCS/SLAC)
 27 //                                                 28 //
                                                   >>  29 // Class Description
                                                   >>  30 // Cross Sections for a high precision (based on evaluated data
                                                   >>  31 // libraries) description of themal neutron scattering below 4 eV;
                                                   >>  32 // Based on Thermal neutron scattering files
                                                   >>  33 // from the evaluated nuclear data files ENDF/B-VI, Release2
                                                   >>  34 // To be used in your physics list in case you need this physics.
                                                   >>  35 // In this case you want to register an object of this class with
                                                   >>  36 // the corresponding process.
                                                   >>  37 // Class Description - End
                                                   >>  38 
 28 // 15-Nov-06 First implementation is done by T     39 // 15-Nov-06 First implementation is done by T. Koi (SLAC/SCCS)
 29 // 070625 implement clearCurrentXSData to fix      40 // 070625 implement clearCurrentXSData to fix memory leaking by T. Koi
 30 // P. Arce, June-2014 Conversion neutron_hp to     41 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
 31 // ------------------------------------------- <<  42 //
 32                                                    43 
 33 #include "G4ParticleHPThermalScatteringData.hh <<  44 #include <list>
                                                   >>  45 #include <algorithm>
 34                                                    46 
 35 #include "G4ElementTable.hh"                   <<  47 #include "G4ParticleHPThermalScatteringData.hh"
 36 #include "G4Neutron.hh"                        << 
 37 #include "G4ParticleHPManager.hh"                  48 #include "G4ParticleHPManager.hh"
                                                   >>  49 
 38 #include "G4SystemOfUnits.hh"                      50 #include "G4SystemOfUnits.hh"
 39 #include "G4Threading.hh"                      <<  51 #include "G4Neutron.hh"
                                                   >>  52 #include "G4ElementTable.hh"
 40                                                    53 
 41 #include <algorithm>                           <<  54 #include "G4Threading.hh"
 42 #include <list>                                << 
 43                                                    55 
 44 G4ParticleHPThermalScatteringData::G4ParticleH     56 G4ParticleHPThermalScatteringData::G4ParticleHPThermalScatteringData()
 45   : G4VCrossSectionDataSet("NeutronHPThermalSc <<  57 :G4VCrossSectionDataSet("NeutronHPThermalScatteringData")
 46 {                                              <<  58 ,coherent(nullptr)
 47   // Upper limit of neutron energy             <<  59 ,incoherent(nullptr)
 48   emax = 4 * eV;                               <<  60 ,inelastic(nullptr)
 49   SetMinKinEnergy(0 * MeV);                    <<  61 {
 50   SetMaxKinEnergy(emax);                       <<  62    // Upper limit of neutron energy 
 51                                                <<  63    emax = 4*eV;
 52   ke_cache = 0.0;                              <<  64    SetMinKinEnergy( 0*MeV );                                   
 53   xs_cache = 0.0;                              <<  65    SetMaxKinEnergy( emax );                                   
 54   element_cache = nullptr;                     <<  66 
 55   material_cache = nullptr;                    <<  67    ke_cache = 0.0;
                                                   >>  68    xs_cache = 0.0;
                                                   >>  69    element_cache = nullptr;
                                                   >>  70    material_cache = nullptr;
 56                                                    71 
 57   indexOfThermalElement.clear();               <<  72    indexOfThermalElement.clear(); 
 58                                                    73 
 59   names = new G4ParticleHPThermalScatteringNam <<  74    names = new G4ParticleHPThermalScatteringNames();
 60 }                                                  75 }
 61                                                    76 
 62 G4ParticleHPThermalScatteringData::~G4Particle     77 G4ParticleHPThermalScatteringData::~G4ParticleHPThermalScatteringData()
 63 {                                                  78 {
 64   clearCurrentXSData();                        <<  79    clearCurrentXSData();
 65                                                    80 
 66   delete names;                                <<  81    delete names;
 67 }                                                  82 }
 68                                                    83 
 69 G4bool G4ParticleHPThermalScatteringData::IsIs <<  84 G4bool G4ParticleHPThermalScatteringData::IsIsoApplicable( const G4DynamicParticle* dp , 
 70                                                <<  85                                                 G4int /*Z*/ , G4int /*A*/ ,
 71                                                <<  86                                                 const G4Element* element ,
                                                   >>  87                                                 const G4Material* material )
 72 {                                                  88 {
 73   G4double eKin = dp->GetKineticEnergy();      <<  89    G4double eKin = dp->GetKineticEnergy();
 74   if (eKin > 4.0 * eV  // GetMaxKinEnergy()    <<  90    if ( eKin > 4.0*eV //GetMaxKinEnergy() 
 75       || eKin < 0  // GetMinKinEnergy()        <<  91      || eKin < 0 //GetMinKinEnergy() 
 76       || dp->GetDefinition() != G4Neutron::Neu <<  92      || dp->GetDefinition() != G4Neutron::Neutron() ) return false;                                   
 77     return false;                              << 
 78                                                    93 
 79   if (dic.find(std::pair<const G4Material*, co <<  94    if ( dic.find( std::pair < const G4Material* , const G4Element* > ( (G4Material*)NULL , element ) ) != dic.end() 
 80         != dic.end()                           <<  95      || dic.find( std::pair < const G4Material* , const G4Element* > ( material , element ) ) != dic.end() ) return true;
 81       || dic.find(std::pair<const G4Material*, << 
 82     return true;                               << 
 83                                                    96 
 84   return false;                                <<  97    return false;
 85 }                                                  98 }
 86                                                    99 
 87 G4double G4ParticleHPThermalScatteringData::Ge << 100 G4double G4ParticleHPThermalScatteringData::GetIsoCrossSection( const G4DynamicParticle* dp ,
 88                                                << 101                                    G4int /*Z*/ , G4int /*A*/ ,
 89                                                << 102                                    const G4Isotope* /*iso*/  ,
 90                                                << 103                                    const G4Element* element ,
 91                                                << 104                                    const G4Material* material )
 92 {                                                 105 {
 93   ke_cache = dp->GetKineticEnergy();           << 106    ke_cache = dp->GetKineticEnergy();
 94   element_cache = element;                     << 107    element_cache = element;
 95   material_cache = material;                   << 108    material_cache = material;
 96   G4double xs = GetCrossSection(dp, element, m << 109    G4double xs = GetCrossSection( dp , element , material );
 97   xs_cache = xs;                               << 110    xs_cache = xs;
 98   return xs;                                   << 111    return xs;
 99 }                                                 112 }
100                                                   113 
101 void G4ParticleHPThermalScatteringData::clearC    114 void G4ParticleHPThermalScatteringData::clearCurrentXSData()
102 {                                                 115 {
103   if (coherent != nullptr) {                   << 116    if ( coherent != nullptr )
104     for (auto it = coherent->cbegin(); it != c << 117    {
105       if (it->second != nullptr) {             << 118      for (auto it=coherent->cbegin() ; it!=coherent->cend(); ++it)
106         for (auto itt = it->second->cbegin();  << 119      {
107           delete itt->second;                  << 120        if ( it->second != nullptr )
108         }                                      << 121        {
                                                   >> 122          for (auto itt=it->second->cbegin(); itt!=it->second->cend(); ++itt)
                                                   >> 123          {
                                                   >> 124            delete itt->second;
                                                   >> 125          }
                                                   >> 126        }
                                                   >> 127        delete it->second;
                                                   >> 128      }
                                                   >> 129      coherent->clear();
                                                   >> 130    }
                                                   >> 131 
                                                   >> 132    if ( incoherent != nullptr )
                                                   >> 133    {
                                                   >> 134      for (auto it=incoherent->cbegin(); it!=incoherent->cend() ; ++it)
                                                   >> 135      {
                                                   >> 136        if ( it->second != nullptr )
                                                   >> 137        {
                                                   >> 138          for (auto itt=it->second->cbegin(); itt!=it->second->cend(); ++itt)
                                                   >> 139          {
                                                   >> 140            delete itt->second;
                                                   >> 141          }
                                                   >> 142        }
                                                   >> 143        delete it->second;
                                                   >> 144      }
                                                   >> 145      incoherent->clear();
                                                   >> 146    }
                                                   >> 147 
                                                   >> 148    if ( inelastic != nullptr )
                                                   >> 149    {
                                                   >> 150      for (auto it=inelastic->cbegin(); it!=inelastic->cend(); ++it)
                                                   >> 151      {
                                                   >> 152        if ( it->second != nullptr )
                                                   >> 153        {
                                                   >> 154          for (auto itt=it->second->cbegin(); itt!=it->second->cend(); ++itt)
                                                   >> 155          {
                                                   >> 156            delete itt->second;
                                                   >> 157          }
                                                   >> 158        }
                                                   >> 159        delete it->second;
                                                   >> 160      }
                                                   >> 161      inelastic->clear();
                                                   >> 162    }
                                                   >> 163 
                                                   >> 164 }
                                                   >> 165 
                                                   >> 166 
                                                   >> 167 G4bool G4ParticleHPThermalScatteringData::IsApplicable( const G4DynamicParticle* aP , const G4Element* anEle )
                                                   >> 168 {
                                                   >> 169    G4bool result = false;
                                                   >> 170 
                                                   >> 171    G4double eKin = aP->GetKineticEnergy();
                                                   >> 172    // Check energy 
                                                   >> 173    if ( eKin < emax )
                                                   >> 174    {
                                                   >> 175       // Check Particle Species
                                                   >> 176       if ( aP->GetDefinition() == G4Neutron::Neutron() ) 
                                                   >> 177       {
                                                   >> 178         // anEle is one of Thermal elements 
                                                   >> 179          G4int ie = (G4int) anEle->GetIndex();
                                                   >> 180          for (auto it = indexOfThermalElement.cbegin();
                                                   >> 181                    it != indexOfThermalElement.cend() ; ++it)
                                                   >> 182          {
                                                   >> 183              if ( ie == *it ) return true;
                                                   >> 184          }
109       }                                           185       }
110       delete it->second;                       << 186    }
111     }                                          << 
112     coherent->clear();                         << 
113   }                                            << 
114                                                << 
115   if (incoherent != nullptr) {                 << 
116     for (auto it = incoherent->cbegin(); it != << 
117       if (it->second != nullptr) {             << 
118         for (auto itt = it->second->cbegin();  << 
119           delete itt->second;                  << 
120         }                                      << 
121       }                                        << 
122       delete it->second;                       << 
123     }                                          << 
124     incoherent->clear();                       << 
125   }                                            << 
126                                                << 
127   if (inelastic != nullptr) {                  << 
128     for (auto it = inelastic->cbegin(); it !=  << 
129       if (it->second != nullptr) {             << 
130         for (auto itt = it->second->cbegin();  << 
131           delete itt->second;                  << 
132         }                                      << 
133       }                                        << 
134       delete it->second;                       << 
135     }                                          << 
136     inelastic->clear();                        << 
137   }                                            << 
138 }                                              << 
139                                                << 
140 G4bool G4ParticleHPThermalScatteringData::IsAp << 
141                                                << 
142 {                                              << 
143   G4bool result = false;                       << 
144                                                << 
145   G4double eKin = aP->GetKineticEnergy();      << 
146   // Check energy                              << 
147   if (eKin < emax) {                           << 
148     // Check Particle Species                  << 
149     if (aP->GetDefinition() == G4Neutron::Neut << 
150       // anEle is one of Thermal elements      << 
151       auto ie = (G4int)anEle->GetIndex();      << 
152       for (int it : indexOfThermalElement) {   << 
153         if (ie == it) return true;             << 
154       }                                        << 
155     }                                          << 
156   }                                            << 
157                                                   187 
158   return result;                               << 188    return result;
159 }                                                 189 }
160                                                   190 
                                                   >> 191 
161 void G4ParticleHPThermalScatteringData::BuildP    192 void G4ParticleHPThermalScatteringData::BuildPhysicsTable(const G4ParticleDefinition& aP)
162 {                                                 193 {
163   if (&aP != G4Neutron::Neutron())             << 
164     throw G4HadronicException(__FILE__, __LINE << 
165                               "Attempt to use  << 
166                                                << 
167   // std::map < std::pair < G4Material* , cons << 
168   //                                           << 
169   dic.clear();                                 << 
170   if (G4Threading::IsMasterThread()) clearCurr << 
171                                                << 
172   std::map<G4String, G4int> co_dic;            << 
173                                                << 
174   // Searching Nist Materials                  << 
175   static G4ThreadLocal G4MaterialTable* theMat << 
176   if (theMaterialTable == nullptr) theMaterial << 
177   std::size_t numberOfMaterials = G4Material:: << 
178   for (std::size_t i = 0; i < numberOfMaterial << 
179     G4Material* material = (*theMaterialTable) << 
180     auto numberOfElements = (G4int)material->G << 
181     for (G4int j = 0; j < numberOfElements; ++ << 
182       const G4Element* element = material->Get << 
183       if (names->IsThisThermalElement(material << 
184         G4int ts_ID_of_this_geometry;          << 
185         G4String ts_ndl_name = names->GetTS_ND << 
186         if (co_dic.find(ts_ndl_name) != co_dic << 
187           ts_ID_of_this_geometry = co_dic.find << 
188         }                                      << 
189         else {                                 << 
190           ts_ID_of_this_geometry = (G4int)co_d << 
191           co_dic.insert(std::pair<G4String, G4 << 
192         }                                      << 
193                                                   194 
194         dic.insert(std::pair<std::pair<G4Mater << 195    if ( &aP != G4Neutron::Neutron() ) 
195           std::pair<G4Material*, const G4Eleme << 196       throw G4HadronicException(__FILE__, __LINE__, "Attempt to use NeutronHP data for particles other than neutrons!!!");  
                                                   >> 197 
                                                   >> 198    //std::map < std::pair < G4Material* , const G4Element* > , G4int > dic;   
                                                   >> 199    //
                                                   >> 200    dic.clear();   
                                                   >> 201    if ( G4Threading::IsMasterThread() ) clearCurrentXSData();
                                                   >> 202 
                                                   >> 203    std::map < G4String , G4int > co_dic;   
                                                   >> 204 
                                                   >> 205    //Searching Nist Materials
                                                   >> 206    static G4ThreadLocal G4MaterialTable* theMaterialTable  = nullptr;
                                                   >> 207    if (!theMaterialTable) theMaterialTable= G4Material::GetMaterialTable();
                                                   >> 208    std::size_t numberOfMaterials = G4Material::GetNumberOfMaterials();
                                                   >> 209    for ( std::size_t i = 0 ; i < numberOfMaterials ; ++i )
                                                   >> 210    {
                                                   >> 211       G4Material* material = (*theMaterialTable)[i];
                                                   >> 212       G4int numberOfElements = (G4int)material->GetNumberOfElements();
                                                   >> 213       for ( G4int j = 0 ; j < numberOfElements ; ++j )
                                                   >> 214       {
                                                   >> 215          const G4Element* element = material->GetElement(j);
                                                   >> 216          if ( names->IsThisThermalElement ( material->GetName() , element->GetName() ) )
                                                   >> 217          {                                    
                                                   >> 218             G4int ts_ID_of_this_geometry; 
                                                   >> 219             G4String ts_ndl_name = names->GetTS_NDL_Name( material->GetName() , element->GetName() ); 
                                                   >> 220             if ( co_dic.find ( ts_ndl_name ) != co_dic.cend() )
                                                   >> 221             {
                                                   >> 222                ts_ID_of_this_geometry = co_dic.find ( ts_ndl_name ) -> second;
                                                   >> 223             }
                                                   >> 224             else
                                                   >> 225             {
                                                   >> 226                ts_ID_of_this_geometry = (G4int)co_dic.size();
                                                   >> 227                co_dic.insert ( std::pair< G4String , G4int >( ts_ndl_name , ts_ID_of_this_geometry ) );
                                                   >> 228             }
                                                   >> 229 
                                                   >> 230             dic.insert( std::pair < std::pair < G4Material* , const G4Element* > , G4int > ( std::pair < G4Material* , const G4Element* > ( material , element ) , ts_ID_of_this_geometry ) );
                                                   >> 231          }
196       }                                           232       }
197     }                                          << 233    }
198   }                                            << 234 
                                                   >> 235    //Searching TS Elements 
                                                   >> 236    static G4ThreadLocal G4ElementTable* theElementTable  = nullptr;
                                                   >> 237    if (!theElementTable) theElementTable= G4Element::GetElementTable();
                                                   >> 238    std::size_t numberOfElements = G4Element::GetNumberOfElements();
                                                   >> 239 
                                                   >> 240    for ( std::size_t i = 0 ; i < numberOfElements ; ++i )
                                                   >> 241    {
                                                   >> 242       const G4Element* element = (*theElementTable)[i];
                                                   >> 243       if ( names->IsThisThermalElement ( element->GetName() ) )
                                                   >> 244       {
                                                   >> 245          if ( names->IsThisThermalElement ( element->GetName() ) )
                                                   >> 246          {                                    
                                                   >> 247             G4int ts_ID_of_this_geometry; 
                                                   >> 248             G4String ts_ndl_name = names->GetTS_NDL_Name( element->GetName() ); 
                                                   >> 249             if ( co_dic.find ( ts_ndl_name ) != co_dic.cend() )
                                                   >> 250             {
                                                   >> 251                ts_ID_of_this_geometry = co_dic.find ( ts_ndl_name ) -> second;
                                                   >> 252             }
                                                   >> 253             else
                                                   >> 254             {
                                                   >> 255                ts_ID_of_this_geometry = (G4int)co_dic.size();
                                                   >> 256                co_dic.insert ( std::pair< G4String , G4int >( ts_ndl_name , ts_ID_of_this_geometry ) );
                                                   >> 257             }
199                                                   258 
200   // Searching TS Elements                     << 259             dic.insert( std::pair < std::pair < const G4Material* , const G4Element* > , G4int > ( std::pair < const G4Material* , const G4Element* > ( (G4Material*)NULL , element ) ,  ts_ID_of_this_geometry ) );
201   auto theElementTable = G4Element::GetElement << 260          }
202   std::size_t numberOfElements = G4Element::Ge << 
203                                                << 
204   for (std::size_t i = 0; i < numberOfElements << 
205     const G4Element* element = (*theElementTab << 
206     if (names->IsThisThermalElement(element->G << 
207       if (names->IsThisThermalElement(element- << 
208         G4int ts_ID_of_this_geometry;          << 
209         G4String ts_ndl_name = names->GetTS_ND << 
210         if (co_dic.find(ts_ndl_name) != co_dic << 
211           ts_ID_of_this_geometry = co_dic.find << 
212         }                                      << 
213         else {                                 << 
214           ts_ID_of_this_geometry = (G4int)co_d << 
215           co_dic.insert(std::pair<G4String, G4 << 
216         }                                      << 
217                                                << 
218         dic.insert(std::pair<std::pair<const G << 
219           std::pair<const G4Material*, const G << 
220           ts_ID_of_this_geometry));            << 
221       }                                           261       }
222     }                                          << 262    }
223   }                                            << 
224                                                   263 
225   G4cout << G4endl;                            << 264    G4cout << G4endl;
226   G4cout << "Neutron HP Thermal Scattering Dat << 265    G4cout << "Neutron HP Thermal Scattering Data: Following material-element pairs and/or elements are registered." << G4endl;
227             "are registered."                  << 266    for ( auto it = dic.cbegin() ; it != dic.cend() ; ++it )   
228          << G4endl;                            << 267    {
229   for (const auto& it : dic) {                 << 268       if ( it->first.first != nullptr ) 
230     if (it.first.first != nullptr) {           << 269       {
231       G4cout << "Material " << it.first.first- << 270          G4cout << "Material " << it->first.first->GetName() << " - Element "
232              << it.first.second->GetName() <<  << 271                 << it->first.second->GetName()
233              << G4endl;                        << 272                 << ",  internal thermal scattering id " << it->second << G4endl;
234     }                                          << 273       }
235     else {                                     << 274       else
236       G4cout << "Element " << it.first.second- << 275       {
237              << it.second << G4endl;           << 276          G4cout << "Element " << it->first.second->GetName()
238     }                                          << 277                 << ",  internal thermal scattering id " << it->second << G4endl;
239   }                                            << 278       }
240   G4cout << G4endl;                            << 279    }
241                                                << 280    G4cout << G4endl;
242   G4ParticleHPManager* hpmanager = G4ParticleH << 281 
243                                                << 282    G4ParticleHPManager* hpmanager = G4ParticleHPManager::GetInstance();
244   coherent = hpmanager->GetThermalScatteringCo << 283 
245   incoherent = hpmanager->GetThermalScattering << 284    coherent = hpmanager->GetThermalScatteringCoherentCrossSections();
246   inelastic = hpmanager->GetThermalScatteringI << 285    incoherent = hpmanager->GetThermalScatteringIncoherentCrossSections();
247                                                << 286    inelastic = hpmanager->GetThermalScatteringInelasticCrossSections();
248   if (G4Threading::IsMasterThread()) {         << 287 
249     if (coherent == nullptr)                   << 288    if ( G4Threading::IsMasterThread() )
250       coherent = new std::map<G4int, std::map< << 289    {
251     if (incoherent == nullptr)                 << 290       if ( coherent == nullptr )
252       incoherent = new std::map<G4int, std::ma << 291         coherent = new std::map< G4int , std::map< G4double , G4ParticleHPVector* >* >;
253     if (inelastic == nullptr)                  << 292       if ( incoherent == nullptr )
254       inelastic = new std::map<G4int, std::map << 293         incoherent = new std::map< G4int , std::map< G4double , G4ParticleHPVector* >* >;
255                                                << 294       if ( inelastic == nullptr )
256     // Read Cross Section Data files           << 295         inelastic = new std::map< G4int , std::map< G4double , G4ParticleHPVector* >* >;
257                                                << 296 
258     G4String dirName;                          << 297       // Read Cross Section Data files
259     if (G4FindDataDir("G4NEUTRONHPDATA") == nu << 298 
260       throw G4HadronicException(               << 299       G4String dirName;
261         __FILE__, __LINE__,                    << 300       if ( !G4FindDataDir( "G4NEUTRONHPDATA" ) )
262         "Please setenv G4NEUTRONHPDATA to poin << 301          throw G4HadronicException(__FILE__, __LINE__, "Please setenv G4NEUTRONHPDATA to point to the neutron cross-section files.");
263     G4String baseName = G4FindDataDir("G4NEUTR << 302       G4String baseName = G4FindDataDir( "G4NEUTRONHPDATA" );
264                                                << 303 
265     dirName = baseName + "/ThermalScattering"; << 304       dirName = baseName + "/ThermalScattering";
266                                                << 305 
267     G4String ndl_filename;                     << 306       G4String ndl_filename;
268     G4String full_name;                        << 307       G4String full_name;
269                                                << 308 
270     for (const auto& it : co_dic) {            << 309       for ( auto it = co_dic.cbegin() ; it != co_dic.cend() ; ++it )  
271       ndl_filename = it.first;                 << 310       {
272       G4int ts_ID = it.second;                 << 311          ndl_filename = it->first;
273                                                << 312          G4int ts_ID = it->second;
274       // Coherent                              << 313 
275       full_name = dirName + "/Coherent/CrossSe << 314          // Coherent
276       auto coh_amapTemp_EnergyCross = readData << 315          full_name = dirName + "/Coherent/CrossSection/" + ndl_filename; 
277       coherent->insert(std::pair<G4int, std::m << 316          auto  coh_amapTemp_EnergyCross = readData( full_name );
278         ts_ID, coh_amapTemp_EnergyCross));     << 317          coherent->insert ( std::pair < G4int , std::map< G4double , G4ParticleHPVector* >* > ( ts_ID , coh_amapTemp_EnergyCross ) );
279                                                << 318 
280       // Incoherent                            << 319          // Incoherent
281       full_name = dirName + "/Incoherent/Cross << 320          full_name = dirName + "/Incoherent/CrossSection/" + ndl_filename; 
282       auto incoh_amapTemp_EnergyCross = readDa << 321          auto  incoh_amapTemp_EnergyCross = readData( full_name );
283       incoherent->insert(std::pair<G4int, std: << 322          incoherent->insert ( std::pair < G4int , std::map< G4double , G4ParticleHPVector* >* > ( ts_ID , incoh_amapTemp_EnergyCross ) );
284         ts_ID, incoh_amapTemp_EnergyCross));   << 323 
285                                                << 324          // Inelastic
286       // Inelastic                             << 325          full_name = dirName + "/Inelastic/CrossSection/" + ndl_filename; 
287       full_name = dirName + "/Inelastic/CrossS << 326          auto  inela_amapTemp_EnergyCross = readData( full_name );
288       auto inela_amapTemp_EnergyCross = readDa << 327          inelastic->insert ( std::pair < G4int , std::map< G4double , G4ParticleHPVector* >* > ( ts_ID , inela_amapTemp_EnergyCross ) );
289       inelastic->insert(std::pair<G4int, std:: << 328       }
290         ts_ID, inela_amapTemp_EnergyCross));   << 329       hpmanager->RegisterThermalScatteringCoherentCrossSections( coherent );
291     }                                          << 330       hpmanager->RegisterThermalScatteringIncoherentCrossSections( incoherent );
292     hpmanager->RegisterThermalScatteringCohere << 331       hpmanager->RegisterThermalScatteringInelasticCrossSections( inelastic );
293     hpmanager->RegisterThermalScatteringIncohe << 332    } 
294     hpmanager->RegisterThermalScatteringInelas << 333 }
295   }                                            << 334 
296 }                                              << 335 
297                                                << 336 std::map< G4double , G4ParticleHPVector* >*
298 std::map<G4double, G4ParticleHPVector*>*       << 337 G4ParticleHPThermalScatteringData::readData ( G4String full_name ) 
299 G4ParticleHPThermalScatteringData::readData(co << 338 {
300 {                                              << 339    auto  aData = new std::map< G4double , G4ParticleHPVector* >; 
301   auto aData = new std::map<G4double, G4Partic << 340    
302                                                << 341    std::istringstream theChannel;
303   std::istringstream theChannel;               << 342    G4ParticleHPManager::GetInstance()->GetDataStream(full_name,theChannel);
304   G4ParticleHPManager::GetInstance()->GetDataS << 
305                                                << 
306   G4int dummy;                                 << 
307   while (theChannel >> dummy)  // MF // Loop c << 
308   {                                            << 
309     theChannel >> dummy;  // MT                << 
310     G4double temp;                             << 
311     theChannel >> temp;                        << 
312     auto anEnergyCross = new G4ParticleHPVecto << 
313     G4int nData;                               << 
314     theChannel >> nData;                       << 
315     anEnergyCross->Init(theChannel, nData, eV, << 
316     aData->insert(std::pair<G4double, G4Partic << 
317   }                                            << 
318                                                << 
319   return aData;                                << 
320 }                                              << 
321                                                << 
322 void G4ParticleHPThermalScatteringData::DumpPh << 
323 {                                              << 
324   if (&aP != G4Neutron::Neutron())             << 
325     throw G4HadronicException(__FILE__, __LINE << 
326                               "Attempt to use  << 
327 }                                              << 
328                                                << 
329 G4double G4ParticleHPThermalScatteringData::Ge << 
330                                                << 
331                                                << 
332 {                                              << 
333   G4double result = 0;                         << 
334                                                << 
335   G4int ts_id = getTS_ID(aM, anE);             << 
336                                                << 
337   if (ts_id == -1) return result;              << 
338                                                << 
339   G4double aT = aM->GetTemperature();          << 
340                                                << 
341   G4double Xcoh = GetX(aP, aT, coherent->find( << 
342   G4double Xincoh = GetX(aP, aT, incoherent->f << 
343   G4double Xinela = GetX(aP, aT, inelastic->fi << 
344                                                << 
345   result = Xcoh + Xincoh + Xinela;             << 
346                                                << 
347   return result;                               << 
348 }                                              << 
349                                                << 
350 G4double G4ParticleHPThermalScatteringData::Ge << 
351                                                << 
352                                                << 
353 {                                              << 
354   G4double result = 0;                         << 
355   G4int ts_id = getTS_ID(aM, anE);             << 
356   G4double aT = aM->GetTemperature();          << 
357   result = GetX(aP, aT, inelastic->find(ts_id) << 
358   return result;                               << 
359 }                                              << 
360                                                << 
361 G4double G4ParticleHPThermalScatteringData::Ge << 
362                                                << 
363                                                << 
364 {                                              << 
365   G4double result = 0;                         << 
366   G4int ts_id = getTS_ID(aM, anE);             << 
367   G4double aT = aM->GetTemperature();          << 
368   result = GetX(aP, aT, coherent->find(ts_id)- << 
369   return result;                               << 
370 }                                              << 
371                                                << 
372 G4double G4ParticleHPThermalScatteringData::Ge << 
373                                                << 
374                                                << 
375 {                                              << 
376   G4double result = 0;                         << 
377   G4int ts_id = getTS_ID(aM, anE);             << 
378   G4double aT = aM->GetTemperature();          << 
379   result = GetX(aP, aT, incoherent->find(ts_id << 
380   return result;                               << 
381 }                                              << 
382                                                << 
383 G4int G4ParticleHPThermalScatteringData::getTS << 
384                                                << 
385 {                                              << 
386   G4int result = -1;                           << 
387   if (dic.find(std::pair<const G4Material*, co << 
388       != dic.end())                            << 
389     return dic.find(std::pair<const G4Material << 
390       ->second;                                << 
391   if (dic.find(std::pair<const G4Material*, co << 
392     return dic.find(std::pair<const G4Material << 
393   return result;                               << 
394 }                                              << 
395                                                << 
396 G4double G4ParticleHPThermalScatteringData::   << 
397 GetX(const G4DynamicParticle* aP, G4double aT, << 
398      std::map<G4double, G4ParticleHPVector*>*  << 
399 {                                              << 
400   G4double result = 0;                         << 
401   if (amapTemp_EnergyCross->empty()) return re << 
402                                                << 
403   G4double eKinetic = aP->GetKineticEnergy();  << 
404                                                << 
405   if (amapTemp_EnergyCross->size() == 1) {     << 
406     if (std::fabs(aT - amapTemp_EnergyCross->c << 
407         > 0.1)                                 << 
408     {                                          << 
409       G4cout                                   << 
410         << "G4ParticleHPThermalScatteringData: << 
411         << "K) is different more than 10% from << 
412         << amapTemp_EnergyCross->begin()->firs << 
413     }                                          << 
414     result = amapTemp_EnergyCross->begin()->se << 
415     return result;                             << 
416   }                                            << 
417                                                << 
418   auto it = amapTemp_EnergyCross->cbegin();    << 
419   for (it = amapTemp_EnergyCross->cbegin(); it << 
420     if (aT < it->first) break;                 << 
421   }                                            << 
422   if (it == amapTemp_EnergyCross->cbegin()) {  << 
423     ++it;  // lower than the first             << 
424   }                                            << 
425   else if (it == amapTemp_EnergyCross->cend()) << 
426     --it;  // upper than the last              << 
427   }                                            << 
428                                                << 
429   G4double TH = it->first;                     << 
430   G4double XH = it->second->GetXsec(eKinetic); << 
431                                                << 
432   if (it != amapTemp_EnergyCross->cbegin()) -- << 
433   G4double TL = it->first;                     << 
434   G4double XL = it->second->GetXsec(eKinetic); << 
435                                                << 
436   if (TH == TL) throw G4HadronicException(__FI << 
437                                                << 
438   G4double T = aT;                             << 
439   G4double X = (XH - XL) / (TH - TL) * (T - TL << 
440   result = X;                                  << 
441                                                   343 
442   return result;                               << 344    G4int dummy; 
                                                   >> 345    while ( theChannel >> dummy )   // MF // Loop checking, 11.05.2015, T. Koi
                                                   >> 346    {
                                                   >> 347       theChannel >> dummy;   // MT
                                                   >> 348       G4double temp; 
                                                   >> 349       theChannel >> temp;   
                                                   >> 350       G4ParticleHPVector* anEnergyCross = new G4ParticleHPVector;
                                                   >> 351       G4int nData;
                                                   >> 352       theChannel >> nData;
                                                   >> 353       anEnergyCross->Init ( theChannel , nData , eV , barn );
                                                   >> 354       aData->insert ( std::pair < G4double , G4ParticleHPVector* > ( temp , anEnergyCross ) );
                                                   >> 355    }
                                                   >> 356 
                                                   >> 357    return aData;
                                                   >> 358 } 
                                                   >> 359 
                                                   >> 360 
                                                   >> 361 void G4ParticleHPThermalScatteringData::DumpPhysicsTable( const G4ParticleDefinition& aP )
                                                   >> 362 {
                                                   >> 363    if( &aP != G4Neutron::Neutron() ) 
                                                   >> 364      throw G4HadronicException(__FILE__, __LINE__, "Attempt to use NeutronHP data for particles other than neutrons!!!");  
                                                   >> 365 }
                                                   >> 366 
                                                   >> 367 
                                                   >> 368 G4double G4ParticleHPThermalScatteringData::GetCrossSection( const G4DynamicParticle* aP , const G4Element*anE , const G4Material* aM )
                                                   >> 369 {
                                                   >> 370    G4double result = 0;
                                                   >> 371    
                                                   >> 372    G4int ts_id =getTS_ID( aM , anE );
                                                   >> 373 
                                                   >> 374    if ( ts_id == -1 ) return result;
                                                   >> 375 
                                                   >> 376    G4double aT = aM->GetTemperature();
                                                   >> 377 
                                                   >> 378    G4double Xcoh = GetX ( aP , aT , coherent->find(ts_id)->second );
                                                   >> 379    G4double Xincoh = GetX ( aP , aT , incoherent->find(ts_id)->second );
                                                   >> 380    G4double Xinela = GetX ( aP , aT , inelastic->find(ts_id)->second );
                                                   >> 381 
                                                   >> 382    result = Xcoh + Xincoh + Xinela;
                                                   >> 383 
                                                   >> 384    return result;
                                                   >> 385 }
                                                   >> 386 
                                                   >> 387 
                                                   >> 388 G4double G4ParticleHPThermalScatteringData::GetInelasticCrossSection( const G4DynamicParticle* aP , const G4Element*anE , const G4Material* aM )
                                                   >> 389 {
                                                   >> 390    G4double result = 0;
                                                   >> 391    G4int ts_id = getTS_ID( aM , anE );
                                                   >> 392    G4double aT = aM->GetTemperature();
                                                   >> 393    result = GetX ( aP , aT , inelastic->find( ts_id )->second );
                                                   >> 394    return result;
443 }                                                 395 }
444                                                   396 
445 void G4ParticleHPThermalScatteringData::AddUse << 397 G4double G4ParticleHPThermalScatteringData::GetCoherentCrossSection( const G4DynamicParticle* aP , const G4Element*anE , const G4Material* aM )
446                                                << 398 {
                                                   >> 399    G4double result = 0;
                                                   >> 400    G4int ts_id = getTS_ID( aM , anE );
                                                   >> 401    G4double aT = aM->GetTemperature();
                                                   >> 402    result = GetX ( aP , aT , coherent->find( ts_id )->second );
                                                   >> 403    return result;
                                                   >> 404 }
                                                   >> 405 
                                                   >> 406 G4double G4ParticleHPThermalScatteringData::GetIncoherentCrossSection( const G4DynamicParticle* aP , const G4Element*anE , const G4Material* aM )
                                                   >> 407 {
                                                   >> 408    G4double result = 0;
                                                   >> 409    G4int ts_id = getTS_ID( aM , anE );
                                                   >> 410    G4double aT = aM->GetTemperature();
                                                   >> 411    result = GetX ( aP , aT , incoherent->find( ts_id )->second );
                                                   >> 412    return result;
                                                   >> 413 }
                                                   >> 414 
                                                   >> 415 G4int G4ParticleHPThermalScatteringData::getTS_ID ( const G4Material* material , const G4Element* element )
                                                   >> 416 {
                                                   >> 417    G4int result = -1;
                                                   >> 418    if ( dic.find( std::pair < const G4Material* , const G4Element* > ( (G4Material*)NULL , element ) ) != dic.end() ) 
                                                   >> 419       return dic.find( std::pair < const G4Material* , const G4Element* > ( (G4Material*)NULL , element ) )->second; 
                                                   >> 420    if ( dic.find( std::pair < const G4Material* , const G4Element* > ( material , element ) ) != dic.end() ) 
                                                   >> 421       return dic.find( std::pair < const G4Material* , const G4Element* > ( material , element ) )->second; 
                                                   >> 422    return result; 
                                                   >> 423 }
                                                   >> 424 
                                                   >> 425 G4double G4ParticleHPThermalScatteringData::GetX ( const G4DynamicParticle* aP, G4double aT , std::map < G4double , G4ParticleHPVector* >* amapTemp_EnergyCross )
                                                   >> 426 {
                                                   >> 427    G4double result = 0;
                                                   >> 428    if ( amapTemp_EnergyCross->size() == 0 ) return result;
                                                   >> 429 
                                                   >> 430    G4double eKinetic = aP->GetKineticEnergy();
                                                   >> 431 
                                                   >> 432    if ( amapTemp_EnergyCross->size() == 1 ) { 
                                                   >> 433       if ( std::fabs ( aT - amapTemp_EnergyCross->cbegin()->first ) / amapTemp_EnergyCross->begin()->first > 0.1 ) {
                                                   >> 434          G4cout << "G4ParticleHPThermalScatteringData:: The temperature of material (" 
                                                   >> 435                 << aT/kelvin << "K) is different more than 10% from temperature of thermal scattering file expected (" 
                                                   >> 436                 << amapTemp_EnergyCross->begin()->first << "K). Result may not be reliable."
                                                   >> 437          << G4endl;
                                                   >> 438       }
                                                   >> 439       result = amapTemp_EnergyCross->begin()->second->GetXsec ( eKinetic ); 
                                                   >> 440       return result;
                                                   >> 441    }
                                                   >> 442 
                                                   >> 443    auto it = amapTemp_EnergyCross->cbegin();
                                                   >> 444    for (it=amapTemp_EnergyCross->cbegin(); it!=amapTemp_EnergyCross->cend(); ++it)
                                                   >> 445    {
                                                   >> 446       if ( aT < it->first ) break;
                                                   >> 447    } 
                                                   >> 448    if ( it == amapTemp_EnergyCross->cbegin() ) {
                                                   >> 449       ++it;  // lower than the first
                                                   >> 450    } else if ( it == amapTemp_EnergyCross->cend() ) {
                                                   >> 451       --it;  // upper than the last
                                                   >> 452    }
                                                   >> 453 
                                                   >> 454    G4double TH = it->first;
                                                   >> 455    G4double XH = it->second->GetXsec ( eKinetic ); 
                                                   >> 456 
                                                   >> 457    if ( it != amapTemp_EnergyCross->cbegin() ) --it;
                                                   >> 458    G4double TL = it->first;
                                                   >> 459    G4double XL = it->second->GetXsec ( eKinetic ); 
                                                   >> 460 
                                                   >> 461    if ( TH == TL )  
                                                   >> 462       throw G4HadronicException(__FILE__, __LINE__, "Thermal Scattering Data Error!");  
                                                   >> 463 
                                                   >> 464    G4double T = aT;
                                                   >> 465    G4double X = ( XH - XL ) / ( TH - TL ) * ( T - TL ) + XL;
                                                   >> 466    result = X;
                                                   >> 467   
                                                   >> 468    return result;
                                                   >> 469 }
                                                   >> 470 
                                                   >> 471 
                                                   >> 472 void G4ParticleHPThermalScatteringData::AddUserThermalScatteringFile( G4String nameG4Element , G4String filename )
447 {                                                 473 {
448   names->AddThermalElement(nameG4Element, file << 474    names->AddThermalElement( nameG4Element , filename );
449 }                                                 475 }
450                                                   476 
451 void G4ParticleHPThermalScatteringData::CrossS    477 void G4ParticleHPThermalScatteringData::CrossSectionDescription(std::ostream& outFile) const
452 {                                                 478 {
453   outFile << "High Precision cross data based  << 479     outFile << "High Precision cross data based on thermal scattering data in evaluated nuclear data libraries for neutrons below 5eV on specific materials\n" ;
454              "libraries for neutrons below 5eV << 
455 }                                                 480 }
456                                                   481