Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // HadrontherapyRBE.hh; 27 // 28 29 #ifndef HadrontherapyRBE_H 30 #define HadrontherapyRBE_H 1 31 32 #include "globals.hh" 33 #include <vector> 34 #include <valarray> 35 #include <map> 36 #include "G4Pow.hh" 37 38 class G4GenericMessenger; 39 40 /** 41 * @brief Main class of the RBE calculation. 42 * 43 * The calculation has to be explicitly enabled 44 * (use macro command) 45 * 46 * Available macro commands: 47 * 48 * - /rbe/calculation 0/1 : enable or disable RBE calculation 49 * - /rbe/verbose 0/1/2 : level of screen output detail 50 * - /rbe/loadLemTable [path] : read a CSV file with alphas, betas, ... 51 * - /rbe/cellLine [name] : select one of the cell lines from the data file 52 * - /rbe/doseScale [number] : factor to make the survival/RBE calculation correct 53 * - /rbe/accumulate 0/1 : enable or disable data summing over multiple runs 54 * - /rbe/reset : clear accumulated data back to 0. 55 */ 56 class HadrontherapyRBE 57 { 58 public: 59 virtual ~HadrontherapyRBE(); 60 61 // Make a new & get instance pointer 62 static HadrontherapyRBE* CreateInstance(G4int nX, G4int nY, G4int nZ, G4double massOfVoxel); 63 static HadrontherapyRBE* GetInstance(); 64 65 // If this is false (set with macro), nothing happens 66 G4bool IsCalculationEnabled() const { return fCalculationEnabled; } 67 68 // If this is true, dose (and alpha/beta parameters) are accumulated over multiple runs 69 G4bool IsAccumulationEnabled() const { return fAccumulate; } 70 71 // Initialization of data from a CSV file 72 void LoadLEMTable(G4String path); 73 74 // Select the cell and update the pointer 75 void SetCellLine(G4String name); 76 77 // Calculate alpha and beta for single deposition, {0,0} if not applicable 78 std::tuple<G4double, G4double> GetHitAlphaAndBeta(G4double E, G4int Z); 79 80 // Parameter setting 81 void SetDoseScale(G4double scale); 82 void SetCalculationEnabled(G4bool enabled); 83 void SetAccumulationEnabled(G4bool accumulate); 84 85 // Verbosity for output 86 void SetVerboseLevel(G4int level) { fVerboseLevel = level; } 87 G4int GetVerboseLevel() const { return fVerboseLevel; } 88 89 // Alias for matrix type 90 using array_type = std::valarray<G4double>; 91 92 // Calculation 93 void ComputeAlphaAndBeta(); 94 void ComputeRBE(); 95 96 // Update the class with accumulated data 97 // (To be used from HadrontherapyRBEAccumulable) 98 void SetAlphaNumerator(const array_type alpha); 99 void SetBetaNumerator(const array_type beta); 100 void SetEnergyDeposit(const array_type eDep); 101 void SetDenominator(const array_type denom); 102 103 // Accumulation variants necessary for multi-run sumation 104 void AddAlphaNumerator(const array_type alpha); 105 void AddBetaNumerator(const array_type beta); 106 void AddEnergyDeposit(const array_type eDep); 107 void AddDenominator(const array_type denom); 108 109 // Clear accumulated data 110 void Reset(); 111 112 // Output to text files (called at the end of run) 113 void StoreAlphaAndBeta(); 114 void StoreRBE(); 115 116 // Information about voxels 117 G4int GetNumberOfVoxelsAlongX() const { return fNumberOfVoxelsAlongX; } 118 G4int GetNumberOfVoxelsAlongY() const { return fNumberOfVoxelsAlongY; } 119 G4int GetNumberOfVoxelsAlongZ() const { return fNumberOfVoxelsAlongZ; } 120 121 // Some basic output to the screen 122 void PrintParameters(); 123 124 protected: 125 inline G4int Index(G4int i, G4int j, G4int k) {return (i * fNumberOfVoxelsAlongY + j) * fNumberOfVoxelsAlongZ + k;} 126 127 // Interpolation 128 // G4int GetRowVecEnergy(); 129 // G4bool NearLookup(G4double E, G4double DE); 130 // G4bool LinearLookup(G4double E, G4double DE, G4int Z); 131 // void interpolation_onE(G4int k,G4int m, G4int indexE, G4double E, G4int Z); 132 // G4bool interpolation_onLET1_onLET2_onE(G4int k,G4int m, G4int indexE, G4double E, G4double LET); 133 // void InitDynamicVec(std::vector<G4double> &vecEnergy, G4int matrix_energy); 134 135 // Messenger initialization 136 void CreateMessenger(); 137 138 private: 139 HadrontherapyRBE(G4int numberOfVoxelX, G4int numberOfVoxelY, G4int numberOfVoxelZ, G4double massOfVoxel); 140 141 G4GenericMessenger* fMessenger; 142 G4Pow* g4pow = G4Pow::GetInstance(); 143 144 static HadrontherapyRBE* instance; 145 G4int fVerboseLevel { 1 }; 146 147 // Parameters for calculation 148 G4double fAlphaX { 0.0 }; 149 G4double fBetaX { 0.0 }; 150 G4double fDoseCut { 0.0 }; 151 G4double fDoseScale { 1.0 }; 152 153 // Output paths (TODO: Change to analysis tools) 154 G4String fAlphaBetaPath { "AlphaAndBeta.out" }; 155 G4String fRBEPath { "RBE.out" }; 156 157 // Voxelization 158 G4int fNumberOfVoxelsAlongX, fNumberOfVoxelsAlongY, fNumberOfVoxelsAlongZ; 159 G4int fNumberOfVoxels; 160 G4double fMassOfVoxel; 161 162 G4double* x; // TODO: Currently not used (that much) 163 164 G4bool fCalculationEnabled { false }; 165 G4bool fAccumulate { false }; 166 167 // Matrices to be set when accumulated 168 array_type fAlpha; 169 array_type fBeta; 170 array_type fDose; // Note: this is calculated from energyDeposit, massOfVoxel and doseScale 171 172 array_type fAlphaNumerator; 173 array_type fBetaNumerator; 174 array_type fDenominator; 175 176 // Matrices of calculated values 177 array_type fLnS; 178 array_type fSurvival; 179 array_type fDoseX; 180 array_type fRBE; 181 182 // Available tables and associated values. 183 using vector_type = std::map<G4int, std::vector<G4double>>; 184 std::map<G4String, vector_type> fTablesEnergy; 185 // std::map<G4String, vector_type> fTablesLet; 186 std::map<G4String, vector_type> fTablesAlpha; 187 std::map<G4String, vector_type> fTablesBeta; 188 std::map<G4String, G4double> fTablesAlphaX; 189 std::map<G4String, G4double> fTablesBetaX; 190 std::map<G4String, G4double> fTablesDoseCut; 191 192 // Selected tables and associated values. 193 // (changed when the cell line is set) 194 G4String fActiveCellLine = ""; 195 vector_type* fActiveTableEnergy { nullptr }; 196 // vector_type* fActiveTableLet { nullptr }; 197 vector_type* fActiveTableAlpha { nullptr }; 198 vector_type* fActiveTableBeta { nullptr }; 199 std::map<G4int, G4double> fMaxEnergies; 200 std::map<G4int, G4double> fMinEnergies; 201 G4int fMinZ; 202 G4int fMaxZ; 203 }; 204 #endif 205 206