Geant4 10.7.0
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 "G4EmParameters.hh"
42#include "G4PhysicsLogVector.hh"
45#include "G4SystemOfUnits.hh"
46#include "G4Exp.hh"
47
48//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
49//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
50
51G4double G4LivermoreGammaConversionModel::lowEnergyLimit = 2.*CLHEP::electron_mass_c2;
52G4int G4LivermoreGammaConversionModel::verboseLevel = 0;
53constexpr G4int G4LivermoreGammaConversionModel::maxZ;
54G4LPhysicsFreeVector* G4LivermoreGammaConversionModel::data[] = {nullptr};
55
57(const G4ParticleDefinition* p, const G4String& nam)
58: G4PairProductionRelModel(p,nam),fParticleChange(nullptr)
59{
60 // Verbosity scale for debugging purposes:
61 // 0 = nothing
62 // 1 = calculation of cross sections, file openings...
63 // 2 = entering in methods
64
65 if(verboseLevel > 0)
66 {
67 G4cout << "G4LivermoreGammaConversionModel is constructed " << G4endl;
68 }
69}
70
71//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
72
74{
75 if(IsMaster()) {
76 for(G4int i=0; i<maxZ; ++i) {
77 if(data[i]) {
78 delete data[i];
79 data[i] = nullptr;
80 }
81 }
82 }
83}
84
85//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
86
88 const G4ParticleDefinition* particle,
89 const G4DataVector& cuts)
91 if (verboseLevel > 1)
92 {
93 G4cout << "Calling Initialise() of G4LivermoreGammaConversionModel."
94 << G4endl
95 << "Energy range: "
96 << LowEnergyLimit() / MeV << " MeV - "
97 << HighEnergyLimit() / GeV << " GeV isMater: " << IsMaster()
98 << G4endl;
99 }
100
101 if(!fParticleChange) {
102 fParticleChange = GetParticleChangeForGamma();
103 }
104
105 if(IsMaster())
106 {
107 // Initialise element selector
108 InitialiseElementSelectors(particle, cuts);
109
110 // Access to elements
111 char* path = std::getenv("G4LEDATA");
112 G4ProductionCutsTable* theCoupleTable =
114
115 G4int numOfCouples = theCoupleTable->GetTableSize();
116
117 for(G4int i=0; i<numOfCouples; ++i)
118 {
119 const G4MaterialCutsCouple* couple = theCoupleTable->GetMaterialCutsCouple(i);
120 SetCurrentCouple(couple);
121 const G4Material* mat = couple->GetMaterial();
122 const G4ElementVector* theElementVector = mat->GetElementVector();
123 G4int nelm = mat->GetNumberOfElements();
124
125 for (G4int j=0; j<nelm; ++j)
126 {
127 G4int Z = std::min((*theElementVector)[j]->GetZasInt(), maxZ);
128 if(!data[Z]) { ReadData(Z, path); }
129 }
130 }
131 }
132}
133
134
135//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
136
137void G4LivermoreGammaConversionModel::ReadData(size_t Z, const char* path)
138{
139 if (verboseLevel > 1)
140 {
141 G4cout << "Calling ReadData() of G4LivermoreGammaConversionModel"
142 << G4endl;
143 }
144
145 if(data[Z]) { return; }
146
147 const char* datadir = path;
148
149 if(!datadir)
150 {
151 datadir = std::getenv("G4LEDATA");
152 if(!datadir)
153 {
154 G4Exception("G4LivermoreGammaConversionModel::ReadData()",
155 "em0006",FatalException,
156 "Environment variable G4LEDATA not defined");
157 return;
158 }
159 }
160 data[Z] = new G4LPhysicsFreeVector();
161 std::ostringstream ost;
162 ost << datadir << "/epics2017/pair/pp-cs-" << Z <<".dat";
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 // Activation of linear interpolation
184 data[Z] ->SetSpline(false); // EPICS2017 has more points -> linear is fine
185}
186
187//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
188
190 const G4ParticleDefinition* particle,
191 G4double GammaEnergy, G4double Z, G4double, G4double, G4double)
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 G4LPhysicsFreeVector* pv = data[intZ];
206
207 // if element was not initialised
208 // do initialisation safely for MT mode
209 if(!pv)
210 {
211 InitialiseForElement(particle, intZ);
212 pv = data[intZ];
213 if(!pv) { 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
224 return xs;
225
226}
227
228//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
229#include "G4AutoLock.hh"
230namespace { G4Mutex LivermoreGammaConversionModelMutex = G4MUTEX_INITIALIZER; }
231
233 const G4ParticleDefinition*,
234 G4int Z)
235{
236 G4AutoLock l(&LivermoreGammaConversionModelMutex);
237 // G4cout << "G4LivermoreGammaConversionModel::InitialiseForElement Z= "
238 // << Z << G4endl;
239 if(!data[Z]) { ReadData(Z); }
240 l.unlock();
241}
242
243//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::vector< G4Element * > G4ElementVector
@ 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
#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
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
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")
const G4Material * GetMaterial() const
const G4ElementVector * GetElementVector() const
Definition: G4Material.hh:188
size_t GetNumberOfElements() const
Definition: G4Material.hh:184
virtual void Initialise(const G4ParticleDefinition *, const G4DataVector &) override
G4double Value(G4double theEnergy, std::size_t &lastidx) const
virtual G4bool Retrieve(std::ifstream &fIn, G4bool ascii=false)
void SetSpline(G4bool)
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
std::size_t GetTableSize() const
static G4ProductionCutsTable * GetProductionCutsTable()
G4ParticleChangeForGamma * GetParticleChangeForGamma()
Definition: G4VEmModel.cc:133
G4double LowEnergyLimit() const
Definition: G4VEmModel.hh:652
G4bool IsMaster() const
Definition: G4VEmModel.hh:736
void SetCurrentCouple(const G4MaterialCutsCouple *)
Definition: G4VEmModel.hh:465
G4double HighEnergyLimit() const
Definition: G4VEmModel.hh:645
void InitialiseElementSelectors(const G4ParticleDefinition *, const G4DataVector &)
Definition: G4VEmModel.cc:148
int G4lrint(double ad)
Definition: templates.hh:134