G4DNACrossSectionDataSet Class Reference

#include <G4DNACrossSectionDataSet.hh>

Inheritance diagram for G4DNACrossSectionDataSet:

G4VEMDataSet

Public Member Functions

 G4DNACrossSectionDataSet (G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
virtual ~G4DNACrossSectionDataSet ()
virtual G4double FindValue (G4double e, 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 *x, G4DataVector *values, G4int componentId)
virtual void SetLogEnergiesData (G4DataVector *x, G4DataVector *values, G4DataVector *log_x, G4DataVector *log_values, G4int componentId)
virtual G4bool LoadData (const G4String &argFileName)
virtual G4bool LoadNonLogData (const G4String &argFileName)
virtual G4bool SaveData (const G4String &argFileName) const
virtual G4double RandomSelect (G4int) const

Detailed Description

Definition at line 55 of file G4DNACrossSectionDataSet.hh.


Constructor & Destructor Documentation

G4DNACrossSectionDataSet::G4DNACrossSectionDataSet ( G4VDataSetAlgorithm algo,
G4double  xUnit = CLHEP::MeV,
G4double  dataUnit = CLHEP::barn 
)

Definition at line 65 of file G4DNACrossSectionDataSet.cc.

References G4DNACrossSectionDataSet().

Referenced by G4DNACrossSectionDataSet().

00068   :
00069    algorithm(argAlgorithm), unitEnergies(argUnitEnergies), unitData(argUnitData)
00070 {
00071   z = 0;
00072 
00073 }

G4DNACrossSectionDataSet::~G4DNACrossSectionDataSet (  )  [virtual]

Definition at line 76 of file G4DNACrossSectionDataSet.cc.

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


Member Function Documentation

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

Implements G4VEMDataSet.

Definition at line 72 of file G4DNACrossSectionDataSet.hh.

Referenced by LoadData(), and LoadNonLogData().

00073   { components.push_back(dataSet); }

G4double G4DNACrossSectionDataSet::FindValue ( G4double  e,
G4int  componentId = 0 
) const [virtual]

Implements G4VEMDataSet.

Definition at line 500 of file G4DNACrossSectionDataSet.cc.

00501 {
00502   // Returns the sum over the shells corresponding to e
00503   G4double value = 0.;
00504 
00505   std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
00506   std::vector<G4VEMDataSet *>::const_iterator end(components.end());
00507 
00508   while (i!=end)
00509     {
00510       value+=(*i)->FindValue(argEnergy);
00511       i++;
00512     }
00513 
00514   return value;
00515 }

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

Implements G4VEMDataSet.

Definition at line 69 of file G4DNACrossSectionDataSet.hh.

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

00070   { return components[componentId]; }

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

Implements G4VEMDataSet.

Definition at line 81 of file G4DNACrossSectionDataSet.hh.

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

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

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

Implements G4VEMDataSet.

Definition at line 78 of file G4DNACrossSectionDataSet.hh.

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

Referenced by SaveData().

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

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

Implements G4VEMDataSet.

Definition at line 87 of file G4DNACrossSectionDataSet.hh.

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

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

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

Implements G4VEMDataSet.

Definition at line 84 of file G4DNACrossSectionDataSet.hh.

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

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

G4bool G4DNACrossSectionDataSet::LoadData ( const G4String argFileName  )  [virtual]

Implements G4VEMDataSet.

Definition at line 84 of file G4DNACrossSectionDataSet.cc.

References AddComponent(), FatalException, and G4Exception().

Referenced by G4DNARuddIonisationModel::Initialise(), G4DNARuddIonisationExtendedModel::Initialise(), G4DNAMeltonAttachmentModel::Initialise(), G4DNAChampionElasticModel::Initialise(), G4DNABornIonisationModel::Initialise(), and G4DNABornExcitationModel::Initialise().

00085 {
00086   CleanUpComponents();
00087 
00088   G4String fullFileName(FullFileName(argFileName));
00089   std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
00090 
00091   if (!in.is_open())
00092     {
00093       G4String message("Data file \"");
00094       message+=fullFileName;
00095       message+="\" not found";
00096       G4Exception("G4DNACrossSectionDataSet::LoadData","em0003",
00097                       FatalException,message);
00098       return false;
00099     }
00100 
00101   std::vector<G4DataVector *> columns;
00102   std::vector<G4DataVector *> log_columns;
00103 
00104   std::stringstream *stream(new std::stringstream);
00105   char c;
00106   G4bool comment(false);
00107   G4bool space(true);
00108   G4bool first(true);
00109 
00110   try
00111     {
00112       while (!in.eof())
00113         {
00114           in.get(c);
00115    
00116           switch (c)
00117             {
00118             case '\r':
00119             case '\n':
00120               if (!first)
00121                 {
00122                   unsigned long i(0);
00123                   G4double value;
00124       
00125                   while (!stream->eof())
00126                     {
00127                       (*stream) >> value;
00128        
00129                       while (i>=columns.size())
00130                         {
00131                          columns.push_back(new G4DataVector);
00132                          log_columns.push_back(new G4DataVector);
00133                         }
00134       
00135                       columns[i]->push_back(value);
00136 
00137 // N. A. Karakatsanis
00138 // A condition is applied to check if negative or zero values are present in the dataset.
00139 // If yes, then a near-zero value is applied to allow the computation of the logarithmic value
00140 // If a value is zero, this simplification is acceptable
00141 // If a value is negative, then it is not acceptable and the data of the particular column of
00142 // logarithmic values should not be used by interpolation methods.
00143 //
00144 // Therefore, G4LogLogInterpolation and G4LinLogLogInterpolation should not be used if negative values are present.
00145 // Instead, G4LinInterpolation is safe in every case
00146 // SemiLogInterpolation is safe only if the energy columns are non-negative
00147 // G4LinLogInterpolation is safe only if the cross section data columns are non-negative
00148 
00149                       if (value <=0.) value = 1e-300;
00150                       log_columns[i]->push_back(std::log10(value));
00151        
00152                       i++;
00153                     }
00154       
00155                   delete stream;
00156                   stream=new std::stringstream;
00157                 }
00158      
00159               first=true;
00160               comment=false;
00161               space=true;
00162               break;
00163      
00164             case '#':
00165               comment=true;
00166               break;
00167      
00168             case '\t':
00169               c=' ';
00170             case ' ':
00171               if (space)
00172                 break;
00173             default:
00174               if (comment)
00175                 break;
00176      
00177               if (c==' ')
00178                 space=true;
00179               else
00180                 {
00181                   if (space && (!first))
00182                     (*stream) << ' ';
00183       
00184                   first=false;
00185                   (*stream) << c;
00186                   space=false;
00187                 }
00188             }
00189         }
00190     }
00191   catch(const std::ios::failure &e)
00192     {
00193       // some implementations of STL could throw a "failture" exception
00194       // when read wants read characters after end of file
00195     }
00196  
00197   delete stream;
00198  
00199   std::vector<G4DataVector *>::size_type maxI(columns.size());
00200  
00201   if (maxI<2)
00202     {
00203       G4String message("Data file \"");
00204       message+=fullFileName;
00205       message+="\" should have at least two columns";
00206       G4Exception("G4DNACrossSectionDataSet::LoadData","em0005",
00207                       FatalException,message);
00208       return false;
00209     }
00210  
00211   std::vector<G4DataVector*>::size_type i(1);
00212   while (i<maxI)
00213     {
00214       G4DataVector::size_type maxJ(columns[i]->size());
00215 
00216       if (maxJ!=columns[0]->size())
00217         {
00218           G4String message("Data file \"");
00219           message+=fullFileName;
00220           message+="\" has lines with a different number of columns";
00221           G4Exception("G4DNACrossSectionDataSet::LoadData","em0005",
00222                       FatalException,message);
00223           return false;
00224         }
00225 
00226       G4DataVector::size_type j(0);
00227 
00228       G4DataVector *argEnergies=new G4DataVector;
00229       G4DataVector *argData=new G4DataVector;
00230       G4DataVector *argLogEnergies=new G4DataVector;
00231       G4DataVector *argLogData=new G4DataVector;
00232 
00233       while(j<maxJ)
00234         {
00235           argEnergies->push_back(columns[0]->operator[] (j)*GetUnitEnergies());
00236           argData->push_back(columns[i]->operator[] (j)*GetUnitData());
00237           argLogEnergies->push_back(log_columns[0]->operator[] (j) + std::log10(GetUnitEnergies()));
00238           argLogData->push_back(log_columns[i]->operator[] (j) + std::log10(GetUnitData()));
00239           j++;
00240         }
00241 
00242       AddComponent(new G4EMDataSet(i-1, argEnergies, argData, argLogEnergies, argLogData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
00243   
00244       i++;
00245     }
00246 
00247   i=maxI;
00248   while (i>0)
00249     {
00250       i--;
00251       delete columns[i];
00252       delete log_columns[i];
00253     }
00254 
00255   return true;
00256 }

G4bool G4DNACrossSectionDataSet::LoadNonLogData ( const G4String argFileName  )  [virtual]

Implements G4VEMDataSet.

Definition at line 259 of file G4DNACrossSectionDataSet.cc.

References AddComponent(), FatalException, and G4Exception().

00260 {
00261   CleanUpComponents();
00262 
00263   G4String fullFileName(FullFileName(argFileName));
00264   std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
00265 
00266   if (!in.is_open())
00267     {
00268       G4String message("Data file \"");
00269       message+=fullFileName;
00270       message+="\" not found";
00271       G4Exception("G4DNACrossSectionDataSet::LoadData","em0003",
00272                       FatalException,message);
00273       return false;
00274     }
00275 
00276   std::vector<G4DataVector *> columns;
00277 
00278   std::stringstream *stream(new std::stringstream);
00279   char c;
00280   G4bool comment(false);
00281   G4bool space(true);
00282   G4bool first(true);
00283 
00284   try
00285     {
00286       while (!in.eof())
00287         {
00288           in.get(c);
00289    
00290           switch (c)
00291             {
00292             case '\r':
00293             case '\n':
00294               if (!first)
00295                 {
00296                   unsigned long i(0);
00297                   G4double value;
00298       
00299                   while (!stream->eof())
00300                     {
00301                       (*stream) >> value;
00302        
00303                       while (i>=columns.size())
00304                         {
00305                          columns.push_back(new G4DataVector);
00306                         }
00307       
00308                       columns[i]->push_back(value);
00309        
00310                       i++;
00311                     }
00312       
00313                   delete stream;
00314                   stream=new std::stringstream;
00315                 }
00316      
00317               first=true;
00318               comment=false;
00319               space=true;
00320               break;
00321      
00322             case '#':
00323               comment=true;
00324               break;
00325      
00326             case '\t':
00327               c=' ';
00328             case ' ':
00329               if (space)
00330                 break;
00331             default:
00332               if (comment)
00333                 break;
00334      
00335               if (c==' ')
00336                 space=true;
00337               else
00338                 {
00339                   if (space && (!first))
00340                     (*stream) << ' ';
00341       
00342                   first=false;
00343                   (*stream) << c;
00344                   space=false;
00345                 }
00346             }
00347         }
00348     }
00349   catch(const std::ios::failure &e)
00350     {
00351       // some implementations of STL could throw a "failture" exception
00352       // when read wants read characters after end of file
00353     }
00354  
00355   delete stream;
00356  
00357   std::vector<G4DataVector *>::size_type maxI(columns.size());
00358  
00359   if (maxI<2)
00360     {
00361       G4String message("Data file \"");
00362       message+=fullFileName;
00363       message+="\" should have at least two columns";
00364       G4Exception("G4DNACrossSectionDataSet::LoadData","em0005",
00365                       FatalException,message);
00366       return false;
00367     }
00368  
00369   std::vector<G4DataVector*>::size_type i(1);
00370   while (i<maxI)
00371     {
00372       G4DataVector::size_type maxJ(columns[i]->size());
00373 
00374       if (maxJ!=columns[0]->size())
00375         {
00376           G4String message("Data file \"");
00377           message+=fullFileName;
00378           message+="\" has lines with a different number of columns.";
00379           G4Exception("G4DNACrossSectionDataSet::LoadData","em0005",
00380                       FatalException,message);
00381           return false;
00382         }
00383 
00384       G4DataVector::size_type j(0);
00385 
00386       G4DataVector *argEnergies=new G4DataVector;
00387       G4DataVector *argData=new G4DataVector;
00388 
00389       while(j<maxJ)
00390         {
00391           argEnergies->push_back(columns[0]->operator[] (j)*GetUnitEnergies());
00392           argData->push_back(columns[i]->operator[] (j)*GetUnitData());
00393           j++;
00394         }
00395 
00396       AddComponent(new G4EMDataSet(i-1, argEnergies, argData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
00397   
00398       i++;
00399     }
00400 
00401   i=maxI;
00402   while (i>0)
00403     {
00404       i--;
00405       delete columns[i];
00406     }
00407 
00408   return true;
00409 }

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

Implements G4VEMDataSet.

Definition at line 75 of file G4DNACrossSectionDataSet.hh.

Referenced by PrintData(), and SaveData().

00076   { return components.size(); }

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

Implements G4VEMDataSet.

Definition at line 518 of file G4DNACrossSectionDataSet.cc.

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

00519 {
00520   const size_t n(NumberOfComponents());
00521 
00522   G4cout << "The data set has " << n << " components" << G4endl;
00523   G4cout << G4endl;
00524  
00525   size_t i(0);
00526  
00527   while (i<n)
00528     {
00529       G4cout << "--- Component " << i << " ---" << G4endl;
00530       GetComponent(i)->PrintData();
00531       i++;
00532     }
00533 }

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

Implements G4VEMDataSet.

Definition at line 103 of file G4DNACrossSectionDataSet.hh.

00103 { return -1.; };

G4bool G4DNACrossSectionDataSet::SaveData ( const G4String argFileName  )  const [virtual]

Implements G4VEMDataSet.

Definition at line 412 of file G4DNACrossSectionDataSet.cc.

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

00413 {
00414   const size_t n(NumberOfComponents());
00415  
00416   if (n==0)
00417     {
00418       G4Exception("G4DNACrossSectionDataSet::SaveData","em0005",
00419                       FatalException,"Expected at least one component");
00420 
00421       return false;
00422     }
00423  
00424   G4String fullFileName(FullFileName(argFileName));
00425   std::ofstream out(fullFileName);
00426 
00427   if (!out.is_open())
00428     {
00429       G4String message("Cannot open \"");
00430       message+=fullFileName;
00431       message+="\"";
00432       G4Exception("G4DNACrossSectionDataSet::SaveData","em0005",
00433                       FatalException,message);
00434       return false;
00435     }
00436  
00437   G4DataVector::const_iterator iEnergies(GetComponent(0)->GetEnergies(0).begin());
00438   G4DataVector::const_iterator iEnergiesEnd(GetComponent(0)->GetEnergies(0).end());
00439   G4DataVector::const_iterator * iData(new G4DataVector::const_iterator[n]);
00440  
00441   size_t k(n);
00442  
00443   while (k>0)
00444     {
00445       k--;
00446       iData[k]=GetComponent(k)->GetData(0).begin();
00447     }
00448  
00449   while (iEnergies!=iEnergiesEnd)
00450     {
00451       out.precision(10);
00452       out.width(15);
00453       out.setf(std::ofstream::left);
00454       out << ((*iEnergies)/GetUnitEnergies());
00455   
00456       k=0;
00457   
00458       while (k<n)
00459         {
00460           out << ' ';
00461           out.precision(10);
00462           out.width(15);
00463           out.setf(std::ofstream::left);
00464           out << ((*(iData[k]))/GetUnitData());
00465 
00466           iData[k]++;
00467           k++;
00468         }
00469   
00470       out << std::endl;
00471   
00472       iEnergies++;
00473     }
00474  
00475   delete[] iData;
00476 
00477   return true;
00478 }

void G4DNACrossSectionDataSet::SetEnergiesData ( G4DataVector x,
G4DataVector values,
G4int  componentId 
) [virtual]

Implements G4VEMDataSet.

Definition at line 536 of file G4DNACrossSectionDataSet.cc.

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

00539 {
00540   G4VEMDataSet * component(components[argComponentId]);
00541  
00542   if (component)
00543     {
00544       component->SetEnergiesData(argEnergies, argData, 0);
00545       return;
00546     }
00547 
00548   std::ostringstream message;
00549   message << "Component " << argComponentId << " not found";
00550  
00551   G4Exception("G4DNACrossSectionDataSet::SetEnergiesData","em0005",
00552                  FatalException,message.str().c_str());
00553   
00554 }

void G4DNACrossSectionDataSet::SetLogEnergiesData ( G4DataVector x,
G4DataVector values,
G4DataVector log_x,
G4DataVector log_values,
G4int  componentId 
) [virtual]

Implements G4VEMDataSet.

Definition at line 557 of file G4DNACrossSectionDataSet.cc.

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

00562 {
00563   G4VEMDataSet * component(components[argComponentId]);
00564  
00565   if (component)
00566     {
00567       component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
00568       return;
00569     }
00570 
00571   std::ostringstream message;
00572   message << "Component " << argComponentId << " not found";
00573  
00574   G4Exception("G4DNACrossSectionDataSet::SetLogEnergiesData","em0005",
00575                  FatalException,message.str().c_str());
00576 
00577 }


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