Geant4  10.00.p01
HadrontherapyMatrix.hh
Go to the documentation of this file.
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 // This is the *BASIC* version of Hadrontherapy, a Geant4-based application
27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
28 //
29 // Visit the Hadrontherapy web site (http://www.lns.infn.it/link/Hadrontherapy) to request
30 // the *COMPLETE* version of this program, together with its documentation;
31 // Hadrontherapy (both basic and full version) are supported by the Italian INFN
32 // Institute in the framework of the MC-INFN Group
33 //
34 
35 #ifndef HadrontherapyMatrix_H
36 #define HadrontherapyMatrix_H 1
37 #include <G4ParticleDefinition.hh>
38 #include "globals.hh"
39 #include <vector>
40 #include <fstream>
41 
42 // The information: energy deposit and position in the phantom
43 // is stored in a matrix
44 
45 // type struct useful to store nucludes data
46 struct ion
47 {
48  G4bool isPrimary; // true if particle is primary
49  G4int PDGencoding; // Particle data group id for the particle
50  //G4String extName; // AZ[excitation energy]: like He3[1277.4], He4[0.0], Li7[231.4], ...
51  G4String name; // simple name without excitation energy: He3, He4, Li7, ...
52  std::string::size_type len; // name length
53  G4int Z; // atomic number
54  G4int A; // mass number
55  G4double *dose; // pointer to dose matrix
56  unsigned int *fluence; // pointer to fluence matrix
57  //friend bool operator<(const ion& a, const ion& b) {return (a.Z == b.Z) ? b.A < a.A : b.Z < a.Z ;}
58  G4bool operator<(const ion& a) const{return (this->Z == a.Z) ? this-> A < a.A : this->Z < a.Z ;}
59 };
60 
62 {
63 private:
67  G4double massOfVoxel); //< this is supposed to be a singleton
68 
69 
70 public:
71 
73  // Get object instance only
75  // Make & Get instance
76  static HadrontherapyMatrix* GetInstance(G4int nX, G4int nY, G4int nZ, G4double mass);
77 
78  static G4bool secondary;
79  // Full list of generated nuclides
80  void PrintNuclides();
81  // Hit array marker (useful to avoid multiple counts of fluence)
82  void ClearHitTrack();
83  G4int* GetHitTrack(G4int i, G4int j, G4int k);
84 
85  // All the elements of the matrix are initialised to zero
86  void Initialize();
87  void Clear();
88  // Fill DOSE/fluence matrix for particle:
89  // if fluence parameter is true then fluence at voxel (i, j, k) is increased
90  // else energyDeposit fill the dose matrix for voxel (i,j,k)
91  G4bool Fill(G4int, G4ParticleDefinition* particleDef, G4int i, G4int j, G4int k, G4double energyDeposit, G4bool fluence=false);
92 
93  // Fill TOTAL DOSE matrix for primary particles only
94  void Fill(G4int i, G4int j, G4int k, G4double energyDeposit);
95  // The matrix is filled with the energy deposit
96  // in the element corresponding to the voxel of the phantom where
97  // the energy deposit was registered
98 
99  // Store the information of the matrix in a ntuple and in
100  // a 1D Histogram
101  void TotalEnergyDeposit();
102 
103  // Store single matrix data to filename
104  void StoreMatrix(G4String file, void* data,size_t psize);
105  // Store all fluence data to filenames
106  void StoreFluenceData();
107  // Store all dose data to filenames
108  void StoreDoseData();
109 
110  // Store all data (except the total dose) to ONE filename
112 
113 #ifdef G4ANALYSIS_USE_ROOT
114  void StoreDoseFluenceRoot();
115 #endif
116 
117  inline G4int Index(G4int i, G4int j, G4int k) { return (i * numberOfVoxelAlongY + j) * numberOfVoxelAlongZ + k; }
118  // Get a unique index from a three dimensional one
119 
120  G4double * GetMatrix(){return matrix;}
121 
122  G4int GetNvoxel(){return numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ;}
123  // Total number of voxels read only access
127 private:
128 
134 
138  std::ofstream ofs;
139 
140  // Dose&fluence data store
141  std::vector <ion> ionStore;
142  // want secondary particles?
144 };
145 #endif
146 
std::string::size_type len
G4String name
G4bool operator<(const ion &a) const
G4double * dose
G4int Index(G4int i, G4int j, G4int k)
void StoreDoseFluenceAscii(G4String filename="")
G4double a
Definition: TRTMaterials.hh:39
int G4int
Definition: G4Types.hh:78
static HadrontherapyMatrix * GetInstance()
void StoreMatrix(G4String file, void *data, size_t psize)
unsigned int * fluence
bool G4bool
Definition: G4Types.hh:79
G4int * GetHitTrack(G4int i, G4int j, G4int k)
G4bool Fill(G4int, G4ParticleDefinition *particleDef, G4int i, G4int j, G4int k, G4double energyDeposit, G4bool fluence=false)
G4int PDGencoding
HadrontherapyMatrix(G4int numberOfVoxelAlongX, G4int numberOfVoxelAlongY, G4int numberOfVoxelAlongZ, G4double massOfVoxel)
static HadrontherapyMatrix * instance
double G4double
Definition: G4Types.hh:76
G4bool isPrimary
std::vector< ion > ionStore