103 G4int atomicNumberIon,
104 G4int atomicNumberElem
107 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
109 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
111 return (iter == dedxMapElements.end()) ?
false :
true;
117 G4int atomicNumberIon,
121 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
123 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
125 return (iter == dedxMapMaterials.end()) ?
false :
true;
131 G4int atomicNumberIon,
132 G4int atomicNumberElem
135 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
137 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
139 return (iter != dedxMapElements.end()) ? iter->second :
nullptr;
145 G4int atomicNumberIon,
149 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
151 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
153 return (iter != dedxMapMaterials.end()) ? iter->second :
nullptr;
160 G4int atomicNumberIon,
161 G4int atomicNumberElem
164 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
166 G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
168 return ( iter != dedxMapElements.end() ) ?
169 (iter->second)->Value( kinEnergyPerNucleon) : 0.0;
176 G4int atomicNumberIon,
180 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
182 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
184 return (iter != dedxMapMaterials.end()) ?
185 (iter->second)->Value( kinEnergyPerNucleon) : 0.0;
192 G4int atomicNumberIon,
194 G4int atomicNumberElem
197 if(physicsVector ==
nullptr) {
198 G4Exception (
"G4ExtDEDXTable::AddPhysicsVector() for material",
200 "Pointer to vector is null-pointer.");
204 if(matIdentifier.empty()) {
205 G4Exception (
"G4ExtDEDXTable::AddPhysicsVector() for material",
210 if(atomicNumberIon <= 2) {
211 G4Exception (
"G4ExtDEDXTable::AddPhysicsVector() for material",
216 if(atomicNumberElem > 0) {
218 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
220 if(dedxMapElements.count(key) == 1) {
221 G4Exception (
"G4ExtDEDXTable::AddPhysicsVector() for material",
223 "Vector already exist, remove it before replacing.");
227 dedxMapElements[key] = physicsVector;
230 G4IonDEDXKeyMat mkey = std::make_pair(atomicNumberIon, matIdentifier);
232 if(dedxMapMaterials.count(mkey) == 1) {
233 G4Exception (
"G4ExtDEDXTable::AddPhysicsVector() for material",
235 "Vector already exist, remove it before replacing.");
239 dedxMapMaterials[mkey] = physicsVector;
247 G4int atomicNumberIon,
254 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
256 G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
258 if(iter == dedxMapMaterials.end()) {
259 G4Exception (
"G4ExtDEDXTable::RemovePhysicsVector() for material",
261 "Pointer to vector is null-pointer.");
265 physicsVector = (*iter).second;
266 dedxMapMaterials.erase(key);
269 G4IonDEDXMapElem::iterator it;
271 for(it=dedxMapElements.begin(); it!=dedxMapElements.end(); ++it) {
273 if( (*it).second == physicsVector ) {
274 dedxMapElements.erase(it);
280 delete physicsVector;
292 std::ofstream ofilestream;
294 ofilestream.open( fileName, std::ios::out );
298 ed <<
"Cannot open file " << fileName;
299 G4Exception (
"G4IonStoppingData::StorePhysicsTable()",
305 size_t nmbMatTables = dedxMapMaterials.size();
309 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
310 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
312 for(;iterMat != iterMat_end; iterMat++) {
313 G4IonDEDXKeyMat key = iterMat ->
first;
316 G4int atomicNumberIon = key.first;
317 G4String matIdentifier = key.second;
319 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
321 if(physicsVector !=
nullptr) {
322 ofilestream << atomicNumberIon <<
" " << matIdentifier;
324 if(atomicNumberElem > 0) ofilestream <<
" " << atomicNumberElem;
326 ofilestream <<
" # <Atomic number ion> <Material name> ";
328 if(atomicNumberElem > 0) ofilestream <<
"<Atomic number element>";
330 ofilestream << G4endl << physicsVector -> GetType() <<
G4endl;
332 physicsVector -> Store(ofilestream,
true);
336 G4Exception (
"G4IonStoppingData::StorePhysicsTable()",
351 std::ifstream ifilestream;
352 ifilestream.open( fileName, std::ios::in|std::ios::binary );
353 if( ! ifilestream ) {
355 ed <<
"Cannot open file " << fileName;
356 G4Exception (
"G4IonStoppingData::RetrievePhysicsTable()",
362 G4int nmbVectors = 0;
363 ifilestream >> nmbVectors;
364 if( ifilestream.fail() || nmbVectors <= 0) {
365 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
366 <<
" File content of " << fileName <<
" ill-formated."
367 <<
" Nvectors= " << nmbVectors
373 for(
G4int i = 0; i<nmbVectors; ++i) {
377 while( line.empty() ) {
379 getline( ifilestream, line );
380 if( ifilestream.fail() ) {
381 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
382 <<
" File content of " << fileName <<
" ill-formated."
388 std::string::size_type
pos = line.find_first_of(
"#");
389 if(pos != std::string::npos && pos > 0) {
390 line = line.substr(0, pos);
394 std::istringstream headerstream( line );
396 std::string::size_type atomicNumberIon;
397 headerstream >> atomicNumberIon;
400 headerstream >> materialName;
402 if( headerstream.fail() || std::string::npos == atomicNumberIon) {
403 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
404 <<
" File content of " << fileName <<
" ill-formated "
405 <<
" (vector header)."
411 std::string::size_type atomicNumberMat;
412 headerstream >> atomicNumberMat;
414 if( headerstream.eof() || std::string::npos == atomicNumberMat) {
419 ifilestream >> vectorType;
423 if(physicsVector ==
nullptr) {
424 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable "
425 <<
" illegal physics Vector type " << vectorType
426 <<
" in " << fileName
432 if( !physicsVector -> Retrieve(ifilestream,
true) ) {
433 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
434 <<
" File content of " << fileName <<
" ill-formated."
440 physicsVector -> SetSpline(
true);
444 materialName, (
G4int)atomicNumberMat) ) {
446 delete physicsVector;
463 switch (vectorType) {
492 return physicsVector;
497 G4int G4ExtDEDXTable::FindAtomicNumberElement(
501 G4int atomicNumber = 0;
503 G4IonDEDXMapElem::iterator iter = dedxMapElements.begin();
504 G4IonDEDXMapElem::iterator iter_end = dedxMapElements.end();
506 for(;iter != iter_end; iter++) {
508 if( (*iter).second == physicsVector ) {
510 G4IonDEDXKeyElem key = (*iter).first;
511 atomicNumber = key.second;
522 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
523 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
525 for(;iterMat != iterMat_end; iterMat++) {
529 if(vec != 0)
delete vec;
532 dedxMapElements.clear();
533 dedxMapMaterials.clear();
540 G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
541 G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
548 <<
"Atomic nmb material"
551 for(;iterMat != iterMat_end; iterMat++) {
552 G4IonDEDXKeyMat key = iterMat ->
first;
555 G4int atomicNumberIon = key.first;
556 G4String matIdentifier = key.second;
558 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
560 if(physicsVector != 0) {
567 if(atomicNumberElem > 0)
G4cout << atomicNumberElem;
G4double GetDEDX(G4double kinEnergyPerNucleon, G4int atomicNumberIon, G4int atomicNumberElem)
std::ostringstream G4ExceptionDescription
G4bool RetrievePhysicsTable(const G4String &fileName)
static constexpr double second
G4bool RemovePhysicsVector(G4int atomicNumberIon, const G4String &matIdentifier)
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4bool AddPhysicsVector(G4PhysicsVector *physicsVector, G4int atomicNumberIon, const G4String &matIdenfier, G4int atomicNumberElem=0)
virtual G4PhysicsVector * GetPhysicsVector(G4int atomicNumberIon, G4int atomicNumberElem)
G4bool StorePhysicsTable(const G4String &fileName)
virtual G4bool BuildPhysicsVector(G4int ionZ, const G4String &matName)
virtual ~G4ExtDEDXTable()
G4PhysicsLogVector G4PhysicsLnVector
static const G4double pos
virtual G4bool IsApplicable(G4int atomicNumberIon, G4int atomicNumberElem)