Geant4  10.02.p01
G4PixeShellDataSet.cc
Go to the documentation of this file.
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: G4PixeShellDataSet.cc 70904 2013-06-07 10:34:25Z gcosmo $
28 //
29 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
30 //
31 // History:
32 // -----------
33 // 1 Aug 2001 MGP Created
34 // 09.10.01 V.Ivanchenko Add case z=0
35 // 9 Mar 2008 MGP Cleaned up unreadable code modified by former developer
36 // (Further clean-up needed)
37 // 31 Jul 2008 MGP Revised
38 //
39 // -------------------------------------------------------------------
40 
41 #include "G4PixeShellDataSet.hh"
42 #include "G4DataSet.hh"
43 #include "G4IInterpolator.hh"
44 #include <fstream>
45 #include <sstream>
46 
47 
49  G4IInterpolator* algo,
50  const G4String& modelK,
51  const G4String& modelL,
52  const G4String& modelM,
53  G4double eUnit,
54  G4double dataUnit):
55  z(zeta),
56  algorithm(algo),
57  unitEnergies(eUnit),
58  unitData(dataUnit)
59 {
60  if (algorithm == 0) G4Exception("G4PixeShellDataSet::G4PixeShellDataSet",
61  "pii00000301",
63  "interpolation == 0");
64 
65  crossModel.push_back(modelK);
66  crossModel.push_back(modelL);
67  crossModel.push_back(modelM);
68 
69  shellName.push_back("k");
70  shellName.push_back("l");
71  shellName.push_back("m");
72 
73  size_t sizeK = modelK.size();
74  size_t sizeL = modelL.size();
75  size_t sizeM = modelM.size();
76 
77  if (sizeK > 0) subShellName.push_back("k");
78 
79  if (sizeK > 0 && sizeL > 0)
80  {
81  subShellName.push_back("l1");
82  subShellName.push_back("l2");
83  subShellName.push_back("l3");
84  }
85  if (sizeK > 0 && sizeL > 0 && sizeM >0)
86  {
87  subShellName.push_back("m1");
88  subShellName.push_back("m2");
89  subShellName.push_back("m3");
90  subShellName.push_back("m4");
91  subShellName.push_back("m5");
92  }
93 }
94 
95 
97 {
99  if (algorithm) delete algorithm;
100 }
101 
102 
104 {
105  // Returns the sum over the shells corresponding to e
106  G4double value = 0.;
107 
108  std::vector<G4IDataSet *>::const_iterator i(components.begin());
109  std::vector<G4IDataSet *>::const_iterator end(components.end());
110 
111  while (i != end)
112  {
113  value += (*i)->FindValue(energy);
114  i++;
115  }
116  return value;
117 }
118 
119 
121 {
122  const size_t n = NumberOfComponents();
123 
124  G4cout << "The data set has " << n << " components" << G4endl;
125  G4cout << G4endl;
126 
127  size_t i = 0;
128 
129  while (i < n)
130  {
131  G4cout << "--- Component " << i << " ---" << G4endl;
132  GetComponent(i)->PrintData();
133  i++;
134  }
135 }
136 
137 
139  G4DataVector* data,
140  G4int componentId)
141 {
142  G4IDataSet* component = components[componentId];
143 
144  if (component)
145  {
146  component->SetEnergiesData(energies, data, 0);
147  return;
148  }
149 
150  std::ostringstream message;
151  message << "G4PixeShellDataSet::SetEnergiesData - component " << componentId << " not found";
152 
153  G4Exception("G4PixeShellDataSet::SetEnergiesData",
154  "pii000000310",
156  message.str().c_str());
157 }
158 
159 
161 {
163 
164  // Load shell cross sections
165 
166  G4int nShells = subShellName.size();
167 
168  for (G4int subShellIndex=0; subShellIndex<nShells; subShellIndex++)
169  {
170  G4String subName = subShellName[subShellIndex];
171  G4String fullFileName = FullFileName(file,subName);
172 
173  // Create component DataSet with the data from the current subshell
174  G4IDataSet* dataSet = new G4DataSet(z,algorithm);
175  dataSet->LoadData(fullFileName);
176 
177  // Add component to the ShellDataSet
178  AddComponent(dataSet);
179  }
180 
181  return true;
182 }
183 
184 
186 {
187  // Dummy implementation
188  return true;
189 }
190 
191 
193 {
194  while (!components.empty())
195  {
196  if (components.back()) delete components.back();
197  components.pop_back();
198  }
199 }
200 
201 
203  const G4String& subShell) const
204 {
205  char* path = getenv("G4PIIDATA");
206  if (!path)
207  G4Exception("G4PixeShellDataSet::FullFileName",
208  "pii00000320",
210  "G4PIIDATA environment variable not set");
211 
212  // Identify the shell this subshell belongs to
213  G4int shellIndex = TranslateShell(subShell);
214  G4String shellString = shellName[shellIndex];
215  G4String shellModel = crossModel[shellIndex];
216 
217  std::ostringstream fullFileName;
218 
219  fullFileName
220  //<< path
221  << "pixe/"
222  << file
223  << '/'
224  << shellString
225  << '/'
226  << shellModel
227  << '/'
228  << subShell
229  << '-' ;
230 // << z
231  // << ".dat";
232 
233  G4String test(fullFileName.str().c_str());
234  // std::cout << "PixeShellDataSet - Reading data from file " << test << std::endl;
235 
236  return G4String(fullFileName.str().c_str());
237 }
238 
240 {
241  // By default return K shell
242  G4int index = 0;
243 
244  if (subShell == "l1" || subShell == "l2" || subShell == "l3" ) index = 1;
245  if (subShell == "m1" ||
246  subShell == "m2" ||
247  subShell == "m3" ||
248  subShell == "m4" ||
249  subShell == "m5" ) index = 2;
250  return index;
251 }
G4IInterpolator * algorithm
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
std::vector< G4String > crossModel
virtual void SetEnergiesData(G4DataVector *energies, G4DataVector *data, G4int componentId)
G4double z
Definition: TRTMaterials.hh:39
virtual G4double FindValue(G4double energy, G4int componentId=0) const
std::vector< G4String > subShellName
std::vector< G4IDataSet * > components
G4String FullFileName(const G4String &particleType, const G4String &subShell) const
int G4int
Definition: G4Types.hh:78
std::vector< G4String > shellName
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
virtual const G4IDataSet * GetComponent(G4int componentId) const
const G4int n
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual G4bool LoadData(const G4String &fileName)=0
G4int TranslateShell(const G4String &subShell) const
G4double energy(const ThreeVector &p, const G4double m)
virtual G4bool LoadData(const G4String &fileName)
#define G4endl
Definition: G4ios.hh:61
virtual void PrintData(void) const
double G4double
Definition: G4Types.hh:76
virtual void PrintData(void) const =0
virtual G4bool SaveData(const G4String &fileName) const
virtual void AddComponent(G4IDataSet *dataSet)
virtual size_t NumberOfComponents(void) const