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 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 //
 28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
 29 //
 30 // History:
 31 // -----------
 32 //  1 Aug 2001   MGP        Created
 33 // 09.10.01   V.Ivanchenko Add case z=0
 34 //  9 Mar 2008   MGP        Cleaned up unreadable code modified by former developer
 35 //                          (Further clean-up needed) 
 36 //
 37 // -------------------------------------------------------------------
 38 
 39 #include "G4RDShellEMDataSet.hh"
 40 #include "G4RDEMDataSet.hh"
 41 #include "G4RDVDataSetAlgorithm.hh"
 42 #include <fstream>
 43 #include <sstream>
 44 
 45 
 46 G4RDShellEMDataSet::G4RDShellEMDataSet(G4int zeta, G4RDVDataSetAlgorithm* algo, 
 47            G4double eUnit, 
 48            G4double dataUnit)
 49   :
 50   z(zeta),
 51   algorithm(algo),
 52   unitEnergies(eUnit),
 53   unitData(dataUnit)
 54 {
 55   if (algorithm == 0)
 56     G4Exception("G4RDShellEMDataSet::G4RDShellEMDataSet()", "InvalidSetup",
 57                 FatalException, "Interpolation == 0!");
 58 }
 59 
 60 
 61 G4RDShellEMDataSet::~G4RDShellEMDataSet()
 62 {
 63   CleanUpComponents();
 64   if (algorithm) delete algorithm;
 65 }
 66 
 67 
 68 G4double G4RDShellEMDataSet::FindValue(G4double energy, G4int /* componentId */) const
 69 {
 70   // Returns the sum over the shells corresponding to e
 71   G4double value = 0.;
 72 
 73   std::vector<G4RDVEMDataSet *>::const_iterator i(components.begin());
 74   std::vector<G4RDVEMDataSet *>::const_iterator end(components.end());
 75 
 76   while (i != end)
 77     {
 78       value += (*i)->FindValue(energy);
 79       i++;
 80     }
 81 
 82   return value;
 83 }
 84 
 85 
 86 void G4RDShellEMDataSet::PrintData(void) const
 87 {
 88   const size_t n = NumberOfComponents();
 89 
 90   G4cout << "The data set has " << n << " components" << G4endl;
 91   G4cout << G4endl;
 92  
 93   size_t i = 0;
 94  
 95   while (i < n)
 96     {
 97       G4cout << "--- Component " << i << " ---" << G4endl;
 98       GetComponent(i)->PrintData();
 99       i++;
100     }
101 }
102 
103 
104 void G4RDShellEMDataSet::SetEnergiesData(G4DataVector* energies, 
105                G4DataVector* data, 
106                G4int componentId)
107 {
108   G4RDVEMDataSet* component = components[componentId];
109  
110   if (component)
111     {
112       component->SetEnergiesData(energies, data, 0);
113       return;
114     }
115 
116   std::ostringstream message;
117   message << "Component " << componentId << " not found";
118  
119   G4Exception("G4RDShellEMDataSet::SetEnergiesData()", "DataNotFound",
120               FatalException, message.str().c_str());
121 }
122 
123 
124 G4bool G4RDShellEMDataSet::LoadData(const G4String& file)
125 {
126   CleanUpComponents();
127 
128   G4String fullFileName = FullFileName(file);
129   std::ifstream in(fullFileName);
130 
131   if (!in.is_open())
132     {
133       G4String message("Data file \"");
134       message += fullFileName;
135       message += "\" not found";
136       G4Exception("G4RDShellEMDataSet::LoadData()", "DataNotFound",
137                   FatalException, message);
138     }
139 
140   G4DataVector* energies = 0;
141   G4DataVector* data = 0;
142 
143   G4double a = 0.;
144   G4int shellIndex = 0;
145   bool energyColumn = true;
146 
147   do
148     {
149       in >> a;
150   
151       if (a == -1)
152   {
153     if (energyColumn && energies!=0)
154       {
155         AddComponent(new G4RDEMDataSet(shellIndex, energies, data, algorithm->Clone(), unitEnergies, unitData));
156         energies = 0;
157         data = 0;
158       }
159    
160     energyColumn = (!energyColumn);
161   }
162       else if (a != -2)
163   {
164     if (energies == 0)
165       {
166         energies = new G4DataVector;
167         data = new G4DataVector;
168       }
169   
170     if (energyColumn)
171       energies->push_back(a * unitEnergies);
172     else
173       data->push_back(a * unitData);
174 
175     energyColumn = (!energyColumn);
176   }
177     }
178   while (a != -2);
179 
180   return true;
181 }
182 
183 
184 G4bool G4RDShellEMDataSet::SaveData(const G4String& file) const
185 {
186   G4String fullFileName = FullFileName(file);
187   std::ofstream out(fullFileName);
188 
189   if (!out.is_open())
190     {
191       G4String message("Cannot open \"");
192       message += fullFileName;
193       message += "\"";
194       G4Exception("G4RDEMDataSet::SaveData()", "CannotOpenFile",
195                   FatalException, message);
196     }
197  
198   const size_t n = NumberOfComponents();
199   size_t k = 0;
200  
201   while (k < n)
202     {
203       const G4RDVEMDataSet* component = GetComponent(k);
204   
205       if (component)
206   {
207     const G4DataVector& energies = component->GetEnergies(0);
208     const G4DataVector& data = component->GetData(0);
209  
210     G4DataVector::const_iterator i = energies.begin();
211     G4DataVector::const_iterator endI = energies.end();
212     G4DataVector::const_iterator j = data.begin();
213   
214     while (i != endI)
215       {
216         out.precision(10);
217         out.width(15);
218         out.setf(std::ofstream::left);
219         out << ((*i)/unitEnergies) << ' ';
220 
221         out.precision(10);
222         out.width(15);
223         out.setf(std::ofstream::left);
224         out << ((*j)/unitData) << std::endl;
225         i++;
226         j++;
227       }
228   }
229   
230       out.precision(10);
231       out.width(15);
232       out.setf(std::ofstream::left);
233       out << -1.f << ' ';
234 
235       out.precision(10);
236       out.width(15);
237       out.setf(std::ofstream::left);
238       out << -1.f << std::endl;
239   
240       k++;
241     }
242  
243   out.precision(10);
244   out.width(15);
245   out.setf(std::ofstream::left);
246   out << -2.f << ' ';
247 
248   out.precision(10);
249   out.width(15);
250   out.setf(std::ofstream::left);
251   out << -2.f << std::endl;
252 
253   return true;
254 }
255 
256 
257 void G4RDShellEMDataSet::CleanUpComponents(void)
258 {
259   while (!components.empty())
260     {
261       if (components.back()) delete components.back();
262       components.pop_back();
263     }
264 }
265 
266 
267 G4String G4RDShellEMDataSet::FullFileName(const G4String& fileName) const
268 {
269   const char* path = G4FindDataDir("G4LEDATA");
270   if (!path)
271     G4Exception("G4RDShellEMDataSet::FullFileName()", "InvalidSetup",
272                 FatalException, "G4LEDATA environment variable not set!");
273   
274   std::ostringstream fullFileName;
275  
276   fullFileName << path << '/' << fileName << z << ".dat";
277                       
278   return G4String(fullFileName.str().c_str());
279 }
280