20#include "BDSException.hh"
21#include "BDSHistBinMapper.hh"
22#include "BDSScorerConversionLoader.hh"
23#include "BDSPSCellFluxScaled3D.hh"
24#include "BDSUtilities.hh"
26#include "G4PhysicsVector.hh"
28#include "G4SystemOfUnits.hh"
31#include "G4VPhysicalVolume.hh"
32#include "G4VPVParameterisation.hh"
33#include "G4UnitsTable.hh"
39#include "src-external/gzstream/gzstream.h"
44 const G4String& unitIn,
51 G4VPrimitiveScorer(scorerName),
54 fDepthi(depi),fDepthj(depj),fDepthk(depk),
55 conversionFactor(nullptr),
59 CheckAndSetUnit(unitIn,
"Per Unit Surface");
67 const G4String& filename,
68 const G4String& unitIn,
78 {
throw BDSException(__METHOD_NAME__,
"no conversionFactorFile provided for \"" + scorerName +
"\" - required");}
81 if (filePath.rfind(
"gz") != std::string::npos)
87 throw BDSException(__METHOD_NAME__,
"Compressed file loading - but BDSIM not compiled with ZLIB.");
97BDSPSCellFluxScaled3D::~BDSPSCellFluxScaled3D()
102G4bool BDSPSCellFluxScaled3D::ProcessHits(G4Step* aStep, G4TouchableHistory*)
104 G4double stepLength = aStep->GetStepLength();
105 G4double radiationQuantity = 0;
110 const G4VTouchable* touchable = aStep->GetPreStepPoint()->GetTouchable();
111 G4VSolid* solid = touchable->GetSolid();
112 G4double cubicVolume = 1;
113 auto search = volumeCache.find(solid);
114 if (search == volumeCache.end())
117 cubicVolume = solid->GetCubicVolume();
118 volumeCache[solid] = cubicVolume;
121 {cubicVolume = search->second;}
123 G4double cellFlux = stepLength / cubicVolume;
124 cellFlux *= aStep->GetPreStepPoint()->GetWeight();
126 G4double kineticEnergy = aStep->GetPreStepPoint()->GetKineticEnergy();
127 G4double factor = GetConversionFactor(aStep->GetTrack()->GetDefinition()->GetPDGEncoding(), kineticEnergy);
128 radiationQuantity = cellFlux * factor;
129 G4int index = GetIndex(aStep);
131 evtMap3D->add(index, radiationQuantity);
135G4double BDSPSCellFluxScaled3D::GetConversionFactor(G4int ,
136 G4double kineticEnergy)
const
141void BDSPSCellFluxScaled3D::Initialize(G4HCofThisEvent* HCE)
146 {
HCID3D = GetCollectionID(0);}
150void BDSPSCellFluxScaled3D::EndOfEvent(G4HCofThisEvent* )
153void BDSPSCellFluxScaled3D::clear()
158G4int BDSPSCellFluxScaled3D::GetIndex(G4Step* aStep)
160 const G4VTouchable* touchable = aStep->GetPreStepPoint()->GetTouchable();
161 G4int i = touchable->GetReplicaNumber(
fDepthi);
162 G4int j = touchable->GetReplicaNumber(
fDepthj);
163 G4int k = touchable->GetReplicaNumber(
fDepthk);
165 if (i<0 || j<0 || k<0)
167 G4ExceptionDescription ED;
168 ED <<
"GetReplicaNumber is negative" << G4endl
169 <<
"touchable->GetReplicaNumber(fDepthi) returns i,j,k = "
170 << i <<
"," << j <<
"," << k <<
" for volume "
171 << touchable->GetVolume(
fDepthi)->GetName() <<
","
172 << touchable->GetVolume(
fDepthj)->GetName() <<
","
173 << touchable->GetVolume(
fDepthk)->GetName() << G4endl;
174 G4Exception(
"BDSPSCellFluxScaled3D::GetIndex",
"DetPS0006",JustWarning,ED);
177 G4int globalIndex =
mapper->GlobalFromIJKLIndex(i,j,k);
184 new G4UnitDefinition(
"percentimeter2",
"percm2",
"Per Unit Surface", (1./CLHEP::cm2));
185 new G4UnitDefinition(
"permillimeter2",
"permm2",
"Per Unit Surface", (1./CLHEP::mm2));
186 new G4UnitDefinition(
"permeter2",
"perm2",
"Per Unit Surface", (1./CLHEP::m2));
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.
G4THitsMap< G4double > * evtMap3D
Hits map.
const BDSHistBinMapper * mapper
Mapping from coordinate systems in mesh to global replica number.
G4int fDepthk
Depth in replica to look for each dimension.
G4PhysicsVector * conversionFactor
Conversion factor interpolator object.
G4int fDepthi
Depth in replica to look for each dimension.
G4int fDepthj
Depth in replica to look for each dimension.
void DefineUnitAndCategory() const
Define units -> taken from G4PSCellFlux.
G4int HCID3D
Collection ID.
BDSPSCellFluxScaled3D(const G4String &scorerName, const BDSHistBinMapper *mapperIn, const G4String &unitIn="percm2", G4int ni=1, G4int nj=1, G4int nk=1, G4int depi=2, G4int depj=1, G4int depk=0)
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 IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())
const char * GetName(int)
Name of element.