92 G4int atomicNumberIon,
93 G4int atomicNumberElem
96 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
98 auto iter = dedxMapElements.find(key);
100 return iter != dedxMapElements.end();
106 G4int atomicNumberIon,
110 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
112 auto iter = dedxMapMaterials.find(key);
114 return iter != dedxMapMaterials.end();
120 G4int atomicNumberIon,
121 G4int atomicNumberElem
124 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
126 auto iter = dedxMapElements.find(key);
128 return (iter != dedxMapElements.end()) ? iter->second :
nullptr;
134 G4int atomicNumberIon,
138 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
140 auto iter = dedxMapMaterials.find(key);
142 return (iter != dedxMapMaterials.end()) ? iter->second :
nullptr;
149 G4int atomicNumberIon,
150 G4int atomicNumberElem
153 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
155 auto iter = dedxMapElements.find(key);
157 return ( iter != dedxMapElements.end() ) ?
158 (iter->second)->Value( kinEnergyPerNucleon) : 0.0;
165 G4int atomicNumberIon,
169 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
171 auto iter = dedxMapMaterials.find(key);
173 return (iter != dedxMapMaterials.end()) ?
174 (iter->second)->Value( kinEnergyPerNucleon) : 0.0;
181 G4int atomicNumberIon,
183 G4int atomicNumberElem
186 if(physicsVector ==
nullptr) {
187 G4Exception (
"G4ExtDEDXTable::AddPhysicsVector() for material",
189 "Pointer to vector is null-pointer.");
193 if(matIdentifier.empty()) {
194 G4Exception (
"G4ExtDEDXTable::AddPhysicsVector() for material",
199 if(atomicNumberIon <= 2) {
200 G4Exception (
"G4ExtDEDXTable::AddPhysicsVector() for material",
205 if(atomicNumberElem > 0) {
207 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
209 if(dedxMapElements.count(key) == 1) {
210 G4Exception (
"G4ExtDEDXTable::AddPhysicsVector() for material",
212 "Vector already exist, remove it before replacing.");
216 dedxMapElements[key] = physicsVector;
219 G4IonDEDXKeyMat mkey = std::make_pair(atomicNumberIon, matIdentifier);
221 if(dedxMapMaterials.count(mkey) == 1) {
222 G4Exception (
"G4ExtDEDXTable::AddPhysicsVector() for material",
224 "Vector already exist, remove it before replacing.");
228 dedxMapMaterials[mkey] = physicsVector;
236 G4int atomicNumberIon,
243 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
245 auto iter = dedxMapMaterials.find(key);
247 if(iter == dedxMapMaterials.end()) {
248 G4Exception (
"G4ExtDEDXTable::RemovePhysicsVector() for material",
250 "Pointer to vector is null-pointer.");
254 physicsVector = (*iter).second;
255 dedxMapMaterials.erase(key);
258 G4IonDEDXMapElem::iterator it;
260 for(it=dedxMapElements.begin(); it!=dedxMapElements.end(); ++it) {
262 if( (*it).second == physicsVector ) {
263 dedxMapElements.erase(it);
269 delete physicsVector;
281 std::ofstream ofilestream;
283 ofilestream.open( fileName, std::ios::out );
287 ed <<
"Cannot open file " << fileName;
288 G4Exception (
"G4IonStoppingData::StorePhysicsTable()",
294 size_t nmbMatTables = dedxMapMaterials.size();
298 auto iterMat = dedxMapMaterials.begin();
299 auto iterMat_end = dedxMapMaterials.end();
301 for(;iterMat != iterMat_end; iterMat++) {
302 G4IonDEDXKeyMat key = iterMat -> first;
305 G4int atomicNumberIon = key.first;
306 G4String matIdentifier = key.second;
308 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
310 if(physicsVector !=
nullptr) {
311 ofilestream << atomicNumberIon <<
" " << matIdentifier;
313 if(atomicNumberElem > 0)
315 ofilestream <<
" " << atomicNumberElem;
318 ofilestream <<
" # <Atomic number ion> <Material name> ";
320 if(atomicNumberElem > 0)
322 ofilestream <<
"<Atomic number element>";
325 ofilestream <<
G4endl << physicsVector -> GetType() <<
G4endl;
327 physicsVector -> Store(ofilestream,
true);
331 G4Exception (
"G4IonStoppingData::StorePhysicsTable()",
346 std::ifstream ifilestream;
347 ifilestream.open( fileName, std::ios::in|std::ios::binary );
348 if( ! ifilestream ) {
350 ed <<
"Cannot open file " << fileName;
351 G4Exception (
"G4IonStoppingData::RetrievePhysicsTable()",
357 G4int nmbVectors = 0;
358 ifilestream >> nmbVectors;
359 if( ifilestream.fail() || nmbVectors <= 0) {
360 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
361 <<
" File content of " << fileName <<
" ill-formated."
362 <<
" Nvectors= " << nmbVectors
368 for(
G4int i = 0; i<nmbVectors; ++i) {
372 while( line.empty() ) {
374 getline( ifilestream, line );
375 if( ifilestream.fail() ) {
376 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
377 <<
" File content of " << fileName <<
" ill-formated."
383 std::string::size_type pos = line.find_first_of(
"#");
384 if(pos != std::string::npos && pos > 0) {
385 line = line.substr(0, pos);
389 std::istringstream headerstream( line );
391 std::string::size_type atomicNumberIon;
392 headerstream >> atomicNumberIon;
395 headerstream >> materialName;
397 if( headerstream.fail() || std::string::npos == atomicNumberIon) {
398 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
399 <<
" File content of " << fileName <<
" ill-formated "
400 <<
" (vector header)."
406 std::string::size_type atomicNumberMat;
407 headerstream >> atomicNumberMat;
409 if( headerstream.eof() || std::string::npos == atomicNumberMat) {
414 ifilestream >> vectorType;
418 if(physicsVector ==
nullptr) {
419 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable "
420 <<
" illegal physics Vector type " << vectorType
421 <<
" in " << fileName
427 if( !physicsVector -> Retrieve(ifilestream,
true) ) {
428 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
429 <<
" File content of " << fileName <<
" ill-formated."
434 physicsVector -> FillSecondDerivatives();
438 materialName, (
G4int)atomicNumberMat) ) {
440 delete physicsVector;
457 switch (vectorType) {
474 return physicsVector;
479G4int G4ExtDEDXTable::FindAtomicNumberElement(
483 G4int atomicNumber = 0;
485 auto iter = dedxMapElements.begin();
486 auto iter_end = dedxMapElements.end();
488 for(;iter != iter_end; ++iter) {
490 if( (*iter).second == physicsVector ) {
492 G4IonDEDXKeyElem key = (*iter).first;
493 atomicNumber = key.second;
503 auto iterMat = dedxMapMaterials.begin();
504 auto iterMat_end = dedxMapMaterials.end();
506 for(;iterMat != iterMat_end; ++iterMat) {
513 dedxMapElements.clear();
514 dedxMapMaterials.clear();
520 auto iterMat = dedxMapMaterials.begin();
521 auto iterMat_end = dedxMapMaterials.end();
523 G4cout << std::setw(15) << std::right
525 << std::setw(25) << std::right
527 << std::setw(25) << std::right
528 <<
"Atomic nmb material"
531 for(;iterMat != iterMat_end; ++iterMat) {
532 G4IonDEDXKeyMat key = iterMat -> first;
535 G4int atomicNumberIon = key.first;
536 G4String matIdentifier = key.second;
538 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
540 if(physicsVector !=
nullptr)
542 G4cout << std::setw(15) << std::right << atomicNumberIon
543 << std::setw(25) << std::right << matIdentifier << std::setw(25)
546 if(atomicNumberElem > 0)
548 G4cout << atomicNumberElem;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
@ T_G4PhysicsLinearVector
G4GLOB_DLL std::ostream G4cout
~G4ExtDEDXTable() override
G4double GetDEDX(G4double kinEnergyPerNucleon, G4int atomicNumberIon, G4int atomicNumberElem)
G4bool StorePhysicsTable(const G4String &fileName)
G4PhysicsVector * GetPhysicsVector(G4int atomicNumberIon, G4int atomicNumberElem) override
G4bool RemovePhysicsVector(G4int atomicNumberIon, const G4String &matIdentifier)
G4bool IsApplicable(G4int atomicNumberIon, G4int atomicNumberElem) override
G4bool AddPhysicsVector(G4PhysicsVector *physicsVector, G4int atomicNumberIon, const G4String &matIdenfier, G4int atomicNumberElem=0)
G4bool BuildPhysicsVector(G4int ionZ, const G4String &matName) override
G4bool RetrievePhysicsTable(const G4String &fileName)