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

Last change on this file since 1168 was 1007, checked in by garnier, 15 years ago

update to geant4.9.2

File size: 5.0 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.13 2008/03/17 13:40:53 pia Exp $
28// GEANT4 tag $Name: geant4-09-02 $
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
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)
55{
56  if (algorithm == 0) 
57    G4Exception("G4CompositeEMDataSet::G4CompositeEMDataSet - interpolation == 0");
58}
59
60
61
62G4CompositeEMDataSet::~G4CompositeEMDataSet()
63{
64  CleanUpComponents();
65  if (algorithm) delete algorithm;
66}
67
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;
131}
132
133
134
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        }
147
148      if (!component->SaveData(argFileName))
149        return false;
150    }
151 
152  return true;
153}
154
155void G4CompositeEMDataSet::CleanUpComponents(void)
156{
157  while (!components.empty())
158    {
159      if (components.back())
160        delete components.back();
161      components.pop_back();
162    }
163}
164
165
166G4double G4CompositeEMDataSet::RandomSelect(G4int componentId) const
167{
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;
175}
Note: See TracBrowser for help on using the repository browser.