G4ExtDEDXTable Class Reference

#include <G4ExtDEDXTable.hh>

Inheritance diagram for G4ExtDEDXTable:

G4VIonDEDXTable

Public Member Functions

 G4ExtDEDXTable ()
virtual ~G4ExtDEDXTable ()
G4bool BuildPhysicsVector (G4int ionZ, const G4String &matName)
G4bool BuildPhysicsVector (G4int ionZ, G4int matZ)
G4bool IsApplicable (G4int atomicNumberIon, G4int atomicNumberElem)
G4bool IsApplicable (G4int atomicNumberIon, const G4String &matIdentifier)
G4PhysicsVectorGetPhysicsVector (G4int atomicNumberIon, G4int atomicNumberElem)
G4PhysicsVectorGetPhysicsVector (G4int atomicNumberIon, const G4String &matIdenfier)
G4double GetDEDX (G4double kinEnergyPerNucleon, G4int atomicNumberIon, G4int atomicNumberElem)
G4double GetDEDX (G4double kinEnergyPerNucleon, G4int atomicNumberIon, const G4String &matIdenfier)
G4bool AddPhysicsVector (G4PhysicsVector *physicsVector, G4int atomicNumberIon, const G4String &matIdenfier, G4int atomicNumberElem=0)
G4bool RemovePhysicsVector (G4int atomicNumberIon, const G4String &matIdentifier)
G4bool StorePhysicsTable (const G4String &fileName)
G4bool RetrievePhysicsTable (const G4String &fileName)
void ClearTable ()
void DumpMap ()

Detailed Description

Definition at line 64 of file G4ExtDEDXTable.hh.


Constructor & Destructor Documentation

G4ExtDEDXTable::G4ExtDEDXTable (  ) 

Definition at line 73 of file G4ExtDEDXTable.cc.

00073                                {
00074 
00075 }

G4ExtDEDXTable::~G4ExtDEDXTable (  )  [virtual]

Definition at line 79 of file G4ExtDEDXTable.cc.

References ClearTable().

00079                                 {
00080 
00081   ClearTable();
00082 }


Member Function Documentation

G4bool G4ExtDEDXTable::AddPhysicsVector ( G4PhysicsVector physicsVector,
G4int  atomicNumberIon,
const G4String matIdenfier,
G4int  atomicNumberElem = 0 
)

Definition at line 216 of file G4ExtDEDXTable.cc.

References G4cout, and G4endl.

Referenced by RetrievePhysicsTable().

00221                                         {
00222 
00223   if(physicsVector == 0) {
00224 
00225 #ifdef G4VERBOSE
00226      G4cout << "G4IonDEDXTable::AddPhysicsVector() Error: Pointer to vector"
00227             << " is null-pointer."
00228             << G4endl;
00229 #endif
00230 
00231      return false;
00232   }
00233 
00234   if(matIdentifier.empty()) {
00235 
00236 #ifdef G4VERBOSE
00237      G4cout << "G4IonDEDXTable::AddPhysicsVector() Error: "
00238             << "Cannot add physics vector. Invalid name."
00239             << G4endl;
00240 #endif
00241 
00242      return false;
00243   }
00244 
00245   if(atomicNumberIon <= 2) {
00246 
00247 #ifdef G4VERBOSE
00248      G4cout << "G4IonDEDXTable::AddPhysicsVector() Error: "
00249             << "Cannot add physics vector. Illegal atomic number."
00250             << G4endl;
00251 #endif
00252 
00253      return false;
00254   }
00255 
00256   if(atomicNumberElem > 0) {
00257 
00258      G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
00259 
00260      if(dedxMapElements.count(key) == 1) {
00261 
00262 #ifdef G4VERBOSE
00263         G4cout << "G4IonDEDXTable::AddPhysicsVector() Error: "
00264                << "Vector already exists. Remove first before replacing."
00265                << G4endl;
00266 #endif
00267         return false;
00268      }
00269 
00270      dedxMapElements[key] = physicsVector;
00271   }
00272 
00273   G4IonDEDXKeyMat mkey = std::make_pair(atomicNumberIon, matIdentifier);
00274 
00275   if(dedxMapMaterials.count(mkey) == 1) {
00276 
00277 #ifdef G4VERBOSE
00278      G4cout << "G4IonDEDXTable::AddPhysicsVector() Error: "
00279             << "Vector already exists. Remove first before replacing."
00280             << G4endl;
00281 #endif
00282 
00283      return false;
00284   }
00285 
00286   dedxMapMaterials[mkey] = physicsVector;
00287 
00288   return true;
00289 }

G4bool G4ExtDEDXTable::BuildPhysicsVector ( G4int  ionZ,
G4int  matZ 
) [virtual]

Implements G4VIonDEDXTable.

Definition at line 86 of file G4ExtDEDXTable.cc.

References IsApplicable().

00086                                                                 {
00087 
00088   return IsApplicable( ionZ, matZ );
00089 }

G4bool G4ExtDEDXTable::BuildPhysicsVector ( G4int  ionZ,
const G4String matName 
) [virtual]

Implements G4VIonDEDXTable.

Definition at line 94 of file G4ExtDEDXTable.cc.

References IsApplicable().

00095                                                                    {
00096 
00097   return IsApplicable( ionZ, matName );
00098 }

void G4ExtDEDXTable::ClearTable (  ) 

Definition at line 600 of file G4ExtDEDXTable.cc.

Referenced by ~G4ExtDEDXTable().

00600                                 {
00601 
00602   G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
00603   G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
00604 
00605   for(;iterMat != iterMat_end; iterMat++) { 
00606 
00607     G4PhysicsVector* vec = iterMat -> second;
00608 
00609     if(vec != 0) delete vec;
00610   }
00611 
00612   dedxMapElements.clear();
00613   dedxMapMaterials.clear();
00614 }

void G4ExtDEDXTable::DumpMap (  ) 

Definition at line 618 of file G4ExtDEDXTable.cc.

References G4cout, and G4endl.

00618                              {
00619 
00620   G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
00621   G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
00622 
00623   G4cout << std::setw(15) << std::right
00624          << "Atomic nmb ion"
00625          << std::setw(25) << std::right
00626          << "Material name"
00627          << std::setw(25) << std::right
00628          << "Atomic nmb material"
00629          << G4endl;
00630 
00631   for(;iterMat != iterMat_end; iterMat++) {
00632       G4IonDEDXKeyMat key = iterMat -> first;
00633       G4PhysicsVector* physicsVector = iterMat -> second; 
00634 
00635       G4int atomicNumberIon = key.first;
00636       G4String matIdentifier = key.second;
00637 
00638       G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
00639 
00640       if(physicsVector != 0) {
00641          G4cout << std::setw(15) << std::right
00642                 << atomicNumberIon
00643                 << std::setw(25) << std::right
00644                 << matIdentifier
00645                 << std::setw(25) << std::right;
00646 
00647          if(atomicNumberElem > 0) G4cout << atomicNumberElem;
00648          else G4cout << "N/A";
00649 
00650          G4cout << G4endl;
00651       }
00652   }
00653 
00654 }

G4double G4ExtDEDXTable::GetDEDX ( G4double  kinEnergyPerNucleon,
G4int  atomicNumberIon,
const G4String matIdenfier 
)

Definition at line 193 of file G4ExtDEDXTable.cc.

00197                                     {
00198   G4double dedx = 0;
00199 
00200   G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
00201 
00202   G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
00203 
00204   if(iter != dedxMapMaterials.end()) {
00205      G4PhysicsVector* physicsVector = iter -> second; 
00206 
00207      G4bool b;
00208      dedx = physicsVector -> GetValue( kinEnergyPerNucleon, b );   
00209   }
00210 
00211   return dedx; 
00212 }

G4double G4ExtDEDXTable::GetDEDX ( G4double  kinEnergyPerNucleon,
G4int  atomicNumberIon,
G4int  atomicNumberElem 
)

Definition at line 170 of file G4ExtDEDXTable.cc.

00174                                     {
00175   G4double dedx = 0;
00176 
00177   G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
00178 
00179   G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
00180 
00181   if( iter != dedxMapElements.end() ) {
00182      G4PhysicsVector* physicsVector = iter -> second; 
00183 
00184      G4bool b;
00185      dedx = physicsVector -> GetValue( kinEnergyPerNucleon, b );   
00186   }
00187 
00188   return dedx; 
00189 }

G4PhysicsVector * G4ExtDEDXTable::GetPhysicsVector ( G4int  atomicNumberIon,
const G4String matIdenfier 
) [virtual]

Implements G4VIonDEDXTable.

Definition at line 152 of file G4ExtDEDXTable.cc.

00155                                       {
00156 
00157   G4PhysicsVector* physVector = 0;
00158 
00159   G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
00160 
00161   G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
00162 
00163   if(iter != dedxMapMaterials.end()) physVector = iter -> second; 
00164 
00165   return physVector; 
00166 }

G4PhysicsVector * G4ExtDEDXTable::GetPhysicsVector ( G4int  atomicNumberIon,
G4int  atomicNumberElem 
) [virtual]

Implements G4VIonDEDXTable.

Definition at line 134 of file G4ExtDEDXTable.cc.

00137                                       {
00138 
00139   G4PhysicsVector* physVector = 0;
00140 
00141   G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
00142 
00143   G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
00144 
00145   if(iter != dedxMapElements.end()) physVector = iter -> second; 
00146 
00147   return physVector; 
00148 }

G4bool G4ExtDEDXTable::IsApplicable ( G4int  atomicNumberIon,
const G4String matIdentifier 
) [virtual]

Implements G4VIonDEDXTable.

Definition at line 118 of file G4ExtDEDXTable.cc.

00121                                       {
00122   G4bool isApplicable = true; 
00123   G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
00124 
00125   G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
00126 
00127   if(iter == dedxMapMaterials.end()) isApplicable = false; 
00128 
00129   return isApplicable; 
00130 }

G4bool G4ExtDEDXTable::IsApplicable ( G4int  atomicNumberIon,
G4int  atomicNumberElem 
) [virtual]

Implements G4VIonDEDXTable.

Definition at line 102 of file G4ExtDEDXTable.cc.

Referenced by BuildPhysicsVector().

00105                                       {
00106   G4bool isApplicable = true; 
00107   G4IonDEDXKeyElem key = std::make_pair(atomicNumberIon, atomicNumberElem);
00108 
00109   G4IonDEDXMapElem::iterator iter = dedxMapElements.find(key);
00110 
00111   if(iter == dedxMapElements.end()) isApplicable = false; 
00112 
00113   return isApplicable; 
00114 }

G4bool G4ExtDEDXTable::RemovePhysicsVector ( G4int  atomicNumberIon,
const G4String matIdentifier 
)

Definition at line 293 of file G4ExtDEDXTable.cc.

References G4cout, and G4endl.

00296                                         {
00297 
00298   G4PhysicsVector* physicsVector = 0;
00299 
00300   // Deleting key of physics vector from material map
00301   G4IonDEDXKeyMat key = std::make_pair(atomicNumberIon, matIdentifier);
00302 
00303   G4IonDEDXMapMat::iterator iter = dedxMapMaterials.find(key);
00304 
00305   if(iter == dedxMapMaterials.end()) {
00306 
00307 #ifdef G4VERBOSE
00308     G4cout << "G4IonDEDXTable::RemovePhysicsVector() Warning: "
00309            << "Cannot remove physics vector. Vector not found."
00310            << G4endl;
00311 #endif
00312 
00313     return false;
00314   }
00315 
00316   physicsVector = (*iter).second;
00317   dedxMapMaterials.erase(key);
00318 
00319   // Deleting key of physics vector from elemental material map (if it exists)
00320   G4IonDEDXMapElem::iterator it;
00321   
00322   for(it=dedxMapElements.begin(); it!=dedxMapElements.end(); ++it) {
00323 
00324      if( (*it).second == physicsVector ) {
00325         dedxMapElements.erase(it);
00326         break;
00327      }
00328   }
00329 
00330   // Deleting physics vector
00331   delete physicsVector;
00332 
00333   return true;
00334 }

G4bool G4ExtDEDXTable::RetrievePhysicsTable ( const G4String fileName  ) 

Definition at line 409 of file G4ExtDEDXTable.cc.

References AddPhysicsVector(), G4cout, and G4endl.

00410 { 
00411   std::ifstream ifilestream;
00412   ifilestream.open( fileName, std::ios::in|std::ios::binary );
00413   if( ! ifilestream ) {
00414 #ifdef G4VERBOSE
00415     G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() " 
00416            << " Cannot open file "<< fileName 
00417            << G4endl;
00418 #endif
00419     return false;
00420   }   
00421 
00422   //std::string::size_type nmbVectors;
00423   G4int nmbVectors;
00424   ifilestream >> nmbVectors;
00425   if( ifilestream.fail() ) { 
00426     G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() " 
00427            << " File content of " << fileName << " ill-formated." 
00428            << G4endl;     
00429     ifilestream.close(); 
00430     return false; 
00431   }
00432 
00433   //  if(nmbVectors == std::string::npos) {
00434   /*
00435   if(nmbVectors <= 0) {
00436 #ifdef G4VERBOSE
00437     G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() " 
00438            << " The file is corrupted " << G4endl;
00439 #endif
00440     return false;
00441   }  
00442   */
00443   //size_t nm = size_t(nmbVectors);
00444   for(G4int i = 0; i<nmbVectors; ++i) {
00445 
00446     G4String line = "";
00447     while( line.empty() ) {
00448 
00449       getline( ifilestream, line );
00450       if( ifilestream.fail() ) { 
00451 #ifdef G4VERBOSE  
00452         G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() " 
00453                << " File content of " << fileName << " ill-formated." 
00454                << G4endl;
00455 #endif          
00456         ifilestream.close(); 
00457         return false; 
00458       }
00459 
00460       std::string::size_type pos = line.find_first_of("#");
00461       if(pos != std::string::npos && pos > 0) {
00462         line = line.substr(0, pos);
00463       }
00464     }
00465 
00466     std::istringstream headerstream( line );     
00467 
00468     std::string::size_type atomicNumberIon;
00469     headerstream >> atomicNumberIon;
00470 
00471     G4String materialName;
00472     headerstream >> materialName;
00473 
00474     if( headerstream.fail() || std::string::npos == atomicNumberIon) {
00475  
00476 #ifdef G4VERBOSE  
00477       G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() " 
00478              << " File content of " << fileName << " ill-formated "
00479              << " (vector header)." 
00480              << G4endl;
00481 #endif          
00482       ifilestream.close();
00483       return false;
00484     } 
00485 
00486     std::string::size_type atomicNumberMat;
00487     headerstream >> atomicNumberMat;
00488 
00489     if( headerstream.eof() || std::string::npos == atomicNumberMat) { 
00490       atomicNumberMat = 0; 
00491     }
00492 
00493     G4int vectorType;
00494     ifilestream >> vectorType;
00495       
00496     G4PhysicsVector* physicsVector = CreatePhysicsVector(vectorType);
00497 
00498     if(physicsVector == 0) {
00499 #ifdef G4VERBOSE  
00500       G4cout << "G4ExtDEDXTable::RetrievePhysicsTable  "
00501              << " illegal physics Vector type " << vectorType
00502              << " in  " << fileName 
00503              << G4endl;
00504 #endif          
00505       ifilestream.close();
00506       return false;
00507     }
00508 
00509     if( !physicsVector -> Retrieve(ifilestream, true) ) {
00510         
00511 #ifdef G4VERBOSE  
00512       G4cout << "G4ExtDEDXTable::RetrievePhysicsTable() " 
00513              << " File content of " << fileName << " ill-formated." 
00514              << G4endl;
00515 #endif          
00516       ifilestream.close();
00517       return false;
00518     } 
00519 
00520     physicsVector -> SetSpline(true);
00521 
00522     // Retrieved vector is added to material store
00523     if( !AddPhysicsVector(physicsVector, (G4int)atomicNumberIon, 
00524                           materialName, (G4int)atomicNumberMat) ) {
00525 
00526       delete physicsVector;
00527       ifilestream.close();
00528       return false;
00529     }
00530   }
00531 
00532   ifilestream.close();
00533 
00534   return true;
00535 }

G4bool G4ExtDEDXTable::StorePhysicsTable ( const G4String fileName  ) 

Definition at line 338 of file G4ExtDEDXTable.cc.

References G4cout, and G4endl.

00340                                       {
00341   G4bool success = true;
00342 
00343   std::ofstream ofilestream;
00344 
00345   ofilestream.open( fileName, std::ios::out );
00346 
00347   if( !ofilestream ) {
00348 
00349 #ifdef G4VERBOSE
00350      G4cout << "G4ExtDEDXTable::StorePhysicsVector() " 
00351             << " Cannot open file "<< fileName 
00352             << G4endl;
00353 #endif
00354       
00355      success = false;
00356   }   
00357   else {
00358 
00359      size_t nmbMatTables = dedxMapMaterials.size();
00360 
00361      ofilestream << nmbMatTables << G4endl << G4endl; 
00362 
00363      G4IonDEDXMapMat::iterator iterMat = dedxMapMaterials.begin();
00364      G4IonDEDXMapMat::iterator iterMat_end = dedxMapMaterials.end();
00365 
00366      for(;iterMat != iterMat_end; iterMat++) {
00367          G4IonDEDXKeyMat key = iterMat -> first;
00368          G4PhysicsVector* physicsVector = iterMat -> second; 
00369 
00370          G4int atomicNumberIon = key.first;
00371          G4String matIdentifier = key.second;
00372 
00373          G4int atomicNumberElem = FindAtomicNumberElement(physicsVector);
00374 
00375          if(physicsVector != 0) {
00376             ofilestream << atomicNumberIon << "  " << matIdentifier;
00377 
00378             if(atomicNumberElem > 0) ofilestream << "  " << atomicNumberElem;
00379 
00380             ofilestream << "  # <Atomic number ion>  <Material name>  ";
00381 
00382             if(atomicNumberElem > 0) ofilestream << "<Atomic number element>";
00383 
00384             ofilestream << G4endl << physicsVector -> GetType() << G4endl;
00385 
00386             physicsVector -> Store(ofilestream, true);
00387 
00388             ofilestream << G4endl;
00389          }
00390          else {
00391 
00392 #ifdef G4VERBOSE
00393               G4cout << "G4ExtDEDXTable::StorePhysicsVector() " 
00394                      << " Cannot store physics vector." 
00395                      << G4endl;
00396 #endif
00397 
00398          }
00399      }
00400   }
00401 
00402   ofilestream.close();
00403 
00404   return success; 
00405 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:51:57 2013 for Geant4 by  doxygen 1.4.7