Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4RDCompositeEMDataSet.cc
이 파일의 문서화 페이지로 가기
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: G4RDCompositeEMDataSet.cc 107396 2017-11-10 08:28:08Z gcosmo $
28 // GEANT4 tag $Name: $
29 //
30 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
31 //
32 // History:
33 // -----------
34 // 1 Aug 2001 MGP Created
35 //
36 // -------------------------------------------------------------------
37 
39 #include "G4RDEMDataSet.hh"
40 #include "G4RDVDataSetAlgorithm.hh"
41 #include <fstream>
42 #include <sstream>
43 
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("G4RDCompositeEMDataSet::G4RDCompositeEMDataSet()",
58  "InvalidSetup", FatalException, "Interpolation == 0!");
59 }
60 
61 
62 
64 {
66  if (algorithm) delete algorithm;
67 }
68 
69 
70 G4double G4RDCompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const
71 {
72  const G4RDVEMDataSet* component(GetComponent(argComponentId));
73 
74  if (component) return component->FindValue(argEnergy);
75 
76  std::ostringstream message;
77  message << "Component " << argComponentId << " not found";
78 
79  G4Exception("G4RDCompositeEMDataSet::FindValue()",
80  "DataNotFound", FatalException, message.str().c_str());
81 
82  return 0.;
83 }
84 
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 
102 void G4RDCompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId)
103 {
104  G4RDVEMDataSet * component(components[argComponentId]);
105 
106  if (component)
107  {
108  component->SetEnergiesData(argEnergies, argData, 0);
109  return;
110  }
111 
112  std::ostringstream message;
113  message << "Component " << argComponentId << " not found";
114 
115  G4Exception("G4RDCompositeEMDataSet::SetEnergiesData()",
116  "DataNotFound", FatalException, message.str().c_str());
117 }
118 
120 {
122 
123  for (G4int z(minZ); z<maxZ; z++)
124  {
126  if (!component->LoadData(argFileName))
127  {
128  delete component;
129  return false;
130  }
131  AddComponent(component);
132  }
133  return true;
134 }
135 
136 
137 
139 {
140  for (G4int z=minZ; z<maxZ; z++)
141  {
142  const G4RDVEMDataSet* component(GetComponent(z-minZ));
143 
144  if (!component)
145  {
146  std::ostringstream message;
147  message << "Component " << (z-minZ) << " not found";
148  G4Exception("G4RDCompositeEMDataSet::SaveData()",
149  "DataNotFound", FatalException, message.str().c_str());
150  }
151 
152  if (!component->SaveData(argFileName))
153  return false;
154  }
155 
156  return true;
157 }
158 
160 {
161  while (!components.empty())
162  {
163  if (components.back())
164  delete components.back();
165  components.pop_back();
166  }
167 }
168 
169 
171 {
172  G4double value = 0.;
173  if (componentId >= 0 && componentId < (G4int)components.size())
174  {
175  const G4RDVEMDataSet* dataSet = GetComponent(componentId);
176  value = dataSet->RandomSelect();
177  }
178  return value;
179 }
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
virtual void AddComponent(G4RDVEMDataSet *dataSet)
virtual G4double FindValue(G4double x, G4int componentId=0) const
virtual G4bool SaveData(const G4String &fileName) const =0
G4RDVDataSetAlgorithm * algorithm
#define G4endl
Definition: G4ios.hh:61
Double_t z
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
virtual void PrintData(void) const
virtual void PrintData(void) const =0
static const G4int maxZ
virtual G4bool LoadData(const G4String &fileName)
virtual G4RDVDataSetAlgorithm * Clone() const =0
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int componentId)
std::vector< G4RDVEMDataSet * > components
virtual G4bool SaveData(const G4String &fileName) const
const XML_Char int const XML_Char * value
Definition: expat.h:331
virtual size_t NumberOfComponents() const
virtual G4double FindValue(G4double x, G4int componentId=0) const =0
virtual G4bool LoadData(const G4String &fileName)=0
virtual G4double RandomSelect(G4int componentId=0) const =0
virtual const G4RDVEMDataSet * GetComponent(G4int componentId) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
Char_t n[5]
virtual G4double RandomSelect(G4int componentId) const