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

Last change on this file since 966 was 961, checked in by garnier, 17 years ago

update processes

File size: 5.0 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//
[961]27// $Id: G4CompositeEMDataSet.cc,v 1.13 2008/03/17 13:40:53 pia Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
[819]29//
30// Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
31//
32// History:
33// -----------
34// 1 Aug 2001 MGP Created
35//
36// -------------------------------------------------------------------
37
38#include "G4CompositeEMDataSet.hh"
39#include "G4EMDataSet.hh"
40#include "G4VDataSetAlgorithm.hh"
41#include <fstream>
42#include <sstream>
43
[961]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)
[819]55{
[961]56 if (algorithm == 0)
57 G4Exception("G4CompositeEMDataSet::G4CompositeEMDataSet - interpolation == 0");
[819]58}
59
60
61
[961]62G4CompositeEMDataSet::~G4CompositeEMDataSet()
[819]63{
[961]64 CleanUpComponents();
65 if (algorithm) delete algorithm;
[819]66}
67
68
[961]69G4double G4CompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const
[819]70{
[961]71 const G4VEMDataSet* component(GetComponent(argComponentId));
[819]72
[961]73 if (component) return component->FindValue(argEnergy);
[819]74
[961]75 std::ostringstream message;
76 message << "G4CompositeEMDataSet::FindValue - component " << argComponentId << " not found";
[819]77
[961]78 G4Exception(message.str().c_str());
[819]79
[961]80 return 0.;
[819]81}
82
[961]83void G4CompositeEMDataSet::PrintData(void) const
[819]84{
[961]85 const size_t n(NumberOfComponents());
[819]86
[961]87 G4cout << "The data set has " << n << " components" << G4endl;
88 G4cout << G4endl;
[819]89
[961]90 size_t i(0);
[819]91
[961]92 while (i<n)
93 {
94 G4cout << "--- Component " << i << " ---" << G4endl;
95 GetComponent(i)->PrintData();
96 i++;
97 }
[819]98}
99
[961]100void G4CompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId)
[819]101{
[961]102 G4VEMDataSet * component(components[argComponentId]);
[819]103
[961]104 if (component)
105 {
106 component->SetEnergiesData(argEnergies, argData, 0);
107 return;
108 }
[819]109
[961]110 std::ostringstream message;
111 message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
[819]112
[961]113 G4Exception(message.str().c_str());
[819]114}
115
[961]116G4bool G4CompositeEMDataSet::LoadData(const G4String& argFileName)
[819]117{
[961]118 CleanUpComponents();
[819]119
[961]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;
[819]131}
132
133
134
[961]135G4bool G4CompositeEMDataSet::SaveData(const G4String& argFileName) const
[819]136{
[961]137 for (G4int z=minZ; z<maxZ; z++)
138 {
139 const G4VEMDataSet* component(GetComponent(z-minZ));
[819]140
[961]141 if (!component)
142 {
143 std::ostringstream message;
144 message << "G4CompositeEMDataSet::SaveData - component " << (z-minZ) << " not found";
145 G4Exception(message.str().c_str());
146 }
[819]147
[961]148 if (!component->SaveData(argFileName))
149 return false;
150 }
[819]151
[961]152 return true;
[819]153}
154
[961]155void G4CompositeEMDataSet::CleanUpComponents(void)
156{
157 while (!components.empty())
158 {
159 if (components.back())
160 delete components.back();
161 components.pop_back();
162 }
163}
[819]164
165
[961]166G4double G4CompositeEMDataSet::RandomSelect(G4int componentId) const
[819]167{
[961]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;
[819]175}
Note: See TracBrowser for help on using the repository browser.