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