Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:18

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
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)) // TODO: Verify this condition
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 }