Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4CrossSectionManager.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
16#include "TG4Globals.h"
17#include "TG4RegionsManager.h"
18
19#include <G4HadronicProcessStore.hh>
20#include <G4NistManager.hh>
21#include <G4ParticleDefinition.hh>
22#include <G4ParticleTable.hh>
23
24#include <TH1.h>
25#include <TObjArray.h>
26
27// Moved after Root includes to avoid shadowed variables
28// generated from short units names
29#include <G4SystemOfUnits.hh>
30
31#include <iomanip>
32
35const G4double TG4CrossSectionManager::fgkDefaultMinKinEnergy = 0.1 * MeV;
38const G4double TG4CrossSectionManager::fgkDefaultMaxMomentum = 100 * TeV;
41const G4double TG4CrossSectionManager::fgkDefaultKinEnergy = 1 * MeV;
42
43//_____________________________________________________________________________
45 : TG4Verbose("crossSectionManager"),
46 fMessenger(this),
47 fHistograms(0),
48 fParticleName(fgkDefaultParticleName),
49 fElementName(fgkDefaultElementName),
50 fMinKinEnergy(fgkDefaultMinKinEnergy),
51 fMaxKinEnergy(fgkDefaultMaxKinEnergy),
52 fMinMomentum(fgkDefaultMinMomentum),
53 fMaxMomentum(fgkDefaultMaxMomentum),
54 fNofBinsE(fgkDefaultNofBinsE),
55 fNofBinsP(fgkDefaultNofBinsP),
56 fLabel(),
57 fKinEnergy(fgkDefaultKinEnergy),
58 fIsInitialised(false),
59 fMakeHistograms(false)
60{
62}
63
64//_____________________________________________________________________________
66{
68
69 // fHistograms->Delete();
70 delete fHistograms;
71}
72
73//
74// private methods
75//
76
77//_____________________________________________________________________________
79{
81
82 const G4ParticleDefinition* particle =
83 G4ParticleTable::GetParticleTable()->FindParticle(fParticleName);
84
85 if (!particle) {
86 TString text = "Particle \"";
87 text += fParticleName.data();
88 text += "\" not found.";
89 TG4Globals::Warning("TG4CrossSectionManager", "GetParticle", text);
90 return 0;
91 }
92
93 return particle;
94}
95
96//_____________________________________________________________________________
97const G4Element* TG4CrossSectionManager::GetElement() const
98{
100
101 const G4Element* element =
102 G4NistManager::Instance()->FindOrBuildElement(fElementName);
103
104 if (!element) {
105 TString text = "Element \"";
106 text += fElementName.data();
107 text += "\" not found.";
108 G4cout << "element:" << fElementName << G4endl;
109 TG4Globals::Warning("TG4CrossSectionManager", "GetElement", text);
110 return 0;
111 }
112
113 return element;
114}
115
116//_____________________________________________________________________________
118{
120
121 const G4ParticleDefinition* particle = GetParticle();
122
123 G4double mass = particle->GetPDGMass();
124 G4double etot = mass + fKinEnergy;
125
126 return std::sqrt(etot * etot - mass * mass);
127}
128
129//_____________________________________________________________________________
131{
133
134 if (fIsInitialised) return;
135
136 fHistograms = new TObjArray();
137
138 TString title0(fLabel.data());
139 title0 += ": ";
140 title0 += fParticleName.data();
141 title0 += " - ";
142 title0 += fElementName.data();
143 title0 += " : ";
144
145 TString title;
146 title =
147 title0 + "Elastic cross section (barn) as a functions of log10(p/GeV)";
148 fHistograms->Add(new TH1D("h1", title, fNofBinsP,
149 std::log10(fMinMomentum / GeV), std::log10(fMaxMomentum / GeV)));
150
151 title =
152 title0 + "Elastic cross section (barn) as a functions of log10(E/MeV)";
153 fHistograms->Add(new TH1D("h2", title, fNofBinsE,
154 std::log10(fMinKinEnergy / GeV), std::log10(fMaxKinEnergy / GeV)));
155
156 title =
157 title0 + "Inelastic cross section (barn) as a functions of log10(p/GeV)";
158 fHistograms->Add(new TH1D("h3", title, fNofBinsP,
159 std::log10(fMinMomentum / GeV), std::log10(fMaxMomentum / GeV)));
160
161 title =
162 title0 + "Inelastic cross section (barn) as a functions of log10(E/MeV)";
163 fHistograms->Add(new TH1D("h4", title, fNofBinsE,
164 std::log10(fMinKinEnergy / GeV), std::log10(fMaxKinEnergy / GeV)));
165
166 if (fParticleName == "neutron") {
167 title =
168 title0 + "Capture cross section (barn) as a functions of log10(E/MeV)";
169 fHistograms->Add(new TH1D("h5", title, fNofBinsE,
170 std::log10(fMinKinEnergy / GeV), std::log10(fMaxKinEnergy / GeV)));
171
172 title =
173 title0 + "Fission cross section (barn) as a functions of log10(E/MeV)";
174 fHistograms->Add(new TH1D("h6", title, fNofBinsE,
175 std::log10(fMinKinEnergy / GeV), std::log10(fMaxKinEnergy / GeV)));
176 }
177 /*
178 title = title0 + "Charge exchange cross section (barn) as a functions of
179 log10(E/MeV)"; fHistograms->Add(new TH1D("h7", title, fNofBinsE,
180 std::log10(fMinKinEnergy/GeV),
181 std::log10(fMaxKinEnergy/GeV)));
182 */
183
184 fIsInitialised = true;
185}
186
187//_____________________________________________________________________________
189{
193
195
196 if (VerboseLevel() > 0) {
197 G4cout << "TG4CrossSectionManager: Filling histograms is started."
198 << G4endl;
199 }
200
201 const G4Element* elm = GetElement();
202 const G4ParticleDefinition* particle = GetParticle();
203
204 if (VerboseLevel() > 0) {
205 G4cout << "### Fill Cross Sections for " << fParticleName << " on "
206 << fElementName << G4endl;
207 G4cout << "-------------------------------------------------------------"
208 << G4endl;
209 G4cout << " N E(MeV) Elastic(barn) Inelastic(barn)";
210 // if ( particle == neutron ) G4cout << " Capture(barn) Fission(barn)";
211 if (fParticleName == "neutron")
212 G4cout << " Capture(barn) Fission(barn)";
213 G4cout << " ChargeExchange(barn)" << G4endl;
214 G4cout << "-------------------------------------------------------------"
215 << G4endl;
216 }
217
218 G4int prec = G4cout.precision();
219 G4cout.precision(7);
220
221 G4HadronicProcessStore* store = G4HadronicProcessStore::Instance();
222 G4double mass = particle->GetPDGMass();
223
224 // Build histograms
225
226 G4double p1 = std::log10(fMinMomentum / GeV);
227 G4double p2 = std::log10(fMaxMomentum / GeV);
228 G4double e1 = std::log10(fMinKinEnergy / MeV);
229 G4double e2 = std::log10(fMaxKinEnergy / MeV);
230 G4double de = (e2 - e1) / G4double(fNofBinsE);
231 G4double dp = (p2 - p1) / G4double(fNofBinsP);
232
233 G4double x = e1 - de * 0.5;
234 G4double e, p, xs;
235 for (G4int i = 0; i < fNofBinsE; ++i) {
236 x += de;
237 e = std::pow(10., x) * MeV;
238
239 if (VerboseLevel() > 0) {
240 G4cout << std::setw(5) << i << std::setw(12) << e;
241 }
242
243 xs = store->GetElasticCrossSectionPerAtom(particle, e, elm);
244 if (VerboseLevel() > 0) {
245 G4cout << std::setw(14) << xs / barn;
246 }
247 ((TH1D*)fHistograms->At(1))->Fill(x, xs / barn);
248
249 xs = store->GetInelasticCrossSectionPerAtom(particle, e, elm);
250 if (VerboseLevel() > 0) {
251 G4cout << " " << std::setw(17) << xs / barn;
252 }
253 ((TH1D*)fHistograms->At(3))->Fill(x, xs / barn);
254
255 // if ( particle == neutron ) {
256 if (fParticleName == "neutron") {
257 xs = store->GetCaptureCrossSectionPerAtom(particle, e, elm);
258 if (VerboseLevel() > 0) {
259 G4cout << " " << std::setw(17) << xs / barn;
260 }
261 ((TH1D*)fHistograms->At(4))->Fill(x, xs / barn);
262
263 xs = store->GetFissionCrossSectionPerAtom(particle, e, elm);
264 if (VerboseLevel() > 0) {
265 G4cout << " " << std::setw(17) << xs / barn;
266 }
267 ((TH1D*)fHistograms->At(5))->Fill(x, xs / barn);
268 }
269
270 xs = store->GetChargeExchangeCrossSectionPerAtom(particle, e, elm);
271 if (VerboseLevel() > 0) {
272 G4cout << " " << std::setw(17) << xs / barn;
273 }
274 //((TH1D*)fHistograms->At(6))->Fill(x, xs/barn);
275
276 if (VerboseLevel() > 0) {
277 G4cout << " " << x << G4endl;
278 }
279 }
280
281 x = p1 - dp * 0.5;
282 for (G4int i = 0; i < fNofBinsP; ++i) {
283 x += dp;
284 p = std::pow(10., x) * GeV;
285 e = std::sqrt(p * p + mass * mass) - mass;
286 xs = store->GetElasticCrossSectionPerAtom(particle, e, elm);
287 ((TH1D*)fHistograms->At(0))->Fill(x, xs / barn);
288 xs = store->GetInelasticCrossSectionPerAtom(particle, e, elm);
289 ((TH1D*)fHistograms->At(2))->Fill(x, xs / barn);
290 }
291 if (VerboseLevel() > 0) {
292 G4cout << "---------------------------------------------------------"
293 << G4endl;
294 }
295 G4cout.precision(prec);
296 // fHistograms->Write();
297}
298
299//
300// public methods
301//
302
303//_____________________________________________________________________________
305{
309
312
313 return fHistograms;
314}
315
316//_____________________________________________________________________________
318{
321
322 if (type == kCapture || type == kFission) {
323 if (fParticleName != "neutron") return 0;
324 }
325
326 const G4Element* elm = GetElement();
327 const G4ParticleDefinition* particle = GetParticle();
328
329 G4HadronicProcessStore* store = G4HadronicProcessStore::Instance();
330 switch (type) {
331 case kElastic:
332 return store->GetElasticCrossSectionPerAtom(particle, fKinEnergy, elm);
333 case kInelastic:
334 return store->GetInelasticCrossSectionPerAtom(particle, fKinEnergy, elm);
335 case kCapture:
336 return store->GetCaptureCrossSectionPerAtom(particle, fKinEnergy, elm);
337 case kFission:
338 return store->GetFissionCrossSectionPerAtom(particle, fKinEnergy, elm);
339 case kChargeExchange:
340 return store->GetChargeExchangeCrossSectionPerAtom(
341 particle, fKinEnergy, elm);
342 default:
343 return 0;
344 }
345}
346
347//_____________________________________________________________________________
349{
352
353 G4cout << G4endl << "For \"" << fParticleName << " : " << fElementName
354 << "\" "
355 << " momentum: " << GetMomentum() / GeV << " GeV"
356 << " kinEnergy: " << fKinEnergy / GeV << " GeV" << G4endl;
357
358 for (G4int i = 0; i < kNoCrossSectionType; ++i) {
359 if ((i == kCapture || i == kFission) && fParticleName != "neutron")
360 continue;
361 G4cout << " " << std::setw(15) << std::left << TG4CrossSectionTypeName(i)
362 << " cross section: "
363 << GetCrossSection(GetCrossSectionType(i)) / barn << " barn"
364 << G4endl;
365 }
366}
367
368//_____________________________________________________________________________
370{
373
374 G4cout << "For \"" << fParticleName << " : " << fElementName << "\" "
375 << " momentum: " << GetMomentum() / GeV << " GeV"
376 << " kinEnergy: " << fKinEnergy / GeV << " GeV" << G4endl;
377 G4cout << " " << TG4CrossSectionTypeName(type)
378 << " cross section: " << GetCrossSection(type) / barn << " barn"
379 << G4endl;
380}
381
382//_____________________________________________________________________________
384{
387
388 const G4ParticleDefinition* particle = GetParticle();
389
390 G4double mass = particle->GetPDGMass();
391 fKinEnergy = std::sqrt(momentum * momentum + mass * mass) - mass;
392}
Definition of the TG4CrossSectionManager class.
G4String TG4CrossSectionTypeName(G4int type)
Return name for given cross section type.
TG4CrossSectionType GetCrossSectionType(G4int type)
Convert G4int to TG4CrossSectionType (for loops)
Definition of the TG4Globals class and basic container types.
Definition of the TG4RegionsManager class.
G4double GetCrossSection(TG4CrossSectionType type) const
G4String fLabel
the histogram label
G4String fParticleName
particle name
static const G4double fgkDefaultMaxMomentum
default maximum momentum
void PrintCrossSection(TG4CrossSectionType type) const
G4double fMaxMomentum
maximum momentum (histogram range)
G4double fMinMomentum
minimum momentum (histogram range)
G4int fNofBinsE
number of bins in kinetic energy
static const G4String fgkDefaultParticleName
default particle name
static const G4int fgkDefaultNofBinsE
defualt number of bins in energy
static const G4String fgkDefaultElementName
default element name
G4String fElementName
element name
G4bool fIsInitialised
info if histograms are created
static const G4int fgkDefaultNofBinsP
defualt number of bins in momentum
G4double fMinKinEnergy
minimum kinetic energy (histogram range)
TObjArray * fHistograms
array of histograms
static const G4double fgkDefaultMinMomentum
default minimum momentum
const G4Element * GetElement() const
static const G4double fgkDefaultMinKinEnergy
default minimum kinetic energy
const G4ParticleDefinition * GetParticle() const
static const G4double fgkDefaultMaxKinEnergy
default maximum kinetic energy
G4double fMaxKinEnergy
maximum kinetic energy( histogram range)
G4int fNofBinsP
number of bins in momentum
G4double fKinEnergy
current kinetic energy
static const G4double fgkDefaultKinEnergy
defualt kinetic energy
static void Warning(const TString &className, const TString &methodName, const TString &text)
Base class for defining the verbose level and a common messenger.
Definition TG4Verbose.h:36
virtual G4int VerboseLevel() const
Definition TG4Verbose.h:78
TG4CrossSectionType
Enumeration for cross section types.
@ kNoCrossSectionType
no cross section type
@ kCapture
capture cross section
@ kElastic
elastic cross section
@ kFission
fission cross section
@ kInelastic
inelastic cross section
@ kChargeExchange
charge exchane cross section