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

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

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 7.1 KB
Line 
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//
27// $Id: G4CompositeEMDataSet.cc,v 1.15 2009/09/25 07:41:34 sincerti Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
29//
30// Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
31//
32// History:
33// -----------
34// 1 Aug 2001   MGP        Created
35//
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//
50// -------------------------------------------------------------------
51
52#include "G4CompositeEMDataSet.hh"
53#include "G4EMDataSet.hh"
54#include "G4VDataSetAlgorithm.hh"
55#include <fstream>
56#include <sstream>
57
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)
69{
70  if (algorithm == 0) 
71    G4Exception("G4CompositeEMDataSet::G4CompositeEMDataSet - interpolation == 0");
72}
73
74
75
76G4CompositeEMDataSet::~G4CompositeEMDataSet()
77{
78  CleanUpComponents();
79  if (algorithm) delete algorithm;
80}
81
82
83G4double G4CompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const
84{
85  const G4VEMDataSet* component(GetComponent(argComponentId));
86 
87  if (component) return component->FindValue(argEnergy);
88
89  std::ostringstream message;
90  message << "G4CompositeEMDataSet::FindValue - component " << argComponentId << " not found";
91 
92  G4Exception(message.str().c_str());
93 
94  return 0.;
95}
96
97void G4CompositeEMDataSet::PrintData(void) const
98{
99  const size_t n(NumberOfComponents());
100
101  G4cout << "The data set has " << n << " components" << G4endl;
102  G4cout << G4endl;
103 
104  size_t i(0);
105 
106  while (i<n)
107    {
108      G4cout << "--- Component " << i << " ---" << G4endl;
109      GetComponent(i)->PrintData();
110      i++;
111    }
112}
113
114void G4CompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId)
115{
116  G4VEMDataSet * component(components[argComponentId]);
117 
118  if (component)
119    {
120      component->SetEnergiesData(argEnergies, argData, 0);
121      return;
122    }
123
124  std::ostringstream message;
125  message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
126 
127  G4Exception(message.str().c_str());
128}
129
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
151G4bool G4CompositeEMDataSet::LoadData(const G4String& argFileName)
152{
153  CleanUpComponents(); 
154
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;
166}
167
168
169G4bool G4CompositeEMDataSet::LoadNonLogData(const G4String& argFileName)
170{
171  CleanUpComponents(); 
172
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
187G4bool G4CompositeEMDataSet::SaveData(const G4String& argFileName) const
188{
189  for (G4int z=minZ; z<maxZ; z++)
190    {
191      const G4VEMDataSet* component(GetComponent(z-minZ));
192 
193      if (!component)
194        {
195          std::ostringstream message;
196          message << "G4CompositeEMDataSet::SaveData - component " << (z-minZ) << " not found";
197          G4Exception(message.str().c_str());
198        }
199
200      if (!component->SaveData(argFileName))
201        return false;
202    }
203 
204  return true;
205}
206
207void G4CompositeEMDataSet::CleanUpComponents(void)
208{
209  while (!components.empty())
210    {
211      if (components.back())
212        delete components.back();
213      components.pop_back();
214    }
215}
216
217
218G4double G4CompositeEMDataSet::RandomSelect(G4int componentId) const
219{
220  G4double value = 0.;
221  if (componentId >= 0 && componentId < (G4int)components.size())
222    {
223      const G4VEMDataSet* dataSet = GetComponent(componentId);
224      value = dataSet->RandomSelect();
225    }
226  return value;
227}
Note: See TracBrowser for help on using the repository browser.