[968] | 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: G4DopplerProfile.cc,v 1.2 2008/03/17 13:40:53 pia Exp $ |
---|
| 28 | // GEANT4 tag $Name: geant4-09-02-ref-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 "G4DopplerProfile.hh" |
---|
| 39 | #include "G4DataVector.hh" |
---|
| 40 | #include "G4SystemOfUnits.hh" |
---|
| 41 | #include "G4VEMDataSet.hh" |
---|
| 42 | #include "G4EMDataSet.hh" |
---|
| 43 | #include "G4CompositeEMDataSet.hh" |
---|
| 44 | #include "G4VDataSetAlgorithm.hh" |
---|
| 45 | #include "G4LogLogInterpolation.hh" |
---|
| 46 | |
---|
| 47 | #include <fstream> |
---|
| 48 | #include <sstream> |
---|
| 49 | #include "Randomize.hh" |
---|
| 50 | |
---|
| 51 | // The following deprecated header is included because <functional> seems not to be found on MGP's laptop |
---|
| 52 | //#include "function.h" |
---|
| 53 | |
---|
| 54 | // Constructor |
---|
| 55 | |
---|
| 56 | G4DopplerProfile::G4DopplerProfile(G4int minZ, G4int maxZ) |
---|
| 57 | : zMin(minZ), zMax(maxZ) |
---|
| 58 | { |
---|
| 59 | nBiggs = 31; |
---|
| 60 | |
---|
| 61 | LoadBiggsP("/doppler/p-biggs"); |
---|
| 62 | |
---|
| 63 | for (G4int Z=zMin; Z<zMax+1; Z++) |
---|
| 64 | { |
---|
| 65 | LoadProfile("/doppler/profile",Z); |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | // Destructor |
---|
| 70 | G4DopplerProfile::~G4DopplerProfile() |
---|
| 71 | { |
---|
| 72 | std::map<G4int,G4VEMDataSet*,std::less<G4int> >::iterator pos; |
---|
| 73 | for (pos = profileMap.begin(); pos != profileMap.end(); ++pos) |
---|
| 74 | { |
---|
| 75 | G4VEMDataSet* dataSet = (*pos).second; |
---|
| 76 | delete dataSet; |
---|
| 77 | dataSet = 0; |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | size_t G4DopplerProfile::NumberOfProfiles(G4int Z) const |
---|
| 83 | { |
---|
| 84 | G4int n = 0; |
---|
| 85 | if (Z>= zMin && Z <= zMax) n = nShells[Z-1]; |
---|
| 86 | return n; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | const G4VEMDataSet* G4DopplerProfile::Profiles(G4int Z) const |
---|
| 91 | { |
---|
| 92 | std::map<G4int,G4VEMDataSet*,std::less<G4int> >::const_iterator pos; |
---|
| 93 | if (Z < zMin || Z > zMax) G4Exception("G4DopplerProfile::Profiles - Z outside boundaries"); |
---|
| 94 | pos = profileMap.find(Z); |
---|
| 95 | G4VEMDataSet* dataSet = (*pos).second; |
---|
| 96 | return dataSet; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | const G4VEMDataSet* G4DopplerProfile::Profile(G4int Z, G4int shellIndex) const |
---|
| 101 | { |
---|
| 102 | const G4VEMDataSet* profis = Profiles(Z); |
---|
| 103 | const G4VEMDataSet* profi = profis->GetComponent(shellIndex); |
---|
| 104 | return profi; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | void G4DopplerProfile::PrintData() const |
---|
| 109 | { |
---|
| 110 | for (G4int Z=zMin; Z<zMax; Z++) |
---|
| 111 | { |
---|
| 112 | const G4VEMDataSet* profis = Profiles(Z); |
---|
| 113 | profis->PrintData(); |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | void G4DopplerProfile::LoadBiggsP(const G4String& fileName) |
---|
| 119 | { |
---|
| 120 | std::ostringstream ost; |
---|
| 121 | ost << fileName << ".dat"; |
---|
| 122 | G4String name(ost.str()); |
---|
| 123 | |
---|
| 124 | char* path = getenv("G4LEDATA"); |
---|
| 125 | if (!path) |
---|
| 126 | { |
---|
| 127 | G4String excep("G4EMDataSet - G4LEDATA environment variable not set"); |
---|
| 128 | G4Exception(excep); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | G4String pathString(path); |
---|
| 132 | G4String dirFile = pathString + name; |
---|
| 133 | std::ifstream file(dirFile); |
---|
| 134 | std::filebuf* lsdp = file.rdbuf(); |
---|
| 135 | |
---|
| 136 | if (! (lsdp->is_open()) ) |
---|
| 137 | { |
---|
| 138 | G4String s1("G4DopplerProfile::LoadBiggsP data file: "); |
---|
| 139 | G4String s2(" not found"); |
---|
| 140 | G4String excep = s1 + dirFile + s2; |
---|
| 141 | G4Exception(excep); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | G4double p; |
---|
| 145 | while(!file.eof()) |
---|
| 146 | { |
---|
| 147 | file >> p; |
---|
| 148 | biggsP.push_back(p); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | // Make sure that the number of data loaded corresponds to the number in Biggs' paper |
---|
| 152 | if (biggsP.size() != nBiggs) |
---|
| 153 | G4Exception("G4DopplerProfile::LoadBiggsP - Number of momenta read in is not 31"); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | void G4DopplerProfile::LoadProfile(const G4String& fileName,G4int Z) |
---|
| 158 | { |
---|
| 159 | std::ostringstream ost; |
---|
| 160 | ost << fileName << "-" << Z << ".dat"; |
---|
| 161 | G4String name(ost.str()); |
---|
| 162 | |
---|
| 163 | char* path = getenv("G4LEDATA"); |
---|
| 164 | if (!path) |
---|
| 165 | { |
---|
| 166 | G4String excep("G4EMDataSet - G4LEDATA environment variable not set"); |
---|
| 167 | G4Exception(excep); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | G4String pathString(path); |
---|
| 171 | G4String dirFile = pathString + name; |
---|
| 172 | std::ifstream file(dirFile); |
---|
| 173 | std::filebuf* lsdp = file.rdbuf(); |
---|
| 174 | |
---|
| 175 | if (! (lsdp->is_open()) ) |
---|
| 176 | { |
---|
| 177 | G4String s1("G4DopplerProfile::LoadProfile data file: "); |
---|
| 178 | G4String s2(" not found"); |
---|
| 179 | G4String excep = s1 + dirFile + s2; |
---|
| 180 | G4Exception(excep); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | G4double p; |
---|
| 184 | G4int nShell = 0; |
---|
| 185 | |
---|
| 186 | // Create CompositeDataSet for the current Z |
---|
| 187 | G4VDataSetAlgorithm* interpolation = new G4LogLogInterpolation; |
---|
| 188 | G4VEMDataSet* dataSetForZ = new G4CompositeEMDataSet(interpolation,1.,1.,1,1); |
---|
| 189 | |
---|
| 190 | while (!file.eof()) |
---|
| 191 | { |
---|
| 192 | nShell++; |
---|
| 193 | G4DataVector* profi = new G4DataVector; |
---|
| 194 | G4DataVector* biggs = new G4DataVector; |
---|
| 195 | |
---|
| 196 | // Read in profile data for the current shell |
---|
| 197 | for (size_t i=0; i<nBiggs; i++) |
---|
| 198 | { |
---|
| 199 | file >> p; |
---|
| 200 | profi->push_back(p); |
---|
| 201 | biggs->push_back(biggsP[i]); |
---|
| 202 | // if (i == 16) G4cout << "profile = " << p << G4endl; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | // Create G4EMDataSet for the current shell |
---|
| 206 | G4VDataSetAlgorithm* algo = interpolation->Clone(); |
---|
| 207 | G4VEMDataSet* dataSet = new G4EMDataSet(Z, biggs, profi, algo, 1., 1., true); |
---|
| 208 | |
---|
| 209 | // Add current shell profile component to G4CompositeEMDataSet for the current Z |
---|
| 210 | dataSetForZ->AddComponent(dataSet); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | // Fill in number of shells for the current Z |
---|
| 214 | nShells.push_back(nShell); |
---|
| 215 | |
---|
| 216 | profileMap[Z] = dataSetForZ; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | G4double G4DopplerProfile::RandomSelectMomentum(G4int Z, G4int shellIndex) const |
---|
| 221 | { |
---|
| 222 | G4double value = 0.; |
---|
| 223 | const G4VEMDataSet* profis = Profiles(Z); |
---|
| 224 | value = profis->RandomSelect(shellIndex); |
---|
| 225 | return value; |
---|
| 226 | } |
---|