G4CompositeDataSet.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 // 31 Jul 2008   MGP        Revised and renamed to G4CompositeDataSet
00035 //
00036 //
00037 // -------------------------------------------------------------------
00038 
00039 #include "G4CompositeDataSet.hh"
00040 #include "G4DataSet.hh"
00041 #include "G4IInterpolator.hh"
00042 #include <fstream>
00043 #include <sstream>
00044 
00045 G4CompositeDataSet::G4CompositeDataSet(G4IInterpolator* algo, 
00046                                        G4double eUnit, 
00047                                        G4double dataUnit, 
00048                                        G4int zMin, 
00049                                        G4int zMax)
00050   :
00051   algorithm(algo),
00052   unitEnergies(eUnit),
00053   unitData(dataUnit),
00054   minZ(zMin),
00055   maxZ(zMax)
00056 {
00057   if (algorithm == 0) 
00058     G4Exception("G4CompositeDataSet::G4CompositeDataSet",
00059                 "pii00000001",
00060                 FatalException,
00061                 "Interpolation == 0");
00062 }
00063 
00064 
00065 
00066 G4CompositeDataSet::~G4CompositeDataSet()
00067 {
00068   CleanUpComponents();
00069   if (algorithm) delete algorithm;
00070 }
00071 
00072 
00073 G4double G4CompositeDataSet::FindValue(G4double energy, G4int componentId) const
00074 {
00075   const G4IDataSet* component(GetComponent(componentId));
00076  
00077   if (component) return component->FindValue(energy);
00078 
00079   std::ostringstream message;
00080   message << "G4CompositeDataSet::FindValue - component " << componentId << " not found";
00081  
00082    G4Exception("G4CompositeDataSet::FindValue",
00083               "pii00000010",
00084               FatalException,
00085               message.str().c_str());
00086  
00087   return 0.;
00088 }
00089 
00090 void G4CompositeDataSet::PrintData(void) const
00091 {
00092   const size_t n(NumberOfComponents());
00093 
00094   G4cout << "The data set has " << n << " components" << G4endl;
00095   G4cout << G4endl;
00096  
00097   size_t i(0);
00098  
00099   while (i<n)
00100     {
00101       G4cout << "--- Component " << i << " ---" << G4endl;
00102       GetComponent(i)->PrintData();
00103       i++;
00104     }
00105 }
00106 
00107 void G4CompositeDataSet::SetEnergiesData(G4DataVector* energies, G4DataVector* data, G4int componentId)
00108 {
00109   G4IDataSet * component(components[componentId]);
00110  
00111   if (component)
00112     {
00113       component->SetEnergiesData(energies, data, 0);
00114       return;
00115     }
00116 
00117   std::ostringstream message;
00118   message << "G4CompositeDataSet::SetEnergiesData - component " << componentId << " not found";
00119  
00120   G4Exception("G4CompositeDataSet::SetEnergiesData",
00121               "pii00000020",
00122               FatalException,
00123               message.str().c_str());
00124 
00125 }
00126 
00127 G4bool G4CompositeDataSet::LoadData(const G4String& argFileName)
00128 {
00129   CleanUpComponents(); 
00130 
00131   for (G4int z(minZ); z<maxZ; z++)
00132     {
00133       G4IDataSet* component = new G4DataSet(z, algorithm->Clone(), unitEnergies, unitData);
00134       if (!component->LoadData(argFileName))
00135         {
00136           delete component;
00137           return false;
00138         }
00139       AddComponent(component);
00140     }
00141   return true;
00142 }
00143 
00144 
00145 
00146 G4bool G4CompositeDataSet::SaveData(const G4String& argFileName) const
00147 {
00148   for (G4int z=minZ; z<maxZ; z++)
00149     {
00150       const G4IDataSet* component(GetComponent(z-minZ));
00151   
00152       if (!component)
00153         {
00154           std::ostringstream message;
00155           message << "G4CompositeDataSet::SaveData - component " << (z-minZ) << " not found";
00156           G4Exception("G4CompositeDataSet::SaveData",
00157                       "pii00000030",
00158                       FatalException,
00159                       message.str().c_str());
00160         }
00161 
00162       if (!component->SaveData(argFileName))
00163         return false;
00164     }
00165  
00166   return true;
00167 }
00168 
00169 void G4CompositeDataSet::CleanUpComponents(void)
00170 {
00171   while (!components.empty())
00172     {
00173       if (components.back())
00174         delete components.back();
00175       components.pop_back();
00176     }
00177 }
00178 
00179 
00180 G4double G4CompositeDataSet::RandomSelect(G4int componentId) const
00181 {
00182   G4double value = 0.;
00183   if (componentId >= 0 && componentId < (G4int)components.size())
00184     {
00185       const G4IDataSet* dataSet = GetComponent(componentId);
00186       value = dataSet->RandomSelect();
00187     }
00188   return value;
00189 }

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