G4CompositeEMDataSet.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
00030 //
00031 // History:
00032 // -----------
00033 // 1 Aug 2001   MGP        Created
00034 //
00035 // 15 Jul 2009   Nicolas A. Karakatsanis
00036 //
00037 //                           - LoadNonLogData method was created to load only the non-logarithmic data from G4EMLOW
00038 //                             dataset. It is essentially performing the data loading operations as in the past.
00039 //
00040 //                           - LoadData method was revised in order to calculate the logarithmic values of the data
00041 //                             It retrieves the data values from the G4EMLOW data files but, then, calculates the
00042 //                             respective log values and loads them to seperate data structures. 
00043 //
00044 //                           - SetLogEnergiesData method was cretaed to set logarithmic values to G4 data vectors.
00045 //                             The EM data sets, initialized this way, contain both non-log and log values.
00046 //                             These initialized data sets can enhance the computing performance of data interpolation
00047 //                             operations
00048 //
00049 // -------------------------------------------------------------------
00050 
00051 #include "G4CompositeEMDataSet.hh"
00052 #include "G4EMDataSet.hh"
00053 #include "G4VDataSetAlgorithm.hh"
00054 #include <fstream>
00055 #include <sstream>
00056 
00057 G4CompositeEMDataSet::G4CompositeEMDataSet(G4VDataSetAlgorithm* argAlgorithm, 
00058                                            G4double argUnitEnergies, 
00059                                            G4double argUnitData, 
00060                                            G4int argMinZ, 
00061                                            G4int argMaxZ)
00062   :
00063   algorithm(argAlgorithm),
00064   unitEnergies(argUnitEnergies),
00065   unitData(argUnitData),
00066   minZ(argMinZ),
00067   maxZ(argMaxZ)
00068 {
00069   if (algorithm == 0) 
00070   G4Exception("G4CompositeEMDataSet::G4CompositeEMDataSet",
00071               "em1003",FatalException,"interpolation == 0");
00072 
00073 }
00074 
00075 
00076 
00077 G4CompositeEMDataSet::~G4CompositeEMDataSet()
00078 {
00079   CleanUpComponents();
00080   if (algorithm) delete algorithm;
00081 }
00082 
00083 
00084 G4double G4CompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const
00085 {
00086   const G4VEMDataSet* component(GetComponent(argComponentId));
00087  
00088   if (component) return component->FindValue(argEnergy);
00089 
00090   std::ostringstream message;
00091   message << "G4CompositeEMDataSet::FindValue - component " << argComponentId << " not found";
00092  
00093   G4Exception("G4CompositeEMDataSet::FindValue",
00094               "em1004",FatalException,message.str().c_str());
00095  
00096   return 0.;
00097 }
00098 
00099 void G4CompositeEMDataSet::PrintData(void) const
00100 {
00101   const size_t n(NumberOfComponents());
00102 
00103   G4cout << "The data set has " << n << " components" << G4endl;
00104   G4cout << G4endl;
00105  
00106   size_t i(0);
00107  
00108   while (i<n)
00109     {
00110       G4cout << "--- Component " << i << " ---" << G4endl;
00111       GetComponent(i)->PrintData();
00112       i++;
00113     }
00114 }
00115 
00116 void G4CompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId)
00117 {
00118   G4VEMDataSet * component(components[argComponentId]);
00119  
00120   if (component)
00121     {
00122       component->SetEnergiesData(argEnergies, argData, 0);
00123       return;
00124     }
00125 
00126   std::ostringstream message;
00127   message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
00128  
00129   G4Exception("G4CompositeEMDataSet::SetEnergiesData",
00130               "em1004",FatalException,message.str().c_str());
00131 }
00132 
00133 void G4CompositeEMDataSet::SetLogEnergiesData(G4DataVector* argEnergies, 
00134                                               G4DataVector* argData,
00135                                               G4DataVector* argLogEnergies,
00136                                               G4DataVector* argLogData, 
00137                                               G4int argComponentId)
00138 {
00139   G4VEMDataSet * component(components[argComponentId]);
00140  
00141   if (component)
00142     {
00143       component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
00144       return;
00145     }
00146 
00147   std::ostringstream message;
00148   message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
00149  
00150   G4Exception("G4CompositeEMDataSet::SetLogEnergiesData",
00151               "em1004",FatalException,message.str().c_str());
00152 }
00153 
00154 
00155 G4bool G4CompositeEMDataSet::LoadData(const G4String& argFileName)
00156 {
00157   CleanUpComponents(); 
00158 
00159   for (G4int z(minZ); z<maxZ; z++)
00160     {
00161       G4VEMDataSet* component = new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
00162       if (!component->LoadData(argFileName))
00163         {
00164           delete component;
00165           return false;
00166         }
00167       AddComponent(component);
00168     }
00169   return true;
00170 }
00171 
00172 
00173 G4bool G4CompositeEMDataSet::LoadNonLogData(const G4String& argFileName)
00174 {
00175   CleanUpComponents(); 
00176 
00177   for (G4int z(minZ); z<maxZ; z++)
00178     {
00179       G4VEMDataSet* component = new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
00180       if (!component->LoadNonLogData(argFileName))
00181         {
00182           delete component;
00183           return false;
00184         }
00185       AddComponent(component);
00186     }
00187   return true;
00188 }
00189 
00190 
00191 G4bool G4CompositeEMDataSet::SaveData(const G4String& argFileName) const
00192 {
00193   for (G4int z=minZ; z<maxZ; z++)
00194     {
00195       const G4VEMDataSet* component(GetComponent(z-minZ));
00196   
00197       if (!component)
00198         {
00199           std::ostringstream message;
00200           message << "G4CompositeEMDataSet::SaveData - component " << (z-minZ) << " not found";
00201           G4Exception("G4CompositeEMDataSet::SaveData",
00202               "em1004",FatalException,message.str().c_str());
00203           return false;
00204         }
00205 
00206       if (!component->SaveData(argFileName))
00207         return false;
00208     }
00209  
00210   return true;
00211 }
00212 
00213 void G4CompositeEMDataSet::CleanUpComponents(void)
00214 {
00215   while (!components.empty())
00216     {
00217       if (components.back())
00218         delete components.back();
00219       components.pop_back();
00220     }
00221 }
00222 
00223 
00224 G4double G4CompositeEMDataSet::RandomSelect(G4int componentId) const
00225 {
00226   G4double value = 0.;
00227   if (componentId >= 0 && componentId < (G4int)components.size())
00228     {
00229       const G4VEMDataSet* dataSet = GetComponent(componentId);
00230       value = dataSet->RandomSelect();
00231     }
00232   return value;
00233 }

Generated on Mon May 27 17:47:56 2013 for Geant4 by  doxygen 1.4.7