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