Back to home page

EIC code displayed by LXR

 
 

    


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

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 // HadrontherapyRBE.hh;
0027 //
0028 
0029 #ifndef HadrontherapyRBE_H
0030 #define HadrontherapyRBE_H 1
0031 
0032 #include "globals.hh"
0033 #include <vector>
0034 #include <valarray>
0035 #include <map>
0036 #include "G4Pow.hh"
0037 
0038 class G4GenericMessenger;
0039 
0040 /**
0041  * @brief Main class of the RBE calculation.
0042  *
0043  * The calculation has to be explicitly enabled
0044  * (use macro command)
0045  *
0046  * Available macro commands:
0047  *
0048  *  - /rbe/calculation 0/1 : enable or disable RBE calculation
0049  *  - /rbe/verbose 0/1/2 : level of screen output detail
0050  *  - /rbe/loadLemTable [path] : read a CSV file with alphas, betas, ...
0051  *  - /rbe/cellLine [name] : select one of the cell lines from the data file
0052  *  - /rbe/doseScale [number] : factor to make the survival/RBE calculation correct
0053  *  - /rbe/accumulate 0/1 : enable or disable data summing over multiple runs
0054  *  - /rbe/reset : clear accumulated data back to 0.
0055  */
0056 class HadrontherapyRBE
0057 {
0058 public:
0059     virtual ~HadrontherapyRBE();
0060 
0061     // Make a new & get instance pointer
0062     static HadrontherapyRBE* CreateInstance(G4int nX, G4int nY, G4int nZ, G4double massOfVoxel);
0063     static HadrontherapyRBE* GetInstance();
0064 
0065     // If this is false (set with macro), nothing happens
0066     G4bool IsCalculationEnabled() const { return fCalculationEnabled; }
0067 
0068     // If this is true, dose (and alpha/beta parameters) are accumulated over multiple runs
0069     G4bool IsAccumulationEnabled() const { return fAccumulate; }
0070 
0071     // Initialization of data from a CSV file
0072     void LoadLEMTable(G4String path);
0073 
0074     // Select the cell and update the pointer
0075     void SetCellLine(G4String name);
0076 
0077     // Calculate alpha and beta for single deposition, {0,0} if not applicable
0078     std::tuple<G4double, G4double> GetHitAlphaAndBeta(G4double E, G4int Z);
0079 
0080     // Parameter setting
0081     void SetDoseScale(G4double scale);
0082     void SetCalculationEnabled(G4bool enabled);
0083     void SetAccumulationEnabled(G4bool accumulate);
0084 
0085     // Verbosity for output
0086     void SetVerboseLevel(G4int level) { fVerboseLevel = level; }
0087     G4int GetVerboseLevel() const { return fVerboseLevel; }
0088     
0089     // Alias for matrix type
0090     using array_type = std::valarray<G4double>;
0091 
0092     // Calculation
0093     void ComputeAlphaAndBeta();
0094     void ComputeRBE();
0095 
0096     // Update the class with accumulated data
0097     // (To be used from HadrontherapyRBEAccumulable)
0098     void SetAlphaNumerator(const array_type alpha);
0099     void SetBetaNumerator(const array_type beta);
0100     void SetEnergyDeposit(const array_type eDep);
0101     void SetDenominator(const array_type denom);
0102     
0103     // Accumulation variants necessary for multi-run sumation
0104     void AddAlphaNumerator(const array_type alpha);
0105     void AddBetaNumerator(const array_type beta);
0106     void AddEnergyDeposit(const array_type eDep);
0107     void AddDenominator(const array_type denom);
0108     
0109     // Clear accumulated data
0110     void Reset();
0111 
0112     // Output to text files (called at the end of run)
0113     void StoreAlphaAndBeta();
0114     void StoreRBE();
0115 
0116     // Information about voxels
0117     G4int GetNumberOfVoxelsAlongX() const { return fNumberOfVoxelsAlongX; }
0118     G4int GetNumberOfVoxelsAlongY() const { return fNumberOfVoxelsAlongY; }
0119     G4int GetNumberOfVoxelsAlongZ() const { return fNumberOfVoxelsAlongZ; }
0120 
0121     // Some basic output to the screen
0122     void PrintParameters();
0123 
0124 protected:
0125     inline G4int Index(G4int i, G4int j, G4int k) {return (i * fNumberOfVoxelsAlongY + j) * fNumberOfVoxelsAlongZ + k;}
0126 
0127     // Interpolation
0128     // G4int GetRowVecEnergy();
0129     // G4bool NearLookup(G4double E, G4double DE);
0130     // G4bool LinearLookup(G4double E, G4double DE, G4int Z);
0131     // void interpolation_onE(G4int k,G4int m, G4int indexE, G4double E, G4int Z);
0132     // G4bool interpolation_onLET1_onLET2_onE(G4int k,G4int m, G4int indexE, G4double E, G4double LET);
0133     // void InitDynamicVec(std::vector<G4double> &vecEnergy, G4int matrix_energy);
0134 
0135     // Messenger initialization
0136     void CreateMessenger();
0137 
0138 private:
0139     HadrontherapyRBE(G4int numberOfVoxelX, G4int numberOfVoxelY, G4int numberOfVoxelZ, G4double massOfVoxel);
0140 
0141     G4GenericMessenger* fMessenger;
0142     G4Pow* g4pow = G4Pow::GetInstance();
0143 
0144     static HadrontherapyRBE* instance;
0145     G4int fVerboseLevel { 1 };
0146 
0147     // Parameters for calculation
0148     G4double fAlphaX { 0.0 };
0149     G4double fBetaX { 0.0 };
0150     G4double fDoseCut { 0.0 };
0151     G4double fDoseScale { 1.0 };
0152 
0153     // Output paths (TODO: Change to analysis tools)
0154     G4String fAlphaBetaPath { "AlphaAndBeta.out" };
0155     G4String fRBEPath { "RBE.out" };
0156 
0157     // Voxelization
0158     G4int fNumberOfVoxelsAlongX, fNumberOfVoxelsAlongY, fNumberOfVoxelsAlongZ;
0159     G4int fNumberOfVoxels;
0160     G4double fMassOfVoxel;
0161 
0162     G4double* x; // TODO: Currently not used (that much)
0163 
0164     G4bool fCalculationEnabled { false };
0165     G4bool fAccumulate { false };
0166 
0167     // Matrices to be set when accumulated
0168     array_type fAlpha;
0169     array_type fBeta;
0170     array_type fDose; // Note: this is calculated from energyDeposit, massOfVoxel and doseScale
0171     
0172     array_type fAlphaNumerator;
0173     array_type fBetaNumerator;
0174     array_type fDenominator;
0175 
0176     // Matrices of calculated values
0177     array_type fLnS;
0178     array_type fSurvival;
0179     array_type fDoseX;
0180     array_type fRBE;
0181 
0182     // Available tables and associated values.
0183     using vector_type = std::map<G4int, std::vector<G4double>>;
0184     std::map<G4String, vector_type> fTablesEnergy;
0185     // std::map<G4String, vector_type> fTablesLet;
0186     std::map<G4String, vector_type> fTablesAlpha;
0187     std::map<G4String, vector_type> fTablesBeta;
0188     std::map<G4String, G4double> fTablesAlphaX;
0189     std::map<G4String, G4double> fTablesBetaX;
0190     std::map<G4String, G4double> fTablesDoseCut;
0191 
0192     // Selected tables and associated values.
0193     // (changed when the cell line is set)
0194     G4String fActiveCellLine = "";
0195     vector_type* fActiveTableEnergy { nullptr };
0196     // vector_type* fActiveTableLet { nullptr };
0197     vector_type* fActiveTableAlpha { nullptr };
0198     vector_type* fActiveTableBeta { nullptr };
0199     std::map<G4int, G4double> fMaxEnergies;
0200     std::map<G4int, G4double> fMinEnergies;
0201     G4int fMinZ;
0202     G4int fMaxZ;
0203 };
0204 #endif
0205