Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:19

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 //
0027 /// \file radiobiology/src/Dose.cc
0028 /// \brief Implementation of the RadioBio::Dose class
0029 
0030 #include "Dose.hh"
0031 
0032 #include "G4SystemOfUnits.hh"
0033 
0034 #include "DetectorConstruction.hh"
0035 #include "DoseAccumulable.hh"
0036 #include "DoseMessenger.hh"
0037 #include "VoxelizedSensitiveDetector.hh"
0038 
0039 #include <fstream>
0040 
0041 namespace RadioBio
0042 {
0043 
0044 #define width 15L
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 Dose::Dose()
0049 {
0050   // Default output filename
0051   fPath = "RadioBio_Dose.out";
0052 
0053   // Create the messenger
0054   fMessenger = new DoseMessenger(this);
0055 
0056   // Initialize the class
0057   Initialize();
0058 }
0059 
0060 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0061 
0062 Dose::~Dose()
0063 {
0064   delete fMessenger;
0065 }
0066 
0067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0068 
0069 void Dose::Initialize()
0070 {
0071   if (fVerboseLevel > 0) G4cout << "Dose::Initialize() called" << G4endl;
0072 
0073   G4int VoxelNumber = VoxelizedSensitiveDetector::GetInstance()->GetTotalVoxelNumber();
0074 
0075   fEnDep.resize(VoxelNumber);
0076   fDose.resize(VoxelNumber);
0077   fInitialized = true;
0078 }
0079 
0080 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0081 
0082 void Dose::Compute()
0083 {
0084   // Skip Dose computation if calculation not enabled.
0085   if (!fCalculationEnabled) {
0086     if (fVerboseLevel > 0) {
0087       G4cout << "Dose::Compute() called but skipped as calculation not enabled" << G4endl;
0088     }
0089     return;
0090   }
0091 
0092   if (fCalculated) return;
0093 
0094   if (fVerboseLevel > 0) G4cout << "Dose::Compute() called" << G4endl;
0095 
0096   auto voxSensDet = VoxelizedSensitiveDetector::GetInstance();
0097 
0098   if (voxSensDet == nullptr)
0099     G4Exception("Dose::Compute", "VoxNotInit", FatalException,
0100                 "Calculating dose without voxelized geometry pointer!");
0101 
0102   G4double voxelMass = voxSensDet->GetVoxelMass();
0103 
0104   for (G4int v = 0; v < voxSensDet->GetTotalVoxelNumber(); v++) {
0105     if (fVerboseLevel > 1) G4cout << "Calculating Dose for voxel number " << v << G4endl;
0106 
0107     // compute total Dose
0108     fDose[v] = fEnDep[v] / voxelMass;
0109   }
0110 
0111   fCalculated = true;
0112 }
0113 
0114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0115 
0116 void Dose::Store()
0117 {
0118   // Skip Dose store if calculation not enabled.
0119   if (!fCalculationEnabled) {
0120     if (fVerboseLevel > 0) {
0121       G4cout << "Dose::Store() called but skipped as calculation not enabled" << G4endl;
0122     }
0123     return;
0124   }
0125 
0126   if (fSaved == true)
0127     G4Exception("Dose::Store", "DoseOverwrite", JustWarning,
0128                 "Overwriting Dose file. For multiple runs, change filename.");
0129 
0130   Compute();
0131 
0132   std::ofstream ofs(fPath);
0133 
0134   if (ofs.is_open()) {
0135     ofs << "x_index" << std::setw(width) << "y_index" << std::setw(width) << "z_index"
0136         << std::setw(width) << "Dose (Gy)" << G4endl;
0137 
0138     auto voxSensDet = VoxelizedSensitiveDetector::GetInstance();
0139 
0140     for (G4int i = 0; i < voxSensDet->GetVoxelNumberAlongX(); i++)
0141       for (G4int j = 0; j < voxSensDet->GetVoxelNumberAlongY(); j++)
0142         for (G4int k = 0; k < voxSensDet->GetVoxelNumberAlongZ(); k++) {
0143           G4int v = voxSensDet->GetThisVoxelNumber(i, j, k);
0144           ofs << i << std::setw(width) << j << std::setw(width) << k << std::setw(width)
0145               << fDose[v] / gray << G4endl;
0146         }
0147   }
0148   if (fVerboseLevel > 0) {
0149     G4cout << "Dose: Dose written to " << fPath << G4endl;
0150   }
0151   fSaved = true;
0152 }
0153 
0154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0155 
0156 void Dose::AddFromAccumulable(G4VAccumulable* GenAcc)
0157 {
0158   DoseAccumulable* acc = (DoseAccumulable*)GenAcc;
0159   AddEnergyDeposit(acc->GetEnDeposit());
0160   fCalculated = false;
0161 }
0162 
0163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0164 
0165 void Dose::Reset()
0166 {
0167   if (fVerboseLevel > 1) {
0168     G4cout << "Dose::Reset(): ";
0169   }
0170   fEnDep = 0.0;
0171   fDose = 0.0;
0172   fCalculated = false;
0173 }
0174 
0175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0176 
0177 void Dose::PrintParameters()
0178 {
0179   G4cout << "*******************************************" << G4endl
0180          << "****** Parameters of the class Dose *******" << G4endl
0181          << "*******************************************" << G4endl;
0182   PrintVirtualParameters();
0183 }
0184 
0185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0186 
0187 }  // namespace RadioBio