source: trunk/source/processes/electromagnetic/pii/src/G4CompositeDataSet.cc@ 1357

Last change on this file since 1357 was 1350, checked in by garnier, 15 years ago

update to last version 4.9.4

File size: 4.9 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: G4CompositeDataSet.cc,v 1.2 2010/11/19 17:16:20 pia Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
29//
30// Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
31//
32// History:
33// -----------
34// 1 Aug 2001 MGP Created
35// 31 Jul 2008 MGP Revised and renamed to G4CompositeDataSet
36//
37//
38// -------------------------------------------------------------------
39
40#include "G4CompositeDataSet.hh"
41#include "G4DataSet.hh"
42#include "G4IInterpolator.hh"
43#include <fstream>
44#include <sstream>
45
46G4CompositeDataSet::G4CompositeDataSet(G4IInterpolator* algo,
47 G4double eUnit,
48 G4double dataUnit,
49 G4int zMin,
50 G4int zMax)
51 :
52 algorithm(algo),
53 unitEnergies(eUnit),
54 unitData(dataUnit),
55 minZ(zMin),
56 maxZ(zMax)
57{
58 if (algorithm == 0)
59 G4Exception("G4CompositeDataSet::G4CompositeDataSet - interpolation == 0");
60}
61
62
63
64G4CompositeDataSet::~G4CompositeDataSet()
65{
66 CleanUpComponents();
67 if (algorithm) delete algorithm;
68}
69
70
71G4double G4CompositeDataSet::FindValue(G4double energy, G4int componentId) const
72{
73 const G4IDataSet* component(GetComponent(componentId));
74
75 if (component) return component->FindValue(energy);
76
77 std::ostringstream message;
78 message << "G4CompositeDataSet::FindValue - component " << componentId << " not found";
79
80 G4Exception(message.str().c_str());
81
82 return 0.;
83}
84
85void G4CompositeDataSet::PrintData(void) const
86{
87 const size_t n(NumberOfComponents());
88
89 G4cout << "The data set has " << n << " components" << G4endl;
90 G4cout << G4endl;
91
92 size_t i(0);
93
94 while (i<n)
95 {
96 G4cout << "--- Component " << i << " ---" << G4endl;
97 GetComponent(i)->PrintData();
98 i++;
99 }
100}
101
102void G4CompositeDataSet::SetEnergiesData(G4DataVector* energies, G4DataVector* data, G4int componentId)
103{
104 G4IDataSet * component(components[componentId]);
105
106 if (component)
107 {
108 component->SetEnergiesData(energies, data, 0);
109 return;
110 }
111
112 std::ostringstream message;
113 message << "G4CompositeDataSet::SetEnergiesData - component " << componentId << " not found";
114
115 G4Exception(message.str().c_str());
116}
117
118G4bool G4CompositeDataSet::LoadData(const G4String& argFileName)
119{
120 CleanUpComponents();
121
122 for (G4int z(minZ); z<maxZ; z++)
123 {
124 G4IDataSet* component = new G4DataSet(z, algorithm->Clone(), unitEnergies, unitData);
125 if (!component->LoadData(argFileName))
126 {
127 delete component;
128 return false;
129 }
130 AddComponent(component);
131 }
132 return true;
133}
134
135
136
137G4bool G4CompositeDataSet::SaveData(const G4String& argFileName) const
138{
139 for (G4int z=minZ; z<maxZ; z++)
140 {
141 const G4IDataSet* component(GetComponent(z-minZ));
142
143 if (!component)
144 {
145 std::ostringstream message;
146 message << "G4CompositeDataSet::SaveData - component " << (z-minZ) << " not found";
147 G4Exception(message.str().c_str());
148 }
149
150 if (!component->SaveData(argFileName))
151 return false;
152 }
153
154 return true;
155}
156
157void G4CompositeDataSet::CleanUpComponents(void)
158{
159 while (!components.empty())
160 {
161 if (components.back())
162 delete components.back();
163 components.pop_back();
164 }
165}
166
167
168G4double G4CompositeDataSet::RandomSelect(G4int componentId) const
169{
170 G4double value = 0.;
171 if (componentId >= 0 && componentId < (G4int)components.size())
172 {
173 const G4IDataSet* dataSet = GetComponent(componentId);
174 value = dataSet->RandomSelect();
175 }
176 return value;
177}
Note: See TracBrowser for help on using the repository browser.