Geant4 Cross Reference |
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 // $Id: G4NeutronElasticXS.cc,v 1.12 2011-01-09 02:37:48 dennis Exp $ >> 27 // GEANT4 tag $Name: not supported by cvs2svn $ >> 28 // 26 // ------------------------------------------- 29 // ------------------------------------------------------------------- 27 // 30 // 28 // GEANT4 Class file 31 // GEANT4 Class file 29 // 32 // 30 // 33 // 31 // File name: G4NeutronElasticXS 34 // File name: G4NeutronElasticXS 32 // 35 // 33 // Author Ivantchenko, Geant4, 3-Aug-09 36 // Author Ivantchenko, Geant4, 3-Aug-09 34 // 37 // 35 // Modifications: 38 // Modifications: 36 // 39 // 37 40 >> 41 #include "G4HadronicException.hh" 38 #include "G4NeutronElasticXS.hh" 42 #include "G4NeutronElasticXS.hh" 39 #include "G4Neutron.hh" 43 #include "G4Neutron.hh" 40 #include "G4DynamicParticle.hh" 44 #include "G4DynamicParticle.hh" 41 #include "G4ElementTable.hh" << 42 #include "G4Material.hh" << 43 #include "G4Element.hh" 45 #include "G4Element.hh" >> 46 #include "G4ElementTable.hh" 44 #include "G4PhysicsLogVector.hh" 47 #include "G4PhysicsLogVector.hh" 45 #include "G4CrossSectionDataSetRegistry.hh" << 48 #include "G4PhysicsVector.hh" 46 #include "G4ComponentGGHadronNucleusXsc.hh" << 49 #include "G4GlauberGribovCrossSection.hh" 47 #include "G4HadronicParameters.hh" << 50 #include "G4HadronNucleonXsc.hh" 48 #include "Randomize.hh" << 51 #include "G4NistManager.hh" 49 #include "G4SystemOfUnits.hh" << 52 #include "G4Proton.hh" 50 #include "G4IsotopeList.hh" << 51 #include "G4AutoLock.hh" << 52 53 >> 54 #include <iostream> 53 #include <fstream> 55 #include <fstream> 54 #include <sstream> 56 #include <sstream> 55 57 56 G4PhysicsVector* G4NeutronElasticXS::data[] = << 58 using namespace std; 57 G4double G4NeutronElasticXS::coeff[] = {0.0}; << 58 G4String G4NeutronElasticXS::gDataDirectory = << 59 G4bool G4NeutronElasticXS::fLock = true; << 60 << 61 namespace << 62 { << 63 G4Mutex nElasticXSMutex = G4MUTEX_INITIALIZE << 64 } << 65 59 66 G4NeutronElasticXS::G4NeutronElasticXS() 60 G4NeutronElasticXS::G4NeutronElasticXS() 67 : G4VCrossSectionDataSet(Default_Name()), << 61 : G4VCrossSectionDataSet("G4NeutronElasticXS"), 68 neutron(G4Neutron::Neutron()) << 62 proton(G4Proton::Proton()), maxZ(92) 69 { 63 { 70 // verboseLevel = 0; 64 // verboseLevel = 0; 71 if (verboseLevel > 0){ << 65 if(verboseLevel > 0){ 72 G4cout << "G4NeutronElasticXS::G4NeutronE 66 G4cout << "G4NeutronElasticXS::G4NeutronElasticXS Initialise for Z < " 73 << MAXZEL << G4endl; << 67 << maxZ + 1 << G4endl; 74 } 68 } 75 ggXsection = << 69 data.resize(maxZ+1, 0); 76 G4CrossSectionDataSetRegistry::Instance()- << 70 coeff.resize(maxZ+1, 1.0); 77 if (ggXsection == nullptr) << 71 ggXsection = new G4GlauberGribovCrossSection(); 78 ggXsection = new G4ComponentGGHadronNucleu << 72 fNucleon = new G4HadronNucleonXsc(); 79 SetForAllAtomsAndEnergies(true); << 73 isInitialized = false; 80 FindDirectoryPath(); << 81 } 74 } 82 75 83 G4NeutronElasticXS::~G4NeutronElasticXS() 76 G4NeutronElasticXS::~G4NeutronElasticXS() 84 { 77 { 85 if (isFirst) { << 78 for(G4int i=0; i<=maxZ; ++i) { 86 for(G4int i=0; i<MAXZEL; ++i) { << 79 delete data[i]; 87 delete data[i]; << 88 data[i] = nullptr; << 89 } << 90 } 80 } 91 } 81 } 92 82 93 void G4NeutronElasticXS::CrossSectionDescripti << 94 { << 95 outFile << "G4NeutronElasticXS calculates th << 96 << "cross section on nuclei using da << 97 << "neutron database. These data ar << 98 << "the resonance region in order to << 99 << "For high energies Glauber-Gribiv << 100 } << 101 << 102 G4bool 83 G4bool 103 G4NeutronElasticXS::IsElementApplicable(const << 84 G4NeutronElasticXS::IsApplicable(const G4DynamicParticle*, 104 G4int, const G4Material*) << 85 const G4Element*) 105 { 86 { 106 return true; 87 return true; 107 } 88 } 108 89 109 G4bool G4NeutronElasticXS::IsIsoApplicable(con << 90 G4bool 110 G4i << 91 G4NeutronElasticXS::IsIsoApplicable(const G4DynamicParticle*, 111 con << 92 G4int /*ZZ*/, G4int /*AA*/) 112 { 93 { 113 return false; 94 return false; 114 } 95 } 115 96 116 G4double 97 G4double 117 G4NeutronElasticXS::GetElementCrossSection(con << 98 G4NeutronElasticXS::GetCrossSection(const G4DynamicParticle* aParticle, 118 G4int Z, const G4Material*) << 99 const G4Element* elm, G4double) 119 { 100 { 120 return ElementCrossSection(aParticle->GetKin << 101 G4double xs = 0.0; 121 aParticle->GetLogKineticEnergy(), Z << 102 G4double ekin = aParticle->GetKineticEnergy(); 122 } << 123 103 124 G4double << 104 G4int Z = G4int(elm->GetZ()); 125 G4NeutronElasticXS::ComputeCrossSectionPerElem << 105 if(Z < 1 || Z > maxZ) { return xs; } 126 const G4ParticleDefinition*, << 106 G4int Amean = G4int(G4NistManager::Instance()->GetAtomicMassAmu(Z)+0.5); 127 const G4Element* elm, << 107 G4PhysicsVector* pv = data[Z]; 128 const G4Material*) << 108 // G4cout << "G4NeutronElasticXS::GetCrossSection e= " << ekin << " Z= " << Z << G4endl; 129 { << 109 130 return ElementCrossSection(ekin, loge, elm-> << 110 // element was not initialised 131 } << 111 if(!pv) { 132 << 112 Initialise(Z); 133 G4double G4NeutronElasticXS::ElementCrossSecti << 113 pv = data[Z]; 134 { << 114 if(!pv) { return xs; } 135 G4int Z = (ZZ >= MAXZEL) ? MAXZEL - 1 : ZZ; << 115 } 136 auto pv = GetPhysicsVector(Z); << 116 >> 117 G4double e1 = pv->Energy(0); >> 118 if(ekin <= e1) { return (*pv)[0]; } >> 119 >> 120 G4int n = pv->GetVectorLength() - 1; >> 121 G4double e2 = pv->Energy(n); >> 122 >> 123 if(ekin <= e2) { >> 124 xs = pv->Value(ekin); >> 125 } else if(1 == Z) { >> 126 fNucleon->GetHadronNucleonXscPDG(aParticle, proton); >> 127 xs = coeff[1]*fNucleon->GetElasticHadronNucleonXsc(); >> 128 } else { >> 129 ggXsection->GetZandACrossSection(aParticle, Z, Amean); >> 130 xs = coeff[Z]*ggXsection->GetElasticGlauberGribovXsc(); >> 131 } 137 132 138 G4double xs = (ekin <= pv->GetMaxEnergy()) ? << 133 if(verboseLevel > 0){ 139 : coeff[Z]*ggXsection->GetElasticElementCr << 134 G4cout << "ekin= " << ekin << ", XSinel= " << xs << G4endl; 140 << 141 << 142 #ifdef G4VERBOSE << 143 if(verboseLevel > 1) { << 144 G4cout << "Z= " << Z << " Ekin(MeV)= " << << 145 << ", nElmXSel(b)= " << xs/CLHEP::barn << 146 << G4endl; << 147 } 135 } 148 #endif << 149 return xs; 136 return xs; 150 } 137 } 151 138 152 G4double << 153 G4NeutronElasticXS::ComputeIsoCrossSection(G4d << 154 const G4ParticleDefinition* << 155 G4int Z, G4int A, << 156 const G4Isotope*, const G4E << 157 const G4Material*) << 158 { << 159 return ElementCrossSection(ekin, loge, Z)*A/ << 160 } << 161 << 162 G4double << 163 G4NeutronElasticXS::GetIsoCrossSection(const G << 164 G4int Z, G4int A, << 165 const G4Isotope*, const G4Eleme << 166 const G4Material*) << 167 { << 168 return ElementCrossSection(aParticle->GetKin << 169 aParticle->GetLogKineticEnergy(), Z << 170 << 171 } << 172 << 173 const G4Isotope* G4NeutronElasticXS::SelectIso << 174 const G4Element* anElement, G4double, G4 << 175 { << 176 G4int nIso = (G4int)anElement->GetNumberOfIs << 177 const G4Isotope* iso = anElement->GetIsotope << 178 << 179 //G4cout << "SelectIsotope NIso= " << nIso < << 180 if(1 == nIso) { return iso; } << 181 << 182 const G4double* abundVector = anElement->Get << 183 G4double q = G4UniformRand(); << 184 G4double sum = 0.0; << 185 << 186 // isotope wise cross section not used << 187 for (G4int j=0; j<nIso; ++j) { << 188 sum += abundVector[j]; << 189 if(q <= sum) { << 190 iso = anElement->GetIsotope(j); << 191 break; << 192 } << 193 } << 194 return iso; << 195 } << 196 139 197 void 140 void 198 G4NeutronElasticXS::BuildPhysicsTable(const G4 141 G4NeutronElasticXS::BuildPhysicsTable(const G4ParticleDefinition& p) 199 { 142 { 200 if(verboseLevel > 0){ 143 if(verboseLevel > 0){ 201 G4cout << "G4NeutronElasticXS::BuildPhysic 144 G4cout << "G4NeutronElasticXS::BuildPhysicsTable for " 202 << p.GetParticleName() << G4endl; 145 << p.GetParticleName() << G4endl; 203 } 146 } 204 if(p.GetParticleName() != "neutron") { << 147 if(isInitialized || p.GetParticleName() != "neutron") { return; } 205 G4ExceptionDescription ed; << 148 isInitialized = true; 206 ed << p.GetParticleName() << " is a wrong << 207 << " only neutron is allowed"; << 208 G4Exception("G4NeutronElasticXS::BuildPhys << 209 FatalException, ed, ""); << 210 return; << 211 } << 212 if (fLock || isFirst) { << 213 G4AutoLock l(&nElasticXSMutex); << 214 if (fLock) { << 215 isFirst = true; << 216 fLock = false; << 217 FindDirectoryPath(); << 218 } << 219 149 220 // Access to elements << 150 // check environment variable 221 const G4ElementTable* table = G4Element::G << 151 // Build the complete string identifying the file with the data set 222 for ( auto & elm : *table ) { << 152 char* path = getenv("G4NEUTRONXSDATA"); 223 G4int Z = std::max( 1, std::min( elm->Ge << 153 if (!path){ 224 if ( nullptr == data[Z] ) { Initialise(Z << 154 G4cout << "G4NEUTRONXSDATA environment variable not set" << G4endl; >> 155 } >> 156 >> 157 G4DynamicParticle* dynParticle = >> 158 new G4DynamicParticle(G4Neutron::Neutron(),G4ThreeVector(1,0,0),1); >> 159 >> 160 // Access to elements >> 161 const G4ElementTable* theElmTable = G4Element::GetElementTable(); >> 162 size_t numOfElm = G4Element::GetNumberOfElements(); >> 163 if(numOfElm > 0) { >> 164 for(size_t i=0; i<numOfElm; ++i) { >> 165 G4int Z = G4int(((*theElmTable)[i])->GetZ()); >> 166 if(Z < 1) { Z = 1; } >> 167 else if(Z > maxZ) { Z = maxZ; } >> 168 //G4cout << "Z= " << Z << G4endl; >> 169 // Initialisation >> 170 if(!data[Z]) { Initialise(Z, dynParticle, path); } 225 } 171 } 226 l.unlock(); << 227 } 172 } >> 173 delete dynParticle; 228 } 174 } 229 175 230 const G4String& G4NeutronElasticXS::FindDirect << 176 void >> 177 G4NeutronElasticXS::DumpPhysicsTable(const G4ParticleDefinition&) 231 { 178 { 232 // build the complete string identifying the << 233 if (gDataDirectory.empty()) { << 234 std::ostringstream ost; << 235 ost << G4HadronicParameters::Instance()->G << 236 gDataDirectory = ost.str(); << 237 } << 238 return gDataDirectory; << 239 } 179 } 240 180 241 void G4NeutronElasticXS::InitialiseOnFly(G4int << 181 void >> 182 G4NeutronElasticXS::Initialise(G4int Z, G4DynamicParticle* dp, >> 183 const char* p) 242 { 184 { 243 G4AutoLock l(&nElasticXSMutex); << 185 if(data[Z]) { return; } 244 Initialise(Z); << 186 const char* path = p; 245 l.unlock(); << 187 if(!p) { 246 } << 188 // check environment variable >> 189 // Build the complete string identifying the file with the data set >> 190 path = getenv("G4NEUTRONXSDATA"); >> 191 if (!path) { >> 192 if(verboseLevel > 1) { >> 193 G4cout << "G4NEUTRONXSDATA environment variable not set" << G4endl; >> 194 } >> 195 return; >> 196 } >> 197 } >> 198 G4DynamicParticle* dynParticle = dp; >> 199 if(!dp) { >> 200 dynParticle = >> 201 new G4DynamicParticle(G4Neutron::Neutron(),G4ThreeVector(1,0,0),1); >> 202 } 247 203 248 void G4NeutronElasticXS::Initialise(G4int Z) << 204 G4int Amean = G4int(G4NistManager::Instance()->GetAtomicMassAmu(Z)+0.5); 249 { << 250 if(data[Z] != nullptr) { return; } << 251 205 252 // upload data from file 206 // upload data from file 253 data[Z] = new G4PhysicsLogVector(); 207 data[Z] = new G4PhysicsLogVector(); 254 208 255 std::ostringstream ost; 209 std::ostringstream ost; 256 ost << FindDirectoryPath() << Z ; << 210 ost << path << "/elast" << Z ; 257 std::ifstream filein(ost.str().c_str()); 211 std::ifstream filein(ost.str().c_str()); 258 if (!filein.is_open()) { << 212 if (!(filein)) { 259 G4ExceptionDescription ed; << 213 G4cout << ost.str() 260 ed << "Data file <" << ost.str().c_str() << 214 << " is not opened by G4NeutronElasticXS" << G4endl; 261 << "> is not opened!"; << 215 throw G4HadronicException(__FILE__, __LINE__, 262 G4Exception("G4NeutronElasticXS::Initialis << 216 "G4NeutronElasticXS: no data sets registered"); 263 FatalException, ed, "Check G4P << 264 return; 217 return; 265 } << 218 }else{ 266 if(verboseLevel > 1) { << 219 if(verboseLevel > 1) { 267 G4cout << "file " << ost.str() << 220 G4cout << "file " << ost.str() 268 << " is opened by G4NeutronElasticXS" << << 221 << " is opened by G4NeutronElasticXS" << G4endl; 269 } << 222 } 270 223 271 // retrieve data from DB << 224 // retrieve data from DB 272 if(!data[Z]->Retrieve(filein, true)) { << 225 data[Z]->Retrieve(filein, true); 273 G4ExceptionDescription ed; << 226 274 ed << "Data file <" << ost.str().c_str() << 227 // smooth transition 275 << "> is not retrieved!"; << 228 size_t n = data[Z]->GetVectorLength() - 1; 276 G4Exception("G4NeutronElasticXS::Initialis << 229 G4double emax = data[Z]->Energy(n); 277 FatalException, ed, "Check G4PARTICLEXSDAT << 230 G4double sig1 = (*data[Z])[n]; 278 return; << 231 dynParticle->SetKineticEnergy(emax); 279 } << 232 G4double sig2 = 0.0; 280 // smooth transition << 233 if(1 == Z) { 281 G4double sig1 = (*(data[Z]))[data[Z]->GetVe << 234 fNucleon->GetHadronNucleonXscPDG(dynParticle, proton); 282 G4double ehigh = data[Z]->GetMaxEnergy(); << 235 sig2 = fNucleon->GetElasticHadronNucleonXsc(); 283 G4double sig2 = ggXsection->GetElasticEleme << 236 } else { 284 ehigh, Z, aeff[ << 237 ggXsection->GetZandACrossSection(dynParticle, Z, Amean); 285 coeff[Z] = (sig2 > 0.) ? sig1/sig2 : 1.0; << 238 sig2 = ggXsection->GetElasticGlauberGribovXsc(); >> 239 } >> 240 if(sig2 > 0.) { coeff[Z] = sig1/sig2; } >> 241 } >> 242 if(!dp) { delete dynParticle; } 286 } 243 } 287 244