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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 ]

Diff markup

Differences between /examples/advanced/eRosita/physics/src/G4RDShellEMDataSet.cc (Version 11.3.0) and /examples/advanced/eRosita/physics/src/G4RDShellEMDataSet.cc (Version 11.1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 //                                                 27 //
 28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@     28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
 29 //                                                 29 //
 30 // History:                                        30 // History:
 31 // -----------                                     31 // -----------
 32 //  1 Aug 2001   MGP        Created                32 //  1 Aug 2001   MGP        Created
 33 // 09.10.01   V.Ivanchenko Add case z=0            33 // 09.10.01   V.Ivanchenko Add case z=0
 34 //  9 Mar 2008   MGP        Cleaned up unreada     34 //  9 Mar 2008   MGP        Cleaned up unreadable code modified by former developer
 35 //                          (Further clean-up      35 //                          (Further clean-up needed) 
 36 //                                                 36 //
 37 // -------------------------------------------     37 // -------------------------------------------------------------------
 38                                                    38 
 39 #include "G4RDShellEMDataSet.hh"                   39 #include "G4RDShellEMDataSet.hh"
 40 #include "G4RDEMDataSet.hh"                        40 #include "G4RDEMDataSet.hh"
 41 #include "G4RDVDataSetAlgorithm.hh"                41 #include "G4RDVDataSetAlgorithm.hh"
 42 #include <fstream>                                 42 #include <fstream>
 43 #include <sstream>                                 43 #include <sstream>
 44                                                    44 
 45                                                    45 
 46 G4RDShellEMDataSet::G4RDShellEMDataSet(G4int z     46 G4RDShellEMDataSet::G4RDShellEMDataSet(G4int zeta, G4RDVDataSetAlgorithm* algo, 
 47            G4double eUnit,                         47            G4double eUnit, 
 48            G4double dataUnit)                      48            G4double dataUnit)
 49   :                                                49   :
 50   z(zeta),                                         50   z(zeta),
 51   algorithm(algo),                                 51   algorithm(algo),
 52   unitEnergies(eUnit),                             52   unitEnergies(eUnit),
 53   unitData(dataUnit)                               53   unitData(dataUnit)
 54 {                                                  54 {
 55   if (algorithm == 0)                              55   if (algorithm == 0)
 56     G4Exception("G4RDShellEMDataSet::G4RDShell     56     G4Exception("G4RDShellEMDataSet::G4RDShellEMDataSet()", "InvalidSetup",
 57                 FatalException, "Interpolation     57                 FatalException, "Interpolation == 0!");
 58 }                                                  58 }
 59                                                    59 
 60                                                    60 
 61 G4RDShellEMDataSet::~G4RDShellEMDataSet()          61 G4RDShellEMDataSet::~G4RDShellEMDataSet()
 62 {                                                  62 {
 63   CleanUpComponents();                             63   CleanUpComponents();
 64   if (algorithm) delete algorithm;                 64   if (algorithm) delete algorithm;
 65 }                                                  65 }
 66                                                    66 
 67                                                    67 
 68 G4double G4RDShellEMDataSet::FindValue(G4doubl     68 G4double G4RDShellEMDataSet::FindValue(G4double energy, G4int /* componentId */) const
 69 {                                                  69 {
 70   // Returns the sum over the shells correspon     70   // Returns the sum over the shells corresponding to e
 71   G4double value = 0.;                             71   G4double value = 0.;
 72                                                    72 
 73   std::vector<G4RDVEMDataSet *>::const_iterato     73   std::vector<G4RDVEMDataSet *>::const_iterator i(components.begin());
 74   std::vector<G4RDVEMDataSet *>::const_iterato     74   std::vector<G4RDVEMDataSet *>::const_iterator end(components.end());
 75                                                    75 
 76   while (i != end)                                 76   while (i != end)
 77     {                                              77     {
 78       value += (*i)->FindValue(energy);            78       value += (*i)->FindValue(energy);
 79       i++;                                         79       i++;
 80     }                                              80     }
 81                                                    81 
 82   return value;                                    82   return value;
 83 }                                                  83 }
 84                                                    84 
 85                                                    85 
 86 void G4RDShellEMDataSet::PrintData(void) const     86 void G4RDShellEMDataSet::PrintData(void) const
 87 {                                                  87 {
 88   const size_t n = NumberOfComponents();           88   const size_t n = NumberOfComponents();
 89                                                    89 
 90   G4cout << "The data set has " << n << " comp     90   G4cout << "The data set has " << n << " components" << G4endl;
 91   G4cout << G4endl;                                91   G4cout << G4endl;
 92                                                    92  
 93   size_t i = 0;                                    93   size_t i = 0;
 94                                                    94  
 95   while (i < n)                                    95   while (i < n)
 96     {                                              96     {
 97       G4cout << "--- Component " << i << " ---     97       G4cout << "--- Component " << i << " ---" << G4endl;
 98       GetComponent(i)->PrintData();                98       GetComponent(i)->PrintData();
 99       i++;                                         99       i++;
100     }                                             100     }
101 }                                                 101 }
102                                                   102 
103                                                   103 
104 void G4RDShellEMDataSet::SetEnergiesData(G4Dat    104 void G4RDShellEMDataSet::SetEnergiesData(G4DataVector* energies, 
105                G4DataVector* data,                105                G4DataVector* data, 
106                G4int componentId)                 106                G4int componentId)
107 {                                                 107 {
108   G4RDVEMDataSet* component = components[compo    108   G4RDVEMDataSet* component = components[componentId];
109                                                   109  
110   if (component)                                  110   if (component)
111     {                                             111     {
112       component->SetEnergiesData(energies, dat    112       component->SetEnergiesData(energies, data, 0);
113       return;                                     113       return;
114     }                                             114     }
115                                                   115 
116   std::ostringstream message;                     116   std::ostringstream message;
117   message << "Component " << componentId << "     117   message << "Component " << componentId << " not found";
118                                                   118  
119   G4Exception("G4RDShellEMDataSet::SetEnergies    119   G4Exception("G4RDShellEMDataSet::SetEnergiesData()", "DataNotFound",
120               FatalException, message.str().c_    120               FatalException, message.str().c_str());
121 }                                                 121 }
122                                                   122 
123                                                   123 
124 G4bool G4RDShellEMDataSet::LoadData(const G4St    124 G4bool G4RDShellEMDataSet::LoadData(const G4String& file)
125 {                                                 125 {
126   CleanUpComponents();                            126   CleanUpComponents();
127                                                   127 
128   G4String fullFileName = FullFileName(file);     128   G4String fullFileName = FullFileName(file);
129   std::ifstream in(fullFileName);                 129   std::ifstream in(fullFileName);
130                                                   130 
131   if (!in.is_open())                              131   if (!in.is_open())
132     {                                             132     {
133       G4String message("Data file \"");           133       G4String message("Data file \"");
134       message += fullFileName;                    134       message += fullFileName;
135       message += "\" not found";                  135       message += "\" not found";
136       G4Exception("G4RDShellEMDataSet::LoadDat    136       G4Exception("G4RDShellEMDataSet::LoadData()", "DataNotFound",
137                   FatalException, message);       137                   FatalException, message);
138     }                                             138     }
139                                                   139 
140   G4DataVector* energies = 0;                     140   G4DataVector* energies = 0;
141   G4DataVector* data = 0;                         141   G4DataVector* data = 0;
142                                                   142 
143   G4double a = 0.;                                143   G4double a = 0.;
144   G4int shellIndex = 0;                           144   G4int shellIndex = 0;
145   bool energyColumn = true;                       145   bool energyColumn = true;
146                                                   146 
147   do                                              147   do
148     {                                             148     {
149       in >> a;                                    149       in >> a;
150                                                   150   
151       if (a == -1)                                151       if (a == -1)
152   {                                               152   {
153     if (energyColumn && energies!=0)              153     if (energyColumn && energies!=0)
154       {                                           154       {
155         AddComponent(new G4RDEMDataSet(shellIn    155         AddComponent(new G4RDEMDataSet(shellIndex, energies, data, algorithm->Clone(), unitEnergies, unitData));
156         energies = 0;                             156         energies = 0;
157         data = 0;                                 157         data = 0;
158       }                                           158       }
159                                                   159    
160     energyColumn = (!energyColumn);               160     energyColumn = (!energyColumn);
161   }                                               161   }
162       else if (a != -2)                           162       else if (a != -2)
163   {                                               163   {
164     if (energies == 0)                            164     if (energies == 0)
165       {                                           165       {
166         energies = new G4DataVector;              166         energies = new G4DataVector;
167         data = new G4DataVector;                  167         data = new G4DataVector;
168       }                                           168       }
169                                                   169   
170     if (energyColumn)                             170     if (energyColumn)
171       energies->push_back(a * unitEnergies);      171       energies->push_back(a * unitEnergies);
172     else                                          172     else
173       data->push_back(a * unitData);              173       data->push_back(a * unitData);
174                                                   174 
175     energyColumn = (!energyColumn);               175     energyColumn = (!energyColumn);
176   }                                               176   }
177     }                                             177     }
178   while (a != -2);                                178   while (a != -2);
179                                                   179 
180   return true;                                    180   return true;
181 }                                                 181 }
182                                                   182 
183                                                   183 
184 G4bool G4RDShellEMDataSet::SaveData(const G4St    184 G4bool G4RDShellEMDataSet::SaveData(const G4String& file) const
185 {                                                 185 {
186   G4String fullFileName = FullFileName(file);     186   G4String fullFileName = FullFileName(file);
187   std::ofstream out(fullFileName);                187   std::ofstream out(fullFileName);
188                                                   188 
189   if (!out.is_open())                             189   if (!out.is_open())
190     {                                             190     {
191       G4String message("Cannot open \"");         191       G4String message("Cannot open \"");
192       message += fullFileName;                    192       message += fullFileName;
193       message += "\"";                            193       message += "\"";
194       G4Exception("G4RDEMDataSet::SaveData()",    194       G4Exception("G4RDEMDataSet::SaveData()", "CannotOpenFile",
195                   FatalException, message);       195                   FatalException, message);
196     }                                             196     }
197                                                   197  
198   const size_t n = NumberOfComponents();          198   const size_t n = NumberOfComponents();
199   size_t k = 0;                                   199   size_t k = 0;
200                                                   200  
201   while (k < n)                                   201   while (k < n)
202     {                                             202     {
203       const G4RDVEMDataSet* component = GetCom    203       const G4RDVEMDataSet* component = GetComponent(k);
204                                                   204   
205       if (component)                              205       if (component)
206   {                                               206   {
207     const G4DataVector& energies = component->    207     const G4DataVector& energies = component->GetEnergies(0);
208     const G4DataVector& data = component->GetD    208     const G4DataVector& data = component->GetData(0);
209                                                   209  
210     G4DataVector::const_iterator i = energies.    210     G4DataVector::const_iterator i = energies.begin();
211     G4DataVector::const_iterator endI = energi    211     G4DataVector::const_iterator endI = energies.end();
212     G4DataVector::const_iterator j = data.begi    212     G4DataVector::const_iterator j = data.begin();
213                                                   213   
214     while (i != endI)                             214     while (i != endI)
215       {                                           215       {
216         out.precision(10);                        216         out.precision(10);
217         out.width(15);                            217         out.width(15);
218         out.setf(std::ofstream::left);            218         out.setf(std::ofstream::left);
219         out << ((*i)/unitEnergies) << ' ';        219         out << ((*i)/unitEnergies) << ' ';
220                                                   220 
221         out.precision(10);                        221         out.precision(10);
222         out.width(15);                            222         out.width(15);
223         out.setf(std::ofstream::left);            223         out.setf(std::ofstream::left);
224         out << ((*j)/unitData) << std::endl;      224         out << ((*j)/unitData) << std::endl;
225         i++;                                      225         i++;
226         j++;                                      226         j++;
227       }                                           227       }
228   }                                               228   }
229                                                   229   
230       out.precision(10);                          230       out.precision(10);
231       out.width(15);                              231       out.width(15);
232       out.setf(std::ofstream::left);              232       out.setf(std::ofstream::left);
233       out << -1.f << ' ';                         233       out << -1.f << ' ';
234                                                   234 
235       out.precision(10);                          235       out.precision(10);
236       out.width(15);                              236       out.width(15);
237       out.setf(std::ofstream::left);              237       out.setf(std::ofstream::left);
238       out << -1.f << std::endl;                   238       out << -1.f << std::endl;
239                                                   239   
240       k++;                                        240       k++;
241     }                                             241     }
242                                                   242  
243   out.precision(10);                              243   out.precision(10);
244   out.width(15);                                  244   out.width(15);
245   out.setf(std::ofstream::left);                  245   out.setf(std::ofstream::left);
246   out << -2.f << ' ';                             246   out << -2.f << ' ';
247                                                   247 
248   out.precision(10);                              248   out.precision(10);
249   out.width(15);                                  249   out.width(15);
250   out.setf(std::ofstream::left);                  250   out.setf(std::ofstream::left);
251   out << -2.f << std::endl;                       251   out << -2.f << std::endl;
252                                                   252 
253   return true;                                    253   return true;
254 }                                                 254 }
255                                                   255 
256                                                   256 
257 void G4RDShellEMDataSet::CleanUpComponents(voi    257 void G4RDShellEMDataSet::CleanUpComponents(void)
258 {                                                 258 {
259   while (!components.empty())                     259   while (!components.empty())
260     {                                             260     {
261       if (components.back()) delete components    261       if (components.back()) delete components.back();
262       components.pop_back();                      262       components.pop_back();
263     }                                             263     }
264 }                                                 264 }
265                                                   265 
266                                                   266 
267 G4String G4RDShellEMDataSet::FullFileName(cons    267 G4String G4RDShellEMDataSet::FullFileName(const G4String& fileName) const
268 {                                                 268 {
269   const char* path = G4FindDataDir("G4LEDATA")    269   const char* path = G4FindDataDir("G4LEDATA");
270   if (!path)                                      270   if (!path)
271     G4Exception("G4RDShellEMDataSet::FullFileN    271     G4Exception("G4RDShellEMDataSet::FullFileName()", "InvalidSetup",
272                 FatalException, "G4LEDATA envi    272                 FatalException, "G4LEDATA environment variable not set!");
273                                                   273   
274   std::ostringstream fullFileName;                274   std::ostringstream fullFileName;
275                                                   275  
276   fullFileName << path << '/' << fileName << z    276   fullFileName << path << '/' << fileName << z << ".dat";
277                                                   277                       
278   return G4String(fullFileName.str().c_str());    278   return G4String(fullFileName.str().c_str());
279 }                                                 279 }
280                                                   280