Geant4  10.02.p03
HadrontherapyMatrix Class Reference

#include <HadrontherapyMatrix.hh>

Collaboration diagram for HadrontherapyMatrix:

Public Member Functions

 ~HadrontherapyMatrix ()
 
void PrintNuclides ()
 
void ClearHitTrack ()
 
G4intGetHitTrack (G4int i, G4int j, G4int k)
 
void Initialize ()
 
void Clear ()
 
G4bool Fill (G4int, G4ParticleDefinition *particleDef, G4int i, G4int j, G4int k, G4double energyDeposit, G4bool fluence=false)
 
void Fill (G4int i, G4int j, G4int k, G4double energyDeposit)
 
void TotalEnergyDeposit ()
 
void StoreMatrix (G4String file, void *data, size_t psize)
 
void StoreFluenceData ()
 
void StoreDoseData ()
 
void StoreDoseFluenceAscii (G4String filename="")
 
G4int Index (G4int i, G4int j, G4int k)
 
G4doubleGetMatrix ()
 
G4int GetNvoxel ()
 
G4int GetNumberOfVoxelAlongX ()
 
G4int GetNumberOfVoxelAlongY ()
 
G4int GetNumberOfVoxelAlongZ ()
 

Static Public Member Functions

static HadrontherapyMatrixGetInstance ()
 
static HadrontherapyMatrixGetInstance (G4int nX, G4int nY, G4int nZ, G4double mass)
 

Static Public Attributes

static G4bool secondary = false
 

Private Member Functions

 HadrontherapyMatrix (G4int numberOfVoxelAlongX, G4int numberOfVoxelAlongY, G4int numberOfVoxelAlongZ, G4double massOfVoxel)
 

Private Attributes

G4int numberOfVoxelAlongX
 
G4int numberOfVoxelAlongY
 
G4int numberOfVoxelAlongZ
 
G4double massOfVoxel
 
G4doublematrix
 
G4inthitTrack
 
G4String stdFile
 
G4String filename
 
std::ofstream ofs
 
std::vector< ionionStore
 
G4double doseUnit
 

Static Private Attributes

static HadrontherapyMatrixinstance = NULL
 

Detailed Description

Definition at line 55 of file HadrontherapyMatrix.hh.

Constructor & Destructor Documentation

◆ HadrontherapyMatrix()

HadrontherapyMatrix::HadrontherapyMatrix ( G4int  numberOfVoxelAlongX,
G4int  numberOfVoxelAlongY,
G4int  numberOfVoxelAlongZ,
G4double  massOfVoxel 
)
private

Definition at line 61 of file HadrontherapyMatrix.cc.

61  :
62  stdFile("Dose.out"),
63  doseUnit(gray)
64 {
65  // Number of the voxels of the phantom
66  // For Y = Z = 1 the phantom is divided in slices (and not in voxels)
67  // orthogonal to the beam axis
68  numberOfVoxelAlongX = voxelX;
69  numberOfVoxelAlongY = voxelY;
70  numberOfVoxelAlongZ = voxelZ;
71  massOfVoxel = mass;
72  // Create the dose matrix
74  if (matrix)
75  {
76  G4cout << "HadrontherapyMatrix: Memory space to store physical dose into " <<
78  " voxels has been allocated " << G4endl;
79  }
80  else G4Exception("HadrontherapyMatrix::HadrontherapyMatrix()", "Hadrontherapy0005", FatalException, "Can't allocate memory to store physical dose!");
81  // Hit voxel (TrackID) marker
82  // This array mark the status of voxel, if a hit occur, with the trackID of the particle
83  // Must be initialized
85  ClearHitTrack();
86 }
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static const double gray
Definition: G4SIunits.hh:306
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~HadrontherapyMatrix()

HadrontherapyMatrix::~HadrontherapyMatrix ( )

Definition at line 89 of file HadrontherapyMatrix.cc.

90 {
91  delete[] matrix;
92  delete[] hitTrack;
93  // free fluences/dose data memory
94  Clear();
95 }
Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void HadrontherapyMatrix::Clear ( )

Definition at line 98 of file HadrontherapyMatrix.cc.

99 {
100  for (size_t i=0; i<ionStore.size(); i++)
101  {
102  delete[] ionStore[i].dose;
103  delete[] ionStore[i].fluence;
104  }
105  ionStore.clear();
106 }
std::vector< ion > ionStore
Here is the caller graph for this function:

◆ ClearHitTrack()

void HadrontherapyMatrix::ClearHitTrack ( )

Definition at line 132 of file HadrontherapyMatrix.cc.

Here is the caller graph for this function:

◆ Fill() [1/2]

G4bool HadrontherapyMatrix::Fill ( G4int  trackID,
G4ParticleDefinition particleDef,
G4int  i,
G4int  j,
G4int  k,
G4double  energyDeposit,
G4bool  fluence = false 
)

Definition at line 148 of file HadrontherapyMatrix.cc.

153 {
154  if ( (energyDeposit <=0. && !fluence) || !secondary) return false;
155  // Get Particle Data Group particle ID
156  G4int PDGencoding = particleDef -> GetPDGEncoding();
157  PDGencoding -= PDGencoding%10;
158 
159  // Search for already allocated data...
160  for (size_t l=0; l < ionStore.size(); l++)
161  {
162  if (ionStore[l].PDGencoding == PDGencoding )
163  { // Is it a primary or a secondary particle?
164  if ( (trackID ==1 && ionStore[l].isPrimary) || (trackID !=1 && !ionStore[l].isPrimary))
165  {
166  if (energyDeposit > 0.) ionStore[l].dose[Index(i, j, k)] += energyDeposit;
167 
168  // Fill a matrix per each ion with the fluence
169  if (fluence) ionStore[l].fluence[Index(i, j, k)]++;
170  return true;
171  }
172  }
173  }
174 
175  G4int Z = particleDef-> GetAtomicNumber();
176  G4int A = particleDef-> GetAtomicMass();
177 
178  G4String fullName = particleDef -> GetParticleName();
179  G4String name = fullName.substr (0, fullName.find("[") ); // cut excitation energy
180  // Let's put a new particle in our store...
181  ion newIon =
182  {
183  (trackID == 1) ? true:false,
184  PDGencoding,
185  name,
186  name.length(),
187  Z,
188  A,
191  };
192  // Initialize data
193  if (newIon.dose && newIon.fluence)
194  {
196  {
197  newIon.dose[q] = 0.;
198  newIon.fluence[q] = 0;
199  }
200  if (energyDeposit > 0.) newIon.dose[Index(i, j, k)] += energyDeposit;
201  if (fluence) newIon.fluence[Index(i, j, k)]++;
202 
203  ionStore.push_back(newIon);
204 
205  // TODO Put some verbosity check
206  /*
207  G4cout << "Memory space to store the DOSE/FLUENCE into " <<
208  numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ <<
209  " voxels has been allocated for the nuclide " << newIon.name <<
210  " (Z = " << Z << ", A = " << A << ")" << G4endl ;
211  */
212  return true;
213  }
214  else // XXX Out of memory! XXX
215  {
216  return false;
217  }
218 
219 }
G4double * dose
G4int Index(G4int i, G4int j, G4int k)
G4String name
Definition: TRTMaterials.hh:40
int G4int
Definition: G4Types.hh:78
double A(double temperature)
unsigned int * fluence
Float_t Z
double G4double
Definition: G4Types.hh:76
std::vector< ion > ionStore
Here is the call graph for this function:

◆ Fill() [2/2]

void HadrontherapyMatrix::Fill ( G4int  i,
G4int  j,
G4int  k,
G4double  energyDeposit 
)

Definition at line 377 of file HadrontherapyMatrix.cc.

379 {
380  if (matrix)
381  matrix[Index(i,j,k)] += energyDeposit;
382 
383  // Store the energy deposit in the matrix element corresponding
384  // to the phantom voxel
385 }
G4int Index(G4int i, G4int j, G4int k)
Here is the call graph for this function:

◆ GetHitTrack()

G4int * HadrontherapyMatrix::GetHitTrack ( G4int  i,
G4int  j,
G4int  k 
)

Definition at line 137 of file HadrontherapyMatrix.cc.

138 {
139  return &(hitTrack[Index(i,j,k)]);
140 }
G4int Index(G4int i, G4int j, G4int k)
Here is the call graph for this function:

◆ GetInstance() [1/2]

HadrontherapyMatrix * HadrontherapyMatrix::GetInstance ( )
static

Definition at line 48 of file HadrontherapyMatrix.cc.

49 {
50  return instance;
51 }
static HadrontherapyMatrix * instance
Here is the caller graph for this function:

◆ GetInstance() [2/2]

HadrontherapyMatrix * HadrontherapyMatrix::GetInstance ( G4int  nX,
G4int  nY,
G4int  nZ,
G4double  mass 
)
static

Definition at line 54 of file HadrontherapyMatrix.cc.

55 {
56  if (instance) delete instance;
57  instance = new HadrontherapyMatrix(voxelX, voxelY, voxelZ, mass);
58  instance -> Initialize();
59  return instance;
60 }
HadrontherapyMatrix(G4int numberOfVoxelAlongX, G4int numberOfVoxelAlongY, G4int numberOfVoxelAlongZ, G4double massOfVoxel)
static HadrontherapyMatrix * instance
Here is the call graph for this function:

◆ GetMatrix()

G4double* HadrontherapyMatrix::GetMatrix ( )
inline

Definition at line 114 of file HadrontherapyMatrix.hh.

114 {return matrix;}

◆ GetNumberOfVoxelAlongX()

G4int HadrontherapyMatrix::GetNumberOfVoxelAlongX ( )
inline

Definition at line 118 of file HadrontherapyMatrix.hh.

◆ GetNumberOfVoxelAlongY()

G4int HadrontherapyMatrix::GetNumberOfVoxelAlongY ( )
inline

Definition at line 119 of file HadrontherapyMatrix.hh.

◆ GetNumberOfVoxelAlongZ()

G4int HadrontherapyMatrix::GetNumberOfVoxelAlongZ ( )
inline

Definition at line 120 of file HadrontherapyMatrix.hh.

◆ GetNvoxel()

G4int HadrontherapyMatrix::GetNvoxel ( )
inline

◆ Index()

G4int HadrontherapyMatrix::Index ( G4int  i,
G4int  j,
G4int  k 
)
inline

Definition at line 111 of file HadrontherapyMatrix.hh.

Here is the caller graph for this function:

◆ Initialize()

void HadrontherapyMatrix::Initialize ( )

Definition at line 110 of file HadrontherapyMatrix.cc.

111 {
112  // Clear ions store
113  Clear();
114  // Clear dose
116  {
117  matrix[i] = 0;
118  }
119 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrintNuclides()

void HadrontherapyMatrix::PrintNuclides ( )

Definition at line 123 of file HadrontherapyMatrix.cc.

124 {
125  for (size_t i=0; i<ionStore.size(); i++)
126  {
127  G4cout << ionStore[i].name << G4endl;
128  }
129 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
std::vector< ion > ionStore

◆ StoreDoseData()

void HadrontherapyMatrix::StoreDoseData ( )

Definition at line 267 of file HadrontherapyMatrix.cc.

268 {
269 
270  for (size_t i=0; i < ionStore.size(); i++){
271  StoreMatrix(ionStore[i].name + "_Dose.out", ionStore[i].dose, sizeof(G4double));
272  }
273 }
Float_t dose
G4String name
Definition: TRTMaterials.hh:40
void StoreMatrix(G4String file, void *data, size_t psize)
double G4double
Definition: G4Types.hh:76
std::vector< ion > ionStore
Here is the call graph for this function:

◆ StoreDoseFluenceAscii()

void HadrontherapyMatrix::StoreDoseFluenceAscii ( G4String  filename = "")

Definition at line 278 of file HadrontherapyMatrix.cc.

279 {
280 #define width 15L
281  filename = (file=="") ? stdFile:file;
282  // Sort like periodic table
283  std::sort(ionStore.begin(), ionStore.end());
284  G4cout << "Dose is being written to " << filename << G4endl;
285  ofs.open(filename, std::ios::out);
286  if (ofs.is_open())
287  {
288  // Write the voxels index and the list of particles/ions
289  ofs << std::setprecision(6) << std::left <<
290  "i\tj\tk\t";
291  // Total dose
292  ofs << std::setw(width) << "Dose(Gy)";
293  if (secondary)
294  {
295  for (size_t l=0; l < ionStore.size(); l++)
296  {
297  G4String a = (ionStore[l].isPrimary) ? "_1":""; // is it a primary?
298  ofs << std::setw(width) << ionStore[l].name + a <<
299  std::setw(width) << ionStore[l].name + a;
300  }
301  ofs << G4endl;
302 
303  /*
304  * PDGencondig
305  */
306  /*
307  ofs << std::setprecision(6) << std::left <<
308  "0\t0\t0\t";
309 
310  // Total dose
311  ofs << std::setw(width) << '0';
312  for (size_t l=0; l < ionStore.size(); l++)
313  {
314  ofs << std::setw(width) << ionStore[l].PDGencoding <<
315  std::setw(width) << ionStore[l].PDGencoding;
316  }
317  ofs << G4endl;
318  */
319  }
320  // Write data
321  for(G4int i = 0; i < numberOfVoxelAlongX; i++)
322  for(G4int j = 0; j < numberOfVoxelAlongY; j++)
323  for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
324  {
325  G4int n = Index(i, j, k);
326  // Write only not identically null data lines
327  if (matrix[n])
328  {
329  ofs << G4endl;
330  ofs << i << '\t' << j << '\t' << k << '\t';
331  // Total dose
332  ofs << std::setw(width) << (matrix[n]/massOfVoxel)/doseUnit;
333  if (secondary)
334  {
335  for (size_t l=0; l < ionStore.size(); l++)
336  {
337  // Fill ASCII file rows
338  ofs << std::setw(width) << ionStore[l].dose[n]/massOfVoxel/doseUnit <<
339  std::setw(width) << ionStore[l].fluence[n];
340  }
341  }
342  }
343  }
344  ofs.close();
345  }
346 }
G4int Index(G4int i, G4int j, G4int k)
#define width
TFile * file
int G4int
Definition: G4Types.hh:78
Char_t n[5]
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
std::vector< ion > ionStore
Here is the call graph for this function:

◆ StoreFluenceData()

void HadrontherapyMatrix::StoreFluenceData ( )

Definition at line 260 of file HadrontherapyMatrix.cc.

261 {
262  for (size_t i=0; i < ionStore.size(); i++){
263  StoreMatrix(ionStore[i].name + "_Fluence.out", ionStore[i].fluence, sizeof(unsigned int));
264  }
265 }
G4String name
Definition: TRTMaterials.hh:40
void StoreMatrix(G4String file, void *data, size_t psize)
std::vector< ion > ionStore
Here is the call graph for this function:

◆ StoreMatrix()

void HadrontherapyMatrix::StoreMatrix ( G4String  file,
void *  data,
size_t  psize 
)

Definition at line 228 of file HadrontherapyMatrix.cc.

229 {
230  if (data)
231  {
232  ofs.open(file, std::ios::out);
233  if (ofs.is_open())
234  {
235  for(G4int i = 0; i < numberOfVoxelAlongX; i++)
236  for(G4int j = 0; j < numberOfVoxelAlongY; j++)
237  for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
238  {
239  G4int n = Index(i, j, k);
240  // Check for data type: u_int, G4double, XXX
241  if (psize == sizeof(unsigned int))
242  {
243  unsigned int* pdata = (unsigned int*)data;
244  if (pdata[n]) ofs << i << '\t' << j << '\t' <<
245  k << '\t' << pdata[n] << G4endl;
246  }
247  else if (psize == sizeof(G4double))
248  {
249  G4double* pdata = (G4double*)data;
250  if (pdata[n]) ofs << i << '\t' << j << '\t' <<
251  k << '\t' << pdata[n] << G4endl;
252  }
253  }
254  ofs.close();
255  }
256  }
257 }
G4int Index(G4int i, G4int j, G4int k)
int G4int
Definition: G4Types.hh:78
Char_t n[5]
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TotalEnergyDeposit()

void HadrontherapyMatrix::TotalEnergyDeposit ( )

Definition at line 386 of file HadrontherapyMatrix.cc.

387 {
388  // Convert energy deposited to dose.
389  // Store the information of the matrix in a ntuple and in
390  // a 1D Histogram
391 #ifdef G4ANALYSIS_USE_ROOT
393 #endif
394 
395  if (matrix)
396  {
397  for(G4int i = 0; i < numberOfVoxelAlongX; i++)
398  for(G4int j = 0; j < numberOfVoxelAlongY; j++)
399  for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
400  {
401 #ifdef G4ANALYSIS_USE_ROOT
402  G4int n = Index(i,j,k);
403  if (analysis -> IsTheTFile() )
404  {
405  analysis -> FillEnergyDeposit(i, j, k, matrix[n]/massOfVoxel/doseUnit);
406  analysis -> BraggPeak(i, matrix[n]/massOfVoxel/doseUnit);
407  }
408 #endif
409  }
410  }
411 }
static HadrontherapyAnalysisManager * GetInstance()
G4int Index(G4int i, G4int j, G4int k)
int G4int
Definition: G4Types.hh:78
Char_t n[5]
Here is the call graph for this function:

Member Data Documentation

◆ doseUnit

G4double HadrontherapyMatrix::doseUnit
private

Definition at line 137 of file HadrontherapyMatrix.hh.

◆ filename

G4String HadrontherapyMatrix::filename
private

Definition at line 131 of file HadrontherapyMatrix.hh.

◆ hitTrack

G4int* HadrontherapyMatrix::hitTrack
private

Definition at line 130 of file HadrontherapyMatrix.hh.

◆ instance

HadrontherapyMatrix * HadrontherapyMatrix::instance = NULL
staticprivate

Definition at line 123 of file HadrontherapyMatrix.hh.

◆ ionStore

std::vector<ion> HadrontherapyMatrix::ionStore
private

Definition at line 135 of file HadrontherapyMatrix.hh.

◆ massOfVoxel

G4double HadrontherapyMatrix::massOfVoxel
private

Definition at line 127 of file HadrontherapyMatrix.hh.

◆ matrix

G4double* HadrontherapyMatrix::matrix
private

Definition at line 129 of file HadrontherapyMatrix.hh.

◆ numberOfVoxelAlongX

G4int HadrontherapyMatrix::numberOfVoxelAlongX
private

Definition at line 124 of file HadrontherapyMatrix.hh.

◆ numberOfVoxelAlongY

G4int HadrontherapyMatrix::numberOfVoxelAlongY
private

Definition at line 125 of file HadrontherapyMatrix.hh.

◆ numberOfVoxelAlongZ

G4int HadrontherapyMatrix::numberOfVoxelAlongZ
private

Definition at line 126 of file HadrontherapyMatrix.hh.

◆ ofs

std::ofstream HadrontherapyMatrix::ofs
private

Definition at line 132 of file HadrontherapyMatrix.hh.

◆ secondary

G4bool HadrontherapyMatrix::secondary = false
static

Definition at line 72 of file HadrontherapyMatrix.hh.

◆ stdFile

G4String HadrontherapyMatrix::stdFile
private

Definition at line 131 of file HadrontherapyMatrix.hh.


The documentation for this class was generated from the following files: