Geant4 Cross Reference |
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.5 2001/10/25 02:32:16 pia Exp $ >> 25 // GEANT4 tag $Name: geant4-04-00 $ 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 "g4std/fstream" 54 #include <sstream> << 39 #include "g4std/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 40 74 } << 75 << 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 delete components[i]; 114 GetComponent(i)->PrintData(); << 115 ++i; << 116 } 65 } >> 66 delete algorithm; 117 } 67 } 118 68 119 //....oooOO0OOooo........oooOO0OOooo........oo << 69 G4double G4CompositeEMDataSet::FindValue(G4double e, G4int id) const 120 << 121 void G4CompositeEMDataSet::SetEnergiesData(G4D << 122 { 70 { 123 G4VEMDataSet * component(components[argCompo << 71 // Returns the value in component id corresponding to e 124 << 72 G4double value = 0.; 125 if (component) << 73 >> 74 G4VEMDataSet* component = components[id]; >> 75 if (component != 0) 126 { 76 { 127 component->SetEnergiesData(argEnergies, << 77 value = component->FindValue(e); 128 return; << 129 } 78 } 130 << 79 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 { 80 { 150 component->SetLogEnergiesData(argEnergie << 81 G4cout << "WARNING - G4CompositeEMDataSet::FindValue - component " 151 return; << 82 << id << " not found" << G4endl; 152 } 83 } 153 84 154 std::ostringstream message; << 85 return value; 155 message << "G4CompositeEMDataSet::SetEnergie << 156 << 157 G4Exception("G4CompositeEMDataSet::SetLogEne << 158 "em1004",FatalException,message.str(). << 159 } 86 } 160 87 161 //....oooOO0OOooo........oooOO0OOooo........oo << 88 void G4CompositeEMDataSet::PrintData() const 162 << 163 G4bool G4CompositeEMDataSet::LoadData(const G4 << 164 { 89 { 165 CleanUpComponents(); << 90 G4cout << "The data set has " << nComponents << " components" << G4endl; 166 91 167 for (G4int z(minZ); z<maxZ; ++z) << 92 for (size_t i=0; i<nComponents; i++) 168 { << 93 { 169 G4VEMDataSet* component = new G4EMDataSe << 94 G4cout << "--- Component " << i << " ---" << G4endl; 170 if (!component->LoadData(argFileName)) << 95 G4VEMDataSet* component = components[i]; 171 { << 96 component->PrintData(); 172 delete component; << 97 } 173 return false; << 98 } >> 99 >> 100 void G4CompositeEMDataSet::LoadData(const G4String& fileName) >> 101 { >> 102 >> 103 for (G4int Z=zMin; Z<zMax; Z++) >> 104 { >> 105 // Build the complete string identifying the file with the data set >> 106 >> 107 char nameChar[100] = {""}; >> 108 G4std::ostrstream ost(nameChar, 100, G4std::ios::out); >> 109 >> 110 ost << fileName << Z << ".dat"; >> 111 >> 112 G4String name(nameChar); >> 113 >> 114 char* path = getenv("G4LEDATA"); >> 115 if (!path) >> 116 { >> 117 G4String excep = "G4CompositeEMDataSet - G4LEDATA environment variable not set"; >> 118 G4Exception(excep); 174 } 119 } 175 AddComponent(component); << 120 176 } << 121 G4String pathString(path); 177 return true; << 122 G4String dirFile = pathString + "/" + name; 178 } << 123 G4std::ifstream file(dirFile); 179 << 124 G4std::filebuf* lsdp = file.rdbuf(); 180 //....oooOO0OOooo........oooOO0OOooo........oo << 125 181 << 126 if (! (lsdp->is_open()) ) 182 G4bool G4CompositeEMDataSet::LoadNonLogData(co << 183 { << 184 CleanUpComponents(); << 185 << 186 for (G4int z(minZ); z<maxZ; ++z) << 187 { << 188 G4VEMDataSet* component = new G4EMDataSe << 189 if (!component->LoadNonLogData(argFileNa << 190 { 127 { 191 delete component; << 128 G4String excep = "G4CompositeEMDataSet - data file: " + dirFile + " not found"; 192 return false; << 129 G4Exception(excep); 193 } 130 } 194 AddComponent(component); << 131 G4double a = 0; 195 } << 132 G4int k = 1; 196 return true; << 133 G4DataVector* energies = new G4DataVector; 197 } << 134 G4DataVector* data = new G4DataVector; 198 << 135 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 { 136 { 209 std::ostringstream message; << 137 file >> a; 210 message << "G4CompositeEMDataSet::SaveData << 138 G4int nColumns = 2; 211 G4Exception("G4CompositeEMDataSet::S << 139 // The file is organized into two columns: 212 "em1004",FatalException,message.str(). << 140 // 1st column is the energy 213 return false; << 141 // 2nd column is the corresponding value 214 } << 142 // The file terminates with the pattern: -1 -1 215 << 143 // -2 -2 216 if (!component->SaveData(argFileName)) << 144 if (a == -1 || a == -2) 217 return false; << 145 { >> 146 } >> 147 else >> 148 { >> 149 if (k%nColumns != 0) >> 150 { >> 151 G4double e = a * unit1; >> 152 energies->push_back(e); >> 153 k++; >> 154 } >> 155 else if (k%nColumns == 0) >> 156 { >> 157 G4double value = a * unit2; >> 158 data->push_back(value); >> 159 k = 1; >> 160 } >> 161 } >> 162 } while (a != -2); // end of file >> 163 >> 164 file.close(); >> 165 >> 166 G4VDataSetAlgorithm* algo = algorithm->Clone(); >> 167 G4VEMDataSet* dataSet = new G4EMDataSet(Z,energies,data,algo); >> 168 AddComponent(dataSet); 218 } 169 } 219 << 220 return true; << 221 } 170 } 222 171 223 //....oooOO0OOooo........oooOO0OOooo........oo << 172 void G4CompositeEMDataSet::AddComponent(G4VEMDataSet* component) 224 << 173 { 225 void G4CompositeEMDataSet::CleanUpComponents(v << 174 components.push_back(component); >> 175 nComponents++; >> 176 } >> 177 >> 178 const G4DataVector& G4CompositeEMDataSet::GetEnergies(G4int i) const 226 { 179 { 227 while (!components.empty()) << 180 const G4VEMDataSet* component = GetComponent(i); 228 { << 181 return (component->GetEnergies(i)); 229 if (components.back()) << 230 delete components.back(); << 231 components.pop_back(); << 232 } << 233 } 182 } 234 183 235 //....oooOO0OOooo........oooOO0OOooo........oo << 184 const G4DataVector& G4CompositeEMDataSet::GetData(G4int i) const 236 << 237 G4double G4CompositeEMDataSet::RandomSelect(G4 << 238 { 185 { 239 G4double value = 0.; << 186 const G4VEMDataSet* component = GetComponent(i); 240 if (componentId >= 0 && componentId < (G4int << 187 return (component->GetData(i)); 241 { << 242 const G4VEMDataSet* dataSet = GetCompone << 243 value = dataSet->RandomSelect(); << 244 } << 245 return value; << 246 } 188 } 247 189