| 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: G4ShellData.cc,v 1.8 2006/06/29 19:41:21 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-01-patch-02 $
|
|---|
| 29 | //
|
|---|
| 30 | // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
|
|---|
| 31 | //
|
|---|
| 32 | // History:
|
|---|
| 33 | // -----------
|
|---|
| 34 | // 31 Jul 2001 MGP Created
|
|---|
| 35 | //
|
|---|
| 36 | // -------------------------------------------------------------------
|
|---|
| 37 |
|
|---|
| 38 | #include "G4ShellData.hh"
|
|---|
| 39 | #include "G4DataVector.hh"
|
|---|
| 40 | #include <fstream>
|
|---|
| 41 | #include <sstream>
|
|---|
| 42 |
|
|---|
| 43 | // Constructor
|
|---|
| 44 |
|
|---|
| 45 | G4ShellData::G4ShellData(G4int minZ, G4int maxZ)
|
|---|
| 46 | : zMin(minZ), zMax(maxZ)
|
|---|
| 47 | { }
|
|---|
| 48 |
|
|---|
| 49 | // Destructor
|
|---|
| 50 | G4ShellData::~G4ShellData()
|
|---|
| 51 | {
|
|---|
| 52 | std::map<G4int,G4DataVector*,std::less<G4int> >::iterator pos;
|
|---|
| 53 |
|
|---|
| 54 | for (pos = idMap.begin(); pos != idMap.end(); ++pos)
|
|---|
| 55 | {
|
|---|
| 56 | G4DataVector* dataSet = (*pos).second;
|
|---|
| 57 | delete dataSet;
|
|---|
| 58 | }
|
|---|
| 59 | for (pos = bindingMap.begin(); pos != bindingMap.end(); ++pos)
|
|---|
| 60 | {
|
|---|
| 61 | G4DataVector* dataSet = (*pos).second;
|
|---|
| 62 | delete dataSet;
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | size_t G4ShellData::NumberOfShells(G4int Z) const
|
|---|
| 68 | {
|
|---|
| 69 | G4int z = Z - 1;
|
|---|
| 70 | G4int n = 0;
|
|---|
| 71 |
|
|---|
| 72 | if (Z>= zMin && Z <= zMax)
|
|---|
| 73 | {
|
|---|
| 74 | n = nShells[z];
|
|---|
| 75 | }
|
|---|
| 76 | return n;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | const G4DataVector& G4ShellData::ShellIdVector(G4int Z) const
|
|---|
| 81 | {
|
|---|
| 82 | std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator pos;
|
|---|
| 83 | if (Z < zMin || Z > zMax)
|
|---|
| 84 | G4Exception("G4ShellData::ShellIdVector - Z outside boundaries");
|
|---|
| 85 | pos = idMap.find(Z);
|
|---|
| 86 | G4DataVector* dataSet = (*pos).second;
|
|---|
| 87 | return *dataSet;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | G4int G4ShellData::ShellId(G4int Z, G4int shellIndex) const
|
|---|
| 91 | {
|
|---|
| 92 | G4int n = -1;
|
|---|
| 93 |
|
|---|
| 94 | if (Z >= zMin && Z <= zMax)
|
|---|
| 95 | {
|
|---|
| 96 | std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator pos;
|
|---|
| 97 | pos = idMap.find(Z);
|
|---|
| 98 | if (pos!= idMap.end())
|
|---|
| 99 | {
|
|---|
| 100 | G4DataVector dataSet = *((*pos).second);
|
|---|
| 101 | G4int nData = dataSet.size();
|
|---|
| 102 | if (shellIndex >= 0 && shellIndex < nData)
|
|---|
| 103 | {
|
|---|
| 104 | n = (G4int) dataSet[shellIndex];
|
|---|
| 105 | }
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 | return n;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | G4double G4ShellData::BindingEnergy(G4int Z, G4int shellIndex) const
|
|---|
| 113 | {
|
|---|
| 114 | G4double value = 0.;
|
|---|
| 115 |
|
|---|
| 116 | if (Z >= zMin && Z <= zMax)
|
|---|
| 117 | {
|
|---|
| 118 | std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator pos;
|
|---|
| 119 | pos = bindingMap.find(Z);
|
|---|
| 120 | if (pos!= bindingMap.end())
|
|---|
| 121 | {
|
|---|
| 122 | G4DataVector dataSet = *((*pos).second);
|
|---|
| 123 | G4int nData = dataSet.size();
|
|---|
| 124 | if (shellIndex >= 0 && shellIndex < nData)
|
|---|
| 125 | {
|
|---|
| 126 | value = dataSet[shellIndex];
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 | return value;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | void G4ShellData::PrintData() const
|
|---|
| 134 | {
|
|---|
| 135 | for (G4int Z = zMin; Z <= zMax; Z++)
|
|---|
| 136 | {
|
|---|
| 137 | G4cout << "---- Shell data for Z = "
|
|---|
| 138 | << Z
|
|---|
| 139 | << " ---- "
|
|---|
| 140 | << G4endl;
|
|---|
| 141 | G4int nSh = nShells[Z-1];
|
|---|
| 142 | std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator posId;
|
|---|
| 143 | posId = idMap.find(Z);
|
|---|
| 144 | G4DataVector* ids = (*posId).second;
|
|---|
| 145 | std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator posE;
|
|---|
| 146 | posE = bindingMap.find(Z);
|
|---|
| 147 | G4DataVector* energies = (*posE).second;
|
|---|
| 148 | for (G4int i=0; i<nSh; i++)
|
|---|
| 149 | {
|
|---|
| 150 | G4int id = (G4int) (*ids)[i];
|
|---|
| 151 | G4double e = (*energies)[i] / MeV;
|
|---|
| 152 | G4cout << i <<") Shell id: " << id
|
|---|
| 153 | << " - Binding energy = "
|
|---|
| 154 | << e << " MeV " << G4endl;
|
|---|
| 155 | }
|
|---|
| 156 | G4cout << "-------------------------------------------------"
|
|---|
| 157 | << G4endl;
|
|---|
| 158 | }
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 | void G4ShellData::LoadData(const G4String& fileName)
|
|---|
| 163 | {
|
|---|
| 164 | // Build the complete string identifying the file with the data set
|
|---|
| 165 |
|
|---|
| 166 | std::ostringstream ost;
|
|---|
| 167 |
|
|---|
| 168 | ost << fileName << ".dat";
|
|---|
| 169 |
|
|---|
| 170 | G4String name(ost.str());
|
|---|
| 171 |
|
|---|
| 172 | char* path = getenv("G4LEDATA");
|
|---|
| 173 | if (!path)
|
|---|
| 174 | {
|
|---|
| 175 | G4String excep("G4EMDataSet - G4LEDATA environment variable not set");
|
|---|
| 176 | G4Exception(excep);
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | G4String pathString(path);
|
|---|
| 180 | G4String dirFile = pathString + name;
|
|---|
| 181 | std::ifstream file(dirFile);
|
|---|
| 182 | std::filebuf* lsdp = file.rdbuf();
|
|---|
| 183 |
|
|---|
| 184 | if (! (lsdp->is_open()) )
|
|---|
| 185 | {
|
|---|
| 186 | G4String s1("G4ShellData - data file: ");
|
|---|
| 187 | G4String s2(" not found");
|
|---|
| 188 | G4String excep = s1 + dirFile + s2;
|
|---|
| 189 | G4Exception(excep);
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | G4double a = 0;
|
|---|
| 193 | G4int k = 1;
|
|---|
| 194 | G4int s = 0;
|
|---|
| 195 |
|
|---|
| 196 | G4int Z = 1;
|
|---|
| 197 | G4DataVector* energies = new G4DataVector;
|
|---|
| 198 | G4DataVector* ids = new G4DataVector;
|
|---|
| 199 |
|
|---|
| 200 | do {
|
|---|
| 201 | file >> a;
|
|---|
| 202 | G4int nColumns = 2;
|
|---|
| 203 | if (a == -1)
|
|---|
| 204 | {
|
|---|
| 205 | if (s == 0)
|
|---|
| 206 | {
|
|---|
| 207 | // End of a shell data set
|
|---|
| 208 | idMap[Z] = ids;
|
|---|
| 209 | bindingMap[Z] = energies;
|
|---|
| 210 | G4int n = ids->size();
|
|---|
| 211 | nShells.push_back(n);
|
|---|
| 212 | // Start of new shell data set
|
|---|
| 213 | ids = new G4DataVector;
|
|---|
| 214 | energies = new G4DataVector;
|
|---|
| 215 | Z++;
|
|---|
| 216 | }
|
|---|
| 217 | s++;
|
|---|
| 218 | if (s == nColumns)
|
|---|
| 219 | {
|
|---|
| 220 | s = 0;
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 | else if (a == -2)
|
|---|
| 224 | {
|
|---|
| 225 | // End of file; delete the empty vectors created when encountering the last -1 -1 row
|
|---|
| 226 | delete energies;
|
|---|
| 227 | delete ids;
|
|---|
| 228 | //nComponents = components.size();
|
|---|
| 229 | }
|
|---|
| 230 | else
|
|---|
| 231 | {
|
|---|
| 232 | // 1st column is shell id
|
|---|
| 233 | if(k%nColumns != 0)
|
|---|
| 234 | {
|
|---|
| 235 | ids->push_back(a);
|
|---|
| 236 | k++;
|
|---|
| 237 | }
|
|---|
| 238 | else if (k%nColumns == 0)
|
|---|
| 239 | {
|
|---|
| 240 | // 2nd column is binding energy
|
|---|
| 241 | G4double e = a * MeV;
|
|---|
| 242 | energies->push_back(e);
|
|---|
| 243 | k = 1;
|
|---|
| 244 | }
|
|---|
| 245 | }
|
|---|
| 246 | } while (a != -2); // end of file
|
|---|
| 247 | file.close();
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|