Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ParticleHPArbitaryTab Class Reference

#include <G4ParticleHPArbitaryTab.hh>

+ Inheritance diagram for G4ParticleHPArbitaryTab:

Public Member Functions

 G4ParticleHPArbitaryTab ()
 
 ~G4ParticleHPArbitaryTab () override
 
void Init (std::istream &theData) override
 
G4double GetFractionalProbability (G4double anEnergy) override
 
G4double Sample (G4double anEnergy) override
 
- Public Member Functions inherited from G4VParticleHPEDis
 G4VParticleHPEDis ()=default
 
virtual ~G4VParticleHPEDis ()=default
 

Detailed Description

Definition at line 46 of file G4ParticleHPArbitaryTab.hh.

Constructor & Destructor Documentation

◆ G4ParticleHPArbitaryTab()

G4ParticleHPArbitaryTab::G4ParticleHPArbitaryTab ( )
inline

Definition at line 49 of file G4ParticleHPArbitaryTab.hh.

50 {
51 theDistFunc = nullptr;
52 nDistFunc = 0;
53 }

◆ ~G4ParticleHPArbitaryTab()

G4ParticleHPArbitaryTab::~G4ParticleHPArbitaryTab ( )
inlineoverride

Definition at line 54 of file G4ParticleHPArbitaryTab.hh.

54{ delete[] theDistFunc; }

Member Function Documentation

◆ GetFractionalProbability()

G4double G4ParticleHPArbitaryTab::GetFractionalProbability ( G4double anEnergy)
inlineoverridevirtual

Implements G4VParticleHPEDis.

Definition at line 99 of file G4ParticleHPArbitaryTab.hh.

100 {
101 return theFractionalProb.GetY(anEnergy);
102 }
G4double GetY(G4double x)

◆ Init()

void G4ParticleHPArbitaryTab::Init ( std::istream & theData)
inlineoverridevirtual

Implements G4VParticleHPEDis.

Definition at line 56 of file G4ParticleHPArbitaryTab.hh.

57 {
58 std::size_t i;
59 theFractionalProb.Init(theData, CLHEP::eV);
60 theData >> nDistFunc; // = number of incoming n energy points
61 const std::size_t dsize = nDistFunc > 0 ? nDistFunc : 1;
62 theDistFunc = new G4ParticleHPVector[dsize];
63 theManager.Init(theData);
64 G4double currentEnergy;
65 for (i = 0; i < dsize; ++i) {
66 theData >> currentEnergy;
67 theDistFunc[i].SetLabel(currentEnergy * CLHEP::eV);
68 theDistFunc[i].Init(theData, CLHEP::eV);
69 theDistFunc[i].IntegrateAndNormalise();
70 //************************************************************************
71 // EMendoza:
72 // ThinOut() assumes that the data is linear-linear, what is false:
73 // theDistFunc[i].ThinOut(0.02); // @@@ optimization to be finished.
74 //************************************************************************
75 }
76
77 //************************************************************************
78 // EMendoza:
79 // Here we calculate the thresholds for the 2D sampling:
80 for (i = 0; i < dsize; ++i) {
81 G4int np = theDistFunc[i].GetVectorLength();
82 theLowThreshold[i] = theDistFunc[i].GetEnergy(0);
83 theHighThreshold[i] = theDistFunc[i].GetEnergy(np - 1);
84 for (G4int j = 0; j < np - 1; ++j) {
85 if (theDistFunc[i].GetXsec(j + 1) > 1.e-20) {
86 theLowThreshold[i] = theDistFunc[i].GetEnergy(j);
87 break;
88 }
89 }
90 for (G4int j = 1; j < np; ++j) {
91 if (theDistFunc[i].GetXsec(j - 1) > 1.e-20) {
92 theHighThreshold[i] = theDistFunc[i].GetEnergy(j);
93 }
94 }
95 }
96 //************************************************************************
97 }
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
void Init(G4int aScheme, G4int aRange)
void SetLabel(G4double aLabel)
G4double GetEnergy(G4int i) const
void Init(std::istream &aDataFile, G4int total, G4double ux=1., G4double uy=1.)
G4int GetVectorLength() const

◆ Sample()

G4double G4ParticleHPArbitaryTab::Sample ( G4double anEnergy)
overridevirtual

Implements G4VParticleHPEDis.

Definition at line 36 of file G4ParticleHPArbitaryTab.cc.

37{
38 G4int i;
39 for (i = 0; i < nDistFunc; i++) {
40 if (anEnergy < theDistFunc[i].GetLabel()) break; // that is the energy we need
41 }
42 G4int low(0), high(0);
43 if (i == nDistFunc) {
44 low = i - 2;
45 high = i - 1;
46 }
47 else if (i == 0) {
48 if (nDistFunc == 0) {
49 G4cerr << "No distribution functions to sample "
50 << "from in G4ParticleHPArbitaryTab::Sample" << G4endl;
51 throw G4HadronicException(__FILE__, __LINE__, "nDistFunc==0");
52 }
53 return theDistFunc[0].Sample();
54 }
55 else {
56 low = i - 1;
57 high = i;
58 }
59 //************************************************************************
60 // EMendoza
61 /*
62 theBuffer.Merge(theManager.GetScheme(low), anEnergy,
63 theDistFunc+low, theDistFunc+high);
64 return theBuffer.Sample();
65 */
66 //************************************************************************
67 // New way to perform the 2D sampling:
68 G4double elow = theDistFunc[low].GetLabel();
69 G4double ehigh = theDistFunc[high].GetLabel();
70 G4double rval = (anEnergy - elow) / (ehigh - elow); // rval is 0 for elow and 1 for ehigh
71 G4double eoutlow = theLowThreshold[low] + rval * (theLowThreshold[high] - theLowThreshold[low]);
72 G4double eouthigh =
73 theHighThreshold[low] + rval * (theHighThreshold[high] - theHighThreshold[low]);
74 G4double rand = G4UniformRand();
75 G4double Eout_1 = 0, Eout_2 = 0;
76 if (rval < rand) {
77 Eout_1 = theDistFunc[low].Sample();
78 Eout_2 = eoutlow
79 + (Eout_1 - theLowThreshold[low]) * (eouthigh - eoutlow)
80 / (theHighThreshold[low] - theLowThreshold[low]);
81 }
82 else {
83 Eout_1 = theDistFunc[high].Sample();
84 Eout_2 = eoutlow
85 + (Eout_1 - theLowThreshold[high]) * (eouthigh - eoutlow)
86 / (theHighThreshold[high] - theLowThreshold[high]);
87 }
88 return Eout_2;
89
90 //************************************************************************
91}
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
#define G4UniformRand()
Definition Randomize.hh:52

The documentation for this class was generated from the following files: