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3 ] [ 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 /processes/electromagnetic/lowenergy/src/G4CompositeEMDataSet.cc (Version 11.3.0) and /processes/electromagnetic/lowenergy/src/G4CompositeEMDataSet.cc (Version 5.2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 //                                                 23 //
                                                   >>  24 // $Id: G4CompositeEMDataSet.cc,v 1.7 2003/06/16 17:00:05 gunter Exp $
                                                   >>  25 // GEANT4 tag $Name: geant4-05-02 $
 27 //                                                 26 //
 28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@     27 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
 29 //                                                 28 //
 30 // History:                                        29 // History:
 31 // -----------                                     30 // -----------
 32 // 1 Aug 2001   MGP        Created                 31 // 1 Aug 2001   MGP        Created
 33 //                                                 32 //
 34 // 15 Jul 2009   Nicolas A. Karakatsanis       << 
 35 //                                             << 
 36 //                           - LoadNonLogData  << 
 37 //                             dataset. It is  << 
 38 //                                             << 
 39 //                           - LoadData method << 
 40 //                             It retrieves th << 
 41 //                             respective log  << 
 42 //                                             << 
 43 //                           - SetLogEnergiesD << 
 44 //                             The EM data set << 
 45 //                             These initializ << 
 46 //                             operations      << 
 47 //                                             << 
 48 // -------------------------------------------     33 // -------------------------------------------------------------------
 49                                                    34 
 50 #include "G4CompositeEMDataSet.hh"                 35 #include "G4CompositeEMDataSet.hh"
 51 #include "G4EMDataSet.hh"                          36 #include "G4EMDataSet.hh"
 52 #include "G4VDataSetAlgorithm.hh"                  37 #include "G4VDataSetAlgorithm.hh"
 53 #include <fstream>                                 38 #include <fstream>
 54 #include <sstream>                             <<  39 #include <strstream>
 55                                                << 
 56 //....oooOO0OOooo........oooOO0OOooo........oo << 
 57                                                << 
 58 G4CompositeEMDataSet::G4CompositeEMDataSet(G4V << 
 59              G4double argUnitEnergies,         << 
 60              G4double argUnitData,             << 
 61              G4int argMinZ,                    << 
 62              G4int argMaxZ)                    << 
 63   :                                            << 
 64   algorithm(argAlgorithm),                     << 
 65   unitEnergies(argUnitEnergies),               << 
 66   unitData(argUnitData),                       << 
 67   minZ(argMinZ),                               << 
 68   maxZ(argMaxZ)                                << 
 69 {                                              << 
 70   if (algorithm == nullptr)                    << 
 71   G4Exception("G4CompositeEMDataSet::G4Composi << 
 72         "em1003",FatalException,"interpolation << 
 73                                                << 
 74 }                                              << 
 75                                                    40 
 76 //....oooOO0OOooo........oooOO0OOooo........oo << 
 77                                                    41 
 78 G4CompositeEMDataSet::~G4CompositeEMDataSet()  <<  42 G4CompositeEMDataSet::G4CompositeEMDataSet(G4VDataSetAlgorithm* interpolation,
                                                   >>  43              G4double unitE, G4double unitData,
                                                   >>  44              G4int minZ, G4int maxZ)
                                                   >>  45   :algorithm(interpolation), unit1(unitE), unit2(unitData), zMin(minZ), zMax(maxZ)
 79 {                                                  46 {
 80   CleanUpComponents();                         <<  47   nComponents = 0;
 81   if (algorithm) delete algorithm;             << 
 82 }                                                  48 }
 83 //....oooOO0OOooo........oooOO0OOooo........oo << 
 84                                                    49 
 85 G4double G4CompositeEMDataSet::FindValue(G4dou <<  50 G4CompositeEMDataSet::G4CompositeEMDataSet(const G4String& dataFile,
                                                   >>  51              G4VDataSetAlgorithm* interpolation,
                                                   >>  52              G4double unitE, G4double unitData,
                                                   >>  53              G4int minZ, G4int maxZ)
                                                   >>  54   : algorithm(interpolation), unit1(unitE), unit2(unitData), zMin(minZ), zMax(maxZ)
 86 {                                                  55 {
 87   const G4VEMDataSet* component(GetComponent(a <<  56   nComponents = 0;
 88                                                <<  57   LoadData(dataFile);
 89   if (component) return component->FindValue(a << 
 90                                                << 
 91   std::ostringstream message;                  << 
 92   message << "G4CompositeEMDataSet::FindValue  << 
 93                                                << 
 94   G4Exception("G4CompositeEMDataSet::FindValue << 
 95         "em1004",FatalException,message.str(). << 
 96                                                << 
 97   return 0.;                                   << 
 98 }                                                  58 }
 99                                                    59 
100 //....oooOO0OOooo........oooOO0OOooo........oo <<  60 G4CompositeEMDataSet::~G4CompositeEMDataSet()
101                                                <<  61 { 
102 void G4CompositeEMDataSet::PrintData(void) con <<  62   for (size_t i=0; i<nComponents; i++)
103 {                                              << 
104   const G4int n = (G4int)NumberOfComponents(); << 
105                                                << 
106   G4cout << "The data set has " << n << " comp << 
107   G4cout << G4endl;                            << 
108                                                << 
109   G4int i(0);                                  << 
110                                                << 
111   while (i<n)                                  << 
112     {                                              63     {
113       G4cout << "--- Component " << i << " --- <<  64       G4VEMDataSet* dataSet = components[i];
114       GetComponent(i)->PrintData();            <<  65       delete dataSet;
115       ++i;                                     << 
116     }                                              66     }
                                                   >>  67   delete algorithm;
117 }                                                  68 }
118                                                    69 
119 //....oooOO0OOooo........oooOO0OOooo........oo <<  70 G4double G4CompositeEMDataSet::FindValue(G4double e, G4int id) const
120                                                << 
121 void G4CompositeEMDataSet::SetEnergiesData(G4D << 
122 {                                                  71 {
123   G4VEMDataSet * component(components[argCompo <<  72   // Returns the value in component id corresponding to e
124                                                <<  73   G4double value = 0.;
125   if (component)                               <<  74 
                                                   >>  75   G4VEMDataSet* component = components[id];
                                                   >>  76   if (component != 0)
126     {                                              77     {
127       component->SetEnergiesData(argEnergies,  <<  78       value = component->FindValue(e);
128       return;                                  << 
129     }                                              79     }
130                                                <<  80   else
131   std::ostringstream message;                  << 
132   message << "G4CompositeEMDataSet::SetEnergie << 
133                                                << 
134   G4Exception("G4CompositeEMDataSet::SetEnergi << 
135         "em1004",FatalException,message.str(). << 
136 }                                              << 
137                                                << 
138 //....oooOO0OOooo........oooOO0OOooo........oo << 
139                                                << 
140 void G4CompositeEMDataSet::SetLogEnergiesData( << 
141                                                << 
142                                                << 
143                                                << 
144                                                << 
145 {                                              << 
146   G4VEMDataSet * component(components[argCompo << 
147                                                << 
148   if (component)                               << 
149     {                                              81     {
150       component->SetLogEnergiesData(argEnergie <<  82       G4cout << "WARNING - G4CompositeEMDataSet::FindValue - component "
151       return;                                  <<  83        << id << " not found" << G4endl; 
152     }                                              84     }
153                                                    85 
154   std::ostringstream message;                  <<  86   return value;
155   message << "G4CompositeEMDataSet::SetEnergie << 
156                                                << 
157   G4Exception("G4CompositeEMDataSet::SetLogEne << 
158         "em1004",FatalException,message.str(). << 
159 }                                                  87 }
160                                                    88 
161 //....oooOO0OOooo........oooOO0OOooo........oo <<  89 void G4CompositeEMDataSet::PrintData() const
162                                                << 
163 G4bool G4CompositeEMDataSet::LoadData(const G4 << 
164 {                                                  90 {
165   CleanUpComponents();                         <<  91   G4cout << "The data set has " << nComponents << " components" << G4endl;
166                                                    92 
167   for (G4int z(minZ); z<maxZ; ++z)             <<  93   for (size_t i=0; i<nComponents; i++)
168     {                                          <<  94   {
169       G4VEMDataSet* component = new G4EMDataSe <<  95     G4cout << "--- Component " << i << " ---" << G4endl;
170       if (!component->LoadData(argFileName))   <<  96     G4VEMDataSet* component = components[i];
171   {                                            <<  97     component->PrintData();
172     delete component;                          <<  98   }
173     return false;                              <<  99 }
                                                   >> 100 
                                                   >> 101 void G4CompositeEMDataSet::LoadData(const G4String& fileName)
                                                   >> 102 { 
                                                   >> 103 
                                                   >> 104   for (G4int Z=zMin; Z<zMax; Z++)
                                                   >> 105     {
                                                   >> 106       // Build the complete string identifying the file with the data set
                                                   >> 107       
                                                   >> 108       char nameChar[100] = {""};
                                                   >> 109       std::ostrstream ost(nameChar, 100, std::ios::out);
                                                   >> 110       
                                                   >> 111       ost << fileName << Z << ".dat";
                                                   >> 112       
                                                   >> 113       G4String name(nameChar);
                                                   >> 114       
                                                   >> 115       char* path = getenv("G4LEDATA");
                                                   >> 116       if (!path)
                                                   >> 117   { 
                                                   >> 118     G4String excep("G4CompositeEMDataSet - G4LEDATA environment variable not set");
                                                   >> 119     G4Exception(excep);
174   }                                               120   }
175       AddComponent(component);                 << 121       
176     }                                          << 122       G4String pathString(path);
177   return true;                                 << 123       G4String separator = G4String("/");
178 }                                              << 124       G4String dirFile = pathString + separator + name;
179                                                << 125       std::ifstream file(dirFile);
180 //....oooOO0OOooo........oooOO0OOooo........oo << 126       std::filebuf* lsdp = file.rdbuf();
181                                                << 127       
182 G4bool G4CompositeEMDataSet::LoadNonLogData(co << 128       if (! (lsdp->is_open()) )
183 {                                              << 
184   CleanUpComponents();                         << 
185                                                << 
186   for (G4int z(minZ); z<maxZ; ++z)             << 
187     {                                          << 
188       G4VEMDataSet* component = new G4EMDataSe << 
189       if (!component->LoadNonLogData(argFileNa << 
190   {                                               129   {
191     delete component;                          << 130     G4String s1("G4CompositeEMDataSet - data file: ");
192     return false;                              << 131           G4String s2(" not found");
                                                   >> 132     G4String excep = s1 + dirFile + s2;
                                                   >> 133     G4Exception(excep);
193   }                                               134   }
194       AddComponent(component);                 << 135       G4double a = 0;
195     }                                          << 136       G4int k = 1;
196   return true;                                 << 137       G4DataVector* energies = new G4DataVector;
197 }                                              << 138       G4DataVector* data = new G4DataVector;
198                                                << 139       do
199 //....oooOO0OOooo........oooOO0OOooo........oo << 
200                                                << 
201 G4bool G4CompositeEMDataSet::SaveData(const G4 << 
202 {                                              << 
203   for (G4int z=minZ; z<maxZ; ++z)              << 
204     {                                          << 
205       const G4VEMDataSet* component(GetCompone << 
206                                                << 
207       if (!component)                          << 
208   {                                               140   {
209     std::ostringstream message;                << 141     file >> a;
210     message << "G4CompositeEMDataSet::SaveData << 142     G4int nColumns = 2;
211           G4Exception("G4CompositeEMDataSet::S << 143     // The file is organized into two columns:
212         "em1004",FatalException,message.str(). << 144     // 1st column is the energy
213     return false;                              << 145     // 2nd column is the corresponding value
214   }                                            << 146     // The file terminates with the pattern: -1   -1
215                                                << 147     //                                       -2   -2
216       if (!component->SaveData(argFileName))   << 148     if (a == -1 || a == -2)
217   return false;                                << 149       {
                                                   >> 150       }
                                                   >> 151     else
                                                   >> 152       {
                                                   >> 153         if (k%nColumns != 0)
                                                   >> 154     { 
                                                   >> 155       G4double e = a * unit1;
                                                   >> 156       energies->push_back(e);
                                                   >> 157       k++;
                                                   >> 158     }
                                                   >> 159         else if (k%nColumns == 0)
                                                   >> 160     {
                                                   >> 161       G4double value = a * unit2;
                                                   >> 162       data->push_back(value);
                                                   >> 163       k = 1;
                                                   >> 164     }
                                                   >> 165       }
                                                   >> 166   } while (a != -2); // end of file
                                                   >> 167       
                                                   >> 168       file.close();
                                                   >> 169 
                                                   >> 170       G4VDataSetAlgorithm* algo = algorithm->Clone();
                                                   >> 171       G4VEMDataSet* dataSet = new G4EMDataSet(Z,energies,data,algo);
                                                   >> 172       AddComponent(dataSet);
218     }                                             173     }
219                                                << 
220   return true;                                 << 
221 }                                                 174 }
222                                                   175 
223 //....oooOO0OOooo........oooOO0OOooo........oo << 176 void G4CompositeEMDataSet::AddComponent(G4VEMDataSet* component)
224                                                << 177 { 
225 void G4CompositeEMDataSet::CleanUpComponents(v << 178   components.push_back(component);
                                                   >> 179   nComponents++;
                                                   >> 180 }
                                                   >> 181 
                                                   >> 182 const G4DataVector& G4CompositeEMDataSet::GetEnergies(G4int i) const
226 {                                                 183 {
227   while (!components.empty())                  << 184   const G4VEMDataSet* component = GetComponent(i);
228     {                                          << 185   return (component->GetEnergies(i));
229       if (components.back())                   << 
230   delete components.back();                    << 
231       components.pop_back();                   << 
232     }                                          << 
233 }                                                 186 }
234                                                   187 
235 //....oooOO0OOooo........oooOO0OOooo........oo << 188 const G4DataVector& G4CompositeEMDataSet::GetData(G4int i) const 
236                                                << 
237 G4double G4CompositeEMDataSet::RandomSelect(G4 << 
238 {                                                 189 {
239   G4double value = 0.;                         << 190   const G4VEMDataSet* component = GetComponent(i);
240   if (componentId >= 0 && componentId < (G4int << 191   return (component->GetData(i));
241     {                                          << 
242       const G4VEMDataSet* dataSet = GetCompone << 
243       value = dataSet->RandomSelect();         << 
244     }                                          << 
245   return value;                                << 
246 }                                                 192 }
247                                                   193