| 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4PixeShellDataSet.cc,v 1.3 2010/11/22 11:29:38 pia Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $
|
|---|
| 29 | //
|
|---|
| 30 | // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
|
|---|
| 31 | //
|
|---|
| 32 | // History:
|
|---|
| 33 | // -----------
|
|---|
| 34 | // 1 Aug 2001 MGP Created
|
|---|
| 35 | // 09.10.01 V.Ivanchenko Add case z=0
|
|---|
| 36 | // 9 Mar 2008 MGP Cleaned up unreadable code modified by former developer
|
|---|
| 37 | // (Further clean-up needed)
|
|---|
| 38 | // 31 Jul 2008 MGP Revised
|
|---|
| 39 | //
|
|---|
| 40 | // -------------------------------------------------------------------
|
|---|
| 41 |
|
|---|
| 42 | #include "G4PixeShellDataSet.hh"
|
|---|
| 43 | #include "G4DataSet.hh"
|
|---|
| 44 | #include "G4IInterpolator.hh"
|
|---|
| 45 | #include <fstream>
|
|---|
| 46 | #include <sstream>
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | G4PixeShellDataSet::G4PixeShellDataSet(G4int zeta,
|
|---|
| 50 | G4IInterpolator* algo,
|
|---|
| 51 | const G4String& modelK,
|
|---|
| 52 | const G4String& modelL,
|
|---|
| 53 | const G4String& modelM,
|
|---|
| 54 | G4double eUnit,
|
|---|
| 55 | G4double dataUnit):
|
|---|
| 56 | z(zeta),
|
|---|
| 57 | algorithm(algo),
|
|---|
| 58 | unitEnergies(eUnit),
|
|---|
| 59 | unitData(dataUnit)
|
|---|
| 60 | {
|
|---|
| 61 | if (algorithm == 0) G4Exception("G4PixeShellDataSet::G4PixeShellDataSet - interpolation == 0");
|
|---|
| 62 |
|
|---|
| 63 | crossModel.push_back(modelK);
|
|---|
| 64 | crossModel.push_back(modelL);
|
|---|
| 65 | crossModel.push_back(modelM);
|
|---|
| 66 |
|
|---|
| 67 | shellName.push_back("k");
|
|---|
| 68 | shellName.push_back("l");
|
|---|
| 69 | shellName.push_back("m");
|
|---|
| 70 |
|
|---|
| 71 | size_t sizeK = modelK.size();
|
|---|
| 72 | size_t sizeL = modelL.size();
|
|---|
| 73 | size_t sizeM = modelM.size();
|
|---|
| 74 |
|
|---|
| 75 | if (sizeK > 0) subShellName.push_back("k");
|
|---|
| 76 |
|
|---|
| 77 | if (sizeK > 0 && sizeL > 0)
|
|---|
| 78 | {
|
|---|
| 79 | subShellName.push_back("l1");
|
|---|
| 80 | subShellName.push_back("l2");
|
|---|
| 81 | subShellName.push_back("l3");
|
|---|
| 82 | }
|
|---|
| 83 | if (sizeK > 0 && sizeL > 0 && sizeM >0)
|
|---|
| 84 | {
|
|---|
| 85 | subShellName.push_back("m1");
|
|---|
| 86 | subShellName.push_back("m2");
|
|---|
| 87 | subShellName.push_back("m3");
|
|---|
| 88 | subShellName.push_back("m4");
|
|---|
| 89 | subShellName.push_back("m5");
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 | G4PixeShellDataSet::~G4PixeShellDataSet()
|
|---|
| 95 | {
|
|---|
| 96 | CleanUpComponents();
|
|---|
| 97 | if (algorithm) delete algorithm;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | G4double G4PixeShellDataSet::FindValue(G4double energy, G4int /* componentId */) const
|
|---|
| 102 | {
|
|---|
| 103 | // Returns the sum over the shells corresponding to e
|
|---|
| 104 | G4double value = 0.;
|
|---|
| 105 |
|
|---|
| 106 | std::vector<G4IDataSet *>::const_iterator i(components.begin());
|
|---|
| 107 | std::vector<G4IDataSet *>::const_iterator end(components.end());
|
|---|
| 108 |
|
|---|
| 109 | while (i != end)
|
|---|
| 110 | {
|
|---|
| 111 | value += (*i)->FindValue(energy);
|
|---|
| 112 | i++;
|
|---|
| 113 | }
|
|---|
| 114 | return value;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | void G4PixeShellDataSet::PrintData(void) const
|
|---|
| 119 | {
|
|---|
| 120 | const size_t n = NumberOfComponents();
|
|---|
| 121 |
|
|---|
| 122 | G4cout << "The data set has " << n << " components" << G4endl;
|
|---|
| 123 | G4cout << G4endl;
|
|---|
| 124 |
|
|---|
| 125 | size_t i = 0;
|
|---|
| 126 |
|
|---|
| 127 | while (i < n)
|
|---|
| 128 | {
|
|---|
| 129 | G4cout << "--- Component " << i << " ---" << G4endl;
|
|---|
| 130 | GetComponent(i)->PrintData();
|
|---|
| 131 | i++;
|
|---|
| 132 | }
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 | void G4PixeShellDataSet::SetEnergiesData(G4DataVector* energies,
|
|---|
| 137 | G4DataVector* data,
|
|---|
| 138 | G4int componentId)
|
|---|
| 139 | {
|
|---|
| 140 | G4IDataSet* component = components[componentId];
|
|---|
| 141 |
|
|---|
| 142 | if (component)
|
|---|
| 143 | {
|
|---|
| 144 | component->SetEnergiesData(energies, data, 0);
|
|---|
| 145 | return;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | std::ostringstream message;
|
|---|
| 149 | message << "G4PixeShellDataSet::SetEnergiesData - component " << componentId << " not found";
|
|---|
| 150 |
|
|---|
| 151 | G4Exception(message.str().c_str());
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 | G4bool G4PixeShellDataSet::LoadData(const G4String& file)
|
|---|
| 156 | {
|
|---|
| 157 | CleanUpComponents();
|
|---|
| 158 |
|
|---|
| 159 | // Load shell cross sections
|
|---|
| 160 |
|
|---|
| 161 | G4int nShells = subShellName.size();
|
|---|
| 162 |
|
|---|
| 163 | for (G4int subShellIndex=0; subShellIndex<nShells; subShellIndex++)
|
|---|
| 164 | {
|
|---|
| 165 | G4String subName = subShellName[subShellIndex];
|
|---|
| 166 | G4String fullFileName = FullFileName(file,subName);
|
|---|
| 167 |
|
|---|
| 168 | // Create component DataSet with the data from the current subshell
|
|---|
| 169 | G4IDataSet* dataSet = new G4DataSet(z,algorithm);
|
|---|
| 170 | dataSet->LoadData(fullFileName);
|
|---|
| 171 |
|
|---|
| 172 | // Add component to the ShellDataSet
|
|---|
| 173 | AddComponent(dataSet);
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | return true;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 | G4bool G4PixeShellDataSet::SaveData(const G4String& /* file */) const
|
|---|
| 181 | {
|
|---|
| 182 | // Dummy implementation
|
|---|
| 183 | return true;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 | void G4PixeShellDataSet::CleanUpComponents(void)
|
|---|
| 188 | {
|
|---|
| 189 | while (!components.empty())
|
|---|
| 190 | {
|
|---|
| 191 | if (components.back()) delete components.back();
|
|---|
| 192 | components.pop_back();
|
|---|
| 193 | }
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 | G4String G4PixeShellDataSet::FullFileName(const G4String& file,
|
|---|
| 198 | const G4String& subShell) const
|
|---|
| 199 | {
|
|---|
| 200 | char* path = getenv("G4PIIDATA");
|
|---|
| 201 | if (!path)
|
|---|
| 202 | G4Exception("G4PixeShellDataSet::FullFileName - G4PIIDATA environment variable not set");
|
|---|
| 203 |
|
|---|
| 204 | // Identify the shell this subshell belongs to
|
|---|
| 205 | G4int shellIndex = TranslateShell(subShell);
|
|---|
| 206 | G4String shellString = shellName[shellIndex];
|
|---|
| 207 | G4String shellModel = crossModel[shellIndex];
|
|---|
| 208 |
|
|---|
| 209 | std::ostringstream fullFileName;
|
|---|
| 210 |
|
|---|
| 211 | fullFileName
|
|---|
| 212 | //<< path
|
|---|
| 213 | << "pixe/"
|
|---|
| 214 | << file
|
|---|
| 215 | << '/'
|
|---|
| 216 | << shellString
|
|---|
| 217 | << '/'
|
|---|
| 218 | << shellModel
|
|---|
| 219 | << '/'
|
|---|
| 220 | << subShell
|
|---|
| 221 | << '-' ;
|
|---|
| 222 | // << z
|
|---|
| 223 | // << ".dat";
|
|---|
| 224 |
|
|---|
| 225 | G4String test(fullFileName.str().c_str());
|
|---|
| 226 | // std::cout << "PixeShellDataSet - Reading data from file " << test << std::endl;
|
|---|
| 227 |
|
|---|
| 228 | return G4String(fullFileName.str().c_str());
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | G4int G4PixeShellDataSet::TranslateShell(const G4String& subShell) const
|
|---|
| 232 | {
|
|---|
| 233 | // By default return K shell
|
|---|
| 234 | G4int index = 0;
|
|---|
| 235 |
|
|---|
| 236 | if (subShell == "l1" || subShell == "l2" || subShell == "l3" ) index = 1;
|
|---|
| 237 | if (subShell == "m1" ||
|
|---|
| 238 | subShell == "m2" ||
|
|---|
| 239 | subShell == "m3" ||
|
|---|
| 240 | subShell == "m4" ||
|
|---|
| 241 | subShell == "m5" ) index = 2;
|
|---|
| 242 | return index;
|
|---|
| 243 | }
|
|---|