G4PixeShellDataSet.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 // 09.10.01   V.Ivanchenko Add case z=0
00035 //  9 Mar 2008   MGP        Cleaned up unreadable code modified by former developer
00036 //                          (Further clean-up needed) 
00037 // 31 Jul 2008   MGP        Revised 
00038 //
00039 // -------------------------------------------------------------------
00040 
00041 #include "G4PixeShellDataSet.hh"
00042 #include "G4DataSet.hh"
00043 #include "G4IInterpolator.hh"
00044 #include <fstream>
00045 #include <sstream>
00046 
00047 
00048 G4PixeShellDataSet::G4PixeShellDataSet(G4int zeta, 
00049                                        G4IInterpolator* algo, 
00050                                        const G4String& modelK,
00051                                        const G4String& modelL,
00052                                        const G4String& modelM,
00053                                        G4double eUnit, 
00054                                        G4double dataUnit):
00055   z(zeta),
00056   algorithm(algo),
00057   unitEnergies(eUnit),
00058   unitData(dataUnit)
00059 {
00060   if (algorithm == 0) G4Exception("G4PixeShellDataSet::G4PixeShellDataSet",
00061                                   "pii00000301",
00062                                   FatalException,
00063                                   "interpolation == 0");
00064 
00065   crossModel.push_back(modelK);
00066   crossModel.push_back(modelL);
00067   crossModel.push_back(modelM);
00068 
00069   shellName.push_back("k");
00070   shellName.push_back("l");
00071   shellName.push_back("m");
00072 
00073   size_t sizeK = modelK.size();
00074   size_t sizeL = modelL.size();
00075   size_t sizeM = modelM.size();
00076   
00077   if (sizeK > 0) subShellName.push_back("k");
00078 
00079   if (sizeK > 0 && sizeL > 0)
00080     {
00081       subShellName.push_back("l1");
00082       subShellName.push_back("l2");
00083       subShellName.push_back("l3");
00084     }
00085   if (sizeK > 0 && sizeL > 0 && sizeM >0)
00086     {
00087       subShellName.push_back("m1");
00088       subShellName.push_back("m2");
00089       subShellName.push_back("m3");
00090       subShellName.push_back("m4");
00091       subShellName.push_back("m5");
00092     }
00093 }
00094 
00095 
00096 G4PixeShellDataSet::~G4PixeShellDataSet()
00097 {
00098   CleanUpComponents();
00099   if (algorithm) delete algorithm;
00100 }
00101 
00102 
00103 G4double G4PixeShellDataSet::FindValue(G4double energy, G4int /* componentId */) const
00104 {
00105   // Returns the sum over the shells corresponding to e
00106   G4double value = 0.;
00107 
00108   std::vector<G4IDataSet *>::const_iterator i(components.begin());
00109   std::vector<G4IDataSet *>::const_iterator end(components.end());
00110 
00111   while (i != end)
00112     {
00113       value += (*i)->FindValue(energy);
00114       i++;
00115     }
00116   return value;
00117 }
00118 
00119 
00120 void G4PixeShellDataSet::PrintData(void) const
00121 {
00122   const size_t n = NumberOfComponents();
00123 
00124   G4cout << "The data set has " << n << " components" << G4endl;
00125   G4cout << G4endl;
00126  
00127   size_t i = 0;
00128  
00129   while (i < n)
00130     {
00131       G4cout << "--- Component " << i << " ---" << G4endl;
00132       GetComponent(i)->PrintData();
00133       i++;
00134     }
00135 }
00136 
00137 
00138 void G4PixeShellDataSet::SetEnergiesData(G4DataVector* energies, 
00139                                          G4DataVector* data, 
00140                                          G4int componentId)
00141 {
00142   G4IDataSet* component = components[componentId];
00143  
00144   if (component)
00145     {
00146       component->SetEnergiesData(energies, data, 0);
00147       return;
00148     }
00149 
00150   std::ostringstream message;
00151   message << "G4PixeShellDataSet::SetEnergiesData - component " << componentId << " not found";
00152  
00153   G4Exception("G4PixeShellDataSet::SetEnergiesData",
00154               "pii000000310",
00155               FatalException,
00156               message.str().c_str());
00157 }
00158 
00159 
00160 G4bool G4PixeShellDataSet::LoadData(const G4String& file)
00161 {
00162   CleanUpComponents();
00163 
00164   // Load shell cross sections
00165   
00166   G4int nShells = subShellName.size();
00167   
00168   for (G4int subShellIndex=0; subShellIndex<nShells; subShellIndex++)
00169     {
00170       G4String subName = subShellName[subShellIndex];    
00171       G4String fullFileName = FullFileName(file,subName);
00172 
00173       // Create component DataSet with the data from the current subshell
00174       G4IDataSet* dataSet = new G4DataSet(z,algorithm);
00175       dataSet->LoadData(fullFileName);
00176       
00177       // Add component to the ShellDataSet
00178       AddComponent(dataSet);
00179     }
00180 
00181   return true;
00182 }
00183 
00184 
00185 G4bool G4PixeShellDataSet::SaveData(const G4String& /* file */) const
00186 {
00187   // Dummy implementation
00188   return true;
00189 }
00190 
00191 
00192 void G4PixeShellDataSet::CleanUpComponents(void)
00193 {
00194   while (!components.empty())
00195     {
00196       if (components.back()) delete components.back();
00197       components.pop_back();
00198     }
00199 }
00200 
00201 
00202 G4String G4PixeShellDataSet::FullFileName(const G4String& file,
00203                                           const G4String& subShell) const
00204 {
00205   char* path = getenv("G4PIIDATA");
00206   if (!path)
00207     G4Exception("G4PixeShellDataSet::FullFileName",
00208                                   "pii00000320",
00209                                   FatalException,
00210                                   "G4PIIDATA environment variable not set");
00211   
00212   // Identify the shell this subshell belongs to
00213   G4int shellIndex = TranslateShell(subShell);
00214   G4String shellString = shellName[shellIndex];
00215   G4String shellModel = crossModel[shellIndex];
00216 
00217   std::ostringstream fullFileName;
00218  
00219   fullFileName 
00220     //<< path 
00221                << "pixe/" 
00222                << file
00223                << '/' 
00224                << shellString
00225                << '/'
00226                << shellModel
00227                << '/'
00228                << subShell
00229                << '-' ;
00230 //             << z 
00231         //       << ".dat";
00232                     
00233   G4String test(fullFileName.str().c_str());
00234   // std::cout << "PixeShellDataSet - Reading data from file " << test << std::endl;
00235 
00236   return G4String(fullFileName.str().c_str());
00237 }
00238 
00239 G4int G4PixeShellDataSet::TranslateShell(const G4String& subShell) const
00240 {
00241   // By default return K shell
00242   G4int index = 0;
00243 
00244   if (subShell == "l1" || subShell == "l2" || subShell == "l3" ) index = 1;
00245   if (subShell == "m1" || 
00246       subShell == "m2" ||
00247       subShell == "m3" ||
00248       subShell == "m4" || 
00249       subShell == "m5" ) index = 2;
00250   return index;
00251 }

Generated on Mon May 27 17:49:22 2013 for Geant4 by  doxygen 1.4.7