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 // =========================================== 26 // =========================================================================== 27 // GEANT4 class source file 27 // GEANT4 class source file 28 // 28 // 29 // Class: G4ExtDEDXTable 29 // Class: G4ExtDEDXTable 30 // 30 // 31 // Base class: G4VIonDEDXTable 31 // Base class: G4VIonDEDXTable 32 // 32 // 33 // Author: Anton Lechner (Anton. 33 // Author: Anton Lechner (Anton.Lechner@cern.ch) 34 // 34 // 35 // First implementation: 29. 02. 2009 35 // First implementation: 29. 02. 2009 36 // 36 // 37 // Modifications: 37 // Modifications: 38 // 03.11.2009 A. Lechner: Added new methods B 38 // 03.11.2009 A. Lechner: Added new methods BuildPhysicsVector according 39 // to interface changes in base cla 39 // to interface changes in base class G4VIonDEDXTable. 40 // 25.10.2010 V.Ivanchenko fixed bug in usage 40 // 25.10.2010 V.Ivanchenko fixed bug in usage of iterators reported by the 41 // Coverity tool 41 // Coverity tool 42 // 01.11.2010 V.Ivanchenko fixed remaining bug 42 // 01.11.2010 V.Ivanchenko fixed remaining bugs reported by Coverity 43 // 43 // 44 // 44 // 45 // Class description: 45 // Class description: 46 // Utility class for users to add their own 46 // Utility class for users to add their own electronic stopping powers 47 // for ions. This class is dedicated for us 47 // for ions. This class is dedicated for use with G4IonParametrisedLossModel 48 // of the low-energy electromagnetic packag 48 // of the low-energy electromagnetic package. 49 // 49 // 50 // Comments: 50 // Comments: 51 // 51 // 52 // =========================================== 52 // =========================================================================== 53 53 54 #include "G4ExtDEDXTable.hh" 54 #include "G4ExtDEDXTable.hh" 55 55 56 #include "G4PhysicsFreeVector.hh" 56 #include "G4PhysicsFreeVector.hh" 57 #include "G4PhysicsLinearVector.hh" 57 #include "G4PhysicsLinearVector.hh" 58 #include "G4PhysicsLogVector.hh" 58 #include "G4PhysicsLogVector.hh" 59 #include "G4PhysicsVector.hh" 59 #include "G4PhysicsVector.hh" 60 #include "G4PhysicsVectorType.hh" 60 #include "G4PhysicsVectorType.hh" 61 61 62 #include <fstream> 62 #include <fstream> 63 #include <iomanip> 63 #include <iomanip> 64 #include <sstream> 64 #include <sstream> 65 65 66 // ########################################### 66 // ######################################################################### 67 67 68 G4ExtDEDXTable::~G4ExtDEDXTable() { ClearTable 68 G4ExtDEDXTable::~G4ExtDEDXTable() { ClearTable(); } 69 69 70 // ########################################### 70 // ######################################################################### 71 71 72 G4bool G4ExtDEDXTable::BuildPhysicsVector(G4in 72 G4bool G4ExtDEDXTable::BuildPhysicsVector(G4int ionZ, G4int matZ) 73 { 73 { 74 return IsApplicable(ionZ, matZ); 74 return IsApplicable(ionZ, matZ); 75 } 75 } 76 76 77 // ########################################### 77 // ######################################################################### 78 78 79 G4bool G4ExtDEDXTable::BuildPhysicsVector(G4in 79 G4bool G4ExtDEDXTable::BuildPhysicsVector(G4int ionZ, const G4String& matName) 80 { 80 { 81 return IsApplicable(ionZ, matName); 81 return IsApplicable(ionZ, matName); 82 } 82 } 83 83 84 // ########################################### 84 // ######################################################################### 85 85 86 G4bool G4ExtDEDXTable::IsApplicable(G4int atom 86 G4bool G4ExtDEDXTable::IsApplicable(G4int atomicNumberIon, // Atomic number of ion 87 G4int atomicNumberElem // Atomic number of 87 G4int atomicNumberElem // Atomic number of elemental material 88 ) 88 ) 89 { 89 { 90 G4IonDEDXKeyElem key = std::make_pair(atomic 90 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem); 91 91 92 auto iter = dedxMapElements.find(key); 92 auto iter = dedxMapElements.find(key); 93 93 94 return iter != dedxMapElements.end(); 94 return iter != dedxMapElements.end(); 95 } 95 } 96 96 97 // ########################################### 97 // ######################################################################### 98 98 99 G4bool G4ExtDEDXTable::IsApplicable(G4int atom 99 G4bool G4ExtDEDXTable::IsApplicable(G4int atomicNumberIon, // Atomic number of ion 100 const G4String& matIdentifier // Name or ch 100 const G4String& matIdentifier // Name or chemical formula of material 101 ) 101 ) 102 { 102 { 103 G4IonDEDXKeyMat key = std::make_pair(atomicN 103 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier); 104 104 105 auto iter = dedxMapMaterials.find(key); 105 auto iter = dedxMapMaterials.find(key); 106 106 107 return iter != dedxMapMaterials.end(); 107 return iter != dedxMapMaterials.end(); 108 } 108 } 109 109 110 // ########################################### 110 // ######################################################################### 111 111 112 G4PhysicsVector* G4ExtDEDXTable::GetPhysicsVec 112 G4PhysicsVector* G4ExtDEDXTable::GetPhysicsVector(G4int atomicNumberIon, // Atomic number of ion 113 G4int atomicNumberElem // Atomic number of 113 G4int atomicNumberElem // Atomic number of elemental material 114 ) 114 ) 115 { 115 { 116 G4IonDEDXKeyElem key = std::make_pair(atomic 116 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem); 117 117 118 auto iter = dedxMapElements.find(key); 118 auto iter = dedxMapElements.find(key); 119 119 120 return (iter != dedxMapElements.end()) ? ite 120 return (iter != dedxMapElements.end()) ? iter->second : nullptr; 121 } 121 } 122 122 123 // ########################################### 123 // ######################################################################### 124 124 125 G4PhysicsVector* G4ExtDEDXTable::GetPhysicsVec 125 G4PhysicsVector* G4ExtDEDXTable::GetPhysicsVector(G4int atomicNumberIon, // Atomic number of ion 126 const G4String& matIdentifier // Name or ch 126 const G4String& matIdentifier // Name or chemical formula of material 127 ) 127 ) 128 { 128 { 129 G4IonDEDXKeyMat key = std::make_pair(atomicN 129 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier); 130 130 131 auto iter = dedxMapMaterials.find(key); 131 auto iter = dedxMapMaterials.find(key); 132 132 133 return (iter != dedxMapMaterials.end()) ? it 133 return (iter != dedxMapMaterials.end()) ? iter->second : nullptr; 134 } 134 } 135 135 136 // ########################################### 136 // ######################################################################### 137 137 138 G4double G4ExtDEDXTable::GetDEDX(G4double kinE 138 G4double G4ExtDEDXTable::GetDEDX(G4double kinEnergyPerNucleon, // Kinetic energy per nucleon 139 G4int atomicNumberIon, // Atomic number of 139 G4int atomicNumberIon, // Atomic number of ion 140 G4int atomicNumberElem // Atomic number of 140 G4int atomicNumberElem // Atomic number of elemental material 141 ) 141 ) 142 { 142 { 143 G4IonDEDXKeyElem key = std::make_pair(atomic 143 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem); 144 144 145 auto iter = dedxMapElements.find(key); 145 auto iter = dedxMapElements.find(key); 146 146 147 return (iter != dedxMapElements.end()) ? (it 147 return (iter != dedxMapElements.end()) ? (iter->second)->Value(kinEnergyPerNucleon) : 0.0; 148 } 148 } 149 149 150 // ########################################### 150 // ######################################################################### 151 151 152 G4double G4ExtDEDXTable::GetDEDX(G4double kinE 152 G4double G4ExtDEDXTable::GetDEDX(G4double kinEnergyPerNucleon, // Kinetic energy per nucleon 153 G4int atomicNumberIon, // Atomic number of 153 G4int atomicNumberIon, // Atomic number of ion 154 const G4String& matIdentifier // Name or ch 154 const G4String& matIdentifier // Name or chemical formula of material 155 ) 155 ) 156 { 156 { 157 G4IonDEDXKeyMat key = std::make_pair(atomicN 157 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier); 158 158 159 auto iter = dedxMapMaterials.find(key); 159 auto iter = dedxMapMaterials.find(key); 160 160 161 return (iter != dedxMapMaterials.end()) ? (i 161 return (iter != dedxMapMaterials.end()) ? (iter->second)->Value(kinEnergyPerNucleon) : 0.0; 162 } 162 } 163 163 164 // ########################################### 164 // ######################################################################### 165 165 166 G4bool G4ExtDEDXTable::AddPhysicsVector(G4Phys 166 G4bool G4ExtDEDXTable::AddPhysicsVector(G4PhysicsVector* physicsVector, // Physics vector 167 G4int atomicNumberIon, // Atomic number of 167 G4int atomicNumberIon, // Atomic number of ion 168 const G4String& matIdentifier, // Name of e 168 const G4String& matIdentifier, // Name of elemental material 169 G4int atomicNumberElem // Atomic number of 169 G4int atomicNumberElem // Atomic number of elemental material 170 ) 170 ) 171 { 171 { 172 if (physicsVector == nullptr) { 172 if (physicsVector == nullptr) { 173 G4Exception("G4ExtDEDXTable::AddPhysicsVec 173 G4Exception("G4ExtDEDXTable::AddPhysicsVector() for material", "mat037", FatalException, 174 "Pointer to vector is null-pointer."); 174 "Pointer to vector is null-pointer."); 175 return false; 175 return false; 176 } 176 } 177 177 178 if (matIdentifier.empty()) { 178 if (matIdentifier.empty()) { 179 G4Exception("G4ExtDEDXTable::AddPhysicsVec 179 G4Exception("G4ExtDEDXTable::AddPhysicsVector() for material", "mat038", FatalException, 180 "Invalid name of the material."); 180 "Invalid name of the material."); 181 return false; 181 return false; 182 } 182 } 183 183 184 if (atomicNumberIon <= 2) { 184 if (atomicNumberIon <= 2) { 185 G4Exception("G4ExtDEDXTable::AddPhysicsVec 185 G4Exception("G4ExtDEDXTable::AddPhysicsVector() for material", "mat039", FatalException, 186 "Illegal atomic number."); 186 "Illegal atomic number."); 187 return false; 187 return false; 188 } 188 } 189 189 190 if (atomicNumberElem > 0) { 190 if (atomicNumberElem > 0) { 191 G4IonDEDXKeyElem key = std::make_pair(atom 191 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem); 192 192 193 if (dedxMapElements.count(key) == 1) { 193 if (dedxMapElements.count(key) == 1) { 194 G4Exception("G4ExtDEDXTable::AddPhysicsV 194 G4Exception("G4ExtDEDXTable::AddPhysicsVector() for material", "mat037", FatalException, 195 "Vector already exist, remove it befor 195 "Vector already exist, remove it before replacing."); 196 return false; 196 return false; 197 } 197 } 198 198 199 dedxMapElements[key] = physicsVector; 199 dedxMapElements[key] = physicsVector; 200 } 200 } 201 201 202 G4IonDEDXKeyMat mkey = std::make_pair(atomic 202 G4IonDEDXKeyMat mkey = std::make_pair(atomicNumberIon, matIdentifier); 203 203 204 if (dedxMapMaterials.count(mkey) == 1) { 204 if (dedxMapMaterials.count(mkey) == 1) { 205 G4Exception("G4ExtDEDXTable::AddPhysicsVec 205 G4Exception("G4ExtDEDXTable::AddPhysicsVector() for material", "mat037", FatalException, 206 "Vector already exist, remove it before 206 "Vector already exist, remove it before replacing."); 207 return false; 207 return false; 208 } 208 } 209 209 210 dedxMapMaterials[mkey] = physicsVector; 210 dedxMapMaterials[mkey] = physicsVector; 211 211 212 return true; 212 return true; 213 } 213 } 214 214 215 // ########################################### 215 // ######################################################################### 216 216 217 G4bool G4ExtDEDXTable::RemovePhysicsVector(G4i 217 G4bool G4ExtDEDXTable::RemovePhysicsVector(G4int atomicNumberIon, // Atomic number of ion 218 const G4String& matIdentifier // Name or ch 218 const G4String& matIdentifier // Name or chemical formula of material 219 ) 219 ) 220 { 220 { 221 G4PhysicsVector* physicsVector = nullptr; 221 G4PhysicsVector* physicsVector = nullptr; 222 222 223 // Deleting key of physics vector from mater 223 // Deleting key of physics vector from material map 224 G4IonDEDXKeyMat key = std::make_pair(atomicN 224 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier); 225 225 226 auto iter = dedxMapMaterials.find(key); 226 auto iter = dedxMapMaterials.find(key); 227 227 228 if (iter == dedxMapMaterials.end()) { 228 if (iter == dedxMapMaterials.end()) { 229 G4Exception("G4ExtDEDXTable::RemovePhysics 229 G4Exception("G4ExtDEDXTable::RemovePhysicsVector() for material", "mat037", FatalException, 230 "Pointer to vector is null-pointer."); 230 "Pointer to vector is null-pointer."); 231 return false; 231 return false; 232 } 232 } 233 233 234 physicsVector = (*iter).second; 234 physicsVector = (*iter).second; 235 dedxMapMaterials.erase(key); 235 dedxMapMaterials.erase(key); 236 236 237 // Deleting key of physics vector from eleme 237 // Deleting key of physics vector from elemental material map (if it exists) 238 G4IonDEDXMapElem::iterator it; 238 G4IonDEDXMapElem::iterator it; 239 239 240 for (it = dedxMapElements.begin(); it != ded 240 for (it = dedxMapElements.begin(); it != dedxMapElements.end(); ++it) { 241 if ((*it).second == physicsVector) { 241 if ((*it).second == physicsVector) { 242 dedxMapElements.erase(it); 242 dedxMapElements.erase(it); 243 break; 243 break; 244 } 244 } 245 } 245 } 246 246 247 // Deleting physics vector 247 // Deleting physics vector 248 delete physicsVector; 248 delete physicsVector; 249 249 250 return true; 250 return true; 251 } 251 } 252 252 253 // ########################################### 253 // ######################################################################### 254 254 255 G4bool G4ExtDEDXTable::StorePhysicsTable(const 255 G4bool G4ExtDEDXTable::StorePhysicsTable(const G4String& fileName // File name 256 ) 256 ) 257 { 257 { 258 G4bool success = true; 258 G4bool success = true; 259 259 260 std::ofstream ofilestream; 260 std::ofstream ofilestream; 261 261 262 ofilestream.open(fileName, std::ios::out); 262 ofilestream.open(fileName, std::ios::out); 263 263 264 if (! ofilestream) { 264 if (! ofilestream) { 265 G4ExceptionDescription ed; 265 G4ExceptionDescription ed; 266 ed << "Cannot open file " << fileName; 266 ed << "Cannot open file " << fileName; 267 G4Exception("G4IonStoppingData::StorePhysi 267 G4Exception("G4IonStoppingData::StorePhysicsTable()", "mat030", FatalException, ed); 268 success = false; 268 success = false; 269 } 269 } 270 else { 270 else { 271 size_t nmbMatTables = dedxMapMaterials.siz 271 size_t nmbMatTables = dedxMapMaterials.size(); 272 272 273 ofilestream << nmbMatTables << G4endl << G 273 ofilestream << nmbMatTables << G4endl << G4endl; 274 274 275 auto iterMat = dedxMapMaterials.begin(); 275 auto iterMat = dedxMapMaterials.begin(); 276 auto iterMat_end = dedxMapMaterials.end(); 276 auto iterMat_end = dedxMapMaterials.end(); 277 277 278 for (; iterMat != iterMat_end; iterMat++) 278 for (; iterMat != iterMat_end; iterMat++) { 279 G4IonDEDXKeyMat key = iterMat->first; 279 G4IonDEDXKeyMat key = iterMat->first; 280 G4PhysicsVector* physicsVector = iterMat 280 G4PhysicsVector* physicsVector = iterMat->second; 281 281 282 G4int atomicNumberIon = key.first; 282 G4int atomicNumberIon = key.first; 283 G4String matIdentifier = key.second; 283 G4String matIdentifier = key.second; 284 284 285 G4int atomicNumberElem = FindAtomicNumbe 285 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector); 286 286 287 if (physicsVector != nullptr) { 287 if (physicsVector != nullptr) { 288 ofilestream << atomicNumberIon << " " 288 ofilestream << atomicNumberIon << " " << matIdentifier; 289 289 290 if (atomicNumberElem > 0) { 290 if (atomicNumberElem > 0) { 291 ofilestream << " " << atomicNumberE 291 ofilestream << " " << atomicNumberElem; 292 } 292 } 293 293 294 ofilestream << " # <Atomic number ion 294 ofilestream << " # <Atomic number ion> <Material name> "; 295 295 296 if (atomicNumberElem > 0) { 296 if (atomicNumberElem > 0) { 297 ofilestream << "<Atomic number eleme 297 ofilestream << "<Atomic number element>"; 298 } 298 } 299 299 300 ofilestream << G4endl << physicsVector 300 ofilestream << G4endl << physicsVector->GetType() << G4endl; 301 301 302 physicsVector->Store(ofilestream, true 302 physicsVector->Store(ofilestream, true); 303 303 304 ofilestream << G4endl; 304 ofilestream << G4endl; 305 } 305 } 306 else { 306 else { 307 G4Exception("G4IonStoppingData::StoreP 307 G4Exception("G4IonStoppingData::StorePhysicsTable()", "mat030", FatalException, 308 "Cannot store vector."); 308 "Cannot store vector."); 309 } 309 } 310 } 310 } 311 } 311 } 312 312 313 ofilestream.close(); 313 ofilestream.close(); 314 314 315 return success; 315 return success; 316 } 316 } 317 317 318 // ########################################### 318 // ######################################################################### 319 319 320 G4bool G4ExtDEDXTable::RetrievePhysicsTable(co 320 G4bool G4ExtDEDXTable::RetrievePhysicsTable(const G4String& fileName) 321 { 321 { 322 std::ifstream ifilestream; 322 std::ifstream ifilestream; 323 ifilestream.open(fileName, std::ios::in | st 323 ifilestream.open(fileName, std::ios::in | std::ios::binary); 324 if (! ifilestream) { 324 if (! ifilestream) { 325 G4ExceptionDescription ed; 325 G4ExceptionDescription ed; 326 ed << "Cannot open file " << fileName; 326 ed << "Cannot open file " << fileName; 327 G4Exception("G4IonStoppingData::RetrievePh 327 G4Exception("G4IonStoppingData::RetrievePhysicsTable()", "mat030", FatalException, ed); 328 return false; 328 return false; 329 } 329 } 330 330 331 // std::string::size_type nmbVectors; 331 // std::string::size_type nmbVectors; 332 G4int nmbVectors = 0; 332 G4int nmbVectors = 0; 333 ifilestream >> nmbVectors; 333 ifilestream >> nmbVectors; 334 if (ifilestream.fail() || nmbVectors <= 0) { 334 if (ifilestream.fail() || nmbVectors <= 0) { 335 G4cout << "G4ExtDEDXTable::RetrievePhysics 335 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() " 336 << " File content of " << fileName 336 << " File content of " << fileName << " ill-formated." 337 << " Nvectors= " << nmbVectors << G 337 << " Nvectors= " << nmbVectors << G4endl; 338 ifilestream.close(); 338 ifilestream.close(); 339 return false; 339 return false; 340 } 340 } 341 341 342 for (G4int i = 0; i < nmbVectors; ++i) { 342 for (G4int i = 0; i < nmbVectors; ++i) { 343 G4String line = ""; 343 G4String line = ""; 344 // Loop checking, 07-Aug-2015, Vladimir Iv 344 // Loop checking, 07-Aug-2015, Vladimir Ivanchenko 345 while (line.empty()) { 345 while (line.empty()) { 346 getline(ifilestream, line); 346 getline(ifilestream, line); 347 if (ifilestream.fail()) { 347 if (ifilestream.fail()) { 348 G4cout << "G4ExtDEDXTable::RetrievePhy 348 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() " 349 << " File content of " << fileN 349 << " File content of " << fileName << " ill-formated." << G4endl; 350 ifilestream.close(); 350 ifilestream.close(); 351 return false; 351 return false; 352 } 352 } 353 353 354 std::string::size_type pos = line.find_f 354 std::string::size_type pos = line.find_first_of('#'); 355 if (pos != std::string::npos && pos > 0) 355 if (pos != std::string::npos && pos > 0) { 356 line = line.substr(0, pos); 356 line = line.substr(0, pos); 357 } 357 } 358 } 358 } 359 359 360 std::istringstream headerstream(line); 360 std::istringstream headerstream(line); 361 361 362 std::string::size_type atomicNumberIon; 362 std::string::size_type atomicNumberIon; 363 headerstream >> atomicNumberIon; 363 headerstream >> atomicNumberIon; 364 364 365 G4String materialName; 365 G4String materialName; 366 headerstream >> materialName; 366 headerstream >> materialName; 367 367 368 if (headerstream.fail() || std::string::np 368 if (headerstream.fail() || std::string::npos == atomicNumberIon) { 369 G4cout << "G4ExtDEDXTable::RetrievePhysi 369 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() " 370 << " File content of " << fileNam 370 << " File content of " << fileName << " ill-formated " 371 << " (vector header)." << G4endl; 371 << " (vector header)." << G4endl; 372 ifilestream.close(); 372 ifilestream.close(); 373 return false; 373 return false; 374 } 374 } 375 375 376 std::string::size_type atomicNumberMat; 376 std::string::size_type atomicNumberMat; 377 headerstream >> atomicNumberMat; 377 headerstream >> atomicNumberMat; 378 378 379 if (headerstream.eof() || std::string::npo 379 if (headerstream.eof() || std::string::npos == atomicNumberMat) { 380 atomicNumberMat = 0; 380 atomicNumberMat = 0; 381 } 381 } 382 382 383 G4int vectorType; 383 G4int vectorType; 384 ifilestream >> vectorType; 384 ifilestream >> vectorType; 385 385 386 G4PhysicsVector* physicsVector = CreatePhy 386 G4PhysicsVector* physicsVector = CreatePhysicsVector(vectorType); 387 387 388 if (physicsVector == nullptr) { 388 if (physicsVector == nullptr) { 389 G4cout << "G4ExtDEDXTable::RetrievePhysi 389 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable " 390 << " illegal physics Vector type 390 << " illegal physics Vector type " << vectorType << " in " << fileName << G4endl; 391 ifilestream.close(); 391 ifilestream.close(); 392 return false; 392 return false; 393 } 393 } 394 394 395 if (! physicsVector->Retrieve(ifilestream, 395 if (! physicsVector->Retrieve(ifilestream, true)) { 396 G4cout << "G4ExtDEDXTable::RetrievePhysi 396 G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() " 397 << " File content of " << fileNam 397 << " File content of " << fileName << " ill-formated." << G4endl; 398 ifilestream.close(); 398 ifilestream.close(); 399 return false; 399 return false; 400 } 400 } 401 physicsVector->FillSecondDerivatives(); 401 physicsVector->FillSecondDerivatives(); 402 402 403 // Retrieved vector is added to material s 403 // Retrieved vector is added to material store 404 if (! AddPhysicsVector( 404 if (! AddPhysicsVector( 405 physicsVector, (G4int)atomicNumberIo 405 physicsVector, (G4int)atomicNumberIon, materialName, (G4int)atomicNumberMat)) 406 { 406 { 407 delete physicsVector; 407 delete physicsVector; 408 ifilestream.close(); 408 ifilestream.close(); 409 return false; 409 return false; 410 } 410 } 411 } 411 } 412 412 413 ifilestream.close(); 413 ifilestream.close(); 414 414 415 return true; 415 return true; 416 } 416 } 417 417 418 // ########################################### 418 // ######################################################################### 419 419 420 G4PhysicsVector* G4ExtDEDXTable::CreatePhysics 420 G4PhysicsVector* G4ExtDEDXTable::CreatePhysicsVector(G4int vectorType) 421 { 421 { 422 G4PhysicsVector* physicsVector = nullptr; 422 G4PhysicsVector* physicsVector = nullptr; 423 423 424 switch (vectorType) { 424 switch (vectorType) { 425 case T_G4PhysicsLinearVector: 425 case T_G4PhysicsLinearVector: 426 physicsVector = new G4PhysicsLinearVecto 426 physicsVector = new G4PhysicsLinearVector(true); 427 break; 427 break; 428 428 429 case T_G4PhysicsLogVector: 429 case T_G4PhysicsLogVector: 430 physicsVector = new G4PhysicsLogVector(t 430 physicsVector = new G4PhysicsLogVector(true); 431 break; 431 break; 432 432 433 case T_G4PhysicsFreeVector: 433 case T_G4PhysicsFreeVector: 434 physicsVector = new G4PhysicsFreeVector( 434 physicsVector = new G4PhysicsFreeVector(true); 435 break; 435 break; 436 436 437 default: 437 default: 438 break; 438 break; 439 } 439 } 440 return physicsVector; 440 return physicsVector; 441 } 441 } 442 442 443 // ########################################### 443 // ######################################################################### 444 444 445 G4int G4ExtDEDXTable::FindAtomicNumberElement( 445 G4int G4ExtDEDXTable::FindAtomicNumberElement(G4PhysicsVector* physicsVector) 446 { 446 { 447 G4int atomicNumber = 0; 447 G4int atomicNumber = 0; 448 448 449 auto iter = dedxMapElements.begin(); 449 auto iter = dedxMapElements.begin(); 450 auto iter_end = dedxMapElements.end(); 450 auto iter_end = dedxMapElements.end(); 451 451 452 for (; iter != iter_end; ++iter) { 452 for (; iter != iter_end; ++iter) { 453 if ((*iter).second == physicsVector) { 453 if ((*iter).second == physicsVector) { 454 G4IonDEDXKeyElem key = (*iter).first; 454 G4IonDEDXKeyElem key = (*iter).first; 455 atomicNumber = key.second; 455 atomicNumber = key.second; 456 } 456 } 457 } 457 } 458 458 459 return atomicNumber; 459 return atomicNumber; 460 } 460 } 461 461 462 // ########################################### 462 // ######################################################################### 463 463 464 void G4ExtDEDXTable::ClearTable() 464 void G4ExtDEDXTable::ClearTable() 465 { 465 { 466 auto iterMat = dedxMapMaterials.begin(); 466 auto iterMat = dedxMapMaterials.begin(); 467 auto iterMat_end = dedxMapMaterials.end(); 467 auto iterMat_end = dedxMapMaterials.end(); 468 468 469 for (; iterMat != iterMat_end; ++iterMat) { 469 for (; iterMat != iterMat_end; ++iterMat) { 470 G4PhysicsVector* vec = iterMat->second; 470 G4PhysicsVector* vec = iterMat->second; 471 471 472 delete vec; 472 delete vec; 473 } 473 } 474 474 475 dedxMapElements.clear(); 475 dedxMapElements.clear(); 476 dedxMapMaterials.clear(); 476 dedxMapMaterials.clear(); 477 } 477 } 478 478 479 // ########################################### 479 // ######################################################################### 480 480 481 void G4ExtDEDXTable::DumpMap() 481 void G4ExtDEDXTable::DumpMap() 482 { 482 { 483 auto iterMat = dedxMapMaterials.begin(); 483 auto iterMat = dedxMapMaterials.begin(); 484 auto iterMat_end = dedxMapMaterials.end(); 484 auto iterMat_end = dedxMapMaterials.end(); 485 485 486 G4cout << std::setw(15) << std::right << "At 486 G4cout << std::setw(15) << std::right << "Atomic nmb ion" << std::setw(25) << std::right 487 << "Material name" << std::setw(25) < 487 << "Material name" << std::setw(25) << std::right << "Atomic nmb material" << G4endl; 488 488 489 for (; iterMat != iterMat_end; ++iterMat) { 489 for (; iterMat != iterMat_end; ++iterMat) { 490 G4IonDEDXKeyMat key = iterMat->first; 490 G4IonDEDXKeyMat key = iterMat->first; 491 G4PhysicsVector* physicsVector = iterMat-> 491 G4PhysicsVector* physicsVector = iterMat->second; 492 492 493 G4int atomicNumberIon = key.first; 493 G4int atomicNumberIon = key.first; 494 G4String matIdentifier = key.second; 494 G4String matIdentifier = key.second; 495 495 496 G4int atomicNumberElem = FindAtomicNumberE 496 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector); 497 497 498 if (physicsVector != nullptr) { 498 if (physicsVector != nullptr) { 499 G4cout << std::setw(15) << std::right << 499 G4cout << std::setw(15) << std::right << atomicNumberIon << std::setw(25) << std::right 500 << matIdentifier << std::setw(25) 500 << matIdentifier << std::setw(25) << std::right; 501 501 502 if (atomicNumberElem > 0) { 502 if (atomicNumberElem > 0) { 503 G4cout << atomicNumberElem; 503 G4cout << atomicNumberElem; 504 } 504 } 505 else { 505 else { 506 G4cout << "N/A"; 506 G4cout << "N/A"; 507 } 507 } 508 508 509 G4cout << G4endl; 509 G4cout << G4endl; 510 } 510 } 511 } 511 } 512 } 512 } 513 513 514 // ########################################### 514 // ######################################################################### 515 515