Ignore:
Timestamp:
Apr 6, 2009, 12:21:12 PM (15 years ago)
Author:
garnier
Message:

update processes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/processes/electromagnetic/lowenergy/src/G4CompositeEMDataSet.cc

    r819 r961  
    2525//
    2626//
    27 // $Id: G4CompositeEMDataSet.cc,v 1.9 2006/06/29 19:38:46 gunter Exp $
    28 // GEANT4 tag $Name: geant4-09-01-patch-02 $
     27// $Id: G4CompositeEMDataSet.cc,v 1.13 2008/03/17 13:40:53 pia Exp $
     28// GEANT4 tag $Name: geant4-09-02-ref-02 $
    2929//
    3030// Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
     
    4242#include <sstream>
    4343
    44                                                 G4CompositeEMDataSet :: G4CompositeEMDataSet(G4VDataSetAlgorithm* argAlgorithm, G4double argUnitEnergies, G4double argUnitData, G4int argMinZ, G4int argMaxZ)
    45 :
    46  algorithm(argAlgorithm),
    47  unitEnergies(argUnitEnergies),
    48  unitData(argUnitData),
    49  minZ(argMinZ),
    50  maxZ(argMaxZ)
     44G4CompositeEMDataSet::G4CompositeEMDataSet(G4VDataSetAlgorithm* argAlgorithm,
     45                                           G4double argUnitEnergies,
     46                                           G4double argUnitData,
     47                                           G4int argMinZ,
     48                                           G4int argMaxZ)
     49  :
     50  algorithm(argAlgorithm),
     51  unitEnergies(argUnitEnergies),
     52  unitData(argUnitData),
     53  minZ(argMinZ),
     54  maxZ(argMaxZ)
    5155{
    52  if (algorithm == 0)
    53   G4Exception("G4CompositeEMDataSet::G4CompositeEMDataSet - interpolation == 0");
     56  if (algorithm == 0)
     57    G4Exception("G4CompositeEMDataSet::G4CompositeEMDataSet - interpolation == 0");
    5458}
    5559
    5660
    5761
    58                                                 G4CompositeEMDataSet :: ~G4CompositeEMDataSet()
     62G4CompositeEMDataSet::~G4CompositeEMDataSet()
    5963{
    60  CleanUpComponents();
     64  CleanUpComponents();
     65  if (algorithm) delete algorithm;
     66}
    6167
    62  if (algorithm)
    63   delete algorithm;
     68
     69G4double G4CompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const
     70{
     71  const G4VEMDataSet* component(GetComponent(argComponentId));
     72 
     73  if (component) return component->FindValue(argEnergy);
     74
     75  std::ostringstream message;
     76  message << "G4CompositeEMDataSet::FindValue - component " << argComponentId << " not found";
     77 
     78  G4Exception(message.str().c_str());
     79 
     80  return 0.;
     81}
     82
     83void G4CompositeEMDataSet::PrintData(void) const
     84{
     85  const size_t n(NumberOfComponents());
     86
     87  G4cout << "The data set has " << n << " components" << G4endl;
     88  G4cout << G4endl;
     89 
     90  size_t i(0);
     91 
     92  while (i<n)
     93    {
     94      G4cout << "--- Component " << i << " ---" << G4endl;
     95      GetComponent(i)->PrintData();
     96      i++;
     97    }
     98}
     99
     100void G4CompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId)
     101{
     102  G4VEMDataSet * component(components[argComponentId]);
     103 
     104  if (component)
     105    {
     106      component->SetEnergiesData(argEnergies, argData, 0);
     107      return;
     108    }
     109
     110  std::ostringstream message;
     111  message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
     112 
     113  G4Exception(message.str().c_str());
     114}
     115
     116G4bool G4CompositeEMDataSet::LoadData(const G4String& argFileName)
     117{
     118  CleanUpComponents();
     119
     120  for (G4int z(minZ); z<maxZ; z++)
     121    {
     122      G4VEMDataSet* component = new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
     123      if (!component->LoadData(argFileName))
     124        {
     125          delete component;
     126          return false;
     127        }
     128      AddComponent(component);
     129    }
     130  return true;
    64131}
    65132
    66133
    67134
     135G4bool G4CompositeEMDataSet::SaveData(const G4String& argFileName) const
     136{
     137  for (G4int z=minZ; z<maxZ; z++)
     138    {
     139      const G4VEMDataSet* component(GetComponent(z-minZ));
     140 
     141      if (!component)
     142        {
     143          std::ostringstream message;
     144          message << "G4CompositeEMDataSet::SaveData - component " << (z-minZ) << " not found";
     145          G4Exception(message.str().c_str());
     146        }
    68147
     148      if (!component->SaveData(argFileName))
     149        return false;
     150    }
     151 
     152  return true;
     153}
    69154
    70 
    71 G4double                                        G4CompositeEMDataSet :: FindValue(G4double argEnergy, G4int argComponentId) const
     155void G4CompositeEMDataSet::CleanUpComponents(void)
    72156{
    73  const G4VEMDataSet * component(GetComponent(argComponentId));
    74  
    75  if (component)
    76   return component->FindValue(argEnergy);
    77 
    78  std::ostringstream message;
    79  message << "G4CompositeEMDataSet::FindValue - component " << argComponentId << " not found";
    80  
    81  G4Exception(message.str().c_str());
    82  
    83  return 0.;
     157  while (!components.empty())
     158    {
     159      if (components.back())
     160        delete components.back();
     161      components.pop_back();
     162    }
    84163}
    85164
    86165
    87 
    88 
    89 
    90 void                                            G4CompositeEMDataSet :: PrintData(void) const
     166G4double G4CompositeEMDataSet::RandomSelect(G4int componentId) const
    91167{
    92  const size_t n(NumberOfComponents());
    93 
    94  G4cout << "The data set has " << n << " components" << G4endl;
    95  G4cout << G4endl;
    96  
    97  size_t i(0);
    98  
    99  while (i<n)
    100  {
    101   G4cout << "--- Component " << i << " ---" << G4endl;
    102   GetComponent(i)->PrintData();
    103   i++;
    104  }
     168  G4double value = 0.;
     169  if (componentId >= 0 && componentId < (G4int)components.size())
     170    {
     171      const G4VEMDataSet* dataSet = GetComponent(componentId);
     172      value = dataSet->RandomSelect();
     173    }
     174  return value;
    105175}
    106 
    107 
    108 
    109 
    110 
    111 void                                            G4CompositeEMDataSet :: SetEnergiesData(G4DataVector * argEnergies, G4DataVector * argData, G4int argComponentId)
    112 {
    113  G4VEMDataSet * component(components[argComponentId]);
    114  
    115  if (component)
    116  {
    117   component->SetEnergiesData(argEnergies, argData, 0);
    118   return;
    119  }
    120 
    121  std::ostringstream message;
    122  message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
    123  
    124  G4Exception(message.str().c_str());
    125 }
    126 
    127 
    128 
    129 
    130 
    131 G4bool                                          G4CompositeEMDataSet :: LoadData(const G4String & argFileName)
    132 {
    133  CleanUpComponents();
    134 
    135  for (G4int z(minZ); z<maxZ; z++)
    136  {
    137   G4VEMDataSet * component=new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
    138   if (!component->LoadData(argFileName))
    139   {
    140    delete component;
    141    return false;
    142   }
    143  
    144   AddComponent(component);
    145  }
    146  
    147  return true;
    148 }
    149 
    150 
    151 
    152 G4bool                                          G4CompositeEMDataSet :: SaveData(const G4String & argFileName) const
    153 {
    154  for (G4int z(minZ); z<maxZ; z++)
    155  {
    156   const G4VEMDataSet * component(GetComponent(z-minZ));
    157  
    158   if (!component)
    159   {
    160    std::ostringstream message;
    161    message << "G4CompositeEMDataSet::SaveData - component " << (z-minZ) << " not found";
    162  
    163    G4Exception(message.str().c_str());
    164   }
    165 
    166   if (!component->SaveData(argFileName))
    167    return false;
    168  }
    169  
    170  return true;
    171 }
    172 
    173 
    174 
    175 
    176 
    177 void                                            G4CompositeEMDataSet :: CleanUpComponents(void)
    178 {
    179  while (!components.empty())
    180  {
    181   if (components.back())
    182    delete components.back();
    183 
    184   components.pop_back();
    185  }
    186 }
    187 
Note: See TracChangeset for help on using the changeset viewer.