G4DarkBreM  v2.1.0
Geant4 Dark Bremmstrahlung from MadGraph
g4db::ElementXsecCache Class Reference

The cache of already computed cross sections. More...

#include <ElementXsecCache.h>

Collaboration diagram for g4db::ElementXsecCache:
[legend]

Public Member Functions

 ElementXsecCache ()=default
 Default constructor. More...
 
 ElementXsecCache (std::shared_ptr< PrototypeModel > model)
 Constructor with a model to calculate the cross section.
 
G4double get (G4double energy, G4double A, G4double Z)
 Get the value of the cross section for the input variables and calculate the cross section if it wasn't calculated before. More...
 
void stream (std::ostream &o) const
 Stream the entire table into the output stream. More...
 

Private Types

typedef unsigned long int key_t
 The type for the key we use in the cache.
 

Private Member Functions

key_t computeKey (G4double energy, G4double A, G4double Z) const
 Compute a key for the cache map Generating a unique key after making the energy [MeV] an integer. More...
 

Private Attributes

std::map< key_t, G4double > the_cache_
 the actual map from cache keys to calculated cross sections
 
std::shared_ptr< PrototypeModelmodel_
 shared pointer to the model for calculating cross sections
 

Static Private Attributes

static const key_t MAX_A {1000}
 The maximum value of A.
 
static const key_t MAX_E {1500000}
 The maximum value for energy [MeV].
 

Friends

std::ostream & operator<< (std::ostream &o, const ElementXsecCache c)
 Overload the streaming operator for ease. More...
 

Detailed Description

The cache of already computed cross sections.

We make a specific class for the cache in order to keep the key encoding/decoding process in a central location.

Constructor & Destructor Documentation

◆ ElementXsecCache()

g4db::ElementXsecCache::ElementXsecCache ( )
default

Default constructor.

Does nothing interesting, but no model for calculating cross section has been set.

Member Function Documentation

◆ computeKey()

ElementXsecCache::key_t g4db::ElementXsecCache::computeKey ( G4double  energy,
G4double  A,
G4double  Z 
) const
private

Compute a key for the cache map Generating a unique key after making the energy [MeV] an integer.

The atomic mass (A) and charge (Z) are given by Geant4 as doubles as well, so I cast them to integers before computing the key.

This is what you would edit if you want a more/less find-grained cache of Xsecs. Right now, since the internal unit of energy in Geant4 is MeV, the cache is binned at the 1MeV scale.

Parameters
[in]energyEnergy of incident lepton [MeV]
[in]Aatomic mass of element [atomic mass units]
[in]Zatomic number of element [num protons]
Returns
unsigned integer cache key for these three inputs
Note
This implicitly converts the input double to a unsigned long int. Since the internal units for energy are MeV, this means the cache is binned at a 1 MeV level. The atomic inputs A and Z also undergo the implicit conversion; however, this is less of a worry since different elements are separated by at least one whole unit in A and Z.

◆ get()

G4double g4db::ElementXsecCache::get ( G4double  energy,
G4double  A,
G4double  Z 
)

Get the value of the cross section for the input variables and calculate the cross section if it wasn't calculated before.

Exceptions
std::runtime_errorif no model is available for calculating cross sections
Parameters
[in]energyEnergy of incident lepton [MeV]
[in]Aatomic mass of element [atomic mass units]
[in]Zatomic number of element [num protons]
Returns
cross section corresponding to the input parameters (including units Geant4 style)

◆ stream()

void g4db::ElementXsecCache::stream ( std::ostream &  o) const

Stream the entire table into the output stream.

Parameters
[in,out]oostream to write to

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  o,
const ElementXsecCache  c 
)
friend

Overload the streaming operator for ease.

Parameters
[in]oostream to write to
[in]ccache to write out
Returns
modified ostream

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