Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4RDShellEMDataSet.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: G4RDShellEMDataSet.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 // 09.10.01 V.Ivanchenko Add case z=0
36 // 9 Mar 2008 MGP Cleaned up unreadable code modified by former developer
37 // (Further clean-up needed)
38 //
39 // -------------------------------------------------------------------
40 
41 #include "G4RDShellEMDataSet.hh"
42 #include "G4RDEMDataSet.hh"
43 #include "G4RDVDataSetAlgorithm.hh"
44 #include <fstream>
45 #include <sstream>
46 
47 
49  G4double eUnit,
50  G4double dataUnit)
51  :
52  z(zeta),
53  algorithm(algo),
54  unitEnergies(eUnit),
55  unitData(dataUnit)
56 {
57  if (algorithm == 0)
58  G4Exception("G4RDShellEMDataSet::G4RDShellEMDataSet()", "InvalidSetup",
59  FatalException, "Interpolation == 0!");
60 }
61 
62 
64 {
66  if (algorithm) delete algorithm;
67 }
68 
69 
71 {
72  // Returns the sum over the shells corresponding to e
73  G4double value = 0.;
74 
75  std::vector<G4RDVEMDataSet *>::const_iterator i(components.begin());
76  std::vector<G4RDVEMDataSet *>::const_iterator end(components.end());
77 
78  while (i != end)
79  {
80  value += (*i)->FindValue(energy);
81  i++;
82  }
83 
84  return value;
85 }
86 
87 
89 {
90  const size_t n = NumberOfComponents();
91 
92  G4cout << "The data set has " << n << " components" << G4endl;
93  G4cout << G4endl;
94 
95  size_t i = 0;
96 
97  while (i < n)
98  {
99  G4cout << "--- Component " << i << " ---" << G4endl;
100  GetComponent(i)->PrintData();
101  i++;
102  }
103 }
104 
105 
107  G4DataVector* data,
108  G4int componentId)
109 {
110  G4RDVEMDataSet* component = components[componentId];
111 
112  if (component)
113  {
114  component->SetEnergiesData(energies, data, 0);
115  return;
116  }
117 
118  std::ostringstream message;
119  message << "Component " << componentId << " not found";
120 
121  G4Exception("G4RDShellEMDataSet::SetEnergiesData()", "DataNotFound",
122  FatalException, message.str().c_str());
123 }
124 
125 
127 {
129 
130  G4String fullFileName = FullFileName(file);
131  std::ifstream in(fullFileName);
132 
133  if (!in.is_open())
134  {
135  G4String message("Data file \"");
136  message += fullFileName;
137  message += "\" not found";
138  G4Exception("G4RDShellEMDataSet::LoadData()", "DataNotFound",
139  FatalException, message);
140  }
141 
142  G4DataVector* energies = 0;
143  G4DataVector* data = 0;
144 
145  G4double a = 0.;
146  G4int shellIndex = 0;
147  bool energyColumn = true;
148 
149  do
150  {
151  in >> a;
152 
153  if (a == -1)
154  {
155  if (energyColumn && energies!=0)
156  {
157  AddComponent(new G4RDEMDataSet(shellIndex, energies, data, algorithm->Clone(), unitEnergies, unitData));
158  energies = 0;
159  data = 0;
160  }
161 
162  energyColumn = (!energyColumn);
163  }
164  else if (a != -2)
165  {
166  if (energies == 0)
167  {
168  energies = new G4DataVector;
169  data = new G4DataVector;
170  }
171 
172  if (energyColumn)
173  energies->push_back(a * unitEnergies);
174  else
175  data->push_back(a * unitData);
176 
177  energyColumn = (!energyColumn);
178  }
179  }
180  while (a != -2);
181 
182  return true;
183 }
184 
185 
187 {
188  G4String fullFileName = FullFileName(file);
189  std::ofstream out(fullFileName);
190 
191  if (!out.is_open())
192  {
193  G4String message("Cannot open \"");
194  message += fullFileName;
195  message += "\"";
196  G4Exception("G4RDEMDataSet::SaveData()", "CannotOpenFile",
197  FatalException, message);
198  }
199 
200  const size_t n = NumberOfComponents();
201  size_t k = 0;
202 
203  while (k < n)
204  {
205  const G4RDVEMDataSet* component = GetComponent(k);
206 
207  if (component)
208  {
209  const G4DataVector& energies = component->GetEnergies(0);
210  const G4DataVector& data = component->GetData(0);
211 
212  G4DataVector::const_iterator i = energies.begin();
213  G4DataVector::const_iterator endI = energies.end();
214  G4DataVector::const_iterator j = data.begin();
215 
216  while (i != endI)
217  {
218  out.precision(10);
219  out.width(15);
220  out.setf(std::ofstream::left);
221  out << ((*i)/unitEnergies) << ' ';
222 
223  out.precision(10);
224  out.width(15);
225  out.setf(std::ofstream::left);
226  out << ((*j)/unitData) << std::endl;
227  i++;
228  j++;
229  }
230  }
231 
232  out.precision(10);
233  out.width(15);
234  out.setf(std::ofstream::left);
235  out << -1.f << ' ';
236 
237  out.precision(10);
238  out.width(15);
239  out.setf(std::ofstream::left);
240  out << -1.f << std::endl;
241 
242  k++;
243  }
244 
245  out.precision(10);
246  out.width(15);
247  out.setf(std::ofstream::left);
248  out << -2.f << ' ';
249 
250  out.precision(10);
251  out.width(15);
252  out.setf(std::ofstream::left);
253  out << -2.f << std::endl;
254 
255  return true;
256 }
257 
258 
260 {
261  while (!components.empty())
262  {
263  if (components.back()) delete components.back();
264  components.pop_back();
265  }
266 }
267 
268 
270 {
271  char* path = getenv("G4LEDATA");
272  if (!path)
273  G4Exception("G4RDShellEMDataSet::FullFileName()", "InvalidSetup",
274  FatalException, "G4LEDATA environment variable not set!");
275 
276  std::ostringstream fullFileName;
277 
278  fullFileName << path << '/' << fileName << z << ".dat";
279 
280  return G4String(fullFileName.str().c_str());
281 }
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
std::vector< G4RDVEMDataSet * > components
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
#define G4endl
Definition: G4ios.hh:61
virtual const G4DataVector & GetEnergies(G4int componentId) const =0
Double_t z
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
virtual void PrintData(void) const =0
virtual void PrintData(void) const
const XML_Char const XML_Char * data
Definition: expat.h:268
virtual G4bool LoadData(const G4String &fileName)
virtual G4RDVDataSetAlgorithm * Clone() const =0
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
const XML_Char int const XML_Char * value
Definition: expat.h:331
virtual const G4RDVEMDataSet * GetComponent(G4int componentId) const
virtual G4double FindValue(G4double energy, G4int componentId=0) const
double energy
Definition: plottest35.C:25
virtual size_t NumberOfComponents(void) const
virtual void AddComponent(G4RDVEMDataSet *dataSet)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
ifstream in
Definition: comparison.C:7
virtual void SetEnergiesData(G4DataVector *energies, G4DataVector *data, G4int componentId)
TFile * file
G4String FullFileName(const G4String &fileName) const
G4RDVDataSetAlgorithm * algorithm
G4GLOB_DLL std::ostream G4cout
virtual const G4DataVector & GetData(G4int componentId) const =0
Char_t n[5]
virtual G4bool SaveData(const G4String &fileName) const