File indexing completed on 2025-01-31 09:22:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include "HadrontherapyRBEAccumulable.hh"
0027 #include "HadrontherapyRBE.hh"
0028
0029 #include <tuple>
0030 #include <G4SystemOfUnits.hh>
0031
0032 using namespace std;
0033
0034 HadrontherapyRBEAccumulable::HadrontherapyRBEAccumulable()
0035 : G4VAccumulable("RBE")
0036 {
0037
0038 }
0039
0040 void HadrontherapyRBEAccumulable::Merge(const G4VAccumulable& rhs)
0041 {
0042 if (GetVerboseLevel() > 1)
0043 {
0044 G4cout << "HadrontherapyRBEAccumulable::Merge()" << G4endl;
0045 }
0046 const HadrontherapyRBEAccumulable& other = dynamic_cast<const HadrontherapyRBEAccumulable&>(rhs);
0047 fAlphaNumerator += other.fAlphaNumerator;
0048 fDenominator += other.fDenominator;
0049 fBetaNumerator += other.fBetaNumerator;
0050 fEnergyDeposit += other.fEnergyDeposit;
0051 }
0052
0053 void HadrontherapyRBEAccumulable::Reset()
0054 {
0055 if (GetVerboseLevel() > 1)
0056 {
0057 G4cout << "HadrontherapyRBEAccumulable::Reset()" << G4endl;
0058 }
0059 if (fInitialized)
0060 {
0061 fAlphaNumerator = 0.0;
0062 fBetaNumerator = 0.0;
0063 fDenominator = 0.0;
0064 fEnergyDeposit = 0.0;
0065 }
0066 else
0067 {
0068 Initialize();
0069 }
0070 }
0071
0072 void HadrontherapyRBEAccumulable::Accumulate(G4double E, G4double energyDeposit, G4double dX, G4int Z, G4int i, G4int j, G4int k)
0073 {
0074 if (!fInitialized)
0075 {
0076 G4Exception("HadrontherapyRBEAccumulable::Accumulate", "NotInitialized", FatalException, "Accumulable not initialized. Must be a programming error.");
0077 }
0078 if (GetVerboseLevel() > 2)
0079 {
0080 G4cout << "HadrontherapyRBEAccumulable::Accumulate() in " << i << ", " << j << ", " << k << G4endl;
0081 }
0082 if (energyDeposit <= 0)
0083 {
0084 return;
0085 }
0086 size_t n = GetIndex(i, j, k);
0087 fEnergyDeposit[n] += energyDeposit;
0088
0089 if ((Z >= 1) && (dX > 0) && (E > 0))
0090 {
0091 tuple<G4double, G4double> alpha_beta = HadrontherapyRBE::GetInstance()->GetHitAlphaAndBeta(E, Z);
0092 fDenominator[n] += energyDeposit;
0093 fAlphaNumerator[n] += get<0>(alpha_beta) * energyDeposit;
0094 fBetaNumerator[n] += sqrt(get<1>(alpha_beta)) * energyDeposit;
0095 }
0096 }
0097
0098 const HadrontherapyRBEAccumulable::array_type HadrontherapyRBEAccumulable::GetEnergyDeposit() const
0099 {
0100 return fEnergyDeposit;
0101 }
0102
0103 G4int HadrontherapyRBEAccumulable::GetVerboseLevel() const
0104 {
0105 return HadrontherapyRBE::GetInstance()->GetVerboseLevel();
0106 }
0107
0108 void HadrontherapyRBEAccumulable::Initialize()
0109 {
0110 if (GetVerboseLevel() > 1)
0111 {
0112 G4cout << "HadrontherapyRBEAccumulable::Initialize(): ";
0113 }
0114 auto rbe = HadrontherapyRBE::GetInstance();
0115
0116 fVoxelsAlongX = rbe->GetNumberOfVoxelsAlongX();
0117 fVoxelsAlongY = rbe->GetNumberOfVoxelsAlongY();
0118 fVoxelsAlongZ = rbe->GetNumberOfVoxelsAlongZ();
0119 fVoxels = (size_t) (fVoxelsAlongX * fVoxelsAlongY * fVoxelsAlongZ);
0120
0121 if (GetVerboseLevel() > 1)
0122 {
0123 G4cout << fVoxels << " voxels." << G4endl;
0124 }
0125
0126 fAlphaNumerator = array_type(0.0, fVoxels);
0127 fBetaNumerator = array_type(0.0, fVoxels);
0128 fDenominator = array_type(0.0, fVoxels);
0129 fEnergyDeposit = array_type(0.0, fVoxels);
0130 fInitialized = true;
0131 }