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$ >> 28 // GEANT4 tag $Name: $ 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 // 35 // 34 // ------------------------------------------- 36 // ------------------------------------------------------------------- 35 37 36 #include "G4RDCompositeEMDataSet.hh" 38 #include "G4RDCompositeEMDataSet.hh" 37 #include "G4RDEMDataSet.hh" 39 #include "G4RDEMDataSet.hh" 38 #include "G4RDVDataSetAlgorithm.hh" 40 #include "G4RDVDataSetAlgorithm.hh" 39 #include <fstream> 41 #include <fstream> 40 #include <sstream> 42 #include <sstream> 41 43 42 G4RDCompositeEMDataSet::G4RDCompositeEMDataSet 44 G4RDCompositeEMDataSet::G4RDCompositeEMDataSet(G4RDVDataSetAlgorithm* argAlgorithm, 43 G4double argUnitEnergies, 45 G4double argUnitEnergies, 44 G4double argUnitData, 46 G4double argUnitData, 45 G4int argMinZ, 47 G4int argMinZ, 46 G4int argMaxZ) 48 G4int argMaxZ) 47 : 49 : 48 algorithm(argAlgorithm), 50 algorithm(argAlgorithm), 49 unitEnergies(argUnitEnergies), 51 unitEnergies(argUnitEnergies), 50 unitData(argUnitData), 52 unitData(argUnitData), 51 minZ(argMinZ), 53 minZ(argMinZ), 52 maxZ(argMaxZ) 54 maxZ(argMaxZ) 53 { 55 { 54 if (algorithm == 0) 56 if (algorithm == 0) 55 G4Exception("G4RDCompositeEMDataSet::G4RDC 57 G4Exception("G4RDCompositeEMDataSet::G4RDCompositeEMDataSet()", 56 "InvalidSetup", FatalException 58 "InvalidSetup", FatalException, "Interpolation == 0!"); 57 } 59 } 58 60 59 61 60 62 61 G4RDCompositeEMDataSet::~G4RDCompositeEMDataSe 63 G4RDCompositeEMDataSet::~G4RDCompositeEMDataSet() 62 { 64 { 63 CleanUpComponents(); 65 CleanUpComponents(); 64 if (algorithm) delete algorithm; 66 if (algorithm) delete algorithm; 65 } 67 } 66 68 67 69 68 G4double G4RDCompositeEMDataSet::FindValue(G4d 70 G4double G4RDCompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const 69 { 71 { 70 const G4RDVEMDataSet* component(GetComponent 72 const G4RDVEMDataSet* component(GetComponent(argComponentId)); 71 73 72 if (component) return component->FindValue(a 74 if (component) return component->FindValue(argEnergy); 73 75 74 std::ostringstream message; 76 std::ostringstream message; 75 message << "Component " << argComponentId << 77 message << "Component " << argComponentId << " not found"; 76 78 77 G4Exception("G4RDCompositeEMDataSet::FindVal 79 G4Exception("G4RDCompositeEMDataSet::FindValue()", 78 "DataNotFound", FatalException, 80 "DataNotFound", FatalException, message.str().c_str()); 79 81 80 return 0.; 82 return 0.; 81 } 83 } 82 84 83 void G4RDCompositeEMDataSet::PrintData(void) c 85 void G4RDCompositeEMDataSet::PrintData(void) const 84 { 86 { 85 const size_t n(NumberOfComponents()); 87 const size_t n(NumberOfComponents()); 86 88 87 G4cout << "The data set has " << n << " comp 89 G4cout << "The data set has " << n << " components" << G4endl; 88 G4cout << G4endl; 90 G4cout << G4endl; 89 91 90 size_t i(0); 92 size_t i(0); 91 93 92 while (i<n) 94 while (i<n) 93 { 95 { 94 G4cout << "--- Component " << i << " --- 96 G4cout << "--- Component " << i << " ---" << G4endl; 95 GetComponent(i)->PrintData(); 97 GetComponent(i)->PrintData(); 96 i++; 98 i++; 97 } 99 } 98 } 100 } 99 101 100 void G4RDCompositeEMDataSet::SetEnergiesData(G 102 void G4RDCompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId) 101 { 103 { 102 G4RDVEMDataSet * component(components[argCom 104 G4RDVEMDataSet * component(components[argComponentId]); 103 105 104 if (component) 106 if (component) 105 { 107 { 106 component->SetEnergiesData(argEnergies, 108 component->SetEnergiesData(argEnergies, argData, 0); 107 return; 109 return; 108 } 110 } 109 111 110 std::ostringstream message; 112 std::ostringstream message; 111 message << "Component " << argComponentId << 113 message << "Component " << argComponentId << " not found"; 112 114 113 G4Exception("G4RDCompositeEMDataSet::SetEner 115 G4Exception("G4RDCompositeEMDataSet::SetEnergiesData()", 114 "DataNotFound", FatalException, 116 "DataNotFound", FatalException, message.str().c_str()); 115 } 117 } 116 118 117 G4bool G4RDCompositeEMDataSet::LoadData(const 119 G4bool G4RDCompositeEMDataSet::LoadData(const G4String& argFileName) 118 { 120 { 119 CleanUpComponents(); 121 CleanUpComponents(); 120 122 121 for (G4int z(minZ); z<maxZ; z++) 123 for (G4int z(minZ); z<maxZ; z++) 122 { 124 { 123 G4RDVEMDataSet* component = new G4RDEMDa 125 G4RDVEMDataSet* component = new G4RDEMDataSet(z, algorithm->Clone(), unitEnergies, unitData); 124 if (!component->LoadData(argFileName)) 126 if (!component->LoadData(argFileName)) 125 { 127 { 126 delete component; 128 delete component; 127 return false; 129 return false; 128 } 130 } 129 AddComponent(component); 131 AddComponent(component); 130 } 132 } 131 return true; 133 return true; 132 } 134 } 133 135 134 136 135 137 136 G4bool G4RDCompositeEMDataSet::SaveData(const 138 G4bool G4RDCompositeEMDataSet::SaveData(const G4String& argFileName) const 137 { 139 { 138 for (G4int z=minZ; z<maxZ; z++) 140 for (G4int z=minZ; z<maxZ; z++) 139 { 141 { 140 const G4RDVEMDataSet* component(GetCompo 142 const G4RDVEMDataSet* component(GetComponent(z-minZ)); 141 143 142 if (!component) 144 if (!component) 143 { 145 { 144 std::ostringstream message; 146 std::ostringstream message; 145 message << "Component " << (z-minZ) << " n 147 message << "Component " << (z-minZ) << " not found"; 146 G4Exception("G4RDCompositeEMDataSet::SaveD 148 G4Exception("G4RDCompositeEMDataSet::SaveData()", 147 "DataNotFound", FatalExc 149 "DataNotFound", FatalException, message.str().c_str()); 148 } 150 } 149 151 150 if (!component->SaveData(argFileName)) 152 if (!component->SaveData(argFileName)) 151 return false; 153 return false; 152 } 154 } 153 155 154 return true; 156 return true; 155 } 157 } 156 158 157 void G4RDCompositeEMDataSet::CleanUpComponents 159 void G4RDCompositeEMDataSet::CleanUpComponents(void) 158 { 160 { 159 while (!components.empty()) 161 while (!components.empty()) 160 { 162 { 161 if (components.back()) 163 if (components.back()) 162 delete components.back(); 164 delete components.back(); 163 components.pop_back(); 165 components.pop_back(); 164 } 166 } 165 } 167 } 166 168 167 169 168 G4double G4RDCompositeEMDataSet::RandomSelect( 170 G4double G4RDCompositeEMDataSet::RandomSelect(G4int componentId) const 169 { 171 { 170 G4double value = 0.; 172 G4double value = 0.; 171 if (componentId >= 0 && componentId < (G4int 173 if (componentId >= 0 && componentId < (G4int)components.size()) 172 { 174 { 173 const G4RDVEMDataSet* dataSet = GetCompo 175 const G4RDVEMDataSet* dataSet = GetComponent(componentId); 174 value = dataSet->RandomSelect(); 176 value = dataSet->RandomSelect(); 175 } 177 } 176 return value; 178 return value; 177 } 179 } 178 180