Geant4 Cross Reference |
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 // $Id: G4CompositeDataSet.cc,v 1.2 2010/11/19 17:16:20 pia Exp $ >> 28 // GEANT4 tag $Name: geant4-09-04 $ 27 // 29 // 28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@ 30 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch) 29 // 31 // 30 // History: 32 // History: 31 // ----------- 33 // ----------- 32 // 1 Aug 2001 MGP Created 34 // 1 Aug 2001 MGP Created 33 // 31 Jul 2008 MGP Revised and rename 35 // 31 Jul 2008 MGP Revised and renamed to G4CompositeDataSet 34 // 36 // 35 // 37 // 36 // ------------------------------------------- 38 // ------------------------------------------------------------------- 37 39 38 #include "G4CompositeDataSet.hh" 40 #include "G4CompositeDataSet.hh" 39 #include "G4DataSet.hh" 41 #include "G4DataSet.hh" 40 #include "G4IInterpolator.hh" 42 #include "G4IInterpolator.hh" 41 #include <fstream> 43 #include <fstream> 42 #include <sstream> 44 #include <sstream> 43 45 44 G4CompositeDataSet::G4CompositeDataSet(G4IInte 46 G4CompositeDataSet::G4CompositeDataSet(G4IInterpolator* algo, 45 G4double eUnit, 47 G4double eUnit, 46 G4double dataUnit, 48 G4double dataUnit, 47 G4int zMin, 49 G4int zMin, 48 G4int zMax) 50 G4int zMax) 49 : 51 : 50 algorithm(algo), 52 algorithm(algo), 51 unitEnergies(eUnit), 53 unitEnergies(eUnit), 52 unitData(dataUnit), 54 unitData(dataUnit), 53 minZ(zMin), 55 minZ(zMin), 54 maxZ(zMax) 56 maxZ(zMax) 55 { 57 { 56 if (algorithm == 0) 58 if (algorithm == 0) 57 G4Exception("G4CompositeDataSet::G4Composi << 59 G4Exception("G4CompositeDataSet::G4CompositeDataSet - interpolation == 0"); 58 "pii00000001", << 59 FatalException, << 60 "Interpolation == 0"); << 61 } 60 } 62 61 63 62 64 63 65 G4CompositeDataSet::~G4CompositeDataSet() 64 G4CompositeDataSet::~G4CompositeDataSet() 66 { 65 { 67 CleanUpComponents(); 66 CleanUpComponents(); 68 if (algorithm) delete algorithm; 67 if (algorithm) delete algorithm; 69 } 68 } 70 69 71 70 72 G4double G4CompositeDataSet::FindValue(G4doubl 71 G4double G4CompositeDataSet::FindValue(G4double energy, G4int componentId) const 73 { 72 { 74 const G4IDataSet* component(GetComponent(com 73 const G4IDataSet* component(GetComponent(componentId)); 75 74 76 if (component) return component->FindValue(e 75 if (component) return component->FindValue(energy); 77 76 78 std::ostringstream message; 77 std::ostringstream message; 79 message << "G4CompositeDataSet::FindValue - 78 message << "G4CompositeDataSet::FindValue - component " << componentId << " not found"; 80 79 81 G4Exception("G4CompositeDataSet::FindValue" << 80 G4Exception(message.str().c_str()); 82 "pii00000010", << 83 FatalException, << 84 message.str().c_str()); << 85 81 86 return 0.; 82 return 0.; 87 } 83 } 88 84 89 void G4CompositeDataSet::PrintData(void) const 85 void G4CompositeDataSet::PrintData(void) const 90 { 86 { 91 const G4int n = (G4int)NumberOfComponents(); << 87 const size_t n(NumberOfComponents()); 92 88 93 G4cout << "The data set has " << n << " comp 89 G4cout << "The data set has " << n << " components" << G4endl; 94 G4cout << G4endl; 90 G4cout << G4endl; 95 91 96 G4int i(0); << 92 size_t i(0); 97 93 98 while (i<n) 94 while (i<n) 99 { 95 { 100 G4cout << "--- Component " << i << " --- 96 G4cout << "--- Component " << i << " ---" << G4endl; 101 GetComponent(i)->PrintData(); 97 GetComponent(i)->PrintData(); 102 ++i; << 98 i++; 103 } 99 } 104 } 100 } 105 101 106 void G4CompositeDataSet::SetEnergiesData(G4Dat 102 void G4CompositeDataSet::SetEnergiesData(G4DataVector* energies, G4DataVector* data, G4int componentId) 107 { 103 { 108 G4IDataSet * component(components[componentI 104 G4IDataSet * component(components[componentId]); 109 105 110 if (component) 106 if (component) 111 { 107 { 112 component->SetEnergiesData(energies, dat 108 component->SetEnergiesData(energies, data, 0); 113 return; 109 return; 114 } 110 } 115 111 116 std::ostringstream message; 112 std::ostringstream message; 117 message << "G4CompositeDataSet::SetEnergiesD 113 message << "G4CompositeDataSet::SetEnergiesData - component " << componentId << " not found"; 118 114 119 G4Exception("G4CompositeDataSet::SetEnergies << 115 G4Exception(message.str().c_str()); 120 "pii00000020", << 121 FatalException, << 122 message.str().c_str()); << 123 << 124 } 116 } 125 117 126 G4bool G4CompositeDataSet::LoadData(const G4St 118 G4bool G4CompositeDataSet::LoadData(const G4String& argFileName) 127 { 119 { 128 CleanUpComponents(); 120 CleanUpComponents(); 129 121 130 for (G4int z(minZ); z<maxZ; ++z) << 122 for (G4int z(minZ); z<maxZ; z++) 131 { 123 { 132 G4IDataSet* component = new G4DataSet(z, 124 G4IDataSet* component = new G4DataSet(z, algorithm->Clone(), unitEnergies, unitData); 133 if (!component->LoadData(argFileName)) 125 if (!component->LoadData(argFileName)) 134 { 126 { 135 delete component; 127 delete component; 136 return false; 128 return false; 137 } 129 } 138 AddComponent(component); 130 AddComponent(component); 139 } 131 } 140 return true; 132 return true; 141 } 133 } 142 134 143 135 144 136 145 G4bool G4CompositeDataSet::SaveData(const G4St 137 G4bool G4CompositeDataSet::SaveData(const G4String& argFileName) const 146 { 138 { 147 for (G4int z=minZ; z<maxZ; ++z) << 139 for (G4int z=minZ; z<maxZ; z++) 148 { 140 { 149 const G4IDataSet* component(GetComponent 141 const G4IDataSet* component(GetComponent(z-minZ)); 150 142 151 if (!component) 143 if (!component) 152 { 144 { 153 std::ostringstream message; 145 std::ostringstream message; 154 message << "G4CompositeDataSet::SaveData - 146 message << "G4CompositeDataSet::SaveData - component " << (z-minZ) << " not found"; 155 G4Exception("G4CompositeDataSet::SaveData" << 147 G4Exception(message.str().c_str()); 156 "pii00000030", << 157 FatalException, << 158 message.str().c_str()); << 159 } 148 } 160 149 161 if (!component->SaveData(argFileName)) 150 if (!component->SaveData(argFileName)) 162 return false; 151 return false; 163 } 152 } 164 153 165 return true; 154 return true; 166 } 155 } 167 156 168 void G4CompositeDataSet::CleanUpComponents(voi 157 void G4CompositeDataSet::CleanUpComponents(void) 169 { 158 { 170 while (!components.empty()) 159 while (!components.empty()) 171 { 160 { 172 if (components.back()) 161 if (components.back()) 173 delete components.back(); 162 delete components.back(); 174 components.pop_back(); 163 components.pop_back(); 175 } 164 } 176 } 165 } 177 166 178 167 179 G4double G4CompositeDataSet::RandomSelect(G4in 168 G4double G4CompositeDataSet::RandomSelect(G4int componentId) const 180 { 169 { 181 G4double value = 0.; 170 G4double value = 0.; 182 if (componentId >= 0 && componentId < (G4int 171 if (componentId >= 0 && componentId < (G4int)components.size()) 183 { 172 { 184 const G4IDataSet* dataSet = GetComponent 173 const G4IDataSet* dataSet = GetComponent(componentId); 185 value = dataSet->RandomSelect(); 174 value = dataSet->RandomSelect(); 186 } 175 } 187 return value; 176 return value; 188 } 177 } 189 178