source: trunk/source/processes/electromagnetic/lowenergy/src/G4CompositeEMDataSet.cc @ 1348

Last change on this file since 1348 was 1347, checked in by garnier, 14 years ago

geant4 tag 9.4

File size: 7.1 KB
RevLine 
[819]1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
[1347]27// $Id: G4CompositeEMDataSet.cc,v 1.16 2010/11/26 11:51:11 pandola Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
[819]29//
30// Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
31//
32// History:
33// -----------
34// 1 Aug 2001   MGP        Created
35//
[1192]36// 15 Jul 2009   Nicolas A. Karakatsanis
37//
38//                           - LoadNonLogData method was created to load only the non-logarithmic data from G4EMLOW
39//                             dataset. It is essentially performing the data loading operations as in the past.
40//
41//                           - LoadData method was revised in order to calculate the logarithmic values of the data
42//                             It retrieves the data values from the G4EMLOW data files but, then, calculates the
43//                             respective log values and loads them to seperate data structures.
44//
45//                           - SetLogEnergiesData method was cretaed to set logarithmic values to G4 data vectors.
46//                             The EM data sets, initialized this way, contain both non-log and log values.
47//                             These initialized data sets can enhance the computing performance of data interpolation
48//                             operations
49//
[819]50// -------------------------------------------------------------------
51
52#include "G4CompositeEMDataSet.hh"
53#include "G4EMDataSet.hh"
54#include "G4VDataSetAlgorithm.hh"
55#include <fstream>
56#include <sstream>
57
[961]58G4CompositeEMDataSet::G4CompositeEMDataSet(G4VDataSetAlgorithm* argAlgorithm, 
59                                           G4double argUnitEnergies, 
60                                           G4double argUnitData, 
61                                           G4int argMinZ, 
62                                           G4int argMaxZ)
63  :
64  algorithm(argAlgorithm),
65  unitEnergies(argUnitEnergies),
66  unitData(argUnitData),
67  minZ(argMinZ),
68  maxZ(argMaxZ)
[819]69{
[961]70  if (algorithm == 0) 
71    G4Exception("G4CompositeEMDataSet::G4CompositeEMDataSet - interpolation == 0");
[819]72}
73
74
75
[961]76G4CompositeEMDataSet::~G4CompositeEMDataSet()
[819]77{
[961]78  CleanUpComponents();
79  if (algorithm) delete algorithm;
[819]80}
81
82
[961]83G4double G4CompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const
[819]84{
[961]85  const G4VEMDataSet* component(GetComponent(argComponentId));
[819]86 
[961]87  if (component) return component->FindValue(argEnergy);
[819]88
[961]89  std::ostringstream message;
90  message << "G4CompositeEMDataSet::FindValue - component " << argComponentId << " not found";
[819]91 
[961]92  G4Exception(message.str().c_str());
[819]93 
[961]94  return 0.;
[819]95}
96
[961]97void G4CompositeEMDataSet::PrintData(void) const
[819]98{
[961]99  const size_t n(NumberOfComponents());
[819]100
[961]101  G4cout << "The data set has " << n << " components" << G4endl;
102  G4cout << G4endl;
[819]103 
[961]104  size_t i(0);
[819]105 
[961]106  while (i<n)
107    {
108      G4cout << "--- Component " << i << " ---" << G4endl;
109      GetComponent(i)->PrintData();
110      i++;
111    }
[819]112}
113
[961]114void G4CompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId)
[819]115{
[961]116  G4VEMDataSet * component(components[argComponentId]);
[819]117 
[961]118  if (component)
119    {
120      component->SetEnergiesData(argEnergies, argData, 0);
121      return;
122    }
[819]123
[961]124  std::ostringstream message;
125  message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
[819]126 
[961]127  G4Exception(message.str().c_str());
[819]128}
129
[1192]130void G4CompositeEMDataSet::SetLogEnergiesData(G4DataVector* argEnergies, 
131                                              G4DataVector* argData,
132                                              G4DataVector* argLogEnergies,
133                                              G4DataVector* argLogData, 
134                                              G4int argComponentId)
135{
136  G4VEMDataSet * component(components[argComponentId]);
137 
138  if (component)
139    {
140      component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
141      return;
142    }
143
144  std::ostringstream message;
145  message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
146 
147  G4Exception(message.str().c_str());
148}
149
150
[961]151G4bool G4CompositeEMDataSet::LoadData(const G4String& argFileName)
[819]152{
[961]153  CleanUpComponents(); 
[819]154
[961]155  for (G4int z(minZ); z<maxZ; z++)
156    {
157      G4VEMDataSet* component = new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
158      if (!component->LoadData(argFileName))
159        {
160          delete component;
161          return false;
162        }
163      AddComponent(component);
164    }
165  return true;
[819]166}
167
168
[1192]169G4bool G4CompositeEMDataSet::LoadNonLogData(const G4String& argFileName)
170{
171  CleanUpComponents(); 
[819]172
[1192]173  for (G4int z(minZ); z<maxZ; z++)
174    {
175      G4VEMDataSet* component = new G4EMDataSet(z, algorithm->Clone(), unitEnergies, unitData);
176      if (!component->LoadNonLogData(argFileName))
177        {
178          delete component;
179          return false;
180        }
181      AddComponent(component);
182    }
183  return true;
184}
185
186
[961]187G4bool G4CompositeEMDataSet::SaveData(const G4String& argFileName) const
[819]188{
[961]189  for (G4int z=minZ; z<maxZ; z++)
190    {
191      const G4VEMDataSet* component(GetComponent(z-minZ));
[819]192 
[961]193      if (!component)
194        {
195          std::ostringstream message;
196          message << "G4CompositeEMDataSet::SaveData - component " << (z-minZ) << " not found";
197          G4Exception(message.str().c_str());
[1347]198          return false;
[961]199        }
[819]200
[961]201      if (!component->SaveData(argFileName))
202        return false;
203    }
[819]204 
[961]205  return true;
[819]206}
207
[961]208void G4CompositeEMDataSet::CleanUpComponents(void)
209{
210  while (!components.empty())
211    {
212      if (components.back())
213        delete components.back();
214      components.pop_back();
215    }
216}
[819]217
218
[961]219G4double G4CompositeEMDataSet::RandomSelect(G4int componentId) const
[819]220{
[961]221  G4double value = 0.;
222  if (componentId >= 0 && componentId < (G4int)components.size())
223    {
224      const G4VEMDataSet* dataSet = GetComponent(componentId);
225      value = dataSet->RandomSelect();
226    }
227  return value;
[819]228}
Note: See TracBrowser for help on using the repository browser.