Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
49namespace { G4Mutex LivermoreGammaConversionModelMutex = G4MUTEX_INITIALIZER; }
50
51//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
52//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
53
54G4double G4LivermoreGammaConversionModel::lowEnergyLimit = 2.*CLHEP::electron_mass_c2;
55G4PhysicsFreeVector* G4LivermoreGammaConversionModel::data[] = {nullptr};
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) {
105 fParticleChange = GetParticleChangeForGamma();
106 }
107
108 if(IsMaster())
109 {
110 // Initialise element selector
111 InitialiseElementSelectors(particle, cuts);
112
113 // Access to elements
114 const char* path = G4FindDataDir("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 = G4FindDataDir("G4LEDATA");
147 if(datadir == nullptr)
148 {
149 G4Exception("G4LivermoreGammaConversionModel::ReadData()",
150 "em0006",FatalException,
151 "Environment variable G4LEDATA not defined");
152 return;
153 }
154 }
155
156 std::ostringstream ost;
157 if(G4EmParameters::Instance()->LivermoreDataDir() == "livermore"){
158 data[Z] = new G4PhysicsFreeVector(true);
159 ost << datadir << "/livermore/pair/pp-cs-" << Z <<".dat";
160 }else{
161 data[Z] = new G4PhysicsFreeVector();
162 ost << datadir << "/epics2017/pair/pp-cs-" << Z <<".dat";
163 }
164
165 std::ifstream fin(ost.str().c_str());
166
167 if( !fin.is_open())
168 {
170 ed << "G4LivermoreGammaConversionModel data file <" << ost.str().c_str()
171 << "> is not opened!" << G4endl;
172 G4Exception("G4LivermoreGammaConversionModel::ReadData()",
173 "em0003",FatalException,
174 ed,"G4LEDATA version should be G4EMLOW8.0 or later.");
175 return;
176 }
177 else
178 {
179
180 if(verboseLevel > 1) { G4cout << "File " << ost.str()
181 << " is opened by G4LivermoreGammaConversionModel" << G4endl;}
182
183 data[Z]->Retrieve(fin, true);
184 }
185}
186
187//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
188
190 const G4ParticleDefinition* particle,
192{
193 if (verboseLevel > 1)
194 {
195 G4cout << "G4LivermoreGammaConversionModel::ComputeCrossSectionPerAtom() Z= "
196 << Z << G4endl;
197 }
198
199 if (GammaEnergy < lowEnergyLimit) { return 0.0; }
200
201 G4double xs = 0.0;
202
203 G4int intZ = std::max(1, std::min(G4lrint(Z), maxZ));
204
205 G4PhysicsFreeVector* pv = data[intZ];
206
207 // if element was not initialised
208 // do initialisation safely for MT mode
209 if(pv == nullptr)
210 {
211 InitialiseForElement(particle, intZ);
212 pv = data[intZ];
213 if(pv == nullptr) { return xs; }
214 }
215 // x-section is taken from the table
216 xs = pv->Value(GammaEnergy);
217
218 if(verboseLevel > 0)
219 {
220 G4cout << "*** Gamma conversion xs for Z=" << Z << " at energy E(MeV)="
221 << GammaEnergy/MeV << " cs=" << xs/millibarn << " mb" << G4endl;
222 }
223 return xs;
224}
225
226//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
227
230 G4int Z)
231{
232 G4AutoLock l(&LivermoreGammaConversionModelMutex);
233 if(data[Z] == nullptr) { ReadData(Z); }
234 l.unlock();
235}
236
237//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::vector< G4Element * > G4ElementTable
const char * G4FindDataDir(const char *)
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
#define elem(i, j)
#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:403
static G4EmParameters * Instance()
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 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:124
G4double LowEnergyLimit() const
Definition: G4VEmModel.hh:641
G4bool IsMaster() const
Definition: G4VEmModel.hh:725
G4double HighEnergyLimit() const
Definition: G4VEmModel.hh:634
void InitialiseElementSelectors(const G4ParticleDefinition *, const G4DataVector &)
Definition: G4VEmModel.cc:139
int G4lrint(double ad)
Definition: templates.hh:134