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 // Class Description 26 // Class Description 27 // Manager of NetronHP 27 // Manager of NetronHP 28 // << 28 // 29 // 121031 First implementation done by T. Koi 29 // 121031 First implementation done by T. Koi (SLAC/PPA) 30 // P. Arce, June-2014 Conversion neutron_hp to 30 // P. Arce, June-2014 Conversion neutron_hp to particle_hp 31 // V. Ivanchenko, July-2023 Basic revision of << 32 // 31 // 33 #include "G4ParticleHPManager.hh" << 34 << 35 #include "G4Exception.hh" << 36 #include "G4HadronicException.hh" << 37 #include "G4ParticleHPMessenger.hh" << 38 #include "G4ParticleDefinition.hh" << 39 #include "G4HadronicParameters.hh" << 40 #include "G4ParticleHPThreadLocalManager.hh" << 41 #include "G4SystemOfUnits.hh" << 42 << 43 #include <zlib.h> 32 #include <zlib.h> 44 #include <fstream> 33 #include <fstream> 45 34 >> 35 #include "G4ParticleHPManager.hh" >> 36 #include "G4ParticleHPThreadLocalManager.hh" >> 37 #include "G4ParticleHPMessenger.hh" >> 38 #include "G4HadronicException.hh" >> 39 #include "G4Exception.hh" >> 40 46 G4ParticleHPManager* G4ParticleHPManager::inst 41 G4ParticleHPManager* G4ParticleHPManager::instance = nullptr; 47 42 48 G4ParticleHPManager::G4ParticleHPManager() 43 G4ParticleHPManager::G4ParticleHPManager() 49 : theMinEnergyDBRC(0.1 * CLHEP::eV), << 44 : verboseLevel(1) 50 theMaxEnergyDBRC(210. * CLHEP::eV), << 45 ,USE_ONLY_PHOTONEVAPORATION(false) 51 theMaxEnergyDoppler(30. * CLHEP::keV) << 46 ,SKIP_MISSING_ISOTOPES(false) 52 { << 47 ,NEGLECT_DOPPLER(false) 53 messenger = new G4ParticleHPMessenger(this); << 48 ,DO_NOT_ADJUST_FINAL_STATE(false) 54 verboseLevel = G4HadronicParameters::Instanc << 49 ,PRODUCE_FISSION_FRAGMENTS(false) 55 const char* ss = G4FindDataDir("NeutronHPNam << 50 ,USE_WENDT_FISSION_MODEL(false) 56 if (nullptr != ss) { CHECK_HP_NAMES = true; << 51 ,USE_NRESP71_MODEL(false) 57 ss = G4FindDataDir("G4PHP_DO_NOT_CHECK_DIFF_ << 52 ,theElasticCrossSections(nullptr) 58 if (nullptr != ss) { PHP_CHECK = false; } << 53 ,theCaptureCrossSections(nullptr) 59 ss = G4FindDataDir("G4PHP_MULTIPLICITY_METHO << 54 ,theFissionCrossSections(nullptr) 60 if (nullptr != ss && "BetweenInts" == G4Stri << 55 ,theElasticFSs(nullptr) 61 ss = G4FindDataDir("G4ParticleHPDebug"); << 56 ,theCaptureFSs(nullptr) 62 if (nullptr != ss) { DEBUG = true; } << 57 ,theFissionFSs(nullptr) 63 << 58 ,theTSCoherentCrossSections(nullptr) 64 // identify and check data path once - it sh << 59 ,theTSIncoherentCrossSections(nullptr) 65 const char* nch = G4FindDataDir("G4NEUTRONHP << 60 ,theTSInelasticCrossSections(nullptr) 66 if (nullptr == nch) { << 61 ,theTSCoherentFinalStates(nullptr) 67 G4Exception("G4ParticleHPManager::G4Partic << 62 ,theTSIncoherentFinalStates(nullptr) 68 FatalException, "G4NEUTRONXSDA << 63 ,theTSInelasticFinalStates(nullptr) 69 } else { << 64 { 70 fDataPath[0] = G4String(nch); << 65 messenger = new G4ParticleHPMessenger( this ); 71 } << 72 // path may be defined by two environment va << 73 // it is not mandatory to access PHP data - << 74 const char* ttp = G4FindDataDir("G4PARTICLEH << 75 G4String tendl = (nullptr == ttp) ? G4String << 76 const char* ssp = G4FindDataDir("G4PROTONHPD << 77 fDataPath[1] = (nullptr == ssp) ? tendl + "/ << 78 << 79 ssp = G4FindDataDir("G4DEUTERONHPDATA"); << 80 fDataPath[2] = (nullptr == ssp) ? tendl + "/ << 81 << 82 ssp = G4FindDataDir("G4TRITONHPDATA"); << 83 fDataPath[3] = (nullptr == ssp) ? tendl + "/ << 84 << 85 ssp = G4FindDataDir("G4HE3HPDATA"); << 86 fDataPath[4] = (nullptr == ssp) ? tendl + "/ << 87 << 88 ssp = G4FindDataDir("G4ALPHAHPDATA"); << 89 fDataPath[5] = (nullptr == ssp) ? tendl + "/ << 90 } 66 } 91 67 92 G4ParticleHPManager::~G4ParticleHPManager() 68 G4ParticleHPManager::~G4ParticleHPManager() 93 { 69 { 94 delete messenger; << 70 delete messenger; 95 } 71 } 96 72 97 G4ParticleHPManager* G4ParticleHPManager::GetI 73 G4ParticleHPManager* G4ParticleHPManager::GetInstance() 98 { 74 { 99 static G4ParticleHPManager manager; 75 static G4ParticleHPManager manager; 100 if (instance == nullptr) { << 76 if (instance == nullptr) >> 77 { 101 instance = &manager; 78 instance = &manager; 102 } 79 } 103 return instance; 80 return instance; 104 } 81 } 105 82 106 G4int G4ParticleHPManager::GetPHPIndex(const G << 107 G4int pdg = part->GetPDGEncoding(); << 108 G4int idx; << 109 if (pdg == 2112) { idx = 0; } << 110 else if (pdg == 2212) { idx = 1; } << 111 else if (pdg == 1000010020) { idx = 2; } << 112 else if (pdg == 1000010030) { idx = 3; } << 113 else if (pdg == 1000020030) { idx = 4; } << 114 else if (pdg == 1000020040) { idx = 5; } << 115 else { << 116 idx = 0; << 117 G4ExceptionDescription ed; << 118 ed << "Particle " << part->GetParticleName << 119 << " cannot be handled by the ParticleH << 120 G4Exception("G4ParticleHPManager::G4Partic << 121 FatalException, ed, ""); << 122 } << 123 return idx; << 124 } << 125 << 126 const G4String& << 127 G4ParticleHPManager::GetParticleHPPath(const G << 128 return fDataPath[GetPHPIndex(part)]; << 129 } << 130 << 131 void G4ParticleHPManager::OpenReactionWhiteBoa 83 void G4ParticleHPManager::OpenReactionWhiteBoard() 132 { 84 { 133 G4ParticleHPThreadLocalManager::GetInstance( << 85 G4ParticleHPThreadLocalManager::GetInstance()->OpenReactionWhiteBoard(); 134 } 86 } 135 87 136 G4ParticleHPReactionWhiteBoard* G4ParticleHPMa 88 G4ParticleHPReactionWhiteBoard* G4ParticleHPManager::GetReactionWhiteBoard() 137 { 89 { 138 return G4ParticleHPThreadLocalManager::GetIn << 90 return G4ParticleHPThreadLocalManager::GetInstance()->GetReactionWhiteBoard(); 139 } 91 } 140 92 141 void G4ParticleHPManager::CloseReactionWhiteBo 93 void G4ParticleHPManager::CloseReactionWhiteBoard() 142 { 94 { 143 G4ParticleHPThreadLocalManager::GetInstance( << 95 G4ParticleHPThreadLocalManager::GetInstance()->CloseReactionWhiteBoard(); 144 } 96 } 145 97 146 void G4ParticleHPManager::GetDataStream(const << 98 void G4ParticleHPManager::GetDataStream( G4String filename , std::istringstream& iss ) 147 { 99 { 148 G4String* data = nullptr; << 100 G4String* data=0; 149 G4String compfilename(filename); << 101 G4String compfilename(filename); 150 compfilename += ".z"; << 102 compfilename += ".z"; 151 auto in = new std::ifstream(compfilename, st << 103 std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate ); 152 if (in->good()) { << 104 if ( in->good() ) 153 // Use the compressed file << 105 { 154 std::streamoff file_size = in->tellg(); << 106 // Use the compressed file 155 in->seekg(0, std::ios::beg); << 107 std::streamoff file_size = in->tellg(); 156 auto compdata = new Bytef[file_size]; << 108 in->seekg( 0 , std::ios::beg ); 157 << 109 Bytef* compdata = new Bytef[ file_size ]; 158 while (*in) { // Loop checking, 11.05.201 << 110 159 in->read((char*)compdata, file_size); << 111 while ( *in ) 160 } << 112 { // Loop checking, 11.05.2015, T. Koi 161 << 113 in->read( (char*)compdata , file_size ); 162 auto complen = (uLongf)(file_size * 4); << 163 auto uncompdata = new Bytef[complen]; << 164 << 165 while (Z_OK != uncompress(uncompdata, &com << 166 { // Loop checking, 11.05.2015, T. Koi << 167 delete[] uncompdata; << 168 complen *= 2; << 169 uncompdata = new Bytef[complen]; << 170 } << 171 delete[] compdata; << 172 // Now "complen" has uncomplessed size << 173 data = new G4String((char*)uncompdata, (G4 << 174 delete[] uncompdata; << 175 } << 176 else { << 177 // Use regular text file << 178 std::ifstream thefData(filename, std::ios: << 179 if (thefData.good()) { << 180 std::streamoff file_size = thefData.tell << 181 thefData.seekg(0, std::ios::beg); << 182 auto filedata = new char[file_size]; << 183 while (thefData) { // Loop checking, 11 << 184 thefData.read(filedata, file_size); << 185 } 114 } 186 thefData.close(); << 115 187 data = new G4String(filedata, file_size) << 116 uLongf complen = (uLongf) ( file_size*4 ); 188 delete[] filedata; << 117 Bytef* uncompdata = new Bytef[complen]; 189 } << 118 190 else { << 119 while ( Z_OK != uncompress ( uncompdata , &complen , compdata , file_size ) ) 191 // found no data file << 120 { // Loop checking, 11.05.2015, T. Koi 192 // set error bit to the stream << 121 delete[] uncompdata; 193 iss.setstate(std::ios::badbit); << 122 complen *= 2; 194 } << 123 uncompdata = new Bytef[complen]; 195 } << 124 } 196 if (data != nullptr) { << 125 delete [] compdata; 197 iss.str(*data); << 126 // Now "complen" has uncomplessed size 198 G4String id; << 127 data = new G4String ( (char*)uncompdata , (G4long)complen ); 199 iss >> id; << 128 delete [] uncompdata; 200 if (id == "G4NDL") { << 129 } 201 // Register information of file << 130 else 202 G4String source; << 131 { 203 iss >> source; << 132 // Use regular text file 204 register_data_file(filename, source); << 133 std::ifstream thefData( filename , std::ios::in | std::ios::ate ); 205 } << 134 if ( thefData.good() ) 206 else { << 135 { 207 iss.seekg(0, std::ios::beg); << 136 std::streamoff file_size = thefData.tellg(); 208 } << 137 thefData.seekg( 0 , std::ios::beg ); 209 } << 138 char* filedata = new char[ file_size ]; 210 in->close(); << 139 while ( thefData ) 211 delete in; << 140 { // Loop checking, 11.05.2015, T. Koi 212 delete data; << 141 thefData.read( filedata , file_size ); >> 142 } >> 143 thefData.close(); >> 144 data = new G4String ( filedata , file_size ); >> 145 delete [] filedata; >> 146 } >> 147 else >> 148 { >> 149 // found no data file >> 150 // set error bit to the stream >> 151 iss.setstate( std::ios::badbit ); >> 152 } >> 153 } >> 154 if ( data != 0 ) >> 155 { >> 156 iss.str(*data); >> 157 G4String id; >> 158 iss >> id; >> 159 if ( id == "G4NDL" ) >> 160 { >> 161 //Register information of file >> 162 G4String source; >> 163 iss >> source; >> 164 register_data_file(filename,source); >> 165 } >> 166 else >> 167 { >> 168 iss.seekg( 0 , std::ios::beg ); >> 169 } >> 170 } >> 171 in->close(); delete in; >> 172 delete data; >> 173 } >> 174 >> 175 void G4ParticleHPManager::GetDataStream2( G4String filename , std::istringstream& iss ) >> 176 { >> 177 // Checking existance of data file >> 178 >> 179 G4String compfilename(filename); >> 180 compfilename += ".z"; >> 181 std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate ); >> 182 if ( in->good() ) >> 183 { >> 184 // Compressed file is exist >> 185 in->close(); >> 186 } >> 187 else >> 188 { >> 189 std::ifstream thefData( filename , std::ios::in | std::ios::ate ); >> 190 if ( thefData.good() ) >> 191 { >> 192 // Regular text file is exist >> 193 thefData.close(); >> 194 } >> 195 else >> 196 { >> 197 // found no data file >> 198 // set error bit to the stream >> 199 iss.setstate( std::ios::badbit ); >> 200 } >> 201 } >> 202 delete in; 213 } 203 } 214 204 215 void G4ParticleHPManager::GetDataStream2(const << 205 void G4ParticleHPManager::SetVerboseLevel( G4int newValue ) 216 { 206 { 217 // Checking existance of data file << 207 G4cout << "You are setting a new verbose level for Particle HP package." << G4endl; >> 208 G4cout << "the new value will be used in whole of the Particle HP package, i.e., models and cross sections for Capture, Elastic, Fission and Inelastic interaction." << G4endl; >> 209 verboseLevel = newValue; >> 210 } 218 211 219 G4String compfilename(filename); << 212 void G4ParticleHPManager::register_data_file(G4String filename, G4String source) 220 compfilename += ".z"; << 213 { 221 auto in = new std::ifstream(compfilename, st << 214 mDataEvaluation.insert( std::pair < G4String , G4String > ( filename , source ) ); 222 if (in->good()) { << 223 // Compressed file is exist << 224 in->close(); << 225 } << 226 else { << 227 std::ifstream thefData(filename, std::ios: << 228 if (thefData.good()) { << 229 // Regular text file is exist << 230 thefData.close(); << 231 } << 232 else { << 233 // found no data file << 234 // set error bit to the stream << 235 iss.setstate(std::ios::badbit); << 236 } << 237 } << 238 delete in; << 239 } 215 } 240 216 241 void G4ParticleHPManager::SetVerboseLevel(G4in << 217 void G4ParticleHPManager::DumpDataSource() 242 { 218 { 243 G4cout << "You are setting a new verbose lev << 219 244 G4cout << "the new value will be used in who << 220 G4cout << "Data source of this Partile HP calculation are " << G4endl; 245 "cross sections for Capture, Elast << 221 for (auto it = mDataEvaluation.cbegin(); it != mDataEvaluation.cend(); ++it) 246 << G4endl; << 222 { 247 verboseLevel = newValue; << 223 G4cout << it->first << " " << it->second << G4endl; >> 224 } >> 225 G4cout << G4endl; 248 } 226 } 249 227 250 void G4ParticleHPManager::register_data_file(c << 228 G4PhysicsTable* G4ParticleHPManager::GetInelasticCrossSections(const G4ParticleDefinition* particle ) 251 { 229 { 252 mDataEvaluation.insert(std::pair<G4String, G << 230 if ( theInelasticCrossSections.end() != theInelasticCrossSections.find( particle ) ) >> 231 return theInelasticCrossSections.find( particle )->second; >> 232 else >> 233 return nullptr; 253 } 234 } 254 235 255 void G4ParticleHPManager::DumpDataSource() con << 236 void G4ParticleHPManager::RegisterInelasticCrossSections( const G4ParticleDefinition* particle, G4PhysicsTable* val ) 256 { 237 { 257 G4cout << "Data source of this Partile HP ca << 238 theInelasticCrossSections.insert( std::pair<const G4ParticleDefinition* , G4PhysicsTable* >( particle , val ) ); 258 for (const auto& it : mDataEvaluation) { << 239 } 259 G4cout << it.first << " " << it.second << << 240 260 } << 241 std::vector<G4ParticleHPChannelList*>* G4ParticleHPManager::GetInelasticFinalStates(const G4ParticleDefinition* particle) 261 G4cout << G4endl; << 242 { >> 243 if ( theInelasticFSs.end() != theInelasticFSs.find( particle ) ) >> 244 return theInelasticFSs.find( particle )->second; >> 245 else >> 246 return nullptr; 262 } 247 } 263 248 >> 249 void G4ParticleHPManager::RegisterInelasticFinalStates( const G4ParticleDefinition* particle , std::vector<G4ParticleHPChannelList*>* val ) >> 250 { >> 251 theInelasticFSs.insert ( std::pair<const G4ParticleDefinition*,std::vector<G4ParticleHPChannelList*>*>( particle , val ) ); >> 252 } >> 253 >> 254 264 void G4ParticleHPManager::DumpSetting() 255 void G4ParticleHPManager::DumpSetting() 265 { 256 { 266 if(isPrinted) { return; } << 267 G4cout << G4endl 257 G4cout << G4endl 268 << "================================= 258 << "=======================================================" << G4endl 269 << "====== ParticleHP Physics P 259 << "====== ParticleHP Physics Parameters ========" << G4endl 270 << "================================= 260 << "=======================================================" << G4endl 271 << " Use only photo-evaporation << 261 << " UseOnlyPhotoEvaporation ? " << USE_ONLY_PHOTONEVAPORATION << G4endl 272 << " Skip missing isotopes << 262 << " SkipMissingIsotopes ? " << SKIP_MISSING_ISOTOPES << G4endl 273 << " Neglect Doppler << 263 << " NeglectDoppler ? " << NEGLECT_DOPPLER << G4endl 274 << " Do not adjust final state << 264 << " DoNotAdjustFinalState ? " << DO_NOT_ADJUST_FINAL_STATE << G4endl 275 << " Produce fission fragments << 265 << " ProduceFissionFragments ? " << PRODUCE_FISSION_FRAGMENTS << G4endl 276 << " Use WendtFissionModel << 266 << " UseWendtFissionModel ? " << USE_WENDT_FISSION_MODEL << G4endl 277 << " Use NRESP71Model << 267 << " UseNRESP71Model ? " << USE_NRESP71_MODEL << G4endl 278 << " Use DBRC << 268 << "=======================================================" << G4endl 279 << " PHP use Poisson << 269 << G4endl; 280 << " PHP check << 281 << " CHECK HP NAMES << 282 << " Enable DEBUG << 283 << " Use probability tables from << 284 << "================================= << 285 isPrinted = true; << 286 } 270 } 287 271