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: G4IonStoppingData.cc 76289 2013-11-08 13:07:00Z gcosmo $ >> 27 // 26 // =========================================== 28 // =========================================================================== 27 // GEANT4 class source file 29 // GEANT4 class source file 28 // 30 // 29 // Class: G4IonStoppingData 31 // Class: G4IonStoppingData 30 // 32 // 31 // Base class: G4VIonDEDXTable << 33 // Base class: G4VIonDEDXTable 32 // << 34 // 33 // Author: Anton Lechner (Anton. 35 // Author: Anton Lechner (Anton.Lechner@cern.ch) 34 // 36 // 35 // First implementation: 03. 11. 2009 37 // First implementation: 03. 11. 2009 36 // 38 // 37 // Modifications: 39 // Modifications: 38 // 25.10.2010 V.Ivanchenko fixed warnings repo 40 // 25.10.2010 V.Ivanchenko fixed warnings reported by the Coverity tool 39 // 25.10.2011: new scheme for G4Exception (mm 41 // 25.10.2011: new scheme for G4Exception (mma) 40 // 42 // 41 // 43 // 42 // Class description: Class which can read ion 44 // Class description: Class which can read ion stopping power data from 43 // $G4LEDATA/ion_stopping_d 45 // $G4LEDATA/ion_stopping_data 44 // 46 // 45 // Comments: 47 // Comments: 46 // 48 // 47 // =========================================== << 49 // =========================================================================== >> 50 // 48 51 49 #include "G4IonStoppingData.hh" << 52 #include <fstream> >> 53 #include <sstream> >> 54 #include <iomanip> 50 55 51 #include "G4PhysicalConstants.hh" << 56 #include "G4IonStoppingData.hh" 52 #include "G4PhysicsFreeVector.hh" << 53 #include "G4PhysicsVector.hh" 57 #include "G4PhysicsVector.hh" >> 58 #include "G4LPhysicsFreeVector.hh" >> 59 #include "G4PhysicalConstants.hh" 54 #include "G4SystemOfUnits.hh" 60 #include "G4SystemOfUnits.hh" 55 61 56 #include <fstream> << 57 #include <iomanip> << 58 #include <sstream> << 59 #include <utility> << 60 << 61 // ########################################### 62 // ######################################################################### 62 63 63 G4IonStoppingData::G4IonStoppingData(const G4S << 64 G4IonStoppingData::G4IonStoppingData(const G4String& leDirectory) : >> 65 subDir( leDirectory ) { >> 66 >> 67 } 64 68 65 // ########################################### 69 // ######################################################################### 66 70 67 G4IonStoppingData::~G4IonStoppingData() { Clea << 71 G4IonStoppingData::~G4IonStoppingData() { >> 72 >> 73 // ClearTable(); >> 74 } 68 75 69 // ########################################### 76 // ######################################################################### 70 77 71 G4bool G4IonStoppingData::IsApplicable(G4int a << 78 G4bool G4IonStoppingData::IsApplicable( 72 G4int atomicNumberElem // Atomic number of << 79 G4int atomicNumberIon, // Atomic number of ion 73 ) << 80 G4int atomicNumberElem // Atomic number of elemental material 74 { << 81 ) { >> 82 G4bool isApplicable = true; 75 G4IonDEDXKeyElem key = std::make_pair(atomic 83 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem); 76 84 77 auto iter = dedxMapElements.find(key); << 85 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key); >> 86 >> 87 if(iter == dedxMapElements.end()) isApplicable = false; 78 88 79 return iter != dedxMapElements.end(); << 89 return isApplicable; 80 } 90 } 81 91 82 // ########################################### 92 // ######################################################################### 83 93 84 G4bool G4IonStoppingData::IsApplicable(G4int a << 94 G4bool G4IonStoppingData::IsApplicable( 85 const G4String& matIdentifier // Name or ch << 95 G4int atomicNumberIon, // Atomic number of ion 86 ) << 96 const G4String& matIdentifier // Name or chemical formula of material 87 { << 97 ) { >> 98 G4bool isApplicable = true; 88 G4IonDEDXKeyMat key = std::make_pair(atomicN 99 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier); 89 100 90 auto iter = dedxMapMaterials.find(key); << 101 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key); 91 102 92 return iter != dedxMapMaterials.end(); << 103 if(iter == dedxMapMaterials.end()) isApplicable = false; >> 104 >> 105 return isApplicable; 93 } 106 } 94 107 95 // ########################################### 108 // ######################################################################### 96 109 97 G4PhysicsVector* G4IonStoppingData::GetPhysics << 110 G4PhysicsVector* G4IonStoppingData::GetPhysicsVector( 98 G4int atomicNumberElem // Atomic number of << 111 G4int atomicNumberIon, // Atomic number of ion 99 ) << 112 G4int atomicNumberElem // Atomic number of elemental material 100 { << 113 ) { >> 114 >> 115 G4PhysicsVector* physVector = 0; >> 116 101 G4IonDEDXKeyElem key = std::make_pair(atomic 117 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem); 102 118 103 auto iter = dedxMapElements.find(key); << 119 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key); 104 120 105 return (iter != dedxMapElements.end()) ? ite << 121 if(iter != dedxMapElements.end()) physVector = iter -> second; >> 122 >> 123 return physVector; 106 } 124 } 107 125 108 // ########################################### 126 // ######################################################################### 109 127 110 G4PhysicsVector* G4IonStoppingData::GetPhysics << 128 G4PhysicsVector* G4IonStoppingData::GetPhysicsVector( 111 const G4String& matIdentifier // Name or ch << 129 G4int atomicNumberIon, // Atomic number of ion 112 ) << 130 const G4String& matIdentifier // Name or chemical formula of material 113 { << 131 ) { >> 132 >> 133 G4PhysicsVector* physVector = 0; >> 134 114 G4IonDEDXKeyMat key = std::make_pair(atomicN 135 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier); 115 136 116 auto iter = dedxMapMaterials.find(key); << 137 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key); 117 138 118 return (iter != dedxMapMaterials.end()) ? it << 139 if(iter != dedxMapMaterials.end()) physVector = iter -> second; >> 140 >> 141 return physVector; 119 } 142 } 120 143 121 // ########################################### 144 // ######################################################################### 122 145 123 G4double G4IonStoppingData::GetDEDX(G4double k << 146 G4double G4IonStoppingData::GetDEDX( 124 G4int atomicNumberIon, // Atomic number of << 147 G4double kinEnergyPerNucleon, // Kinetic energy per nucleon 125 G4int atomicNumberElem // Atomic number of << 148 G4int atomicNumberIon, // Atomic number of ion 126 ) << 149 G4int atomicNumberElem // Atomic number of elemental material 127 { << 150 ) { >> 151 G4double dedx = 0; >> 152 128 G4IonDEDXKeyElem key = std::make_pair(atomic 153 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem); 129 154 130 auto iter = dedxMapElements.find(key); << 155 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key); 131 156 132 return (iter != dedxMapElements.end()) ? (it << 157 if( iter != dedxMapElements.end() ) { >> 158 G4PhysicsVector* physicsVector = iter -> second; >> 159 >> 160 G4bool b; >> 161 dedx = physicsVector -> GetValue( kinEnergyPerNucleon, b ); >> 162 } >> 163 >> 164 return dedx; 133 } 165 } 134 166 135 // ########################################### 167 // ######################################################################### 136 168 137 G4double G4IonStoppingData::GetDEDX(G4double k << 169 G4double G4IonStoppingData::GetDEDX( 138 G4int atomicNumberIon, // Atomic number of << 170 G4double kinEnergyPerNucleon, // Kinetic energy per nucleon 139 const G4String& matIdentifier // Name or ch << 171 G4int atomicNumberIon, // Atomic number of ion 140 ) << 172 const G4String& matIdentifier // Name or chemical formula of material 141 { << 173 ) { >> 174 G4double dedx = 0; >> 175 142 G4IonDEDXKeyMat key = std::make_pair(atomicN 176 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier); 143 177 144 auto iter = dedxMapMaterials.find(key); << 178 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key); >> 179 >> 180 if(iter != dedxMapMaterials.end()) { >> 181 G4PhysicsVector* physicsVector = iter -> second; 145 182 146 return (iter != dedxMapMaterials.end()) ? (i << 183 G4bool b; >> 184 dedx = physicsVector -> GetValue( kinEnergyPerNucleon, b ); >> 185 } >> 186 >> 187 return dedx; 147 } 188 } 148 189 149 // ########################################### 190 // ######################################################################### 150 191 151 G4bool G4IonStoppingData::AddPhysicsVector(G4P << 192 G4bool G4IonStoppingData::AddPhysicsVector( 152 G4int atomicNumberIon, // Atomic number of << 193 G4PhysicsVector* physicsVector, // Physics vector 153 const G4String& matIdentifier // Name of el << 194 G4int atomicNumberIon, // Atomic number of ion 154 ) << 195 const G4String& matIdentifier // Name of elemental material 155 { << 196 ) { 156 if (physicsVector == nullptr) { << 197 157 G4Exception("G4IonStoppingData::AddPhysics << 198 if(physicsVector == 0) { 158 "Pointer to vector is null-pointer."); << 199 159 return false; << 200 #ifdef G4VERBOSE >> 201 G4cerr << "G4IonStoppingData::AddPhysicsVector() Error: Pointer to vector" >> 202 << " is null-pointer." >> 203 << G4endl; >> 204 #endif >> 205 >> 206 return false; 160 } 207 } 161 208 162 if (matIdentifier.empty()) { << 209 if(matIdentifier.empty()) { 163 G4Exception("G4IonStoppingData::AddPhysics << 210 164 "Invalid name of the material."); << 211 #ifdef G4VERBOSE 165 return false; << 212 G4cerr << "G4IonStoppingData::AddPhysicsVector() Error: " >> 213 << "Cannot add physics vector. Invalid name." >> 214 << G4endl; >> 215 #endif >> 216 >> 217 return false; 166 } 218 } 167 219 168 if (atomicNumberIon <= 0) { << 220 if(atomicNumberIon <= 0) { 169 G4Exception("G4IonStoppingData::AddPhysics << 221 170 "Illegal atomic number."); << 222 #ifdef G4VERBOSE 171 return false; << 223 G4cerr << "G4IonStoppingData::AddPhysicsVector() Error: " >> 224 << "Cannot add physics vector. Illegal atomic number." >> 225 << G4endl; >> 226 #endif >> 227 >> 228 return false; 172 } 229 } 173 230 174 G4IonDEDXKeyMat mkey = std::make_pair(atomic 231 G4IonDEDXKeyMat mkey = std::make_pair(atomicNumberIon, matIdentifier); 175 232 176 if (dedxMapMaterials.count(mkey) == 1) { << 233 if(dedxMapMaterials.count(mkey) == 1) { 177 G4ExceptionDescription ed; << 234 178 ed << "Vector with Z1 = " << atomicNumberI << 235 #ifdef G4VERBOSE 179 << "already exists. Remove first before << 236 G4cerr << "G4IonStoppingData::AddPhysicsVector() Error: " 180 G4Exception("G4IonStoppingData::AddPhysics << 237 << "Vector with Z1 = " << atomicNumberIon << ", mat = " 181 return false; << 238 << matIdentifier >> 239 << "already exists. Remove first before replacing." >> 240 << G4endl; >> 241 #endif >> 242 >> 243 return false; 182 } 244 } 183 245 184 dedxMapMaterials[mkey] = physicsVector; 246 dedxMapMaterials[mkey] = physicsVector; 185 247 186 return true; 248 return true; 187 } 249 } 188 250 189 // ########################################### 251 // ######################################################################### 190 252 191 G4bool G4IonStoppingData::AddPhysicsVector(G4P << 253 G4bool G4IonStoppingData::AddPhysicsVector( 192 G4int atomicNumberIon, // Atomic number of << 254 G4PhysicsVector* physicsVector, // Physics vector 193 G4int atomicNumberElem // Atomic number of << 255 G4int atomicNumberIon, // Atomic number of ion 194 ) << 256 G4int atomicNumberElem // Atomic number of elemental material 195 { << 257 ) { 196 if (physicsVector == nullptr) { << 258 197 G4Exception("G4IonStoppingData::AddPhysics << 259 if(physicsVector == 0) { 198 "Pointer to vector is null-pointer."); << 260 199 return false; << 261 #ifdef G4VERBOSE >> 262 G4cerr << "G4IonStoppingData::AddPhysicsVector() Error: " >> 263 << "Pointer to vector is null-pointer." >> 264 << G4endl; >> 265 #endif >> 266 >> 267 return false; 200 } 268 } 201 269 202 if (atomicNumberIon <= 0) { << 270 if(atomicNumberIon <= 0) { 203 G4Exception("G4IonStoppingData::AddPhysics << 271 204 "Invalid ion number."); << 272 #ifdef G4VERBOSE 205 return false; << 273 G4cerr << "G4IonStoppingData::AddPhysicsVector() Error: " >> 274 << "Cannot add physics vector. Illegal atomic number." >> 275 << G4endl; >> 276 #endif >> 277 >> 278 return false; 206 } 279 } 207 280 208 if (atomicNumberElem <= 0) { << 281 if(atomicNumberElem <= 0) { 209 G4Exception("G4IonStoppingData::AddPhysics << 282 210 "Illegal atomic number."); << 283 #ifdef G4VERBOSE 211 return false; << 284 G4cerr << "G4IonStoppingData::AddPhysicsVector() Error: " >> 285 << "Atomic number of element < 0." >> 286 << G4endl; >> 287 #endif >> 288 return false; 212 } 289 } 213 290 214 G4IonDEDXKeyElem key = std::make_pair(atomic 291 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem); 215 292 216 if (dedxMapElements.count(key) == 1) { << 293 if(dedxMapElements.count(key) == 1) { 217 G4ExceptionDescription ed; << 294 218 ed << "Vector with Z1 = " << atomicNumberI << 295 #ifdef G4VERBOSE 219 << "already exists. Remove first before << 296 G4cerr << "G4IonStoppingData::AddPhysicsVector() Error: " 220 G4Exception("G4IonStoppingData::AddPhysics << 297 << "Vector with Z1 = " << atomicNumberIon << ", Z2 = " 221 return false; << 298 << atomicNumberElem >> 299 << " already exists. Remove first before replacing." >> 300 << G4endl; >> 301 #endif >> 302 return false; 222 } 303 } 223 304 224 dedxMapElements[key] = physicsVector; 305 dedxMapElements[key] = physicsVector; 225 306 226 return true; 307 return true; 227 } 308 } 228 309 229 // ########################################### 310 // ######################################################################### 230 311 231 G4bool G4IonStoppingData::RemovePhysicsVector( << 312 G4bool G4IonStoppingData::RemovePhysicsVector( 232 const G4String& matIdentifier // Name or ch << 313 G4int atomicNumberIon, // Atomic number of ion 233 ) << 314 const G4String& matIdentifier // Name or chemical formula of material 234 { << 315 ) { >> 316 235 G4IonDEDXKeyMat key = std::make_pair(atomicN 317 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier); 236 318 237 auto iter = dedxMapMaterials.find(key); << 319 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key); 238 320 239 if (iter == dedxMapMaterials.end()) { << 321 if(iter == dedxMapMaterials.end()) { 240 G4Exception("G4IonStoppingData::RemovePhys << 322 241 "Invalid name of the material."); << 323 #ifdef G4VERBOSE 242 return false; << 324 G4cerr << "G4IonStoppingData::RemovePhysicsVector() Warning: " >> 325 << "Cannot remove physics vector. Vector not found." >> 326 << G4endl; >> 327 #endif >> 328 >> 329 return false; 243 } 330 } 244 331 245 G4PhysicsVector* physicsVector = (*iter).sec 332 G4PhysicsVector* physicsVector = (*iter).second; 246 333 247 // Deleting key of physics vector from mater 334 // Deleting key of physics vector from material map 248 dedxMapMaterials.erase(key); 335 dedxMapMaterials.erase(key); 249 336 250 // Deleting physics vector 337 // Deleting physics vector 251 delete physicsVector; 338 delete physicsVector; 252 339 253 return true; 340 return true; 254 } 341 } 255 342 256 // ########################################### 343 // ######################################################################### 257 344 258 G4bool G4IonStoppingData::RemovePhysicsVector( << 345 G4bool G4IonStoppingData::RemovePhysicsVector( 259 G4int atomicNumberElem // Atomic number of << 346 G4int atomicNumberIon, // Atomic number of ion 260 ) << 347 G4int atomicNumberElem // Atomic number of elemental material 261 { << 348 ) { 262 G4IonDEDXKeyElem key = std::make_pair(atomic 349 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem); 263 350 264 auto iter = dedxMapElements.find(key); << 351 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key); 265 352 266 if (iter == dedxMapElements.end()) { << 353 if(iter == dedxMapElements.end()) { 267 G4Exception("G4IonStoppingData::RemovePhys << 354 268 "Invalid element."); << 355 #ifdef G4VERBOSE 269 return false; << 356 G4cerr << "G4IonStoppingData::RemovePhysicsVector() Warning: " >> 357 << "Cannot remove physics vector. Vector not found." >> 358 << G4endl; >> 359 #endif >> 360 >> 361 return false; 270 } 362 } 271 363 272 G4PhysicsVector* physicsVector = (*iter).sec 364 G4PhysicsVector* physicsVector = (*iter).second; 273 365 274 // Deleting key of physics vector from mater 366 // Deleting key of physics vector from material map 275 dedxMapElements.erase(key); 367 dedxMapElements.erase(key); 276 368 277 // Deleting physics vector 369 // Deleting physics vector 278 delete physicsVector; 370 delete physicsVector; 279 371 280 return true; 372 return true; 281 } 373 } 282 374 283 // ########################################### 375 // ######################################################################### 284 376 285 G4bool G4IonStoppingData::BuildPhysicsVector(G << 377 G4bool G4IonStoppingData::BuildPhysicsVector( 286 const G4String& matname // Name of material << 378 G4int atomicNumberIon, // Atomic number of ion 287 ) << 379 const G4String& matIdentifier // Name of material 288 { << 380 ) { 289 if (IsApplicable(atomicNumberIon, matname)) << 290 return true; << 291 } << 292 << 293 const char* path = G4FindDataDir("G4LEDATA") << 294 if (path == nullptr) { << 295 G4Exception("G4IonStoppingData::BuildPhysi << 296 "G4LEDATA environment variable not set") << 297 return false; << 298 } << 299 << 300 std::ostringstream file; << 301 G4String ww = << 302 (fICRU90 && (matname == "G4_WATER" || matn << 303 << 304 381 305 file << path << "/" << subDir << ww << "/z" << 382 if( IsApplicable(atomicNumberIon, matIdentifier) ) return true; 306 G4String fileName = G4String(file.str().c_st << 307 383 308 std::ifstream ifilestream(fileName); << 384 char* path = getenv("G4LEDATA"); 309 << 385 if ( !path ) { 310 if (! ifilestream.is_open()) { << 386 G4Exception("G4IonStoppingData::BuildPhysicsVector()", "mat521", 311 return false; << 387 FatalException, "G4LEDATA environment variable not set"); 312 } << 313 << 314 auto* physicsVector = new G4PhysicsFreeVecto << 315 << 316 if (! physicsVector->Retrieve(ifilestream, t << 317 ifilestream.close(); << 318 return false; 388 return false; 319 } 389 } 320 << 390 321 physicsVector->ScaleVector(MeV, MeV * cm2 / << 391 std::ostringstream file; 322 physicsVector->FillSecondDerivatives(); << 392 >> 393 file << path << "/" << subDir << "/z" >> 394 << atomicNumberIon << "_" << matIdentifier >> 395 << ".dat"; >> 396 >> 397 G4String fileName = G4String( file.str().c_str() ); >> 398 >> 399 std::ifstream ifilestream( fileName ); >> 400 >> 401 if ( !ifilestream.is_open() ) return false; >> 402 >> 403 G4LPhysicsFreeVector* physicsVector = new G4LPhysicsFreeVector(); >> 404 >> 405 if( !physicsVector -> Retrieve(ifilestream, true) ) { >> 406 >> 407 ifilestream.close(); >> 408 return false; >> 409 } >> 410 >> 411 physicsVector -> ScaleVector( MeV, MeV * cm2 /( 0.001 * g) ); >> 412 physicsVector -> SetSpline( true ); >> 413 physicsVector -> FillSecondDerivatives(); 323 414 324 // Retrieved vector is added to material sto 415 // Retrieved vector is added to material store 325 if (! AddPhysicsVector(physicsVector, atomic << 416 if( !AddPhysicsVector(physicsVector, atomicNumberIon, matIdentifier) ) { 326 delete physicsVector; << 417 delete physicsVector; 327 ifilestream.close(); << 418 ifilestream.close(); 328 return false; << 419 return false; 329 } 420 } 330 421 331 ifilestream.close(); 422 ifilestream.close(); 332 return true; 423 return true; 333 } 424 } 334 425 335 // ########################################### 426 // ######################################################################### 336 427 337 G4bool G4IonStoppingData::BuildPhysicsVector(G << 428 G4bool G4IonStoppingData::BuildPhysicsVector( 338 G4int ZElem // Atomic number of elemental m << 429 G4int atomicNumberIon, // Atomic number of ion 339 ) << 430 G4int atomicNumberElem // Atomic number of elemental material 340 { << 431 ) { 341 if (IsApplicable(ZIon, ZElem)) { << 432 342 return true; << 433 if( IsApplicable(atomicNumberIon, atomicNumberElem) ) return true; 343 } << 434 344 << 435 char* path = getenv("G4LEDATA"); 345 const char* path = G4FindDataDir("G4LEDATA") << 436 if ( !path ) { 346 if (path == nullptr) { << 437 G4Exception("G4IonStoppingData::BuildPhysicsVector()", "mat522", 347 G4Exception("G4IonStoppingData::BuildPhysi << 438 FatalException, "G4LEDATA environment variable not set"); 348 "G4LEDATA environment variable not set") << 349 return false; 439 return false; 350 } 440 } 351 std::ostringstream file; 441 std::ostringstream file; 352 G4String ww = << 442 353 (fICRU90 && ZIon <= 18 && (ZElem == 1 || Z << 443 file << path << "/" << subDir << "/z" 354 << 444 << atomicNumberIon << "_" << atomicNumberElem 355 file << path << "/" << subDir << ww << "/z" << 445 << ".dat"; 356 << 446 357 G4String fileName = G4String(file.str().c_st << 447 G4String fileName = G4String( file.str().c_str() ); 358 std::ifstream ifilestream(fileName); << 448 359 << 449 std::ifstream ifilestream( fileName ); 360 if (! ifilestream.is_open()) { << 450 361 return false; << 451 if ( !ifilestream.is_open() ) return false; 362 } << 452 363 auto* physicsVector = new G4PhysicsFreeVecto << 453 G4LPhysicsFreeVector* physicsVector = new G4LPhysicsFreeVector(); 364 << 454 365 if (! physicsVector->Retrieve(ifilestream, t << 455 if( !physicsVector -> Retrieve(ifilestream, true) ) { 366 ifilestream.close(); << 456 367 return false; << 457 ifilestream.close(); 368 } << 458 return false; 369 << 459 } 370 physicsVector->ScaleVector(MeV, MeV * cm2 / << 460 371 physicsVector->FillSecondDerivatives(); << 461 physicsVector -> ScaleVector( MeV, MeV * cm2 /( 0.001 * g) ); >> 462 physicsVector -> SetSpline( true ); >> 463 physicsVector -> FillSecondDerivatives(); 372 464 373 // Retrieved vector is added to material sto 465 // Retrieved vector is added to material store 374 if (! AddPhysicsVector(physicsVector, ZIon, << 466 if( !AddPhysicsVector(physicsVector, atomicNumberIon, atomicNumberElem) ) { 375 delete physicsVector; << 467 delete physicsVector; 376 ifilestream.close(); << 468 ifilestream.close(); 377 return false; << 469 return false; 378 } 470 } 379 471 380 ifilestream.close(); 472 ifilestream.close(); 381 return true; 473 return true; 382 } 474 } 383 475 384 // ########################################### 476 // ######################################################################### 385 477 386 void G4IonStoppingData::ClearTable() << 478 void G4IonStoppingData::ClearTable() { 387 { << 479 388 auto iterMat = dedxMapMaterials.begin(); << 480 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin(); 389 auto iterMat_end = dedxMapMaterials.end(); << 481 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end(); >> 482 >> 483 for(;iterMat != iterMat_end; iterMat++) { 390 484 391 for (; iterMat != iterMat_end; iterMat++) { << 485 G4PhysicsVector* vec = iterMat -> second; 392 G4PhysicsVector* vec = iterMat->second; << 393 486 394 delete vec; << 487 if(vec != 0) delete vec; 395 } 488 } 396 489 397 dedxMapMaterials.clear(); 490 dedxMapMaterials.clear(); 398 491 399 auto iterElem = dedxMapElements.begin(); << 492 G4IonDEDXMapElem::iterator iterElem = dedxMapElements.begin(); 400 auto iterElem_end = dedxMapElements.end(); << 493 G4IonDEDXMapElem::iterator iterElem_end = dedxMapElements.end(); 401 494 402 for (; iterElem != iterElem_end; iterElem++) << 495 for(;iterElem != iterElem_end; iterElem++) { 403 G4PhysicsVector* vec = iterElem->second; << 404 496 405 delete vec; << 497 G4PhysicsVector* vec = iterElem -> second; >> 498 >> 499 if(vec != 0) delete vec; 406 } 500 } 407 501 408 dedxMapElements.clear(); 502 dedxMapElements.clear(); 409 } 503 } 410 504 411 // ########################################### 505 // ######################################################################### 412 506 413 void G4IonStoppingData::DumpMap() << 507 void G4IonStoppingData::DumpMap() { 414 { << 415 auto iterMat = dedxMapMaterials.begin(); << 416 auto iterMat_end = dedxMapMaterials.end(); << 417 << 418 G4cout << std::setw(15) << std::right << "At << 419 << "Material name" << G4endl; << 420 << 421 for (; iterMat != iterMat_end; iterMat++) { << 422 G4IonDEDXKeyMat key = iterMat->first; << 423 G4PhysicsVector* physicsVector = iterMat-> << 424 508 425 G4int atomicNumberIon = key.first; << 509 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin(); 426 G4String matIdentifier = key.second; << 510 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end(); 427 511 428 if (physicsVector != nullptr) { << 512 G4cout << std::setw(15) << std::right 429 G4cout << std::setw(15) << std::right << << 513 << "Atomic nmb ion" 430 << matIdentifier << G4endl; << 514 << std::setw(25) << std::right 431 } << 515 << "Material name" >> 516 << G4endl; >> 517 >> 518 for(;iterMat != iterMat_end; iterMat++) { >> 519 G4IonDEDXKeyMat key = iterMat -> first; >> 520 G4PhysicsVector* physicsVector = iterMat -> second; >> 521 >> 522 G4int atomicNumberIon = key.first; >> 523 G4String matIdentifier = key.second; >> 524 >> 525 if(physicsVector != 0) { >> 526 G4cout << std::setw(15) << std::right >> 527 << atomicNumberIon >> 528 << std::setw(25) << std::right >> 529 << matIdentifier >> 530 << G4endl; >> 531 } >> 532 } >> 533 >> 534 G4IonDEDXMapElem::iterator iterElem = dedxMapElements.begin(); >> 535 G4IonDEDXMapElem::iterator iterElem_end = dedxMapElements.end(); >> 536 >> 537 G4cout << std::setw(15) << std::right >> 538 << "Atomic nmb ion" >> 539 << std::setw(25) << std::right >> 540 << "Atomic nmb material" >> 541 << G4endl; >> 542 >> 543 for(;iterElem != iterElem_end; iterElem++) { >> 544 G4IonDEDXKeyElem key = iterElem -> first; >> 545 G4PhysicsVector* physicsVector = iterElem -> second; >> 546 >> 547 G4int atomicNumberIon = key.first; >> 548 G4int atomicNumberElem = key.second; >> 549 >> 550 if(physicsVector != 0) { >> 551 G4cout << std::setw(15) << std::right >> 552 << atomicNumberIon >> 553 << std::setw(25) << std::right >> 554 << atomicNumberElem >> 555 << G4endl; >> 556 } 432 } 557 } 433 558 434 auto iterElem = dedxMapElements.begin(); << 435 auto iterElem_end = dedxMapElements.end(); << 436 << 437 G4cout << std::setw(15) << std::right << "At << 438 << "Atomic nmb material" << G4endl; << 439 << 440 for (; iterElem != iterElem_end; iterElem++) << 441 G4IonDEDXKeyElem key = iterElem->first; << 442 G4PhysicsVector* physicsVector = iterElem- << 443 << 444 G4int atomicNumberIon = key.first; << 445 G4int atomicNumberElem = key.second; << 446 << 447 if (physicsVector != nullptr) { << 448 G4cout << std::setw(15) << std::right << << 449 << atomicNumberElem << G4endl; << 450 } << 451 } << 452 } 559 } 453 560 454 // ########################################### 561 // ######################################################################### >> 562 455 563