Geant4-11
G4LivermoreGammaConversionModel.cc
Go to the documentation of this file.
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// Author: Sebastien Incerti
27// 22 January 2012
28// on base of G4LivermoreGammaConversionModel (original version)
29// and G4LivermoreRayleighModel (MT version)
30//
31// Modifications: Zhuxin Li@CENBG
32// 11 March 2020
33// derives from G4PairProductionRelModel
34// -------------------------------------------------------------------
35
37#include "G4Electron.hh"
38#include "G4Positron.hh"
39#include "G4AutoLock.hh"
40#include "G4EmParameters.hh"
43#include "G4PhysicsLogVector.hh"
46#include "G4SystemOfUnits.hh"
47#include "G4Exp.hh"
48
50
51//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
52//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
53
56
58(const G4ParticleDefinition* p, const G4String& nam)
59: G4PairProductionRelModel(p,nam),fParticleChange(nullptr),maxZ(100)
60{
61 verboseLevel = 0;
62 // Verbosity scale for debugging purposes:
63 // 0 = nothing
64 // 1 = calculation of cross sections, file openings...
65 // 2 = entering in methods
66 if(verboseLevel > 0)
67 {
68 G4cout << "G4LivermoreGammaConversionModel is constructed " << G4endl;
69 }
70}
71
72//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
73
75{
76 if(IsMaster()) {
77 for(G4int i = 0; i <= maxZ; ++i)
78 {
79 if(data[i])
80 {
81 delete data[i];
82 data[i] = nullptr;
83 }
84 }
85 }
86}
87
88//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
89
91 const G4ParticleDefinition* particle,
92 const G4DataVector& cuts)
94 if (verboseLevel > 1)
95 {
96 G4cout << "Calling Initialise() of G4LivermoreGammaConversionModel."
97 << G4endl
98 << "Energy range: "
99 << LowEnergyLimit() / MeV << " MeV - "
100 << HighEnergyLimit() / GeV << " GeV isMater: " << IsMaster()
101 << G4endl;
102 }
103
104 if(fParticleChange == nullptr) {
106 }
107
108 if(IsMaster())
109 {
110 // Initialise element selector
111 InitialiseElementSelectors(particle, cuts);
112
113 // Access to elements
114 char* path = std::getenv("G4LEDATA");
115 const G4ElementTable* elemTable = G4Element::GetElementTable();
116 size_t numElems = (*elemTable).size();
117 for(size_t ie = 0; ie < numElems; ++ie)
118 {
119 const G4Element* elem = (*elemTable)[ie];
120 const G4int Z = std::min(maxZ, elem->GetZasInt());
121 if(data[Z] == nullptr)
122 {
123 ReadData(Z, path);
124 }
125 }
126 }
127}
128
129
130//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
131
132void G4LivermoreGammaConversionModel::ReadData(size_t Z, const char* path)
133{
134 if (verboseLevel > 1)
135 {
136 G4cout << "Calling ReadData() of G4LivermoreGammaConversionModel"
137 << G4endl;
138 }
139
140 if(data[Z]!= nullptr) { return; }
141
142 const char* datadir = path;
143
144 if(datadir == nullptr)
145 {
146 datadir = std::getenv("G4LEDATA");
147 if(datadir == nullptr)
148 {
149 G4Exception("G4LivermoreGammaConversionModel::ReadData()",
150 "em0006",FatalException,
151 "Environment variable G4LEDATA not defined");
152 return;
153 }
154 }
155 data[Z] = new G4PhysicsFreeVector();
156 std::ostringstream ost;
157 if(G4EmParameters::Instance()->LivermoreDataDir() == "livermore"){
158 ost << datadir << "/livermore/pair/pp-cs-" << Z <<".dat";
159 }else{
160 ost << datadir << "/epics2017/pair/pp-cs-" << Z <<".dat";
161 }
162
163 std::ifstream fin(ost.str().c_str());
164
165 if( !fin.is_open())
166 {
168 ed << "G4LivermoreGammaConversionModel data file <" << ost.str().c_str()
169 << "> is not opened!" << G4endl;
170 G4Exception("G4LivermoreGammaConversionModel::ReadData()",
171 "em0003",FatalException,
172 ed,"G4LEDATA version should be G4EMLOW6.27 or later.");
173 return;
174 }
175 else
176 {
177
178 if(verboseLevel > 1) { G4cout << "File " << ost.str()
179 << " is opened by G4LivermoreGammaConversionModel" << G4endl;}
180
181 data[Z]->Retrieve(fin, true);
182 }
183}
184
185//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
186
188 const G4ParticleDefinition* particle,
190{
191 if (verboseLevel > 1)
192 {
193 G4cout << "G4LivermoreGammaConversionModel::ComputeCrossSectionPerAtom() Z= "
194 << Z << G4endl;
195 }
196
197 if (GammaEnergy < lowEnergyLimit) { return 0.0; }
198
199 G4double xs = 0.0;
200
201 G4int intZ = std::max(1, std::min(G4lrint(Z), maxZ));
202
203 G4PhysicsFreeVector* pv = data[intZ];
204
205 // if element was not initialised
206 // do initialisation safely for MT mode
207 if(pv == nullptr)
208 {
209 InitialiseForElement(particle, intZ);
210 pv = data[intZ];
211 if(pv == nullptr) { return xs; }
212 }
213 // x-section is taken from the table
214 xs = pv->Value(GammaEnergy);
215
216 if(verboseLevel > 0)
217 {
218 G4cout << "*** Gamma conversion xs for Z=" << Z << " at energy E(MeV)="
219 << GammaEnergy/MeV << " cs=" << xs/millibarn << " mb" << G4endl;
220 }
221 return xs;
222}
223
224//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
225
228 G4int Z)
229{
231 if(data[Z] == nullptr) { ReadData(Z); }
232 l.unlock();
233}
234
235//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::vector< G4Element * > G4ElementTable
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
static const G4int maxZ
#define elem(i, j)
static constexpr double millibarn
Definition: G4SIunits.hh:86
static constexpr double GeV
Definition: G4SIunits.hh:203
static constexpr double MeV
Definition: G4SIunits.hh:200
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:85
std::mutex G4Mutex
Definition: G4Threading.hh:81
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
const G4int Z[17]
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:397
static G4EmParameters * Instance()
static G4PhysicsFreeVector * data[101]
G4double ComputeCrossSectionPerAtom(const G4ParticleDefinition *, G4double kinEnergy, G4double Z, G4double A=0.0, G4double cut=0.0, G4double emax=DBL_MAX) override
void InitialiseForElement(const G4ParticleDefinition *, G4int Z) override
void ReadData(size_t Z, const char *path=nullptr)
void Initialise(const G4ParticleDefinition *, const G4DataVector &) override
G4LivermoreGammaConversionModel(const G4ParticleDefinition *p=nullptr, const G4String &nam="LivermoreConversion")
void Initialise(const G4ParticleDefinition *, const G4DataVector &) override
G4bool Retrieve(std::ifstream &fIn, G4bool ascii=false)
G4double Value(const G4double energy, std::size_t &lastidx) const
G4ParticleChangeForGamma * GetParticleChangeForGamma()
Definition: G4VEmModel.cc:123
G4double LowEnergyLimit() const
Definition: G4VEmModel.hh:662
G4bool IsMaster() const
Definition: G4VEmModel.hh:746
G4double HighEnergyLimit() const
Definition: G4VEmModel.hh:655
void InitialiseElementSelectors(const G4ParticleDefinition *, const G4DataVector &)
Definition: G4VEmModel.cc:138
static constexpr double electron_mass_c2
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
int G4lrint(double ad)
Definition: templates.hh:134