G4ShellEMDataSet Class Reference

#include <G4ShellEMDataSet.hh>

Inheritance diagram for G4ShellEMDataSet:

G4VEMDataSet

Public Member Functions

 G4ShellEMDataSet (G4int Z, G4VDataSetAlgorithm *algo, G4double eUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
virtual ~G4ShellEMDataSet ()
virtual G4double FindValue (G4double energy, G4int componentId=0) const
virtual void PrintData (void) const
virtual const G4VEMDataSetGetComponent (G4int componentId) const
virtual void AddComponent (G4VEMDataSet *dataSet)
virtual size_t NumberOfComponents (void) const
virtual const G4DataVectorGetEnergies (G4int componentId) const
virtual const G4DataVectorGetData (G4int componentId) const
virtual const G4DataVectorGetLogEnergies (G4int componentId) const
virtual const G4DataVectorGetLogData (G4int componentId) const
virtual void SetEnergiesData (G4DataVector *energies, G4DataVector *data, G4int componentId)
virtual void SetLogEnergiesData (G4DataVector *energies, G4DataVector *data, G4DataVector *log_energies, G4DataVector *log_data, G4int componentId)
virtual G4bool LoadData (const G4String &fileName)
virtual G4bool LoadNonLogData (const G4String &fileName)
virtual G4bool SaveData (const G4String &fileName) const
virtual G4double RandomSelect (G4int) const

Protected Member Functions

G4double GetUnitEnergies () const
G4double GetUnitData () const
const G4VDataSetAlgorithmGetAlgorithm () const
void CleanUpComponents (void)

Detailed Description

Definition at line 60 of file G4ShellEMDataSet.hh.


Constructor & Destructor Documentation

G4ShellEMDataSet::G4ShellEMDataSet ( G4int  Z,
G4VDataSetAlgorithm algo,
G4double  eUnit = CLHEP::MeV,
G4double  dataUnit = CLHEP::barn 
)

Definition at line 64 of file G4ShellEMDataSet.cc.

References FatalErrorInArgument, G4Exception(), and G4ShellEMDataSet().

Referenced by G4ShellEMDataSet().

00067   :
00068   z(zeta),
00069   algorithm(algo),
00070   unitEnergies(eUnit),
00071   unitData(dataUnit)
00072 {
00073   if (algorithm == 0) G4Exception("G4ShellEMDataSet::G4ShellEMDataSet()","em0007",FatalErrorInArgument, "Interpolation == 0");
00074 }

G4ShellEMDataSet::~G4ShellEMDataSet (  )  [virtual]

Definition at line 77 of file G4ShellEMDataSet.cc.

References CleanUpComponents().

00078 {
00079   CleanUpComponents();
00080   if (algorithm) delete algorithm;
00081 }


Member Function Documentation

virtual void G4ShellEMDataSet::AddComponent ( G4VEMDataSet dataSet  )  [inline, virtual]

Implements G4VEMDataSet.

Definition at line 75 of file G4ShellEMDataSet.hh.

Referenced by LoadData(), and LoadNonLogData().

00075 { components.push_back(dataSet); }

void G4ShellEMDataSet::CleanUpComponents ( void   )  [protected]

Definition at line 389 of file G4ShellEMDataSet.cc.

Referenced by LoadData(), LoadNonLogData(), and ~G4ShellEMDataSet().

00390 {
00391   while (!components.empty())
00392     {
00393       if (components.back()) delete components.back();
00394       components.pop_back();
00395     }
00396 }

G4double G4ShellEMDataSet::FindValue ( G4double  energy,
G4int  componentId = 0 
) const [virtual]

Implements G4VEMDataSet.

Definition at line 84 of file G4ShellEMDataSet.cc.

00085 {
00086   // Returns the sum over the shells corresponding to e
00087   G4double value = 0.;
00088 
00089   std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
00090   std::vector<G4VEMDataSet *>::const_iterator end(components.end());
00091 
00092   while (i != end)
00093     {
00094       value += (*i)->FindValue(energy);
00095       i++;
00096     }
00097 
00098   return value;
00099 }

const G4VDataSetAlgorithm* G4ShellEMDataSet::GetAlgorithm (  )  const [inline, protected]

Definition at line 101 of file G4ShellEMDataSet.hh.

00101 { return algorithm; }

virtual const G4VEMDataSet* G4ShellEMDataSet::GetComponent ( G4int  componentId  )  const [inline, virtual]

Implements G4VEMDataSet.

Definition at line 74 of file G4ShellEMDataSet.hh.

Referenced by GetData(), GetEnergies(), GetLogData(), GetLogEnergies(), PrintData(), and SaveData().

00074 { return components[componentId]; }

virtual const G4DataVector& G4ShellEMDataSet::GetData ( G4int  componentId  )  const [inline, virtual]

Implements G4VEMDataSet.

Definition at line 79 of file G4ShellEMDataSet.hh.

References GetComponent(), and G4VEMDataSet::GetData().

00079 { return GetComponent(componentId)->GetData(0); }

virtual const G4DataVector& G4ShellEMDataSet::GetEnergies ( G4int  componentId  )  const [inline, virtual]

Implements G4VEMDataSet.

Definition at line 78 of file G4ShellEMDataSet.hh.

References GetComponent(), and G4VEMDataSet::GetEnergies().

00078 { return GetComponent(componentId)->GetEnergies(0); }

virtual const G4DataVector& G4ShellEMDataSet::GetLogData ( G4int  componentId  )  const [inline, virtual]

Implements G4VEMDataSet.

Definition at line 81 of file G4ShellEMDataSet.hh.

References GetComponent(), and G4VEMDataSet::GetLogData().

00081 { return GetComponent(componentId)->GetLogData(0); }

virtual const G4DataVector& G4ShellEMDataSet::GetLogEnergies ( G4int  componentId  )  const [inline, virtual]

Implements G4VEMDataSet.

Definition at line 80 of file G4ShellEMDataSet.hh.

References GetComponent(), and G4VEMDataSet::GetLogEnergies().

00080 { return GetComponent(componentId)->GetLogEnergies(0); }

G4double G4ShellEMDataSet::GetUnitData (  )  const [inline, protected]

Definition at line 100 of file G4ShellEMDataSet.hh.

00100 { return unitData; }

G4double G4ShellEMDataSet::GetUnitEnergies (  )  const [inline, protected]

Definition at line 99 of file G4ShellEMDataSet.hh.

00099 { return unitEnergies; }

G4bool G4ShellEMDataSet::LoadData ( const G4String fileName  )  [virtual]

Implements G4VEMDataSet.

Definition at line 160 of file G4ShellEMDataSet.cc.

References AddComponent(), CleanUpComponents(), G4VDataSetAlgorithm::Clone(), FatalException, and G4Exception().

00161 {
00162   CleanUpComponents();
00163 
00164   G4String fullFileName = FullFileName(file);
00165   std::ifstream in(fullFileName);
00166 
00167   if (!in.is_open())
00168     {
00169       G4String message("Data file \"");
00170       message += fullFileName;
00171       message += "\" not found";
00172       G4Exception("G4ShellEMDataSet::LoadData()", "em0003",FatalException, message);
00173       return 0;
00174     }
00175 
00176   G4DataVector* orig_shell_energies = 0;
00177   G4DataVector* orig_shell_data = 0;
00178   G4DataVector* log_shell_energies = 0;
00179   G4DataVector* log_shell_data = 0;
00180 
00181   G4double a = 0.;
00182   G4int shellIndex = 0;
00183   G4int k = 0;
00184   G4int nColumns = 2;
00185 
00186   do
00187     {
00188       in >> a;
00189 
00190       if (a==0.) a=1e-300;
00191 
00192       // The file is organized into four columns:
00193       // 1st column contains the values of energy
00194       // 2nd column contains the corresponding data value
00195       // The file terminates with the pattern: -1   -1
00196       //                                       -2   -2
00197       //
00198       if (a == -1)
00199         {
00200           if ((k%nColumns == 0) && (orig_shell_energies != 0) )
00201             {
00202              AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, log_shell_energies, log_shell_data, algorithm->Clone(), unitEnergies, unitData));
00203               orig_shell_energies = 0;
00204               orig_shell_data = 0;
00205               log_shell_energies = 0;
00206               log_shell_data = 0;
00207             }
00208         }
00209       else if (a != -2)
00210         {
00211           if (orig_shell_energies == 0)
00212             {
00213              orig_shell_energies = new G4DataVector;
00214              orig_shell_data = new G4DataVector;
00215              log_shell_energies = new G4DataVector;
00216              log_shell_data = new G4DataVector;
00217             }
00218           if (k%nColumns == 0)
00219             {
00220              orig_shell_energies->push_back(a*unitEnergies);
00221              log_shell_energies->push_back(std::log10(a) + std::log10(unitEnergies));
00222             }
00223           else if (k%nColumns == 1)
00224             {
00225              orig_shell_data->push_back(a*unitData);
00226              log_shell_data->push_back(std::log10(a) + std::log10(unitData));
00227             }
00228           k++;
00229         }
00230       else k = 1;
00231     }
00232   while (a != -2);  // End of file
00233  
00234 
00235   delete orig_shell_energies;
00236   delete orig_shell_data;
00237   delete log_shell_energies;
00238   delete log_shell_data;
00239 
00240   return true;
00241 }

G4bool G4ShellEMDataSet::LoadNonLogData ( const G4String fileName  )  [virtual]

Implements G4VEMDataSet.

Definition at line 244 of file G4ShellEMDataSet.cc.

References AddComponent(), CleanUpComponents(), G4VDataSetAlgorithm::Clone(), FatalException, and G4Exception().

00245 {
00246   CleanUpComponents();
00247 
00248   G4String fullFileName = FullFileName(file);
00249   std::ifstream in(fullFileName);
00250 
00251   if (!in.is_open())
00252     {
00253       G4String message("G4ShellEMDataSet::LoadData - data file \"");
00254       message += fullFileName;
00255       message += "\" not found";
00256       G4Exception("G4ShellEMDataSet::LoadNonLogData()", "em0003",FatalException, message);
00257       return 0;
00258     }
00259 
00260   G4DataVector* orig_shell_energies = 0;
00261   G4DataVector* orig_shell_data = 0;
00262 
00263   G4double a = 0.;
00264   G4int shellIndex = 0;
00265   G4int k = 0;
00266   G4int nColumns = 2;
00267 
00268   do
00269     {
00270       in >> a;
00271 
00272       // The file is organized into four columns:
00273       // 1st column contains the values of energy
00274       // 2nd column contains the corresponding data value
00275       // The file terminates with the pattern: -1   -1
00276       //                                       -2   -2
00277       //
00278       if (a == -1)
00279         {
00280           if ((k%nColumns == 0) && (orig_shell_energies != 0) )
00281             {
00282              AddComponent(new G4EMDataSet(shellIndex, orig_shell_energies, orig_shell_data, algorithm->Clone(), unitEnergies, unitData));
00283               orig_shell_energies = 0;
00284               orig_shell_data = 0;
00285             }
00286         }
00287       else if (a != -2)
00288         {
00289           if (orig_shell_energies == 0)
00290             {
00291              orig_shell_energies = new G4DataVector;
00292              orig_shell_data = new G4DataVector;
00293             }
00294           if (k%nColumns == 0)
00295             {
00296              orig_shell_energies->push_back(a*unitEnergies);
00297             }
00298           else if (k%nColumns == 1)
00299             {
00300              orig_shell_data->push_back(a*unitData);
00301             }
00302           k++;
00303         }
00304       else k = 1;
00305     }
00306   while (a != -2);  // End of file
00307 
00308 
00309   delete orig_shell_energies;
00310   delete orig_shell_data;
00311 
00312   return true;
00313 }

virtual size_t G4ShellEMDataSet::NumberOfComponents ( void   )  const [inline, virtual]

Implements G4VEMDataSet.

Definition at line 76 of file G4ShellEMDataSet.hh.

Referenced by PrintData(), and SaveData().

00076 { return components.size(); }

void G4ShellEMDataSet::PrintData ( void   )  const [virtual]

Implements G4VEMDataSet.

Definition at line 102 of file G4ShellEMDataSet.cc.

References G4cout, G4endl, GetComponent(), CLHEP::detail::n, NumberOfComponents(), and G4VEMDataSet::PrintData().

00103 {
00104   const size_t n = NumberOfComponents();
00105 
00106   G4cout << "The data set has " << n << " components" << G4endl;
00107   G4cout << G4endl;
00108  
00109   size_t i = 0;
00110  
00111   while (i < n)
00112     {
00113       G4cout << "--- Component " << i << " ---" << G4endl;
00114       GetComponent(i)->PrintData();
00115       i++;
00116     }
00117 }

virtual G4double G4ShellEMDataSet::RandomSelect ( G4int   )  const [inline, virtual]

Implements G4VEMDataSet.

Definition at line 95 of file G4ShellEMDataSet.hh.

00095 { return -1.; };

G4bool G4ShellEMDataSet::SaveData ( const G4String fileName  )  const [virtual]

Implements G4VEMDataSet.

Definition at line 317 of file G4ShellEMDataSet.cc.

References FatalException, G4Exception(), GetComponent(), G4VEMDataSet::GetData(), G4VEMDataSet::GetEnergies(), CLHEP::detail::n, and NumberOfComponents().

00318 {
00319   G4String fullFileName = FullFileName(file);
00320   std::ofstream out(fullFileName);
00321 
00322   if (!out.is_open())
00323     {
00324       G4String message("Cannot open \"");
00325       message += fullFileName;
00326       message += "\"";
00327       G4Exception("G4EMDataSet::SaveData()","em0005",FatalException,message);
00328     }
00329  
00330   const size_t n = NumberOfComponents();
00331   size_t k = 0;
00332  
00333   while (k < n)
00334     {
00335       const G4VEMDataSet* component = GetComponent(k);
00336   
00337       if (component)
00338         {
00339           const G4DataVector& energies = component->GetEnergies(0);
00340           const G4DataVector& data = component->GetData(0);
00341  
00342           G4DataVector::const_iterator i = energies.begin();
00343           G4DataVector::const_iterator endI = energies.end();
00344           G4DataVector::const_iterator j = data.begin();
00345   
00346           while (i != endI)
00347             {
00348               out.precision(10);
00349               out.width(15);
00350               out.setf(std::ofstream::left);
00351               out << ((*i)/unitEnergies) << ' ';
00352 
00353               out.precision(10);
00354               out.width(15);
00355               out.setf(std::ofstream::left);
00356               out << ((*j)/unitData) << std::endl;
00357               i++;
00358               j++;
00359             }
00360         }
00361   
00362       out.precision(10);
00363       out.width(15);
00364       out.setf(std::ofstream::left);
00365       out << -1.f << ' ';
00366 
00367       out.precision(10);
00368       out.width(15);
00369       out.setf(std::ofstream::left);
00370       out << -1.f << std::endl;
00371   
00372       k++;
00373     }
00374  
00375   out.precision(10);
00376   out.width(15);
00377   out.setf(std::ofstream::left);
00378   out << -2.f << ' ';
00379 
00380   out.precision(10);
00381   out.width(15);
00382   out.setf(std::ofstream::left);
00383   out << -2.f << std::endl;
00384 
00385   return true;
00386 }

void G4ShellEMDataSet::SetEnergiesData ( G4DataVector energies,
G4DataVector data,
G4int  componentId 
) [virtual]

Implements G4VEMDataSet.

Definition at line 120 of file G4ShellEMDataSet.cc.

References FatalErrorInArgument, G4Exception(), and G4VEMDataSet::SetEnergiesData().

00123 {
00124   G4VEMDataSet* component = components[componentId];
00125  
00126   if (component)
00127     {
00128       component->SetEnergiesData(energies, data, 0);
00129       return;
00130     }
00131 
00132   G4String msg = "component " + (G4String)componentId + " not found";
00133  
00134   G4Exception("G4ShellEMDataSet::SetEnergiesData()","em0008", FatalErrorInArgument ,msg);
00135 }

void G4ShellEMDataSet::SetLogEnergiesData ( G4DataVector energies,
G4DataVector data,
G4DataVector log_energies,
G4DataVector log_data,
G4int  componentId 
) [virtual]

Implements G4VEMDataSet.

Definition at line 138 of file G4ShellEMDataSet.cc.

References FatalErrorInArgument, G4Exception(), and G4VEMDataSet::SetLogEnergiesData().

00143 {
00144   G4VEMDataSet* component = components[componentId];
00145  
00146   if (component)
00147     {
00148       component->SetLogEnergiesData(energies, data, log_energies, log_data, 0);
00149       return;
00150     }
00151 
00152   G4String msg = "component " + (G4String)componentId + " not found";
00153  
00154   G4Exception("G4ShellEMDataSet::SetLogEnergiesData()","em0008", FatalErrorInArgument ,msg);
00155 
00156 }


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