20#include "BDSException.hh"
21#include "BDSHistBinMapper.hh"
22#include "BDSScorerConversionLoader.hh"
23#include "BDSPSCellFluxScaledPerParticle3D.hh"
24#include "BDSUtilities.hh"
27#include "G4PhysicsVector.hh"
28#include "G4SystemOfUnits.hh"
30#include "G4VPhysicalVolume.hh"
31#include "G4VPVParameterisation.hh"
38#include "src-external/gzstream/gzstream.h"
41BDSPSCellFluxScaledPerParticle3D::BDSPSCellFluxScaledPerParticle3D(
const G4String& scorerName,
43 const G4String& pathname,
44 const G4String& unitIn,
54 if (filePath.back() !=
'/')
57 const std::map<std::string, G4int> files = {{
"protons.dat", 2212},
58 {
"neutrons.dat", 2112},
60 {
"electrons.dat", 11},
61 {
"positrons.dat", -11}};
63 G4cout <<
"Scorer \"" <<
GetName() <<
"\" - adding conversionFiles:" << G4endl;
65 for (
const auto& filePDG : files)
67 G4String uncompressedFile = filePath + filePDG.first;
68 G4String compressedFile = filePath + filePDG.first+
".gz";
71 conversionFactors[filePDG.second] = loader.
Load(uncompressedFile);
72 G4cout <<
"Adding: " << uncompressedFile << G4endl;
78 conversionFactors[filePDG.second] = loaderC.
Load(compressedFile);
79 G4cout <<
"Adding: " << compressedFile << G4endl;
81 throw BDSException(__METHOD_NAME__,
"Compressed file loading - but BDSIM not compiled with ZLIB.");
85 if (conversionFactors.empty())
87 G4String message =
"no conversion files for scorer \"" + scorerName +
"\" found. Please specify one of:\n";
88 for (
const auto &kv : files)
89 {message += kv.first +
"\n";}
90 message +=
"In the specified directory \"" + pathname +
"\"\n";
91 message +=
"Would result in a factor of 0 for all particles and all energies.";
96BDSPSCellFluxScaledPerParticle3D::~BDSPSCellFluxScaledPerParticle3D()
98 for (
auto cf : conversionFactors)
102G4double BDSPSCellFluxScaledPerParticle3D::GetConversionFactor(G4int particleID, G4double kineticEnergy)
const
104 auto search = conversionFactors.find(particleID);
105 if (search != conversionFactors.end())
106 {
return search->second->Value(kineticEnergy);}
General exception with possible name of object and message.
Mapping from axis indices to 1D index.
Primitive scorer for cell flux in a 3D mesh with a conversion factor.
Loader for scoring conversion tables as function of energy.
G4PhysicsVector * Load(const G4String &fileName, G4bool silent=false)
Load the file.
G4String GetFullPath(G4String filename, bool excludeNameFromPath=false, bool useCWDForPrefix=false)
G4bool FileExists(const G4String &filename)
Checks if filename exists.
const char * GetName(int)
Name of element.