87 G4int atomicNumberElem
90 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
92 auto iter = dedxMapElements.find(key);
94 return iter != dedxMapElements.end();
103 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
105 auto iter = dedxMapMaterials.find(key);
107 return iter != dedxMapMaterials.end();
113 G4int atomicNumberElem
116 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
118 auto iter = dedxMapElements.find(key);
120 return (iter != dedxMapElements.end()) ? iter->second :
nullptr;
129 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
131 auto iter = dedxMapMaterials.find(key);
133 return (iter != dedxMapMaterials.end()) ? iter->second :
nullptr;
139 G4int atomicNumberIon,
140 G4int atomicNumberElem
143 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
145 auto iter = dedxMapElements.find(key);
147 return (iter != dedxMapElements.end()) ? (iter->second)->Value(kinEnergyPerNucleon) : 0.0;
153 G4int atomicNumberIon,
157 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
159 auto iter = dedxMapMaterials.find(key);
161 return (iter != dedxMapMaterials.end()) ? (iter->second)->Value(kinEnergyPerNucleon) : 0.0;
167 G4int atomicNumberIon,
169 G4int atomicNumberElem
172 if (physicsVector ==
nullptr) {
174 "Pointer to vector is null-pointer.");
178 if (matIdentifier.empty()) {
180 "Invalid name of the material.");
184 if (atomicNumberIon <= 2) {
186 "Illegal atomic number.");
190 if (atomicNumberElem > 0) {
191 G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
193 if (dedxMapElements.count(key) == 1) {
195 "Vector already exist, remove it before replacing.");
199 dedxMapElements[key] = physicsVector;
202 G4IonDEDXKeyMat mkey = std::make_pair(atomicNumberIon, matIdentifier);
204 if (dedxMapMaterials.count(mkey) == 1) {
206 "Vector already exist, remove it before replacing.");
210 dedxMapMaterials[mkey] = physicsVector;
224 G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
226 auto iter = dedxMapMaterials.find(key);
228 if (iter == dedxMapMaterials.end()) {
230 "Pointer to vector is null-pointer.");
234 physicsVector = (*iter).second;
235 dedxMapMaterials.erase(key);
238 G4IonDEDXMapElem::iterator it;
240 for (it = dedxMapElements.begin(); it != dedxMapElements.end(); ++it) {
241 if ((*it).second == physicsVector) {
242 dedxMapElements.erase(it);
248 delete physicsVector;
260 std::ofstream ofilestream;
262 ofilestream.open(fileName, std::ios::out);
266 ed <<
"Cannot open file " << fileName;
271 size_t nmbMatTables = dedxMapMaterials.size();
275 auto iterMat = dedxMapMaterials.begin();
276 auto iterMat_end = dedxMapMaterials.end();
278 for (; iterMat != iterMat_end; iterMat++) {
279 G4IonDEDXKeyMat key = iterMat->first;
282 G4int atomicNumberIon = key.first;
283 G4String matIdentifier = key.second;
285 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
287 if (physicsVector !=
nullptr) {
288 ofilestream << atomicNumberIon <<
" " << matIdentifier;
290 if (atomicNumberElem > 0) {
291 ofilestream <<
" " << atomicNumberElem;
294 ofilestream <<
" # <Atomic number ion> <Material name> ";
296 if (atomicNumberElem > 0) {
297 ofilestream <<
"<Atomic number element>";
302 physicsVector->
Store(ofilestream,
true);
308 "Cannot store vector.");
322 std::ifstream ifilestream;
323 ifilestream.open(fileName, std::ios::in | std::ios::binary);
326 ed <<
"Cannot open file " << fileName;
332 G4int nmbVectors = 0;
333 ifilestream >> nmbVectors;
334 if (ifilestream.fail() || nmbVectors <= 0) {
335 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
336 <<
" File content of " << fileName <<
" ill-formated."
337 <<
" Nvectors= " << nmbVectors <<
G4endl;
342 for (
G4int i = 0; i < nmbVectors; ++i) {
345 while (line.empty()) {
346 getline(ifilestream, line);
347 if (ifilestream.fail()) {
348 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
349 <<
" File content of " << fileName <<
" ill-formated." <<
G4endl;
354 std::string::size_type pos = line.find_first_of(
'#');
355 if (pos != std::string::npos && pos > 0) {
356 line = line.substr(0, pos);
360 std::istringstream headerstream(line);
362 std::string::size_type atomicNumberIon;
363 headerstream >> atomicNumberIon;
366 headerstream >> materialName;
368 if (headerstream.fail() || std::string::npos == atomicNumberIon) {
369 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
370 <<
" File content of " << fileName <<
" ill-formated "
371 <<
" (vector header)." <<
G4endl;
376 std::string::size_type atomicNumberMat;
377 headerstream >> atomicNumberMat;
379 if (headerstream.eof() || std::string::npos == atomicNumberMat) {
384 ifilestream >> vectorType;
388 if (physicsVector ==
nullptr) {
389 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable "
390 <<
" illegal physics Vector type " << vectorType <<
" in " << fileName <<
G4endl;
395 if (! physicsVector->
Retrieve(ifilestream,
true)) {
396 G4cout <<
"G4ExtDEDXTable::RetrievePhysicsTable() "
397 <<
" File content of " << fileName <<
" ill-formated." <<
G4endl;
405 physicsVector, (
G4int)atomicNumberIon, materialName, (
G4int)atomicNumberMat))
407 delete physicsVector;
424 switch (vectorType) {
440 return physicsVector;
447 G4int atomicNumber = 0;
449 auto iter = dedxMapElements.begin();
450 auto iter_end = dedxMapElements.end();
452 for (; iter != iter_end; ++iter) {
453 if ((*iter).second == physicsVector) {
454 G4IonDEDXKeyElem key = (*iter).first;
455 atomicNumber = key.second;
466 auto iterMat = dedxMapMaterials.begin();
467 auto iterMat_end = dedxMapMaterials.end();
469 for (; iterMat != iterMat_end; ++iterMat) {
475 dedxMapElements.clear();
476 dedxMapMaterials.clear();
483 auto iterMat = dedxMapMaterials.begin();
484 auto iterMat_end = dedxMapMaterials.end();
486 G4cout << std::setw(15) << std::right <<
"Atomic nmb ion" << std::setw(25) << std::right
487 <<
"Material name" << std::setw(25) << std::right <<
"Atomic nmb material" <<
G4endl;
489 for (; iterMat != iterMat_end; ++iterMat) {
490 G4IonDEDXKeyMat key = iterMat->first;
493 G4int atomicNumberIon = key.first;
494 G4String matIdentifier = key.second;
496 G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
498 if (physicsVector !=
nullptr) {
499 G4cout << std::setw(15) << std::right << atomicNumberIon << std::setw(25) << std::right
500 << matIdentifier << std::setw(25) << std::right;
502 if (atomicNumberElem > 0) {
503 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)
G4bool Store(std::ofstream &fOut, G4bool ascii=false) const
G4PhysicsVectorType GetType() const
G4bool Retrieve(std::ifstream &fIn, G4bool ascii=false)
void FillSecondDerivatives(const G4SplineType=G4SplineType::Base, const G4double dir1=0.0, const G4double dir2=0.0)